ps

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2018 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

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

Constants

View Source
const TOLERANCE = 0.000001

Tolerance for comparing real values.

Variables

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

Common errors.

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

Functions

func PSObjectArrayToFloat64Array

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

Types

type PSBoolean

type PSBoolean struct {
	Val bool
}

Bool.

func MakeBool

func MakeBool(val bool) *PSBoolean

func (*PSBoolean) DebugString

func (this *PSBoolean) DebugString() string

func (*PSBoolean) Duplicate

func (this *PSBoolean) Duplicate() PSObject

func (*PSBoolean) String

func (this *PSBoolean) String() string

type PSExecutor

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

func NewPSExecutor(program *PSProgram) *PSExecutor

func (*PSExecutor) Execute

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

type PSInteger

type PSInteger struct {
	Val int
}

Integer.

func (*PSInteger) DebugString

func (this *PSInteger) DebugString() string

func (*PSInteger) Duplicate

func (this *PSInteger) Duplicate() PSObject

func (*PSInteger) String

func (this *PSInteger) String() string

type PSObject

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

func MakeInteger

func MakeInteger(val int) PSObject

func MakeReal

func MakeReal(val float64) PSObject

type PSOperand

type PSOperand string

Operand.

func MakeOperand

func MakeOperand(val string) *PSOperand

func (*PSOperand) Abs

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

Absolute value.

func (*PSOperand) Add

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

5 27 add -> 32

func (*PSOperand) And

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

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

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

func (*PSOperand) Bitshift

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

bitshift int1 shift bitshift -> int2

func (*PSOperand) Ceiling

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

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

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

func (*PSOperand) Cos

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

Cosine angle cos -> real Angle is in degrees

func (*PSOperand) Cvi

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

Convert to integer

func (*PSOperand) Cvr

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

Convert number tor real

func (*PSOperand) DebugString

func (this *PSOperand) DebugString() string

func (*PSOperand) Div

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

func (*PSOperand) Dup

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

Duplicates the top object on the stack (dup)

func (*PSOperand) Duplicate

func (this *PSOperand) Duplicate() PSObject

func (*PSOperand) Eq

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

Check for equality. any1 any2 eq bool

func (*PSOperand) Exch

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

Exchange the top two elements of the stack (exch)

func (*PSOperand) Exec

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

func (*PSOperand) Exp

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

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

Floor of number.

func (*PSOperand) Ge

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

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

func (*PSOperand) Gt

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

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

func (*PSOperand) IDiv

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

Integral division 25 3 div -> 8

func (*PSOperand) If

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

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

func (*PSOperand) IfElse

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

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

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

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

func (*PSOperand) Ln

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

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

func (*PSOperand) Log

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

num log -> real

func (*PSOperand) Lt

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

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

func (*PSOperand) Mod

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

12 10 mod -> 2

func (*PSOperand) Mul

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

6 8 mul -> 48

func (*PSOperand) Ne

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

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

func (*PSOperand) Neg

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

Negate 6 neg -> -6

func (*PSOperand) Not

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

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

func (*PSOperand) Or

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

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

Remove the top element on the stack (pop)

func (*PSOperand) Roll

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

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

Round number off. num1 round -> num2

func (*PSOperand) Sin

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

Sine. angle sin -> real Angle is in degrees

func (*PSOperand) Sqrt

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

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

func (*PSOperand) String

func (this *PSOperand) String() string

func (*PSOperand) Sub

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

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

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

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

func NewPSParser

func NewPSParser(content []byte) *PSParser

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

func (*PSParser) Parse

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

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

type PSProgram

type PSProgram []PSObject

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

func NewPSProgram

func NewPSProgram() *PSProgram

func (*PSProgram) Append

func (this *PSProgram) Append(obj PSObject)

func (*PSProgram) DebugString

func (this *PSProgram) DebugString() string

func (*PSProgram) Duplicate

func (this *PSProgram) Duplicate() PSObject

func (*PSProgram) Exec

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

func (*PSProgram) String

func (this *PSProgram) String() string

type PSReal

type PSReal struct {
	Val float64
}

Real number.

func (*PSReal) DebugString

func (this *PSReal) DebugString() string

func (*PSReal) Duplicate

func (this *PSReal) Duplicate() PSObject

func (*PSReal) String

func (this *PSReal) String() string

type PSStack

type PSStack []PSObject

func NewPSStack

func NewPSStack() *PSStack

func (*PSStack) DebugString

func (this *PSStack) DebugString() string

func (*PSStack) Empty

func (stack *PSStack) Empty()

func (*PSStack) Pop

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

func (*PSStack) PopInteger

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

func (*PSStack) PopNumberAsFloat64

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

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

func (*PSStack) String

func (this *PSStack) String() string

Jump to

Keyboard shortcuts

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