TFF file inner information extraction by Java or C#

僤鯓⒐⒋嵵緔 提交于 2020-12-08 05:18:36

问题


Currently, I am working on TTF font related software. I need to create some tool for extract the Kerning and Ligature information which is included in the TTF(given font) file.

I searched for many resources but I am unable to find any useful information.

Any opinion for Java or c#?

Thank you.


回答1:


You haven't indicated what platform/framework/library you're working with. And there's some complexity to what you're after.

TrueType/OpenType have long support a 'kern' table with kerning data.

Windows GDI has the GetKerningPairs() function that returns all the data from a font's 'kern' table (if present). It's limited in that it can't support Unicode supplementary-plane characters (code points U+10000 and above).

Windows DirectWrite has an API that is similar: IDWriteFontFace1::GetKerningPairAdjustments(). It might not be quite what you're after, though: it doesn't list the font's kerning pairs but rather take a glyph sequence and returns the adjustments for that sequence. DWrite also has IDWriteFontFace1::HasKerningPairs() that will tell you whether the font even has kerning pairs in a 'kern' table.

But here's the added complication: the 'kern' table is older technology that was later superseded by OpenType Layout mechanisms. A font can have a 'GPOS' table that specifies different types of glyph-positioning adjustments:

  • adjust a single glyphs advance width or x,y placement
  • adjust advances / placements on a pair of glyphs
  • adjust positioning of a single glyph or pair of glyphs in particular contexts
  • etc.

Positioning adjustment's might be done for many different reasons; the cases you'd be interested in, "kerning", would be linked to a 'kern' feature tag. You could use an API like IDWriteFontFace::TryGetFontTable to retrieve the GPOS table data and parse it yourself. You'd want to examine the GPOS table's FeatureList subtable to find a FeatureTable associated with the 'kern' feature, and (if present) get the array of lookup indices from that feature table. Then you can look in the GPOS table's LookupList subtable to find the specified Lookup tables. Then you'd need to parse out the Lookup sub-table for each of the specified Lookup tables to determine exactly what glyphs or glyph pairs get acted on.



来源:https://stackoverflow.com/questions/62033721/tff-file-inner-information-extraction-by-java-or-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!