Skip to content
Talk to an engineerRequest access

Display list

What a MathLayout paints — every display item class, the fills, transforms and source metadata they carry, and the path commands of glyph outlines.

renderLatex and layoutFormula return a MathLayout whose items are the display list: everything there is to paint. Items are positioned in em of the base font size, x to the right and y down, with the origin on the formula’s baseline at its left edge; multiply by the font size for pixels. An item’s color is null when it takes the renderer’s current colour, and its info (an ItemInfo) ties it back to the source: the span and the stable id of the node that produced it.

In Flutter, MathPainter paints the list. Anywhere else, read it yourself. DisplayItem is sealed, so a switch can match every item class:

final layout = renderLatex(r'\frac{a}{b} + \sqrt{x}');
for (final item in layout.items) {
switch (item) {
case GlyphItem(:final x, :final y, :final size):
print('glyph at ($x, $y), scale $size'); // outline: item.outline
case RectItem(:final x, :final y, :final width, :final height):
print('rule $x $y $width × $height');
case PathItem(:final commands):
print('path of ${commands.length} commands');
default:
print(item.runtimeType);
}
}

A GlyphItem’s outline is a GlyphPath in font units with y up: scale it by size / font.unitsPerEm, flip y, and move it to (x, y). Path commands in items (PathItem, FillItem) are already in em with y down.

Class Description
GlyphItem A glyph of a math font, drawn from its outline.
RectItem A filled rectangle (fraction bars, radical overbars, rules, table lines).
LineItem A stroked straight line (strikes, dashed table rules).
PathItem A general path (circles, rounded boxes, angle marks), already in item coordinates (em, y down).
TextItem A run of text, shaped by the renderer’s text engine (or by the core’s fallback, which then also supplies glyphs).
ImageItem An image (\includegraphics).
FillItem A filled path (y down, em), optionally clipped to clip: colour-font glyphs (COLR) are made of these.
CompositeItem Two groups of items composited: source onto backdrop by mode, the result over what is below (COLR v1 PaintComposite).

A laid-out piece of a formula: a size and the items that paint it.

More about Box

All lengths are in em of the base font size. height is above the baseline, depth below it (both usually ≥ 0). Items are positioned relative to the box origin: left edge, on the baseline, y down.

Constructor Description
Box(width, height, depth, items, {italic = 0, skew = 0}) Creates a box.
Box.empty({double width = 0, double height = 0, double depth = 0}) An empty box of the given size.
Box.kern(double width) Horizontal space of width.
Field Type Default Description
width double required Advance width.
height double required Extent above the baseline.
depth double required Extent below the baseline.
italic double 0 Italic correction of the last glyph (for script placement).
skew double 0 Horizontal accent offset (top accent attachment minus centre).
items List<DisplayItem> required Painted items.
Member Type Description
totalHeight double Height plus depth.
raise(double amount) Box This box raised by amount (negative lowers).
withSize({…}) Box This box with different dimensions but the same items.
invisible Box This box with no items (phantom).
itemsAt(double dx, double dy) Iterable<DisplayItem> Items moved by dx, dy.
island(int id) Box Marks every item as one left-to-right island (see ItemInfo.island).
decorate({LatexColor? color, String? addClass, String? link}) Box Applies color to items without a colour and adds metadata.
static hbox(List<Box> boxes) Box Places boxes side by side on a common baseline.
static vbox(List<(Box, double, double)> children, {double? width}) Box Stacks children vertically. Each child is (box, baseline shift down from the result’s baseline, x offset). The result’s baseline is 0.
withSize: more
Box withSize({
double? width,
double? height,
double? depth,
double? italic,
double? skew,
})

Metadata every painted item carries back to the source.

Constructor Description
ItemInfo({span, String? nodeId, classes = const [], link, island}) Creates metadata.
ItemInfo.deferred({span, required String? Function() nodeId}) Metadata whose nodeId is computed by nodeId when first read: numbering every node of a formula costs more than laying it out, and most items are never asked for their id.
Field Type Default Description
span SourceSpan? Source span of the node that produced the item.
classes List<String> const [] \htmlClass / \class names in effect.
link String? \href target in effect.
island int? Items sharing an island id keep their left-to-right order when a formula is mirrored for right-to-left math (numbers, Latin names).
Member Type Description
static none = ItemInfo() No metadata.
nodeId String? Stable id of that node (see ParseResult.idOf).
wrap({String? addClass, String? link}) ItemInfo A copy with more classes or a link.
inIsland(int id) ItemInfo A copy in island id.
withSpan(SourceSpan span) ItemInfo A copy for another span of the same node.

Something to paint. Coordinates are in em of the base font size, x to the right, y down, origin on the formula’s baseline at its left edge.

Field Type Default Description
color LatexColor? Colour; null means the renderer’s current colour.
info ItemInfo Source metadata.
Member Type Description
translate(double dx, double dy) DisplayItem This item moved by (dx, dy).
decorate({LatexColor? color, String? addClass, String? link}) DisplayItem This item with color if it has none yet, and extra metadata.

A glyph of a math font, drawn from its outline.

Constructor Description
GlyphItem(font, glyph, x, y, size, {…}) Creates a glyph.
GlyphItem: more
const GlyphItem(
this.font,
this.glyph,
this.x,
this.y,
this.size, {
this.mirrorable = false,
this.flipped = false,
LatexColor? color,
ItemInfo info = ItemInfo.none,
})
Field Type Default Description
font MathFont required The font.
glyph int required Glyph id.
x double required Left of the glyph origin.
y double required Baseline.
size double required Scale: 1 = base font size.
mirrorable bool false Whether the glyph has a direction (delimiters, radicals, ∑, arrows, <…) and is drawn mirrored in right-to-left math.
flipped bool false Draw mirrored left-to-right: the outline is reflected about the middle of the glyph’s advance.
Member Type Description
outline GlyphPath The outline in font units, y up. To paint: scale by size / font.unitsPerEm, flip y, and move to (x, y); when flipped, also reflect x within the advance (x' = advance - x).
advance double The glyph’s advance in em at size.
withFlip({required bool flipped, double? x}) GlyphItem A copy with different mirroring.

A filled rectangle (fraction bars, radical overbars, rules, table lines).

Constructor Description
RectItem(x, y, width, height, {…}) Creates a rectangle.
RectItem: more
const RectItem(
this.x,
this.y,
this.width,
this.height, {
LatexColor? color,
ItemInfo info = ItemInfo.none,
})
Field Type Default Description
x double required Left.
y double required Top.
width double required Width.
height double required Height.

A stroked straight line (strikes, dashed table rules).

Constructor Description
LineItem(x1, y1, x2, y2, thickness, {…}) Creates a line.
LineItem: more
const LineItem(
this.x1,
this.y1,
this.x2,
this.y2,
this.thickness, {
this.dashed = false,
LatexColor? color,
ItemInfo info = ItemInfo.none,
})
Field Type Default Description
x1 double required Start x.
y1 double required Start y.
x2 double required End x.
y2 double required End y.
thickness double required Stroke width.
dashed bool false Dashed.

A general path (circles, rounded boxes, angle marks), already in item coordinates (em, y down).

Constructor Description
PathItem(commands, {…}) Creates a path.
PathItem.glyph(GlyphSource source, {…}) A glyph’s outline under source’s transform (a turned, reflected, scaled or stretched letter), filled; source is kept so a renderer that draws glyphs itself can draw the glyph rather than the path.
PathItem: more
const PathItem(
this.commands, {
this.stroke,
this.fill = false,
this.source,
LatexColor? color,
ItemInfo info = ItemInfo.none,
})
PathItem.glyph: more
PathItem.glyph(
GlyphSource this.source, {
LatexColor? color,
ItemInfo info = ItemInfo.none,
})
Field Type Default Description
source GlyphSource? required The glyph this path is the outline of, when it is exactly one filled glyph outline; null for anything drawn. Either may be drawn: they are the same shape.
commands List<PathCommand> required Commands, y down.
stroke double? Stroke width, or null for no stroke.
fill bool false Whether the path is filled.

A glyph placed by an arbitrary affine map: transform takes its outline from font units (y up) to the item’s em space (y down).

Constructor Description
GlyphSource(font, glyph, transform) Creates a source.
Field Type Default Description
font MathFont required The font.
glyph int required Glyph id.
transform Affine required Font units to em.
Member Type Description
moved(double dx, double dy) GlyphSource The same glyph moved by (dx, dy) em.
mapped(Affine outer) GlyphSource The same glyph with outer applied after its transform.

Font request for a text run.

Constructor Description
TextFont({…}) Creates a text font request.
TextFont: more
const TextFont({
this.family = TextFamily.roman,
this.bold = false,
this.italic = false,
this.smallCaps = false,
this.slanted = false,
})
Field Type Default Description
family TextFamily TextFamily.roman Family.
bold bool false Bold weight.
italic bool false Italic or slanted.
smallCaps bool false Small capitals.
slanted bool false Slanted (\textsl): the upright face sheared by slant — renderers apply the shear around the run’s baseline.
Member Type Description
static roman = TextFont() Default roman text.
static slant = 1 / 6 The shear of slanted text: x moves by this much per unit of height (Computer Modern’s slanted fonts lean about 9.5°).
copyWith({…}) TextFont A copy with changes.
copyWith: more
TextFont copyWith({
TextFamily? family,
bool? bold,
bool? italic,
bool? smallCaps,
bool? slanted,
})

Text font families.

Value Description
roman Serif (\textrm).
sans Sans serif (\textsf).
mono Monospace (\texttt, \verb).

A run of text, shaped by the renderer’s text engine (or by the core’s fallback, which then also supplies glyphs).

Constructor Description
TextItem(text, font, x, y, size, width, {…}) Creates a text run.
TextItem: more
const TextItem(
this.text,
this.font,
this.x,
this.y,
this.size,
this.width, {
this.glyphs,
this.rtl,
this.reflected = false,
LatexColor? color,
ItemInfo info = ItemInfo.none,
})
Field Type Default Description
reflected bool false Drawn mirrored left to right about the middle of its width (\reflectbox).
rtl bool? Base direction of the run’s paragraph: true right-to-left, false left-to-right, null from its first strong character (LayoutOptions.textDirection).
text String required The text.
font TextFont required Requested font.
x double required Left.
y double required Baseline.
size double required Scale: 1 = base font size.
width double required Measured width.
glyphs List<DisplayItem>? What the pure-Dart shaper drew for the run, positioned relative to its origin: glyphs, and for colour fonts (emoji) FillItems and ImageItems; null when the host shaper measured the run.
Member Type Description
withReflected(bool reflected, {double? x}) TextItem A copy mirrored or not, at x when given.

An image (\includegraphics).

Constructor Description
ImageItem(source, x, y, width, height, {…}) Creates an image.
ImageItem: more
const ImageItem(
this.source,
this.x,
this.y,
this.width,
this.height, {
this.alt,
this.reflected = false,
ItemInfo info = ItemInfo.none,
})
Field Type Default Description
reflected bool false Drawn mirrored left to right (\reflectbox).
source String required URL.
x double required Left.
y double required Top.
width double required Width.
height double required Height.
alt String? Alternative text.
Member Type Description
withReflected(bool reflected, {double? x}) ImageItem A copy mirrored or not, at x when given.

An affine map (x, y) → (a·x + c·y + e, b·x + d·y + f).

Constructor Description
Affine(a, b, c, d, e, f) Creates a map.
Field Type Default Description
a double required Coefficients.
b double required Coefficients.
c double required Coefficients.
d double required Coefficients.
e double required Coefficients.
f double required Coefficients.
Member Type Description
static identity = Affine(1, 0, 0, 1, 0, 0) The identity.
apply(double x, double y) (double, double) The image of (x, y).
times(Affine inner) Affine This map after inner: this(inner(p)).
moved(double dx, double dy) Affine This map, then a move by (dx, dy).
path(List<PathCommand> commands) List<PathCommand> The path commands mapped.

How a gradient continues past its ends.

Value Description
pad The end colours continue.
repeat The gradient repeats.
reflect The gradient repeats, mirrored every other time.

One colour stop of a gradient; a null colour is the current colour.

typedef ColorStop = (double offset, LatexColor? color);

How a FillItem is painted.

One colour (null: the item’s colour, or the current colour).

Constructor Description
SolidFill([color]) Creates a solid fill.
Field Type Default Description
color LatexColor? The colour.

A linear gradient from (x0, y0) to (x1, y1) in gradient space, which transform maps to item coordinates.

Constructor Description
LinearFill(x0, y0, x1, y1, stops, {…}) Creates a linear gradient.
LinearFill: more
const LinearFill(
this.x0,
this.y0,
this.x1,
this.y1,
this.stops, {
this.extend = GradientExtend.pad,
this.transform = Affine.identity,
})
Field Type Default Description
x0 double required Start and end points.
y0 double required Start and end points.
x1 double required Start and end points.
y1 double required Start and end points.
stops List<ColorStop> required Stops, offsets from 0 (start) to 1 (end), ascending.
extend GradientExtend GradientExtend.pad Beyond the ends.
transform Affine Affine.identity Gradient space to item coordinates.

A two-circle radial gradient in gradient space, which transform maps to item coordinates.

Constructor Description
RadialFill(x0, y0, r0, x1, y1, r1, stops, {…}) Creates a radial gradient.
RadialFill: more
const RadialFill(
this.x0,
this.y0,
this.r0,
this.x1,
this.y1,
this.r1,
this.stops, {
this.extend = GradientExtend.pad,
this.transform = Affine.identity,
})
Field Type Default Description
x0 double required Start circle.
y0 double required Start circle.
r0 double required Start circle.
x1 double required End circle.
y1 double required End circle.
r1 double required End circle.
stops List<ColorStop> required Stops, offsets from 0 (start circle) to 1 (end circle), ascending.
extend GradientExtend GradientExtend.pad Beyond the circles.
transform Affine Affine.identity Gradient space to item coordinates.

A sweep (conic) gradient around (cx, cy) in gradient space, from startAngle to endAngle (radians, counter-clockwise from +x with y up, as in fonts), which transform maps to item coordinates.

Constructor Description
SweepFill(cx, cy, startAngle, endAngle, stops, {…}) Creates a sweep gradient.
SweepFill: more
const SweepFill(
this.cx,
this.cy,
this.startAngle,
this.endAngle,
this.stops, {
this.extend = GradientExtend.pad,
this.transform = Affine.identity,
})
Field Type Default Description
cx double required Centre.
cy double required Centre.
startAngle double required Where the colour line starts and ends, in radians.
endAngle double required Where the colour line starts and ends, in radians.
stops List<ColorStop> required Stops, offsets from 0 (start angle) to 1 (end angle), ascending.
extend GradientExtend GradientExtend.pad Beyond the ends.
transform Affine Affine.identity Gradient space to item coordinates.

A filled path (y down, em), optionally clipped to clip: colour-font glyphs (COLR) are made of these.

Constructor Description
FillItem(commands, fill, {…}) Creates a fill.
FillItem: more
const FillItem(
this.commands,
this.fill, {
this.clip,
LatexColor? color,
ItemInfo info = ItemInfo.none,
})
Field Type Default Description
commands List<PathCommand> required The area to fill.
fill Fill required Its paint.
clip List<PathCommand>? Only the part inside this path is painted.
Member Type Description
mapped(Affine m) FillItem A copy with every coordinate (paths and gradient) mapped by m.

How a CompositeItem’s source combines with its backdrop: the Porter-Duff operators and the blend modes of CSS compositing, in the order of COLR v1’s CompositeMode.

Value Description
clear Nothing.
src The source only.
dest The backdrop only.
srcOver The source over the backdrop.
destOver The backdrop over the source.
srcIn The source where the backdrop is.
destIn The backdrop where the source is.
srcOut The source where the backdrop is not.
destOut The backdrop where the source is not.
srcAtop The source where the backdrop is, over the backdrop.
destAtop The backdrop where the source is, over the source.
xor Each where the other is not.
plus The sum of both.
screen Blend modes (source over, its colour blended with the backdrop’s).
overlay See screen.
darken See screen.
lighten See screen.
colorDodge See screen.
colorBurn See screen.
hardLight See screen.
softLight See screen.
difference See screen.
exclusion See screen.
multiply See screen.
hue The non-separable blend modes.
saturation See hue.
color See hue.
luminosity See hue.

Two groups of items composited: source onto backdrop by mode, the result over what is below (COLR v1 PaintComposite).

Constructor Description
CompositeItem(backdrop, source, mode, {…}) Creates a composite.
CompositeItem: more
const CompositeItem(
this.backdrop,
this.source,
this.mode, {
LatexColor? color,
ItemInfo info = ItemInfo.none,
})
Field Type Default Description
backdrop List<DisplayItem> required What is composited onto.
source List<DisplayItem> required What is composited.
mode CompositeMode required How.
Member Type Description
map(DisplayItem Function(DisplayItem) f) CompositeItem This composite with f applied to every item of both groups.

Outlines and paths are lists of PathCommands.

Class Description
MoveTo Starts a new contour.
LineTo Straight line.
QuadTo Quadratic Bézier (TrueType outlines).
CubicTo Cubic Bézier (CFF outlines).
ClosePath Closes the current contour.

A command of a glyph outline. Coordinates are in font units, y up.

Starts a new contour.

Constructor Description
MoveTo(x, y) Creates a move.
Field Type Default Description
x double required Target x.
y double required Target y.

Straight line.

Constructor Description
LineTo(x, y) Creates a line.
Field Type Default Description
x double required Target x.
y double required Target y.

Quadratic Bézier (TrueType outlines).

Constructor Description
QuadTo(cx, cy, x, y) Creates a quadratic curve.
Field Type Default Description
cx double required Control point x.
cy double required Control point y.
x double required Target x.
y double required Target y.

Cubic Bézier (CFF outlines).

Constructor Description
CubicTo(c1x, c1y, c2x, c2y, x, y) Creates a cubic curve.
Field Type Default Description
c1x double required First control point x.
c1y double required First control point y.
c2x double required Second control point x.
c2y double required Second control point y.
x double required Target x.
y double required Target y.

Closes the current contour.

Constructor Description
ClosePath() Creates a close.

An axis-aligned rectangle in font units, y up.

Constructor Description
GlyphBounds(xMin, yMin, xMax, yMax) Creates bounds.
Field Type Default Description
xMin double required Left edge.
yMin double required Bottom edge (negative below the baseline).
xMax double required Right edge.
yMax double required Top edge.
Member Type Description
static empty = GlyphBounds(0, 0, 0, 0) Empty bounds at the origin (space glyphs).

A glyph outline.

Constructor Description
GlyphPath(commands) Creates a path from commands.
Field Type Default Description
commands List<PathCommand> required The commands, in order.
Member Type Description
bounds GlyphBounds Tight bounds of the ink, including curve extrema.
isEmpty bool Whether there is no ink.
mirrored(double width) GlyphPath This outline reflected left-to-right within an advance of width font units (x' = width - x).
toSvgPathData({double scale = 1, double dx = 0, double dy = 0}) String SVG path data (y flipped to screen coordinates, scaled by scale).