summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfdoc/fpdf_doc.h61
-rw-r--r--core/src/fpdfdoc/doc_annot.cpp120
-rw-r--r--core/src/fpdfdoc/doc_form.cpp2
3 files changed, 60 insertions, 123 deletions
diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h
index 168d9ebee0..cc5cf08005 100644
--- a/core/include/fpdfdoc/fpdf_doc.h
+++ b/core/include/fpdfdoc/fpdf_doc.h
@@ -394,7 +394,8 @@ class CPDF_Annot : public CFX_PrivateData {
void GetRect(CFX_FloatRect& rect) const;
- CPDF_Dictionary* GetAnnotDict();
+ const CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict; }
+ CPDF_Dictionary* GetAnnotDict() { return m_pAnnotDict; }
FX_BOOL DrawAppearance(const CPDF_Page* pPage,
CFX_RenderDevice* pDevice,
@@ -427,45 +428,18 @@ class CPDF_Annot : public CFX_PrivateData {
class CPDF_AnnotList {
public:
- CPDF_AnnotList(CPDF_Page* pPage);
-
+ explicit CPDF_AnnotList(CPDF_Page* pPage);
~CPDF_AnnotList();
- void GetAnnotMatrix(const CPDF_Dictionary* pAnnotDict,
- const CFX_Matrix* pUser2Device,
- CFX_Matrix& matrix) const;
-
- void GetAnnotRect(const CPDF_Dictionary* pAnnotDict,
- const CFX_Matrix* pUser2Device,
- CPDF_Rect& rtAnnot) const;
-
- void DisplayAnnots(const CPDF_Page* pPage,
- CFX_RenderDevice* pDevice,
- CFX_AffineMatrix* pMatrix,
- FX_BOOL bShowWidget,
- CPDF_RenderOptions* pOptions);
-
void DisplayAnnots(const CPDF_Page* pPage,
CPDF_RenderContext* pContext,
FX_BOOL bPrinting,
CFX_AffineMatrix* pMatrix,
FX_BOOL bShowWidget,
CPDF_RenderOptions* pOptions) {
- DisplayAnnots(pPage, NULL, pContext, bPrinting, pMatrix,
- bShowWidget ? 3 : 1, pOptions, NULL);
+ DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix,
+ bShowWidget ? 3 : 1, pOptions, nullptr);
}
-
- void DisplayAnnots(const CPDF_Page* pPage,
- CPDF_RenderContext* pContext,
- FX_BOOL bPrinting,
- CFX_AffineMatrix* pMatrix,
- FX_BOOL bShowWidget,
- CPDF_RenderOptions* pOptions,
- FX_RECT* pClipRect) {
- DisplayAnnots(pPage, NULL, pContext, bPrinting, pMatrix,
- bShowWidget ? 3 : 1, pOptions, pClipRect);
- }
-
void DisplayAnnots(const CPDF_Page* pPage,
CFX_RenderDevice* pDevice,
CPDF_RenderContext* pContext,
@@ -474,24 +448,12 @@ class CPDF_AnnotList {
FX_DWORD dwAnnotFlags,
CPDF_RenderOptions* pOptions,
FX_RECT* pClipRect);
-
- CPDF_Annot* GetAt(int index) { return (CPDF_Annot*)m_AnnotList.GetAt(index); }
-
- int Count() { return m_AnnotList.GetSize(); }
-
- int GetIndex(CPDF_Annot* pAnnot);
-
+ size_t Count() const { return m_AnnotList.size(); }
+ CPDF_Annot* GetAt(size_t index) const { return m_AnnotList[index]; }
+ const std::vector<CPDF_Annot*>& All() const { return m_AnnotList; }
CPDF_Document* GetDocument() const { return m_pDocument; }
protected:
- CFX_PtrArray m_AnnotList;
-
- CPDF_Dictionary* m_pPageDict;
-
- CPDF_Document* m_pDocument;
-
- CFX_PtrArray m_Borders;
-
void DisplayPass(const CPDF_Page* pPage,
CFX_RenderDevice* pDevice,
CPDF_RenderContext* pContext,
@@ -500,8 +462,11 @@ class CPDF_AnnotList {
FX_BOOL bWidget,
CPDF_RenderOptions* pOptions,
FX_RECT* clip_rect);
- friend class CPDF_Annot;
+
+ CPDF_Document* const m_pDocument;
+ std::vector<CPDF_Annot*> m_AnnotList;
};
+
#define COLORTYPE_TRANSPARENT 0
#define COLORTYPE_GRAY 1
#define COLORTYPE_RGB 2
@@ -623,7 +588,7 @@ class CPDF_InterForm : public CFX_PrivateData {
FX_FLOAT pdf_y,
int* z_order) const;
- CPDF_FormControl* GetControlByDict(CPDF_Dictionary* pWidgetDict) const;
+ CPDF_FormControl* GetControlByDict(const CPDF_Dictionary* pWidgetDict) const;
CPDF_Document* GetDocument() const { return m_pDocument; }
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,
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index c155b947d9..5cc2a66a89 100644
--- a/core/src/fpdfdoc/doc_form.cpp
+++ b/core/src/fpdfdoc/doc_form.cpp
@@ -818,7 +818,7 @@ CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage,
}
CPDF_FormControl* CPDF_InterForm::GetControlByDict(
- CPDF_Dictionary* pWidgetDict) const {
+ const CPDF_Dictionary* pWidgetDict) const {
const auto it = m_ControlMap.find(pWidgetDict);
return it != m_ControlMap.end() ? it->second : nullptr;
}