display

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0, MIT Imports: 12 Imported by: ? 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 display defines the immutable output contract for UI hosts.

Index

Constants

View Source
const AltDescriptionVersion = 2

AltDescriptionVersion is the current structured accessibility schema.

View Source
const DefaultMinContrast float32 = 4.5

DefaultMinContrast is the WCAG AA contrast threshold used when ColorPolicy.MinContrast is zero.

View Source
const FormulaTagLine = -1

FormulaTagLine identifies a tag that belongs to the complete formula rather than one rendered display line or source row.

View Source
const NoPath = -1

NoPath marks an item that does not reference Box.Paths.

Variables

View Source
var ErrCannotSplit = errors.New("display: cannot split box")

ErrCannotSplit reports a box that cannot be divided into independent inline geometry.

View Source
var ErrInvalidAlt = errors.New("display: invalid alternative text")

ErrInvalidAlt reports malformed alternative text.

View Source
var ErrInvalidAltDescription = errors.New("display: invalid alternative description")

ErrInvalidAltDescription reports a malformed structured accessibility description.

View Source
var ErrInvalidBox = errors.New("display: invalid box")

Functions

This section is empty.

Types

type Align

type Align uint8

Align is horizontal placement within a constrained display line frame. Inline layout and display layout with MaxWidth zero ignore it.

const (
	AlignStart Align = iota
	AlignCenter
	AlignEnd
)

type Alt

type Alt struct {
	Speech string
	Text   string
	// Description is a versioned, source-independent semantic tree for hosts
	// that localize accessibility output instead of using the English Speech
	// string. Nil is permitted for compatibility with host-constructed Alt
	// values and older callers.
	Description *AltDescription
}

Alt is semantic alternative text derived from the neutral expression tree.

func (Alt) Clone

func (a Alt) Clone() Alt

Clone returns an independent copy of the alternative text.

func (Alt) Equal added in v0.4.0

func (a Alt) Equal(other Alt) bool

Equal reports whether two Alt values contain the same text and structured description.

func (Alt) MarshalCanonical

func (a Alt) MarshalCanonical() ([]byte, error)

MarshalCanonical returns deterministic JSON for alternative-text tests. It is not a stable cross-language protocol.

func (Alt) Validate

func (a Alt) Validate() error

Validate checks that alternative text is valid UTF-8, contains no NUL, and, when present, carries a valid structured description.

func (Alt) ValidateWithLimits added in v0.4.0

func (a Alt) ValidateWithLimits(limits source.Limits) error

ValidateWithLimits checks alternative text against caller-owned traversal and literal-text limits. A zero-value limits uses source.DefaultLimits.

type AltBreakKind added in v0.4.0

type AltBreakKind string

AltBreakKind identifies why a line break is legal.

const (
	AltBreakRelation AltBreakKind = "relation"
	AltBreakBinary   AltBreakKind = "binary"
	AltBreakExplicit AltBreakKind = "explicit"
)

type AltCancelRole added in v0.4.0

type AltCancelRole string

AltCancelRole distinguishes cancellation, negation, and Feynman slash.

const (
	AltCancelStrike   AltCancelRole = "strike"
	AltCancelNegation AltCancelRole = "negation"
	AltCancelSlashed  AltCancelRole = "slashed"
)

type AltColumn added in v0.4.0

type AltColumn struct {
	Align AltColumnAlign `json:"align"`
}

AltColumn records one table column's alignment.

type AltColumnAlign added in v0.4.0

type AltColumnAlign string

AltColumnAlign identifies a table column alignment.

const (
	AltColumnCenter AltColumnAlign = "center"
	AltColumnLeft   AltColumnAlign = "left"
	AltColumnRight  AltColumnAlign = "right"
)

type AltDescription added in v0.4.0

type AltDescription struct {
	Version int      `json:"version"`
	Root    AltNode  `json:"root"`
	Tags    []AltTag `json:"tags,omitempty"`
}

AltDescription is a stable, source-independent semantic description derived from canonical IR. It contains no source ranges, node identities, paint, fonts, or geometry. Hosts map its tokens and literal text payloads to their own locale and accessibility vocabulary.

func (*AltDescription) Clone added in v0.4.0

func (d *AltDescription) Clone() *AltDescription

Clone returns an independent copy of d.

func (*AltDescription) Equal added in v0.4.0

func (d *AltDescription) Equal(other *AltDescription) bool

Equal reports whether two structured descriptions are structurally equal.

func (*AltDescription) MarshalCanonical added in v0.4.0

func (d *AltDescription) MarshalCanonical() ([]byte, error)

MarshalCanonical returns deterministic JSON for a validated structured accessibility description. It is an inspection and golden-test serializer, not an unversioned wire protocol.

func (*AltDescription) Validate added in v0.4.0

func (d *AltDescription) Validate() error

Validate checks the default-limit structural contract.

func (*AltDescription) ValidateWithLimits added in v0.4.0

func (d *AltDescription) ValidateWithLimits(limits source.Limits) error

ValidateWithLimits checks the version, semantic shape, text encoding, node and nesting budgets, and aggregate literal-text budget. A zero-value limits uses source.DefaultLimits.

type AltFlag added in v0.4.0

type AltFlag string

AltFlag carries a stable semantic boolean. Absence means false; a defined positive or negative token records the authored state where needed.

const (
	AltFlagBalanced        AltFlag = "balanced"
	AltFlagBar             AltFlag = "bar"
	AltFlagWeak            AltFlag = "weak"
	AltFlagStretchy        AltFlag = "stretchy"
	AltFlagNaturalFit      AltFlag = "natural-fit"
	AltFlagDotless         AltFlag = "dotless"
	AltFlagExactFrameWidth AltFlag = "exact-frame-width"
	AltFlagCross           AltFlag = "cross"
	AltFlagInverted        AltFlag = "inverted"
	AltFlagCentered        AltFlag = "centered"
	AltFlagCramped         AltFlag = "cramped"
	AltFlagUncramped       AltFlag = "uncramped"
	AltFlagFill            AltFlag = "fill"
	AltFlagBorder          AltFlag = "border"
	AltFlagPhantomWidth    AltFlag = "phantom-width"
	AltFlagPhantomHeight   AltFlag = "phantom-height"
	AltFlagPhantomDepth    AltFlag = "phantom-depth"
)

type AltFontSize added in v0.4.0

type AltFontSize struct {
	Percent float64 `json:"percent"`
}

AltFontSize is an explicit uniform font-size percentage relative to the root host font size. A value of 100 means 100 percent.

type AltFractionRole added in v0.4.0

type AltFractionRole string

AltFractionRole identifies the semantic operation represented by a fraction-shaped node.

const (
	AltFractionOrdinary AltFractionRole = "ordinary"
	AltFractionBinomial AltFractionRole = "binomial"
	AltFractionStacked  AltFractionRole = "stacked"
)

type AltFractionStyle added in v0.4.0

type AltFractionStyle string

AltFractionStyle identifies the geometric fraction construction.

const (
	AltFractionVertical   AltFractionStyle = "vertical"
	AltFractionNoBar      AltFractionStyle = "no-bar"
	AltFractionSkewed     AltFractionStyle = "skewed"
	AltFractionHorizontal AltFractionStyle = "horizontal"
)

type AltMathSize added in v0.4.0

type AltMathSize string

AltMathSize identifies an explicit math-size wrapper.

const (
	AltSizeInherit      AltMathSize = "inherit"
	AltSizeDisplay      AltMathSize = "display"
	AltSizeText         AltMathSize = "text"
	AltSizeScript       AltMathSize = "script"
	AltSizeScriptScript AltMathSize = "script-script"
)

type AltNode added in v0.4.0

type AltNode struct {
	Kind AltNodeKind `json:"kind"`

	// Text is literal source-independent content for glyph, text, operator,
	// delimiter, error, and placeholder nodes. It is not localized prose.
	Text string `json:"text,omitempty"`
	// Code is a stable error or diagnostic token for error nodes.
	Code string `json:"code,omitempty"`

	Variant          AltVariant          `json:"variant,omitempty"`
	FractionRole     AltFractionRole     `json:"fractionRole,omitempty"`
	FractionStyle    AltFractionStyle    `json:"fractionStyle,omitempty"`
	ScriptRole       AltScriptRole       `json:"scriptRole,omitempty"`
	TableRole        AltTableRole        `json:"tableRole,omitempty"`
	CancelRole       AltCancelRole       `json:"cancelRole,omitempty"`
	Position         AltPosition         `json:"position,omitempty"`
	Space            AltSpaceKind        `json:"space,omitempty"`
	SpaceWidth       AltSpaceWidth       `json:"spaceWidth,omitempty"`
	Break            AltBreakKind        `json:"break,omitempty"`
	Sizing           AltSizingKind       `json:"sizing,omitempty"`
	Size             AltMathSize         `json:"size,omitempty"`
	OverlayAlignment AltOverlayAlignment `json:"overlayAlignment,omitempty"`
	RaiseDirection   AltRaiseDirection   `json:"raise,omitempty"`
	FontSize         *AltFontSize        `json:"fontSize,omitempty"`

	Flags   []AltFlag   `json:"flags,omitempty"`
	Parts   []AltPart   `json:"parts,omitempty"`
	Rows    []AltRow    `json:"rows,omitempty"`
	Columns []AltColumn `json:"columns,omitempty"`
}

AltNode is one semantic node. Kind determines which optional fields and child collections are meaningful.

func (AltNode) Clone added in v0.4.0

func (n AltNode) Clone() AltNode

Clone returns a deep copy of n.

type AltNodeKind added in v0.4.0

type AltNodeKind string

AltNodeKind identifies one semantic node in a structured accessibility description. Values are stable protocol tokens, not user-facing prose.

const (
	AltKindRow            AltNodeKind = "row"
	AltKindGlyph          AltNodeKind = "glyph"
	AltKindText           AltNodeKind = "text"
	AltKindOperator       AltNodeKind = "operator"
	AltKindSpace          AltNodeKind = "space"
	AltKindFraction       AltNodeKind = "fraction"
	AltKindRadical        AltNodeKind = "radical"
	AltKindScripts        AltNodeKind = "scripts"
	AltKindFenced         AltNodeKind = "fenced"
	AltKindSizedDelimiter AltNodeKind = "sized-delimiter"
	AltKindAccent         AltNodeKind = "accent"
	AltKindLine           AltNodeKind = "line"
	AltKindCancel         AltNodeKind = "cancel"
	AltKindTable          AltNodeKind = "table"
	AltKindMultiline      AltNodeKind = "multiline"
	AltKindStyle          AltNodeKind = "style"
	AltKindOverlay        AltNodeKind = "overlay"
	AltKindRaise          AltNodeKind = "raise"
	AltKindColor          AltNodeKind = "color"
	AltKindBox            AltNodeKind = "box"
	AltKindPhantom        AltNodeKind = "phantom"
	AltKindError          AltNodeKind = "error"
	AltKindPlaceholder    AltNodeKind = "placeholder"
	AltKindBreak          AltNodeKind = "break"
	AltKindAlignMarker    AltNodeKind = "align-marker"
)

type AltOverlayAlignment added in v0.4.0

type AltOverlayAlignment string

AltOverlayAlignment identifies the horizontal placement of zero-width overlay content.

const (
	AltOverlayStart  AltOverlayAlignment = "start"
	AltOverlayCenter AltOverlayAlignment = "center"
	AltOverlayEnd    AltOverlayAlignment = "end"
)

type AltPart added in v0.4.0

type AltPart struct {
	Role AltPartRole `json:"role"`
	Node AltNode     `json:"node"`
}

AltPart attaches a child node to a named semantic position.

type AltPartRole added in v0.4.0

type AltPartRole string

AltPartRole names the semantic position of a child node.

const (
	AltPartItem        AltPartRole = "item"
	AltPartBody        AltPartRole = "body"
	AltPartNumerator   AltPartRole = "numerator"
	AltPartDenominator AltPartRole = "denominator"
	AltPartRadicand    AltPartRole = "radicand"
	AltPartIndex       AltPartRole = "index"
	AltPartBase        AltPartRole = "base"
	AltPartTop         AltPartRole = "top"
	AltPartBottom      AltPartRole = "bottom"
	AltPartTopLeft     AltPartRole = "top-left"
	AltPartBottomLeft  AltPartRole = "bottom-left"
	AltPartTopRight    AltPartRole = "top-right"
	AltPartBottomRight AltPartRole = "bottom-right"
	AltPartOpen        AltPartRole = "open"
	AltPartClose       AltPartRole = "close"
	AltPartContent     AltPartRole = "content"
	AltPartAccent      AltPartRole = "accent"
)

type AltPosition added in v0.4.0

type AltPosition string

AltPosition identifies an above/below decoration.

const (
	AltPositionAbove AltPosition = "above"
	AltPositionBelow AltPosition = "below"
)

type AltRaiseDirection added in v0.4.0

type AltRaiseDirection string

AltRaiseDirection identifies the semantic vertical direction of a raise.

const (
	AltRaiseUp   AltRaiseDirection = "up"
	AltRaiseDown AltRaiseDirection = "down"
	AltRaiseZero AltRaiseDirection = "zero"
)

type AltRow added in v0.4.0

type AltRow struct {
	Items []AltNode `json:"items,omitempty"`
}

AltRow is one table or multiline row. Items are cells for tables and row-level components for multiline expressions.

type AltScriptRole added in v0.4.0

type AltScriptRole string

AltScriptRole identifies the semantic purpose of scripts and limits.

const (
	AltScriptOrdinary   AltScriptRole = "ordinary"
	AltScriptLimits     AltScriptRole = "limits"
	AltScriptOverlay    AltScriptRole = "overlay"
	AltScriptBraceLabel AltScriptRole = "brace-label"
)

type AltSizingKind added in v0.4.0

type AltSizingKind string

AltSizingKind identifies a delimiter target policy.

const (
	AltSizingContent  AltSizingKind = "content"
	AltSizingRelative AltSizingKind = "relative"
	AltSizingAbsolute AltSizingKind = "absolute"
)

type AltSpaceKind added in v0.4.0

type AltSpaceKind string

AltSpaceKind identifies the semantic kind of an explicit or interword space.

const (
	AltSpaceExplicit  AltSpaceKind = "explicit"
	AltSpaceInterword AltSpaceKind = "interword"
	AltSpaceIgnored   AltSpaceKind = "ignored"
)

type AltSpaceWidth added in v0.4.0

type AltSpaceWidth string

AltSpaceWidth identifies the authored width of an explicit space when it matches a stable semantic width.

const (
	AltSpaceWidthZero           AltSpaceWidth = "zero"
	AltSpaceWidthThin           AltSpaceWidth = "thin"
	AltSpaceWidthMedium         AltSpaceWidth = "medium"
	AltSpaceWidthThick          AltSpaceWidth = "thick"
	AltSpaceWidthEn             AltSpaceWidth = "en"
	AltSpaceWidthQuad           AltSpaceWidth = "quad"
	AltSpaceWidthDoubleQuad     AltSpaceWidth = "double-quad"
	AltSpaceWidthNegativeThin   AltSpaceWidth = "negative-thin"
	AltSpaceWidthNegativeMedium AltSpaceWidth = "negative-medium"
	AltSpaceWidthNegativeThick  AltSpaceWidth = "negative-thick"
	AltSpaceWidthCustom         AltSpaceWidth = "custom"
)

type AltTableRole added in v0.4.0

type AltTableRole string

AltTableRole identifies the semantic kind of a table.

const (
	AltTableMatrix AltTableRole = "matrix"
	AltTableArray  AltTableRole = "array"
	AltTableCases  AltTableRole = "cases"
	AltTableVector AltTableRole = "vector"
)

type AltTag added in v0.4.0

type AltTag struct {
	Body       *AltNode `json:"body,omitempty"`
	Manual     bool     `json:"manual,omitempty"`
	Starred    bool     `json:"starred,omitempty"`
	Suppressed bool     `json:"suppressed,omitempty"`
	Line       int      `json:"line"`
}

AltTag describes one formula- or row-scoped tag event. A suppressed event has no body. Line is FormulaTagLine for the complete formula or the zero-based source row for a multiline row tag.

type AltVariant added in v0.4.0

type AltVariant string

AltVariant identifies a semantic math alphabet.

const (
	AltVariantNormal       AltVariant = "normal"
	AltVariantItalic       AltVariant = "italic"
	AltVariantBold         AltVariant = "bold"
	AltVariantBoldItalic   AltVariant = "bold-italic"
	AltVariantDoubleStruck AltVariant = "double-struck"
	AltVariantScript       AltVariant = "script"
	AltVariantBoldScript   AltVariant = "bold-script"
	AltVariantFraktur      AltVariant = "fraktur"
	AltVariantBoldFraktur  AltVariant = "bold-fraktur"
	AltVariantSans         AltVariant = "sans-serif"
	AltVariantBoldSans     AltVariant = "bold-sans-serif"
	AltVariantMonospace    AltVariant = "monospace"
)

type Box

type Box struct {
	Width   float32
	Ascent  float32
	Descent float32
	// Italic is the signed OpenType MATH italic correction at the end of the
	// box. It may be negative; hosts must not treat it as a nonnegative size.
	Italic     float32
	AxisHeight float32
	// Overflow is a nonnegative lower bound for rendered ink outside the box and,
	// for constrained display boxes, the largest logical line-width excess.
	Overflow float32

	Items []Item
	// Paths contains path templates shared by one or more items. A glyph-path
	// item resolves a point as At + templatePoint*Em.
	Paths  []PathTemplate
	Hits   []Hit
	Breaks []Break
	// CaretStops is source ordered in final box coordinates. Use Carets for an
	// immutable snapshot and CaretAt to resolve a source offset.
	CaretStops []CaretStop
	Alt        Alt
	// Diagnostics reports recoverable layout problems, such as unavailable
	// glyphs rendered as visible placeholders. Parse diagnostics remain on the
	// high-level RenderResult.
	Diagnostics []source.Diagnostic
	// FontUsage reports resolved face selection and missing fallback needs for
	// shaped text clusters. It is separate from Diagnostics and remains empty
	// when a formula contains no shaped text.
	FontUsage FontUsage
	// Tag is a single-line display equation tag in parent coordinates. Its
	// Items and Hits ranges identify its records in this Box. It is excluded
	// from formula-root breaks.
	Tag *TagBox
	// Tags contains source-row-scoped equation tags in ascending row order.
	// It is mutually exclusive with Tag. Each range indexes this Box's
	// parent-frame Items and Hits and remains row-scoped even when a constrained
	// display wraps the formula block as one line.
	Tags []TagBox
	// Lines is populated only for display layout with a positive Style.MaxWidth.
	// A constrained display result always has at least one line, including when
	// the complete formula fits. Its Width is the requested MaxWidth, even when
	// every line is narrower or an unbreakable line overflows it. Lines are
	// source ordered and index the single parent-frame Items and Hits storage.
	Lines []LineBox
}

Box is a flattened formula relative to the start of its baseline.

func (*Box) At

func (b *Box) At(p geometry.Point) (Hit, bool)

At returns the innermost hit containing p.

func (*Box) Bounds

func (b *Box) Bounds() geometry.Rect

Bounds returns the baseline-relative rectangle that contains the box's nominal geometry and its certified overflow. The result is suitable for fitting the complete display list into a host viewport.

func (*Box) CaretAt added in v0.4.0

func (b *Box) CaretAt(offset int) (CaretStop, bool)

CaretAt returns the preferred caret for offset.

An exact source offset wins. When no stop exists at offset, the nearest previous or following proven source boundary is returned. Ties prefer the earlier source offset, then deterministic top-to-bottom and left-to-right geometry. Negative offsets and an empty caret map return false.

func (*Box) Carets added in v0.4.0

func (b *Box) Carets() []CaretStop

Carets returns an independent copy of the source-ordered caret stops.

func (*Box) Clone

func (b *Box) Clone() *Box

Clone returns an independent copy of the box.

func (*Box) Covering

func (b *Box) Covering(r source.Range) []geometry.Rect

Covering returns the innermost placed areas intersecting source range r. Ancestor structure hits are ignored when a deeper hit also intersects r. Areas on the same line that overlap or touch are merged deterministically.

func (*Box) MarshalCanonical

func (b *Box) MarshalCanonical() ([]byte, error)

MarshalCanonical returns deterministic JSON for golden tests and diagnostics. It is not a stable cross-language protocol.

func (*Box) NearestCaret added in v0.4.0

func (b *Box) NearestCaret(p geometry.Point) (CaretStop, bool)

NearestCaret returns the caret stop geometrically nearest to p.

Vertical distance is minimized first so a point never snaps to a caret on a different line merely because its x coordinate is closer. Within one line, horizontal distance resolves the left/right affinity. Ties use the same stable source and geometry ordering as CaretAt.

func (*Box) Split added in v0.4.0

func (b *Box) Split(at Break) (left, right *Box, err error)

Split divides an inline box at one of its legal Break opportunities.

The returned boxes have independent item, path, hit, caret, and break storage. Left keeps parent coordinates and uses at.X as its width. Right is translated so its origin is zero. Hit rectangles are clipped to each side; caret stops on the boundary are retained by both sides. Alt and FontUsage are cleared because neither whole-formula metadata can be divided soundly.

Constrained display boxes, tagged boxes, unknown break values, and endpoint breaks cannot be split. Passing a Break from Box.Breaks is required.

func (*Box) Validate

func (b *Box) Validate() error

Validate checks structural and numeric output invariants.

type Break

type Break struct {
	X    float32
	Kind BreakKind
}

Break is an inline wrapping opportunity relative to the box baseline origin. Relation, binary, and explicit kinds describe why a cut is legal; they do not carry a relative cost. Display wrapping is width-greedy and chooses the earliest source cut when multiple opportunities have equal width.

type BreakKind

type BreakKind uint8

BreakKind describes why an inline break point is legal.

const (
	BreakRelation BreakKind = iota
	BreakBinary
	BreakExplicit
)

type CaretStop added in v0.4.0

type CaretStop struct {
	Source int
	X      float32
	Top    float32
	Bottom float32
	NodeID identity.NodeID
}

CaretStop is one source-ordered caret position in box coordinates.

Source is an absolute UTF-8 byte offset. X is the caret line's horizontal position and Top/Bottom are its vertical extent. A formula may have multiple stops for one offset, for example where a nested construct contributes more than one baseline. NodeID is the optional semantic identity associated with the stop.

type ColorPolicy added in v0.4.0

type ColorPolicy struct {
	Mode        ColorPolicyMode
	Palette     ColorRolePalette
	Background  RGBA
	MinContrast float32
}

ColorPolicy controls output-time treatment of authored explicit colors.

Semantic role paints are never changed. Preserve is the zero value and keeps explicit colors byte-for-byte unchanged. MapToRoles discards authored color and alpha and emits a serializable semantic role. AdjustContrast preserves alpha and changes only the RGB needed to reach MinContrast against an opaque Background. If the preserved alpha makes the threshold impossible, it moves to the highest-contrast RGB endpoint. A zero MinContrast uses the WCAG AA normal-text threshold 4.5.

func (ColorPolicy) Resolve added in v0.4.0

func (p ColorPolicy) Resolve(paint Paint) Paint

Resolve returns paint with this policy applied.

Callers must Validate the policy first. Preserve and unknown modes are intentionally no-ops so an unvalidated zero-value policy cannot corrupt output.

func (ColorPolicy) Validate added in v0.4.0

func (p ColorPolicy) Validate() error

Validate checks a color policy before layout.

type ColorPolicyMode added in v0.4.0

type ColorPolicyMode uint8

ColorPolicyMode selects how authored explicit colors participate in output.

const (
	// ColorPreserve leaves every authored explicit color unchanged. It is the
	// zero-value policy and the default behavior.
	ColorPreserve ColorPolicyMode = iota
	// ColorMapToRoles replaces explicit colors with the perceptually nearest
	// semantic role in ColorPolicy.Palette.
	ColorMapToRoles
	// ColorAdjustContrast minimally adjusts explicit colors until they meet
	// ColorPolicy.MinContrast against ColorPolicy.Background.
	ColorAdjustContrast
)

type ColorRolePalette added in v0.4.0

type ColorRolePalette struct {
	Ink         RGBA
	Error       RGBA
	Placeholder RGBA
}

ColorRolePalette supplies concrete colors for semantic paint roles when explicit colors are mapped back to roles.

type FaceUse added in v0.4.0

type FaceUse struct {
	Source   source.Range
	FaceID   string
	Fallback bool
	Missing  bool
}

FaceUse identifies the resolved face used for one or more shaped text clusters. Source ranges are in logical source order after layout finalization. Fallback is true when the face was not the first face requested for that text role.

type FontUsage added in v0.4.0

type FontUsage struct {
	Faces   []FaceUse
	Missing []MissingFallback
}

FontUsage reports shaped text face selection for hosts that need to load fallback fonts ahead of future layouts or explain the current selection.

Faces contains resolved face spans in source order. Missing contains merged, deduplicated fallback requirements. Math glyphs selected directly through OpenType MATH tables are not text clusters and are intentionally absent.

func (FontUsage) Clone added in v0.4.0

func (u FontUsage) Clone() FontUsage

Clone returns an independent copy.

func (FontUsage) NeedsFallback added in v0.4.0

func (u FontUsage) NeedsFallback() bool

NeedsFallback reports whether any shaped text cluster lacked coverage.

func (FontUsage) UsesFallback added in v0.4.0

func (u FontUsage) UsesFallback() bool

UsesFallback reports whether any shaped text cluster used a non-primary face.

func (FontUsage) Validate added in v0.4.0

func (u FontUsage) Validate() error

Validate checks the structured face report.

type Hit

type Hit struct {
	Source source.Range
	Area   geometry.Rect
	Depth  int
	Kind   HitKind
	// NodeID is the optional stable identity of the source node represented by
	// this hit. Zero means unassigned.
	NodeID identity.NodeID
}

Hit maps a source range to one placed area.

type HitKind

type HitKind uint8

HitKind identifies the source semantic represented by a hit area.

const (
	HitAtom HitKind = iota
	HitGroup
	HitScript
	HitFractionNumerator
	HitFractionDenominator
	HitRadical
	HitFence
	HitTableCell
	HitRow
	HitOther
)

type HitRange

type HitRange struct {
	Start int
	Count int
}

HitRange identifies a contiguous range in Box.Hits.

Start is the zero-based index of the first hit and Count is the number of hits. An empty range is valid. Ranges returned by layout always refer to parent-frame storage.

func (HitRange) End

func (r HitRange) End() int

End returns Start+Count.

type Item

type Item struct {
	Kind  ItemKind
	Paint Paint
	Bound geometry.Rect
	// NodeID is the optional stable identity of the semantic source node that
	// produced this item. Zero means the item has no assigned identity.
	NodeID identity.NodeID

	// PathIndex selects Box.Paths. It is NoPath for items without path data.
	PathIndex int
	Rect      geometry.Rect
	// Snap identifies a thin rule's minor axis. It is present even when
	// Style.PixelGrid is disabled, allowing hosts to apply their own equivalent
	// policy without inferring rule orientation again.
	Snap SnapAxis

	FontID string
	Glyph  uint16
	// At places Paths[PathIndex] for ItemGlyphPath and is the font glyph origin
	// for ItemGlyphRef. Path points resolve as At + templatePoint*Em.
	At geometry.Point
	Em float32
}

Item is one already-positioned drawing instruction.

type ItemKind

type ItemKind uint8

ItemKind identifies one flattened drawing item.

const (
	ItemGlyphPath ItemKind = iota
	ItemRule
	ItemGlyphRef
)

type ItemRange

type ItemRange struct {
	Start int
	Count int
}

ItemRange identifies a contiguous range in Box.Items.

Start is the zero-based index of the first item and Count is the number of items. An empty range is valid. Ranges returned by layout always refer to parent-frame storage and never require a coordinate translation.

func (ItemRange) End

func (r ItemRange) End() int

End returns Start+Count.

type LineBox

type LineBox struct {
	Baseline float32
	OffsetX  float32
	Width    float32
	Ascent   float32
	Descent  float32
	Overflow float32
	Items    ItemRange
	Hits     HitRange
	// Tag is the borrowed canonical Box.Tag for a tag associated with this
	// line. If non-nil, it must be the same pointer as Box.Tag. Its range is
	// separate from the line range.
	Tag *TagBox
}

LineBox is metadata for one display line inside a constrained Box.

Baseline is the line baseline's vertical offset from the parent box baseline, positive downward. Adjacent baselines are separated by the previous line's descent plus the current line's ascent; no additional leading is invented. OffsetX is the nonnegative horizontal offset of the line inside the parent's MaxWidth-wide alignment frame. Items and Hits are contiguous ranges into the owning Box's parent-frame slices. Overflow is max(line-local ink overflow, line width minus the parent frame width); the parent Box.Overflow covers the assembled aligned aggregate. When Tag is non-nil, line alignment is computed in the reduced frame MaxWidth-Tag.Width; an overfull formula line uses zero offset and the tag follows the formula.

type MissingFallback added in v0.4.0

type MissingFallback struct {
	Source     source.Range
	Text       string
	TriedFaces []string
}

MissingFallback identifies text for which none of TriedFaces supplied a usable outline cluster. It is structured lookup data, not a second diagnostic: recovery and CodeMissingGlyph diagnostics remain authoritative.

type Paint

type Paint struct {
	Role        Role
	Explicit    RGBA
	HasExplicit bool
}

Paint is a role or explicit color.

type PathTemplate

type PathTemplate struct {
	Segments []geometry.Segment
	// Bound is the local control-point bounds before item placement.
	Bound geometry.Rect
}

PathTemplate is one immutable path template in local em coordinates. Items place it in box coordinates with At and Em.

type PixelGrid added in v0.4.0

type PixelGrid struct {
	Scale      float32
	PixelRatio float32
}

PixelGrid describes an optional device-pixel grid for thin rules and stems.

Scale is the host-unit-to-output-pixel scale and PixelRatio is the additional device-pixel ratio. The zero value disables snapping. Both fields must be positive and finite when either is set.

func (PixelGrid) Enabled added in v0.4.0

func (p PixelGrid) Enabled() bool

Enabled reports whether the grid requests any snapping.

func (PixelGrid) SnapRect added in v0.4.0

func (p PixelGrid) SnapRect(rect geometry.Rect, axis SnapAxis) geometry.Rect

SnapRect aligns the minor axis of a thin rule to the configured grid.

Snapping is deliberately conservative: only rules whose minor thickness is between 0.25 and 3 physical pixels are changed. The start edge moves to the nearest grid boundary, and thickness rounds to the nearest physical-pixel count with a one-pixel minimum. The major axis and all non-rule geometry are unchanged. An unset or invalid axis/grid is a no-op.

func (PixelGrid) Validate added in v0.4.0

func (p PixelGrid) Validate() error

Validate checks pixel-grid configuration before layout.

type RGBA

type RGBA struct {
	R uint8
	G uint8
	B uint8
	A uint8
}

RGBA is an explicit output color.

type Role

type Role uint8

Role is a theme-resolved paint role.

const (
	RoleInk Role = iota
	RoleError
	RolePlaceholder
)

type SnapAxis added in v0.4.0

type SnapAxis uint8

SnapAxis identifies the minor axis of a thin rule that can be aligned.

const (
	// SnapNone means the item is not a conservative snapping candidate.
	SnapNone SnapAxis = iota
	// SnapX aligns a vertical rule's x position and width.
	SnapX
	// SnapY aligns a horizontal rule's y position and thickness.
	SnapY
)

type Style

type Style struct {
	Size float32
	// MaxWidth enables constrained display line boxes when positive. A
	// constrained Box.Width is the requested frame width.
	MaxWidth    float32
	Align       Align
	ScriptLevel int
	Features    []string
	GlyphRefs   bool
	// GenerateAlt requests Box.Alt generation through the public Engine
	// facade. Expr.Alt remains available independently for parsed expressions.
	GenerateAlt bool
	// ColorPolicy controls explicit-color resolution in the serializable
	// display list. The zero value preserves authored colors.
	ColorPolicy ColorPolicy
	// PixelGrid enables conservative device-pixel snapping for thin rules and
	// stems. The zero value is a no-op.
	PixelGrid PixelGrid
}

Style is a layout request in host units.

type TagBox

type TagBox struct {
	Source  source.Range
	Manual  bool
	Starred bool
	// Line is FormulaTagLine for a formula-level tag, or a zero-based source
	// row for a multiline row tag.
	Line    int
	X       float32
	Y       float32
	Width   float32
	Ascent  float32
	Descent float32
	Italic  float32
	Items   ItemRange
	Hits    HitRange
}

TagBox is equation-tag metadata. Its Items and Hits ranges index the owning Box's parent-frame slices. X and Y are parent-frame coordinates and do not move with LineBox.OffsetX. Line is FormulaTagLine for Box.Tag, or a zero-based source row for an entry in Box.Tags.

Jump to

Keyboard shortcuts

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