# Glint resources

**Status:** NORMATIVE for format version 8. This document is part of
[the Glint stream format specification](specification.md). It defines the
identity of each resource, the bytes of the resource messages and the
work that a client does to install each resource.

All integers are little-endian. An f32 is an IEEE 754 binary32 value and
an f64 is an IEEE 754 binary64 value. Offsets are decimal bytes from the
start of the body, the payload or the record. The payload of a message is
its compressed part after decompression. The error codes are those of
"Errors" in the specification.

## Identities

| Identity | Range | Named by | Installed by |
| --- | --- | --- | --- |
| Font number | 0 to 511 | Text `font` (u16), glyph row `font` (u16), Glyphs `font` (u32), Color glyph `font` and its path row `font` (u32) | Font (3): font n is the n-th Font message of the connection |
| Variation key | 1 to 255; 0 is no key | Text `variationKey`, glyph row `variationKey` | Variation (17): key n is the n-th Variation message of the connection |
| Image index, kind 0 (decoded image) | 0 to 32767 | Image `image` (u16) with `kind` 0 | Image (4), entry kind 0 |
| Image index, kind 1 (color glyph bitmap) | 0 to 16383 | Image `image` (u16) with `kind` 1 | Image (4), entry kind 1 |
| Path index, kind 0 (SVG path) | 0 to 32767 | SVG path `path` (u16) with `kind`, path-mask `path` (u32) with `pathKind`, path row `path` (u32) with `pathKind` | Path (6), path kind 0 |
| Path index, kind 1 (color glyph layer) | 0 to 16383 | as above | Path (6), path kind 1: the connection numbers these indices in the order of their first Path message |
| Path index, kind 2 (text stroke) | 0 to 16380 | as above | Path (6), path kind 2 |
| Color glyph cache slot | 0 to 16127 | Color glyph command `slot` (u16) | Color glyph (14): the n-th Color glyph message of the connection installs cache slot n |
| Color glyph path slot | 0 to 16383 | the FILL and PUSH_MASK operations of a color glyph program | Color glyph (14) path rows: the n-th path row of the connection installs path slot n |

Each kind has its own index space, from 0. A record names an image index
or a path index together with its kind. An index outside the space of its
kind is error 18 in a command of stream 0, error 21 in a path row of
stream 5 and error 23 in an Image, Image release or Path message.

A color glyph path slot is defined only by its path row (font, glyph,
box). A path index of kind 1 is defined only by its Path message (path
text). The two identities are independent: path index n of kind 1 and
path slot n are not related.

### Order of the resource messages

A resource message precedes the first frame that reads the resource. The
client applies the messages in arrival order. Before each frame a
server sends, in this order: a Configuration when it differs
from the last one, Font messages in increasing font number, Variation
messages in increasing key, Glyphs messages, Color glyph messages in the
order in which stream 0 first draws each slot (so in increasing cache
slot), Path messages in the order of the path rows of stream 5
(increasing path kind, then path index), Image messages, and Image
release messages.

A writer can send the resource messages of a frame in another order,
with these conditions:

- A Font message precedes each Glyphs, Color glyph and frame that names
  its font number.
- The Variation messages are in increasing key.
- The program of a Color glyph message names only the path slots of this
  message and of earlier Color glyph messages.
- A Path message of kind 1 names an index that an earlier Path message
  of kind 1 named, or the next index.
- Each message precedes the frame that reads it.

The client numbers the cache slots, the path slots and the path indices
of kind 1 in arrival order. A client that skips or reorders these
messages numbers them differently from the server.

### Numbering for a writer

A writer gives each resource its number. Some numbers come from the
order of the messages, and the client counts them; the writer chooses
the others. Two writers that follow the canonical rule write equal bytes
for equal frames. A client
accepts every number that the "Client accepts" column permits.

| Number | Canonical rule | Client accepts |
| --- | --- | --- |
| Font number | From 0, in the order of first use: the text commands of stream 0 in stream order, then the glyph rows of stream 5, frame after frame. | Any number less than the count of Font messages before the frame (error 8). Font n is the n-th Font message. |
| Variation key | From 1, in the order of first use, as the font numbers. | Any key that a Variation message before the frame defined (errors 18 and 21). Key n is the n-th Variation message. |
| Color glyph cache slot | From 0, in the order in which stream 0 first draws each slot. | Slot n is the n-th Color glyph message (error 18 for a slot without a message). |
| Color glyph path slot | From 0, in the order of the path rows of the Color glyph messages. | Path slot n is the n-th path row. |
| Path index of kind 1 | From 0, in the order of the first Path message of each layer path. | Any index in the space of kind 1 that a Path message defined. |
| Image index of kind 0 or 1, path index of kind 0 or 2 | The writer's choice, in the space of the kind. A decoded image of a color picker plane is `0x7F00 + n` ("Color picker planes" in [the streams](streams.md)). | Any index in the space of its kind (errors 18, 21 and 23). The writer can use an index again after an Image release, or replace its image with a new Image message. |

A number of the first group stays valid for the rest of the connection:
no message removes a font, a variation key, a cache slot, a path slot or
a layer path. A writer therefore sends each of these resources once. The
numbers of a frame's scroll entries, gradient stops and scrollbar groups
belong to the frame ([the streams](streams.md), streams 2, 3 and 4).

## Configuration (2)

A Configuration message gives the raster target of the frames that follow
it. It has no compressed part. The body is 53 bytes.

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | target width | The width of the client's raster target, device px: `ceil(visible width × device scale)`. |
| 4 | 4 | u32 | target height | The height of the raster target, device px: `ceil(visible height × device scale)`. |
| 8 | 4 | f32 | device scale | Device px for each CSS px: `s` of [the streams](streams.md). More than 0. |
| 12 | 1 | u8 | render mode | 0 standard dynamic range, 1 high dynamic range (see "Color encoding" in [the streams](streams.md)). |
| 13 | 4 | f32 | visible x | The left of the visible rectangle, CSS px in layer space: `vx`. |
| 17 | 4 | f32 | visible y | The top of the visible rectangle, CSS px: `vy`. |
| 21 | 4 | f32 | visible width | CSS px. |
| 25 | 4 | f32 | visible height | CSS px. |
| 29 | 16 | f32[4] | background | The color that fills the raster target before the first command of each frame, red, green, blue, alpha, in the color encoding of [the streams](streams.md). 0, 0, 0, 0 is transparent; the commands then paint every pixel that shows. |
| 45 | 4 | f32 | light-ink thickening | Device px that each glyph edge of light text moves outward. 0 or more and finite. |
| 49 | 4 | f32 | dark-ink thickening | Device px that each glyph edge of dark text moves outward. 0 or more and finite. |

A body shorter than 53 bytes is error 3. The client moves each glyph edge
outward by `mix(dark ink, light ink, luma of the text color)` device px;
0 and 0 draw the exact outlines.

The first frame of a connection follows a Configuration. A server writes
a Configuration only when it differs from the last one, and its next
frame is then a Keyframe ("Encoder" in the specification).
A clip writer follows "Configuration at a keyframe" in
[the clips](clips.md).

## Font (3)

A Font message registers one font instance: one face of one font file at
one normalized coordinate on each axis of the face other than `wght` and
`opsz`. The font number is its identity: the n-th Font message of a
connection has font number n (see "Font numbers"). The body carries no
number.

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | face index | The face in a `ttcf` collection; 0 for a file with one face. |
| 4 | 4 | u32 | file source | 0xFFFFFFFF: the payload starts a new file. Another value: the number of an earlier font whose file has the same bytes; it must be less than the number of this font, else error 8. |
| 8 | 4 | u32 | file length | The byte length of the font file. 0 when the file source is an earlier font. |
| 12 | 2 | u16 | axis count | The number of axis records. |
| 14 | 6 × count | records | axes | For each axis: `tag` (u32, the `fvar` tag) and `coordinate` (i16, F2Dot14, −16384 to 16384). |
| 14 + 6 × count | — | bytes | compressed part | The payload: file ranges. |

A body shorter than 14 bytes or than its axis records is error 3. A
connection has at most 512 fonts (see "Limits" in [the
specification](specification.md)).

The axes are the `fvar` axes of the face other than `wght` and `opsz`, in
`fvar` order, each once. The coordinate of an axis is its normalized
coordinate before `avar`: the user value clamped to the axis range,
normalized against the default to −1 .. 0 .. 1 (by `default − minimum`
below the default and `maximum − default` above it), and rounded once to
1/16384. An axis that the message omits is at its default (coordinate
0). The row's weight and optical size give `wght` and `opsz` (see
"Client work").

The client reports error 8 for a tag that is not an `fvar` axis of the
face, for `wght` or `opsz`, for a repeated tag, and for a coordinate
outside −16384 to 16384. A client keeps `wdth` and `slnt` for an
instance, and every other axis at its default: it reports error 8 for a
coordinate other than 0 on another axis.

### File ranges

The payload of a Font or a Glyphs message is a sequence of ranges to its
end.

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | file offset | The byte offset in the font file. |
| 4 | 4 | u32 | length | The byte count. |
| 8 | length | bytes | bytes | The file bytes at `file offset`. |

A range that the payload cuts is error 3. A range past the file length is
error 17. A later range overwrites an earlier one. The bytes that the
client never receives stay 0.

With file source 0xFFFFFFFF the payload is the skeleton of the face:

1. For a `ttcf` file: the collection header and its offsets, bytes 0 to
   `12 + 4 × numFonts`.
2. The table directory of the face: `12 + 16 × numTables` bytes. The
   directory keeps the records of the tables that the skeleton omits.
3. Each table whole, except the tables in items 4 to 7.
4. No bytes of `glyf`, `loca`, the shaping tables (`GSUB`, `GPOS`, `GDEF`,
   `kern`, `kerx`, `morx`, `mort`, `JSTF`, `BASE`, `MATH`, `post`, `DSIG`)
   and the color tables (`COLR`, `CPAL`, `sbix`, `CBDT`, `CBLC`, `SVG `).
5. Of `hmtx` and `vmtx`: the last long metric only.
6. Of `gvar`: the 20-byte header, the glyph variation data offsets and the
   shared tuples.
7. Of `CFF ` and `CFF2`: the table without the data of its CharStrings
   INDEX (the INDEX count, offset size and offsets stay).

When the file source is an earlier font, the instance shares the file of
that font. When its face index differs from the face index of that font,
the payload holds the skeleton ranges (items 1 to 7) of the new face, and
the client writes them into the shared file. Else the payload is empty.

The skeleton is the least that a Font message with file source
0xFFFFFFFF carries: the client reads the tables of items 1 to 3 when it
registers the instance. A writer can send more bytes of the file, up to
the whole file as one range at offset 0 with the length of the file. The
client then holds the data of every glyph, and the writer sends no
Glyphs message for that file. `file length` is the length of the
original file in every case, because the table directory gives offsets in
it. The ranges can be in any order, and they can overlap.

A writer sends, before each frame, the bytes of every glyph that the
frame draws and that the client does not hold (see "Glyphs (13)"). The
client does not check that it holds them: a glyph whose bytes are 0
draws nothing, or a wrong outline.

### Client work

1. With file source 0xFFFFFFFF: make a file of `file length` zero bytes
   and write the ranges. Else: write the ranges into the file of the
   source font. All the instances on one file read the same bytes.
2. Register the instance at the coordinates of the message. The user
   value of coordinate `c` on an axis is `default + c / 16384 × range`,
   with the range on the side of `c`. A registration that fails is error
   8.
3. The units per em of the face come from `head.unitsPerEm`. Text commands
   carry the same value in `unitsPerEm`.

The client draws outlines from the file bytes with an OpenType outline
reader: `glyf` and `loca` with `gvar` deltas, or `CFF ` or `CFF2`
charstrings. It never shapes text.

The outline instance of a glyph row of stream 5 has these coordinates:
`wght` = the row `weight`; `opsz` = the row `opticalSize`, clamped to the
axis range, when the face has `opsz` and the row's variation key does not
turn optical sizing off; each axis of the Font message at its coordinate;
then each pair of the row's variation key, which replaces the value of
the axis it names (see "Variation").

### Variation key

A variation key of a text command and of a glyph row is 0, or a number
that names one `font-variation-settings` and `font-optical-sizing`
control. The n-th Variation message of a connection defines key n (see
"Variation (17)"). A connection has at most 255 keys. A key that no
Variation message defined is error 18 in a text command and error 21 in
a glyph row.

### Font numbers

Every endpoint numbers the fonts of its connection from 0 in the order of
first use: the text commands of stream 0 in stream order, then the glyph
rows of stream 5, frame after frame. Font n is the font of the n-th Font
message. The server writes these numbers into the frames and into the
Glyphs and Color glyph messages, and sends only the fonts that the frames
use. A font number of a frame or a message without a Font message is
error 8.

## Variation (17)

A Variation message defines one variation key. It has no compressed part.

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 2 | u16 | key | 1 to 255; the n-th Variation message of the connection defines key n. |
| 2 | 1 | u8 | optical sizing off | 1: `font-optical-sizing: none`, the glyph rows of the key set no `opsz`. 0: automatic optical sizing. |
| 3 | 2 | u16 | pair count | The number of pairs. |
| 5 | 8 × count | records | pairs | For each pair: `tag` (u32, the axis tag) and `value` (f32, the user value of `font-variation-settings`), one pair for each tag. |

The body is exactly `5 + 8 × pair count` bytes: shorter is error 3, longer
error 19. A key of 0 or above 255, a key that an earlier message defined, a
key that is not the next key, and an optical sizing byte above 1 are
error 19.

The server sends the Variation messages of the keys that a frame uses
before the frame, after the Font messages. The client applies the pairs
of a key after the coordinates of the Font message and the row's weight
and optical size: each pair replaces the value of the axis it names, or
adds the axis (see "Client work" in "Font").

## Glyphs (13)

A Glyphs message adds glyph data to one font file.

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | font | The font number of a font on the file. A number without a Font message is error 8. |
| 4 | — | bytes | compressed part | The payload: file ranges, as for Font. |

For each glyph `g` that a frame draws and that the client does not have,
and for each component glyph of `g`, the payload holds:

| Data | File bytes |
| --- | --- |
| `loca` | the two entries of `g` (2 or 4 bytes each, by `head.indexToLocFormat`) |
| `glyf` | the record of `g`; nothing for an empty glyph |
| `hmtx` | the metric of `g`: 4 bytes below `numberOfHMetrics`, else the 2-byte left side bearing |
| `vmtx` | the same with `numberOfLongVerMetrics` |
| `gvar` | the variation data of `g` |
| `CFF ` or `CFF2` | the charstring of `g` in the CharStrings INDEX |

The glyphs of a frame are the glyph IDs of its text commands (without
65535) and the glyphs of the path slots of the color glyph cache slots
that it draws. The client writes the ranges into the file of the font.
All the instances on the file then read the new bytes.

A writer can send any number of Glyphs messages for one file, and any
ranges of the file in them; the canonical writer sends one message for
each file that has new glyphs before a frame. A writer that sent the
whole file in its Font message sends no Glyphs message (see "File
ranges").

## Color glyph (14)

A Color glyph message installs one color glyph cache slot: a COLR glyph
program at one font size and, for a program that paints the text color,
one text color. The n-th Color glyph message of the connection installs
cache slot n (n from 0); the body has no cache slot field. Stream 0 draws
the slot as one Color glyph command (23). The message also installs the
path slots that the program uses: one glyph outline of one font each.
The n-th path row of the connection, counted over all its Color glyph
messages in order, installs path slot n; a path row has no path slot
field.

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | font | The font number of the connection, else error 8. |
| 4 | 4 | f32 | font size | CSS px, the `fontSize` of the text. The client uses `floor(size × 100) / 100`. |
| 8 | 4 | u32 | units per em | The `unitsPerEm` of the text. |
| 12 | 16 | f32[4] | text color | The `color` of the text; 0 when the program does not paint the text color. |
| 28 | 16 | f32[4] | box | Left, top, right, bottom of the ink box in CSS px from the glyph origin, y down. |
| 44 | 1 | u8 | cached | 1. |
| 45 | 4 | u32 | path row count | The number of path rows in the payload. |
| 49 | — | bytes | compressed part | The payload: the path rows, then the program. |

A body shorter than 49 bytes is error 3. The 16129th Color glyph message
of a connection is error 20 (16128 cache slots).

Path row (24 bytes):

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | font | The font number of the connection, else error 8. |
| 4 | 4 | u32 | glyph | The glyph ID in bits 0 to 15; bits 16 to 31 are 0. |
| 8 | 16 | f32[4] | box | x0, y0, x1, y1 of the outline in font units, y down. |

The 16385th path row of a connection is error 20 (16384 path slots).

Program, after the rows; it must end at the end of the payload, else
error 3:

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | operation length | L, the byte length of the operations. |
| 4 | 4 | u32 | text color flag | 1 when an operation paints the text color. |
| 8 | L | bytes | operations | The operations, to the end. |

### Program operations

The operation encoding of this section is part of format 8.

Each operation starts with a u32 header: bits 0 to 7 the code, bits 8 to
31 the byte length of the operation with the header. The program space P
is font units × 512, y up, origin at the glyph origin. The path space q of
a path slot is font units, y down. An affine `(a, b, c, d, e, f)` maps
`(x, y)` to `(a·x + c·y + e, b·x + d·y + f)`.

| Code | Name | Length | Fields after the header |
| --- | --- | --- | --- |
| 0 | NOP | any | none; the client skips it |
| 1 | FILL | 68, or 112 + 24 × stops | below |
| 2 | PUSH_GROUP | 16 | blend mode u32 (0 to 15, as push group), alpha f32, composite operator u32 (0 to 12, as push group) |
| 3 | POP_GROUP | 4 | none |
| 4 | PUSH_CLIP | 44 | rectangle f32[4] (x0, y0, x1, y1), affine f32[6] from the rectangle to P |
| 5 | POP_CLIP | 4 | none |
| 6 | PUSH_MASK | 32 | path slot u32, affine f32[6] from q to P |
| 7 | POP_MASK | 4 | none |

FILL:

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 4 | 4 | u32 | path slot | The outline that the fill paints. |
| 8 | 4 | u32 | flags | Bit 0: paint the text color (the color alpha multiplies the text alpha). Bit 1: gradient. |
| 12 | 24 | f32[6] | affine | From q to P. |
| 36 | 16 | f32[4] | box | The box of the path slot in q. |
| 52 | 16 | f32[4] | color | The color, encoded sRGB, straight alpha. |
| 68 | 4 | u32 | gradient kind | Gradient only: 4 linear, 5 radial, 6 concentric radial, 7 sweep, with bit 6 reflect and bit 7 repeat. |
| 72 | 24 | f32[6] | gradient affine | From the position in the fill box to the canonical space of the gradient. |
| 96 | 4 | f32 | parameter 0 | Radial: r0. Sweep: the start angle, radians. Linear: 0. |
| 100 | 4 | f32 | parameter 1 | Radial: r1. Sweep: the end angle, radians. Linear: 0. |
| 104 | 4 | u32 | stop count | 1 to 255. |
| 108 | 4 | u32 | stop offset | 0xFFFFFFFF. |
| 112 | 24 × count | bytes | stops | Stop records: offset f32, text color u32 (1: the stop paints the text color with alpha × text alpha), color f32[4]. |

Each operation length must be at least 4, end in the program and be the
length of its code. The stop count of a FILL must be 1 to 255 and fit its
length. Groups, clips and masks must nest and balance, at a depth of at
most 32. Every path slot that an operation names must be installed by
this message or an earlier one. A client rejects a program that breaks
one of these rules with error 20, before it installs the program.

### Client work

1. Count the message: the n-th Color glyph message of the connection is
   cache slot n. Check the cache slot count, the font and each path row
   (errors 20, 8 and 3).
2. Install the path rows in order: the n-th path row of the connection is
   path slot n. Store the font, the glyph and the box of each path slot.
   The outline of a path slot is the glyph outline of the registered font
   at the coordinates of its Font message.
3. Copy the program. Keep the stops of each gradient FILL as gradient
   stop entries (position, color, missing 0, length 0) in the stop pool
   of the client, unless a stop paints the text color (`text color` = 1).
   A FILL with such a stop takes the text color each time the slot draws.
4. To draw a slot at device scale `k`, the client computes its entry in a
   cache page from the box: left `floor(box.left × k) − 2`, top
   `floor(box.top × k) − 2`, width `ceil(box.right × k) + 2 − left`,
   height `ceil(box.bottom × k) + 2 − top`. It draws the program into a
   transparent RGBA page at the glyph origin: each FILL fills the outline
   of its path slot through its affine, with the glyph origin snapping of
   GLYPH_ORIGIN and with its color or its gradient; each group is a
   compositing group; each clip and each mask clips the content that it
   holds (a mask by the outline of its path slot). The CSS px of the slot
   are P × `u` with `u = font size / (units per em × 512)`, y flipped.
5. A Color glyph command (23) of the slot then samples the entry of the
   page.

How the client stores a cache slot and its path slots is the client's
choice; no message or stream names its storage.

### Larger color glyphs

A COLR glyph that the cache does not take (transformed text, a box larger
than 256 CSS px, or no free slot) keeps its layer commands in stream 0:
SVG path commands of kind 1 (color glyph layer), whose outlines Path
messages of path kind 1 carry. The connection numbers the path indices of
kind 1 in the order of their first Path message: the first Path message
of kind 1 names index 0, the Path message of a new layer path names the
next index, and so on. These path indices are not path slots of a Color
glyph message. The gradient stops of the layers are in stream 3, as the
stops of every gradient of stream 0.

## Image (4)

An Image message installs the decoded pixels of one image at its image
index, and replaces an earlier image at that index. The image index is in
the index space of the entry kind: the entry kind is the image kind of
"Identities". Another entry kind, or an index outside the space of the
entry kind, is error 23.

Entry kind 0 (a decoded image), 41 bytes before the compressed part:

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | image index | The identity in the space of the entry kind: 0 to 32767 for kind 0, 0 to 16383 for kind 1. Else error 23. |
| 4 | 1 | u8 | entry kind | 0 decoded image, 1 color glyph bitmap. Else error 23. |
| 5 | 1 | u8 | contents opaque | 1 when every pixel is opaque. |
| 6 | 4 | u32 | width | Pixels. |
| 10 | 4 | u32 | height | Pixels. |
| 14 | 4 | u32 | row stride | Bytes from the start of a row to the start of the next row. |
| 18 | 1 | u8 | channel layout | 0 gray, 1 gray-alpha, 2 rgb, 3 rgba. |
| 19 | 1 | u8 | sample type | 0 uint8, 1 uint16, 2 float16, 3 float32. |
| 20 | 1 | u8 | bits per sample | 1 to 8 (uint8), 1 to 16 (uint16, float16), 1 to 32 (float32). |
| 21 | 1 | u8 | alpha mode | 0 opaque, 1 straight, 2 premultiplied. |
| 22 | 1 | u8 | transfer function | 0 srgb, 1 linear, 2 gamma, 3 pq, 4 hlg, 5 rec2020, 6 prophoto-rgb. |
| 23 | 1 | u8 | primaries | 0 srgb, 1 display-p3, 2 rec2020, 3 a98-rgb, 4 prophoto-rgb, 5 xyz-d50, 6 xyz-d65. |
| 24 | 8 | f64 | gamma | The exponent of transfer function 2; else NaN. |
| 32 | 8 | f64 | reference white luminance | cd/m². |
| 40 | 1 | u8 | canvas tone mapping | 1: standard tone mapping (a float16 image); else 0. |
| 41 | — | bytes | compressed part | The pixel bytes. |

Entry kind 1 (a color glyph bitmap, image index 0 to 16383) inserts a
20-byte glyph box after byte 5; the fields from width on move 20 bytes
later (61 bytes before the compressed part):

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 6 | 4 | f32 | left | The left of the bitmap in ems of the font size, from the glyph origin. |
| 10 | 4 | f32 | top | The top of the bitmap in ems, y down from the origin. |
| 14 | 4 | f32 | width | Ems. |
| 18 | 4 | f32 | height | Ems. |
| 22 | 4 | f32 | whole pixel | 1: the origin x snaps to a whole device pixel (`sbix`); 0: to a quarter device pixel (`CBDT`). |

The enumeration values of the tables are the values of the format. The
white point is D65. Format 8 carries no ICC profile, and no
transfer function needs one. A server whose image has an ICC transfer
function reports error 22. A client that receives an enumeration value
outside its table reports error 22.

Pixel bytes: row `r` starts at byte `r × row stride`. A row holds `width`
pixels, then padding to the stride. A pixel holds its channels in layout
order (gray; gray, alpha; R, G, B; R, G, B, A). A sample is 1 byte
(uint8), 2 bytes (uint16; float16 as binary16) or 4 bytes (float32),
little-endian. The row stride is at least `width × channels × sample
bytes` and a multiple of the sample bytes. The payload is exactly `row
stride × height` bytes; a client rejects another length with error 3.

The client stores the image at its index in the space of its kind. An
Image command of kind 1 places a kind 1 image with its glyph box (see
"Image (3)" in [the streams](streams.md)). An Image command whose index
has no image draws nothing.

## Image release (5)

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | image index | An image that the client holds and that the next frame does not draw, in the space of the entry kind. |
| 4 | 1 | u8 | entry kind | 0 decoded image, 1 color glyph bitmap. |

The body is 5 bytes. Another length is error 3. Another entry kind, or an
index outside the space of the entry kind, is error 23. The client
deletes the image of that kind and index.

## Path (6)

A Path message installs the definition of one path index of one path
kind. The server sends it for each path row of stream 5 whose definition
the client does not hold, and again when the definition changes.

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 4 | u32 | path index | The identity in the space of the path kind (see "Identities"). Else error 23. |
| 4 | 1 | u8 | path kind | 0 SVG path, 1 color glyph layer, 2 text stroke. Else error 23. |
| 5 | — | bytes | compressed part | The payload: the path record, the path text, the dashes. |

A body shorter than 5 bytes is error 3. The payload is exactly
`40 + text length + 4 × dash count` bytes. A
payload of another length is error 3. The connection numbers the path
indices of kind 1 in the order of their first Path message (see "Larger
color glyphs"): a Path message of kind 1 names an index that an earlier
Path message of kind 1 named, or the next index.

Path record (40 bytes):

| Offset | Size | Type | Field | Meaning |
| --- | --- | --- | --- | --- |
| 0 | 1 | u8 | fill rule | 0 nonzero, 1 evenodd. |
| 1 | 1 | u8 | stroke kind | 0 fill; 1 stroke. |
| 2 | 1 | u8 | cap | 0 butt, 1 round, 2 square. |
| 3 | 1 | u8 | join | 0 miter, 1 round, 2 bevel. |
| 4 | 4 | f32 | stroke width | Path units (font units for a text stroke). |
| 8 | 4 | f32 | miter limit | A ratio. |
| 12 | 4 | f32 | dash phase | Path units. |
| 16 | 4 | u32 | dash count | The number of f32 dash lengths. |
| 20 | 4 | u32 | text length | The byte length of the path text. |
| 24 | 16 | f32[4] | bounds | The bounds of the outline that the path's atlas entry covers (the fill, or the stroked outline), in path units: min x, min y, max x, max y. |

The path text follows the record: SVG 2 path
data in UTF-8 (commands M L H V C S Q T A Z, both cases). A glyph outline
(a color glyph layer or a text stroke) uses absolute M, L, Q, C and Z in
font units, y down. The dashes follow the text as `dash count` f32 values
without alignment.

The bounds are the box of the path. A command's rectangle maps onto them
(streams.md, "SVG path"), and a command with ENTRY_BOUNDS draws the path
at them. A client uses them and does not measure the path.

A writer computes the bounds of a fill (stroke kind 0) with fill rule 0
(nonzero) in these steps:

1. Parse the path text into segments. A segment is a line, a quadratic
   curve or a cubic curve, in path units as f64.
2. Take the minimum and the maximum over each segment: its two end
   points and, for a curve, each point where its x or its y derivative is
   0 inside the segment.
3. Round each of the four values once to f32, to the nearest value.

For such a path of M, L, H, V and Z commands, the bounds are the minimum
and maximum of its vertices. This document does not yet define the
bounds of an arc (A), an evenodd fill (fill rule 1) or a stroke (stroke
kind 1). A writer converts such a shape to a nonzero fill of lines and
curves before it writes the Path message.

Every path draws from its distance field: a connection carries no device
coverage draw. A stroke or a contour narrower than two texels of its
field can lose ink where it crosses itself. A producer sends a stroke
that does not scale (`vector-effect: non-scaling-stroke`) as a stroke of
its centerline mapped into the host space, with ENTRY_BOUNDS; a
non-scaling stroke with a gradient paint is a producer error.

The client stores the definition by path kind and path index and replaces
an earlier one. The path atlas reads the definition of each path row of
stream 5.