[HarfBuzz] Inheriting/copying font functions

Behdad Esfahbod behdad at behdad.org
Wed May 11 07:09:41 PDT 2011


On 05/11/11 09:57, Tom Hacohen wrote:
> Dear Behadad [sic],

Hi Tom,


> After your recent changes (which removed the
> hb_font_funcs_get_contour_point_func and the like) and since there's no
> way to inherit/copy other func functions. It's now impossible to
> implement only part of the font functions and use Harfbuzz's default for
> freetype for the rest. Correct me if I'm wrong, but that's at least from
> my observation on the exposed API.

The changes I pushed was exactly to allow subclassing fonts with automatic
chainup.  The problem at hand is quite complex (it's dynamic anonymous
subclassing at runtime with per-class and per-instance private data!).  Here
is how you do it now:

You start by subclassing the font:

  font = hb_font_create_sub_font (parent);

And set your own font-funcs on it:

  hb_font_set_funcs (font, ffuncs, your_user_data, your_destroy);

Now you only have to override any functions you need, and in your function if
you need to chain up, you do, eg.

{
  if (not in cache...) {
    hb_font_get_contour_point (hb_font_get_parent (font),
                               glyph, point_index, x, y);
    add to cache...
  } else {
    lookup from cache...
  }
}

Makes sense?

Note that I changed the signature of get_contour_point and get_kerning
callbacks and functions slightly.


> Furthermore, do you really think that letting the users set user data
> with keys is the way to go? I think just solving the problem of internal
> user_data and external user data by having two of those is more than
> enough and probably a lot faster. I doubt that anyone will ever need
> more than 1 user data once you do the internal/external separation, so
> we'll probably just lose precious cpu cycles here.

Yes, multiple user_data is essential for any object system.  It's required by
bindings, as well as many generic programming technics.  FreeType's lack of
support for that has been a major pain (see hb_ft_create_face_cached() for
example).

behdad


> Thanks,
> Tom.
> 
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/harfbuzz
> 



More information about the HarfBuzz mailing list