opentype

package
v0.0.0-...-61352bb Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Font

type Font struct {
	IsCFF bool

	GlyphNames []string

	FontName string // PostScript name for the font. Set after names table has been read or within a CFF font

	UnitsPerEM  uint16
	ToUni       map[int]rune // glyph id to unicode value
	ToCodepoint map[rune]int

	Hhea                Hhea
	Head                Head
	Maxp                Maxp
	Post                Post
	OS2                 OS2
	OS2AdditionalFields OS2AdditionalFields
	Glyph               []Glyph
	SubsetID            string
	CFF                 *cff.CFF
	// contains filtered or unexported fields
}

Font represents the font file for a TrueType font

func LoadFace

func LoadFace(filename string, fontindex int) (*Font, error)

LoadFace loads a truetype font. The fontindex is a 0 based index within the font (ttc or cff for example).

func Open

func Open(r io.ReadSeeker, fontindex int) (*Font, error)

Open initializes the TrueType font

func (*Font) Ascender

func (tt *Font) Ascender() int

Ascender returns the /Ascent value for the PDF file

func (*Font) BoundingBox

func (tt *Font) BoundingBox() string

BoundingBox returns the /FontBBox value for the PDF file

func (*Font) CMap

func (tt *Font) CMap() string

CMap returns a CMap string to be used in a PDF file

func (*Font) CapHeight

func (tt *Font) CapHeight() int

CapHeight returns the /CapHeight value for the PDF file

func (*Font) Codepoints

func (tt *Font) Codepoints(runes []rune) []int

Codepoints returns the codepoints for each rune

func (*Font) Descender

func (tt *Font) Descender() int

Descender returns the /Descent value for the PDF file

func (*Font) Flags

func (tt *Font) Flags() int

Flags returns the /Flags value for the PDF file

func (*Font) GetIndex

func (tt *Font) GetIndex(r rune) (int, error)

GetIndex returns the internal code point for this rune

func (*Font) GlyphAdvance

func (tt *Font) GlyphAdvance(idx int) (int, error)

GlyphAdvance returns the width of the glyph

func (*Font) ItalicAngle

func (tt *Font) ItalicAngle() int

ItalicAngle returns the /ItalicAngle value for the PDF file

func (*Font) PDFName

func (tt *Font) PDFName() string

PDFName returns the font name with the subset id.

func (*Font) ReadTableData

func (tt *Font) ReadTableData(tbl string) ([]byte, error)

ReadTableData does not interpret the bytes read.

func (*Font) ReadTables

func (tt *Font) ReadTables() error

ReadTables reads all tables from the font file

func (*Font) StemV

func (tt *Font) StemV() int

StemV returns the /StemV value for the PDF file

func (*Font) String

func (tt *Font) String() string

func (*Font) Subset

func (tt *Font) Subset(codepoints []int) error

Subset removes all data from the font except the one needed for the given code points.

func (*Font) Widths

func (tt *Font) Widths() string

Widths returns a widths string to be used in a PDF file

func (*Font) WriteSubset

func (tt *Font) WriteSubset(w io.Writer) error

WriteSubset writes a valid font to w that is suitable for including in PDF

func (*Font) WriteTable

func (tt *Font) WriteTable(w io.Writer, tbl string) error

WriteTable writes the table to w.

func (*Font) XHeight

func (tt *Font) XHeight() int

XHeight returns the /XHeight value for the PDF file

type Glyph

type Glyph []byte

Glyph is a TrueType glyph. Since we are not interested in the glyph details, only the whole data is stored here

type Head struct {
	MajorVersion       uint16 // 1
	MinorVersion       uint16 // 0
	FontRevision       uint32 // fixed
	ChecksumAdjustment uint32 // to be calculated
	MagicNumber        uint32 // 0x5F0F3CF5
	Flags              uint16
	UnitsPerEm         uint16
	Created            uint64
	Modified           uint64
	XMin               uint16
	YMin               uint16
	XMax               uint16
	YMax               uint16
	MacStyle           uint16
	LowestRecPPEM      uint16
	FontDirectionHint  int16
	IndexToLocFormat   int16
	GlyphDataFormat    int16
}

Head Font header

type Hhea

type Hhea struct {
	MajorVersion        uint16 // 1
	MinorVersion        uint16 // 0
	Ascender            int16  // see spec
	Descender           int16  // see spec
	LineGap             int16  // Negative LineGap values are treated as zero in some legacy platform implementations.
	AdvanceWidthMax     uint16
	MinLeftSideBearing  int16
	MinRightSideBearing int16
	XMaxExtent          int16
	CaretSlopeRise      int16
	CaretSlopeRun       int16
	CaretOffset         int16
	MetricDataFormat    int16
	NumberOfHMetrics    uint16
}

Hhea Horizontal Header Table.

type Maxp

type Maxp struct {
	Version               uint32
	NumGlyphs             uint16
	MaxPoints             uint16
	MaxContours           uint16
	MaxCompositePoints    uint16
	MaxCompositeContours  uint16
	MaxZones              uint16
	MaxTwilightPoints     uint16
	MaxStorage            uint16
	MaxFunctionDefs       uint16
	MaxInstructionDefs    uint16
	MaxStackElements      uint16
	MaxSizeOfInstructions uint16
	MaxComponentElements  uint16
	MaxComponentDepth     uint16
}

Maxp table maxp

type OS2

type OS2 struct {
	Version             uint16
	XAvgCharWidth       int16
	UsWeightClass       uint16
	UsWidthClass        uint16
	FsType              uint16
	YSubscriptXSize     int16
	YSubscriptYSize     int16
	YSubscriptXOffset   int16
	YSubscriptYOffset   int16
	YSuperscriptXSize   int16
	YSuperscriptYSize   int16
	YSuperscriptXOffset int16
	YSuperscriptYOffset int16
	YStrikeoutSize      int16
	YStrikeoutPosition  int16
	SFamilyClass        int16
	Panose              [10]uint8
	UlUnicodeRange1     uint32
	UlUnicodeRange2     uint32
	UlUnicodeRange3     uint32
	UlUnicodeRange4     uint32
	AchVendID           uint32
	FsSelection         uint16
	UsFirstCharIndex    uint16
	UsLastCharIndex     uint16
	STypoAscender       int16
	STypoDescender      int16
	STypoLineGap        int16
	UsWinAscent         uint16
	UsWinDescent        uint16
}

OS2 OS/2 font table

type OS2AdditionalFields

type OS2AdditionalFields struct {
	UlCodePageRange1        uint32
	UlCodePageRange2        uint32
	SxHeight                int16
	SCapHeight              int16
	UsDefaultChar           uint16
	UsBreakChar             uint16
	UsMaxContext            uint16
	UsLowerOpticalPointSize uint16
	UsUpperOpticalPointSize uint16
}

OS2AdditionalFields has version > 0 fields

type Post

type Post struct {
	Version            uint32
	ItalicAngle        int32
	UnderlinePosition  int16
	UnderlineThickness int16
	IsFixedPitch       uint32
	MinMemType42       uint32
	MaxMemType42       uint32
	MinMemType1        uint32
	MaxMemType1        uint32
	NumGlyphs          uint16
}

Post table

Jump to

Keyboard shortcuts

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