Typeface selection scheme

A typeface selection scheme defines a set of rules that the TopLeaf typesetting engine uses when rendering a character in the context of a mapping. When a mapping is processed, TopLeaf first checks if the mapping references a typeface selection scheme rather than an explicit typeface. If a scheme is used the composition engine applies its selection rules to determine the typeface to use.

Advantages of a typeface selection scheme include:

  • You can define a set of generic font families. By declaring mappings that reference selection schemes, rather than specific typefaces, you can create a set of mappings that are both publication and system independent. Migrating a set of mappings to a different publication (or platform) is simplified — you only need to declare or adjust the selection schemes.

  • The typeface selected can depend on the data being rendered. For example, this allows a document containing multiple languages to use a different font for each language.

Typeface selection schemes are either embedded in the mappings.tlx file or in a separate file called scheme.cfg. Schemes stored in the mappings file only apply to that stylesheet. Schemes in a separate file apply to all stylesheets in folders below the containing folder.

Schemes are stored in an XML element called <schemes> which contains one or more <scheme> elements. Each <scheme> contains one or more <typeface> elements specifying typefaces that may be chosen when this scheme is in effect.

The Mapping Editor contains an option for creating and modifying the selection schemes. The scheme editor will modify the embedded schemes if they are found, or look for an external file if not. If neither are found a new set of embedded schemes will be created.

[Note] Note

Previous versions allowed the scheme.cfg file to exist in the same folder as the mappings.tlx file. When the scheme editor is used to modify this configuration it will embed the schemes in the stylesheet file and remove the external file.

Operation

Each selection scheme consists of one or more typeface selection rules. TopLeaf tests each selection rule in a scheme in the order they are specified. The first one that contains a glyph for the character being rendered is chosen. If none of the typefaces in the scheme contain a glyph for the character, TopLeaf will attempt to render the character by using the character map.

A condition can be associated with each typeface selection rule, so that it is only available for selection for a certain language, locale and/or specific character codes.

The value of language and locale can be set by the <text-properties/> command or by the value of the xml:lang attribute when the <topleaf-properties/> command indicates that this should be honoured. The language value is always lower-case, so you should only use lower-case values in selection rules. Case is ignored when selecting locale values.

To limit the selection rule to specific character codes, add a range attribute whose value is a comma-separated list of hexadecimal value ranges. Each range can be either a single value or a pair of values separated by “-”.

When several lang, locale and/or range attributes are present, all conditions must be satisfied for the typeface to be included.

[Warning] Warning

Although the scheme file uses a syntax that is compatible with XML, it is not read using a full XML parser. Do not put anything other than tags and comments in this file, and only use ASCII characters.

Example

The following is an example scheme.cfg file:

<schemes>

  <scheme name="Titles">
    <typeface name="Arial"/>
    <typeface name="Arial Unicode MS"/>
  </scheme>

  <scheme name="Body">
    <typeface name="Fraktur"  lang="de"/>
    <typeface name="MS Song"  locale="zh-CN" />
    <typeface name="UnBatang" range="AC00-D7A3,1100-11FF"/>
    <typeface name="Times New Roman"/>
  </scheme>

  <scheme name="Arial" >
    <typeface name="Times New Roman" range="0600-06FF" />
    <typeface name="Times New Roman" range="0750-077F" />
    <typeface name="Times New Roman" range="FB50-FDFF" />
    <typeface name="Times New Roman" range="FE70-FEFE" />
    <typeface name="Arial" />
 </scheme>
</schemes>

This defines three schemes. The first one, called Titles, specifies two typefaces. When rendering a character, TopLeaf will first attempt to find a glyph in the Arial typeface. If no glyph is found, it will then look for one in the Arial Unicode MS typeface.

The second scheme specifies typefaces that are only available under certain conditions. The Fraktur typeface can only be selected when the current language is German. The MS Song typeface can only be used when the current language locale is simplified Chinese. The UnBatang typeface will only be used for rendering characters in the ranges U+AC00 to U+D7A3 and U+1100 to U+11FF inclusive.

The third scheme, called Arial, sources all Arabic characters (including all presentational forms) from the Times New Roman typeface, and all other glyphs from the Arial typeface.

Typeface selection for secondary transforms

In output created by secondary transforms it is generally not possible to control typeface selection for individual characters as it is in paginated output. The transform engine therefore processes typeface selection schemes in a slightly different way.

You can create a scheme file used for a specific output type by using the name “scheme-format.cfg”. The transform engine will use this in preference to the standard scheme file. For example, when producing RTF output the scheme-rtf.cfg file will be used if it is present; otherwise the standard schemes will be used.

Within a specific scheme, preference will be given to unqualified typefaces (i.e. those without any selection attributes). The way typefaces are selected depends on the type of output format:

  • For formats that require a specific typeface (e.g. RTF) the first unqualified typeface in the scheme is used, or the first typeface in the list if there are no unqualified typefaces.

  • For formats that can use a list of typefaces (e.g. HTML) the unqualified typefaces are listed first, followed by the other typefaces.

In the example above, the Body scheme would select typefaces as follows:

  • For RTF: Times New Roman;

  • For HTML: Times New Roman, Fraktur, MS Song, UnBatang.