freetype
[Top][All Lists]
Advanced

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

Re: Initial pen position in freetype?


From: Werner LEMBERG
Subject: Re: Initial pen position in freetype?
Date: Tue, 04 Aug 2020 07:19:06 +0200 (CEST)

> [...]  What I want is the framing of the text to be as the font
> designer intended.  .ascender above the top baseline and .descender
> below the bottom baseline looks right to me so far for all the fonts
> I've checked.

OK.

> I've also observed that FT_Load_Glyph(FT_LOAD_DEFAULT) seems to take
> about 80% as long as FT_Load_Glyph(FT_LOAD_RENDER) for small scales
> (EM: 10-20px), consequently making one pass of the glyphs calling
> FT_Load_Glyph(FT_LOAD_DEFAULT) for layout and then another pass
> calling FT_Load_Glyph(FT_LOAD_RENDER) takes almost twice as long as
> making a singular pass calling FT_Load_Glyph(FT_LOAD_RENDER) once
> per glyph.  Unless I am missing some faster way of loading the
> glyphs on the first layout pass?

It depends, since...

> I'm not sure I fully understand what FT_Load_Glyph(FT_LOAD_DEFAULT)
> is doing under the hood that it takes almost the same amount of time
> as FT_Load_Glyph(FT_LOAD_RENDER) - my profiling tools say something
> about "TT_RunIns" - is that something to do with walking the font
> outline?  Is there some way I can just get face->glyph->advance
> calculated without doing any of the other work
> FT_Load_Glyph(FT_LOAD_DEFAULT) does?  advance is all I need on a
> layout pass.

... in TrueType fonts the advance widths can change (and actually are)
in two modes, namely B/W rendering and v35 grayscale rendering.  In
other words, you *must* execute the bytecode engine (this is the
`TT_RunIns` function) to get correct advance widths in these two
modes.

This was a problem since the very beginning, and for this reason a
shortcut exists, namely the `hdmx` table in TrueType fonts, which
contains pre-computed advance width values for a limited set of pixel
sizes – very old fonts even have such data for various non-square
pixels, too.  FreeType doesn't have explicit support for that table;
you have to parse it by yourself.

Today, however, you won't find `hdmx` tables anymore.  First of all,
the dominant rendering mode for TrueType fonts is ClearType, which
still allows modification of the advance width by bytecode
instructions under certain assumptions, but all major applications
that use ClearType, in particular web browsers, don't support this
ClearType feature.  Additionally, variation fonts explicitly disallow
the modification of advance width values with bytecode, IIRC.

To summarize: If you use a ClearType rendering mode, or if you use
non-TrueType fonts, a single pass is sufficient to quickly extract the
advance width values with `FT_Get_Advance` or `FT_Get_Advances`.


    Werner

reply via email to

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