fonts

package
v0.0.0-...-73e6ce1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2023 License: AGPL-3.0, AGPL-3.0-only Imports: 14 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
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")
)
View Source
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")
)
View Source
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")
)
View Source
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")
)

Variables

This section is empty.

Functions

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.

Types

type CharMetrics

type CharMetrics struct {
	Wx float64
	Wy float64 // TODO(dennwc): none of code paths sets this to anything except 0
}

CharMetrics represents width and height metrics of a glyph.

func (CharMetrics) String

func (m CharMetrics) String() string

type Descriptor

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
}

Descriptor describes geometric properties of a font.

type Font

type Font interface {
	Encoder() textencoding.TextEncoder
	GetRuneMetrics(r rune) (CharMetrics, bool)
}

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 FontWeight

type FontWeight int

FontWeight specified font weight.

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

Font weights

type GID

type GID = textencoding.GID

GID is a glyph index.

type GlyphName

type GlyphName = textencoding.GlyphName

GlyphName is a name of a glyph.

type StdFont

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

StdFont represents one of the built-in fonts and it is assumed that every reader has access to it.

func NewStdFont

func NewStdFont(desc Descriptor, metrics map[rune]CharMetrics) 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 map[rune]CharMetrics, 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() map[rune]CharMetrics

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

type StdFontName string

StdFontName is a name of a standard font.

type TtfType

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
}

TtfType describes a TrueType font file. http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=iws-chapter08

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`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL