How to read kerning pair table from a TTF file in Android

I am currently drawing text on canvas using an external (non-standard) font loaded from a TTF file. I want to enable kerning for the displayed text.

I want to know if it is possible to read kerning pairs using a font using the Android API.

+5
source share
1 answer

I want to know if it is possible to read kerning pairs using a font using the Android API.

There is no open API for reading kerning pairs from a TTF file. However, I pulled the appropriate code from Apache FOP , and you can read kerning pairs using this library .

Using an example:

TTFFile file = TTFFile.open(getAssets().open("fonts/font.ttf")); Map<Integer, Map<Integer, Integer>> kerning = file.getKerning(); 

You can also get other metadata. Example:

 TTFFile ttfFile = TTFFile.open(new File("/system/fonts/Roboto-Regular.ttf")); String name = ttfFile.getFullName(); // "Roboto Regular" String family = ttfFile.getSubFamilyName(); // "Regular" int fontWeight = ttfFile.getWeightClass(); // 400 String copyright = ttfFile.getCopyrightNotice(); // "Font data copyright Google 2014" 

I want to enable kerning for the displayed text.

Cm:

How to set up text kerning in Android TextView?

setLetterSpacing (float)

+5
source

Source: https://habr.com/ru/post/1241473/


All Articles