Skip to content
Permalink
Browse files

Fix #80, #81

  • Loading branch information...
hhrutter committed May 10, 2019
1 parent 9d476dd commit f9a4092442562289304485a9d0867be7e29a8084
Showing with 12 additions and 21 deletions.
  1. +3 −5 pkg/pdfcpu/dict.go
  2. +6 −16 pkg/pdfcpu/parse_dict_test.go
  3. +3 −0 pkg/pdfcpu/validate/pages.go
@@ -40,12 +40,10 @@ func (d Dict) Len() int {

// Insert adds a new entry to this PDFDict.
func (d Dict) Insert(key string, value Object) (ok bool) {
if o, found := d.Find(key); found {
if o.PDFString() != value.PDFString() {
return false
}
_, found := d.Find(key)
if !found {
d[key] = value
}
d[key] = value
return true
}

@@ -43,29 +43,19 @@ func doTestParseDictGeneral(t *testing.T) {
doTestParseDictFail("<<>", t)
doTestParseDictOK("<<>>", t)
doTestParseDictOK("<< >>", t)
doTestParseDictFail("<</Key1/Value1/Key1/Value2>>", t)
doTestParseDictOK("<</Key1/Value1/key1/Value2>>", t)

doTestParseDictOK("<</Type/Page/Parent 2 0 R/Resources<</Font<</F1 5 0 R/F2 7 0 R/F3 9 0 R>>/XObject<</Image11 11 0 R>>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/MediaBox[ 0 0 595.32 841.92]/Contents 4 0 R/Group<</Type/Group/S/Transparency/CS/DeviceRGB>>/Tabs/S/StructParents 0>>", t)
doTestParseDictOK("<</Type /Pages /Count 24 /Kids [6 0 R 16 0 R 21 0 R 27 0 R 30 0 R 32 0 R 34 0 R 36 0 R 38 0 R 40 0 R 42 0 R 44 0 R 46 0 R 48 0 R 50 0 R 52 0 R 54 0 R 56 0 R 58 0 R 60 0 R 62 0 R 64 0 R 69 0 R 71 0 R] /MediaBox [0 0 595.2756 841.8898]>>", t)
doTestParseDictOK("<< /Key1 <abc> /Key2 <d> >>", t)
doTestParseDictFail("<<", t)
doTestParseDictFail("<<>", t)
doTestParseDictOK("<<>>", t)
doTestParseDictOK("<< >>", t)
doTestParseDictFail("<</Key1/Value1/Key1/Value2>>", t)
doTestParseDictOK("<</Key1/Value1/key1/Value2>>", t)
}

func doTestParseDictNameObjects(t *testing.T) {
// Name Objects
doTestParseDictOK("<</S/A>>", t) // empty name
// doTestParseDictOK("<</K1 / /K2 /Name2>>", t)
// doTestParseDictOK("<</Key/Value>>", t)
// doTestParseDictOK("<< /Key /Value>>", t)
// doTestParseDictOK("<< /Key/Value >>", t)
// doTestParseDictOK("<< /Key /Value >>", t)
// doTestParseDictOK("<</Key1/Value1/Key2/Value2>>", t)
doTestParseDictOK("<</K1 / /K2 /Name2>>", t)
doTestParseDictOK("<</Key/Value>>", t)
doTestParseDictOK("<< /Key /Value>>", t)
doTestParseDictOK("<< /Key/Value >>", t)
doTestParseDictOK("<< /Key /Value >>", t)
doTestParseDictOK("<</Key1/Value1/Key2/Value2>>", t)
}

func doTestParseDictStringLiteral(t *testing.T) {
@@ -450,6 +450,9 @@ func validatePageEntryTabs(xRefTable *pdf.XRefTable, d pdf.Dict, required bool,
// Include out of spec entry "W"
validateTabs := func(s string) bool { return pdf.MemberOf(s, []string{"R", "C", "S", "W"}) }

if xRefTable.ValidationMode == pdf.ValidationRelaxed {
sinceVersion = pdf.V14
}
_, err := validateNameEntry(xRefTable, d, "pagesDict", "Tabs", required, sinceVersion, validateTabs)

return err

0 comments on commit f9a4092

Please sign in to comment.
You can’t perform that action at this time.