poppler/Annot.cc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
New commits: commit 8fc71482b4ef9ceabe6159708dd2747e2648dd7d Author: Georgiy Sgibnev <geor...@lab50.net> Date: Wed Oct 6 11:47:34 2021 +0300 The field rendering logic should take into account not only AcroForm's DR but also field's DR diff --git a/poppler/Annot.cc b/poppler/Annot.cc index f31e1533..caf64f53 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -51,6 +51,7 @@ // Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <i...@kdab.com>. // Copyright (C) 2021 Zachary Travis <ztra...@everlaw.com> // Copyright (C) 2021 Mahmoud Ahmed Khalil <mahmoudkhali...@gmail.com> +// Copyright (C) 2021 Georgiy Sgibnev <geor...@sgibnev.com>. Work sponsored by lab50.net. // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -5101,13 +5102,31 @@ void AnnotWidget::generateFieldAppearance() if (!da && form) da = form->getDefaultAppearance(); - const GfxResources *resources = form ? form->getDefaultResources() : nullptr; Dict *appearDict = new Dict(doc->getXRef()); + // Let's init resourcesDictObj and resources. + // In PDF 1.2, an additional entry in the field dictionary, DR, was defined. + // Beginning with PDF 1.5, this entry is obsolete. + // And yet Acrobat Reader seems to be taking a field's DR into account. Object resourcesDictObj; - if (form && form->getDefaultResourcesObj()->isDict()) { - resourcesDictObj = form->getDefaultResourcesObj()->copy(); - } else { + const GfxResources *resources = nullptr; + GfxResources *resourcesToFree = nullptr; + if (field && field->getObj() && field->getObj()->isDict()) { + // Let's use a field's resource dictionary. + resourcesDictObj = field->getObj()->dictLookup("DR"); + if (resourcesDictObj.isDict()) { + resourcesToFree = new GfxResources(doc->getXRef(), resourcesDictObj.getDict(), form ? form->getDefaultResources() : nullptr); + resources = resourcesToFree; + } + } + if (!resourcesDictObj.isDict()) { + // No luck with a field's resource dictionary. Let's use an AcroForm's resource dictionary. + if (form && form->getDefaultResourcesObj()->isDict()) { + resourcesDictObj = form->getDefaultResourcesObj()->copy(); + resources = form->getDefaultResources(); + } + } + if (!resourcesDictObj.isDict()) { resourcesDictObj = Object(new Dict(doc->getXRef())); } @@ -5136,6 +5155,10 @@ void AnnotWidget::generateFieldAppearance() // build the appearance stream Stream *appearStream = new AutoFreeMemStream(copyString(appearBuf->c_str()), 0, appearBuf->getLength(), Object(appearDict)); appearance = Object(appearStream); + + if (resourcesToFree) { + delete resourcesToFree; + } } void AnnotWidget::updateAppearanceStream()