GNU TeXmacsUser manualReferenceAboutEnglish
Emulated (poor man's) fonts

1.Introduction

An emulated font is a wrapper around a base font which modifies the appearance of its glyphs: it makes them bolder, slanted, wider, smaller, hollow, irregular or blurred. The implementations are the files Graphics/Fonts/poor_*.cpp; the constructors are declared in

Graphics/Fonts/font.hpp

:

font poor_rubber_font (font base);
font poor_smallcaps_font (font base);
font poor_italic_font (font base, double slant);
font poor_stretched_font (font base, double zoomx, double zoomy);
font poor_extended_font (font base, double factor, double lw);
font poor_extended_font (font base, double factor);
font poor_mono_font (font base, double lw, double phw);
font poor_bold_font (font base, double lofat, double upfat);
font poor_bold_font (font base);
font poor_bbb_font (font base, double penw, double penh, double fatw);
font poor_bbb_font (font base);
font poor_distorted_font (font base, tree kind);
font poor_effected_font (font base, tree kind);

Emulated fonts are used in three situations:

  1. Automatically, when the font database has no font for the requested series, shape or variant (missing bold, italic, small capitals or blackboard bold), see below.

  2. By smart fonts, for particular characters: bold wide accents, double struck letters, extensible delimiters.

  3. Explicitly, through the font-effects environment variable (see font effects).

2.Common structure

All emulated fonts follow the same pattern. Let us take poor_italic_font_rep as an example.

Drawing through transformed bitmap tables works on any renderer, but on printers it would produce bitmap (Type 3) fonts. Several emulations therefore have a separate printer path which keeps the output vectorial:

poor_italic_font_rep, poor_stretched_font_rep

On printers (!ren->is_screen), install a transformation (slanting resp. scaling) with ren->set_transformation, draw the base font, and reset the transformation. poor_stretched_font_rep also falls back on this method on the screen when the base font has no glyph tables.

poor_mono_font_rep

Always draws the base font, glyph by glyph, centered in a cell of width wquad; glyphs which are too wide are horizontally compressed with a scaling transformation.

poor_bold_font_rep

On printers, draws the base glyph nine times with small horizontal offsets (and, for characters which need extra width, from a horizontally stretched base font with a slight vertical slope), which simulates a thicker pen.

The other emulations (poor_bbb_font_rep, poor_extended_font_rep, poor_distorted_font_rep, poor_effected_font_rep) always draw bitmaps.

3.Catalogue

poor_bold_font (base, lofat, upfat)

Emboldening by bolden. lofat and upfat are the extra pen widths for lower and upper case letters, as fractions of the design size wfn; the version without parameters uses wline/wfn. A small table (get_bold_multiplier) makes wide letters such as M and W gain more width than the others.

poor_italic_font (base, slant)

Slanting by slanted. The automatic emulation uses the slant 0.25001 on a font compressed horizontally by \(5 / 6\); this precise value is recognized by concat_math (

Typeset/Concat/concat_math.cpp

) when positioning scripts.

poor_smallcaps_font (base)

Not a bitmap transformation but a small dispatcher, similar to a smart font: runs of lower case characters (uni_upcase_char differs) are upcased and drawn with a magnified version of the base font, whose horizontal and vertical factors are derived from the ratio of the heights of x and X.

poor_bbb_font (base, penw, penh, fatw)

Blackboard bold (“double struck”) letters built by make_bbb, which doubles the strokes; the pen dimensions and the extra width are fractions of wfn.

poor_stretched_font (base, zoomx, zoomy)

Anisotropic magnification. Since fonts can be magnified isotropically, the constructor reduces to base->magnify (zoomx) followed by a vertical stretching by zoomy/zoomx, and returns the base font if no stretching is needed. This is also the default font_rep::poor_magnify.

poor_extended_font (base, factor, lw)

Horizontal extension or condensation which, unlike a plain stretching, preserves the width of vertical strokes (extended, widen). The two argument version measures the stroke width lw from the glyphs o and O.

poor_mono_font (base, lw, phw)

A monospaced version of a proportional font: every character occupies lw times the quad width of the base font, and characters wider than phw quads are compressed.

poor_distorted_font (base, kind)

Random distortions of the glyphs (distorted in

Graphics/Bitmap_fonts/glyph_distorted.cpp

); kind is a tuple (degraded threshold frequency), (distorted strength frequency) or (gnawed strength frequency).

poor_effected_font (base, kind)

Graphical effects applied to the glyphs (

glyph_effected.cpp

). Currently only (blurred radius [dx dy]) is recognized: it is translated into a Gaussian blur effect (EFF_BLUR, EFF_GAUSSIAN), optionally moved (EFF_MOVE).

poor_rubber_font (base)

Extensible delimiters and big operators for Unicode fonts without such glyphs; see below.

Two related wrappers are not emulations of a variant but are used by the font effects: recolored_font (base, kind) draws the base font with the color kind (it changes the pencil of the renderer and restores it afterwards), and superposed_font (fns, ref) draws all fonts of fns on top of each other, taking metrics and glyphs from fns[ref] (the ink boxes are merged).

4.Emulation of missing series and shapes

The automatic emulation is decided during the font selection, in find_closest (

Graphics/Fonts/font_translate.cpp

, see also the chapter on font selection). After finding the closest physical font, it compares the requested logical features with the features of the font which was found (both those declared in the database and those guessed from its name). If a feature was requested but is not present, a suffix is appended to the name which is returned:

outline (blackboard bold) missing

The variant gets the suffix -poorbbb.

bold missing

The series gets the suffix -poorbf.

smallcaps missing

The shape gets the suffix -poorsc.

italic or oblique missing

The shape gets the suffix -poorit.

closest_font then calls find_font (family, variant, series, shape, sz, dpi) (

Graphics/Fonts/find_font.cpp

), which recognizes these suffixes, recursively finds the font without the suffix, and wraps it:

if (ends (shape, "-poorit")) {
  string shape2= shape (0, N(shape) - 7);
  font fn= find_font (family, variant, series, shape2, sz, dpi);
  if (!is_nil (fn)) {
    font nafn= fn->magnify (5.0/6.0, 1.0);
    font itfn= poor_italic_font (nafn, 0.25001);
    // NOTE: precise value 0.25001 also used in 'concat_math'
    font::instances (s)= (pointer) itfn.rep;
    return itfn;
  }
}
else if (ends (shape, "-poorsc")) …       // poor_smallcaps_font (fn)
else if (ends (series, "-poorbf")) …      // poor_bold_font (fn)
else if (ends (variant, "-poorbbb")) …    // poor_bbb_font (fn)

Since only one suffix is handled per call and the recursive call handles the next one, combinations such as a bold italic emulation of a regular font work naturally. Because smart fonts obtain all their subfonts through closest_font, the emulation also applies to the mathematical alphabets: if a family has no outline variant, the bbb subfont of the smart font is an emulated blackboard bold version of the family.

5.Emulated subfonts inside smart fonts

Besides the automatic emulation, smart fonts create emulated subfonts directly in smart_font_rep::initialize_font:

6.Extensible delimiters: poor_rubber_font

Mathematical typesetting needs delimiters of arbitrary size (<left-(-n>, <mid-|-n>, …) and big operators (<big-sum-1>, <big-sum-2>). Ordinary Unicode text fonts provide none of them. poor_rubber_font (base) builds them from the ordinary glyphs. A font with a MATH table does not go through this emulation: its make_rubber_font returns a rubber_unicode_font which uses the size variants and the assemblies of the table, so that the poor rubber font now only serves the fonts which have none.

The global has_poor_rubber (in

Graphics/Fonts/font.cpp

, true by default) enables this mechanism; use_poor_rubber (fn) is consulted by the typesetter (

Typeset/Concat/concat_post.cpp

), which always creates a delimiter box for such fonts, even for small delimiters.

7.The error font

error_font (fn) (

Graphics/Fonts/font.cpp

) is the last resort of every smart font. It claims to support every string, measures it with fn and draws it in red with fn. The error font of a smart font is based on the sans serif variant of the roman family. Note that error_font_rep::draw_fixed sets the pencil to red without restoring it.

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