diff options
| author | Simon Glass <[email protected]> | 2025-04-02 06:29:37 +1300 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2025-05-02 13:40:25 -0600 |
| commit | a7bbc59c31f4099a8da3acccf6919b886fb590f6 (patch) | |
| tree | 002a69a6f8e7488523babdb2366466934874a2bd /drivers | |
| parent | 236ae39fb0c571d2553271a7fa75920348f9c5eb (diff) | |
video: truetype: Fill in the measured line
Create a measured line for the (single) line of text.
Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/video/console_truetype.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index 7b9033818d3..39d77ad9818 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -737,11 +737,13 @@ static int truetype_measure(struct udevice *dev, const char *name, uint size, struct alist *lines) { struct console_tt_metrics *met; + struct vidconsole_mline mline; + const char *s; stbtt_fontinfo *font; int lsb, advance; - const char *s; int width; - int last; + int start; + int lastch; int ret; ret = get_metrics(dev, name, size, &met); @@ -754,25 +756,39 @@ static int truetype_measure(struct udevice *dev, const char *name, uint size, font = &met->font; width = 0; - for (last = 0, s = text; *s; s++) { + bbox->y1 = 0; + start = 0; + for (lastch = 0, s = text; *s; s++) { + int neww; int ch = *s; - /* Used kerning to fine-tune the position of this character */ - if (last) - width += stbtt_GetCodepointKernAdvance(font, last, ch); - /* First get some basic metrics about this character */ stbtt_GetCodepointHMetrics(font, ch, &advance, &lsb); + neww = width + advance; - width += advance; - last = ch; + /* Use kerning to fine-tune the position of this character */ + if (lastch) + neww += stbtt_GetCodepointKernAdvance(font, lastch, ch); + lastch = ch; + + width = neww; } + /* add the line */ + mline.bbox.x0 = 0; + mline.bbox.y0 = bbox->y1; + mline.bbox.x1 = tt_ceil((double)width * met->scale); + bbox->y1 += met->font_size; + mline.bbox.y1 = bbox->y1; + mline.start = start; + mline.len = (s - text) - start; + if (lines && !alist_add(lines, mline)) + return log_msg_ret("ttM", -ENOMEM); + bbox->valid = true; bbox->x0 = 0; bbox->y0 = 0; bbox->x1 = tt_ceil((double)width * met->scale); - bbox->y1 = met->font_size; return 0; } |
