the ctx protocol

The ctx text format is a direct serialization of the API. This text format is more stable than the internal binary representation, though neither of them are feature complete/frozen yet. This protocol permits sending rendering commands over serial, ptys and other forms of network - enabling remote and/or sandboxed rendering.

This format maps to the C API if you turn camelCase into snake_case, and prefix each command with ctx_.

When a keyword is parsed the parser expects a series of commands of the same type, following arguments will be consumed in chunks as the number of arguments fill up, until a command change. Each command also has a short one-byte long name, where applicable these match the SVG path data format.

graygraysets gray source, and color model
grayagray alphasets gray alpha source, and color model
rgbr g bsets rgb source
rgbar g b argb alpha color source
cmykc m y kcmyk color source
cmykac m y k acmyk alpha color source
drgbr g bsets rgb source, in device space
drgbar g b argb alpha color source, in device space
dcmykc m y kcmyk color source, in device space
dcmykac m y k acmyk alpha color source, in device space
a relArcTo5
b clip
c relCurveTo6
g save
e translatex y
f linearGradientx0 y0 x1 y1
h relHorLinex
ka globalAlphaalpha
kb textBaselinealphabetic | top | bottom | middle | hanging | ideographic
kB blendModenormal | multiply | screen | overlay | darken | lighten | colorDodge | colorBurn | hardLight | softLight | difference | exclusion | hue | saturation | color | luminosity | divide | addition | subtract
kc lineCap capnone | round | square
kC shadowColorcolor componentsworks like gradientAddStop
kf fontSizefont_size
kj lineJoin joinbevel | round | miter0 1 or 2 are also valid values
kl miterLimitmiter_limit
km compositingModesourceOver | copy | clear | sourceIn | sourceOut | sourceAtop | destinationOver | destination | destinationIn | destination_out | destinationAtop | xor
ks shadowBlurblur_radius
kt textAlignstart | end | center | left | right
kw lineWidthline_width
kx shadowOffsetXhorizontal_offset
ky shadowOffsetYvertical_offset
l relLineTox y
m relMoveTox y
n font"font name"
o radialGradient6
p gradientAddStop addStoppos R G B Aarguments depend on current color model, you can change the color model without setting a color by specifying a color without arguments.
q relQuadTocx cy x y
r rectangle rectx y width height
s relSmoothTocx cy x y
t relSmoothQuadTox y
u strokeText"utf8-string"
v relVerLiney
w glyphunichardraws a single unicode character, the character no is currently passed in as decimal. (might be made internal), since a text string duplicates the API.
x text"utf8-string" | kerningInterspersed with utf8 sequences of text numbers can appear that shift the horizontal position.
y identity
z closePath
A arcTox1 y1 x2 y2 radius
B arcx y radius angle1 angle2 direction
C curveTocx1 cy1 cx2 cy2 x y
E stroke
F fill
G restore
H horLineTox
J rotateradians
L lineTox y
M moveTox y
N beginPath
O scalescale_x scale_y
Q quadTocx cy x y
S smoothTocx cy x y
T smoothQuadTox y
U reset
V verLineToy
X exit
X done
Z closePath
W transforma b c d e fapplies the transformation matrix
{ startGroupstarts a compositing group
} endGroupends a compositing group, and blends and composites it with the content before the group using the now current compositing mode, blending mode and global alpha.

Detailed syntax description

The language consists of a stream of words, numbers and strings, optionally separated by white space. The characters ,=(); are also treated as white-space. Words are substrings consisting of one or more characters in the ranges a-z and A-Z. Numbers are sequences of 0-9. Numbers can be followed by the suffixes % or @, indicating that units of percent canvas width/height should be used or a global em / cell-size. ^ is equivalent to CSS vh, and ~ vw, this can be used to override the automatic choice done by %, which favors height for dimensions that are independent of x/y like lineWidth and shadowBlur. Strings are raw binary UTF8 contained in ' or " pairs. "\n\r" etc from C are available for escaping newlines, though they can also be directly included in the string. # introduces a comment and the rest of the line is ignored.

Blobs can also be represented as a85