Documentation
¶
Overview ¶
Package fontface owns the renderer-internal OpenType parsing, shaping, and color-glyph pipeline shared by scene construction and native raster output.
Index ¶
- func BundledNotoColorEmojiCoversRune(value rune) bool
- func IsDefaultIgnorableRune(value rune) bool
- func RegisterBundledFace(data []byte, digest [sha256.Size]byte) error
- func RegisterOwnedBundledNotoColorEmoji(data []byte) ([]byte, error)
- func RegisteredBundledFaceBackingDigest(data []byte) ([sha256.Size]byte, bool)
- func RegisteredBundledNotoColorEmojiBackingDigest(data []byte) ([sha256.Size]byte, bool)
- type BundledFaceSource
- func (s *BundledFaceSource) COLR0GlyphLayers(glyphID uint32) ([]ColorGlyphLayer, bool, error)
- func (s *BundledFaceSource) CloneReadOnly() (*ParsedFace, error)
- func (s *BundledFaceSource) CloneReadOnlyInto(clone *ParsedFace) error
- func (s *BundledFaceSource) CompileBundledNotoColorEmojiCOLRv1Plan(glyphID uint32) (*COLRv1Plan, bool, error)
- func (s *BundledFaceSource) GlyphDataKind(glyphID uint32) (string, error)
- func (s *BundledFaceSource) GlyphRenderBounds(glyphID uint32, size fixed.Int26_6) (fixed.Rectangle26_6, bool, error)
- func (s *BundledFaceSource) IsBundledNotoColorEmoji() bool
- func (s *BundledFaceSource) Outline() (*sfnt.Font, error)
- func (s *BundledFaceSource) SupportsRenderableRune(value rune) (bool, error)
- type BundledNotoColorEmojiSource
- type COLRv1Affine
- type COLRv1ClipBox
- type COLRv1ColorLine
- type COLRv1ColorStop
- type COLRv1Composite
- type COLRv1CompositeMode
- type COLRv1Glyph
- type COLRv1Layers
- type COLRv1LimitError
- type COLRv1LinearGradient
- type COLRv1Paint
- type COLRv1Plan
- type COLRv1PlanUsage
- type COLRv1RadialGradient
- type COLRv1Solid
- type COLRv1Transform
- type COLRv1UnsupportedCompositeError
- type COLRv1UnsupportedExtendError
- type COLRv1UnsupportedPaintError
- type COLRv1UntrustedFontError
- type Collection
- type ColorGlyphLayer
- type FaceCountLimitError
- type ParsedFace
- func (f *ParsedFace) COLR0GlyphLayers(glyphID uint32) ([]ColorGlyphLayer, bool, error)
- func (f *ParsedFace) Clone() (*ParsedFace, error)
- func (f *ParsedFace) CloneInto(clone *ParsedFace) error
- func (f *ParsedFace) CompileBundledNotoColorEmojiCOLRv1Plan(glyphID uint32) (*COLRv1Plan, bool, error)
- func (f *ParsedFace) GlyphRenderBounds(glyphID uint32, size fixed.Int26_6) (fixed.Rectangle26_6, bool, error)
- func (f *ParsedFace) IsBundledNotoColorEmoji() bool
- func (f *ParsedFace) SupportsRenderableRune(value rune) (bool, error)
- type ShapeFace
- type ShapeLimits
- type ShapedGlyph
- type ShapedText
- type ShapingWorkspace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BundledNotoColorEmojiCoversRune ¶
BundledNotoColorEmojiCoversRune reports whether the pinned font's ordinary cmap maps value to a non-zero glyph. Variation selectors are handled by the shaper after fallback selects the base character's face.
func IsDefaultIgnorableRune ¶
IsDefaultIgnorableRune reports whether the pinned pure-Go HarfBuzz shaper treats value as default-ignorable. These code points normally affect shaping or protocol state without painting a glyph of their own.
Keep this exact range list shared by scene construction and raster shaping. It intentionally follows HarfBuzz's spacing-glyph exceptions for Hangul fillers and its shorthand-format-control exception, rather than blindly copying Unicode's broader Default_Ignorable_Code_Point property. Using the still broader General_Category=Cf would also incorrectly hide visible prepended concatenation marks such as U+0600 and U+06DD.
func RegisterBundledFace ¶
RegisterBundledFace records the authenticated size and digest of a D2 font. It does not retain data. Parsing and a private backing copy are created lazily from the first matching candidate, so a public font registry cannot expose or mutate parser-owned tables. Callers must not register dynamic fonts.
func RegisterOwnedBundledNotoColorEmoji ¶
RegisterOwnedBundledNotoColorEmoji authenticates and takes ownership of a freshly allocated decoded resource. The caller must not retain or mutate data after this call. This avoids a complete second decoded-font allocation and is restricted to D2's private loader, which has sole ownership of its decoder output.
func RegisteredBundledFaceBackingDigest ¶
RegisteredBundledFaceBackingDigest identifies the exact process-owned backing of a registered font without scanning it. The source is still authenticated and dual-parsed by RegisteredBundledFaceDigest before use. Byte-identical copies deliberately do not match this identity-only path.
func RegisteredBundledNotoColorEmojiBackingDigest ¶
RegisteredBundledNotoColorEmojiBackingDigest identifies the exact private decoded backing without scanning it. RegisteredBundledNotoColorEmoji still authenticates and parses the resource before a clone source is used.
Types ¶
type BundledFaceSource ¶
type BundledFaceSource struct {
// contains filtered or unexported fields
}
BundledFaceSource is an authenticated, package-owned clone source. Its parser state is not exposed.
func RegisteredBundledFace ¶
func RegisteredBundledFace(data []byte, faceIndex uint16) (*BundledFaceSource, bool, error)
RegisteredBundledFace authenticates data against D2's fixed bundled-font registry. A non-match is not an error so arbitrary scene fonts continue down the ordinary bounded parser path.
func RegisteredBundledFaceDigest ¶
func RegisteredBundledFaceDigest(data []byte, faceIndex uint16, digest [sha256.Size]byte) (*BundledFaceSource, bool, error)
RegisteredBundledFaceDigest is RegisteredBundledFace for callers that have already computed the source digest as part of their own bounded cache key.
func (*BundledFaceSource) COLR0GlyphLayers ¶
func (s *BundledFaceSource) COLR0GlyphLayers(glyphID uint32) ([]ColorGlyphLayer, bool, error)
COLR0GlyphLayers resolves immutable COLRv0 table data without allocating a mutable go-text Face clone. Returned layers are detached value records.
func (*BundledFaceSource) CloneReadOnly ¶
func (s *BundledFaceSource) CloneReadOnly() (*ParsedFace, error)
CloneReadOnly returns independent shaping caches while sharing go-text's documented read-only Font. It is for renderer-owned faces whose parsed table fields are never reassigned by the caller.
func (*BundledFaceSource) CloneReadOnlyInto ¶
func (s *BundledFaceSource) CloneReadOnlyInto(clone *ParsedFace) error
CloneReadOnlyInto is CloneReadOnly with caller-owned result storage.
func (*BundledFaceSource) CompileBundledNotoColorEmojiCOLRv1Plan ¶
func (s *BundledFaceSource) CompileBundledNotoColorEmojiCOLRv1Plan(glyphID uint32) (*COLRv1Plan, bool, error)
CompileBundledNotoColorEmojiCOLRv1Plan compiles an immutable renderer plan through the authenticated package-private color tables.
func (*BundledFaceSource) GlyphDataKind ¶
func (s *BundledFaceSource) GlyphDataKind(glyphID uint32) (string, error)
GlyphDataKind reports only the diagnostic category of a glyph. Keeping the table-backed GlyphData value private prevents callers from retaining or modifying parser-owned slices while still preserving renderer errors.
func (*BundledFaceSource) GlyphRenderBounds ¶
func (s *BundledFaceSource) GlyphRenderBounds(glyphID uint32, size fixed.Int26_6) (fixed.Rectangle26_6, bool, error)
GlyphRenderBounds reads glyph paint bounds without constructing per-Face shaping caches.
func (*BundledFaceSource) IsBundledNotoColorEmoji ¶
func (s *BundledFaceSource) IsBundledNotoColorEmoji() bool
IsBundledNotoColorEmoji reports whether this source is D2's authenticated color-emoji font without exposing its parser face.
func (*BundledFaceSource) Outline ¶
func (s *BundledFaceSource) Outline() (*sfnt.Font, error)
Outline returns the immutable sfnt reader for this authenticated source. sfnt.Font has no mutable exported state; callers supply their own Buffer for every operation, so the reader may safely be shared by concurrent renders.
func (*BundledFaceSource) SupportsRenderableRune ¶
func (s *BundledFaceSource) SupportsRenderableRune(value rune) (bool, error)
SupportsRenderableRune checks exact bundled-font coverage without mutating a shaping face cache, so one registered source can serve concurrent resolvers. The fixed ordinary D2 fonts contain only authenticated outline glyphs, so a matching non-zero cmap entry is sufficient. The bundled color-emoji source additionally validates its supported COLR paint path.
type BundledNotoColorEmojiSource ¶
type BundledNotoColorEmojiSource = BundledFaceSource
BundledNotoColorEmojiSource preserves the specific name used by the bundled emoji resolver and its authenticated color-paint and coverage APIs.
func RegisteredBundledNotoColorEmoji ¶
func RegisteredBundledNotoColorEmoji(data []byte, faceIndex uint16) (*BundledNotoColorEmojiSource, bool, error)
RegisteredBundledNotoColorEmoji authenticates an exact candidate and returns a package-owned source for parser-issued clones. The registered Face and its mutable caches remain private; clones share only go-text's concurrent-safe, read-only Font tables. A same-sized unrelated font is not claimed, so callers can continue through their ordinary parser path.
type COLRv1Affine ¶
type COLRv1Affine struct{ Xx, Yx, Xy, Yy, Dx, Dy float64 }
type COLRv1ClipBox ¶
type COLRv1ClipBox struct{ XMin, YMin, XMax, YMax float64 }
type COLRv1ColorLine ¶
type COLRv1ColorLine struct {
Stops []COLRv1ColorStop
}
type COLRv1ColorStop ¶
type COLRv1Composite ¶
type COLRv1Composite struct {
Source, Backdrop COLRv1Paint
Mode COLRv1CompositeMode
}
type COLRv1CompositeMode ¶
type COLRv1CompositeMode uint8
const ( COLRv1CompositeSrcIn COLRv1CompositeMode = iota COLRv1CompositeSoftLight )
type COLRv1Glyph ¶
type COLRv1Glyph struct {
GlyphID uint32
Paint COLRv1Paint
}
type COLRv1Layers ¶
type COLRv1Layers struct{ Paints []COLRv1Paint }
type COLRv1LimitError ¶
func (*COLRv1LimitError) Error ¶
func (e *COLRv1LimitError) Error() string
type COLRv1LinearGradient ¶
type COLRv1LinearGradient struct {
ColorLine COLRv1ColorLine
X0, Y0 float64
X1, Y1 float64
X2, Y2 float64
}
type COLRv1Paint ¶
type COLRv1Paint interface {
// contains filtered or unexported methods
}
COLRv1Paint is the closed set of paint operations emitted by the trusted compiler.
type COLRv1Plan ¶
type COLRv1Plan struct {
GlyphID uint32
Root COLRv1Paint
Clip *COLRv1ClipBox
Usage COLRv1PlanUsage
}
COLRv1Plan is a renderer-neutral, fully palette-resolved paint graph for one glyph. Coordinates remain in the font's design units. Renderers choose their own outline rasterizer, transform convention, and temporary-layer strategy.
type COLRv1PlanUsage ¶
type COLRv1RadialGradient ¶
type COLRv1RadialGradient struct {
ColorLine COLRv1ColorLine
X0, Y0, Radius0 float64
X1, Y1, Radius1 float64
}
type COLRv1Solid ¶
type COLRv1Transform ¶
type COLRv1Transform struct {
Matrix COLRv1Affine
Paint COLRv1Paint
}
type COLRv1UnsupportedCompositeError ¶
type COLRv1UnsupportedCompositeError struct{ Mode uint8 }
func (*COLRv1UnsupportedCompositeError) Error ¶
func (e *COLRv1UnsupportedCompositeError) Error() string
type COLRv1UnsupportedExtendError ¶
type COLRv1UnsupportedExtendError struct{ Extend uint8 }
func (*COLRv1UnsupportedExtendError) Error ¶
func (e *COLRv1UnsupportedExtendError) Error() string
type COLRv1UnsupportedPaintError ¶
type COLRv1UnsupportedPaintError struct{ Type string }
func (*COLRv1UnsupportedPaintError) Error ¶
func (e *COLRv1UnsupportedPaintError) Error() string
type COLRv1UntrustedFontError ¶
type COLRv1UntrustedFontError struct{}
COLRv1UntrustedFontError says that a caller attempted to use the compiler for arbitrary external font data.
func (COLRv1UntrustedFontError) Error ¶
func (COLRv1UntrustedFontError) Error() string
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection parses one font source with both libraries used by the raster text pipeline. A source is accepted only when outline lookup and HarfBuzz-compatible shaping agree on its face topology.
func ParseFaceCollectionWithLimit ¶
func ParseFaceCollectionWithLimit(data []byte, maxFaces int) (*Collection, error)
ParseFaceCollectionWithLimit inspects the cheap sfnt collection directory first and rejects excessive face counts before go-text eagerly constructs its per-face parser state.
func (*Collection) Face ¶
func (c *Collection) Face(index int) (*ParsedFace, error)
Face returns one parser-authenticated face by zero-based index.
func (*Collection) NumFaces ¶
func (c *Collection) NumFaces() int
NumFaces reports the number of matching outline and shaping faces.
type ColorGlyphLayer ¶
ColorGlyphLayer is one foreground or palette-colored outline in a COLRv0 glyph. Layers are returned in paint order.
type FaceCountLimitError ¶
FaceCountLimitError reports a collection rejected before the shaping parser constructs one Face per entry.
func (*FaceCountLimitError) Error ¶
func (e *FaceCountLimitError) Error() string
type ParsedFace ¶
type ParsedFace struct {
Outline *sfnt.Font
Shaping *gotextfont.Face
// contains filtered or unexported fields
}
ParsedFace is one matching outline/shaping face. The Shaping face owns mutable lookup caches and must not be shared across concurrent renders.
func ParseFace ¶
func ParseFace(data []byte, faceIndex uint16) (*ParsedFace, error)
ParseFace parses one face from a TrueType, OpenType, or collection resource.
func (*ParsedFace) COLR0GlyphLayers ¶
func (f *ParsedFace) COLR0GlyphLayers(glyphID uint32) ([]ColorGlyphLayer, bool, error)
COLR0GlyphLayers returns the default-palette layers for one supported COLRv0 glyph. A false second result means the glyph should use its ordinary outline; this preserves outline fallback for other color-font formats.
func (*ParsedFace) Clone ¶
func (f *ParsedFace) Clone() (*ParsedFace, error)
Clone returns a face with fresh shaping caches while preserving provenance only when this value still contains the exact parser-selected components. It is safe to use the resulting face independently in another render.
func (*ParsedFace) CloneInto ¶
func (f *ParsedFace) CloneInto(clone *ParsedFace) error
CloneInto is Clone with caller-owned result storage.
func (*ParsedFace) CompileBundledNotoColorEmojiCOLRv1Plan ¶
func (f *ParsedFace) CompileBundledNotoColorEmojiCOLRv1Plan(glyphID uint32) (*COLRv1Plan, bool, error)
CompileBundledNotoColorEmojiCOLRv1Plan compiles the static COLRv1 subset used by D2's bundled Noto Color Emoji asset. A false result means the glyph has no COLR paint. Parser-issued provenance is checked before inspecting the color table; arbitrary external COLRv1 fonts remain unsupported and callers cannot replace the safety ceilings.
func (*ParsedFace) GlyphRenderBounds ¶
func (f *ParsedFace) GlyphRenderBounds(glyphID uint32, size fixed.Int26_6) (fixed.Rectangle26_6, bool, error)
GlyphRenderBounds returns paint bounds in the same fixed-point coordinate system as sfnt.LoadGlyph. Authenticated COLRv1 glyphs use their static COLR clip box; all other faces use outlines or COLRv0 layers.
func (*ParsedFace) IsBundledNotoColorEmoji ¶
func (f *ParsedFace) IsBundledNotoColorEmoji() bool
IsBundledNotoColorEmoji reports whether this face retains parser-issued provenance for D2's exact bundled color-emoji resource.
func (*ParsedFace) SupportsRenderableRune ¶
func (f *ParsedFace) SupportsRenderableRune(value rune) (bool, error)
SupportsRenderableRune reports whether both parsers select the same non-zero glyph and the raster pipeline can paint its base outline, COLRv0/CPAL layers, or an authenticated bundled COLRv1 plan. Empty outline glyphs are valid: spaces and spacing format controls can intentionally paint no contour while still contributing advance.
type ShapeFace ¶
type ShapeFace struct {
ID string
Face *ParsedFace
}
ShapeFace couples a caller-owned identifier to one parsed OpenType face. ParsedFace.Shaping contains mutable lookup caches, so callers must not share one ShapeFace concurrently between shaping calls.
type ShapeLimits ¶
ShapeLimits bounds all work which shaping cannot interrupt internally. Every field must be positive. Callers enforcing document-wide budgets pass the remaining aggregate allowance for CoverageChecks, Runs, and Glyphs.
type ShapedGlyph ¶
type ShapedGlyph struct {
ID uint32
Face int
PositionX float64
PositionY float64
Advance float64
Ink fixed.Rectangle26_6
HasInk bool
Empty bool
Source rune
SourceIndex int
}
ShapedGlyph is renderer-neutral placement for one glyph. Ink stays in the source font's fixed-point, Y-down coordinate system and is relative to the glyph position. Empty glyphs intentionally carry ID zero and no ink.
type ShapedText ¶
type ShapedText struct {
Glyphs []ShapedGlyph
Advance float64
Runes int
CoverageChecks int64
Runs int
}
ShapedText is one visually ordered, left-to-right placed line. Work reports the charged units so a caller can update aggregate document/frame budgets.
type ShapingWorkspace ¶
type ShapingWorkspace struct {
// contains filtered or unexported fields
}
ShapingWorkspace owns mutable scratch state for a sequence of shaping calls. Reusing one workspace for an operation lets go-text retain its HarfBuzz font cache and segmentation buffers without sharing mutable state between concurrent document builds or renders.
A ShapingWorkspace must not be used concurrently. Returned ShapedText values borrow their Glyphs until the workspace is reused. ParsedFace pointers and their exported Outline and Shaping fields must remain unchanged between calls; the workspace deliberately caches immutable font answers.
func (*ShapingWorkspace) ShapeTextTransient ¶
func (w *ShapingWorkspace) ShapeTextTransient(ctx context.Context, text string, size fixed.Int26_6, faces []ShapeFace, limits ShapeLimits) (ShapedText, error)
ShapeTextTransient applies pure-Go HarfBuzz-compatible shaping with bidi, script, ligature, mark, and ordered font-fallback support. Font selection has grapheme-cluster affinity: one face must cover every visible rune in a UAX #29 extended grapheme cluster. This prevents a combining mark that happens to exist in the primary font from being detached from a fallback base.
It reuses the workspace's output storage in addition to its internal scratch. The returned Glyphs remain valid only until the next call to ShapeTextTransient on this workspace. It is intended for document pipelines which immediately translate the neutral glyphs into owned scene or raster records.