GNU TeXmacsUser manualReferenceAboutEnglish
Smart fonts, emulated fonts and virtual fonts

1.Introduction

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:

Smart fonts

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.

Virtual fonts

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.

Emulated fonts

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.

2.Why smart 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:

3.Overview of the layers

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:

4.Source files

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.

Graphics/Fonts/poor_*.cpp

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, …).

$TEXMACS_PATH/fonts/virtual/

The virtual font definitions tradi-*.vfn and emu-*.vfn.

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".