loader

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause, Unlicense Imports: 7 Imported by: 12

Documentation

Overview

Package opentype provides the low level routines required to read Opentype font files, including collections.

This package is designed to provide an efficient, lazy, reading API.

For the parsing of the various tables, see package [tables].

Index

Constants

This section is empty.

Variables

View Source
var (
	// TrueType is the first four bytes of an OpenType file containing a TrueType font
	TrueType = Tag(0x00010000)
	// AppleTrueType is the first four bytes of an OpenType file containing a TrueType font
	// (specifically one designed for Apple products, it's recommended to use TrueType instead)
	AppleTrueType = MustNewTag("true")
	// PostScript1 is the first four bytes of an OpenType file containing a PostScript 1 font
	PostScript1 = MustNewTag("typ1")
	// OpenType is the first four bytes of an OpenType file containing a PostScript Type 2 font
	// as specified by OpenType
	OpenType = MustNewTag("OTTO")
)

Functions

func WriteTTF

func WriteTTF(tables []Table) []byte

WriteTTF creates a single Truetype font file (.ttf) from the given [tables] slice, which must be sorted by Tag

Types

type Loader

type Loader struct {

	// Type represents the kind of this font being loaded.
	// It is one of TrueType, TrueTypeApple, PostScript1, OpenType
	Type Tag
	// contains filtered or unexported fields
}

Loader is the low level font reader, providing full control over table loading.

func NewLoader

func NewLoader(file Resource) (*Loader, error)

NewLoader reads the `file` header and returns a new lazy loader. `file` will be used to parse tables, and should not be close.

func NewLoaders

func NewLoaders(file Resource) ([]*Loader, error)

NewLoaders is the same as `NewLoader`, but supports collections.

func (*Loader) HasTable

func (pr *Loader) HasTable(table Tag) bool

HasTable returns true if [table] is present.

func (*Loader) RawTable

func (pr *Loader) RawTable(tag Tag) ([]byte, error)

RawTable returns the binary content of the given table, or an error if not found.

func (*Loader) RawTableTo

func (pr *Loader) RawTableTo(tag Tag, dst []byte) ([]byte, error)

RawTable writes the binary content of the given table to [dst], returning it, or an error if not found.

func (*Loader) Tables

func (ld *Loader) Tables() []Tag

Tables returns all the tables found in the file, as a sorted slice.

type Resource

type Resource interface {
	Read([]byte) (int, error)
	ReadAt([]byte, int64) (int, error)
	Seek(int64, int) (int64, error)
}

Resource is a combination of io.Reader, io.Seeker and io.ReaderAt. This interface is satisfied by most things that you'd want to parse, for example *os.File, io.SectionReader or *bytes.Reader.

type Table

type Table struct {
	Content []byte
	Tag     Tag
}

Table is one opentype binary table and its tag.

type Tag

type Tag uint32

Tag represents an open-type name. These are technically uint32's, but are usually displayed in ASCII as they are all acronyms. See https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html#Overview

func MustNewTag

func MustNewTag(str string) Tag

MustNewTag gives you the Tag corresponding to the acronym. This function will panic if the string passed in is not 4 bytes long.

func NewTag

func NewTag(a, b, c, d byte) Tag

NewTag returns the tag for <abcd>.

func (Tag) String

func (t Tag) String() string

String return the ASCII form of the tag.

Jump to

Keyboard shortcuts

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