package psinterpreter
import "github.com/go-text/typesetting/font/cff/interpreter"
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
- func (a *ArgStack) Clear()
- func (a *ArgStack) Pop() float64
- func (a *ArgStack) PopN(numPop int32) error
- func (a *ArgStack) Uint16() uint16
- 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
- func (p *Machine) CallSubroutine(index int32, isLocal bool) error
- func (p *Machine) Return() error
- func (p *Machine) Run(instructions []byte, localSubrs, globalSubrs [][]byte, handler OperatorHandler) error
- func (p *Machine) SkipBytes(count int32)
- type Operator
- type OperatorHandler
- type PathBounds
- type Point
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
func LocalSubr ¶
LocalSubr 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) Clear ¶
func (a *ArgStack) Clear()
Clear clears the stack
func (*ArgStack) Pop ¶
Pop returns the top level value and decrease `Top` It will panic if the stack is empty.
func (*ArgStack) PopN ¶
PopN check and remove the n top levels entries. Passing a negative `numPop` clears all the stack.
func (*ArgStack) Uint16 ¶
Uint16 returns the top level value as uint16, without popping the stack.
type CharstringReader ¶
type CharstringReader struct { // Acumulated segments for the glyph outlines Segments []ot.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 Context ¶
type Context uint32
Context is the flavour of the Postcript language.
const ( TopDict Context = iota // Top dict in CFF files PrivateDict // Private dict in CFF files Type2Charstring // Charstring in CFF files Type1Charstring // Charstring in Type1 font files )
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.
func (*Machine) Return ¶
Return returns from a subroutine call.
func (*Machine) Run ¶
func (p *Machine) Run(instructions []byte, localSubrs, globalSubrs [][]byte, handler OperatorHandler) error
Run runs the instructions in the PostScript context asked by `handler`. `localSubrs` and `globalSubrs` contains the subroutines that may be called in the instructions.
func (*Machine) SkipBytes ¶
SkipBytes skips the next `count` bytes from the instructions, and clears the argument stack. It does nothing if `count` exceed the length of the instructions.
type Operator ¶
Operator is a postcript command, which may be escaped.
func (Operator) String ¶
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() ot.GlyphExtents
ToExtents converts a path bounds to the corresponding glyph extents.
type Point ¶
type Point struct{ X, Y float64 }
Point is a 2D Point in font units.
func (*Point) Move ¶
Move translates the Point.
Source Files ¶
- Version
- v0.3.0 (latest)
- Published
- Feb 21, 2025
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 15 hours ago –
Tools for package owners.