font

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 28 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectionIndex

func CollectionIndex(data []byte, name string) (int, error)

func DefaultCFFFontPath

func DefaultCFFFontPath() (string, error)

func DefaultFontPath

func DefaultFontPath() (string, error)

func IsGlyphFormatControl

func IsGlyphFormatControl(r rune) bool

IsGlyphFormatControl identifies joiners, variation selectors and emoji tags. They remain in the source text for selection but have no standalone ink or advance.

func RasterizerVersion

func RasterizerVersion() string

RasterizerVersion identifies the built-in pure Go rasterizer in visual reports. It does not require cgo or a system font library.

Types

type Bounds

type Bounds struct {
	XMin int16
	YMin int16
	XMax int16
	YMax int16
}

type CompositeComponent

type CompositeComponent struct {
	Transform [4]float64
	GlyphID   uint16
	Arg1      int16
	Arg2      int16
	UseXY     bool
}

type CompositeGlyph

type CompositeGlyph struct {
	Components   []CompositeComponent
	Instructions []byte
}

type Decoder

type Decoder interface {
	DecodeFont([]byte, string) (*Face, error)
}

Decoder decodes one statically selected font format collection.

type DecoderSet

type DecoderSet[A, B FormatDecoder] struct{}

DecoderSet is a compile-time font format collection. It performs no runtime registration and does not allocate while selecting a decoder.

func (DecoderSet[A, B]) DecodeFont

func (DecoderSet[A, B]) DecodeFont(data []byte, path string) (*Face, error)

type Face

type Face struct {
	Cmap cmap

	Kern kernTable

	SFNT *sfnt

	CFF *cffFont

	Glyf []byte
	Data []byte

	Loca []uint32

	Metrics []LongHorMetric

	Hhea Hhea
	Head Head
	Maxp Maxp
	// contains filtered or unexported fields
}

func Load

func Load(path string) (*Face, error)

func LoadDefault

func LoadDefault() (*Face, error)

func Parse

func Parse(data []byte) (*Face, error)

func ParseIndex

func ParseIndex(data []byte, index int) (*Face, error)

func (*Face) CacheKey

func (f *Face) CacheKey() uint64

func (*Face) CapHeight

func (f *Face) CapHeight() int16

CapHeight returns the cap-height metric in font units, using H for fonts without the optional OS/2 metric. It does not rasterize a glyph.

func (*Face) Close

func (f *Face) Close() error

Close releases the file or memory backing owned by the face. Callers must stop using the face and any scaled faces created from it before closing it.

func (*Face) Glyph

func (f *Face) Glyph(glyphID uint16) (*Glyph, error)

func (*Face) GlyphBounds

func (f *Face) GlyphBounds(glyphID uint16) (Bounds, error)

GlyphBounds reads TrueType ink bounds without decoding or retaining contours.

func (*Face) GlyphIndex

func (f *Face) GlyphIndex(r rune) uint16

func (*Face) GlyphKerning

func (f *Face) GlyphKerning(left, right uint16) int

GlyphKerning returns horizontal advance adjustment in font design units. GPOS kern lookups take precedence over the legacy kern table.

func (*Face) HorizontalMetrics

func (f *Face) HorizontalMetrics(glyphID uint16) (LongHorMetric, error)

func (*Face) Italic

func (f *Face) Italic() *Face

Italic returns a shared synthetic oblique face, or the original face if it already contains italic glyphs. The source must remain open while it is used. Font tables and metrics are shared; raster and outline caches are independent.

func (*Face) Outline

func (f *Face) Outline(glyphID uint16) (*Outline, error)

func (*Face) RasterizeGlyph

func (f *Face) RasterizeGlyph(glyphID uint16, pixelsPerEm float64) (*GlyphBitmap, error)

func (*Face) RasterizeGlyphAt

func (f *Face) RasterizeGlyphAt(glyphID uint16, pixelsPerEm float64, phaseX, phaseY uint8) (*GlyphBitmap, error)

RasterizeGlyphAt samples a glyph at a quarter-pixel device-space origin. The sixteen possible phases bound cache growth independently of positions.

func (*Face) ResolveGlyph

func (f *Face) ResolveGlyph(r rune) (*Face, uint16)

ResolveGlyph returns both the owning face and its local glyph ID. If every candidate is missing the character, it returns this face's .notdef glyph. System fallback faces are shared; callers must not modify or close them.

func (*Face) UseFallback

func (f *Face) UseFallback(face *Face)

UseFallback sets a shared face to consult for missing glyphs before system fallback. Configure it before measuring or rendering. The caller owns the fallback and must keep it open while this face is in use.

func (*Face) UseSystemFallback

func (f *Face) UseSystemFallback()

UseSystemFallback enables lazy, shared system glyph fallback. Configure the face before measuring or rendering it; raw glyph-ID APIs remain face-local. Closing this face does not close the shared fallback faces.

func (*Face) XHeight

func (f *Face) XHeight() int16

XHeight returns the x-height metric in font units without rasterizing.

type FaceOptions

type FaceOptions struct {
	Size float64
	DPI  float64
}

type FormatDecoder

type FormatDecoder interface {
	MatchesFont([]byte, string) bool
	DecodeFont([]byte, string) (*Face, error)
}

FormatDecoder handles one font path extension in DecoderSet.

type Glyph

type Glyph struct {
	Simple           *SimpleGlyph
	Composite        *CompositeGlyph
	Bounds           Bounds
	GlyphID          uint16
	NumberOfContours int16
}

type GlyphBitmap

type GlyphBitmap struct {
	Image   *image.Alpha
	Color   *image.RGBA
	Bounds  image.Rectangle
	Advance float64
	Scale   float64
}
type Head struct {
	UnitsPerEm       uint16
	XMin             int16
	YMin             int16
	XMax             int16
	YMax             int16
	IndexToLocFormat int16
}

type Hhea

type Hhea struct {
	Ascent              int16
	Descent             int16
	LineGap             int16
	AdvanceWidthMax     uint16
	MinLeftSideBearing  int16
	MinRightSideBearing int16
	XMaxExtent          int16
	NumberOfHMetrics    uint16
}

type Int26_6

type Int26_6 int32

Int26_6 is a signed 26.6 fixed-point number.

type LCDColor

type LCDColor uint16

LCDColor identifies Skia's eight canonical foreground intensities per channel. Coverage correction depends on foreground color, not background. Quantization bounds glyph-cache variants to 512 colors.

func GrayColorFromRGB

func GrayColorFromRGB(r, g, b uint8) LCDColor

GrayColorFromRGB selects Skia's A8 luminance bucket without prematurely quantizing the individual foreground channels.

func LCDColorFromRGB

func LCDColorFromRGB(r, g, b uint8) LCDColor

func (LCDColor) PreblendGray

func (color LCDColor) PreblendGray(bitmap *image.Alpha)

PreblendGray applies coverage gamma without LCD's five-bit quantization.

func (LCDColor) PreblendLCD

func (color LCDColor) PreblendLCD(bitmap *image.RGBA)

PreblendLCD converts raw RGB coverage into the mask used by the existing component blend passes. Alpha remains opaque. Grayscale masks are unchanged.

type LongHorMetric

type LongHorMetric struct {
	AdvanceWidth    uint16
	LeftSideBearing int16
}

type Maxp

type Maxp struct {
	NumGlyphs uint16
}

type Metrics

type Metrics struct {
	Height  Int26_6
	Ascent  Int26_6
	Descent Int26_6
}

type NoDecoder

type NoDecoder struct{}

NoDecoder fills an unused DecoderSet slot.

func (NoDecoder) DecodeFont

func (NoDecoder) DecodeFont(_ []byte, _ string) (*Face, error)

func (NoDecoder) MatchesFont

func (NoDecoder) MatchesFont([]byte, string) bool

type Outline

type Outline struct {
	Contours []OutlineContour
	Bounds   Bounds
}

type OutlineContour

type OutlineContour []OutlinePoint

type OutlinePoint

type OutlinePoint struct {
	X float64
	Y float64
}

type Point

type Point struct {
	X       int16
	Y       int16
	OnCurve bool
}

type Point26_6

type Point26_6 struct {
	X Int26_6
	Y Int26_6
}

Point26_6 is a point represented in 26.6 fixed-point coordinates.

type PositionedGlyph

type PositionedGlyph struct {
	Rune    rune
	PenX    float32
	X       float64
	Y       float64
	Advance float64
}

PositionedGlyph carries a glyph's authored position in logical pixels. PenX is the pen origin; X includes the glyph's left side bearing.

type SFNTDecoder

type SFNTDecoder struct{}

SFNTDecoder handles TTF, OTF, and TTC fonts in the core parser.

func (SFNTDecoder) DecodeFont

func (SFNTDecoder) DecodeFont(data []byte, _ string) (*Face, error)

func (SFNTDecoder) MatchesFont

func (SFNTDecoder) MatchesFont(data []byte, path string) bool

type ScaledFace

type ScaledFace struct {
	// contains filtered or unexported fields
}

func NewFace

func NewFace(face *Face, opts *FaceOptions) (*ScaledFace, error)

func (*ScaledFace) Close

func (f *ScaledFace) Close() error

func (*ScaledFace) Glyph

func (*ScaledFace) GlyphAdvance

func (f *ScaledFace) GlyphAdvance(r rune) (Int26_6, bool)

func (*ScaledFace) GlyphBounds

func (f *ScaledFace) GlyphBounds(r rune) (image.Rectangle, Int26_6, bool)

GlyphBounds matches Glyph at the pixel origin without rasterizing a bitmap.

func (*ScaledFace) GlyphLCD

func (f *ScaledFace) GlyphLCD(r rune, phaseX uint8) (image.Rectangle, *image.RGBA, Int26_6, bool)

GlyphLCD produces raw RGB coverage using Skia's four-sample LCD filter. Atlas users apply foreground preblend and retain the resulting bitmap.

func (*ScaledFace) GlyphOutline

func (f *ScaledFace) GlyphOutline(r rune) (*Outline, Int26_6, bool)

func (*ScaledFace) Kern

func (f *ScaledFace) Kern(left, right rune) Int26_6

func (*ScaledFace) Metrics

func (f *ScaledFace) Metrics() Metrics

type SimpleGlyph

type SimpleGlyph struct {
	EndPtsOfContours []uint16
	Instructions     []byte
	Points           []Point
}

type SystemFont

type SystemFont struct {
	Family    string
	Path      string
	Index     int
	Weight    int
	Italic    bool
	Monospace bool
}

SystemFont identifies one installed face, including its index in a collection. Listing faces reads metadata only; Load parses the selected face on demand.

func SystemFonts

func SystemFonts() ([]SystemFont, error)

SystemFonts returns the process-cached installed font list. Callers must not modify the returned slice. Fonts installed later become available on restart.

func (SystemFont) Load

func (f SystemFont) Load() (*Face, error)

Directories

Path Synopsis
codec

Jump to

Keyboard shortcuts

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