如何从Android中的TTF文件读取字距调整对表 [英] How to read kerning pairs table from TTF file in Android
问题描述
我当前正在使用从TTF文件加载的外部(非标准)字体在Canvas上绘制文本.我要为显示的文本启用字距调整.
我想知道的是是否有可能使用Android API从字样中读取字距调整对.
我想知道的是是否有可能使用Android API从字样中读取字距调整对.
没有公共API可以从TTF文件中读取字距调整对.但是,我从 Apache FOP 中提取了相关代码,您可以使用此库.
用法示例:
TTFFile文件= TTFFile.open(getAssets().open("fonts/font.ttf")));Map< Integer,Map< Integer,Integer>字距调整= file.getKerning();
您还可以检索其他元数据.示例:
TTFFile ttfFile = TTFFile.open(new File("/system/fonts/Roboto-Regular.ttf"));字符串名称= ttfFile.getFullName();//"Roboto Regular"字符串族= ttfFile.getSubFamilyName();//常规的"int fontWeight = ttfFile.getWeightClass();//400字符串版权= ttfFile.getCopyrightNotice();//字体数据版权Google 2014"
我要为显示的文本启用字距调整.
请参阅:
I am currently drawing text on Canvas while using external (non-standard) font, loaded from TTF file. I want to enable kerning for the text I am displaying.
What I want to know is if there is a possibility to read kerning pairs from typeface using Android API.
What I want to know is if there is a possibility to read kerning pairs from typeface using Android API.
There is no public API to read kerning pairs from a TTF file. However, I pulled the relevant code from Apache FOP and you can read the kerning pairs using this library.
Example usage:
TTFFile file = TTFFile.open(getAssets().open("fonts/font.ttf"));
Map<Integer, Map<Integer, Integer>> kerning = file.getKerning();
You can also retrieve 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 text I am displaying.
See:
How to adjust text kerning in Android TextView?
这篇关于如何从Android中的TTF文件读取字距调整对表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!