[Top][All Lists]

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

Re: Glyph extents

From: Jean Abou Samra
Subject: Re: Glyph extents
Date: Wed, 19 Apr 2023 02:52:23 +0200
User-agent: Evolution 3.46.4 (3.46.4-1.fc37)

Le mercredi 19 avril 2023 à 02:28 +0200, Jean Abou Samra a écrit :

> Le mercredi 19 avril 2023 à 02:00 +0200, Jean Abou Samra a écrit :
> > Does anyone have an idea why it happens?
> OK, now I see this:
> [...]
> Why are we using the `ink_rect` for Y extents but `logical_rect` for X 
> extents?

The other side of the problem is

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/`). Why do we need to put 
the bbox into a Scheme table, can't we get it from the glyph itself via 

That sounds pretty much like what the last 3 lines of code are doing. These are 
dead code, according to my experiments. However, if I remove everything that's 
before to make the extents always computed through 
`get_unscaled_indexed_char_dimensions`, I get wrong output. The blue rectangle 
is exactly fitted to the glyph ink. I don't understand why. That's not what I 
would expect to happen based on the pictures here:

and the code

ly_FT_get_unscaled_indexed_char_dimensions (FT_Face const &face,
                                            size_t signed_idx)
  FT_UInt idx = FT_UInt (signed_idx);
  FT_Load_Glyph (face, idx, FT_LOAD_NO_SCALE);

  FT_Glyph_Metrics m = face->glyph->metrics;
  FT_Pos hb = m.horiBearingX;
  FT_Pos vb = m.horiBearingY;

  // is this viable for all grobs?
  return Box (
    Interval (static_cast<Real> (hb), static_cast<Real> (hb + m.width)),
    Interval (static_cast<Real> (vb - m.height), static_cast<Real> (vb)));

Werner, can you help here?

Attachment: signature.asc
Description: This is a digitally signed message part

reply via email to

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