Cells containing a codepoint from the registration block that had a
registered glyph when they were printed are rendered with that glyph,
into the area the character occupies: its cell, the cells given to it
by the text sizing protocol, or two cells when it is followed by a space
and the width of its viewBox when fit to the cell height is more than
one cell.
The glyph is bound to the text when it is printed, by storing a
reference to it in the text cache entry of the cell. Changing or
clearing a registration affects only text printed afterwards, so
programs using the same codepoints do not change each other's output
and registering never requires re-rendering lines. Bound entries are
kept in a separate map so that other text is not slowed down. Glyphs
are interned by a seeded hash of their content.
Glyphs that use only the foreground color are alpha masks and glyphs
that use only fixed colors are colored sprites. Glyphs that mix them are
a colored sprite followed in the sprite map by a sprite with the weight
of the foreground color, which the cell shader combines with the
foreground color, so that selection, cursor and other foreground color
changes apply to them exactly.
Sprites of a glyph are freed when the glyph is, which happens only when
no cell uses it, and are reused. Each window can keep alive a limited
number and size of glyphs, beyond which registration fails with
no_space, so a program that keeps registering and printing new glyphs
cannot exhaust memory or sprites for other windows.
A dedicated renderer for vg glyphs. Paths are flattened to polygons in
device space and rasterized by a scanline rasterizer that computes exact
winding numbers on 16 sub-scanlines per pixel row with exact horizontal
coverage, so both fill rules and unions of overlapping polygons are
correct. Strokes are generated in layer space, where the pen is round,
as a union of quadrilaterals, joins and caps, giving the elliptical pen
of SVG under non-uniform matrices. Gradients are linear and two point
conical with pad, reflect and repeat.
The output is decomposed into a premultiplied color, an alpha and a
foreground weight, so that the foreground color can be applied when
drawing, which is exact as compositing is linear in the opaque
foreground color.
Parse vg payloads into a VGGlyph structure, normalizing path data to
absolute moves, lines, quadratic and cubic Béziers and closes, with
arcs converted to cubics as the spec requires. All limits of the spec
are enforced while parsing.
Registrations are stored per screen in a GlyphRegistry owned by the
text cache of the screen. r and c are implemented and RIS clears all
registrations.
Parse the APC escape codes of the glyph protocol (kitty#10872) into a
GlyphCommand structure and reply to the s and q verbs. The s verb
advertises no payload formats until rendering is implemented. q for
codepoints in the registration block is answered from the
registrations; for all other codepoints it is answered with
reason=unknown, as kitty does not perform font lookups while parsing
input. Grapheme queries are not supported.