layout

package
v1.17.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: BSD-3-Clause Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package layout lays out paragraphs: it turns the styled text of a ui.ParagraphBuilder into lines of shaped glyphs with go-text. The steps are those of SPEC §10:

  1. the text is split into runs by bidi level, script, style and font (with fallback through text.Collection);
  2. the runs are shaped with HarfBuzz;
  3. the lines are broken (UAX #14) honoring the width, the maximum number of lines and the ellipsis;
  4. each line is reordered for bidi;
  5. the text is aligned and justified, and the lines take their height from the fonts, the style heights and the strut;
  6. the metrics (baselines, line metrics, intrinsic widths) are computed.

Offsets into the text are UTF-8 byte offsets (SPEC §12.10).

Flutter: engine/src/flutter/third_party/txt (libtxt) and Skia's skparagraph module

Index

Constants

View Source
const DoubleDecorationSpacing = 3.0

DoubleDecorationSpacing is the distance between the two lines of a double decoration.

Flutter: engine/src/flutter/third_party/skia/modules/skparagraph/src/Decorations.cpp kDoubleDecorationSpacing

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	// Start and End are the byte range of the text that the cluster covers.
	Start, End int
	// X0 and X1 are the horizontal extent of the cluster's advance, in paragraph coordinates, and Baseline is the y of the
	// baseline of its line.
	X0, X1, Baseline float64
	// RTL says that the cluster is in a right-to-left run.
	RTL bool
	// Size is the font size of the cluster, and Ascent and Descent the font's metrics at that size (both positive).
	Size, Ascent, Descent float64
	// Underline, Strike and Overline are the distances of the centers of the decoration lines below the baseline
	// (negative is above it), and UnderlineThickness and StrikeThickness their thicknesses.
	Underline, Strike, Overline         float64
	UnderlineThickness, StrikeThickness float64
	// Glyphs are what draws the cluster.
	Glyphs []ClusterGlyph
}

Cluster is a cluster of a laid-out paragraph with the glyphs that draw it, for a caller that places the glyphs itself (SVG text, which positions each character).

Flutter: no counterpart

type ClusterGlyph

type ClusterGlyph struct {
	// Path is the outline, with its origin at the pen position and y growing down; nil for a glyph with no outline or a
	// color glyph.
	Path *ui.Path
	// Picture is a color glyph (an emoji) drawn with Matrix, or nil.
	Picture *ui.Picture
	Matrix  *ui.Matrix4
	// Origin is where the origin of Path is, in paragraph coordinates.
	Origin ui.Offset
}

ClusterGlyph is one glyph of a Cluster.

Flutter: no counterpart

type Clusterer

type Clusterer interface {
	// Clusters returns the clusters of the laid-out paragraph in the order of the text.
	Clusters() []Cluster
}

Clusterer is implemented by the paragraphs that this package lays out: the clusters of the text in logical order.

Flutter: no counterpart

type DecorationSegment

type DecorationSegment struct {
	// Line is the line the segment is on.
	Line int
	// Kind is one of TextDecorationUnderline, TextDecorationOverline and TextDecorationLineThrough.
	Kind ui.TextDecoration
	// Style is how the line is drawn: solid, double, dotted, dashed or wavy.
	Style ui.TextDecorationStyle
	// Color is the color of the line.
	Color ui.Color
	// X0 and X1 are the horizontal extent of the line.
	X0, X1 float64
	// Y is the vertical center of the line (of the first line, for a double decoration).
	Y float64
	// Thickness is the thickness of the line.
	Thickness float64
	// FontSize is the size of the font of the text, for the shape of dotted, dashed and wavy lines.
	FontSize float64
}

DecorationSegment is one line of a text decoration: an underline, an overline or a line through a stretch of text of one style on one line, ready to draw. The positions are in paragraph coordinates.

Flutter: engine/src/flutter/third_party/skia/modules/skparagraph/src/Decorations.cpp Decorations

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is the text engine: it makes paragraphs from the fonts of a text.Collection. It implements ui.ParagraphFactory. An Engine and its paragraphs are for the UI thread only (SPEC §13).

Flutter: engine/src/flutter/lib/ui/text/paragraph_builder.cc ParagraphBuilder

func NewEngine

func NewEngine(ctx context.Context, fonts *text.Collection, opts ...EngineOpts) *Engine

NewEngine makes a text engine over a font collection. ctx bounds the loading of font files, which happens while a paragraph is built. More than one options value panics with MultipleOptions.

Flutter: no counterpart

func (*Engine) BuildParagraph

func (e *Engine) BuildParagraph(c *ui.ParagraphContent) ui.ParagraphLayout

BuildParagraph shapes the content (ui.ParagraphFactory). The intrinsic widths are known at once; everything else needs a layout, which Layout makes for a width. A paragraph that is asked before it is laid out is laid out with an infinite width first.

func (*Engine) FontMetrics

func (e *Engine) FontMetrics(style *ui.ResolvedTextStyle) ui.FontMetrics

FontMetrics measures the face that the style draws the digit "0" with, the way a paragraph of one line in the style does (ui.FontMetricsEngine): the ascent, descent and height are those of the line of a paragraph of "0" (the style's height and the paragraph defaults applied), the leading is the font's line gap at the size, and the advance is the width of the "0". It is for the UI thread.

Flutter: no counterpart

func (*Engine) InstalledFontFamilies

func (e *Engine) InstalledFontFamilies() []string

InstalledFontFamilies lists the families of the system's, bundled and loaded fonts, sorted without regard to case. When the system's fonts cannot be listed, the others are.

Flutter: no counterpart

func (*Engine) LoadFontFromList

func (e *Engine) LoadFontFromList(list []byte, family string) error

LoadFontFromList adds a font to the engine's collection under a family name (the family inside the font when family is empty), so that styles can name it. What the engine resolved before is forgotten, so a family that was missing now finds the font. It fails like text.Collection.AddFont. It is for the UI thread.

Flutter: dart:ui loadFontFromList

func (*Engine) ResolveFont

func (e *Engine) ResolveFont(family string, weight ui.FontWeight, style ui.FontStyle) (ui.ResolvedFont, bool)

ResolveFont says which face the family resolves to: the first font of the family that loads, in the order of text.Collection.Match (the loaded fonts, the closest to the weight and slant first, then the bundled one, then the system's). It is false when the family has none, so a family that nothing has does not resolve to the system's default font.

Flutter: no counterpart

type EngineOpts

type EngineOpts struct {
	// OnFontError, when not nil, receives the problems with finding or loading a
	// font; the layout goes on with the next font.
	OnFontError func(error)
}

EngineOpts are the optional parameters of NewEngine.

Flutter: no counterpart

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL