Skip to content

Commit

Permalink
Fix #737
Browse files Browse the repository at this point in the history
  • Loading branch information
hhrutter committed Nov 25, 2023
1 parent b34248d commit d6f60e1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pkg/pdfcpu/annotation.go
Expand Up @@ -142,7 +142,7 @@ func Annotation(xRefTable *model.XRefTable, d types.Dict) (model.AnnotationRende
return nil, err
}

r, err := types.RectForArray(arr)
r, err := xRefTable.RectForArray(arr)
if err != nil {
return nil, err
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/pdfcpu/model/xreftable.go
Expand Up @@ -2792,3 +2792,28 @@ func (xRefTable *XRefTable) BindViewerPreferences() {

xRefTable.RootDict["ViewerPreferences"] = d
}

// RectForArray returns a new rectangle for given Array.
func (xRefTable *XRefTable) RectForArray(a types.Array) (*types.Rectangle, error) {
llx, err := xRefTable.DereferenceNumber(a[0])
if err != nil {
return nil, err
}

lly, err := xRefTable.DereferenceNumber(a[1])
if err != nil {
return nil, err
}

urx, err := xRefTable.DereferenceNumber(a[2])
if err != nil {
return nil, err
}

ury, err := xRefTable.DereferenceNumber(a[2])
if err != nil {
return nil, err
}

return types.NewRectangle(llx, lly, urx, ury), nil
}
2 changes: 1 addition & 1 deletion pkg/pdfcpu/primitives/comboBox.go
Expand Up @@ -722,7 +722,7 @@ func NewComboBox(

cb := &ComboBox{Value: v}

bb, err := types.RectForArray(d.ArrayEntry("Rect"))
bb, err := ctx.RectForArray(d.ArrayEntry("Rect"))
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pdfcpu/primitives/dateField.go
Expand Up @@ -860,7 +860,7 @@ func NewDateField(

df := &DateField{Value: v}

bb, err := types.RectForArray(d.ArrayEntry("Rect"))
bb, err := ctx.RectForArray(d.ArrayEntry("Rect"))
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pdfcpu/primitives/listBox.go
Expand Up @@ -874,7 +874,7 @@ func NewListBox(

lb := &ListBox{Options: opts, Ind: ind}

bb, err := types.RectForArray(d.ArrayEntry("Rect"))
bb, err := ctx.RectForArray(d.ArrayEntry("Rect"))
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pdfcpu/primitives/textField.go
Expand Up @@ -877,7 +877,7 @@ func NewTextField(

tf := &TextField{Value: v, Multiline: multiLine}

bb, err := types.RectForArray(d.ArrayEntry("Rect"))
bb, err := ctx.RectForArray(d.ArrayEntry("Rect"))
if err != nil {
return nil, nil, err
}
Expand Down
41 changes: 0 additions & 41 deletions pkg/pdfcpu/types/types.go
Expand Up @@ -21,8 +21,6 @@ import (
"encoding/hex"
"fmt"
"strconv"

"github.com/pkg/errors"
)

// Supported line delimiters
Expand Down Expand Up @@ -172,32 +170,6 @@ func NewRectangle(llx, lly, urx, ury float64) *Rectangle {
return &Rectangle{LL: Point{llx, lly}, UR: Point{urx, ury}}
}

// RectForArray returns a new rectangle for given Array.
func RectForArray(a Array) (*Rectangle, error) {

llx, err := a.FloatNumber(0)
if err != nil {
return nil, err
}

lly, err := a.FloatNumber(1)
if err != nil {
return nil, err
}

urx, err := a.FloatNumber(2)
if err != nil {
return nil, err
}

ury, err := a.FloatNumber(3)
if err != nil {
return nil, err
}

return NewRectangle(llx, lly, urx, ury), nil
}

// RectForDim returns a new rectangle for given dimensions.
func RectForDim(width, height float64) *Rectangle {
return NewRectangle(0.0, 0.0, width, height)
Expand Down Expand Up @@ -349,19 +321,6 @@ func (r Rectangle) Format(unit DisplayUnit) string {
return r.String()
}

// FloatNumber returns the element at index ind of a numbers array and returns a float64.
func (a Array) FloatNumber(ind int) (float64, error) {
f, ok := a[ind].(Float)
if ok {
return f.Value(), nil
}
i, ok := a[ind].(Integer)
if ok {
return float64(i.Value()), nil
}
return 0, errors.Errorf("pdfcpu: array element %d not a number (Float/Integer", ind)
}

///////////////////////////////////////////////////////////////////////////////////

// QuadLiteral is a polygon with four edges and four vertices.
Expand Down

0 comments on commit d6f60e1

Please sign in to comment.