![]() |
TeX fonts: pitfalls and known bugs | ![]() |
The TeX helper programs and font directories are detected only when the home directory is set up. After installing or removing a TeX distribution, reset the settings (texmacs -setup) before expecting fonts to be generated, see finding and generating TeX font files.
Failures are remembered in $TEXMACS_HOME_PATH/fonts/error. A font which could not be generated once is never tried again until this directory is emptied (-delete-font-cache, an upgrade, or a change in the type1 and truetype font directories). A PK marker is written even when generation is disabled, so that enabling a generator later does not help either.
With a Type 1 substitute, the glyphs come from the .pfb file but the metrics, ligatures and kerning come from the .tfm file. The two must belong to the same font; a .pfb of another design size is scaled, while the metric of the requested size is used.
When load_tex finds neither the requested font nor ecrm at the same size, it ends with FAILED, which aborts the current action (see fatal errors).
TeX fonts have at most 256 characters; anything else is rendered by the smart and virtual font layers on top of them.
The following problems were found while writing this chapter; they are reported from reading the code, not from runtime tests.
Positions and drawing disagree on final kerning instructions. In tex_font_metric_rep::execute, which is used for drawing, a final instruction (skip byte 128 or more) is still applied if it matches the next character, as in TeX. In get_xpositions, the stop test comes before the match test (
Plugins/Metafont/load_tfm.cpp:264
), so a matching final instruction is ignored. The positions computed for selections and the cursor can then differ from what is drawn, by the amount of that kern. The commented-out code at line 148 shows that execute once had the same order and was corrected, but get_xpositions was not.
Ligatures which keep one of the two characters. For the ligature operations which keep only the left or only the right character (operation bytes 1, 2 and their variants with \(a > 0\)), the stack manipulation in execute (load_tfm.cpp:181-183) and in get_xpositions (line 272) seems to put the kept character on the wrong side of the ligature: the left character is pushed back when the right one should be kept, and conversely. Simple ligatures (fi, ff, --, …) are not affected. Not verified on a font which uses these operations.
Valid PK files rejected. The flag byte cases 5 and 6 (extended short format with a packet length of 65536 or more) are valid PK characters, but pk_loader::load_pk treats them as a loss of synchronization and fails (load_pk.cpp:335-343). Only very large characters are concerned.
Unchecked input in the .tfm decoder. load_tfm ignores the result of load_string (
load_tfm.cpp:386
) and the parse helpers of
Data/String/analyze.cpp
do not check the string length. The consistency test on lf catches most corrupted files, but an empty or truncated file is read past its end first. Likewise tag (c) and rem (c) (lines 81-82) do not check that c lies in \([\operatorname{bc}, \operatorname{ec}]\), unlike the other accessors.
Wrong destination of maketfm and makepk. The Windows generators are given the destination get_env("$TEXMACS_HOME_PATH") (in
tex_files.cpp:147
, 180 and 185). The environment variable is called TEXMACS_HOME_PATH, without the dollar sign, so the result is empty and the files are written to \fonts\tfm and \fonts\pk at the root of the current drive, outside the search path.
Inter-sentence space cannot stretch. In the constructors of tex_font_rep and tex_rubber_font_rep (tex_font.cpp:130-131, tex_rubber_font.cpp:82-83), extra->min is halved and then extra->max is set to twice the halved minimum, that is (up to rounding) to the default value, so the extra space may shrink but never stretch. Doubling the default was probably meant.
Font names do not identify the font. The resource names of tex_font and its variants (
tex_font.cpp:1110
and following) do not contain the fall-back design size dsize, and the name of tex_rubber_font (
tex_rubber_font.cpp:108
) does not contain the translator. Two requests which differ only in these arguments share the font which was created first.
Missing glyphs in the metric table. tfm_font_metric_rep::get (
tex_font.cpp:1086
) uses the glyph of a character to compute its ink box without checking that it exists. Characters of the .tfm range which have no glyph in the PK file give a nil glyph. The current callers only ask for characters returned by index_glyph, which checks this, so the problem is latent.
Joining of extensible pieces disabled under Qt. The adjustment of the joining rows of extensible pieces after shrinking (Graphics/Bitmap_fonts/glyph_shrink.cpp:235-240) is compiled only without QTTEXMACS, although rubber_fix still marks the pieces in all builds.
Dead and stale code. In try_pk (
load_tex.cpp:207
), the test font_glyphs::instances->contains (tt_name) can never succeed, because tt_font_glyphs registers its tables under another name; the function works because tt_font_glyphs itself returns the cached instance. The comment we need pfbtopfa which excludes Type 1 embedding in PostScript on Windows (
Graphics/Renderer/printer.cpp:490
) is stale: the conversion is done by the internal pfb_to_pfa.