![]() |
Font effects | ![]() |
The environment variable font-effects (C++ name FONT_EFFECTS, declared in
Data/Drd/vars.cpp
, default value the empty string in
Typeset/Env/env_default.cpp
) contains a comma separated list of effects of the form effect=value. It belongs to the font variables (Env_Font), so changing it triggers edit_env_rep::update_font, which applies the effects on top of the smart font:
string eff= get_string (FONT_EFFECTS);
if (N(eff) != 0) fn= apply_effects (fn, eff); |
The effects are therefore applied to the whole smart font, including all its subfonts (fallback fonts, virtual and emulated symbols). Just before the effects, the OpenType features of font-features, another variable of type Env_Font, are applied in the same way (apply_features), so that an effect such as bold=… emboldens the substituted glyphs; see OpenType features. The user level documentation of the variable is in the font environment variables.
At the markup level, the effects are used by the macros of
packages/standard/std-markup.ts
, which append an effect to the current list with add-font-effect:
<assign|add-font-effect|<macro|prop|val|body|<with|font-effects|<merge|<value|font-effects>|<if|<equal|<value|font-effects>|>||,>|<arg|prop>|=|<arg|val>>|<arg|body>>>> <assign|embold|<macro|body|<add-font-effect|bold|<value|embold-strength>|<arg|body>>>> |
The macros embold, embbb, slanted, hmagnified, vmagnified, condensed, extended, monospaced, degraded, distorted, gnawed, blurred and enhanced take their parameters from style variables such as embold-strength (2), slanted-slope (0.25) or condensed-factor (0.8). Most of them are available from the Font effects submenus of the text properties menus (text-font-effects-menu in
progs/generic/format-menu.scm
).
Splits effects at the commas and each item at the equal sign, and successively wraps fn with the corresponding emulated font. Unknown effects and items without a value are ignored. The order of the list is the order of application.
The recognized effects, with the clamping of their values, are (
Graphics/Fonts/smart_font.cpp
):
\(e \in [1, 5]\). poor_bold_font (fn, fat, fat) with \(\operatorname{fat}= (e - 1) \cdot \operatorname{wline}/\operatorname{wfn}\).
\(e \in [1, 5]\). poor_bbb_font (fn, penw, penh, fat) with pen dimensions \(\operatorname{wline}/\operatorname{wfn}\) and \(\operatorname{fat}= (e - 1) \cdot \operatorname{wline}/\operatorname{wfn}\).
\(s \in [- 2, 2]\). poor_italic_font (fn, s).
\(f \in [0.1, 10]\). poor_stretched_font horizontally or vertically.
\(f \in [0.1, 10]\). poor_extended_font (fn, f) (stroke preserving; used for both condensed and extended). A vextended effect is present in the code but commented out, so it is currently ignored.
\(f \in [0.1, 10]\). poor_mono_font (fn, f, f).
Defaults 0.666 and 1.0, clamped to \([0.01, 0.99]\) and \([0.1, 10]\). poor_distorted_font with kind (degraded …).
Defaults 1.0 and 1.0, strength clamped to \([0.1, 9.9]\). poor_distorted_font with kind (distorted …) resp. (gnawed …).
A length; if its unit is pt it is divided by the font size, otherwise the number is taken as a fraction of the font size; clamped to \([0.01, 1]\). poor_effected_font with kind (blurred r).
An engraved look: two blurred copies of the font, shifted diagonally in opposite directions and recolored with the colors shadow (default black) and sunny (default white), are superposed under the original font:
font fn1= recolored_font (blurred1, shadow);
…
font fn2= recolored_font (blurred2, sunny);
array<font> a; a << fn1 << fn2 << fn;
fn= superposed_font (a, 2); |
Parameters inside one effect are separated by semicolons, since the comma separates the effects. The values are parsed by the static helpers get_double_parameter, get_string_parameter and get_length_parameter.
Each effect font implements magnify by applying the same effect to the magnified base font, so that the effects survive the zooming in font_rep::draw. The parameters are expressed relative to the design size (wfn), hence the appearance does not depend on the zoom.
As explained for emulated fonts, slanting, stretching and monospacing are drawn with renderer transformations on printers, whereas bold, blackboard bold, extended, distorted and blurred glyphs are bitmaps. On the screen all of them use transformed glyph tables through index_glyph, except monospacing.
Implement the glyph transformation, typically as a function on glyph and on font_glyphs (and on font_metric if the metrics change) in
Graphics/Bitmap_fonts/
, and declare it in
bitmap_font.hpp
.
Either add a new kind to an existing wrapper (poor_distorted_font_rep and poor_effected_font_rep take a tree describing the effect, so adding a new tuple there is the least intrusive way), or write a new poor_name.cpp by copying the simplest existing wrapper (
poor_distorted.cpp
): delegate everything to base, transform the tables in index_glyph and get_glyph, and draw with ren->draw (c, fng, x, y). Give the font a unique resource name which includes all parameters, and implement magnify. Declare the constructor in
Graphics/Fonts/font.hpp
.
Add a branch to apply_effects, with clamping of the parameters.
Optionally add a macro in
std-markup.ts
based on add-font-effect, an entry in text-font-effects-menu, and document the effect in
doc/devel/format/environment/env-font.en.tm
.