I know that it's possible to detect Type 1 and OpenType CFF (“PostScript flavored OpenType”) fonts by checking the first 4 bytes for 'OTTO' (0x4F54544F).
How would I do this in Python with the fontTools library? I.e., which font table would I need to check for this value?
The version is stored in the font file header, not in a font data table. If you have a
ttLib.TTFontobject (i.e. you've opened a font file with fontTools), you can look at the.sfntVersionattribute of yourTTFontobject to get the version (which will usually be either0x00010000/Version 1 or0x4F54544F/OTTO, but there are other possible values, see below). But that kind of assumes you've already created aTTFontobject by opening a font file, so this might be a kind of chicken-and-egg issue. If you're interested in knowing the version before you attempt to open the file/create aTTFont, you'll have to sniff the first four bytes (at least), outside of fontTools.Note: I'm a little confused by your question. You mention Type 1, which is indeed a kind of PostScript font, but not (usually) the kind in OpenType/sfnt-housed fonts (that would be Type 2, "Compact Font Format", or CFF). There is supposedly a way to store Type 1 in OpenType/sfnt-housed fonts; Apple mentions this in their TrueType Reference manual:
So if
typ1is in fact what you're asking about, you could look for0x74797031/"typ1" in the first four bytes of the file. But actualtyp1sfnt-housed fonts are exceedingly rare -- like almost non-existent. The overwhelming majority of actual Type 1 fonts will be in either .PFA/.PFB files (for non-Mac platforms), or in a "Printer Font" file (pre-OS X Mac), which would be paired with the old resource-fork "suitcase" file containing bitmaps. Type 1 font files will have%!PS-AdobeFont-1as the first bytes of the file.