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:
- the text is split into runs by bidi level, script, style and font (with fallback through text.Collection);
- the runs are shaped with HarfBuzz;
- the lines are broken (UAX #14) honoring the width, the maximum number of lines and the ellipsis;
- each line is reordered for bidi;
- the text is aligned and justified, and the lines take their height from the fonts, the style heights and the strut;
- 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 ¶
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 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 result is laid out at once with an infinite width, so that the intrinsic widths are known; Layout lays it out for a width.
func (*Engine) LoadFontFromList ¶
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
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