Documentation
¶
Overview ¶
Package imagefont builds bitmap fonts for terminal image rendering. It does not install fonts, change terminal preferences, or write files.
Index ¶
- Constants
- func EncodePNG(ctx context.Context, encoder *png.Encoder, dst io.Writer, src image.Image) (err error)
- func PreservedGlyphCapacity(source PreserveOptions) (int, error)
- func ScaleBitmap(ctx context.Context, dst draw.Image, dr image.Rectangle, src image.Image, ...) (err error)
- type Font
- type Frame
- type Options
- type PreserveOptions
- type Preview
Constants ¶
const ( FirstCodepoint = '\ue000' LastCodepoint = '\uf8ff' MaxGlyphs = int(LastCodepoint-FirstCodepoint) + 1 MaxFrameRows = 32 )
const ( FirstSupplementaryCodepoint = '\U000f0000' LastSupplementaryCodepoint = FirstSupplementaryCodepoint + rune(MaxGlyphs) - 1 )
Variables ¶
This section is empty.
Functions ¶
func EncodePNG ¶
func EncodePNG(ctx context.Context, encoder *png.Encoder, dst io.Writer, src image.Image) (err error)
EncodePNG checks cancellation while scanning pixels and writing compressed data, including highly compressible images that rarely flush their output. The PNG library still filters and compresses each scanline between callbacks; font bitmaps bound their width before calling this helper.
func PreservedGlyphCapacity ¶ added in v1.28.0
func PreservedGlyphCapacity(source PreserveOptions) (int, error)
PreservedGlyphCapacity reports the aggregate image-cell budget for this text face and geometry. Callers can reserve cells before adding optional previews. Encoding still validates individual frame dimensions and all source tables.
Types ¶
type Font ¶
func Encode ¶
Encode creates a TrueType font containing lossless PNG glyphs at 32 and 64ppem. Tiles default to 16×32 pixels at 32ppem. The 750/-250 ascent/descent divide evenly at 16pt and 32pt. Custom tile geometry affects only image pixels; text advances and line metrics remain fixed to avoid changing the cell layout. Image fitting preserves aspect ratio and alpha, with transparent edge padding. An empty frame list produces the base monospace ASCII font for initial setup.
func EncodePreserving ¶
func EncodePreserving(ctx context.Context, frames []Frame, options Options, source PreserveOptions) (Font, error)
EncodePreserving creates a private, uniquely named copy of an outline face, with extra bitmap glyphs. Source font files are never modified. Images occupy a supplementary private-use range, preserving existing BMP icons.
type Frame ¶
type Frame struct {
Image image.Image
Columns, Rows int // Zero selects 32 columns and an aspect-ratio-derived row count.
CodepointStart rune // Zero allocates after the preceding frame, starting at U+E000.
}
Frame supplies one image and its immutable character range. Reusing its range for a different image would change the appearance of existing text.
type Options ¶
type Options struct {
Family, PostScript string
// TileWidth and TileHeight are bitmap dimensions at 32ppem. Both zero selects
// 16×32. Otherwise width must be 8..24 and height 16..48. These adapt image
// tiles to terminal cell spacing without changing the font's text metrics.
TileWidth, TileHeight int
}
Options identifies this font and its bitmap cell geometry. Callers must choose a unique identity whenever the contents change because platform font caches can retain older glyphs.
type PreserveOptions ¶
type PreserveOptions struct {
Tables map[string][]byte
SourcePostScript string
// SourceName retains an exact bundled full face name when PostScript names
// are shared by different installed files. Empty uses SourcePostScript.
SourceName string
Variations map[string]float64
// FamilyClass is the native public typographic classification (0..15).
FamilyClass uint8
PointSize int
CellWidth, CellHeight int
Baseline int
// TextHeight is the original font's natural line height rounded up, before
// profile spacing. Monaco needs this to preserve Terminal's special layout.
TextHeight int
// LegacyAliases restores old BMP gallery characters during an explicit
// migration. Off by default so fallback-font private-use icons are retained.
LegacyAliases bool
}
PreserveOptions supplies the installed text face to extend. Its original outlines, hinting, layout tables, style, character mappings and text metrics remain unchanged. Pixel geometry is measured from the user's Terminal tab.