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
- type DecorationSegment
- type Engine
- func (e *Engine) BuildParagraph(c *ui.ParagraphContent) ui.ParagraphLayout
- func (e *Engine) InstalledFontFamilies() []string
- func (e *Engine) LoadFontFromList(list []byte, family string) error
- func (e *Engine) ResolveFont(family string, weight ui.FontWeight, style ui.FontStyle) (ui.ResolvedFont, bool)
- type EngineOpts
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 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) InstalledFontFamilies ¶
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 ¶
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