GNU TeXmacsUser manualReferenceAboutEnglish
Older composite fonts: compound and math fonts

1.Introduction

Before smart fonts were introduced (2013), the combination of several physical fonts was described explicitly by the rule based font selection (find_font in

Graphics/Fonts/find_font.cpp

and the set-font-rules declarations in progs/fonts/*.scm, see the overview). Three kinds of composite fonts are used there: compound fonts, math fonts and Unicode math fonts. They remain in use for the TeX based fonts, for all fonts when the preference "new style fonts" is off, and inside smart fonts for the historical families (the math subfonts of smart fonts). All of them are static: the mapping from symbols to fonts is given by encoding tables rather than computed from the fonts themselves.

2.Charmaps

A charmap (

Graphics/Fonts/charmap.hpp

) decides which of several fonts renders a symbol, and how the symbol is called in that font:

struct charmap_rep: rep<charmap> {
  int                    fast_map[256];
  hashmap<string,int>    slow_map;
  hashmap<string,string> slow_subst;

  inline virtual int arity () { return 1; }
  inline virtual charmap child (int i) { … }
  inline virtual void lookup (string s, int& ch, string& r) { ch= 0; r= s; }
  void advance (string s, int& pos, string& r, int& ch);
};

lookup returns a font number ch (or -1) and the translated symbol r; results are cached in slow_map and slow_subst, and in fast_map for the one-byte characters which are not translated. advance extracts the longest run of characters with the same font number, concatenating the translated symbols, exactly like smart_font_rep::advance. The concrete charmaps (

Graphics/Fonts/charmap.cpp

) are:

any

Every symbol, unchanged.

ec

One-byte characters and <less>, <gtr>.

la, hangul, oriental

The Unicode ranges U+400–U+4FF, U+AC00–U+D7A3 and U+3000–U+FFFF (range_charmap), for symbols written as <#…>.

any other name

An explicit_charmap based on the translator (encoding file fonts/enc/name.enc or virtual font) of that name: a symbol in the dictionary is replaced by the one-byte string of its code.

load_charmap (def) builds a join_charmap from a list of such names: a symbol goes to the first charmap which accepts it, and the font numbers are offset by the arities of the preceding charmaps.

3.Compound fonts

A compound font is described by the macro (compound (cm1 font1) …), as in

progs/fonts/fonts-composite.scm

:

((modern $v $a $b $s $d)
 (compound (ec (roman $v $a $b $s $d))
           (la (cyrillic $v $a $b $s $d))
           (cmr (tex cmr $s $d))
           …
           (tradi-long (virtual tradi-long $s $d))
           …))

compound_font (def, hzf, vzf) creates a compound_font_rep with the charmap load_charmap of the first elements and an array of subfonts, of which only the first one is created immediately. The others are created in compound_font_rep::advance the first time a run needs them: by virtual_font (this, name, size, dpi, …) for a (virtual name size dpi) specification (the compound font itself is the base, as for the virtual subfonts of smart fonts), and by find_magnified_font otherwise. Measuring and drawing proceed run by run as in smart fonts.

4.Math fonts

math_font (t, base_fn, error_fn, hzf, vzf) (

Graphics/Fonts/math_font.cpp

) implements the (math (math enc fonts…) (rubber enc fonts…) base error) macro (see

progs/fonts/fonts-math.scm

). It holds two translators, math and rubber, loaded from the encodings named by the first elements, and the lists of fonts. A translator code \(c\) designates the font number \(c / 256\) and the character \(c\&255\) in it (encoding files concatenate the encodings of several fonts by blocks of 256). math_font_rep::search_font finds the font and rewrites the symbol:

Fonts given as (virtual name size dpi) are virtual fonts with the math font as base, as for compound fonts. This is how the tradi-* virtual fonts originated.

5.Unicode math fonts

unicode_math_font (up, it, bup, bit, fb) (

Plugins/Freetype/unicode_math_font.cpp

) implements the unimath macro, which combines an upright, an italic, a bold upright and a bold italic Unicode font with a fallback font (

progs/fonts/fonts-math.scm

, rules unicode-math). search_font_sub classifies each symbol once (cached in mapper): single letters go to the italic font, <b-…> symbols to the bold fonts, - and | are rewritten into <minus> and <mid>, big operators are mapped to Unicode symbols, and symbols without a Unicode code point go to the fallback font. Several of these rules were later carried over to the REWRITE_SPECIAL and mathematical rules of smart fonts.

6.Comparison with smart fonts

Static versus dynamic

Composite fonts route symbols with fixed encoding tables; smart fonts ask the fonts whether they supports a symbol and consult the font database.

Eager versus lazy decisions

Charmaps compute the destination of every symbol from the tables; smart fonts resolve characters on demand and share the decisions among all sizes (smart_map).

Common mechanisms

Both cut strings into runs with an advance routine, both use virtual fonts with the composite font itself as base, and both delegate slopes and corrections to the subfont of the first or last run.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".