Documentation
¶
Index ¶
Constants ¶
const ToUnicodeCMap = "" /* 364-byte string literal not displayed */
ToUnicodeCMap is the standard CMap for mapping CIDs to Unicode code points. Used in the PDF ToUnicode stream for CIDFont Type2 fonts.
Variables ¶
This section is empty.
Functions ¶
func StringWidth ¶
StringWidth returns the width of s in 1/1000 text space units.
func StringWidthUTF8 ¶
StringWidthUTF8 returns the width of a UTF-8 string in 1/1000 text space units using the TTF font's character widths.
Types ¶
type CoreFont ¶
type CoreFont struct {
Name string // PDF BaseFont name
Up int // underline position
Ut int // underline thickness
Widths [256]int // character widths in 1/1000 text units
}
CoreFont holds metrics for a standard PDF core font.
type FontEntry ¶
type FontEntry struct {
Index string // sequential label: "1", "2", ... (used as /F1, /F2)
Key string // lookup key: familyStr + styleStr, e.g. "helveticaB"
Name string // PDF BaseFont name, e.g. "Helvetica-Bold"
Type string // "Core" or "TTF"
Widths [256]int // character widths in 1/1000 text space units (core fonts)
Up int // underline position
Ut int // underline thickness
ObjNum int // set during serialization
// TTF-specific fields (only set when Type == "TTF")
TTF *TTFFont // parsed TTF data
UsedRunes map[int]int // runes used in the document (for subsetting)
SubsetData []byte // subset font bytes (populated during serialization)
RuneToGlyph map[int]int // unicode -> glyph ID (populated during serialization)
DescObjNum int // FontDescriptor object number
CIDFontObjNum int // CIDFont object number
ToUnicodeObjNum int // ToUnicode CMap object number
FileFontObjNum int // font file stream object number
}
FontEntry represents a registered font.
func (*FontEntry) AddUsedRune ¶
AddUsedRune marks a rune as used in this font (for subsetting).
func (*FontEntry) AddUsedRunes ¶
AddUsedRunes marks all runes in s as used in this font.
type FontRegistry ¶
type FontRegistry struct {
// contains filtered or unexported fields
}
FontRegistry manages font registrations and deduplication.
func NewFontRegistry ¶
func NewFontRegistry() *FontRegistry
NewFontRegistry creates an empty font registry.
func (*FontRegistry) All ¶
func (r *FontRegistry) All() []*FontEntry
All returns all registered fonts in insertion order.
func (*FontRegistry) Get ¶
func (r *FontRegistry) Get(family, style string) (*FontEntry, bool)
Get retrieves a registered font entry by family and style.
func (*FontRegistry) Register ¶
func (r *FontRegistry) Register(family, style string) (*FontEntry, error)
Register registers a core font and returns its entry. If already registered, returns the existing entry. family is case-insensitive; "arial" maps to "helvetica". style is "", "B", "I", or "BI".
func (*FontRegistry) RegisterTTF ¶
func (r *FontRegistry) RegisterTTF(family, style string, ttf *TTFFont) (*FontEntry, error)
RegisterTTF registers a TrueType font from parsed TTF data. family is the user-facing name (case-insensitive). style is "", "B", "I", or "BI".
type ImageEntry ¶
type ImageEntry struct {
Key string // SHA-1 hash of data for deduplication
Name string // resource name label: "1", "2", ... → /Im1, /Im2
Data []byte // image bytes (JPEG: raw file; PNG: zlib-compressed pixels)
Width int // pixels
Height int // pixels
ColorSpace string // "DeviceRGB", "DeviceGray", "DeviceCMYK"
BPC int // bits per component (usually 8)
Filter string // "DCTDecode" for JPEG, "FlateDecode" for PNG
ObjNum int // set during serialization
// SMask holds zlib-compressed alpha-channel data for images with
// transparency (e.g. RGBA PNGs). When non-nil, putImages writes a
// separate SMask XObject and references it from the main image.
SMaskData []byte
SMaskObjNum int
}
ImageEntry holds parsed image data ready for PDF embedding.
type ImageRegistry ¶
type ImageRegistry struct {
// contains filtered or unexported fields
}
ImageRegistry manages image registrations with deduplication.
func NewImageRegistry ¶
func NewImageRegistry() *ImageRegistry
NewImageRegistry creates an empty image registry.
func (*ImageRegistry) All ¶
func (r *ImageRegistry) All() []*ImageEntry
All returns all unique images in registration order.
func (*ImageRegistry) Get ¶
func (r *ImageRegistry) Get(name string) (*ImageEntry, bool)
Get retrieves a registered image by its user-provided name.
func (*ImageRegistry) RegisterJPEG ¶
func (r *ImageRegistry) RegisterJPEG(name string, data io.Reader) (*ImageEntry, error)
RegisterJPEG registers a JPEG image. If identical image data was already registered, the existing entry is reused (deduplication via SHA-1).
func (*ImageRegistry) RegisterPNG ¶
func (r *ImageRegistry) RegisterPNG(name string, data io.Reader) (*ImageEntry, error)
RegisterPNG registers a PNG image. The pixel data is extracted and zlib-compressed for FlateDecode embedding. If the PNG has an alpha channel, a separate SMask stream is created.
type TTFFont ¶
type TTFFont struct {
// Font metrics (scaled to 1000 units per em)
Ascent int
Descent int
CapHeight int
StemV int
ItalicAngle int
Flags int
Bbox [4]int // [xMin, yMin, xMax, yMax]
UnderlinePosition float64
UnderlineThickness float64
DefaultWidth float64
// Character widths: indexed by Unicode code point (up to 65535).
// Values in units of 1/1000 text space.
CharWidths []int
// Maps: unicode code point -> glyph index
CharToGlyph map[int]int
// contains filtered or unexported fields
}
TTFFont holds parsed TrueType font data needed for PDF embedding.
func ParseTTF ¶
ParseTTF parses a TrueType font from raw bytes and extracts metrics and character widths needed for PDF generation.
func (*TTFFont) Subset ¶
Subset creates a subset TrueType font containing only the glyphs referenced by the given runes. It preserves original glyph IDs so that GPOS/GSUB table references (critical for Thai mark positioning) remain valid.
usedRunes maps arbitrary keys to Unicode code points. Returns the subset font bytes and a mapping of unicode -> glyph ID.