损坏的 TrueType 字体检测
我目前正在处理损坏的 TrueType 字体。 我可用的程序告诉我 maxp
表 -- maxContours
成员的值太大。 是否有一种可靠的方法可以检测 maxContours 值何时过高或过低(是的,这也可能是一个问题)? (字体是程序,因此检测字体文件的一种方法是执行它们,但这对我来说不是一个可接受的解决方案。)
我不需要字体库,因为我无法添加字体库。 我已经推出了自己的 TrueType 字体解析器。 剩下的就是检查上表中的给定值是否错误。 然后我会将解析器和检查添加到我的产品中。
我没有重建字体的选项。 我是一名消费者——我需要检测传入的字体是否已损坏,以及是否可以通过尽可能少的工作来解决。
如果它有帮助的话——我使用的是 Windows XP/Vista 32 和 32 位操作系统。 64 位及其服务器版本!
I am at present dealing with a corrupt TrueType font. Programs available to me tell me there is a problem with the maxp
table -- the maxContours
member has a value that is too large. Is there a sure-fire way to detect when a maxContours
value is too high or too low (yes that too can be a problem)? (Fonts are programs so one way to detect a font file is good is to execute them, but this is not an acceptable solution for me.)
I don't need a font library because I can't add one. I have already rolled my own TrueType font parser. What remains is to check if a given value of the above mentioned table is incorrect. I'll then add my parser and the checks to my product.
I don't have the option of rebuilding the font. I am a consumer -- I need to detect if the incoming font is corrupt or not and if it is bail out with as little work done as possible.
In case it helps -- I'm on Windows XP/Vista both 32 & 64 bit and their server versions!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现最方便的方法是使用 FontForge 重建故障字体,而不是尝试检测错误。 这可以完全自动化,因为它提供了丰富的命令行和脚本 API。 另外,如果需要,您可以将字体转换为更方便的格式或编码。
Rather than trying to detect errors, I've found it most convenient to just rebuild the trouble-font with FontForge. This can be completely automated, since it provides a rich command line and scripting API. Plus, You can transform the font into a more convenient format or encoding, if you need.
是的。如果您已经按照您的指示构建/拥有 TrueType/OpenType 解析库,则这个特定值相当容易验证。 您需要解析每个字形(来自 'glyf' 表 ,使用“loca”表作为索引),逐一获取每个字形的轮廓数,并将字体宽度最大值与存储在 'maxp'。
请注意,“maxp”中的一些其他值不这么容易测试; 例如,maxZones、maxTwilightPoints、maxStorage、maxFunctionDefs、maxInstructionDefs、maxStackElements、maxSizeOfInstructions 都需要解析其他表,并且对于其中一些表,需要访问 TrueType 缩放器和解释器。
一点背景知识:“maxp”(最大配置文件)表旨在成为潜在有用的字体范围最大值的快捷方式/摘要,作为内存分配的辅助。 所以一般来说,如果“maxp”中的值高于实际字体值,最糟糕的情况是您分配了太多内存......也就是说,如果您所在的平台实际上使用了所有字体用于此目的的“maxp”值。
Yes. If you've already built/have a TrueType/OpenType parsing library as you've indicated, this particular value is fairly easy to validate. You'll need to parse each of the glyphs (from the 'glyf' table, using the 'loca' table as an index), obtain the number of contours from each glyph, one-by-one, and compare the font-wide maximum to that stored in the 'maxp'.
Note that some other values in the 'maxp' are not this simple to test; for example, maxZones, maxTwilightPoints, maxStorage, maxFunctionDefs, maxInstructionDefs, maxStackElements, maxSizeOfInstructions all require parsing of additional tables and for some of those, access to a TrueType scaler and interpreter.
A little background: the 'maxp' (maximum profile) table was intended to be a shortcut/ summary of potentially-useful font-wide maximums, as an aid in memory allocation. So generally speaking, if a value in the 'maxp' is higher than the actual font value, the worst that will happen is that you allocate too much memory...that is, if you're on a platform that actually uses all of the 'maxp' values for that purpose.
您使用什么平台? 我已经能够使用 Python 的 FontTools 库非常愉快地破解 TrueType 文件:
ETA re q编辑:那么问题只是“maxContours 的哪些值太低/太高”? 据我所知,没有记录的限制,但我知道在 maxContours 中“添加一些”是相当常见的,以防字形包含比其规定的更多的轮廓。
(麻烦的字体中的 maxContours 是什么,它与字形中实际使用的轮廓数有何关系?)
What platform are you using? I've been able to hack TrueType files quite pleasantly using the FontTools library for Python:
ETA re q edit: So is the question just “what values of maxContours are too low/too high”? As far as I am aware there isn't a documented limit, but I know it's fairly common to ‘add a few on’ to maxContours in case a glyph contains more contours than it states.
(What's maxContours in the troublesome font, and how does it related to the number of contours actually used in glyphs?)