Documentation
¶
Overview ¶
Package fontstore registers and resolves fonts and measures text. It parses embedded fonts with go-text/typesetting and falls back to the 14 standard PDF fonts (via the afm package) when an unregistered standard family is requested.
Measurement here uses nominal glyph advances (no shaping); OpenType shaping with kerning and ligatures arrives with the text engine (textkit).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Descriptor ¶
type Descriptor struct {
Ascent, Descent, CapHeight float64
BBox [4]float64 // xMin, yMin, xMax, yMax
ItalicAngle float64
Flags int
StemV float64
}
Descriptor holds the metrics a PDF FontDescriptor needs for an embedded font, in 1000-unit text space (font units scaled by 1000/upem).
type Face ¶
Face is one registered font face.
A Face is shared across concurrent renders via the template asset cache, but its parsed go-text/typesetting Face is not safe for concurrent use: glyph lookups lazily populate internal caches. mu serializes every access to parsed, and the render-invariant Descriptor is memoized so the hot path never touches parsed after warmup.
func (*Face) Descriptor ¶
func (f *Face) Descriptor() Descriptor
Descriptor returns the FontDescriptor metrics for embedding this face. The result is render-invariant, so it is computed once and memoized; concurrent callers share the cached value and never race on the underlying go-text Face.
func (*Face) EmbeddedFont ¶
func (f *Face) EmbeddedFont() *pdf.EmbeddedFont
EmbeddedFont returns the pdf.EmbeddedFont for this face (program bytes + descriptor + WinAnsi widths), ready to embed as a simple TrueType PDF font. The value is built once and cached: returning the same pointer on every call lets the PDF writer dedupe the font program to a single FontFile2 stream no matter how many text boxes use the face.
func (*Face) FontName ¶
FontName returns a PDF-safe /BaseFont name derived from the family and weight/style. Embedders may prefix a subset tag (e.g. "ABCDEF+").
func (*Face) StringWidth ¶
StringWidth measures text using nominal glyph advances. It is safe for concurrent use: access to the shared go-text Face is serialized by f.mu.
func (*Face) WinAnsiWidths ¶
WinAnsiWidths returns advance widths in 1000-unit space for WinAnsi codes 0..255 (0 for unmapped codes), for the PDF simple-font /Widths array. It is safe for concurrent use: access to the shared go-text Face is serialized by f.mu.
type Font ¶
type Font interface {
// StringWidth returns the advance width of text in points at the given size.
StringWidth(text string, size float64) float64
}
Font is anything that can measure text; both a registered Face and a standard font's metrics satisfy it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a concurrency-safe font registry.
func (*Store) Resolve ¶
Resolve returns a Font for the requested family/weight/style. Registered families are checked first; otherwise a standard PDF font matching the family name is used. weight 0 is treated as 400.
func (*Store) ResolveFace ¶
ResolveFace returns a registered face for family/weight/style, or false if the family has no registered faces. Unlike Resolve it never falls back to a standard PDF font — the caller handles standard fonts separately (they don't need embedding). weight 0 is treated as 400.