HomeUniDoc
HomeUniDoc
...

Package ps

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 ▾

Variables
func PSObjectArrayToFloat64Array(objects []PSObject) ([]float64, error)
type PSBoolean
    func MakeBool(val bool) *PSBoolean
    func (bool *PSBoolean) DebugString() string
    func (bool *PSBoolean) Duplicate() PSObject
    func (bool *PSBoolean) String() string
type PSExecutor
    func NewPSExecutor(program *PSProgram) *PSExecutor
    func (exec *PSExecutor) Execute(objects []PSObject) ([]PSObject, error)
type PSInteger
    func MakeInteger(val int) *PSInteger
    func (int *PSInteger) DebugString() string
    func (int *PSInteger) Duplicate() PSObject
    func (int *PSInteger) String() string
type PSObject
type PSOperand
    func MakeOperand(val string) *PSOperand
    func (op *PSOperand) DebugString() string
    func (op *PSOperand) Duplicate() PSObject
    func (op *PSOperand) Exec(stack *PSStack) error
    func (op *PSOperand) String() string
type PSParser
    func NewPSParser(content []byte) *PSParser
    func (p *PSParser) Parse() (*PSProgram, error)
type PSProgram
    func NewPSProgram() *PSProgram
    func (prog *PSProgram) Append(obj PSObject)
    func (prog *PSProgram) DebugString() string
    func (prog *PSProgram) Duplicate() PSObject
    func (prog *PSProgram) Exec(stack *PSStack) error
    func (prog *PSProgram) String() string
type PSReal
    func MakeReal(val float64) *PSReal
    func (real *PSReal) DebugString() string
    func (real *PSReal) Duplicate() PSObject
    func (real *PSReal) String() string
type PSStack
    func NewPSStack() *PSStack
    func (stack *PSStack) DebugString() string
    func (stack *PSStack) Empty()
    func (stack *PSStack) Pop() (PSObject, error)
    func (stack *PSStack) PopInteger() (int, error)
    func (stack *PSStack) PopNumberAsFloat64() (float64, error)
    func (stack *PSStack) Push(obj PSObject) error
    func (stack *PSStack) String() string

Package files

const.go doc.go exec.go object.go operations.go parser.go stack.go utils.go

Variables

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

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

ErrStackOverflow is due to a stack overflow.

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

ErrStackUnderflow is due to a stack underflow.

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

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

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

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

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

ErrUnsupportedOperand occurs when an unsupported operand is encountered.

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

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.

type PSBoolean

PSBoolean represents a boolean value.

type PSBoolean struct {
    Val bool
}

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

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

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

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

PSInteger represents an integer.

type PSInteger struct {
    Val int
}

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

PSObject represents a postscript object.

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
}

type PSOperand

PSOperand represents a Postscript operand (text string).

type PSOperand 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

PSParser is a basic Postscript parser.

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

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

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

type PSProgram []PSObject

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

PSReal represents a real number.

type PSReal struct {
    Val float64
}

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

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

type PSStack []PSObject

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.