font

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package font provides font management functionality for PDF documents.

Index

Constants

This section is empty.

Variables

View Source
var StandardFontMap = map[string]StandardFont{

	"Helvetica":             Helvetica,
	"Helvetica-Bold":        HelveticaBold,
	"Helvetica-Oblique":     HelveticaOblique,
	"Helvetica-BoldOblique": HelveticaBoldOblique,

	"Times-Roman":      TimesRoman,
	"Times-Bold":       TimesBold,
	"Times-Italic":     TimesItalic,
	"Times-BoldItalic": TimesBoldItalic,

	"Courier":             Courier,
	"Courier-Bold":        CourierBold,
	"Courier-Oblique":     CourierOblique,
	"Courier-BoldOblique": CourierBoldOblique,

	"Symbol":       Symbol,
	"ZapfDingbats": ZapfDingbats,
}

StandardFontMap maps PDF font names to StandardFont values.

Functions

func ContainsFont added in v0.12.0

func ContainsFont(fontName, target string) bool

ContainsFont checks if fontName contains the target string (case-insensitive).

func IsStandardFontName

func IsStandardFontName(name string) bool

IsStandardFontName checks if a given name is a standard font.

Types

type StandardFont

type StandardFont string

StandardFont represents one of the 14 standard PDF fonts. These fonts are built into PDF viewers and don't need to be embedded.

const (
	// Sans-serif fonts
	Helvetica            StandardFont = "Helvetica"
	HelveticaBold        StandardFont = "Helvetica-Bold"
	HelveticaOblique     StandardFont = "Helvetica-Oblique"
	HelveticaBoldOblique StandardFont = "Helvetica-BoldOblique"

	// Serif fonts
	TimesRoman      StandardFont = "Times-Roman"
	TimesBold       StandardFont = "Times-Bold"
	TimesItalic     StandardFont = "Times-Italic"
	TimesBoldItalic StandardFont = "Times-BoldItalic"

	// Monospace fonts
	Courier            StandardFont = "Courier"
	CourierBold        StandardFont = "Courier-Bold"
	CourierOblique     StandardFont = "Courier-Oblique"
	CourierBoldOblique StandardFont = "Courier-BoldOblique"

	// Symbol fonts
	Symbol       StandardFont = "Symbol"
	ZapfDingbats StandardFont = "ZapfDingbats"
)

Standard Type1 fonts defined in PDF specification

func GetStandardFont

func GetStandardFont(name string) (StandardFont, error)

GetStandardFont returns a StandardFont by name. Returns an error if the font name is not a standard font.

func MapToStandardFont added in v0.12.0

func MapToStandardFont(fontName string, isBold bool) (StandardFont, bool)

MapToStandardFont maps a PDF font name to a StandardFont. Returns the mapped font and true if found, otherwise empty string and false.

func (StandardFont) Encoding

func (f StandardFont) Encoding() string

Encoding returns the encoding used by the font.

func (StandardFont) IsStandard

func (f StandardFont) IsStandard() bool

IsStandard returns true since this is a standard font.

func (StandardFont) Name

func (f StandardFont) Name() string

Name returns the PostScript name of the font.

func (StandardFont) Type

func (f StandardFont) Type() string

Type returns the font type (always "Type1" for standard fonts).

type TTFFont

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

TTFFont represents a TrueType Font

func LoadSystemJapaneseFont added in v0.12.0

func LoadSystemJapaneseFont() (*TTFFont, error)

LoadSystemJapaneseFont loads a Japanese font from system fonts.

func LoadTTF

func LoadTTF(path string) (*TTFFont, error)

LoadTTF loads a TrueType font from a file path

func LoadTTFFromBytes

func LoadTTFFromBytes(data []byte) (*TTFFont, error)

LoadTTFFromBytes loads a TrueType font from byte slice It handles both TTF (single font) and TTC (font collection) files

func (*TTFFont) Data

func (f *TTFFont) Data() []byte

Data returns the original font file data

func (*TTFFont) Font

func (f *TTFFont) Font() *sfnt.Font

Font returns the underlying sfnt.Font

func (*TTFFont) GetGlyphIndex

func (f *TTFFont) GetGlyphIndex(r rune) (uint16, error)

GetGlyphIndex returns the glyph index for a rune This is used to map Unicode characters to actual glyph indices in the font

func (*TTFFont) GlyphWidth

func (f *TTFFont) GlyphWidth(r rune, fontSize float64) (float64, error)

GlyphWidth returns the width of a character in PDF user units

func (*TTFFont) GlyphWidthBatch

func (f *TTFFont) GlyphWidthBatch(runes []rune, fontSize float64) ([]float64, error)

GlyphWidthBatch returns widths for multiple characters

func (*TTFFont) Name

func (f *TTFFont) Name() string

Name returns the font name

func (*TTFFont) TextWidth

func (f *TTFFont) TextWidth(text string, fontSize float64) (float64, error)

TextWidth calculates the total width of a text string

Jump to

Keyboard shortcuts

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