header

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Overview

Package header reads and writes TrueType and OpenType file headers. https://docs.microsoft.com/en-us/typography/opentype/spec/otff#table-directory

Index

Constants

View Source
const (
	// ScalerTypeTrueType is the scaler type for fonts which use TrueType
	// outlines.
	ScalerTypeTrueType uint32 = 0x00010000

	// ScalerTypeCFF is the scaler type for fonts which use CFF
	// outlines (version 1 or 2).
	ScalerTypeCFF uint32 = 0x4F54544F // "OTTO"

	// ScalerTypeApple is recognised as an alternative for ScalerTypeTrueType
	// on Apple systems.
	ScalerTypeApple uint32 = 0x74727565 // "true"
)

Variables

This section is empty.

Functions

func IsMissing

func IsMissing(err error) bool

IsMissing returns true, if err indicates a missing sfnt table.

func Write

func Write(w io.Writer, scalerType uint32, tables map[string][]byte) (int64, error)

Write writes an sfnt file containing the given tables. Tables where the data is nil are not written, use a zero-length slice to write a table with no data. This changes the checksum in the "head" table in place.

Types

type ErrMissing

type ErrMissing struct {
	TableName string
}

ErrMissing indicates that a required table is missing from a TrueType or OpenType font file.

func (*ErrMissing) Error

func (err *ErrMissing) Error() string

type Info

type Info struct {
	ScalerType uint32
	Toc        map[string]Record
}

Info contains information about the tables present in an sfnt font file.

func Read

func Read(r io.ReaderAt) (*Info, error)

Read reads the file header of an sfnt font file. All checksum data is ignored, but basic sanity checks for the table structure are performed.

func (*Info) Has

func (h *Info) Has(tableNames ...string) bool

Has returns true if all of the given tables are present in the font, and none of them are empty.

func (*Info) ReadTableBytes

func (h *Info) ReadTableBytes(r io.ReaderAt, tableName string) ([]byte, error)

ReadTableBytes returns the un-decoded table contents.

func (*Info) TableReader

func (h *Info) TableReader(r io.ReaderAt, tableName string) (*io.SectionReader, error)

TableReader returns an io.Reader for the given table.

type Record

type Record struct {
	Offset uint32
	Length uint32
}

A Record contains the offset and length of a table in an sfnt font file.

Jump to

Keyboard shortcuts

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