Skip to content

Commit

Permalink
Fix PS processing of dup operand. Fixes #98.
Browse files Browse the repository at this point in the history
Added test cases to verify.
  • Loading branch information
Gunnsteinn Hall authored and Gunnsteinn Hall committed Aug 6, 2017
1 parent 07289e3 commit d3d0312
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pdf/ps/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package ps

import (
"fmt"

"github.com/unidoc/unidoc/common"
)

// A PSExecutor has its own execution stack and is used to executre a PS routine (program).
Expand Down Expand Up @@ -52,6 +54,7 @@ func (this *PSExecutor) Execute(objects []PSObject) ([]PSObject, error) {

err := this.program.Exec(this.Stack)
if err != nil {
common.Log.Debug("Exec failed: %v", err)
return nil, err
}

Expand Down
6 changes: 6 additions & 0 deletions pdf/ps/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@ func (this *PSOperand) Dup(stack *PSStack) error {
return err
}

// Push it back.
err = stack.Push(obj)
if err != nil {
return err
}
// Push the duplicate.
err = stack.Push(obj.Duplicate())
return err
}
Expand Down
26 changes: 25 additions & 1 deletion pdf/ps/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
)

func init() {
common.SetLogger(common.ConsoleLogger{})
common.SetLogger(common.NewConsoleLogger(common.LogLevelDebug))
//common.SetLogger(common.NewConsoleLogger(common.LogLevelTrace))
}

func makeReaderForText(txt string) *bufio.Reader {
Expand Down Expand Up @@ -270,6 +271,8 @@ func TestFunctionOperations(t *testing.T) {

func TestVariousCases(t *testing.T) {
testcases := []ComplexTestEntry{
// dup
{progText: "{ 99 dup }", expected: "[ int:99 int:99 ]"},
// ceiling
{progText: "{ 3.2 ceiling }", expected: "[ real:4.00000 ]"},
{progText: "{ -4.8 ceiling }", expected: "[ real:-4.00000 ]"},
Expand Down Expand Up @@ -405,3 +408,24 @@ func TestVariousCases(t *testing.T) {
}
}
}

func TestTintTransform1(t *testing.T) {
testcases := []ComplexTestEntry{
// from corpus epson_pages3_color_pages1.pdf.
{progText: "{ 0.0000 dup 0 mul exch dup 0 mul exch dup 0 mul exch 1 mul }", expected: "[ real:0.00000 real:0.00000 real:0.00000 real:0.00000 ]"},
}

for _, testcase := range testcases {
stack, err := quickTest(testcase.progText)
if err != nil {
t.Errorf("Error: %v", err)
return
}

// Maybe not the most robust test (comparing the strings), but should do.
if stack.DebugString() != testcase.expected {
t.Errorf("Wrong result: '%s' != '%s'", stack.DebugString(), testcase.expected)
return
}
}
}

0 comments on commit d3d0312

Please sign in to comment.