Skip to content

Commit

Permalink
Fix #772
Browse files Browse the repository at this point in the history
  • Loading branch information
hhrutter committed Jan 31, 2024
1 parent 96659b7 commit 6ae90db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
13 changes: 10 additions & 3 deletions pkg/pdfcpu/validate/font.go
Expand Up @@ -135,11 +135,18 @@ func validateFontDescriptorPart1(xRefTable *model.XRefTable, d types.Dict, dictN
return err
}

_, err = validateNameEntry(xRefTable, d, dictName, "FontName", REQUIRED, model.V10, nil)
required := true
if xRefTable.ValidationMode == model.ValidationRelaxed {
required = false
}
_, err = validateNameEntry(xRefTable, d, dictName, "FontName", required, model.V10, nil)
if err != nil {
_, err = validateStringEntry(xRefTable, d, dictName, "FontName", REQUIRED, model.V10, nil)
_, err = validateStringEntry(xRefTable, d, dictName, "FontName", required, model.V10, nil)
if err != nil {
return err
if xRefTable.ValidationMode != model.ValidationRelaxed {
return err
}
reportSpecViolation(xRefTable, err)
}
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/pdfcpu/validate/page.go
Expand Up @@ -102,8 +102,12 @@ func validatePageContents(xRefTable *model.XRefTable, d types.Dict) (hasContents

}

if xRefTable.ValidationMode != model.ValidationRelaxed {
return false, errors.Errorf("validatePageContents: empty page content array detected")
if !hasContents {
err := errors.Errorf("validatePageContents: empty page content array detected")
if xRefTable.ValidationMode == model.ValidationStrict {
return false, err
}
reportSpecViolation(xRefTable, err)
}

default:
Expand Down
11 changes: 11 additions & 0 deletions pkg/pdfcpu/validate/xReftable.go
Expand Up @@ -31,6 +31,17 @@ import (
"github.com/pkg/errors"
)

func reportSpecViolation(xRefTable *model.XRefTable, err error) {
// TODO Apply across code base.
pre := fmt.Sprintf("digesting spec violation around obj#(%d)", xRefTable.CurObj)
if log.ValidateEnabled() {
log.CLI.Printf("%s: %v\n", pre, err)
}
if log.CLIEnabled() {
log.Validate.Printf("%s: %v\n", pre, err)
}
}

// XRefTable validates a PDF cross reference table obeying the validation mode.
func XRefTable(xRefTable *model.XRefTable) error {
if log.InfoEnabled() {
Expand Down

0 comments on commit 6ae90db

Please sign in to comment.