unidoc: github.com/unidoc/unidoc/pdf/ps Index | Files

package ps

import "github.com/unidoc/unidoc/pdf/ps"

Package ps implements a small subset of the postscript language used in PDF for type 4 functions. Only objects are integers, real numbers, and boolean values only.

Index

Package Files

const.go exec.go handy.go object.go parser.go stack.go

Constants

const TOLERANCE = 0.000001

Tolerance for comparing real values.

Variables

var ErrRangeCheck = errors.New("Range check error")
var ErrStackOverflow = errors.New("Stack overflow")
var ErrStackUnderflow = errors.New("Stack underflow")

Common errors.

var ErrTypeCheck = errors.New("Type check error")
var ErrUndefinedResult = errors.New("Undefined result error")

func PSObjectArrayToFloat64Array Uses

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

type PSBoolean Uses

type PSBoolean struct {
    Val bool
}

Bool.

func MakeBool Uses

func MakeBool(val bool) *PSBoolean

func (*PSBoolean) DebugString Uses

func (this *PSBoolean) DebugString() string

func (*PSBoolean) Duplicate Uses

func (this *PSBoolean) Duplicate() PSObject

func (*PSBoolean) String Uses

func (this *PSBoolean) String() string

type PSExecutor Uses

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

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

func NewPSExecutor Uses

func NewPSExecutor(program *PSProgram) *PSExecutor

func (*PSExecutor) Execute Uses

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

type PSInteger Uses

type PSInteger struct {
    Val int
}

Integer.

func (*PSInteger) DebugString Uses

func (this *PSInteger) DebugString() string

func (*PSInteger) Duplicate Uses

func (this *PSInteger) Duplicate() PSObject

func (*PSInteger) String Uses

func (this *PSInteger) String() string

type PSObject Uses

type PSObject interface {
    Duplicate() PSObject
    DebugString() string // Only for debugging.
    String() string
}

func MakeInteger Uses

func MakeInteger(val int) PSObject

func MakeReal Uses

func MakeReal(val float64) PSObject

type PSOperand Uses

type PSOperand string

Operand.

func MakeOperand Uses

func MakeOperand(val string) *PSOperand

func (*PSOperand) Abs Uses

func (this *PSOperand) Abs(stack *PSStack) error

Absolute value.

func (*PSOperand) Add Uses

func (this *PSOperand) Add(stack *PSStack) error

5 27 add -> 32

func (*PSOperand) And Uses

func (this *PSOperand) And(stack *PSStack) error

And operation. if bool: returns the logical "and" of the inputs bool1 bool2 and -> bool3 if int: returns the bitwise "and" of the inputs int1 int2 and -> int3

func (*PSOperand) Atan Uses

func (this *PSOperand) Atan(stack *PSStack) error

den num atan -> atan(num/den) in degrees. result is a real value.

func (*PSOperand) Bitshift Uses

func (this *PSOperand) Bitshift(stack *PSStack) error

bitshift int1 shift bitshift -> int2

func (*PSOperand) Ceiling Uses

func (this *PSOperand) Ceiling(stack *PSStack) error

Ceiling of number. num1 ceiling -> num2 The type of the result is the same as of the operand.

func (*PSOperand) Copy Uses

func (this *PSOperand) Copy(stack *PSStack) error

Copy any1 ... anyn n copy -> any1 ... anyn any1 ... anyn

func (*PSOperand) Cos Uses

func (this *PSOperand) Cos(stack *PSStack) error

Cosine angle cos -> real Angle is in degrees

func (*PSOperand) Cvi Uses

func (this *PSOperand) Cvi(stack *PSStack) error

Convert to integer

func (*PSOperand) Cvr Uses

func (this *PSOperand) Cvr(stack *PSStack) error

Convert number tor real

func (*PSOperand) DebugString Uses

func (this *PSOperand) DebugString() string

func (*PSOperand) Div Uses

func (this *PSOperand) Div(stack *PSStack) error

func (*PSOperand) Dup Uses

func (this *PSOperand) Dup(stack *PSStack) error

Duplicates the top object on the stack (dup)

func (*PSOperand) Duplicate Uses

func (this *PSOperand) Duplicate() PSObject

func (*PSOperand) Eq Uses

func (this *PSOperand) Eq(stack *PSStack) error

Check for equality. any1 any2 eq bool

func (*PSOperand) Exch Uses

func (this *PSOperand) Exch(stack *PSStack) error

Exchange the top two elements of the stack (exch)

func (*PSOperand) Exec Uses

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

func (*PSOperand) Exp Uses

func (this *PSOperand) Exp(stack *PSStack) error

base exponent exp -> base^exp Raises base to exponent power. The result is a real number.

func (*PSOperand) Floor Uses

func (this *PSOperand) Floor(stack *PSStack) error

Floor of number.

func (*PSOperand) Ge Uses

func (this *PSOperand) Ge(stack *PSStack) error

Greater than or equal num1 num2 ge -> bool; num1 >= num2

func (*PSOperand) Gt Uses

func (this *PSOperand) Gt(stack *PSStack) error

Greater than num1 num2 gt -> bool; num1 > num2

func (*PSOperand) IDiv Uses

func (this *PSOperand) IDiv(stack *PSStack) error

Integral division 25 3 div -> 8

func (*PSOperand) If Uses

func (this *PSOperand) If(stack *PSStack) error

If conditional bool proc if -> run proc() if bool is true

func (*PSOperand) IfElse Uses

func (this *PSOperand) IfElse(stack *PSStack) error

If else conditional bool proc1 proc2 ifelse -> execute proc1() if bool is true, otherwise proc2()

func (*PSOperand) Index Uses

func (this *PSOperand) Index(stack *PSStack) error

Add a copy of the nth object in the stack to the top. any_n ... any_0 n index -> any_n ... any_0 any_n index from 0

func (*PSOperand) Le Uses

func (this *PSOperand) Le(stack *PSStack) error

Less or equal num1 num2 le -> bool; num1 <= num2

func (*PSOperand) Ln Uses

func (this *PSOperand) Ln(stack *PSStack) error

num ln -> ln(num) The result is a real number.

func (*PSOperand) Log Uses

func (this *PSOperand) Log(stack *PSStack) error

num log -> real

func (*PSOperand) Lt Uses

func (this *PSOperand) Lt(stack *PSStack) error

Less than num1 num2 lt -> bool; num1 < num2

func (*PSOperand) Mod Uses

func (this *PSOperand) Mod(stack *PSStack) error

12 10 mod -> 2

func (*PSOperand) Mul Uses

func (this *PSOperand) Mul(stack *PSStack) error

6 8 mul -> 48

func (*PSOperand) Ne Uses

func (this *PSOperand) Ne(stack *PSStack) error

Not equal (inverse of eq) any1 any2 ne -> bool

func (*PSOperand) Neg Uses

func (this *PSOperand) Neg(stack *PSStack) error

Negate 6 neg -> -6

func (*PSOperand) Not Uses

func (this *PSOperand) Not(stack *PSStack) error

Logical/bitwise negation bool1 not -> bool2 (logical) int1 not -> int2 (bitwise)

func (*PSOperand) Or Uses

func (this *PSOperand) Or(stack *PSStack) error

OR logical/bitwise operation. bool1 bool2 or -> bool3 (logical or) int1 int2 or -> int3 (bitwise or)

func (*PSOperand) Pop Uses

func (this *PSOperand) Pop(stack *PSStack) error

Remove the top element on the stack (pop)

func (*PSOperand) Roll Uses

func (this *PSOperand) Roll(stack *PSStack) error

Roll stack contents (num dir roll) num: number of elements, dir: direction 7 8 9 3 1 roll -> 9 7 8 7 8 9 3 -1 roll -> 8 9 7 n j roll

func (*PSOperand) Round Uses

func (this *PSOperand) Round(stack *PSStack) error

Round number off. num1 round -> num2

func (*PSOperand) Sin Uses

func (this *PSOperand) Sin(stack *PSStack) error

Sine. angle sin -> real Angle is in degrees

func (*PSOperand) Sqrt Uses

func (this *PSOperand) Sqrt(stack *PSStack) error

Square root. num sqrt -> real; real=sqrt(num) The result is a real number.

func (*PSOperand) String Uses

func (this *PSOperand) String() string

func (*PSOperand) Sub Uses

func (this *PSOperand) Sub(stack *PSStack) error

8.3 6.6 sub -> 1.7 (real) 8 6.3 sub -> 1.7 (real) 8 6 sub -> 2 (int)

func (*PSOperand) Truncate Uses

func (this *PSOperand) Truncate(stack *PSStack) error

Truncate number. num1 truncate -> num2 The resulting number is the same type as the input.

func (*PSOperand) Xor Uses

func (this *PSOperand) Xor(stack *PSStack) error

XOR logical/bitwise operation. bool1 bool2 xor -> bool3 (logical xor) int1 int2 xor -> int3 (bitwise xor)

type PSParser Uses

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

func NewPSParser Uses

func NewPSParser(content []byte) *PSParser

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

func (*PSParser) Parse Uses

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

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

type PSProgram Uses

type PSProgram []PSObject

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

func NewPSProgram Uses

func NewPSProgram() *PSProgram

func (*PSProgram) Append Uses

func (this *PSProgram) Append(obj PSObject)

func (*PSProgram) DebugString Uses

func (this *PSProgram) DebugString() string

func (*PSProgram) Duplicate Uses

func (this *PSProgram) Duplicate() PSObject

func (*PSProgram) Exec Uses

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

func (*PSProgram) String Uses

func (this *PSProgram) String() string

type PSReal Uses

type PSReal struct {
    Val float64
}

Real number.

func (*PSReal) DebugString Uses

func (this *PSReal) DebugString() string

func (*PSReal) Duplicate Uses

func (this *PSReal) Duplicate() PSObject

func (*PSReal) String Uses

func (this *PSReal) String() string

type PSStack Uses

type PSStack []PSObject

func NewPSStack Uses

func NewPSStack() *PSStack

func (*PSStack) DebugString Uses

func (this *PSStack) DebugString() string

func (*PSStack) Empty Uses

func (stack *PSStack) Empty()

func (*PSStack) Pop Uses

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

func (*PSStack) PopInteger Uses

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

func (*PSStack) PopNumberAsFloat64 Uses

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

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

func (*PSStack) Push Uses

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

func (*PSStack) String Uses

func (this *PSStack) String() string

Package ps imports 9 packages (graph) and is imported by 2 packages. Updated 2019-06-04. Refresh now. Tools for package owners.