type1

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: GPL-3.0 Imports: 15 Imported by: 7

Documentation

Overview

Package type1 implements reading and writing of PostScript Type 1 fonts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileFormat

type FileFormat int

FileFormat specifies the on-disk format of a font file.

const (
	FormatPFA     FileFormat = iota + 1 // hex eexec
	FormatPFB                           // hex eexec, pfb wrapper
	FormatBinary                        // binary eexec
	FormatNoEExec                       // no eexec
)

List of supported file formats.

type Font

type Font struct {
	*FontInfo

	Glyphs map[string]*Glyph

	Private *PrivateDict

	Encoding []string

	CreationDate time.Time
}

Font represents a Type 1 font.

TODO(voss): make this more similar to cff.Font

func Read

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

Read reads a Type 1 font from a reader. The function supports both ".pfa" and ".pfb" files.

func (*Font) BBox

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

BBox returns the font bounding box. This is the smallest rectangle enclosing all glyphs in the font.

func (*Font) GlyphList

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

GlyphList returns a list of all glyph names in the font. The list starts with ".notdef", followed by the glyphs in the Encoding vector, followed by the remaining glyph names in alphabetical order.

func (*Font) NewGlyph

func (f *Font) NewGlyph(name string, width float64) *Glyph

NewGlyph creates a new glyph with the given name and width.

func (*Font) NumGlyphs

func (f *Font) NumGlyphs() int

NumGlyphs returns the number of glyphs in the font (including the .notdef glyph).

func (*Font) Write

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

Write writes the font to the given writer.

func (*Font) WritePDF

func (f *Font) WritePDF(w io.Writer) (int, int, error)

WritePDF writes the font in the format required for embedding in a PDF file.

type FontInfo

type FontInfo struct {
	// PostScript language name (FontName or CIDFontName) of the font.
	FontName string

	// Version is the version number of the font program.
	Version string

	// Notice is used to save any trademark notice/information for the font.
	Notice string

	// The copyright notice of the font.
	Copyright string

	// FullName is a unique, human-readable name for an individual font.
	FullName string

	// FamilyName is a human-readable name for a group of fonts that are
	// stylistic variants of a single design.  All fonts that are members of
	// such a group should have exactly the same FamilyName value.
	FamilyName string

	// A human-readable name for the weight, or "boldness," of a font.
	Weight string

	// ItalicAngle is the angle, in degrees counterclockwise from the vertical,
	// of the dominant vertical strokes of the font.
	ItalicAngle float64

	// IsFixedPitch is a flag indicating whether the font is a fixed-pitch
	// (monospaced) font.
	IsFixedPitch bool

	// UnderlinePosition is the recommended distance from the baseline for
	// positioning underlining strokes. This number is the y coordinate (in the
	// glyph coordinate system) of the center of the stroke.
	UnderlinePosition funit.Float64

	// UnderlineThickness is the recommended stroke width for underlining, in
	// units of the glyph coordinate system.
	UnderlineThickness funit.Float64

	// FontMatrix is the transformation from glyph space to user space.
	FontMatrix [6]float64
}

FontInfo contains information about a font.

type Glyph

type Glyph struct {
	Cmds   []GlyphOp
	HStem  []funit.Int16
	VStem  []funit.Int16
	WidthX float64
	WidthY float64
}

Glyph represents a glyph in a Type 1 font.

TODO(voss): use float64 instead of funit.Int16?

func (*Glyph) BBox added in v0.4.0

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

BBox computes the bounding box of the glyph.

func (*Glyph) ClosePath

func (g *Glyph) ClosePath()

ClosePath closes the current sub-path.

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) 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.

type GlyphOp

type GlyphOp struct {
	Op   GlyphOpType
	Args []float64
}

GlyphOp is a Type 1 glyph drawing command.

func (GlyphOp) String

func (c GlyphOp) String() string

type GlyphOpType

type GlyphOpType byte

GlyphOpType is the type of a Type 1 glyph drawing command.

const (
	// OpMoveTo tarts a new subpath 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

	// OpClosePath closes the current subpath by appending a straight line from
	// the current point to the starting point of the current subpath.  This
	// does not change the current point.
	OpClosePath
)

func (GlyphOpType) String

func (op GlyphOpType) String() string

type InvalidFontError

type InvalidFontError struct {
	Reason string
}

InvalidFontError indicates a problem with font data.

func (*InvalidFontError) Error

func (err *InvalidFontError) Error() string

type KernPair

type KernPair struct {
	Left, Right string
	Adjust      funit.Int16 // negative = move glyphs closer together
}

KernPair represents a kerning pair.

type PrivateDict

type PrivateDict struct {
	// BlueValues is an array containing an even number of integers.
	// The first integer in each pair is less than or equal to the second integer.
	// The first pair is the baseline overshoot position and the baseline.
	// All subsequent pairs describe alignment zones for the tops of character features.
	BlueValues []funit.Int16

	OtherBlues []funit.Int16

	BlueScale float64

	BlueShift int32

	BlueFuzz int32

	// StdHW is the dominant width of horizontal stems for glyphs in the font.
	StdHW float64

	// StdVW the dominant width of vertical stems.
	// Typically, this will be the width of straight stems in lower case letters.
	StdVW float64

	ForceBold bool
}

PrivateDict contains information about a font's private dictionary.

type WriterOptions

type WriterOptions struct {
	Format FileFormat // which file format to write (default: FormatPFA)
}

WriterOptions contains options for writing a font.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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