[HarfBuzz] Getting glyph information using Harfbuzz API

Behdad Esfahbod behdad at behdad.org
Wed May 24 22:54:59 UTC 2017


Hi Deepak,

On Tue, May 23, 2017 at 8:45 PM, Deepak Jois <deepak.jois at gmail.com> wrote:

> I am using Harfbuzz to layout text using LuaTeX[1]. As part of that, I
> need to provide LuaTeX with some information about all the glyphs in the
> font. Strictly speaking, this is more of a job for an Opentype parsing
> library than a shaping library like Harfbuzz.
>
> However, Khaled Hosny mentioned that I might be able to get the
> information I need from Harfbuzz itself. It seems the functionality I need
> should be somewhere in hb-font.h or hb-ot-layout.h I am looking at the API
> and it is not immediately obvious how I can do the following things with
> Harfbuzz:
>
> 1. Get a list of all the glyph ids in the font
>

That would be 0..hb_face_get_glyph_count(face)-1



> 2. Get a list of character to glyph mapping, i.e. the contents of the cmap
> table.
>

We don't expose this yet.  You can get the mapping from Unicode char to
glyph using hb_font_get_nominal_glyph().  What's missing is a way to get
set of Unicode characters.  I like to add that, just hasn't happened yet.
I'll see what I can do...



> 3 I suppose if I have (1) above I can get a hb_glyph_extents_t for each
> glyph. I am not sure how to convert it to a value that makes sense to
> LuaTeX which requires a width, depth and height.
>

Right.  Simon Cozens also wanted this for Sile... Problem is, in the TeX
model, the depth and height are "logical" boundaries, not glyph ink
extents.  Those numbers do not exist in OpenType.  For width, you want
advance width.  For depth and height, you really are on your own IMO.
Glyph extents are a bad fallback.

For really well-constructed fonts that have vertical metrics, taking
vertical origin height and vertical advance probably give you better
numbers, but it's hard to know when fonts are really well-constructed.



> 4. How does (3) above work for OpenType fonts with PostScript outlines
> which apparently do not store the character depth and height in the file. I
> know LuaTeX’s internal fontloader (based on FontForge) does some
> calculations to find the bounding box for each glyph. Can Harfbuzz do that
> too? Is that what this issue[2] talks about?
>

Yes, exactly.


> [1]: https://github.com/deepakjois/luatex-harfbuzz
> [2]: https://github.com/behdad/harfbuzz/issues/249
>
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/harfbuzz
>
>


-- 
behdad
http://behdad.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/harfbuzz/attachments/20170524/c70064ad/attachment.html>


More information about the HarfBuzz mailing list