summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_annot.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-05-03 17:19:53 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-03 17:19:53 +0000
commit525147a1f6d6cd736a407d1e189ac25d2f4726e8 (patch)
treebdc818c52d902a5a4e8ce8a4f0ba29bd11007b05 /fpdfsdk/fpdf_annot.cpp
parentccd9421589922b8f35ee5330d7fdac7edea081db (diff)
downloadpdfium-525147a1f6d6cd736a407d1e189ac25d2f4726e8.tar.xz
Use strict types in FPDF API, try #3
Rather than messing with actual inheritence, add type-checking wrappers and just blatantly cast to incomplete types. Along the way, this points out places where we would downcast without checking, which I fix. Change-Id: Ieb303eb46ad8522dfe082454f1f10f247ffd52d5 Reviewed-on: https://pdfium-review.googlesource.com/32030 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_annot.cpp')
-rw-r--r--fpdfsdk/fpdf_annot.cpp56
1 files changed, 12 insertions, 44 deletions
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 6504ee7402..0dbad498ce 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -22,6 +22,7 @@
#include "core/fpdfdoc/cpdf_interform.h"
#include "core/fpdfdoc/cpvt_generateap.h"
#include "core/fxge/cfx_color.h"
+#include "fpdfsdk/cpdf_annotcontext.h"
#include "fpdfsdk/cpdfsdk_helpers.h"
namespace {
@@ -141,45 +142,6 @@ static_assert(static_cast<int>(CPDF_Object::Type::REFERENCE) ==
FPDF_OBJECT_REFERENCE,
"CPDF_Object::REFERENCE value mismatch");
-class CPDF_AnnotContext {
- public:
- CPDF_AnnotContext(CPDF_Dictionary* pAnnotDict,
- CPDF_Page* pPage,
- CPDF_Stream* pStream)
- : m_pAnnotDict(pAnnotDict), m_pPage(pPage) {
- SetForm(pStream);
- }
- ~CPDF_AnnotContext() {}
-
- bool HasForm() const { return !!m_pAnnotForm; }
-
- void SetForm(CPDF_Stream* pStream) {
- if (!pStream)
- return;
-
- // Reset the annotation matrix to be the identity matrix, since the
- // appearance stream already takes matrix into account.
- pStream->GetDict()->SetMatrixFor("Matrix", CFX_Matrix());
-
- m_pAnnotForm = pdfium::MakeUnique<CPDF_Form>(
- m_pPage->m_pDocument.Get(), m_pPage->m_pResources.Get(), pStream);
- m_pAnnotForm->ParseContent();
- }
-
- CPDF_Form* GetForm() const { return m_pAnnotForm.get(); }
- CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict.Get(); }
- CPDF_Page* GetPage() const { return m_pPage.Get(); }
-
- private:
- std::unique_ptr<CPDF_Form> m_pAnnotForm;
- UnownedPtr<CPDF_Dictionary> m_pAnnotDict;
- UnownedPtr<CPDF_Page> m_pPage;
-};
-
-CPDF_AnnotContext* CPDFAnnotContextFromFPDFAnnotation(FPDF_ANNOTATION annot) {
- return static_cast<CPDF_AnnotContext*>(annot);
-}
-
bool HasAPStream(const CPDF_Dictionary* pAnnotDict) {
return !!FPDFDOC_GetAnnotAP(pAnnotDict, CPDF_Annot::AppearanceMode::Normal);
}
@@ -270,9 +232,10 @@ FPDFPage_CreateAnnot(FPDF_PAGE page, FPDF_ANNOTATION_SUBTYPE subtype) {
CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayFor("Annots");
if (!pAnnotList)
pAnnotList = pPage->m_pFormDict->SetNewFor<CPDF_Array>("Annots");
-
pAnnotList->Add(std::move(pDict));
- return pNewAnnot.release();
+
+ // Caller takes ownership.
+ return FPDFAnnotationFromCPDFAnnotContext(pNewAnnot.release());
}
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetAnnotCount(FPDF_PAGE page) {
@@ -296,7 +259,9 @@ FPDF_EXPORT FPDF_ANNOTATION FPDF_CALLCONV FPDFPage_GetAnnot(FPDF_PAGE page,
CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(index));
auto pNewAnnot = pdfium::MakeUnique<CPDF_AnnotContext>(pDict, pPage, nullptr);
- return pNewAnnot.release();
+
+ // Caller takes ownership.
+ return FPDFAnnotationFromCPDFAnnotContext(pNewAnnot.release());
}
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetAnnotIndex(FPDF_PAGE page,
@@ -480,7 +445,8 @@ FPDFAnnot_GetObject(FPDF_ANNOTATION annot, int index) {
pAnnot->SetForm(pStream);
}
- return pAnnot->GetForm()->GetPageObjectByIndex(index);
+ return FPDFPageObjectFromCPDFPageObject(
+ pAnnot->GetForm()->GetPageObjectByIndex(index));
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
@@ -868,7 +834,9 @@ FPDFAnnot_GetLinkedAnnot(FPDF_ANNOTATION annot, FPDF_BYTESTRING key) {
auto pLinkedAnnot = pdfium::MakeUnique<CPDF_AnnotContext>(
pLinkedDict, pAnnot->GetPage(), nullptr);
- return pLinkedAnnot.release();
+
+ // Caller takes ownership.
+ return FPDFAnnotationFromCPDFAnnotContext(pLinkedAnnot.release());
}
FPDF_EXPORT int FPDF_CALLCONV FPDFAnnot_GetFlags(FPDF_ANNOTATION annot) {