diff options
author | Jane Liu <janeliulwq@google.com> | 2017-06-21 12:18:37 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-22 13:56:38 +0000 |
commit | e17011dc1f5d046dc60c3347b89c0aad7d674dff (patch) | |
tree | 8624d9b8d6c156b64f0da291890478d1f9e0cb5a /core/fpdfdoc | |
parent | 4b95360b7611aa73f928de2dc47390f78573c6cc (diff) | |
download | pdfium-e17011dc1f5d046dc60c3347b89c0aad7d674dff.tar.xz |
Minor change to AP generation logic
Current behavior:
Our CPVT_GenerateAP::Generate*AP() functions do not get called as
long as the annotation dictionary has an "AP" entry.
Problem:
We always need the "N" entry in AP dictionary to display an
annotation. Even though the spec requires "AP" dictionary to have an
"N" entry for normal mode appearance, in case of a malformed pdf
with "AP" but without "N" in "AP", we won't be able to display the
annotation at all.
Fix:
Always check if "AP" has "N" entry to decide whether AP needs to be
generated. If not, then we still need to generate AP, and add to the
AP dictionary under the key "N".
Bug=pdfium:778
Change-Id: Icf0c6a681b3c8c22b0b67bf8d16ce6fefdc2c45b
Reviewed-on: https://pdfium-review.googlesource.com/6692
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Jane Liu <janeliulwq@google.com>
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r-- | core/fpdfdoc/cpdf_annot.cpp | 7 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_generateap.cpp | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp index eab6cd0145..e0f073f394 100644 --- a/core/fpdfdoc/cpdf_annot.cpp +++ b/core/fpdfdoc/cpdf_annot.cpp @@ -34,9 +34,10 @@ bool IsTextMarkupAnnotation(CPDF_Annot::Subtype type) { } bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) { - // If AP dictionary exists, we use the appearance defined in the - // existing AP dictionary. - if (pAnnotDict->KeyExist("AP")) + // If AP dictionary exists and defines an appearance for normal mode, we use + // the appearance defined in the existing AP dictionary. + CPDF_Dictionary* pAP = pAnnotDict->GetDictFor("AP"); + if (pAP && pAP->GetDictFor("N")) return false; return !CPDF_Annot::IsAnnotationHidden(pAnnotDict); diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index d542e8cb32..f76f58ad0b 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -602,7 +602,10 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc, CPDF_Stream* pNormalStream = pDoc->NewIndirect<CPDF_Stream>(); pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); - CPDF_Dictionary* pAPDict = pAnnotDict->SetNewFor<CPDF_Dictionary>("AP"); + CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); + if (!pAPDict) + pAPDict = pAnnotDict->SetNewFor<CPDF_Dictionary>("AP"); + pAPDict->SetNewFor<CPDF_Reference>("N", pDoc, pNormalStream->GetObjNum()); CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |