![]() |
Smart fonts, emulated fonts and virtual fonts | ![]() |
The overview of fonts explains the general philosophy of fonts in TeXmacs: a font is an object which associates a graphical meaning to words, that is to strings of Cork characters and universal symbols like <alpha> or <#2212>. The present chapter describes the layer which makes this philosophy work in practice with real, incomplete physical fonts. It consists of three cooperating mechanisms:
A smart font (smart_font_rep in
Graphics/Fonts/smart_font.cpp
) is the font which the typesetter actually uses when the preference "new style fonts" is on. It is a dispatcher: it cuts each string into runs of characters, finds for every character a subfont which can render it, possibly rewrites the characters into the encoding expected by that subfont, and delegates measuring and drawing. Subfonts are created lazily and the decisions are cached.
A virtual font (virtual_font_rep in
Graphics/Fonts/virtual_font.cpp
) builds new glyphs out of glyphs of a base font, following definitions written in a small Scheme-like language in the files $TEXMACS_PATH/fonts/virtual/*.vfn. Long arrows, negated relations, missing brackets, integrals with several signs or extensible delimiters are all obtained in this way when the physical font does not provide them.
The “poor man's” fonts in Graphics/Fonts/poor_*.cpp synthesize variants which do not exist physically: bold, italic, small capitals, blackboard bold, stretched, extended or condensed, monospaced, distorted or blurred variants of an existing font, as well as extensible delimiters. They are used automatically when the font database does not contain the requested series or shape, and explicitly through the font-effects environment variable.
The three mechanisms are composable: a smart font may have virtual fonts and emulated fonts among its subfonts, a virtual font may be built on top of a smart font or of an emulated font, and the font effects are applied on top of the smart font. All of them are subclasses of the abstract font_rep (see
Graphics/Fonts/font.hpp
and the overview) and are therefore interchangeable from the point of view of the typesetter and of the renderers.
The selection of a physical font from a family name, variant, series and shape (the font database, logical_font, search_font, find_closest and closest_font) is documented separately in the chapter on the font database and font selection. Here we take closest_font as a black box which returns the best available physical font, and we concentrate on what happens around it. The routing of characters is presented from the user's point of view, together with the font inspector, in from markup to glyph and the following pages of the reference chapter; the OpenType math fonts, whose MATH table changes several of the decisions described here, are treated in the chapter OpenType fonts, and presented to users in mathematical fonts.
Physical fonts are always incomplete. A text font usually covers Latin and perhaps Greek and Cyrillic, but not mathematical symbols; a mathematical OpenType font has most symbols but no Chinese characters; few fonts contain bold calligraphic letters, double struck digits or a long <leftrightarrow>. On the other hand, a TeXmacs document is written using a font independent encoding, and the user expects that every symbol is rendered, in a style as close as possible to the chosen font. Smart fonts reconcile these requirements:
Characters missing in the main font are taken from other fonts: explicitly mentioned fonts (the font variable may contain a comma separated list of families, possibly with conditions such as mathlarge=TeX Gyre Pagella,Linux Libertine), and then from progressively less similar fonts found in the font database for the relevant Unicode range.
Fallback fonts are scaled so that their x-height matches the one of the main font (smart_font_rep::adjusted_dpi).
Mathematical conventions are implemented at the font level: in mathematical mode isolated Latin letters are taken from the italic variant of the font, Greek letters are taken from the italic math alphabet if available, Unicode mathematical alphanumeric symbols (U+1D400 and following) are mapped to bold, calligraphic, fraktur or double struck variants of the current family, and so on. When the main font is an OpenType math font without hand-tuned tables, the letters and the Greek are taken from its own mathematical italic alphabet instead, so that its italic corrections and kerns apply.
A smart font whose main font has a MATH table forwards the questions of the typesetter about size variants, accents, extended shapes and feature substitutions to the subfont of the character (get_rubber_variant, get_wide_variant, get_top_accent, is_extended_shape, get_feature_variant, and the height dependent script corrections).
Symbols which no font provides are constructed with virtual fonts or emulated fonts, and only as a last resort drawn in red using the error font. For a main font with a MATH table, an emulation which a PDF export could only hold as a bitmap gives way to the glyph of STIX Two Math, which is shipped with TeXmacs.
The following picture summarizes the objects involved when the typesetter asks the current font to measure or draw a string.
edit_env_rep::update_font (Typeset/Env/env_semantics.cpp)
fn = smart_font (family, variant, series, shape, size, dpi)
fn = feature_font (fn, "ssty", …) in scripts, OpenType math only
fn = apply_features (fn, font-features) -> feature_font
fn = apply_effects (fn, font-effects) -> poor_bold, poor_italic, …
smart_font_rep (one per family/variant/series/shape/size/dpi)
sm : smart_map (shared by all sizes) char -> subfont number
fn : array<font> subfonts, created lazily
fn[0] main font = closest_font (main family, …)
fn[1] error font = error_font (closest_font ("roman", "ss", …))
fn[k] e.g. closest_font (other family or range, …)
smart_font_bis (family, "outline", …) for bbb
virtual_font (this, "tradi-long", …)
virtual_font (main, "emu-arrows", …, true)
poor_bold_font (…), poor_bbb_font (…)
unicode_font ("STIXTwoMath-Regular", …) "shipped-math"
rubber_font (fn[j]) -> poor_rubber_font or MATH |
The rest of this chapter is organized as follows:
Graphics/Fonts/smart_font.cpp
The smart font, the smart_map cache, the rewriting rules, the user entry points smart_font, smart_font_bis and apply_effects, the profile fixes of the OpenType math fonts (profile_fix), and the debugging support of the font inspector (debug_draw, smart_font_debug_info; see inspecting the font system).
Graphics/Fonts/math_font_profiles.cpp,
feature_font.cpp
The profiles of the named OpenType math fonts, and fonts seen through an OpenType substitution feature (feature_font, apply_features); see math font profiles and OpenType features.
Graphics/Fonts/virtual_font.cpp
Virtual fonts: compilation of .vfn definitions into glyphs, metrics and vector drawing.
Graphics/Fonts/virtual_enhance.cpp
adds virtual definitions to an existing font.
Graphics/Fonts/translator.cpp
Loading of .enc encodings and .vfn files into translator objects.
Emulated fonts: poor_bold, poor_italic, poor_smallcaps, poor_bbb, poor_stretched, poor_extended, poor_mono, poor_distorted, poor_effected and poor_rubber, together with
recolored_font.cpp
and
superposed_font.cpp
.
Graphics/Fonts/font.cpp
The base class, the error font and rubber_font.
Graphics/Fonts/compound_font.cpp,
math_font.cpp,
charmap.cpp
Older composite fonts used by the rule based font selection.
Graphics/Bitmap_fonts/
Glyph (bitmap) manipulation routines used by virtual and emulated fonts (join, hor_flip, bolden, slanted, make_bbb, …).
The virtual font definitions tradi-*.vfn and emu-*.vfn.