summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortonikitoo <tonikitoo@igalia.com>2016-08-24 10:37:00 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-24 10:37:00 -0700
commitade4b495433751ac853f2d677b9e1da94d0d6bf7 (patch)
treebd686d5545859527685695acafb4aad232cdaa1c
parenta61c01ea4527dd98699005099e9335a4a842b545 (diff)
downloadpdfium-ade4b495433751ac853f2d677b9e1da94d0d6bf7.tar.xz
Lazy generate an "AP" when an Annot's hidden state changes
Now that Document::getAnnot works and annotation instances can have its properties changed, consider the following scenario: - A PDF content has an annotation without AP and CPVT_GenerateAP is called to generate one. - However the annotation also has its hidden flag set (/F 2), and CPVT_GenerateAP bails out earlier, not generating an AP. - When the PDF's Javascript runs, it acquires an instance of this annotation object, bounded to JS using Document::getAnnot(), and set its "hidden" flag to false. - At this point, the annotation should get drawn, but it does not because its "AP" was never generated. CL fixes this scenario by making PDFium able to lazy generate APs, if needed. BUG=pdfium:492 Review-Url: https://codereview.chromium.org/2265313002
-rw-r--r--core/fpdfdoc/cpdf_annot.cpp19
-rw-r--r--core/fpdfdoc/include/cpdf_annot.h2
2 files changed, 17 insertions, 4 deletions
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index df12e9a82e..76d3f9c6d4 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -22,6 +22,14 @@ CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument)
: m_pAnnotDict(pDict),
m_pDocument(pDocument),
m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) {
+ GenerateAPIfNeeded();
+}
+
+CPDF_Annot::~CPDF_Annot() {
+ ClearCachedAP();
+}
+
+void CPDF_Annot::GenerateAPIfNeeded() {
if (m_sSubtype == "Circle")
CPVT_GenerateAP::GenerateCircleAP(m_pDocument, m_pAnnotDict);
else if (m_sSubtype == "Highlight")
@@ -40,10 +48,6 @@ CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument)
CPVT_GenerateAP::GenerateUnderlineAP(m_pDocument, m_pAnnotDict);
}
-CPDF_Annot::~CPDF_Annot() {
- ClearCachedAP();
-}
-
void CPDF_Annot::ClearCachedAP() {
m_APMap.clear();
}
@@ -149,6 +153,13 @@ FX_BOOL CPDF_Annot::DrawAppearance(CPDF_Page* pPage,
if (IsAnnotationHidden(m_pAnnotDict))
return FALSE;
+ // It might happen that by the time this annotation instance was created,
+ // it was flagged as "hidden" (e.g. /F 2), and hence CPVT_GenerateAP decided
+ // to not "generate" its AP.
+ // If for a reason the object is no longer hidden, but still does not have
+ // its "AP" generated, generate it now.
+ GenerateAPIfNeeded();
+
CFX_Matrix matrix;
CPDF_Form* pForm =
FPDFDOC_Annot_GetMatrix(pPage, this, mode, pUser2Device, matrix);
diff --git a/core/fpdfdoc/include/cpdf_annot.h b/core/fpdfdoc/include/cpdf_annot.h
index 4999349155..4029bba4cc 100644
--- a/core/fpdfdoc/include/cpdf_annot.h
+++ b/core/fpdfdoc/include/cpdf_annot.h
@@ -63,6 +63,8 @@ class CPDF_Annot {
CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode);
private:
+ void GenerateAPIfNeeded();
+
CPDF_Dictionary* const m_pAnnotDict;
CPDF_Document* const m_pDocument;
const CFX_ByteString m_sSubtype;