Freigeben über


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

  • Anonymous
    December 01, 2009
    The comment has been removed

  • Anonymous
    December 02, 2009
    The comment has been removed

  • Anonymous
    December 02, 2009
    Thanks Koby and Adam. I'll fix these errors in the post

  • Anonymous
    December 05, 2009
    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.)

  • Anonymous
    December 06, 2009
    The comment has been removed

  • Anonymous
    December 20, 2009
    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:)

  • Anonymous
    January 01, 2010
    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 :-)

  • Anonymous
    June 04, 2010
    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.

  • Anonymous
    June 04, 2010
    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.

  • Anonymous
    June 05, 2010
    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.

  • Anonymous
    June 10, 2010
    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 www.typophile.com/.../71171 for more details.

  • Anonymous
    June 10, 2010
    The comment has been removed

  • Anonymous
    June 11, 2010
    The comment has been removed

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