-1

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.

  • The specification for the TTF file format is a good place to start: https://developer.apple.com/fonts/TrueType-Reference-Manual/ – Bradley Smith May 27 '20 at 00:48
  • I saw that article. I need to extract information by using java code or c# code. – Upekha Anthony May 27 '20 at 01:04
  • There are two kinds of kerning information that could be used in an OpenType font: a 'kern' table, or kerning adjustments in a 'GPOS' table. Ligatures would be provided by data in a 'GSUB' table. The 'kern' table isn't too complex, but 'GPOS' and 'GSUB' tables are quite complex. https://docs.microsoft.com/en-us/typography/opentype/spec/ I have a start on a [C# project](https://github.com/PeterConstable/OTCodec) to parse OpenType font data, but I haven't yet added kern, GPOS or GSUB tables. (I have another implementation I did some time ago, but haven't ported it all yet.) It's not trivial! – Peter Constable May 31 '20 at 02:39
  • Btw, it might help if you explained what exactly you're trying to do. When you say, "extract the kerning and ligature information", what specific information are you expecting and how will it get used? – Peter Constable May 31 '20 at 23:25
  • @PeterConstable Thank you for comments. I want to list that all available kerning and ligature information in particular TTF (font) file. ( As the First step, it is better to have Kerning information) – Upekha Anthony Jun 03 '20 at 06:35
  • Still not clear: You want to show that a font has kerning information? Or you want to show all of the glyph-pair-by-glyph-pair details (a lot of information)? The format is much easier than the latter. – Peter Constable Jun 03 '20 at 17:53
  • @PeterConstable I want to get the all kerning pair information. Just for not, I want to list the all available kerning pairs. Ex : TimeNewRome.ttf avaible kerning pairs, Aa Ac Ad Af At Ay aQ aZ a- a& ...etc I want to get information something like above programmatically. Thank you for your consideration. – Upekha Anthony Jun 03 '20 at 23:59

1 Answers1

0

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.

Peter Constable
  • 2,707
  • 10
  • 23