Documentation
¶
Overview ¶
Package font provides font management functionality for PDF documents.
Index ¶
- Variables
- func ContainsFont(fontName, target string) bool
- func IsStandardFontName(name string) bool
- type StandardFont
- type TTFFont
- func (f *TTFFont) Data() []byte
- func (f *TTFFont) Font() *sfnt.Font
- func (f *TTFFont) GetGlyphIndex(r rune) (uint16, error)
- func (f *TTFFont) GlyphWidth(r rune, fontSize float64) (float64, error)
- func (f *TTFFont) GlyphWidthBatch(runes []rune, fontSize float64) ([]float64, error)
- func (f *TTFFont) Name() string
- func (f *TTFFont) TextWidth(text string, fontSize float64) (float64, error)
Constants ¶
This section is empty.
Variables ¶
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
ContainsFont checks if fontName contains the target string (case-insensitive).
func IsStandardFontName ¶
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
LoadSystemJapaneseFont loads a Japanese font from system fonts.
func LoadTTFFromBytes ¶
LoadTTFFromBytes loads a TrueType font from byte slice It handles both TTF (single font) and TTC (font collection) files
func (*TTFFont) GetGlyphIndex ¶
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 ¶
GlyphWidth returns the width of a character in PDF user units
func (*TTFFont) GlyphWidthBatch ¶
GlyphWidthBatch returns widths for multiple characters