Documentation ¶
Overview ¶
Package psinterpreter implement a Postscript interpreter required to parse .CFF files, and Type1 and Type2 Charstrings. This package provides the low-level mechanisms needed to read such formats; the data is consumed in higher level packages, which implement `PsOperatorHandler`. It also provides helpers to interpret glyph outline descriptions, shared between Type1 and CFF font formats.
See https://adobe-type-tools.github.io/font-tech-notes/pdfs/5177.Type2.pdf
Index ¶
- Variables
- func GlobalSubr(state *Machine) error
- func LocalSubr(state *Machine) error
- type ArgStack
- type CharstringReader
- func (out *CharstringReader) ClosePath()
- func (out *CharstringReader) Flex(state *Machine) error
- func (out *CharstringReader) Flex1(state *Machine) error
- func (out *CharstringReader) Hflex(state *Machine) error
- func (out *CharstringReader) Hflex1(state *Machine) error
- func (out *CharstringReader) Hhcurveto(state *Machine)
- func (out *CharstringReader) Hintmask(state *Machine)
- func (out *CharstringReader) Hlineto(state *Machine)
- func (out *CharstringReader) Hmoveto(state *Machine) error
- func (out *CharstringReader) Hstem(state *Machine)
- func (out *CharstringReader) Hvcurveto(state *Machine)
- func (out *CharstringReader) Rcurveline(state *Machine) error
- func (out *CharstringReader) RelativeCurveTo(arg1, arg2, arg3 Point)
- func (out *CharstringReader) Rlinecurve(state *Machine) error
- func (out *CharstringReader) Rlineto(state *Machine)
- func (out *CharstringReader) Rmoveto(state *Machine) error
- func (out *CharstringReader) Rrcurveto(state *Machine)
- func (out *CharstringReader) Vhcurveto(state *Machine)
- func (out *CharstringReader) Vlineto(state *Machine)
- func (out *CharstringReader) Vmoveto(state *Machine) error
- func (out *CharstringReader) Vstem(state *Machine)
- func (out *CharstringReader) Vvcurveto(state *Machine)
- type Context
- type Machine
- type Operator
- type OperatorHandler
- type PathBounds
- type Point
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInterrupt signals the interpreter to stop early, without erroring. ErrInterrupt = errors.New("interruption") )
Functions ¶
func GlobalSubr ¶
GlobalSubr pops the subroutine index and call it
Types ¶
type ArgStack ¶
type ArgStack struct { Vals [psArgStackSize]float64 // we have to use float64 to properly store floats and int32 values // Effecive size currently in use. The first value to // pop is at index Top-1 Top int32 }
func (*ArgStack) Pop ¶
Pop returns the top level value and decrease `Top` It will panic if the stack is empty.
type CharstringReader ¶
type CharstringReader struct { // Acumulated segments for the glyph outlines Segments []api.Segment // Acumulated bounds for the glyph outlines Bounds PathBounds CurrentPoint Point // contains filtered or unexported fields }
CharstringReader provides implementation of the operators found in a font charstring.
func (*CharstringReader) ClosePath ¶
func (out *CharstringReader) ClosePath()
ClosePath closes the current contour, adding a segment to the first point if needed.
func (*CharstringReader) Flex ¶
func (out *CharstringReader) Flex(state *Machine) error
func (*CharstringReader) Flex1 ¶
func (out *CharstringReader) Flex1(state *Machine) error
func (*CharstringReader) Hflex ¶
func (out *CharstringReader) Hflex(state *Machine) error
func (*CharstringReader) Hflex1 ¶
func (out *CharstringReader) Hflex1(state *Machine) error
func (*CharstringReader) Hhcurveto ¶
func (out *CharstringReader) Hhcurveto(state *Machine)
func (*CharstringReader) Hintmask ¶
func (out *CharstringReader) Hintmask(state *Machine)
func (*CharstringReader) Hlineto ¶
func (out *CharstringReader) Hlineto(state *Machine)
func (*CharstringReader) Hmoveto ¶
func (out *CharstringReader) Hmoveto(state *Machine) error
func (*CharstringReader) Hstem ¶
func (out *CharstringReader) Hstem(state *Machine)
func (*CharstringReader) Hvcurveto ¶
func (out *CharstringReader) Hvcurveto(state *Machine)
func (*CharstringReader) Rcurveline ¶
func (out *CharstringReader) Rcurveline(state *Machine) error
func (*CharstringReader) RelativeCurveTo ¶
func (out *CharstringReader) RelativeCurveTo(arg1, arg2, arg3 Point)
RelativeCurveTo draws a curve with controls points computed from the current point and `arg1`, `arg2`, `arg3`
func (*CharstringReader) Rlinecurve ¶
func (out *CharstringReader) Rlinecurve(state *Machine) error
func (*CharstringReader) Rlineto ¶
func (out *CharstringReader) Rlineto(state *Machine)
func (*CharstringReader) Rmoveto ¶
func (out *CharstringReader) Rmoveto(state *Machine) error
func (*CharstringReader) Rrcurveto ¶
func (out *CharstringReader) Rrcurveto(state *Machine)
func (*CharstringReader) Vhcurveto ¶
func (out *CharstringReader) Vhcurveto(state *Machine)
func (*CharstringReader) Vlineto ¶
func (out *CharstringReader) Vlineto(state *Machine)
func (*CharstringReader) Vmoveto ¶
func (out *CharstringReader) Vmoveto(state *Machine) error
func (*CharstringReader) Vstem ¶
func (out *CharstringReader) Vstem(state *Machine)
func (*CharstringReader) Vvcurveto ¶
func (out *CharstringReader) Vvcurveto(state *Machine)
type Machine ¶
type Machine struct { ArgStack ArgStack // contains filtered or unexported fields }
Machine is a PostScript interpreter. A same interpreter may be re-used using muliples `Run` calls.
func (*Machine) CallSubroutine ¶
CallSubroutine calls the subroutine, identified by its index, as found in the instructions (that is, before applying the subroutine biased). `isLocal` controls whether the local or global subroutines are used. No argument stack modification is performed.
type OperatorHandler ¶
type OperatorHandler interface { // Context defines the precise behaviour of the interpreter, // which has small nuances depending on the context. Context() Context // Apply implements the operator defined by `operator` (which is the second byte if `escaped` is true). // // Returning `ErrInterrupt` stop the parsing of the instructions, without reporting an error. // It can be used as an optimization. Apply(state *Machine, operator Operator) error }
OperatorHandler defines the behaviour of an operator.
type PathBounds ¶
type PathBounds struct {
Min, Max Point
}
PathBounds represents a control bounds for a glyph outline (in font units).
func (*PathBounds) Enlarge ¶
func (b *PathBounds) Enlarge(pt Point)
Enlarge enlarges the bounds to include pt
func (*PathBounds) ToExtents ¶
func (b *PathBounds) ToExtents() api.GlyphExtents
ToExtents converts a path bounds to the corresponding glyph extents.