freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how can I set exactly pixel?


From: Werner LEMBERG
Subject: Re: how can I set exactly pixel?
Date: Fri, 27 Dec 2019 12:58:22 +0100 (CET)

> I am currently working on a Thai text synthesis project which used
> freetype. My code is as follows (I’m using the font:“angsa.ttf”):
>
>   if (FT_Set_Pixel_Sizes(face, charWidth, charDotSize) != 0)
>   {
>     return (ERROR);
>   }
>
>   ascender = FT_MulFix(face->ascender, face->size->metrics.y_scale);
>   descender = FT_MulFix(face->descender, face->size->metrics.y_scale);
>
>   fontHeight = (UI_16)ceil((DOUBLE)(ascender - descender) / 64);
>
> I have some questions.  Assume that I need render one character to
> byte array with fixed size, in correct position.  Character size
> must be exactly size that fits in output bitmap, no clipping
> allowed.
>
> I specified character width=height=100.  But when I calculate the
> font height, it’s 117.
>
> How should I set height to get exactly 100px output, not 117, for
> any normal font?  If it isn't possible, then is there any way to
> calculate output character height exactly in pixels before
> FT_Render_Glyph.

For most outline fonts, it is not possible to get exact glyph
dimensions in advance (exception: the font contains an `hdmx' table
that holds horizontal, device-dependent information for selected pixel
sizes).  In other words, you have to render all (needed) glyphs to get
their widths and heights, adjusting the scaling value as necessary in
an iterative process until you are done.

To avoid rendering again you should use a glyph image and metrics
cache.


    Werner

reply via email to

[Prev in Thread] Current Thread [Next in Thread]