Sprites.Media.Font

The font editor and its glyph model. A font is a set of glyphs over one cell size and mode, its data { w, h, mode, first, chars }, where chars is the list of glyphs and first the code point of the first. The editor edits one glyph at a time, the one the Characters window selects. It has no layers and no frames, so it is the flattest media. It reuses the shared pixel parts under Sprites.Media.Sprite for the canvas, the draw, move and select tools, the palette and the info window; only the model, the Tools window and the Characters window are font specific.

Sprites.Media.Font

Sprites.Media.Font.BlankDocument Object

Sprites.Media.Font.BlankDocument(w, h, mode)

A new blank freeform font document at the given size: a full printable ASCII set of transparent glyphs, so the Characters window opens on a usable range. A boot factory a page hands to the store, so it builds plain data here rather than staying a live reactive.

InputTypeDescription
wNumberThe glyph cell width.
hNumberThe glyph cell height.
modeStringThe mode name to stamp on the document.

Returns a plain { w, h, mode, first, chars } font document.

Sprites.Media.Font.CharThumbnail Value

Sprites.Media.Font.CharThumbnail(char, width, height, optionalPaletteSlots, aspect)

A PNG data URL of one glyph, drawn at the font size through the palette and pixel aspect, as a reactive value that follows the glyph's pixels, for a character cell's preview. A composite over the shared sprite Thumbnail: a glyph and a sprite are both a grid of cells, so the same raster serves both.

InputTypeDescription
charObjectThe glyph, a { pixels } of cells.
widthNumberThe glyph cell width.
heightNumberThe glyph cell height.
optionalPaletteSlotsArrayThe slot colours for an indexed font, or absent for a freeform glyph that already holds packed colours.
aspectNumberThe pixel aspect the mode draws at.

Returns a reactive PNG data URL string that follows the glyph.

Sprites.Media.Font.Editor Void

Sprites.Media.Font.Editor(data, thumb, info, optionalModes, optionalModeName, optionalSelectedColours, optionalAllColours)

The font editor. Builds the glyph view on the host, the pan and zoom overlay, the Tools window, each canvas tool's own window, the file, history and characters panels, and the Palette and Info windows. It edits one glyph at a time, the one the Characters window selects. It reuses the shared pixel parts under Sprites.Media.Sprite for the canvas, the draw, move and select tools, the palette and the info window, so a font drives them the same way a sprite does. It builds interface and returns nothing; the doc fields it is given are where the edits land.

InputTypeDescription
dataValueThe doc's font data, a two way { w, h, mode, first, chars }. The editor edits one glyph of it, and the size controls resize every glyph.
thumbValueA value the editor Sets to a fresh PNG data URL of the current glyph on every edit, so the doc's saved preview follows the drawing.
infoValueA value the editor Sets to a short mode, size and character-count summary on every edit. See Summary.
optionalModesArrayThe machine's font modes, each { name, colours, pixelAspect, allowedWidths, allowedHeights }. Left out, one free-size mode is used and the size controls float free.
optionalModeNameValueA two way value of the current mode's name, the doc's stored mode. Left out, the editor keeps its own mode name.
optionalSelectedColoursArrayThe slot colours as packed 0xRRGGBBAA integers, paper then ink, which makes the editor indexed. Left out, the editor is freeform, painting any packed colour.
optionalAllColoursObjectWhere a slot edit draws from: { palette: [...] } for a fixed set, or { bitsPerChannel: n } for a free picker.

Returns nothing.

Sprites.Media.Font.FreeformCount Number

The number of glyphs a blank freeform font starts with: the printable ASCII run, space through tilde.

95

Sprites.Media.Font.FreeformFirst Number

The code point of the first glyph a blank freeform font starts with: space.

32

Sprites.Media.Font.Ink Number

The ink cell of an indexed glyph: slot one, the foreground colour a set bit decodes to.

1

Sprites.Media.Font.MaxSide Number

The largest a glyph side may be, in a freeform font.

256

Sprites.Media.Font.MinSide Number

The smallest a glyph side may be.

1

Sprites.Media.Font.NewDocument Object

Sprites.Media.Font.NewDocument(charset, mode)

A new font document seeded from a machine charset: the { w, h, mode, first, chars } shape the store keeps, one glyph per character decoded to paper and ink cells. A set bit becomes the ink slot and a clear bit the paper slot. A boot factory, plain data for the store.

InputTypeDescription
charsetObjectA platform Font charset, { name, w, h, first, glyphs }, each glyph one byte per row, the top bit the leftmost pixel.
modeStringThe mode name to stamp on the document.

Returns a plain { w, h, mode, first, chars } font document.

Sprites.Media.Font.Paper Number

The paper cell of an indexed glyph: slot zero, the background colour a clear bit decodes to.

0

Sprites.Media.Font.ResizeAll Value

Sprites.Media.Font.ResizeAll(data, width, height, pad)

The same font resized so every glyph is the new width and height, cropping or padding each glyph's pixels with pad. The size lives on the document, shared by every glyph, so a size change resizes them all together. A composite over Array.Map, Grid.Two.Resize and ReadOnly, keeping the mode and the first code point.

InputTypeDescription
dataValueThe two way font data.
widthNumberThe new glyph cell width.
heightNumberThe new glyph cell height.
padNumberThe cell value to fill new area with, the transparent cell for a freeform font.

Returns a reactive font-data value at the new size.

Sprites.Media.Font.SelectedGrid Value

Sprites.Media.Font.SelectedGrid(data, charIndex)

A two way { w, h, cells } grid over the glyph at charIndex. Reading composes the grid from the size and that glyph's pixels, so the editor edits one flat glyph. Writing lays the edited pixels back into that one glyph through the chars list, keeping every other glyph, the size, the mode and the first code point, so a paint touches only the selected character.

InputTypeDescription
dataValueThe two way stored { w, h, mode, first, chars } value.
charIndexNumberThe index of the glyph to edit.

Returns a two way { w, h, cells } grid value.

Sprites.Media.Font.Summary String

Sprites.Media.Font.Summary(modeName, grid, count)

The meta info summary for a font: its mode, glyph size and character count as one short string, for the meta record a listing reads. A plain reader for use inside a reverse handler: it reads the mode name, the grid's sides and the count and joins them, dropping the mode when there is none.

InputTypeDescription
modeNameValueThe current mode's name, or absent.
gridObjectThe current glyph grid, { w, h, cells }.
countNumberThe number of characters in the font.

Returns a plain summary string, for example Standard · 8×8 · 96 chars.

Sprites.Media.Font.Transparent Undefined

The transparent cell: an absent value, undefined. A freeform glyph holds this where nothing is painted, and a resize or an erase writes it.

undefined

Sprites.Media.Font.WrapColours Value

Sprites.Media.Font.WrapColours(data, count)

The same font with every pixel of every glyph folded into a colour count, a transparent pixel staying transparent, so a mode with fewer colours wraps the pixels of all the glyphs into range at once. A composite over Array.Map, Sprites.Maths.Modulo and Sprites.Logic.Select, keeping the size, the mode and the first code point.

InputTypeDescription
dataValueThe two way font data.
countNumberThe colour count to fold each cell into.

Returns a reactive font-data value folded into the colour count.