Skip to content

Commit 6ae90db

Browse files
committed
Fix #772
1 parent 96659b7 commit 6ae90db

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

pkg/pdfcpu/validate/font.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,18 @@ func validateFontDescriptorPart1(xRefTable *model.XRefTable, d types.Dict, dictN
135135
return err
136136
}
137137

138-
_, err = validateNameEntry(xRefTable, d, dictName, "FontName", REQUIRED, model.V10, nil)
138+
required := true
139+
if xRefTable.ValidationMode == model.ValidationRelaxed {
140+
required = false
141+
}
142+
_, err = validateNameEntry(xRefTable, d, dictName, "FontName", required, model.V10, nil)
139143
if err != nil {
140-
_, err = validateStringEntry(xRefTable, d, dictName, "FontName", REQUIRED, model.V10, nil)
144+
_, err = validateStringEntry(xRefTable, d, dictName, "FontName", required, model.V10, nil)
141145
if err != nil {
142-
return err
146+
if xRefTable.ValidationMode != model.ValidationRelaxed {
147+
return err
148+
}
149+
reportSpecViolation(xRefTable, err)
143150
}
144151
}
145152

pkg/pdfcpu/validate/page.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ func validatePageContents(xRefTable *model.XRefTable, d types.Dict) (hasContents
102102

103103
}
104104

105-
if xRefTable.ValidationMode != model.ValidationRelaxed {
106-
return false, errors.Errorf("validatePageContents: empty page content array detected")
105+
if !hasContents {
106+
err := errors.Errorf("validatePageContents: empty page content array detected")
107+
if xRefTable.ValidationMode == model.ValidationStrict {
108+
return false, err
109+
}
110+
reportSpecViolation(xRefTable, err)
107111
}
108112

109113
default:

pkg/pdfcpu/validate/xReftable.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ import (
3131
"github.com/pkg/errors"
3232
)
3333

34+
func reportSpecViolation(xRefTable *model.XRefTable, err error) {
35+
// TODO Apply across code base.
36+
pre := fmt.Sprintf("digesting spec violation around obj#(%d)", xRefTable.CurObj)
37+
if log.ValidateEnabled() {
38+
log.CLI.Printf("%s: %v\n", pre, err)
39+
}
40+
if log.CLIEnabled() {
41+
log.Validate.Printf("%s: %v\n", pre, err)
42+
}
43+
}
44+
3445
// XRefTable validates a PDF cross reference table obeying the validation mode.
3546
func XRefTable(xRefTable *model.XRefTable) error {
3647
if log.InfoEnabled() {

0 commit comments

Comments
 (0)