fix wrong git ignore

This commit is contained in:
Adrian Zürcher
2025-12-15 17:44:00 +01:00
parent ed9f31bb96
commit 8f313c00f0
126 changed files with 70589 additions and 1 deletions

60
internal/pdf/ps/exec.go Normal file
View File

@@ -0,0 +1,60 @@
package ps
// A limited postscript parser for PDF function type 4.
import (
"fmt"
"gitea.tecamino.com/paadi/pdfmerge/internal/pdf/common"
)
// A PSExecutor has its own execution stack and is used to executre a PS routine (program).
type PSExecutor struct {
Stack *PSStack
program *PSProgram
}
func NewPSExecutor(program *PSProgram) *PSExecutor {
executor := &PSExecutor{}
executor.Stack = NewPSStack()
executor.program = program
return executor
}
func PSObjectArrayToFloat64Array(objects []PSObject) ([]float64, error) {
vals := []float64{}
for _, obj := range objects {
if number, is := obj.(*PSInteger); is {
vals = append(vals, float64(number.Val))
} else if number, is := obj.(*PSReal); is {
vals = append(vals, number.Val)
} else {
return nil, fmt.Errorf("Type error")
}
}
return vals, nil
}
func (this *PSExecutor) Execute(objects []PSObject) ([]PSObject, error) {
// Add the arguments on stack
// [obj1 obj2 ...]
for _, obj := range objects {
err := this.Stack.Push(obj)
if err != nil {
return nil, err
}
}
err := this.program.Exec(this.Stack)
if err != nil {
common.Log.Debug("Exec failed: %v", err)
return nil, err
}
result := []PSObject(*this.Stack)
this.Stack.Empty()
return result, nil
}