package opentype
import "github.com/go-text/typesetting/font/opentype"
Package opentype provides the low level routines required to read and write 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 ¶
- Variables
- func WriteTTF(tables []Table) []byte
- type GID
- type GlyphExtents
- type Loader
- func NewLoader(file Resource) (*Loader, error)
- func NewLoaders(file Resource) ([]*Loader, error)
- func (pr *Loader) HasTable(table Tag) bool
- func (pr *Loader) RawTable(tag Tag) ([]byte, error)
- func (pr *Loader) RawTableTo(tag Tag, dst []byte) ([]byte, error)
- func (ld *Loader) Tables() []Tag
- type Resource
- type Segment
- type SegmentOp
- type SegmentPoint
- type Table
- type Tag
Variables ¶
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 ¶
WriteTTF creates a single Truetype font file (.ttf) from the given [tables] slice, which must be sorted by Tag
Types ¶
type GID ¶
type GID uint32
type GlyphExtents ¶
type GlyphExtents struct { XBearing float32 // Left side of glyph from origin YBearing float32 // Top side of glyph from origin Width float32 // Distance from left to right side Height float32 // Distance from top to bottom side }
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 ¶
NewLoader reads the `file` header and returns a new lazy ot. `file` will be used to parse tables, and should not be close.
func NewLoaders ¶
NewLoaders is the same as `NewLoader`, but supports collections.
func (*Loader) HasTable ¶
HasTable returns true if [table] is present.
func (*Loader) RawTable ¶
RawTable returns the binary content of the given table, or an error if not found.
func (*Loader) RawTableTo ¶
RawTable writes the binary content of the given table to [dst], returning it, or an error if not found.
func (*Loader) Tables ¶
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) }
type Segment ¶
type Segment struct { Op SegmentOp // Args is up to three (x, y) coordinates, depending on the // operation. // The Y axis increases up. Args [3]SegmentPoint }
func (*Segment) ArgsSlice ¶
func (s *Segment) ArgsSlice() []SegmentPoint
ArgsSlice returns the effective slice of points used (whose length is between 1 and 3).
type SegmentOp ¶
type SegmentOp uint8
type SegmentPoint ¶
type SegmentPoint struct { X, Y float32 // expressed in fonts units }
func (*SegmentPoint) Move ¶
func (pt *SegmentPoint) Move(dx, dy float32)
Move translates the point.
type Table ¶
Table is one opentype binary table and its tag.
type Tag ¶
type Tag uint32
func MustNewTag ¶
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 ¶
NewTag returns the tag for <abcd>.
func (Tag) String ¶
String return the ASCII form of the tag.
Source Files ¶
opentype.go reader.go reader_otf.go reader_woff.go writer.go
Directories ¶
Path | Synopsis |
---|---|
font/opentype/tables |
- Version
- v0.3.0 (latest)
- Published
- Feb 21, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 15 hours ago –
Tools for package owners.