Windows 8.1 color fonts

Michelle Perham mihill at microsoft.com
Thu Jul 18 22:29:58 CEST 2013


As promised, the specification for this work has been posted to the MPEG yahoo group.

I've also pasted the text below.


Color 'COLR' Table

Overview

The COLR table is designed to add support to OpenType for multi-colored glyphs in a manner that is compatible with existing text engines and easy to support with current OpenType font files.

The COLR table defines a list of base glyphs-which are regular OpenType glyphs, typically mapped to a cmap entry. Each base glyph is associated by the COLR table to a list of glyphs, each corresponding to layers that can be combined, creating a colored representation of the base glyph. The layered glyphs are explicitly defined in bottom-up z-order and each of their advance widths must match those of the base glyph. If the font has vertical metrics, the associated layer glyphs must also have the same advance height and vertical Y origin as the base glyph.

The COLR table works together with the CPAL table which holds the color palettes used by the color layers.

A requirement for OpenType fonts using COLR and CPAL table is Glyph ID 1 must implement the .null glyph, as noted in the recommendations section of the specification.

If the COLR table is present in a font but no CPAL table exists, then color will not be supported for this font.

When placing and registering glyphs for a layered color approach there is the possible issue of "seaming" where the edge rendering of one glyph interfere with another glyph. This may be more or less visible based on the contrast of the colors used.

Any use scenario that attempts to map glyphs to character codes must be aware of the mapping done by the COLR table.

Header

The table starts with a fixed portion describing the overall setup for the color font records. As with many OpenType tables, the first version of this table will be indicated by version zero. All offsets, unless otherwise noted, will be from the beginning of the table.

COLR Header

Type        Name                    Description
------------------------------------------------------------------------------------------------
USHORT      version                 Table version number (0).
USHORT      numBaseGlyphRecords     Number of Base Glyph Records.
ULONG       offsetBaseGlyphRecord   Offset (from beginning of COLR table) to Base Glyph records.
ULONG       offsetLayerRecord       Offset (from beginning of COLR table) to Layer Records.
USHORT      numLayerRecords         Number of Layer Records.

Base Glyph Record

The header of the COLR table points to the base glyph record. This record is used to match the base glyph to the layered glyphs. Each base glyph record contains a base glyph index. This is usually the glyph index that is referenced in the cmap table. The number of layers is used to indicate how many color layers will be used for this base glyph. Each record then has an index to a glyph layer record. There will be numLayers of layer records for each base glyph. The firstLayerIndex refers to the lowest z-order, or bottom, glyph id for the colored glyph. The next layer record will represent the next highest glyph in the z-order, and this continues bottom-up until it reaches the numLayers glyph at the top of the z-order. The index is relative to the start of the Layer Records. The index does not have to be unique for each base glyph ID. If two base glyphs need to share the color glyphs and palette indices, this is acceptable. Likewise a Base Glyph Record could point partway into a z-order of another base glyph.

The base glyph records are sorted by glyph id. It is assumed that a binary search can be used to efficiently access the glyph IDs that have color values.

Base Glyph Record

Type     Name              Description
------------------------------------------------------------------------------------
USHORT   GID               Glyph ID of reference glyph. This glyph is for reference
                           only and is not rendered for color.
USHORT   firstLayerIndex   Index (from beginning of the Layer Records) to the layer
                           record. There will be numLayers consecutive entries for
                           this base glyph.
USHORT   numLayers         Number of color layers associated with this glyph.

Layer Record

GID / Palette Index Pairs Record

Type     Name            Description
-----------------------------------------------------------------------------------------
USHORT   GID             Glyph ID of layer glyph (must be in z-order from bottom to top).
USHORT   paletteIndex    Index value to use in the appropriate palette. This value must
                         be less than numPaletteEntries in the CPAL table, except for
                         the special case noted below. Each palette entry is 16 bits.
                         A palette index of 0xFFFF is a special case indicating that
                         the text foreground color should be used.

Color Palette (CPAL) Table

Palette Table

The palette table is a set of one or more palettes, each containing a predefined number of RGBA values arranged consecutively by palette index value.

The first palette, number 0, is the default palette. The palettes are referenced by colorRecordIndices, this is the index into the array of color records where the palette starts. Multiple colorRecordIndices may refer to the same palette, therefore the number of actual palettes in the table may be less than the numPalettes entry. A minimum of one palette, the default, must be provided in the table. Each palette must have the same number of entries as defined by numPaletteEntries, which must be at least one entry. Any empty CPAL table, with no palettes and no color records is not permissible. It is permissible for palettes to overlap and share data.

For each of the palettes, the first color record is index zero. As noted in the COLR table description, the palette index of 0xFFFF represents the foreground color used in the system. This special value does not change across multiple palettes. There can be no more than numPaletteEntries of RGBA values. The maximum palette index is 65535 - 1, as the 65536th position is used in the COLR table to indicate the foreground font color. The colors in the Color Record should not be pre-multiplied and the alpha value should be explicitly set for each palette entry.

Palette Table

Type         Name                              Description
-----------------------------------------------------------------------------------------------
USHORT       version                           Table version number (0).
USHORT       numPaletteEntries                 Number of palette entries in each palette.
USHORT       numPalettes                       Number of palettes in the table.
USHORT       numColorRecords                   Total number of color records, combined for
                                               all palettes.
ULONG        offsetFirstColorRecord            Offset from the beginning of CPAL table to the
                                               first ColorRecord.
USHORT       colorRecordIndices[numPalettes]   Index of each palette's first color record in
                                               the combined color record array.
ColorRecord  colorRecords[]                    Color records for all palettes.

Color Record

Type   Name    Description
---------------------------------
BYTE   blue    Blue value (B0).
BYTE   green   Green value (B1).
BYTE   red     Red value (B2).
BYTE   alpha   Alpha value (B3).

Example

The example section is available in the document posted to the yahoo group.


Michelle


From: Michelle Perham
Sent: Wednesday, June 26, 2013 2:15 PM
To: mpeg-OTspec at yahoogroups.com
Cc: opentype-migration-list at indx.co.uk
Subject: Windows 8.1 color fonts

Dear OpenType /MPEG OFF List members,

Today at the Microsoft //build conference in San Francisco,  Dan McLachlan of our Graphics team will talk about Windows 8.1 approach to color fonts. We'd like to thank P22, Monotype, The Font Bureau and FontFont for providing us with font data that we were able to use to test this approach.

Our implementation uses a base glyph for reference, which would be used for non-color situations. A data structure, implemented as a new 'COLR' table in OpenType, breaks down the base glyph into a separate set of glyphs, each with its own z-order and single color reference. The color references are handled has palette indices, with a separate table, 'CPAL' in OpenType that resolves the RGBA colors actually used for the glyph.

We plan to submit documentation on this approach for standardization through the ISO MPEG process (for inclusion in the Open Font Format) within the next few weeks. However, if you'd like to see the approach in practice you can download the Windows 8.1 Preview and see a color font (Segoe UI Emoji) used on the touch enabled keyboard.

I'll also be giving a talk at TypeCon on this, hope to see some of you there.

Thanks, Michelle


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.aau.at/pipermail/mpeg-otspec/attachments/20130718/84d8593d/attachment.html>


More information about the mpeg-otspec mailing list