Developing fonts > Specifications

Developing OpenType Fonts
for Thai Script (2 of 3):
Shaping Engine

The Uniscribe Thai shaping engine processes text in stages. The stages are:

  1. Analyze characters for valid diacritic combinations
  2. Shape (substitute) glyphs with OTLS (OpenType Library Services)
  3. Position glyphs with OTLS

The descriptions which follow will help font developers understand the rationale for the Thai feature encoding model, and help application developers better understand how layout clients can divide responsibilities with operating system functions.


Analyze Characters

The unit that the shaping engine receives for the purpose of shaping is a string of Unicode characters, in a sequence. The contextual analysis engine verifies valid diacritic combinations. For additional information, see Invalid Combining Marks.


Shape Glyphs with OTLS

The first step Uniscribe takes in shaping the character string is to map all characters to their nominal form glyphs.

Next, Uniscribe calls OTLS to apply the features. All OTL processing is divided into a set of predefined features (described and illustrated in the Features section). Each feature is applied, one by one, to the appropriate glyphs in the syllable and OTLS processes them. Uniscribe makes as many calls to the OTL Services as there are features. This ensures that the features are executed in the desired order.

The steps of the shaping process are outlined below. Not all of the features listed apply to all Thai script languages.

Shaping features:

  1. Language forms
    1. Apply feature 'ccmp' to preprocess any glyphs that require composition or decomposition.


Position Glyphs with OTLS

Uniscribe next applies features concerned with positioning, calling functions of OTLS to position glyphs.

Positioning features:

  1. Kerning
    1. Apply feature 'kern' to provide pair kerning between base glyphs requiring adjustment for better typographical quality.

  2. Mark to base
    1. Apply feature 'mark' to position diacritic glyphs to the base glyph.

  3. Mark to mark
    1. Apply feature 'mkmk' to position diacritic glyphs to other diacritic glyphs.


Invalid Combining Marks

Combining marks and signs that appear in text not in conjunction with a valid consonant base are considered invalid. Uniscribe displays these marks using the fallback rendering mechanism defined in the Unicode Standard (section 5.12, 'Rendering Non-Spacing Marks' of the Unicode Standard 3.1), i.e. positioned on a dotted circle.

Please note that to render a sign standalone (in apparent isolation from any base) one should apply it on a space (see section 2.5 'Combining Marks' of Unicode Standard 3.1). Uniscribe requires a ZWJ to be placed between the space and a mark for them to combine into a standalone sign.

For the fallback mechanism to work properly, a Thai OTL font should contain a glyph for the dotted circle (U+25CC). In case this glyph is missing from the font, the invalid signs will be displayed on the missing glyph shape (white box).

In addition to the 'dotted circle' other Unicode code points that are recommended for inclusion in any Thai font isthe ZWSP (zero width space; U+200B). Thai words are not separated by spaces, therefore the ZWSP can be used for word boundaries since its width will 'grow' when justifying text.

If an invalid combination is found, the diacritic that causes the invalid state is placed on a dotted circle to indicate to the user the invalid combination. The shaping engine for non-OpenType fonts will cause invalid mark combinations to overstrike. This is the problem that inserting the dotted circle for the invalid base solves. It should also be noted that the dotted circle is not inserted into the application's backing store. This is a run-time insertion into the glyph array that is returned from the ScriptShape function.

The invalid diacritic logic for Thai is based on the classes listed below. There is a check to make sure more than one mark of a class is not placed on the same base.

Class Description Code points
ABOVE1 Above mark closest to base U+0E31, U+0E34, U+0E35, U+0E36, U+0E37
ABOVE2 Second level above mark U+0E47, U+0E4D
ABOVE 3 Third level above mark U+0E48, U+0E49, U+0E4A, U+0E4B
ABOVE 4 Fourth level above mark U+0E4C, U+0E4E
BELOW1 Below mark closest to base U+0E38, U+0E39
BELOW2 Second level below mark U+0E3A
AM The AM character needs to be broken into two glyphs and some reordering might be required so that the ring is the base glyph U+0E33

Next section:  Features

introduction | shaping engine | features | appendix

Top of page