const ( // CourierName is a PDF name of the Courier font. CourierName = StdFontName("Courier") // CourierBoldName is a PDF name of the Courier (bold) font. CourierBoldName = StdFontName("Courier-Bold") // CourierObliqueName is a PDF name of the Courier (oblique) font. CourierObliqueName = StdFontName("Courier-Oblique") // CourierBoldObliqueName is a PDF name of the Courier (bold, oblique) font. CourierBoldObliqueName = StdFontName("Courier-BoldOblique") )
const ( // HelveticaName is a PDF name of the Helvetica font. HelveticaName = StdFontName("Helvetica") // HelveticaBoldName is a PDF name of the Helvetica (bold) font. HelveticaBoldName = StdFontName("Helvetica-Bold") // HelveticaObliqueName is a PDF name of the Helvetica (oblique) font. HelveticaObliqueName = StdFontName("Helvetica-Oblique") // HelveticaBoldObliqueName is a PDF name of the Helvetica (bold, oblique) font. HelveticaBoldObliqueName = StdFontName("Helvetica-BoldOblique") )
const ( // SymbolName is a PDF name of the Symbol font. SymbolName = StdFontName("Symbol") // ZapfDingbatsName is a PDF name of the ZapfDingbats font. ZapfDingbatsName = StdFontName("ZapfDingbats") )
const ( // TimesRomanName is a PDF name of the Times font. TimesRomanName = StdFontName("Times-Roman") // TimesBoldName is a PDF name of the Times (bold) font. TimesBoldName = StdFontName("Times-Bold") // TimesItalicName is a PDF name of the Times (italic) font. TimesItalicName = StdFontName("Times-Italic") // TimesBoldItalicName is a PDF name of the Times (bold, italic) font. TimesBoldItalicName = StdFontName("Times-BoldItalic") )
func IsStdFont(name StdFontName) bool
IsStdFont check if a name is registered for a standard font.
func RegisterStdFont(name StdFontName, fnc func() StdFont, aliases ...StdFontName)
RegisterStdFont registers a given StdFont constructor by font name. Font can then be created with NewStdFontByName.
CharMetrics represents width and height metrics of a glyph.
type CharMetrics struct { Wx float64 Wy float64 // TODO(dennwc): none of code paths sets this to anything except 0 }
func (m CharMetrics) String() string
Descriptor describes geometric properties of a font.
type Descriptor struct { Name StdFontName Family string Weight FontWeight Flags uint BBox [4]float64 ItalicAngle float64 Ascent float64 Descent float64 CapHeight float64 XHeight float64 StemV float64 StemH float64 }
Font represents a font which is a series of glyphs. Character codes from PDF strings can be mapped to and from glyphs. Each glyph has metrics.
type Font interface { Encoder() textencoding.TextEncoder GetRuneMetrics(r rune) (CharMetrics, bool) }
FontWeight specified font weight.
type FontWeight int
Font weights
const ( FontWeightMedium FontWeight = iota // Medium FontWeightBold // Bold FontWeightRoman // Roman )
GID is a glyph index.
type GID = textencoding.GID
GlyphName is a name of a glyph.
type GlyphName = textencoding.GlyphName
RuneCharSafeMap is the concurrently safe map for rune and charmetrics.
type RuneCharSafeMap struct {
// contains filtered or unexported fields
}
func MakeRuneCharSafeMap(length int) *RuneCharSafeMap
MakeRuneCharSafeMap creates new RuneCharSafeMap with provided length.
func (m *RuneCharSafeMap) Copy() *RuneCharSafeMap
Copy creates a copy of given map.
func (m *RuneCharSafeMap) Length() int
Length returns the length of the map.
func (m *RuneCharSafeMap) Range(f func(key rune, val CharMetrics) (breakLoop bool))
Range is a function that iterates over the key, values with a read lock. It executes provided input 'f' function. If the function returns false the iteration breaks.
func (m *RuneCharSafeMap) Read(b rune) (CharMetrics, bool)
Read reads the map value.
func (m *RuneCharSafeMap) Write(b rune, r CharMetrics)
Write writes into the map concurrently safe.
StdFont represents one of the built-in fonts and it is assumed that every reader has access to it.
type StdFont struct {
// contains filtered or unexported fields
}
func NewStdFont(desc Descriptor, metrics *RuneCharSafeMap) StdFont
NewStdFont returns a new instance of the font with a default encoder set (StandardEncoding).
func NewStdFontByName(name StdFontName) (StdFont, bool)
NewStdFontByName creates a new StdFont by registered name. See RegisterStdFont.
func NewStdFontWithEncoding(desc Descriptor, metrics *RuneCharSafeMap, encoder textencoding.TextEncoder) StdFont
NewStdFontWithEncoding returns a new instance of the font with a specified encoder.
func (font StdFont) Descriptor() Descriptor
Descriptor returns a font descriptor.
func (font StdFont) Encoder() textencoding.TextEncoder
Encoder returns the font's text encoder.
func (font StdFont) GetMetricsTable() *RuneCharSafeMap
GetMetricsTable is a method specific to standard fonts. It returns the metrics table of all glyphs. Caller should not modify the table.
func (font StdFont) GetRuneMetrics(r rune) (CharMetrics, bool)
GetRuneMetrics returns character metrics for a given rune.
func (font StdFont) Name() string
Name returns a PDF name of the font.
func (font StdFont) ToPdfObject() core.PdfObject
ToPdfObject returns a primitive PDF object representation of the font.
StdFontName is a name of a standard font.
type StdFontName string
TtfType describes a TrueType font file. http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-chapter08
type TtfType struct { UnitsPerEm uint16 PostScriptName string Bold bool ItalicAngle float64 IsFixedPitch bool TypoAscender int16 TypoDescender int16 UnderlinePosition int16 UnderlineThickness int16 Xmin, Ymin, Xmax, Ymax int16 CapHeight int16 // Widths is a list of glyph widths indexed by GID. Widths []uint16 // Chars maps rune values (unicode) to GIDs (the indexes in GlyphNames). i.e. GlyphNames[Chars[r]] is // the glyph corresponding to rune r. // // TODO(dennwc): CharCode is currently defined as uint16, but some tables may store 32 bit charcodes // not the case right now, but make sure to update it once we support those tables // TODO(dennwc,peterwilliams97): it should map char codes to GIDs Chars map[rune]GID // GlyphNames is a list of glyphs from the "post" section of the TrueType file. GlyphNames []GlyphName }
func NewFontFile2FromPdfObject(obj core.PdfObject) (TtfType, error)
NewFontFile2FromPdfObject returns a TtfType describing the TrueType font file in PdfObject `obj`.
func TtfParse(r io.ReadSeeker) (TtfType, error)
TtfParse returns a TtfType describing the TrueType font.
func TtfParseFile(fileStr string) (TtfType, error)
TtfParseFile returns a TtfType describing the TrueType font file in disk file `fileStr`.
func (ttf *TtfType) MakeEncoder() (textencoding.SimpleEncoder, error)
MakeEncoder returns an encoder built from the tables in `rec`.
func (ttf *TtfType) MakeToUnicode() *cmap.CMap
MakeToUnicode returns a ToUnicode CMap based on the encoding of `ttf`. TODO(peterwilliams97): This currently gives a bad text mapping for creator_test.go but leads to an otherwise valid PDF file that Adobe Reader displays without error.
func (ttf *TtfType) NewEncoder() textencoding.TextEncoder
NewEncoder returns a new TrueType font encoder.
func (ttf *TtfType) String() string
String returns a human readable representation of `ttf`.