display

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0, MIT Imports: 9 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 FormulaTagLine = -1

FormulaTagLine identifies a tag that belongs to the complete formula rather than one rendered display line. It is the only Phase-1 TagBox line value.

View Source
const NoPath = -1

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

Variables

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

ErrInvalidAlt reports malformed alternative text.

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
}

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) 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 and contains no NUL.

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
	Alt    Alt
	// 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
	// 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) 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 placed areas intersecting source range 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) 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 Hit

type Hit struct {
	Source source.Range
	Area   geometry.Rect
	Depth  int
	Kind   HitKind
}

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

	// PathIndex selects Box.Paths. It is NoPath for items without path data.
	PathIndex int
	Rect      geometry.Rect

	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 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 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 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
}

Style is a layout request in host units.

type TagBox

type TagBox struct {
	Source  source.Range
	Manual  bool
	Starred bool
	// Line is FormulaTagLine. Zero-based row tags are reserved for future
	// multiline equation-tag support and are not emitted by Phase 1.
	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 the formula-level Phase-1 contract.

Jump to

Keyboard shortcuts

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