High Fonts and Math Fonts

Math fonts differ from other fonts not only in their extensive coverage of math operators, symbols, and math alphanumerics, but also in the large number of glyph variants they have to support two sizes of sub/superscripts and many sizes of stretchable characters like parentheses and brackets. Some such glyphs can be many times as high as the normal line height. The name given to fonts that contain glyphs larger than the line height is a “high font”. Fancy fonts like Gabriola have elegant swash variants that look great on wedding invitations and the like. Some of these glyph variants have ascents and descents much bigger than the line height and hence those fonts are also high fonts.


High fonts must be handled in a special way, at least on Windows.  The reason for this dates back to the early 1990s when TrueType fonts were introduced into Windows 3.1. At that time, fonts didn’t have glyphs larger than the line height, so two heights were unified: the first is how big to make the bitmap used to rasterize the glyphs and the second is the line height itself. The corresponding height information is contained in the TEXTMETRIC structure and the line height is given nominally by the sum TEXTMETRIC::tmAscent + TEXTMETRIC::tmDescent. Here tmAscent is the height above the text baseline and tmDescent is the (positive) height below the baseline. One could also add leading, but the sum of the ascent and descent sufficed to determine the height of the rasterization bitmap.


Now consider a high font with its large glyphs. Clearly the bitmap has to have tmAscent and tmDescent large enough for the largest glyph. Accordingly tmAscent and tmDescent can be considerably larger than the ascent and descent for ordinary characters such as A—Z and a—z. When these quantities are used to display a high font, the ordinary characters look very small inside a line that’s much bigger. You can see this by selecting Cambria Math or Gabriola into NotePad. At least up through Windows 7, the system edit control, which is used in NotePad, doesn’t know how to render high fonts correctly. But Word, RichEdit, PowerPoint, and other more sophisticated text programs do know how, namely they use the ascent and descent values provided by the OUTLINETEXTMETRIC structure’s otmAscent and otmDescent.


If you display text using ExtTextOut() using baseline alignment (call SetTextAlign() with TA_BASELINE), you only have to use the OUTLINETEXTMETRIC values. But if you use the default text alignment, TA_TOP, then you need to subtract tmAscent to get to the “top”. Kind of strange, since that may result in a negative y coordinate, but it works fine. RichEdit uses TA_TOP since it used to be faster than TA_BASELINE, although it may not be any longer. Word uses TA_BASELINE.


You may be wondering how to find out if a font is a high font. Officially a font is a high font if bit 7 (0x80) of OUTLINETEXTMETRIC::otmfsSelection is nonzero. This bit is named USE_TYPO_METRICS. Since fonts might not set it when they should, you might also want to conclude that a font is a high font if (unsigned)tm.tmAscent > 2*(otm.otmAscent + otm.otmLineGap).


As a last note, you may wonder how to tell if a font is a math font, since not all high fonts are math fonts. One way is to find out if the font has an OpenType “MATH” table. To do this, call GetFontData(hdc, tagMATH, 0, NULL, 0), where tagMATH is defined by


#define MakeTag(a, b, c, d)        (((d)<<24) | ((c)<<16) | ((b)<<8) | a)

#define tagMATH            MakeTag('M','A','T','H')


If the return value is a positive number, it is the count of bytes in the “MATH” table.


There’s a lot more to a math font than what’s given in this post. An earlier post on High Quality Editing and Display of Mathematical Text in Office 2007 has a section on the math font, although it doesn’t contain the material in the present post. A full specification is available for people interested in developing math fonts.


Thanks to Koby Kahane and Adam Twardoch for helpful comments improving this post.

Comments (14)

  1. Koby Kahane says:

    The link to "High Quality Editing and Display of Mathematical Text in Office 2007" is broken and seems to point to a Microsoft OWA server.

  2. Murray,

    the structure is reasonably documented in the OpenType spec, the "OS/2" table, fsSelection field — which is hosted on the Microsoft Typography website:


    "Bit 7, USE_TYPO_METRICS: If set, it is strongly recommended to use OS/2.sTypoAscender – OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font.

    (Note: Bit 7 was specified in OS/2 table v. 4. If fonts created with an earlier version of the OS/2 table are updated to the current version of the OS/2 table, then, in order to minimize potential reflow of existing documents which use the fonts, the bit would be set only for fonts for which using the OS/2.usWin* metrics for line height would yield significantly inferior results than using the OS/2.sTypo* values. New fonts, however, are not constrained by backward compatibility situations, and so are free to set this bit always.)"

  3. MurrayS3 says:

    Thanks Koby and Adam. I’ll fix these errors in the post

  4. Robert says:

    I found the ..ascent/..descent metrics in OUTLINETEXTMETRIC of limited use as they do not seem to be used consistently by different fonts. In the end, I decided to explicitely measure a number of characters by using GetGlyphOutline.

    (By the way, the links to the TEXTMETRIC and OUTLINETEXTMETRIC structures still seem to point to an Exchange server.)

  5. MurrayS3 says:

    I fixed the links. Thanks. RichEdit only uses OUTLINETEXTMETRIC ascent/descent values for high fonts. Actually measuring the glyph outlines of various characters like x and m is an interesting idea.

  6. Tomas says:

    Can you show us how to access these stretchy glyphs which don’t have assigned unicode character? Is it possible to encode them as surrogate pairs? Can we still use ExtTextOut or similar to print them? Where can I find more info about math table? Sorry for so many questions:)

  7. Nali says:

    Many interesting keywords (commands) for (math-)font formating are available in PowerPoint 2010, Excel 2010, and OneNote 2010 🙂  You can easy switch between regular, italic, bold, bold italic, sans serif, and typewriter symbols.

    Useful commands/macros are:

    Roman symbols                     rm   or   hbox   or   mathnor   and   mathrm (for "Normal Text")

    Italic symbols                         it   or    mathit   or   mit

    Bold symbols                          mathbf

    Bold italic symbols                  bit   or   mathbit

    Sans serif symbols                 mathsf

    Monospace symbols               mathtt

    Script symbols                        mathscr   or   mathcal   or   sA, sa, sB, sb, sC, sc,…, sZ, sz

    Fraktur symbols                      mathfrak   or   fA, fa, fB, fb, fC, fc,…, fZ, fz

    Doubke-Struck symbols        mathbb   or   bA, ba, bB, bb, bC, bc,…, bZ, bz

    Another interesting commands are:    vmatrix,  stackrel,  char,  displaystyle,  textstylescriptstyle,  scriptscriptstyle,  text,  fbox,  mbox,  and also  eqno.  Office 2010 has great support for math 🙂

  8. Nali says:

    On the 28 May 2010, Stix Fonts Version 1.0 was released. Version 1.1, which will include fonts packaged for use with Microsoft Office (2007/2010) applications, is scheduled for release by the end of 2010.

  9. MurrayS says:

    The STIX fonts (see http://stixfonts.org/) have very complete coverage of the Unicode math character repertoire and are based on a Times Roman typeface. It will be really fine when we can use them with the Microsoft Office math facility. Basically they need to be combined into a single font that includes all the math alphanumeric styles and with the various glyph variants accessible via OpenType tables as described in the post blogs.msdn.com/…/special-capabilities-of-a-math-font.aspx.

  10. Nali says:

    Just now, I remembered that also the Asana-Math font (see en.wikipedia.org/…/Asana-Math) is an Opentype mathematical font with advanced layout features and can be used in Office 2007/2010 (only .otf, but not .ttf). It is based on a Palatino typeface.

  11. Khaled Hosny says:

    I'm working on an OpenType MATH enhanced version of STIX, but I cam across several issues with Office 2007 that I'm unable to solve, see http://www.typophile.com/…/71171 for more details.

  12. MurrayS3 says:

    I tried opening Khaled's XITS V3 file (khaledhosny-xits-math-v1.003-0-ge579833.zip) on Windows 7, but got an error message saying the compressed (zipped) folder is invalid. If I can get your XITS font running with RichEdit, maybe I can spot some problems. (Nice RtL name!)

  13. Khaled Hosny says:

    It is a tarred bzip2 archive, I don't think it is supported out of box on Windows, alternatively you can try the zip downloads at the bottom, it gives you a snapshot of the repository, just few extra harmless files than the official releases.

  14. Khaled Hosny says:

    Aha, it seems the zip snapshots are broken, I think you can find some Windows tool that can open bzip2 archives (7zip can, IIRC).

Skip to main content