HomeUniDoc
...

Package fonts

Overview ▾

Package fonts is used for internal representation for working with fonts in PDF.

Index ▾

Constants
func IsStdFont(name StdFontName) bool
func RegisterStdFont(name StdFontName, fnc func() StdFont, aliases ...StdFontName)
type CharMetrics
    func (m CharMetrics) String() string
type Descriptor
type Font
type FontWeight
type GID
type GlyphName
type RuneCharSafeMap
    func MakeRuneCharSafeMap(length int) *RuneCharSafeMap
    func (m *RuneCharSafeMap) Copy() *RuneCharSafeMap
    func (m *RuneCharSafeMap) Length() int
    func (m *RuneCharSafeMap) Range(f func(key rune, val CharMetrics) (breakLoop bool))
    func (m *RuneCharSafeMap) Read(b rune) (CharMetrics, bool)
    func (m *RuneCharSafeMap) Write(b rune, r CharMetrics)
type StdFont
    func NewStdFont(desc Descriptor, metrics *RuneCharSafeMap) StdFont
    func NewStdFontByName(name StdFontName) (StdFont, bool)
    func NewStdFontWithEncoding(desc Descriptor, metrics *RuneCharSafeMap, encoder textencoding.TextEncoder) StdFont
    func (font StdFont) Descriptor() Descriptor
    func (font StdFont) Encoder() textencoding.TextEncoder
    func (font StdFont) GetMetricsTable() *RuneCharSafeMap
    func (font StdFont) GetRuneMetrics(r rune) (CharMetrics, bool)
    func (font StdFont) Name() string
    func (font StdFont) ToPdfObject() core.PdfObject
type StdFontName
type TtfType
    func NewFontFile2FromPdfObject(obj core.PdfObject) (TtfType, error)
    func TtfParse(r io.ReadSeeker) (TtfType, error)
    func TtfParseFile(fileStr string) (TtfType, error)
    func (ttf *TtfType) MakeEncoder() (textencoding.SimpleEncoder, error)
    func (ttf *TtfType) MakeToUnicode() *cmap.CMap
    func (ttf *TtfType) NewEncoder() textencoding.TextEncoder
    func (ttf *TtfType) String() string

Package files

doc.go font.go safe_map.go std.go std_courier.go std_helvetica.go std_other.go std_times.go ttfparser.go

Constants

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

func IsStdFont(name StdFontName) bool

IsStdFont check if a name is registered for a standard font.

func RegisterStdFont

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.

type CharMetrics

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 (CharMetrics) String

func (m CharMetrics) String() string

type Descriptor

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
}

type Font

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)
}

type FontWeight

FontWeight specified font weight.

type FontWeight int

Font weights

const (
    FontWeightMedium FontWeight = iota // Medium
    FontWeightBold                     // Bold
    FontWeightRoman                    // Roman
)

type GID

GID is a glyph index.

type GID = textencoding.GID

type GlyphName

GlyphName is a name of a glyph.

type GlyphName = textencoding.GlyphName

type RuneCharSafeMap

RuneCharSafeMap is the concurrently safe map for rune and charmetrics.

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

func MakeRuneCharSafeMap

func MakeRuneCharSafeMap(length int) *RuneCharSafeMap

MakeRuneCharSafeMap creates new RuneCharSafeMap with provided length.

func (*RuneCharSafeMap) Copy

func (m *RuneCharSafeMap) Copy() *RuneCharSafeMap

Copy creates a copy of given map.

func (*RuneCharSafeMap) Length

func (m *RuneCharSafeMap) Length() int

Length returns the length of the map.

func (*RuneCharSafeMap) Range

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 (*RuneCharSafeMap) Read

func (m *RuneCharSafeMap) Read(b rune) (CharMetrics, bool)

Read reads the map value.

func (*RuneCharSafeMap) Write

func (m *RuneCharSafeMap) Write(b rune, r CharMetrics)

Write writes into the map concurrently safe.

type StdFont

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

func NewStdFont(desc Descriptor, metrics *RuneCharSafeMap) StdFont

NewStdFont returns a new instance of the font with a default encoder set (StandardEncoding).

func NewStdFontByName

func NewStdFontByName(name StdFontName) (StdFont, bool)

NewStdFontByName creates a new StdFont by registered name. See RegisterStdFont.

func NewStdFontWithEncoding

func NewStdFontWithEncoding(desc Descriptor, metrics *RuneCharSafeMap, encoder textencoding.TextEncoder) StdFont

NewStdFontWithEncoding returns a new instance of the font with a specified encoder.

func (StdFont) Descriptor

func (font StdFont) Descriptor() Descriptor

Descriptor returns a font descriptor.

func (StdFont) Encoder

func (font StdFont) Encoder() textencoding.TextEncoder

Encoder returns the font's text encoder.

func (StdFont) GetMetricsTable

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 (StdFont) GetRuneMetrics

func (font StdFont) GetRuneMetrics(r rune) (CharMetrics, bool)

GetRuneMetrics returns character metrics for a given rune.

func (StdFont) Name

func (font StdFont) Name() string

Name returns a PDF name of the font.

func (StdFont) ToPdfObject

func (font StdFont) ToPdfObject() core.PdfObject

ToPdfObject returns a primitive PDF object representation of the font.

type StdFontName

StdFontName is a name of a standard font.

type StdFontName string

type TtfType

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

func NewFontFile2FromPdfObject(obj core.PdfObject) (TtfType, error)

NewFontFile2FromPdfObject returns a TtfType describing the TrueType font file in PdfObject `obj`.

func TtfParse

func TtfParse(r io.ReadSeeker) (TtfType, error)

TtfParse returns a TtfType describing the TrueType font.

func TtfParseFile

func TtfParseFile(fileStr string) (TtfType, error)

TtfParseFile returns a TtfType describing the TrueType font file in disk file `fileStr`.

func (*TtfType) MakeEncoder

func (ttf *TtfType) MakeEncoder() (textencoding.SimpleEncoder, error)

MakeEncoder returns an encoder built from the tables in `rec`.

func (*TtfType) MakeToUnicode

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 (*TtfType) NewEncoder

func (ttf *TtfType) NewEncoder() textencoding.TextEncoder

NewEncoder returns a new TrueType font encoder.

func (*TtfType) String

func (ttf *TtfType) String() string

String returns a human readable representation of `ttf`.