console: Allow measuring the bounding box of text
For laying out text accurately it is necessary to know the width and height of the text. Add a measure() method to the console API, so this can be supported. Add an implementation for truetype and a base implementation for the normal console. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -82,6 +82,27 @@ struct vidconsole_colour {
|
||||
u32 colour_bg;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct vidconsole_bbox - Bounding box of text
|
||||
*
|
||||
* This describes the bounding box of something, measured in pixels. The x0/y0
|
||||
* pair is inclusive; the x1/y2 pair is exclusive, meaning that it is one pixel
|
||||
* beyond the extent of the object
|
||||
*
|
||||
* @valid: Values are valid (bounding box is known)
|
||||
* @x0: left x position, in pixels from left side
|
||||
* @y0: top y position, in pixels from top
|
||||
* @x1: right x position + 1
|
||||
* @y1: botton y position + 1
|
||||
*/
|
||||
struct vidconsole_bbox {
|
||||
bool valid;
|
||||
int x0;
|
||||
int y0;
|
||||
int x1;
|
||||
int y1;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct vidconsole_ops - Video console operations
|
||||
*
|
||||
@@ -189,6 +210,20 @@ struct vidconsole_ops {
|
||||
* Returns: 0 on success, -ENOENT if no such font
|
||||
*/
|
||||
int (*select_font)(struct udevice *dev, const char *name, uint size);
|
||||
|
||||
/**
|
||||
* measure() - Measure the bounds of some text
|
||||
*
|
||||
* @dev: Device to adjust
|
||||
* @name: Font name to use (NULL to use default)
|
||||
* @size: Font size to use (0 to use default)
|
||||
* @text: Text to measure
|
||||
* @bbox: Returns bounding box of text, assuming it is positioned
|
||||
* at 0,0
|
||||
* Returns: 0 on success, -ENOENT if no such font
|
||||
*/
|
||||
int (*measure)(struct udevice *dev, const char *name, uint size,
|
||||
const char *text, struct vidconsole_bbox *bbox);
|
||||
};
|
||||
|
||||
/* Get a pointer to the driver operations for a video console device */
|
||||
@@ -215,6 +250,19 @@ int vidconsole_get_font(struct udevice *dev, int seq,
|
||||
*/
|
||||
int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
|
||||
|
||||
/*
|
||||
* vidconsole_measure() - Measuring the bounding box of some text
|
||||
*
|
||||
* @dev: Console device to use
|
||||
* @name: Font name, NULL for default
|
||||
* @size: Font size, ignored if @name is NULL
|
||||
* @text: Text to measure
|
||||
* @bbox: Returns nounding box of text
|
||||
* Returns: 0 if OK, -ve on error
|
||||
*/
|
||||
int vidconsole_measure(struct udevice *dev, const char *name, uint size,
|
||||
const char *text, struct vidconsole_bbox *bbox);
|
||||
|
||||
/**
|
||||
* vidconsole_push_colour() - Temporarily change the font colour
|
||||
*
|
||||
|
Reference in New Issue
Block a user