如何从Android中的TTF文件读取字距调整对表 [英] How to read kerning pairs table from TTF file in Android

查看:74
本文介绍了如何从Android中的TTF文件读取字距调整对表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用从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" 


我要为显示的文本启用字距调整.

请参阅:

如何在Android TextView中调整文本字距?

setLetterSpacing(float)

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?

setLetterSpacing(float)

这篇关于如何从Android中的TTF文件读取字距调整对表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆