GNU TeXmacsUser manualReferenceAboutEnglish
Extending, debugging and pitfalls

1.Adding a new virtual glyph

Suppose that a symbol <foo> is drawn in red although it could be built from other symbols. No recompilation is needed for this, only a definition in a .vfn file.

  1. Choose the file. If the symbol should be drawn in the style of the current text font, from the glyphs of that font, put it in the appropriate emu-*.vfn file (relations in emu-relations.vfn, arrows in emu-arrows.vfn, and so on); these fonts are used in extend mode on top of the main font and of emu-fundamental, so the definition can use all symbols of the main font and all the building blocks of emu-fundamental.vfn. If the symbol is a traditional combination which should work with any font, put it in one of the tradi-*.vfn files; these are built on the smart font itself and are only tried after all physical fonts.

  2. Write the definition, as a new entry (foo expression). Use names of more than one character. Prefer the operators which can be drawn as vector graphics (see the reference); use bitmap explicitly when a vector rendering would be wrong. When the definition depends on peculiarities of particular fonts, guard the alternatives with or and font, as in emu-fundamental.vfn:

    (minus* (or (font (scale (hor-crop _) (hor-crop +) 1 *)
                      Baskerville meyne_textur Papyrus)
                (scale - + 1 *)))
  3. Test the symbol with several main fonts, at several magnifications, in text and in mathematics, both on the screen and in a PDF export (the screen uses the bitmap path, printing the vector path). Since translators and fonts are cached, restart TeXmacs after modifying a .vfn file. A personal copy of a file in $TEXMACS_HOME_PATH/fonts/virtual overrides the system one, which is convenient for experiments.

A new .vfn file is not used automatically: the list of emulation fonts is hard-coded in emu_font_names and the list of traditional fonts in initialize_virtual, both in

Graphics/Fonts/smart_font.cpp

. The order of these lists is the order in which the files are searched.

2.Extending the smart font

2.1.A new fallback or rewriting rule

To render a class of characters in a new way:

  1. If the subfont needs the characters in another encoding, add a constant REWRITE_NAME and a case in the static function rewrite.

  2. Choose a specification tree for the subfont, for instance ("my-kind" parameters), and add a branch to smart_font_rep::initialize_font which creates the font. Use smart_font_bis for a variant of the same family, closest_font together with adjusted_dpi for another family, and wrap the result with adjust_subfont if it is not a smart font, so that the horizontal resolution is respected.

  3. Add a rule at the right place of smart_font_rep::resolve (string c) or of resolve (c, fam, attempt), which registers the decision with sm->add_font (key, rewr) and sm->add_char (key, c). Check that the subfont supports the (rewritten) character before registering it, otherwise the character will be invisible rather than red.

The decision must only depend on the family, variant, series and shape of the smart font and on the character, never on its size or resolution, since the smart map is shared by all sizes.

2.2.A new Unicode range

Ranges are defined in get_unicode_range (int code). A new range name can then be used in conditional family entries (myrange=Some Font) and is used automatically in the attempts \(k > 1\), which request the variant variant-myrange from the font database; for this to be useful, the font database must know which fonts cover the range (see the font selection).

3.Adding a new emulation

To emulate a variant which the font database may lack (for instance a condensed shape), proceed as follows:

  1. Implement the emulated font, following the pattern of the existing ones: a font_rep subclass with a base font, transformed metrics in get_extents and get_xpositions, transformed glyph tables in index_glyph and get_glyph, a draw_fixed which draws through ren->draw on the screen and, if possible, through renderer transformations on printers, a magnify and a constructor function with a unique resource name. Declare it in

    Graphics/Fonts/font.hpp

    and add the file to the build.

  2. In find_closest (

    Graphics/Fonts/font_translate.cpp

    ), append a new suffix (like -poorbf) to the series, shape or variant when the requested logical feature is not provided by the font which was found.

  3. In find_font (family, variant, series, shape, sz, dpi) (

    Graphics/Fonts/find_font.cpp

    ), recognize the suffix, find the font without it, wrap it with the new emulation, and store the result in font::instances under the full name.

  4. If the emulation should also be available on demand, add an effect to apply_effects (see font effects).

4.Debugging

Red symbols

A symbol drawn in red went through the whole resolution algorithm without finding a font: it is rendered by the error font. Check that the name of the symbol is right, that some installed font has it (the font database must be up to date, see font database), or define it virtually.

Which subfont is used?

The font inspector, Tools\(\rightarrow\)Fonts\(\rightarrow\)Font inspector, answers this question without recompiling: it reports the route, the subfont, the file and the rewriting of the character at the cursor, read from the smart map (smart_font_debug_info), and can colour every glyph by its route (debug switch fonts) or list all the characters of a document by route in a font report; see inspecting the font system. For finer questions,

smart_font.cpp

contains many commented out traces, such as //cout << "Found " << c << " in " … in resolve and //cout << "Font " << nr … at the end of initialize_font. Enabling them temporarily is the fastest way to understand a resolution. Remember that decisions are cached in the smart map for the whole session.

Debug output

Font related messages are written to the debug_fonts stream (channel debug-fonts, visible in the debugging console). The loading of encodings and virtual fonts is reported when the std debug flag is set, for instance with (debug-set "std" #t).

Character tables

build-character-table in

progs/fonts/font-sample.scm

builds, as Scheme markup, a table with all characters between two code points, for instance (insert (stree->tree (build-character-table #x2190 #x21FF))). Inserting such tables with various values of font shows at a glance which characters are native, emulated or missing.

Comparing with the old mechanism

Switching off the preference "new style fonts" makes smart_font fall back on the rule based find_font. Similarly, (set-hand-tuned-math-fonts #f) typesets the fonts which have both hand-tuned tables and a MATH table (TeX Gyre, Stix) from their table only.

Missing glyph bitmaps

The warning no bitmap available for … comes from the default font_rep::get_glyph: a virtual or emulated font was built on a font which cannot export glyphs. Setting get_glyph_fatal in

Graphics/Fonts/font.cpp

turns these warnings into failures, which gives a backtrace.

Fatal errors

"invalid virtual character" (with the offending tree) means that compile_bis met an unknown construct; "bad virtual font format" that a .vfn file does not start with virtual-font; "substitution font loop detected" that initialize_font produced the smart font itself as a subfont.

5.Pitfalls

6.Known issues in the code

The following problems were noticed in the code while writing this documentation:

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