ps

package
v0.0.0-...-fc0e231 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: AGPL-3.0, AGPL-3.0-only Imports: 8 Imported by: 0

Documentation

Overview

Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular for PDF function type 4.

Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular for PDF function type 4.

Index

Constants

This section is empty.

Variables

View Source
var ErrRangeCheck = errors.New("range check error")

ErrRangeCheck occurs when an input value is incorrect or within valid boundaeries.

View Source
var ErrStackOverflow = errors.New("stack overflow")

ErrStackOverflow is due to a stack overflow.

View Source
var ErrStackUnderflow = errors.New("stack underflow")

ErrStackUnderflow is due to a stack underflow.

View Source
var ErrTypeCheck = errors.New("type check error")

ErrTypeCheck is due to a type mismatch, typically when a type is expected as input but a different type is received instead.

View Source
var ErrUndefinedResult = errors.New("undefined result error")

ErrUndefinedResult occurs when the function does not have a result for given input parameters. An example is division by 0.

View Source
var ErrUnsupportedOperand = errors.New("unsupported operand")

ErrUnsupportedOperand occurs when an unsupported operand is encountered.

Functions

func PSObjectArrayToFloat64Array

func PSObjectArrayToFloat64Array(objects []PSObject) ([]float64, error)

PSObjectArrayToFloat64Array converts []PSObject into a []float64 array. Each PSObject must represent a number, otherwise a ErrTypeCheck error occurs.

Types

type PSBoolean

type PSBoolean struct {
	Val bool
}

PSBoolean represents a boolean value.

func MakeBool

func MakeBool(val bool) *PSBoolean

MakeBool returns a new PSBoolean object initialized with `val`.

func (*PSBoolean) DebugString

func (bool *PSBoolean) DebugString() string

func (*PSBoolean) Duplicate

func (bool *PSBoolean) Duplicate() PSObject

func (*PSBoolean) String

func (bool *PSBoolean) String() string

type PSExecutor

type PSExecutor struct {
	Stack *PSStack
	// contains filtered or unexported fields
}

PSExecutor has its own execution stack and is used to executre a PS routine (program).

func NewPSExecutor

func NewPSExecutor(program *PSProgram) *PSExecutor

NewPSExecutor returns an initialized PSExecutor for an input `program`.

func (*PSExecutor) Execute

func (exec *PSExecutor) Execute(objects []PSObject) ([]PSObject, error)

Execute executes the program for an input parameters `objects` and returns a slice of output objects.

type PSInteger

type PSInteger struct {
	Val int
}

PSInteger represents an integer.

func MakeInteger

func MakeInteger(val int) *PSInteger

MakeInteger returns a new PSInteger object initialized with `val`.

func (*PSInteger) DebugString

func (int *PSInteger) DebugString() string

func (*PSInteger) Duplicate

func (int *PSInteger) Duplicate() PSObject

func (*PSInteger) String

func (int *PSInteger) String() string

type PSObject

type PSObject interface {
	// Duplicate makes a fresh copy of the PSObject.
	Duplicate() PSObject

	// DebugString returns a descriptive representation of the PSObject with more information than String()
	// for debugging purposes.
	DebugString() string

	// String returns a string representation of the PSObject.
	String() string
}

PSObject represents a postscript object.

type PSOperand

type PSOperand string

PSOperand represents a Postscript operand (text string).

func MakeOperand

func MakeOperand(val string) *PSOperand

MakeOperand returns a new PSOperand object based on string `val`.

func (*PSOperand) DebugString

func (op *PSOperand) DebugString() string

func (*PSOperand) Duplicate

func (op *PSOperand) Duplicate() PSObject

func (*PSOperand) Exec

func (op *PSOperand) Exec(stack *PSStack) error

Exec executes the operand `op` in the state specified by `stack`.

func (*PSOperand) String

func (op *PSOperand) String() string

type PSParser

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

PSParser is a basic Postscript parser.

func NewPSParser

func NewPSParser(content []byte) *PSParser

NewPSParser returns a new instance of the PDF Postscript parser from input data.

func (*PSParser) Parse

func (p *PSParser) Parse() (*PSProgram, error)

Parse parses the postscript and store as a program that can be executed.

type PSProgram

type PSProgram []PSObject

PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).

func NewPSProgram

func NewPSProgram() *PSProgram

NewPSProgram returns an empty, initialized PSProgram.

func (*PSProgram) Append

func (prog *PSProgram) Append(obj PSObject)

Append appends an object to the PSProgram.

func (*PSProgram) DebugString

func (prog *PSProgram) DebugString() string

func (*PSProgram) Duplicate

func (prog *PSProgram) Duplicate() PSObject

func (*PSProgram) Exec

func (prog *PSProgram) Exec(stack *PSStack) error

Exec executes the program, typically leaving output values on the stack.

func (*PSProgram) String

func (prog *PSProgram) String() string

type PSReal

type PSReal struct {
	Val float64
}

PSReal represents a real number.

func MakeReal

func MakeReal(val float64) *PSReal

MakeReal returns a new PSReal object initialized with `val`.

func (*PSReal) DebugString

func (real *PSReal) DebugString() string

func (*PSReal) Duplicate

func (real *PSReal) Duplicate() PSObject

func (*PSReal) String

func (real *PSReal) String() string

type PSStack

type PSStack []PSObject

PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.

func NewPSStack

func NewPSStack() *PSStack

NewPSStack returns an initialized PSStack.

func (*PSStack) DebugString

func (stack *PSStack) DebugString() string

DebugString returns a descriptive string representation of the stack - intended for debugging.

func (*PSStack) Empty

func (stack *PSStack) Empty()

Empty empties the stack.

func (*PSStack) Pop

func (stack *PSStack) Pop() (PSObject, error)

Pop pops an object from the top of the stack.

func (*PSStack) PopInteger

func (stack *PSStack) PopInteger() (int, error)

PopInteger specificially pops an integer from the top of the stack, returning the value as an int.

func (*PSStack) PopNumberAsFloat64

func (stack *PSStack) PopNumberAsFloat64() (float64, error)

PopNumberAsFloat64 pops and return the numeric value of the top of the stack as a float64. Real or integer only.

func (*PSStack) Push

func (stack *PSStack) Push(obj PSObject) error

Push pushes an object on top of the stack.

func (*PSStack) String

func (stack *PSStack) String() string

String returns a string representation of the stack.

Jump to

Keyboard shortcuts

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