diff --git a/pdf/contentstream/parser.go b/pdf/contentstream/parser.go index 3e6b4f46..82aed9d2 100644 --- a/pdf/contentstream/parser.go +++ b/pdf/contentstream/parser.go @@ -46,6 +46,7 @@ func (this *ContentStreamParser) Parse() (*ContentStreamOperations, error) { obj, err, isOperand := this.parseObject() if err != nil { if err == io.EOF { + // End of data. Successful exit point. return &operations, nil } return &operations, err @@ -69,9 +70,6 @@ func (this *ContentStreamParser) Parse() (*ContentStreamOperations, error) { operation.Params = append(operation.Params, im) } } - - common.Log.Debug("Operation list: %v\n", operations) - return &operations, nil } // Skip over any spaces. Returns the number of spaces skipped and diff --git a/pdf/contentstream/processor.go b/pdf/contentstream/processor.go index 50f0a25a..8b27c234 100644 --- a/pdf/contentstream/processor.go +++ b/pdf/contentstream/processor.go @@ -7,7 +7,6 @@ package contentstream import ( "errors" - "fmt" "github.com/unidoc/unidoc/common" . "github.com/unidoc/unidoc/pdf/core" @@ -25,10 +24,6 @@ type GraphicsState struct { type GraphicStateStack []GraphicsState -func (gs *GraphicsState) String() string { - return fmt.Sprintf("%+v", gs) -} - func (gsStack *GraphicStateStack) Push(gs GraphicsState) { *gsStack = append(*gsStack, gs) } diff --git a/pdf/core/parser.go b/pdf/core/parser.go index abb14ba6..2fca8734 100644 --- a/pdf/core/parser.go +++ b/pdf/core/parser.go @@ -570,8 +570,6 @@ func (parser *PdfParser) parseObject() (PdfObject, error) { return nil, errors.New("Object parsing error - unexpected pattern") } } - - return nil, errors.New("Object parsing error - unexpected pattern") } // Reads and parses a PDF dictionary object enclosed with '<<' and '>>' @@ -657,13 +655,12 @@ func (parser *PdfParser) parsePdfVersion() (int, int, error) { result1 := rePdfVersion.FindStringSubmatch(string(b)) if len(result1) < 3 { major, minor, err := parser.seekPdfVersionTopDown() - if err == nil { + if err != nil { common.Log.Debug("Failed recovery - unable to find version") return 0, 0, err } return major, minor, nil - return 0, 0, errors.New("PDF version not found") } majorVersion, err := strconv.ParseInt(result1[1], 10, 64) diff --git a/pdf/core/parser_test.go b/pdf/core/parser_test.go index 7b27f956..c3d47048 100644 --- a/pdf/core/parser_test.go +++ b/pdf/core/parser_test.go @@ -151,7 +151,7 @@ func TestBoolParsing(t *testing.T) { return } if bool(val) != expected { - t.Errorf("bool not as expected (%b)", val) + t.Errorf("bool not as expected (got %t, expected %t)", bool(val), expected) return } } @@ -188,7 +188,7 @@ func TestNumericParsing1(t *testing.T) { return } if float32(*num) != val { - t.Errorf("Idx %d, value incorrect (%f)", idx) + t.Errorf("Idx %d, value incorrect (%f)", idx, val) } } @@ -230,7 +230,7 @@ func TestNumericParsing2(t *testing.T) { return } if float32(*num) != val { - t.Errorf("Idx %d, value incorrect (%f)", idx) + t.Errorf("Idx %d, value incorrect (%f)", idx, val) } } } @@ -265,7 +265,7 @@ func TestNumericParsing3(t *testing.T) { return } if float32(*num) != val { - t.Errorf("Idx %d, value incorrect (%f)", idx) + t.Errorf("Idx %d, value incorrect (%f)", idx, val) } } } diff --git a/pdf/model/image.go b/pdf/model/image.go index 03fe72aa..48e09ba2 100644 --- a/pdf/model/image.go +++ b/pdf/model/image.go @@ -124,7 +124,7 @@ func (this *Image) ToGoImage() (goimage.Image, error) { b := uint16(samples[i+4])<<8 | uint16(samples[i+5]) a := uint16(0) if this.alphaData != nil && len(this.alphaData) > aidx+1 { - a = uint16(this.alphaData[aidx]<<8) | uint16(this.alphaData[aidx+1]) + a = (uint16(this.alphaData[aidx]) << 8) | uint16(this.alphaData[aidx+1]) aidx += 2 } c = gocolor.RGBA64{R: r, G: g, B: b, A: a}