Determine whether a font file is OpenType format or TrueType format

We are working on a program that needs to distinguish between OpenType fonts to TTF fonts [like the font list InDesign has], but we could not mannge to find the right way to determine if a given font is OpenType format file.
I have found some discussions about it on Stackoverflow - like: here and here and here.
And it seems that they don't have the right answer, cause it does not depend on file extension, for there can be a TTF file that has opentype format.
So my question is - how can i make my program distinguish between OpenType font file to TrueType font file.


Tagged:

Comments

  • Erwin DenissenErwin Denissen Posts: 128
    edited November 21
    An in-depth discussion about TrueType versus OpenType can be found here:

    Based on the specifications, all TrueType fonts are also OpenType fonts, but only a very small percentage of OpenType fonts are also TrueType fonts.

    Another thing you should be aware of is the fact people sometimes talk about TrueType fonts while they actually refer to OpenType fonts based on TrueType outlines.
  • Depends on what you want to do with that information, you can either check the first four bytes or check the presence of CFF or CFF2 tables vs. glyf & loca tables.
  • The first four bytes indicate whether a font is:
    - OpenType font that contains TrueType outlines
    - OpenType font containing CFF data
    - Something else

    It doesn't distinguish between
    - TrueType fonts
    - OpenType fonts that contain TrueType outlines

    If a font contains TrueType based outlines (thus contains both glyf and loca tables) and doesn't contain OpenType feature related tables (e.g. DSIG, GDEF, GSUB, GPOS) then it is most likely a TrueType font.
  • TrueType and OpenType can mean a lot of things.

    What do you need to differentiate: the outline format, the presence of OpenType layout extension, or both?
  • Yeshurun KubiYeshurun Kubi Posts: 2
    edited November 21
    Depends on what you want to do with that information, you can either check the first four bytes or check the presence of CFF or CFF2 tables vs. glyf & loca tables.
    Though this information is helpful ,still it looks like technical information and very formal, and it might be not what we realy need, dealing a program that needs to render text.
    ...
    Based on the specifications, all TrueType fonts are also OpenType fonts, but only a very small percentage of OpenType fonts are also TrueType fonts.
    ...
    TrueType and OpenType can mean a lot of things.
    What do you need to differentiate: the outline format, the presence of OpenType layout extension, or both?
    This makes me figure that the distinguish we need is between fonts that have opentype features to other fonts that have no features, for it looks like designers that want to use a font, might prefer those that has opentype features, and that what makes them think "this is an opentype font".
    Though i am not sure but it might be the way InDesign do that on there font list.

    opt.png 11.3K
  • John HudsonJohn Hudson Posts: 1,497
    edited November 22
    I'm pretty sure InDesign is deciding which icon to display only on the basis of which outline type is used, not whether the font contains OpenType Layout features. There are fonts identified as TrueType in the InDesign menu that I know for a fact have OTL features.

    Back in 1997, when OpenType was announced, the only distinction Microsoft could come up with between a TrueType font and an OpenType font with TT outlines was the presence of a DSIG table, since the OTL tables were all considered optional. So technically, one can have a TTF with OTL tables that is not an OpenType font.  :D

    And of course it is possible to make a CFF font with no OTL features, and InDesign will dutifully assign it the OT icon.

    It sounds like for your purposes you're going to want to check for the presence of a GSUB table. That's the most likely indicator that a font contains some kind of glyph processing beyond the cmap table.



  • For Wakamai Fondue I check for the presence of a glyf table to call it a TrueType font, and if it's not there I call it an OpenType/CFF font. 

    The comment above that code says "TODO: is this oversimplified?", and judging by the comments in this thread the answer to that is "yes".
  • You need to ask WHY you want to make a distinction.

    For many needs, what Roel does, and what Adobe does, is useful: distinguish between the two different kinds of outlines.

    I do not find the approach Windows uses to ever be helpful.

    You could try to make some kind of feature-based distinction instead. Depends on your audience and needs, that might be fine. For myself, I don’t find it helpful to have two different fonts with different outline formats to get the same icon/indicator. But it depends on your audience and their needs.
  • InDesign CS6 shows a TTF with OT tables with TT 'glyf' outlines as OT font if it has a DSIG, and as TT font it it doesn’t have a DSIG.
  • John HudsonJohn Hudson Posts: 1,497
    My inclination, in terms of providing accurate and useful information is not to make a distinction between TrueType and OpenType, but instead between TTF and CFF (outline format distinction) and then indicate whether it is an OpenType Layout font (contains GSUB/GPOS tables.
Sign In or Register to comment.