Skip to content

Commit

Permalink
Few fixes: Shadingtype 4 handling, inline image handling (compatibili…
Browse files Browse the repository at this point in the history
…ty), encoding name (compatibility)
  • Loading branch information
Gunnsteinn Hall authored and Gunnsteinn Hall committed Aug 14, 2017
1 parent 144fa3f commit b3e3008
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pdf/contentstream/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func newMultiEncoderFromInlineImage(inlineImage *ContentStreamInlineImage) (*cor
dParams = dict
}

if *name == core.StreamEncodingFilterNameFlate {
if *name == core.StreamEncodingFilterNameFlate || *name == "Fl" {
// XXX: need to separate out the DecodeParms..
encoder, err := newFlateEncoderFromInlineImage(inlineImage, dParams)
if err != nil {
Expand All @@ -375,7 +375,7 @@ func newMultiEncoderFromInlineImage(inlineImage *ContentStreamInlineImage) (*cor
} else if *name == core.StreamEncodingFilterNameASCIIHex {
encoder := core.NewASCIIHexEncoder()
mencoder.AddEncoder(encoder)
} else if *name == core.StreamEncodingFilterNameASCII85 {
} else if *name == core.StreamEncodingFilterNameASCII85 || *name == "A85" {
encoder := core.NewASCII85Encoder()
mencoder.AddEncoder(encoder)
} else {
Expand Down
12 changes: 6 additions & 6 deletions pdf/contentstream/inline-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,25 +327,25 @@ func (this *ContentStreamParser) ParseInlineImage() (*ContentStreamInlineImage,
return nil, fmt.Errorf("Not expecting an operand")
}

if *param == "BPC" {
if *param == "BPC" || *param == "BitsPerComponent" {
im.BitsPerComponent = valueObj
} else if *param == "CS" {
} else if *param == "CS" || *param == "ColorSpace" {
im.ColorSpace = valueObj
} else if *param == "D" {
im.Decode = valueObj
} else if *param == "DP" {
} else if *param == "DP" || *param == "DecodeParms" {
im.DecodeParms = valueObj
} else if *param == "F" {
} else if *param == "F" || *param == "Filter" {
im.Filter = valueObj
} else if *param == "H" {
} else if *param == "H" || *param == "Height" {
im.Height = valueObj
} else if *param == "IM" {
im.ImageMask = valueObj
} else if *param == "Intent" {
im.Intent = valueObj
} else if *param == "I" {
im.Interpolate = valueObj
} else if *param == "W" {
} else if *param == "W" || *param == "Width" {
im.Width = valueObj
} else {
return nil, fmt.Errorf("Unknown inline image parameter %s", *param)
Expand Down
5 changes: 5 additions & 0 deletions pdf/contentstream/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ func (this *ContentStreamParser) parseNumber() (PdfObject, error) {
return &o, err
} else {
intVal, err := strconv.ParseInt(numStr, 10, 64)
if err != nil {
common.Log.Debug("Error parsing integer %q err=%v. Using 0. Output may be incorrect", numStr, err)
intVal = 0
err = nil
}
o := PdfObjectInteger(intVal)
return &o, err
}
Expand Down
2 changes: 1 addition & 1 deletion pdf/core/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewEncoderFromStream(streamObj *PdfObjectStream) (StreamEncoder, error) {
return newRunLengthEncoderFromStream(streamObj, nil)
} else if *method == StreamEncodingFilterNameASCIIHex {
return NewASCIIHexEncoder(), nil
} else if *method == StreamEncodingFilterNameASCII85 {
} else if *method == StreamEncodingFilterNameASCII85 || *method == "A85" {
return NewASCII85Encoder(), nil
} else if *method == StreamEncodingFilterNameCCITTFax {
return NewCCITTFaxEncoder(), nil
Expand Down
18 changes: 8 additions & 10 deletions pdf/model/shading.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,18 +524,16 @@ func newPdfShadingType4FromDictionary(dict *PdfObjectDictionary) (*PdfShadingTyp
}
shading.Decode = arr

// Function (required).
// Function (optional).
obj = dict.Get("Function")
if obj == nil {
common.Log.Debug("Required attribute missing: Function")
return nil, errors.New("Required attribute missing")
}
function, err := newPdfFunctionFromPdfObject(obj)
if err != nil {
common.Log.Debug("Error parsing function: %v", err)
return nil, err
if obj != nil {
function, err := newPdfFunctionFromPdfObject(obj)
if err != nil {
common.Log.Debug("Error parsing function: %v", err)
return nil, err
}
shading.Function = function
}
shading.Function = function

return &shading, nil
}
Expand Down

0 comments on commit b3e3008

Please sign in to comment.