[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dealing with different character map formats when mapping glyph indi
From: |
Werner LEMBERG |
Subject: |
Re: Dealing with different character map formats when mapping glyph indicies to character codes |
Date: |
Thu, 25 May 2023 20:26:17 +0000 (UTC) |
> Would you mind addressing the other approaches given, and why yours
> will work the best?
>
> To me, simply looking up the characters that need adjustments
> beforehand to get their glyph indices makes the most sense.
As you said by yourself, directly using a cmap provided by FreeType is
a first start for working. However, it is not sufficient, as
mentioned in an earlier e-mail. FreeType receives a *glyph index*,
and in modern OpenType fonts there are *a lot* of glyph indices not
part of any cmap.
Please get acquainted with OpenType's GSUB table mechanism.
https://learn.microsoft.com/en-us/typography/opentype/spec/gsub
As an example, let's assume that a user has activated the 'onum'
feature (oldstyle figures), and we look at figure '4'. The character
code is 0x34, and in our hypothetical font it gets mapped to glyph
index 104 by the cmap table. However, because of the 'onum' feature,
this glyph index gets remapped to another glyph index, say, 204, which
represents the oldstyle shape of digit 4. This glyph index 204 does
*not* appear in the cmap! In other words, you need a means to
eventually map glyph index 204 back to character code 0x34.
Let's say that another feature present in the font is 'pnum'
(proportional figures). If this is active, glyph index 104 gets
mapped to index 304, representing a glyph for figure '4' with a
different, proportional width.
All things put together, input character code 0x34 now maps to (at
least) three different glyph indices (104, 204, and 304), depending on
what feature is active.
Werner