lilypond-devel
[Top][All Lists]
Advanced

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

Re: Glyph extents


From: Werner LEMBERG
Subject: Re: Glyph extents
Date: Wed, 19 Apr 2023 06:02:00 +0000 (UTC)

> ```
> Box
> Open_type_font::get_indexed_char_dimensions (size_t signed_idx) const
> {
>   const size_t len = 256;
>   char name[len];
>   FT_Error code
>     = FT_Get_Glyph_Name (face_, FT_UInt (signed_idx), name, FT_UInt (len));
>   if (code)
>     warning (_f ("FT_Get_Glyph_Name () Freetype error: %s",
>                  freetype_error_string (code)));
> 
>   SCM sym = ly_symbol2scm (name);
>   SCM alist = scm_hashq_ref (lily_character_table_, sym, SCM_BOOL_F);
> 
>   if (scm_is_true (alist))
>     {
>       SCM bbox = scm_cdr (scm_assq (ly_symbol2scm ("bbox"), alist));
> 
>       Box b;
>       b[X_AXIS][LEFT] = from_scm<double> (scm_car (bbox));
>       bbox = scm_cdr (bbox);
>       b[Y_AXIS][LEFT] = from_scm<double> (scm_car (bbox));
>       bbox = scm_cdr (bbox);
>       b[X_AXIS][RIGHT] = from_scm<double> (scm_car (bbox));
>       bbox = scm_cdr (bbox);
>       b[Y_AXIS][RIGHT] = from_scm<double> (scm_car (bbox));
>       bbox = scm_cdr (bbox);
> 
>       b.scale (point_constant);
> 
>       return b;
>     }
> 
>   Box b = get_unscaled_indexed_char_dimensions (signed_idx);
> 
>   b.scale (design_size () / static_cast<Real> (face_->units_per_EM));
>   return b;
> }
> ```
> 
> I don't understand this code.  It gets the bbox in the LILY font
> table generated by the build scripts
> (`scripts/build/mf-to-table.py`).  Why do we need to put the bbox
> into a Scheme table, can't we get it from the glyph itself via
> FreeType?

No, we can't.

For FreeType, a bounding box ('bbox') of a glyph is set up by the
minima and maxima of all its contours (omitting single-point
contours).  Computing this is very slow.  However, much faster to
compute is the control box ('cbox'), which consists of the minimum and
maximum values of all points all contours of a glyph.  In well-formed
fonts (i.e., fonts that have a curve points at all contour extrema),
the bbox and cbox dimensions are identical.

Note that the bbox/cbox information is *not* part of an OpenType font!
Only the advance width together with the left-side bearing ('lsb',
which is negative for Emmentaler's glyph 'f') is stored in the 'hmtx'
table.  While the advance width is an arbitrary value set by the font
designer, the lsb is not.

For LilyPond, the term 'bbox' means something completely different: It
is an artificial box suited for LilyPond's needs but *completely
decoupled* from the actual glyph dimensions.  For a glyph's width,
breapth, height, and depth, the OpenType SFNT tables only deliver
'width'.

>   FT_Pos hb = m.horiBearingX;
>   FT_Pos vb = m.horiBearingY;

FreeType computes these values from the glyph's 'cbox' while loading
the glyph for retrieving its metrics.


    Werner



reply via email to

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