From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Anatolij Gustschin <agust@denx.de>
Cc: u-boot@lists.denx.de
Subject: Re: [PATCH 1/1] video: fix positioning in TrueType console
Date: Wed, 27 Oct 2021 20:10:36 +0200 [thread overview]
Message-ID: <ae69dc4a-7d4b-8263-df54-32de07cf6683@gmx.de> (raw)
In-Reply-To: <20210203161254.970-1-xypron.glpk@gmx.de>
Dear Anatolij,
somehow you lost track of this patch since March:
https://patchwork.ozlabs.org/project/uboot/patch/20210203161254.970-1-xypron.glpk@gmx.de/
Could you, please, review it and consider it for merging.
Best regards
Heinrich
On 2/3/21 17:12, Heinrich Schuchardt wrote:
> With the patch accurate positioning is possible for mono-typed fonts:
>
> Fix the return value of console_truetype_putc_xy(). The current position
> is passed as parameter x. Some part of x represents a fractional pixel.
> The return value represents how much the character position must be
> advanced. This should only comprise the width of the current character and
> not the preexisting fractional pixel position.
>
> Characters are not square. As all characters of a mono-type font we can
> take the width of any character. 'W' as one of the widest ANSI characters
> provides also a good value for variable width fonts.
>
> The character width must be a float.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> drivers/video/console_truetype.c | 27 ++++++++++++++++++++-------
> include/video_console.h | 2 +-
> 2 files changed, 21 insertions(+), 8 deletions(-)
>
> --
> 2.30.1
>
> diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
> index 318a060926..56939af849 100644
> --- a/drivers/video/console_truetype.c
> +++ b/drivers/video/console_truetype.c
> @@ -211,7 +211,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
> int width_frac, linenum;
> struct pos_info *pos;
> u8 *bits, *data;
> - int advance;
> + int advance, kern_adv;
> void *start, *line, *sync_start, *sync_end;
> int row, ret;
> int bg_r, bg_g, bg_b;
> @@ -226,8 +226,11 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
> * this character */
> xpos = frac(VID_TO_PIXEL((double)x));
> if (vc_priv->last_ch) {
> - xpos += priv->scale * stbtt_GetCodepointKernAdvance(font,
> - vc_priv->last_ch, ch);
> + kern_adv = stbtt_GetCodepointKernAdvance(font, vc_priv->last_ch,
> + ch);
> + xpos += priv->scale * kern_adv;
> + } else {
> + kern_adv = 0;
> }
>
> /*
> @@ -238,8 +241,8 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
> */
> x_shift = xpos - (double)tt_floor(xpos);
> xpos += advance * priv->scale;
> - width_frac = (int)VID_TO_POS(xpos);
> - if (x + width_frac >= vc_priv->xsize_frac)
> + width_frac = VID_TO_POS(priv->scale * (kern_adv + advance));
> + if (x + (int)VID_TO_POS(xpos) >= vc_priv->xsize_frac)
> return -EAGAIN;
>
> /* Write the current cursor position into history */
> @@ -591,20 +594,21 @@ static int console_truetype_probe(struct udevice *dev)
> struct udevice *vid_dev = dev->parent;
> struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
> stbtt_fontinfo *font = &priv->font;
> - int ascent;
> + int advance, ascent, lsb;
>
> debug("%s: start\n", __func__);
> +
> if (vid_priv->font_size)
> priv->font_size = vid_priv->font_size;
> else
> priv->font_size = CONFIG_CONSOLE_TRUETYPE_SIZE;
> +
> priv->font_data = console_truetype_find_font();
> if (!priv->font_data) {
> debug("%s: Could not find any fonts\n", __func__);
> return -EBFONT;
> }
>
> - vc_priv->x_charsize = priv->font_size;
> vc_priv->y_charsize = priv->font_size;
> vc_priv->xstart_frac = VID_TO_POS(2);
> vc_priv->cols = vid_priv->xsize / priv->font_size;
> @@ -618,6 +622,15 @@ static int console_truetype_probe(struct udevice *dev)
>
> /* Pre-calculate some things we will need regularly */
> priv->scale = stbtt_ScaleForPixelHeight(font, priv->font_size);
> +
> + /* Assuming that 'W' is the widest character */
> + stbtt_GetCodepointHMetrics(font, 'W', &advance, &lsb);
> + advance += stbtt_GetCodepointKernAdvance(font, 'W', 'W');
> + vc_priv->cols =
> + (int)VID_TO_POS(vid_priv->xsize - 2) /
> + (int)VID_TO_POS(advance * priv->scale);
> + vc_priv->x_charsize = advance * priv->scale;
> +
> stbtt_GetFontVMetrics(font, &ascent, 0, 0);
> priv->baseline = (int)(ascent * priv->scale);
> debug("%s: ready\n", __func__);
> diff --git a/include/video_console.h b/include/video_console.h
> index 8747299d61..cf306e5ca2 100644
> --- a/include/video_console.h
> +++ b/include/video_console.h
> @@ -68,7 +68,7 @@ struct vidconsole_priv {
> int ycur;
> int rows;
> int cols;
> - int x_charsize;
> + double x_charsize;
> int y_charsize;
> int tab_width_frac;
> int xsize_frac;
>
next prev parent reply other threads:[~2021-10-27 18:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-28 19:05 [PATCH 1/1] video: fix positioning in TrueType console Heinrich Schuchardt
2021-10-27 18:10 ` Heinrich Schuchardt [this message]
2021-10-27 19:52 ` Anatolij Gustschin
2021-10-28 5:22 ` Heinrich Schuchardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ae69dc4a-7d4b-8263-df54-32de07cf6683@gmx.de \
--to=xypron.glpk@gmx.de \
--cc=agust@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.