cff

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: 15 Imported by: 5

Documentation

Overview

Package cff implements reading and writing of CFF fonts.

CFF fonts are typically embedded in OpenType font files, rather than being used as stand-alone font files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StandardEncoding

func StandardEncoding(glyphs []*Glyph) []glyph.ID

StandardEncoding returns the encoding vector for the standard encoding. The result can be used for the `Outlines.Encoding` field.

Types

type FDSelectFn added in v0.3.4

type FDSelectFn func(glyph.ID) int

FDSelectFn maps glyphID values to private dicts in Font.Info.Private.

type Font

type Font struct {
	*type1.FontInfo
	*Outlines
}

Font stores a CFF font.

TODO(voss): make this more similar to type1.Font. Maybe merge Outlines into Font?

func Read

func Read(r parser.ReadSeekSizer) (*Font, error)

Read reads a CFF font from r.

func (*Font) Clone added in v0.3.5

func (cff *Font) Clone() *Font

Clone creates a new font, consisting of shallow copies of the FontInfo and Outlines fields.

func (*Font) GlyphWidthPDF added in v0.4.0

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

func (*Font) NumGlyphs added in v0.3.5

func (cff *Font) NumGlyphs() int

NumGlyphs returns the number of glyphs in the font.

func (*Font) Widths

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

Widths returns the widths of all glyphs.

func (*Font) Write added in v0.3.5

func (cff *Font) Write(w io.Writer) error

Write writes the binary form of a CFF font.

type Glyph

type Glyph struct {
	Name  string
	Cmds  []GlyphOp
	HStem []funit.Int16
	VStem []funit.Int16
	Width funit.Int16
}

Glyph represents a glyph in a CFF font.

func NewGlyph

func NewGlyph(name string, width funit.Int16) *Glyph

NewGlyph allocates a new glyph.

func (*Glyph) CurveTo

func (g *Glyph) CurveTo(x1, y1, x2, y2, x3, y3 float64)

CurveTo adds a cubic Bezier curve to the current sub-path.

func (*Glyph) Extent

func (g *Glyph) Extent() funit.Rect16

Extent computes the Glyph extent in font design units

func (*Glyph) LineTo

func (g *Glyph) LineTo(x, y float64)

LineTo adds a straight line to the current sub-path.

func (*Glyph) MoveTo

func (g *Glyph) MoveTo(x, y float64)

MoveTo starts a new sub-path and moves the current point to (x, y). The previous sub-path, if any, is closed.

func (*Glyph) String

func (g *Glyph) String() string

type GlyphOp

type GlyphOp struct {
	Op   GlyphOpType
	Args []float64
}

GlyphOp is a CFF glyph drawing command.

func (GlyphOp) String

func (c GlyphOp) String() string

type GlyphOpType

type GlyphOpType byte

GlyphOpType is the type of a CFF glyph drawing command.

TODO(voss): merge this with the Type 1 command type?

const (
	// OpMoveTo closes the previous subpath and starts a new one at the given point.
	OpMoveTo GlyphOpType = iota + 1

	// OpLineTo appends a straight line segment from the previous point to the given point.
	OpLineTo

	// OpCurveTo appends a Bezier curve segment from the previous point to the given point.
	OpCurveTo

	// OpHintMask adds a CFF hintmask command.
	OpHintMask

	// OpCntrMask adds a CFF cntrmask command.
	OpCntrMask
)

func (GlyphOpType) String

func (op GlyphOpType) String() string

type Outlines

type Outlines struct {
	Glyphs []*Glyph

	Private []*type1.PrivateDict

	// FDSelect determines which private dictionary is used for each glyph.
	FDSelect FDSelectFn

	// Encoding lists the glyphs corresponding to the 256 one-byte character
	// codes in a simple font. The length of this slice must be 256, entries
	// for unused character codes must be set to 0.
	// For CIDFonts (where ROS != nil), Encoding must be nil.
	Encoding []glyph.ID

	// ROS specifies the character collection of the font, using Adobe's
	// Registry, Ordering, Supplement system.  This must be non-nil
	// if and only if the font is a CIDFont.
	ROS *cid.SystemInfo

	// GIDToCID lists the character identifiers corresponding to the glyphs.
	// This is only present for CIDFonts, and encodes the information from the
	// charset table in the CFF font.  When present, the first entry
	// (corresponding to the .notdef glyph) must be 0.
	GIDToCID []cid.CID
}

Outlines stores the glyph data of a CFF font.

func (*Outlines) BBox added in v0.3.5

func (o *Outlines) BBox() (bbox funit.Rect16)

BBox returns the font bounding box.

func (*Outlines) BuiltinEncoding added in v0.4.0

func (o *Outlines) BuiltinEncoding() []string

BuiltinEncoding returns the built-in encoding of the font. For simple CFF fonts, the result is a slice of length 256. For CIDFonts, the result is nil.

func (*Outlines) IsCIDKeyed added in v0.3.4

func (o *Outlines) IsCIDKeyed() bool

IsCIDKeyed returns true if the font is a CID-keyed font.

Jump to

Keyboard shortcuts

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