通过 CTFontRef 或 CGFontRef 对象中的字形索引获取 unicode 字符 [英] Get unicode character by glyph index in a CTFontRef or CGFontRef object

查看:96
本文介绍了通过 CTFontRef 或 CGFontRef 对象中的字形索引获取 unicode 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CTFontRef 提供了出色的方法,例如 CTFontGetGlyphsForCharacters 用于将字符映射到字形.我的问题是,是否有任何反转映射的方法?也就是说,我可以通过给定的字形获得字符吗?由于我发现有一个 CTFontCopyCharacterSet 用于获取所有支持的字符,我认为会有一些不错的解决方案.

The CTFontRef provides excellent method such as CTFontGetGlyphsForCharacters for mapping character(s) to glyph(s). My question is, is there any method for invert mapping? That is say, can I get characters(s) by given glyph(s)? Since I found there is a CTFontCopyCharacterSet for getting all supported characters, I think there will be some nice solutions.

推荐答案

我认为您最终可能不得不自己解析字体的映射表.您可以使用 CGFontCopyTableForTag() 获取对表的访问权限;您需要的表是cmap"表,其格式记录在此处:

I think you may end up having to parse the font’s mapping tables yourself. You can obtain access to the tables using CGFontCopyTableForTag(); the table you're after is the 'cmap' table, the format of which is documented here:

http://www.microsoft.com/typography/otspec/cmap.htm

还有这里:

http://developer.apple.com/fonts/TTRefMan/RM06/Chap6cmap.html

不幸的是,通过阅读这些内容,您会发现,将字符映射到字形的工作绝对是不平凡的,此外,任何给定的字体可能有多个映射表(即使用字符集的字符集)给定的字形可能取决于您(或渲染器)选择的映射表格式).

Unfortunately, as you’ll discover by reading through these, the business of mapping characters to glyphs is decidedly non-trivial, and in addition any given font may have more than one mapping table (i.e. the set of characters that use a given glyph may depend on which mapping table format you—or the renderer—chooses).

此外,像 OpenType 或 AAT 这样的高级字体技术可能会导致存在没有字符直接映射的字形,但由于进行了替换,这些字形仍然存在于输出中通过智能字体技术.反转 OpenType 或 AAT 替换机制会很棘手,而且可能也不会导致单个 Unicode 代码点(甚至单个字素簇).

Furthermore, advanced font technology like OpenType or AAT may result in the existence of glyphs for which there is no direct mapping from characters, but that are nevertheless present in the output as a result of substitutions made by the smart font technology. Inverting the OpenType or AAT substitution mechanisms would be tricky, and might also not lead to a single Unicode code point (or indeed even a single grapheme cluster).

这篇关于通过 CTFontRef 或 CGFontRef 对象中的字形索引获取 unicode 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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