summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortonikitoo <tonikitoo@igalia.com>2016-09-06 06:14:06 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-06 06:14:06 -0700
commit921d58f43cbf0dc3f12394b80cb315d00ee0bd35 (patch)
tree1cbefd5fb63cbce4b9ee12c761756004d9082f96
parent7b36672405c05037709a7ba3e8cc96efe2471408 (diff)
downloadpdfium-921d58f43cbf0dc3f12394b80cb315d00ee0bd35.tar.xz
Move ShouldGenerateAPForAnnotation check to CPDF_Annot::GenerateAPIfNeeded
By doing this, we simplify the code in cpvt_generateap.cpp, and avoid calling CPVT_GenerateAP methods altogether, when it is known that they are bailing out. This is a preparation to fix pdfium bug 585. BUG=pdfium:585 Review-Url: https://codereview.chromium.org/2310873002
-rw-r--r--core/fpdfdoc/cpdf_annot.cpp18
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp33
2 files changed, 17 insertions, 34 deletions
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 942d334a2d..4e0b04e9b6 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -18,6 +18,19 @@
#include "core/fxge/include/cfx_pathdata.h"
#include "core/fxge/include/cfx_renderdevice.h"
+namespace {
+
+bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) {
+ // If AP dictionary exists, we use the appearance defined in the
+ // existing AP dictionary.
+ if (pAnnotDict->KeyExist("AP"))
+ return false;
+
+ return !CPDF_Annot::IsAnnotationHidden(pAnnotDict);
+}
+
+} // namespace
+
CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict,
CPDF_Document* pDocument,
bool bToOwnDict)
@@ -37,6 +50,9 @@ CPDF_Annot::~CPDF_Annot() {
}
void CPDF_Annot::GenerateAPIfNeeded() {
+ if (!ShouldGenerateAPForAnnotation(m_pAnnotDict))
+ return;
+
if (m_nSubtype == CPDF_Annot::Subtype::CIRCLE)
CPVT_GenerateAP::GenerateCircleAP(m_pDocument, m_pAnnotDict);
else if (m_nSubtype == CPDF_Annot::Subtype::HIGHLIGHT)
@@ -149,7 +165,7 @@ static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage,
return pForm;
}
-// static
+// Static.
bool CPDF_Annot::IsAnnotationHidden(CPDF_Dictionary* pAnnotDict) {
return !!(pAnnotDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN);
}
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index d19992ec60..be96d2d1d3 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -674,15 +674,6 @@ CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) {
return sAppStream.MakeString();
}
-bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) {
- // If AP dictionary exists, we use the appearance defined in the
- // existing AP dictionary.
- if (pAnnotDict->KeyExist("AP"))
- return false;
-
- return !CPDF_Annot::IsAnnotationHidden(pAnnotDict);
-}
-
} // namespace
bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
@@ -735,9 +726,6 @@ bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc,
bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- if (!ShouldGenerateAPForAnnotation(pAnnotDict))
- return false;
-
CFX_ByteTextBuf sAppStream;
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
@@ -811,9 +799,6 @@ bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- if (!ShouldGenerateAPForAnnotation(pAnnotDict))
- return false;
-
CFX_ByteTextBuf sAppStream;
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
@@ -841,9 +826,6 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- if (!ShouldGenerateAPForAnnotation(pAnnotDict))
- return false;
-
FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
bool bIsStroke = fBorderWidth > 0;
@@ -897,9 +879,6 @@ bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- if (!ShouldGenerateAPForAnnotation(pAnnotDict))
- return false;
-
CFX_ByteTextBuf sAppStream;
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
@@ -922,9 +901,6 @@ bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- if (!ShouldGenerateAPForAnnotation(pAnnotDict))
- return false;
-
CFX_ByteTextBuf sAppStream;
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
@@ -989,9 +965,6 @@ bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc,
bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- if (!ShouldGenerateAPForAnnotation(pAnnotDict))
- return false;
-
CFX_ByteTextBuf sAppStream;
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
@@ -1039,9 +1012,6 @@ bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc,
bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- if (!ShouldGenerateAPForAnnotation(pAnnotDict))
- return false;
-
CFX_ByteTextBuf sAppStream;
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";
@@ -1090,9 +1060,6 @@ bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- if (!ShouldGenerateAPForAnnotation(pAnnotDict))
- return false;
-
CFX_ByteTextBuf sAppStream;
CFX_ByteString sExtGSDictName = "GS";
sAppStream << "/" << sExtGSDictName << " gs ";