Documentation
¶
Overview ¶
Package font provides support for TrueType fonts.
Index ¶
- Variables
- func Ascent(fontName string, fontSize int) (float64, error)
- func BoundingBox(fontName string) (*types.Rectangle, error)
- func CharWidth(fontName string, r rune) (int, error)
- func CoreFontNames() []string
- func Descent(fontName string, fontSize int) (float64, error)
- func GlyphSpaceUnits(userSpaceUnits float64, fontScalingFactor int) float64
- func GlyphSpaceUnitsFloat(userSpaceUnits, fontScalingFactor float64) float64
- func InstallFontFromBytes(fontDir, fontName string, bb []byte) error
- func InstallFontFromBytesQuiet(fontDir, fontName string, bb []byte) error
- func IsCoreFont(fontName string) bool
- func IsUserFont(fontName string) (bool, error)
- func LineHeight(fontName string, fontSize int) (float64, error)
- func LoadUserFonts() error
- func Read(fileName string) (bb []byte, err error)
- func ReloadUserFonts() error
- func Size(text, fontName string, width float64) (int, error)
- func SizeForLineHeight(fontName string, lh float64) (int, error)
- func Subset(fontName string, usedGIDs map[uint16]bool) ([]byte, error)
- func SupportedFont(fontName string) (bool, error)
- func TextWidth(text, fontName string, fontSize int) (float64, error)
- func TextWidthFloat(text, fontName string, fontSize float64) (float64, error)
- func UserFontNames() ([]string, error)
- func UserFontNamesVerbose() ([]string, error)
- func UserSpaceFontBBox(fontName string, fontSize int) (*types.Rectangle, error)
- func UserSpaceUnits(glyphSpaceUnits float64, fontScalingFactor int) float64
- func UserSpaceUnitsFloat(glyphSpaceUnits, fontScalingFactor float64) float64
- func ValidateTTFLight(fd TTFLight) error
- type InstallReport
- func InstallTrueTypeCollection(fontDir, fn string) (InstallReport, error)
- func InstallTrueTypeCollectionResults(fontDir, fn string) (InstallReport, error)
- func InstallTrueTypeFont(fontDir, fontName string) (InstallReport, error)
- func InstallTrueTypeFontResult(fontDir, fontName string) (InstallReport, error)
- type InstallResult
- type TTFLight
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingFontDir signals a missing destination font directory. ErrMissingFontDir = errors.New("missing font directory") // ErrMissingFontName signals a missing font name. ErrMissingFontName = errors.New("missing font name") // ErrMissingFontData signals missing font data. ErrMissingFontData = errors.New("missing font data") // ErrInvalidFontData signals malformed or inconsistent font data. ErrInvalidFontData = errors.New("invalid font data") // ErrUnsupportedFontFormat signals a valid but unsupported font format. ErrUnsupportedFontFormat = errors.New("unsupported font format") // ErrUnknownFont signals an unavailable font. ErrUnknownFont = errors.New("unknown font") // ErrDuplicatePostScriptName signals conflicting PostScript output names. ErrDuplicatePostScriptName = errors.New("duplicate PostScript name") )
var UserFontDir string
UserFontDir is the location for installed TTF or OTF font files.
Functions ¶
func BoundingBox ¶
BoundingBox returns the font bounding box for a given font.
func CoreFontNames ¶
func CoreFontNames() []string
CoreFontNames returns a list of the 14 PDF standard Type 1 fonts.
func GlyphSpaceUnits ¶ added in v0.3.3
GlyphSpaceUnits transforms userSpaceUnits into glyphspace Units.
func GlyphSpaceUnitsFloat ¶ added in v0.14.0
GlyphSpaceUnitsFloat transforms userSpaceUnits into glyphspace units using a fractional font scaling factor.
func InstallFontFromBytes ¶ added in v0.7.0
InstallFontFromBytes saves an internal representation of TrueType font fontName to the pdfcpu config dir.
func InstallFontFromBytesQuiet ¶ added in v0.14.0
InstallFontFromBytesQuiet saves an internal representation of TrueType font fontName without logging.
func IsCoreFont ¶
IsCoreFont returns true for the 14 PDF standard Type 1 fonts.
func IsUserFont ¶
IsUserFont returns true for installed TrueType fonts.
func LineHeight ¶ added in v0.3.3
LineHeight returns fontName's line height in user-space units for fontSize.
func LoadUserFonts ¶ added in v0.3.6
func LoadUserFonts() error
LoadUserFonts loads any installed TTF or OTF font files. This function is idempotent - it can be called multiple times safely. The actual loading happens exactly once, protected by sync.Once.
func ReloadUserFonts ¶ added in v0.14.0
func ReloadUserFonts() error
ReloadUserFonts reloads installed user fonts after the font directory has changed.
func SizeForLineHeight ¶ added in v0.7.0
SizeForLineHeight returns the needed font size in points for rendering using a given font name fitting into given line height lh.
func SupportedFont ¶
SupportedFont returns true for core fonts or installed user fonts.
func TextWidthFloat ¶ added in v0.14.0
TextWidthFloat returns the width in user-space units for text using a fractional font size.
func UserFontNames ¶
UserFontNames returns a list of all installed TrueType fonts.
func UserFontNamesVerbose ¶ added in v0.3.7
UserFontNamesVerbose returns installed TrueType fonts with glyph counts.
func UserSpaceFontBBox ¶
UserSpaceFontBBox returns the font box for given font name and font size in user space coordinates.
func UserSpaceUnits ¶ added in v0.3.3
UserSpaceUnits transforms glyphSpaceUnits into userspace units.
func UserSpaceUnitsFloat ¶ added in v0.14.0
UserSpaceUnitsFloat transforms glyphSpaceUnits into userspace units using a fractional font scaling factor.
func ValidateTTFLight ¶ added in v0.14.0
ValidateTTFLight validates the semantic invariants required for font embedding.
Types ¶
type InstallReport ¶ added in v0.14.0
type InstallReport struct {
Fonts []InstallResult
Warnings []error
}
InstallReport describes successfully installed fonts and non-fatal cleanup failures. A non-nil warning means the fonts were published successfully but temporary or backup artifacts may remain.
func InstallTrueTypeCollection ¶ added in v0.3.7
func InstallTrueTypeCollection(fontDir, fn string) (InstallReport, error)
InstallTrueTypeCollection transactionally installs all fonts contained in a TrueType collection. No collection member remains installed when parsing, staging, or commit fails. Cleanup failures after publication are returned in InstallReport.Warnings.
func InstallTrueTypeCollectionResults ¶ added in v0.14.0
func InstallTrueTypeCollectionResults(fontDir, fn string) (InstallReport, error)
InstallTrueTypeCollectionResults transactionally installs a TrueType collection and reports every member. No collection member remains installed when parsing, staging, or commit fails. Cleanup failures after publication are returned in InstallReport.Warnings.
func InstallTrueTypeFont ¶
func InstallTrueTypeFont(fontDir, fontName string) (InstallReport, error)
InstallTrueTypeFont saves an internal representation of TrueType font fontName to the pdfcpu config dir.
func InstallTrueTypeFontResult ¶ added in v0.14.0
func InstallTrueTypeFontResult(fontDir, fontName string) (InstallReport, error)
InstallTrueTypeFontResult saves a TrueType font and reports its installed PostScript name.
type InstallResult ¶ added in v0.14.0
InstallResult identifies an installed PostScript font name and optional collection member.
type TTFLight ¶
type TTFLight struct {
PostscriptName string // name: NameID 6
Protected bool // OS/2: fsType
UnitsPerEm int // head: unitsPerEm
Ascent int // OS/2: sTypoAscender
Descent int // OS/2: sTypoDescender
CapHeight int // OS/2: sCapHeight
FirstChar uint16 // OS/2: fsFirstCharIndex
LastChar uint16 // OS/2: fsLastCharIndex
UnicodeRange [4]uint32 // OS/2: Unicode Character Range
LLx, LLy, URx, URy float64 // head: xMin, yMin, xMax, yMax (fontbox)
ItalicAngle float64 // post: italicAngle
FixedPitch bool // post: isFixedPitch
Bold bool // OS/2: usWeightClass == 7
HorMetricsCount int // hhea: numOfLongHorMetrics
GlyphCount int // maxp: numGlyphs
GlyphWidths []int // hmtx: fd.HorMetricsCount.advanceWidth
Chars map[uint32]uint16 // cmap: Unicode character to glyph index
ToUnicode map[uint16]uint32 // map glyph index to unicode character
Planes map[int]bool // used Unicode planes
}
TTFLight represents a TrueType font w/o font file.
func UserFont ¶ added in v0.14.0
UserFont returns a detached copy of the metrics for an installed TrueType font.