summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc/doc_annot.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-30 23:55:35 -0700
committerLei Zhang <thestig@chromium.org>2015-10-30 23:55:35 -0700
commit1b700c3c452429dacde3c163a6edb2706f93d4a7 (patch)
tree4efaf4dcec5b28a4d6cac575727dc61356e8a4fe /core/src/fpdfdoc/doc_annot.cpp
parentde6088db8403e775e2963ce6e0bd55e5356beb73 (diff)
downloadpdfium-1b700c3c452429dacde3c163a6edb2706f93d4a7.tar.xz
Merge to XFA: Clean up CPDF_AnnotList.
- Remove dead code - Stop using CFX_PtrArray - Mark more things const - Fix style nits TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1425093003 . (cherry picked from commit c88c42f317c0e94c4c7b98949bfe1a495aef07a9) Review URL: https://codereview.chromium.org/1430803003 .
Diffstat (limited to 'core/src/fpdfdoc/doc_annot.cpp')
-rw-r--r--core/src/fpdfdoc/doc_annot.cpp120
1 files changed, 46 insertions, 74 deletions
diff --git a/core/src/fpdfdoc/doc_annot.cpp b/core/src/fpdfdoc/doc_annot.cpp
index d37b1aaadb..ae253a086a 100644
--- a/core/src/fpdfdoc/doc_annot.cpp
+++ b/core/src/fpdfdoc/doc_annot.cpp
@@ -8,25 +8,23 @@
#include "../../include/fpdfdoc/fpdf_doc.h"
#include "../../include/fpdfapi/fpdf_pageobj.h"
-CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) {
- ASSERT(pPage != NULL);
- m_pPageDict = pPage->m_pFormDict;
- if (m_pPageDict == NULL) {
+CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
+ : m_pDocument(pPage->m_pDocument) {
+ if (!pPage->m_pFormDict)
return;
- }
- m_pDocument = pPage->m_pDocument;
- CPDF_Array* pAnnots = m_pPageDict->GetArray("Annots");
- if (pAnnots == NULL) {
+
+ CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots");
+ if (!pAnnots)
return;
- }
+
CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
FX_BOOL bRegenerateAP = pAcroForm && pAcroForm->GetBoolean("NeedAppearances");
for (FX_DWORD i = 0; i < pAnnots->GetCount(); ++i) {
CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetElementValue(i));
- if (!pDict) {
+ if (!pDict)
continue;
- }
+
FX_DWORD dwObjNum = pDict->GetObjNum();
if (dwObjNum == 0) {
dwObjNum = m_pDocument->AddIndirectObject(pDict);
@@ -35,24 +33,20 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) {
pAnnots->RemoveAt(i + 1);
pDict = pAnnots->GetDict(i);
}
- CPDF_Annot* pAnnot = new CPDF_Annot(pDict, this);
- m_AnnotList.Add(pAnnot);
+ m_AnnotList.push_back(new CPDF_Annot(pDict, this));
if (bRegenerateAP &&
- pDict->GetConstString(FX_BSTRC("Subtype")) == FX_BSTRC("Widget"))
- if (CPDF_InterForm::UpdatingAPEnabled()) {
- FPDF_GenerateAP(m_pDocument, pDict);
- }
+ pDict->GetConstString(FX_BSTRC("Subtype")) == FX_BSTRC("Widget") &&
+ CPDF_InterForm::UpdatingAPEnabled()) {
+ FPDF_GenerateAP(m_pDocument, pDict);
+ }
}
}
+
CPDF_AnnotList::~CPDF_AnnotList() {
- int i = 0;
- for (i = 0; i < m_AnnotList.GetSize(); ++i) {
- delete (CPDF_Annot*)m_AnnotList[i];
- }
- for (i = 0; i < m_Borders.GetSize(); ++i) {
- delete (CPDF_PageObjects*)m_Borders[i];
- }
+ for (CPDF_Annot* annot : m_AnnotList)
+ delete annot;
}
+
void CPDF_AnnotList::DisplayPass(const CPDF_Page* pPage,
CFX_RenderDevice* pDevice,
CPDF_RenderContext* pContext,
@@ -61,34 +55,32 @@ void CPDF_AnnotList::DisplayPass(const CPDF_Page* pPage,
FX_BOOL bWidgetPass,
CPDF_RenderOptions* pOptions,
FX_RECT* clip_rect) {
- for (int i = 0; i < m_AnnotList.GetSize(); ++i) {
- CPDF_Annot* pAnnot = (CPDF_Annot*)m_AnnotList[i];
+ for (CPDF_Annot* pAnnot : m_AnnotList) {
FX_BOOL bWidget = pAnnot->GetSubType() == "Widget";
- if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) {
+ if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget))
continue;
- }
+
FX_DWORD annot_flags = pAnnot->GetFlags();
- if (annot_flags & ANNOTFLAG_HIDDEN) {
+ if (annot_flags & ANNOTFLAG_HIDDEN)
continue;
- }
- if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) {
+
+ if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0)
continue;
- }
- if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) {
+
+ if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW))
continue;
- }
- if (pOptions != NULL) {
+
+ if (pOptions) {
IPDF_OCContext* pOCContext = pOptions->m_pOCContext;
CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
- if (pOCContext != NULL && pAnnotDict != NULL &&
+ if (pOCContext && pAnnotDict &&
!pOCContext->CheckOCGVisible(pAnnotDict->GetDict(FX_BSTRC("OC")))) {
continue;
}
}
CPDF_Rect annot_rect_f;
pAnnot->GetRect(annot_rect_f);
- CFX_Matrix matrix;
- matrix = *pMatrix;
+ CFX_Matrix matrix = *pMatrix;
if (clip_rect) {
annot_rect_f.Transform(&matrix);
FX_RECT annot_rect = annot_rect_f.GetOutterRect();
@@ -105,20 +97,7 @@ void CPDF_AnnotList::DisplayPass(const CPDF_Page* pPage,
}
}
}
-void CPDF_AnnotList::DisplayAnnots(const CPDF_Page* pPage,
- CFX_RenderDevice* pDevice,
- CFX_AffineMatrix* pUser2Device,
- FX_BOOL bShowWidget,
- CPDF_RenderOptions* pOptions) {
- FX_RECT clip_rect;
- if (pDevice) {
- clip_rect = pDevice->GetClipBox();
- }
- FX_BOOL bPrinting = pDevice->GetDeviceClass() == FXDC_PRINTER ||
- (pOptions && (pOptions->m_Flags & RENDER_PRINTPREVIEW));
- DisplayAnnots(pPage, pDevice, NULL, bPrinting, pUser2Device,
- bShowWidget ? 3 : 1, pOptions, &clip_rect);
-}
+
void CPDF_AnnotList::DisplayAnnots(const CPDF_Page* pPage,
CFX_RenderDevice* pDevice,
CPDF_RenderContext* pContext,
@@ -136,13 +115,7 @@ void CPDF_AnnotList::DisplayAnnots(const CPDF_Page* pPage,
pOptions, pClipRect);
}
}
-int CPDF_AnnotList::GetIndex(CPDF_Annot* pAnnot) {
- for (int i = 0; i < m_AnnotList.GetSize(); ++i)
- if (m_AnnotList[i] == (void*)pAnnot) {
- return i;
- }
- return -1;
-}
+
CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_AnnotList* pList)
: m_pAnnotDict(pDict),
m_pList(pList),
@@ -176,10 +149,6 @@ FX_DWORD CPDF_Annot::GetFlags() const {
return m_pAnnotDict->GetInteger("F");
}
-CPDF_Dictionary* CPDF_Annot::GetAnnotDict() {
- return m_pAnnotDict;
-}
-
CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict,
CPDF_Annot::AppearanceMode mode) {
CPDF_Dictionary* pAP = pAnnotDict->GetDict("AP");
@@ -217,20 +186,23 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict,
}
return nullptr;
}
+
CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) {
CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode);
- if (pStream == NULL) {
- return NULL;
- }
- CPDF_Form* pForm;
- if (m_APMap.Lookup(pStream, (void*&)pForm)) {
- return pForm;
- }
- pForm = new CPDF_Form(m_pList->m_pDocument, pPage->m_pResources, pStream);
- pForm->ParseContent(NULL, NULL, NULL, NULL);
- m_APMap.SetAt(pStream, pForm);
- return pForm;
+ if (!pStream)
+ return nullptr;
+
+ void* pForm;
+ if (m_APMap.Lookup(pStream, pForm))
+ return static_cast<CPDF_Form*>(pForm);
+
+ CPDF_Form* pNewForm =
+ new CPDF_Form(m_pList->GetDocument(), pPage->m_pResources, pStream);
+ pNewForm->ParseContent(nullptr, nullptr, nullptr, nullptr);
+ m_APMap.SetAt(pStream, pNewForm);
+ return pNewForm;
}
+
static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage,
CPDF_Annot* pAnnot,
CPDF_Annot::AppearanceMode mode,