![]() |
TeX fonts: Metafont, PK, TFM and Type 1 | ![]() |
The fonts which TeXmacs uses by default for text and mathematics (the European Computer Modern fonts ec*, the Computer Modern fonts cm*, the AMS symbol fonts, the cmex rubber characters, and so on) are TeX fonts. A TeX font consists of a font metric file (.tfm) which gives the dimensions, ligatures, kerning and extensible recipes of at most 256 characters, and of the glyphs themselves, which come either from a Type 1 outline font (.pfb) or from a bitmap font in PK format (.dpipk), possibly generated on the fly by Metafont.
This chapter describes how TeXmacs finds, generates, decodes, typesets and outputs such fonts. The general font model (the class font_rep, font names and font trees) is explained in TeXmacs fonts; how a logical font request is mapped to a font tree in the font database and font selection; how missing characters are emulated and how fonts are combined in smart, virtual and emulated fonts; and how the renderers draw glyphs in the renderer interface. These subjects are only summarized here.
All file names are relative to
src/src/
unless stated otherwise.
A TeX font is requested by a font tree such as (ec ecrm 10 600), which the font rules of
TeXmacs/progs/fonts/fonts-ec.scm
(relative to
src/
) produce for the roman family, and which find_font (
Graphics/Fonts/find_font.cpp
) turns into a call of one of the constructors tex_font, tex_ec_font, tex_cm_font, tex_la_font, tex_gr_font, tex_adobe_font, tex_rubber_font or tex_dummy_rubber_font. From there, the data flow is:
font tree (ec ecrm 10 600)
|
v
tex_font_rep (Plugins/Metafont/tex_font.cpp)
|-- load_tex (family, size, dpi, dsize) (load_tex.cpp)
| |-- metrics: load_tex_tfm -> resolve_tex ("ecrm10.tfm")
| | -> load_tfm -> tex_font_metric
| |-- glyphs: load_tex_pk -> Type 1 file found?
| yes: tt_font_glyphs (FreeType rasterizes the .pfb)
| no: resolve_tex ("ecrm10.600pk"), mktexpk if
| needed -> pk_loader (lazy unpacking)
|
|-- screen: renderer shrinks the glyph bitmap, caches the pixmap
|-- PDF: Type 1 embedded natively, PK glyphs as Type 3 fonts
|-- PS: Type 1 embedded as PFA, PK glyphs as bitmap fonts |
Locating files goes through a search path built at startup from the settings of $TEXMACS_HOME_PATH/system/settings.scm, through the TeX utility kpsewhich if it is available, and through the persistent cache font_cache.scm. Files which could not be found or generated are remembered as empty marker files in $TEXMACS_HOME_PATH/fonts/error, so that the (slow) generation is not attempted again.
TeXmacs ships its own copies of the most common TeX fonts in $TEXMACS_PATH/fonts/tfm and $TEXMACS_PATH/fonts/type1 (subdirectories ec, la, math, ams, adobe, tc, cbgreek, public, …), so that in the usual case no TeX installation is needed and no font is generated. The metrics are shipped at many sizes (for instance about 250 .tfm files for the ec families) and the outlines at the design sizes only (45 .pfb files for ec); tt_find_name picks the outline of a nearby design size, so that for these families the PK path is never taken.
Plugins/Metafont/tex_files.hpp,
tex_files.cpp
Search paths for .tfm, .pk and .pfb files (reset_tfm_path, reset_pk_path, reset_pfb_path), lookup (resolve_tex, exists_in_tex, kpsewhich, kpsepath) and generation (make_tex_tfm, make_tex_pk).
Plugins/Metafont/tex_init.cpp
Detection of the TeX helper programs and of the standard TeX font directories at the first run (setup_tex), and initialization of the paths at each run (init_tex).
Plugins/Metafont/load_tex.hpp,
load_tex.cpp
The search for a metric and glyphs of a given family, size and resolution (load_tex, load_tex_tfm, load_tex_pk), including the substitution by Type 1 fonts and the error cache.
Plugins/Metafont/load_tfm.hpp,
load_tfm.cpp
The class tex_font_metric_rep: decoding of .tfm files, the ligature and kerning program, extensible recipes.
Plugins/Metafont/load_pk.hpp,
load_pk.cpp
The pk_loader, which decodes .pk files into glyphs.
Plugins/Metafont/tex_font.cpp
The class tex_font_rep and its six variants, and tfm_font_metric.
Plugins/Metafont/tex_rubber_font.cpp
Rubber (extensible) characters from TeX fonts: tex_rubber_font_rep and tex_dummy_rubber_font_rep.
Plugins/Metafont/adjust_cmr.cpp
Hand-tuned script and accent position corrections for the Computer Modern and related families.
Graphics/Bitmap_fonts/bitmap_font.hpp,
glyph.cpp,
bitmap_font.cpp,
glyph_shrink.cpp
The classes glyph, font_metric and font_glyphs, and the shrinking of glyphs for display. The other files of this directory implement glyph transformations, which are described in emulated fonts.
Plugins/Freetype/tt_file.cpp,
tt_face.cpp
Location of .pfb files and their rasterization through FreeType (tt_find_name, tt_font_find, tt_font_glyphs).
Plugins/Pdf/pdf_hummus_renderer.cpp,
Graphics/Renderer/printer.cpp
Embedding of TeX fonts in PDF and PostScript output.
TeXmacs/progs/fonts/fonts-ec.scm,
fonts-composite.scm,
fonts-adobe.scm,
fonts-math.scm
(relative to
src/
) Font rules which map logical font requests to TeX font trees.