sfnt

package module
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: GPL-3.0 Imports: 32 Imported by: 9

README

seehuhn.de/go/sfnt

This is a library for reading and writing font files. It is written in Go and currently supports TrueType and OpenType fonts. The package is named after the SFNT container format used by these fonts.

API documentation is available at https://pkg.go.dev/seehuhn.de/go/sfnt .

Documentation

Overview

Package sfnt implements support for OpenType and TrueType font files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Font added in v0.3.5

type Font struct {
	FamilyName string
	Width      os2.Width
	Weight     os2.Weight
	IsRegular  bool // glyphs are in the standard weight/style for the font
	IsBold     bool // glyphs are emboldened
	IsItalic   bool // font contains italic or oblique glyphs
	IsOblique  bool // font contains oblique glyphs
	IsSerif    bool
	IsScript   bool // Glyphs resemble cursive handwriting.

	CodePageRange os2.CodePageRange

	Version          head.Version
	CreationTime     time.Time
	ModificationTime time.Time
	Description      string
	SampleText       string

	Copyright  string
	Trademark  string
	License    string
	LicenseURL string
	PermUse    os2.Permissions

	UnitsPerEm uint16
	FontMatrix [6]float64

	Ascent    funit.Int16
	Descent   funit.Int16 // negative
	LineGap   funit.Int16 // LineGap = Leading - Ascent + Descent
	CapHeight funit.Int16
	XHeight   funit.Int16

	ItalicAngle        float64       // Italic angle (degrees counterclockwise from vertical)
	UnderlinePosition  funit.Float64 // Underline position (negative)
	UnderlineThickness funit.Float64 // Underline thickness

	Outlines interface{} // either *cff.Outlines or *glyf.Outlines

	CMapTable cmap.Table

	Gdef *gdef.Table
	Gsub *gtab.Info
	Gpos *gtab.Info
}

Font contains information about a TrueType or OpenType font.

TODO(voss): clarify the relation between IsOblique, IsItalic, and ItalicAngle != 0.

func Read

func Read(r io.Reader) (*Font, error)

Read reads a TrueType or OpenType font from an io.Reader. If r does not implement the io.ReaderAt interface, the whole font file will be read into memory.

func ReadFile

func ReadFile(fname string) (*Font, error)

ReadFile reads a TrueType or OpenType font from a file.

func (*Font) AsCFF added in v0.3.5

func (f *Font) AsCFF() *cff.Font

AsCFF returns the CFF font data for the given font. Panics if the font does not contain CFF outlines.

func (*Font) BBox added in v0.3.5

func (f *Font) BBox() (bbox funit.Rect16)

BBox returns the bounding box of the font.

func (*Font) Clone added in v0.3.5

func (f *Font) Clone() *Font

Clone makes a shallow copy of the font object.

func (*Font) EnsureGlyphNames added in v0.3.5

func (f *Font) EnsureGlyphNames()

EnsureGlyphNames makes sure that all glyphs in the font have a name. If all names are present, the function does nothing. Otherwise, the function tries to infer the missing glyph names from the "cmap" and "gsub" tables.

func (*Font) FullName added in v0.3.5

func (f *Font) FullName() string

FullName returns the full name of the font.

func (*Font) GetFontInfo added in v0.3.5

func (f *Font) GetFontInfo() *type1.FontInfo

GetFontInfo returns an Adobe FontInfo structure for the given font.

func (*Font) GlyphBBox added in v0.3.5

func (f *Font) GlyphBBox(gid glyph.ID) funit.Rect16

GlyphBBox returns the glyph bounding box for one glyph in font design units.

func (*Font) GlyphBBoxes added in v0.3.5

func (f *Font) GlyphBBoxes() []funit.Rect16

GlyphBBoxes returns the glyph bounding boxes for the font.

func (*Font) GlyphName added in v0.3.5

func (f *Font) GlyphName(gid glyph.ID) string

GlyphName returns the name of a glyph. If the name is not known, the empty string is returned.

func (*Font) GlyphWidth added in v0.3.5

func (f *Font) GlyphWidth(gid glyph.ID) funit.Int16

GlyphWidth returns the advance width of the glyph with the given glyph ID, in font design units.

func (*Font) GlyphWidthPDF added in v0.4.0

func (f *Font) GlyphWidthPDF(gid glyph.ID) float64

GlyphWidthPDF returns the advance width in PDF text space units.

func (*Font) InstallCMap added in v0.3.5

func (f *Font) InstallCMap(s cmap.Subtable)

InstallCMap replaces the cmap table in the font with the given subtable.

func (*Font) IsCFF added in v0.3.5

func (f *Font) IsCFF() bool

IsCFF returns true if the font contains CFF glyph outlines.

func (*Font) IsFixedPitch added in v0.3.5

func (f *Font) IsFixedPitch() bool

IsFixedPitch returns true if all glyphs in the font have the same width.

func (*Font) IsGlyf added in v0.3.5

func (f *Font) IsGlyf() bool

IsGlyf returns true if the font contains TrueType glyph outlines.

func (*Font) MakeGlyphNames added in v0.3.5

func (f *Font) MakeGlyphNames() []string

MakeGlyphNames returns a list of glyph names which can be used for the font. If all names are present, the function returns the existing names. Otherwise, the function tries to infer the missing glyph names from the "cmap" and "gsub" tables.

func (*Font) NewLayouter added in v0.4.5

func (f *Font) NewLayouter(lang language.Tag, gsubFeatures, gposFeatures map[string]bool) (*Layouter, error)

NewLayouter creates a new layouter for the given cmap and lookups.

func (*Font) NumGlyphs added in v0.3.5

func (f *Font) NumGlyphs() int

NumGlyphs returns the number of glyphs in the font.

func (*Font) PostScriptName added in v0.4.0

func (f *Font) PostScriptName() string

PostScriptName returns the PostScript name of the font.

func (*Font) Subfamily added in v0.3.5

func (f *Font) Subfamily() string

Subfamily returns the subfamily name of the font.

func (*Font) Subset added in v0.3.5

func (f *Font) Subset(glyphs []glyph.ID) (*Font, error)

Subset returns a subset of the font containing containing the given glyphs at the first positions. More glyphs may be included in the subset, if they occur as ligatures between the given glyphs.

func (*Font) Widths added in v0.3.5

func (f *Font) Widths() []funit.Int16

Widths returns the advance widths of the glyphs in the font.

func (*Font) WidthsPDF added in v0.4.0

func (f *Font) WidthsPDF() []float64

WidthsPDF returns the advance widths of the glyphs in the font.

func (*Font) Write added in v0.3.5

func (f *Font) Write(w io.Writer) (int64, error)

Write writes the binary form of the font to the given writer.

func (*Font) WriteOpenTypeCFFPDF added in v0.3.5

func (f *Font) WriteOpenTypeCFFPDF(w io.Writer) error

WriteOpenTypeCFFPDF writes a minimal OpenType file, which includes only the tables required for PDF embedding.

func (*Font) WriteTrueTypePDF added in v0.3.5

func (f *Font) WriteTrueTypePDF(w io.Writer) (int64, error)

WriteTrueTypePDF writes the binary form of a TrueType font to the given writer. Only the tables needed for PDF embedding are included.

if the font does not use TrueType outlines, the function panics.

type Layouter added in v0.4.5

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

A Layouter can turn a string into a sequence of glyphs.

func (*Layouter) Layout added in v0.4.5

func (l *Layouter) Layout(s string) []glyph.Info

Layout returns the glyph sequence for the given text.

The returned slice is owned by the Layouter and is only valid until the next call to Layout.

Directories

Path Synopsis
Package cff implements reading and writing of CFF fonts.
Package cff implements reading and writing of CFF fonts.
Package cmap reads and writes "cmap" tables.
Package cmap reads and writes "cmap" tables.
examples
extract-cff
Extract-cff extracts the CFF data from OpenType font files.
Extract-cff extracts the CFF data from OpenType font files.
font-info
Font-info shows information about a font file.
Font-info shows information about a font file.
list-sfnt-tables
List-sfnt-tables prints a list of the tables in an sfnt font file.
List-sfnt-tables prints a list of the tables in an sfnt font file.
rewrite-font
Rewrite-font rewrites the font files given on the command line.
Rewrite-font rewrites the font files given on the command line.
Package glyf reads and writes "glyf" and "loca" tables.
Package glyf reads and writes "glyf" and "loca" tables.
Package glyph contains types for representing glyphs.
Package glyph contains types for representing glyphs.
Package head reads and writes "head" tables.
Package head reads and writes "head" tables.
Package header reads and writes TrueType and OpenType file headers.
Package header reads and writes TrueType and OpenType file headers.
Package hmtx reads and writes "hhea" and "hmtx" tables.
Package hmtx reads and writes "hhea" and "hmtx" tables.
internal
debug
Package debug provides a simple font for use in unit tests.
Package debug provides a simple font for use in unit tests.
Package kern reads and writes "kern" tables.
Package kern reads and writes "kern" tables.
Package mac implements the Mac Roman encoding.
Package mac implements the Mac Roman encoding.
Package maxp reads and writes "maxp" tables.
Package maxp reads and writes "maxp" tables.
Package name reads and writes "name" tables.
Package name reads and writes "name" tables.
opentype
anchor
Package anchor encodes and decodes OpenType "Anchor Tables".
Package anchor encodes and decodes OpenType "Anchor Tables".
classdef
Package classdef reads and writes OpenType "Class Definition Tables".
Package classdef reads and writes OpenType "Class Definition Tables".
coverage
Package coverage reads and writes OpenType "Coverage Tables".
Package coverage reads and writes OpenType "Coverage Tables".
gdef
Package gdef reads and writes OpenType "GDEF" tables.
Package gdef reads and writes OpenType "GDEF" tables.
gtab
Package gtab reads and writes OpenType "GSUB" and "GPOS" tables.
Package gtab reads and writes OpenType "GSUB" and "GPOS" tables.
markarray
Package markarray contains types for representing OpenType mark array tables.
Package markarray contains types for representing OpenType mark array tables.
Package os2 reads and writes "OS/2" tables.
Package os2 reads and writes "OS/2" tables.
Package post reads and writes "post" tables.
Package post reads and writes "post" tables.

Jump to

Keyboard shortcuts

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