views:

492

answers:

2

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!

A: 

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

bobince
Thanks! But no, I don't need a parser. I'll edit my question to add clarity.
dirkgently
A: 

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.

TokenMacGuy
I am consuming the input and I need to bail out asap -- so this doesn't work. I'll add this to the question :)
dirkgently