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:
«1

Comments

  • Erwin DenissenErwin Denissen Posts: 291
    edited November 2018
    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: 14
    edited November 2018
    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: 2,955
    edited November 2018
    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.
  • We dropped the O v TT icons in Office as they really were not helpful. Previously we looked for CFF and/or DSIG table. An alternative would have been to base the icon on CFF and / or GPOS, GSUB. 
  • Dave CrosslandDave Crossland Posts: 1,389
    edited December 2018
    Based on the specifications, all TrueType fonts are also OpenType fonts, but only a very small percentage of OpenType fonts are also TrueType fonts.

    This is not right, in my opinion. 

    All TrueType fonts are valid as OpenType fonts, but that is because OpenType is mostly a superset of TrueType; and a huge percentage of OpenType fonts are also TrueType fonts,  and called "TrueType flavor" OpenType fonts.

    The OpenType fonts that are not TrueType fonts are the "CFF flavor" ones. 

    I believe that a simple heuristic to answer Yeshurun Kubi's question, "how can i make my program distinguish between OpenType font file to TrueType font file" is by checking for the presence of either a CFF or GSUB table - if either is present, its OpenType, and if neither is present, its TrueType.
  • and a huge percentage of OpenType fonts are also TrueType fonts,  and called "TrueType flavor" OpenType fonts.
    These TrueType flavor OpenType fonts (I refer to them as OpenType fonts with TrueType based outlines), shouldn't be called TrueType fonts, unless they have no OpenType features, no DSIG table, no license description, and an OS/2 version of 0 or 1. That is way I think only a small percentage of OpenType fonts is also considered to be TrueType fonts.


  • John HudsonJohn Hudson Posts: 2,955
    edited December 2018
    How one diagrams the relationships of the various sfnt font flavours depends on what aspect of those relationships one considers important. I tend to think in terms of outline format and glyph processing capability:

    sfnt fonts<br>——TrueType outlines<br>————non-smart TTF (no glyph processing tables)<br>————Apple smart TTF (GX/AAT glyph processing)<br>————Microsoft smart TTF (TrueType Open / OpenType glyph processing)<br>——CFF outlines<br>————non-smart CFF (PDF embedding format)<br>————smart CFF (OpenType glyph processing)
  • k.l.k.l. Posts: 106
    Nice how you 'repurpose' DecoType's notion of "smart", backport it to refer to OpenType Layout, when 'smart' in DecoType-speak refers to something that OTL is not.
    Your 'glyph processing' is not exactly exact, by the way, as 'GX/AAT glyph processing' indicates, with 'GX' referring to interpolation of glyphs' outlines and 'AAT' referring to layout or positioning of glyphs.
    What I find striking, given above attempts to clarify the meaning of 'OpenType', is just how cleverly vague the term 'OpenType' is, and has been since day one, which makes me wonder if this is intentionally so. For illustration: How to express that a font uses either glyf/loca or CFF[2] tables for outline description – but addresses a different layout technology? Correctly speaking, it would be something like 'based on standard sfnt font data structure', but then ... explain 'sfnt' to a lay or even type designer audience ... so one inevitably needs to resort to a better known term like 'TrueType based' or 'OpenType based'. Yet 'TrueType' most likely bears the connotation of glyf/loca outline description while 'OpenType' is associated with OTL and 'features' in particular. But then, the ambiguity of the data format's (or data formats') name (or names) reflects the mess, or more politely: diversity, of data that one may find inside, so it may be considered appropriate. :)
  • k.l.k.l. Posts: 106
    edited December 2018
    The term 'smart font' was common in the introduction of OpenType twenty years ago. I don't recall, but it is quite possible that the term was also used around the introduction of GX fonts. SIL use the term also in reference to their Graphite glyph processing, which I should have thought to include in my diagram. DecoType doesn't have a monopoly on the use of the term or on its interpretation.
    The art of referring to far-away precedence when actual precedence is much closer.

    As to GX/AAT, I am aware of all this, the old QuickDraw brochure still sits somewhere on one of my bookshelves. But history does not really help with today's 'define the format' effort. There is no monolithic QuickDraw GX plus TrueType GX any more (where outline description, outline variation, line layout etc are part and parcel), as opposed to a monolithic OpenType with Microsoft OpenType Layout technology inside (TrueType+ but unfortunately Adobe brought CFF plus some other tables to the table too, when again one term ended up referring to more than just one specific aspect of it). Things are more fragmented now, and separate ingredients need to be told apart in a meaningful way, ideally by category (outline description? outline scaling? outline interpolation/variation? layout technology?), to make an at least halfway precise description possible.

    To allow for more precision, a chart better be structured by way of categories, rather than a list (even if hierarchical):
    carrier format:<br>— sfnt<br>— ?<br>outline data:*<br>— bezier, cubic<br>— bezier, quadratic<br>— ? (cf font format history)<br>outline tables:*<br>— CFF (alternatively: CFF2)<br>— glyf/loca (additionally: -var)<br>— ? (cf font format history)<br>layout tables†:<br>— AAT's tables<br>— ACE's tables<br>— OTL's tables<br>— SIL's tables<br>— ?
    This allows to choose, per each category, without a risk to make or evoke implicit assumptions about any other category.

    * Note how I keep outline data and outline table separate. E.g. URW stored IK, bezier, etc data (almost) the same way. E.g. it has been discussed to store cubic bezier data the same way as quadratic bezier data, in glyf/loca tables.

    † Including glyph substitution and positioning.

    [Now this is completely outside of the scope of the original question.]
  • k.l.k.l. Posts: 106
    edited December 2018
    Fun fact. The alleged earlier uses of ‹smart› – for OT, for GX – do not seem to exist. I re-read the QuickDraw GX brochure of 1992 and could not find a single occurrence. (This brochure is striking in that it lacks the hyperbole that is so typical for Apple PR today.) No occurence in the announcement of and early information on OT either. (OT-related PR repeatedly speaks of ‹Advanced Typography› though.)
  • John HudsonJohn Hudson Posts: 2,955
    edited December 2018
    Some of us were there.

    As I wrote earlier, I don't recall whether the term was used around the time that GX fonts were announced, but by the time OpenType arrived there was a need to distinguish between fonts with glyph processing capabilities (smart) and those without (dumb). This was common parlance when talking with folk in the relevant technical teams at Microsoft and Adobe, and the term is intuitive enough — and non-specific in terms of particular technology — that I've never found anyone to be confused as to what it meant. When SIL announced Graphite at the Unicode conference, they used the term 'a smart font technology' and everyone understood it to refer to parallel Graphite to AAT and OpenType.
  • k.l.k.l. Posts: 106
    edited December 2018
    If you say so.
  • Thomas PhinneyThomas Phinney Posts: 2,732
    edited December 2018
    I think that having “smart fonts” in the titles of talks at both the major type conferences of the time is strong evidence that the terms was in general use in 2002.
    I can second John’s recollection that talking about smart fonts became common lingo during the move to OpenType. Many of us involved in creating and promoting the technology used the phrase on a regular basis. I think it started to come into use about 20 years ago (late 90s) as OpenType started to ramp up.
    The title of my presentation at TypeCon on 13 July 2002 was “Smart fonts are dead! Long live smart fonts!” (subtitle: Why OpenType is succeeding where GX didn’t)
    Paul Nelson’s presentation at ATypI in September 2002 was titled “OpenType and other smart font technologies for multiple scripts.”
    A 2004 “Graphite Overview” presentation by Sharon Correll and Peter Constable, which I have a copy of, talks about “smart font behaviors” in the notes for the title slide.
  • John HudsonJohn Hudson Posts: 2,955
    And here's SIL not only using but defining the term in mid-1996:

    TrueType Open (TTO) is a Microsoft designed extension of the TrueType technology that provides facilities such as contextual substitution and glyph positioning. We use the term “smart font” to describe technologies such as TTO and Apple’s QuickDraw GX fonts because there is the ability to encode information into the font itself that modifies the way each character is displayed based on its context.

    from NRSI Update #1 – July 1996

    I think it is quite possible that SIL personnel first started using the term and the rest of us picked it up from there.
  • k.l.k.l. Posts: 106
    edited December 2018
    Thanks for both of these references! (I was aware of SIL. My hunch was with GX and OT in particular.)
  • Victor GaultneyVictor Gaultney Posts: 7
    edited February 2021
    We in SIL were using the term as early as 1992 specifically to describe the things that GX would allow. It may be that the term came out of discussions with Apple, but I'm not sure.
  • 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.
    Hi John, is this what generally is explained as having a "Postscript flavored" and “Truetype flavored" font? Aside from Opentype features, doesn’t the first have a "OTF" extension and the second a "TTF" one?
  • Technically, a TTF font can have the .otf extension if it has GSUB/GPOS tables. I can't remember why at the moment, but few do in practice.
  • Erwin DenissenErwin Denissen Posts: 291
    edited February 2021
    Hi John, is this what generally is explained as having a "Postscript flavored" and “Truetype flavored" font? Aside from Opentype features, doesn’t the first have a "OTF" extension and the second a "TTF" one?
    The file extension has no meaning; you need to look inside the file to determine what it contains. If you don't believe me, do change the file extension from an OpenType font file that contains CFF based outlines from .otf to .ttf.
    It remains an OpenType font with CFF based outlines, but you can still install it in Windows.
  • John HudsonJohn Hudson Posts: 2,955
    Hi John, is this what generally is explained as having a "Postscript flavored" and “Truetype flavored" font?

    Yes, although technically CFF is not actually PostScript in the sense that Type 1 fonts were.

    Aside from Opentype features, doesn’t the first have a "OTF" extension and the second a "TTF" one?
    That’s just a convention, and one that mainly exists so that TTF OpenType fonts could be backwards compatible with older versions operating systems that didn’t recognise the .otf extension. There isn’t really a need for the convention any more.

  • Hi John, is this what generally is explained as having a "Postscript flavored" and “Truetype flavored" font?

    Yes, although technically CFF is not actually PostScript in the sense that Type 1 fonts were.

    Aside from Opentype features, doesn’t the first have a "OTF" extension and the second a "TTF" one?
    That’s just a convention, and one that mainly exists so that TTF OpenType fonts could be backwards compatible with older versions operating systems that didn’t recognise the .otf extension. There isn’t really a need for the convention any more.

    Thanks! So the first and foremost difference comes from outlines description, right? Which are either TT curves or PS curves. And secondarily, whether the font has Opentype features or not does not affect the format per se, right?
    As far as the convention goes, technically a font could be recognized by older OSs by merely changing the extension at desktop level?
  • Hi John, is this what generally is explained as having a "Postscript flavored" and “Truetype flavored" font? Aside from Opentype features, doesn’t the first have a "OTF" extension and the second a "TTF" one?
    The file extension has no meaning; you need to look inside the file to determine what it contains. If you don't believe me, do change the file extension from an OpenType font file that contains CFF based outlines from .otf to .ttf.
    It remains an OpenType font with CFF based outlines, but you can still install it in Windows.
    I see Erwin already replied, thanks. So basically the extension change works in similar way as some "video container" formats do?
Sign In or Register to comment.