Custom Fonts
NEW FONT builds a working font out of one picture per character. Hand it an .svg, .png or .ico for each letter and it answers a real OpenType file - installable, embeddable, and scalable to any size. FONT UPDATE opens a font that already exists and adds or replaces individual characters in it.
Building a font costs 5 queries, plus 1 for each character in DEFINE, charged before it runs, on top of the query of the script itself. A 26-letter alphabet costs 31. See Quotas & Pricing.
.svg source becomes true vector outlines. A raster source - .png, .ico - is traced to outlines on the way in, so the result stays sharp at 8pt and at 800pt alike, and the file stays small. Tracing reads shape, not colour, so a colour source is reported back to you as flattened rather than quietly losing its colour.Syntax
NEW FONT NAME "myfont" TYPE "otf" INTO "/root/myfont.otf"
DEFINE ["z" AS "https://website.com/z.svg" AND "c" AS "/mounted/letters/c.png"]
SET ?font
Only NAME and DEFINE are required. TYPE defaults to "otf", and an empty TYPE "" is read as the default. INTO defaults to /root/<name>.<type> in your own namespace, so the minimal form is complete on its own:
NEW FONT NAME "myfont" TYPE "" DEFINE ["z" AS "/root/letters/z.svg" AND "c" AS "/root/letters/c.png"] SET ?font
AFTER EMIT ?font("path")
Modifiers
| Modifier | Syntax | Description |
|---|---|---|
NAME | NAME "string" | Required. The family name written into the font itself - what a font menu will show. |
TYPE | TYPE "otf" | Output format. "otf", "ttf" or "woff2". Omitted or empty means "otf". |
INTO | INTO "/root/f.otf" | Where to write the font. Defaults to /root/<name>.<type>. |
DEFINE | DEFINE ["c" AS "src"] | Required. One character per entry, each paired with the picture that draws it. |
AS DRAWN | AS DRAWN | Keep every character where and as large as it was drawn on its own canvas, instead of fitting each one to the em. See AS DRAWN. |
DEFINE
DEFINE takes the object literal documented in Arrays & Objects: a key, AS, a value, joined by AND. The key is the character the picture draws - exactly one character, never a word. The value is where the picture lives.
AND is the separator. OcaltQL has no comma separator anywhere in the language - not here and not in any other bracket literal. A character map of any length is joined with AND, exactly as Chaining describes.NEW FONT NAME "myfont" TYPE "" DEFINE ["z" AS "https://website.com/z.svg" AND "c" AS "/mounted/letters/c.png" AND "y" AS "/mounted/letters/y.ico" AND "r" AS "/mounted/letters/r.png"] SET ?font
AFTER EMIT ?font
Where a Source May Live
| Written as | Read from |
|---|---|
"https://website.com/z.svg" | Fetched over HTTP or HTTPS, exactly as FETCH would fetch it. |
"/root/letters/f.png" | Your own namespace. |
"/mounted/letters/c.png" | Your /mounted storage - the second permanent location in your namespace, alongside /root, for keeping bulk data apart from your working files. It is sized by plan and the Free plan has none; see Namespace Storage and Quotas & Pricing. |
"/external/letters/c.png" | A remote file server bound into the namespace for the life of the script with EXTERNAL BIND - see FTP & External Storage. |
Source Formats
| Extension | How it becomes a glyph |
|---|---|
.svg | Its geometry is read straight through as outlines. Paths and the basic shapes - rect, circle, ellipse, line, polyline, polygon - are all understood. This is the highest-fidelity source: nothing is traced and nothing is approximated. |
.png | Traced to outlines. Where the image carries transparency, the alpha channel defines the shape; where it does not, darkness does. |
.ico | Traced as above. An .ico holds several sizes; the largest is used, because tracing a bigger image yields a cleaner outline. |
An SVG is worth preferring wherever you have one. A traced raster is a faithful outline of the pixels it was given, which means a small or soft source traces to a slightly ragged edge - trace from the largest art you have.
What SET Receives
Both verbs answer an object describing what was built, so a script can check the result instead of assuming it.
| Key | Value |
|---|---|
path | Where the font was written. |
name | The family name in the font. |
format | "otf", "ttf" or "woff2". |
characters | An array of the characters the font now draws. |
flattened | An array of characters whose source carried more than one colour. They are in the font, in a single colour. |
skipped | An array of messages, one per entry that could not be drawn. Empty when every character was built. |
NEW FONT NAME "myfont" DEFINE ["a" AS "/root/letters/a.svg" AND "b" AS "/root/letters/b.png"] SET ?font
AFTER IF COUNT ?font("skipped") IS GREATER THAN 0
OPEN
EMIT "Some characters did not build:"
AFTER FOREACH ?font("skipped") SET ?why
OPEN
EMIT ?why
CLOSE
CLOSE
OR EMIT "Built " & COUNT ?font("characters") & " characters into " & ?font("path")
skipped. Only when no character could be drawn does the verb raise an error - a font with nothing in it is never written.FONT UPDATE
FONT UPDATE takes the path of a font that already exists and changes the characters you name, leaving every other character in that font exactly as it was. A character already in the font is replaced; one that is not is added.
FONT UPDATE "/root/myfont.otf" DEFINE ["x" AS "https://website.com/x.png"] SET ?font
AFTER EMIT ?font("characters")
The font is rewritten where it stands. Add INTO to keep the original untouched and write the updated font somewhere else:
FONT UPDATE "/root/myfont.otf" DEFINE ["x" AS "/root/letters/x.svg"] INTO "/root/myfont-v2.otf" SET ?font
TYPE is accepted on FONT UPDATE as well, which converts the font on the way out - read an .otf, write a .woff2 for the web:
FONT UPDATE "/root/myfont.otf" TYPE "woff2" INTO "/root/myfont.woff2" DEFINE ["x" AS "/root/letters/x.svg"] SET ?web
Output Formats
| TYPE | File | Use it for |
|---|---|---|
"otf" | OpenType, cubic outlines | The default. Installing on a machine, embedding in a document or a deck. |
"ttf" | TrueType, quadratic outlines | Where a tool or platform asks for TrueType specifically. |
"woff2" | Web Open Font Format 2 | Serving over the web. Compressed, and the smallest of the three. |
The Em Box
A font measures everything against the em - the square a character is drawn inside. Every glyph built here is fitted into that square: scaled up or down until it fits, with its proportions kept, and placed with a small breathing space on each side so that two characters set next to each other do not touch. A wide picture therefore produces a wide character and a narrow picture a narrow one, which is what makes a character map of mixed artwork set as type rather than as a row of equal-sized tiles.
AS DRAWN - Keeping Each Character Where It Was Drawn
Fitting suits a set of icons or a logo font, where every picture should fill the em. It does not suit an alphabet: a full stop fitted to the em is as tall as a capital, and a lowercase x stands as high as an H. Text set in it reads as a row of tiles.
With AS DRAWN, each picture's whole canvas is the em instead - the SVG's view box, or a PNG's full width and height. The top of the canvas is the top of the em and its bottom is the bottom of the descender space, so the bottom fifth of every canvas is below the baseline: draw every character on canvases of the same size, sit them on that line, and the font keeps their sizes and heights exactly. A full stop stays small and low, a g keeps its descender, and capitals and lowercase keep the heights you gave them. Each character keeps its own drawn width, with the same small breathing space on each side.
(* every source is 500 x 500, the baseline 100 up from the bottom *)
NEW FONT NAME "handwriting" TYPE "woff2" AS DRAWN
DEFINE ["a" AS "/root/glyphs/a.png" AND "g" AS "/root/glyphs/g.png" AND "." AS "/root/glyphs/dot.png" AND " " AS "/root/glyphs/space.png"]
SET ?font
An empty canvas is accepted AS DRAWN and becomes a blank character a quarter of an em wide - which is how a font gets its space. Without AS DRAWN an empty source is still skipped, since there is nothing to fit. FONT UPDATE takes AS DRAWN too, placing new characters against the font's own ascender and descender so they sit with the ones already there.
Characters You Did Not Define
A font built here draws the characters you defined and nothing else. Any other character falls to the font's .notdef glyph, which is blank - so text set in the font shows your characters and leaves gaps where it has none, rather than showing a box or refusing to render. Define every character you intend to set, including the space if you want one.
Using the Font
Once written, the file is an ordinary font and an ordinary file in your namespace. Serve it from a hosted site with an @font-face rule, embed it in a deck with Presentations, set a document in it with Documents & Rich Text, or hand it to a visitor with File Manager.
NEW FONT NAME "myfont" TYPE "woff2" INTO "/root/site/myfont.woff2"
DEFINE ["a" AS "/root/letters/a.svg" AND "b" AS "/root/letters/b.svg" AND "c" AS "/root/letters/c.svg"]
SET ?font
AFTER FILE WRITE "/root/site/font.css" AS "@font-face{font-family:'myfont';src:url('/myfont.woff2') format('woff2');}"
AFTER EMIT "Serving " & ?font("path")
Errors
| Condition | What happens |
|---|---|
| A key is longer than one character | That entry is skipped and reported in skipped. A font maps characters, so "ab" names no single character. |
| A source cannot be read or fetched | That entry is skipped and reported. |
| A source holds no shape | That entry is skipped and reported - an empty image has no outline to trace. With AS DRAWN it becomes a blank character instead. |
| No character could be drawn | The verb errors and no file is written. |
TYPE is not one of the three | The verb errors, naming what is accepted. |
FONT UPDATE on a path that is not there | The verb errors. Use NEW FONT to make one. |