Corrupt TrueType Font Detection

我是研究僧i 提交于 2020-01-20 04:14:04

问题


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!


回答1:


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.




回答2:


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)?

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.




回答3:


What platform are you using? I've been able to hack TrueType files quite pleasantly using the FontTools library for Python:

font= fontTools.ttLib.TTFont("suspect.ttf")
font['maxp'].maxContours

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?)



来源:https://stackoverflow.com/questions/615479/corrupt-truetype-font-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!