summaryrefslogtreecommitdiff
path: root/fpdfsdk
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
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')
-rw-r--r--fpdfsdk/cpdf_annotcontext.cpp35
-rw-r--r--fpdfsdk/cpdf_annotcontext.h38
-rw-r--r--fpdfsdk/cpdfsdk_helpers.cpp8
-rw-r--r--fpdfsdk/cpdfsdk_helpers.h167
-rw-r--r--fpdfsdk/fpdf_annot.cpp56
-rw-r--r--fpdfsdk/fpdf_attachment.cpp9
-rw-r--r--fpdfsdk/fpdf_doc.cpp59
-rw-r--r--fpdfsdk/fpdf_doc_unittest.cpp27
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp8
-rw-r--r--fpdfsdk/fpdf_editimg.cpp27
-rw-r--r--fpdfsdk/fpdf_editpage.cpp16
-rw-r--r--fpdfsdk/fpdf_editpath.cpp17
-rw-r--r--fpdfsdk/fpdf_edittext.cpp21
-rw-r--r--fpdfsdk/fpdf_formfill.cpp2
-rw-r--r--fpdfsdk/fpdf_progressive.cpp2
-rw-r--r--fpdfsdk/fpdf_searchex.cpp7
-rw-r--r--fpdfsdk/fpdf_structtree.cpp48
-rw-r--r--fpdfsdk/fpdf_text.cpp32
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp8
-rw-r--r--fpdfsdk/fpdf_view.cpp40
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp3
21 files changed, 414 insertions, 216 deletions
diff --git a/fpdfsdk/cpdf_annotcontext.cpp b/fpdfsdk/cpdf_annotcontext.cpp
new file mode 100644
index 0000000000..d76d5d2f8c
--- /dev/null
+++ b/fpdfsdk/cpdf_annotcontext.cpp
@@ -0,0 +1,35 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "fpdfsdk/cpdf_annotcontext.h"
+
+#include "core/fpdfapi/page/cpdf_form.h"
+#include "core/fpdfapi/page/cpdf_page.h"
+#include "core/fpdfapi/parser/cpdf_dictionary.h"
+#include "core/fpdfapi/parser/cpdf_stream.h"
+#include "third_party/base/ptr_util.h"
+
+CPDF_AnnotContext::CPDF_AnnotContext(CPDF_Dictionary* pAnnotDict,
+ CPDF_Page* pPage,
+ CPDF_Stream* pStream)
+ : m_pAnnotDict(pAnnotDict), m_pPage(pPage) {
+ SetForm(pStream);
+}
+
+CPDF_AnnotContext::~CPDF_AnnotContext() = default;
+
+void CPDF_AnnotContext::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();
+}
diff --git a/fpdfsdk/cpdf_annotcontext.h b/fpdfsdk/cpdf_annotcontext.h
new file mode 100644
index 0000000000..38cc91e031
--- /dev/null
+++ b/fpdfsdk/cpdf_annotcontext.h
@@ -0,0 +1,38 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FPDFSDK_CPDF_ANNOTCONTEXT_H_
+#define FPDFSDK_CPDF_ANNOTCONTEXT_H_
+
+#include <memory>
+
+#include "core/fxcrt/unowned_ptr.h"
+
+class CPDF_Dictionary;
+class CPDF_Form;
+class CPDF_Page;
+class CPDF_Stream;
+
+class CPDF_AnnotContext {
+ public:
+ CPDF_AnnotContext(CPDF_Dictionary* pAnnotDict,
+ CPDF_Page* pPage,
+ CPDF_Stream* pStream);
+ ~CPDF_AnnotContext();
+
+ void SetForm(CPDF_Stream* pStream);
+ bool HasForm() const { return !!m_pAnnotForm; }
+ 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;
+};
+
+#endif // FPDFSDK_CPDF_ANNOTCONTEXT_H_
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index bffc6eb240..1b90497456 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -172,20 +172,12 @@ CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) {
#endif // PDF_ENABLE_XFA
}
-CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
- return static_cast<CPDF_PageObject*>(page_object);
-}
-
ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string) {
return WideString::FromUTF16LE(wide_string,
WideString::WStringLength(wide_string))
.UTF8Encode();
}
-CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) {
- return static_cast<CFX_DIBitmap*>(bitmap);
-}
-
void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) {
CPDF_Annot::Subtype nAnnotSubtype = pPDFAnnot->GetSubtype();
if (nAnnotSubtype == CPDF_Annot::Subtype::THREED) {
diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h
index 937ceed75e..0cd2617412 100644
--- a/fpdfsdk/cpdfsdk_helpers.h
+++ b/fpdfsdk/cpdfsdk_helpers.h
@@ -23,17 +23,28 @@
#endif
class CPDF_Annot;
+class CPDF_AnnotContext;
+class CPDF_ClipPath;
+class CPDF_ContentMarkItem;
+class CPDF_Object;
+class CPDF_Font;
+class CPDF_LinkExtract;
class CPDF_Page;
class CPDF_PageObject;
class CPDF_PageRenderContext;
class CPDF_PathObject;
class CPDF_Stream;
+class CPDF_StructElement;
+class CPDF_StructTree;
+class CPDF_TextPage;
+class CPDF_TextPageFind;
class IPDFSDK_PauseAdapter;
class FX_PATHPOINT;
#ifdef PDF_ENABLE_XFA
class CPDFXFA_Context;
class CPDFXFA_Page;
+class CXFA_FFWidget;
#endif // PDF_ENABLE_XFA
// Object types for public FPDF_ types; these correspond to next layer down
@@ -48,17 +59,161 @@ using UnderlyingPageType = CPDFXFA_Page;
// Conversions to/from underlying types.
UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page);
FPDF_PAGE FPDFPageFromUnderlying(UnderlyingPageType* page);
-
-// Conversions to/from FPDF_ types.
-CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc);
+CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page);
FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc);
+CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc);
+
+// Conversions to/from incomplete FPDF_ API types.
+inline FPDF_ACTION FPDFActionFromCPDFDictionary(CPDF_Dictionary* action) {
+ return reinterpret_cast<FPDF_ACTION>(action);
+}
+inline CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) {
+ return reinterpret_cast<CPDF_Dictionary*>(action);
+}
+
+inline FPDF_ANNOTATION FPDFAnnotationFromCPDFAnnotContext(
+ CPDF_AnnotContext* annot) {
+ return reinterpret_cast<FPDF_ANNOTATION>(annot);
+}
+inline CPDF_AnnotContext* CPDFAnnotContextFromFPDFAnnotation(
+ FPDF_ANNOTATION annot) {
+ return reinterpret_cast<CPDF_AnnotContext*>(annot);
+}
+
+inline FPDF_ATTACHMENT FPDFAttachmentFromCPDFObject(CPDF_Object* attachment) {
+ return reinterpret_cast<FPDF_ATTACHMENT>(attachment);
+}
+inline CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment) {
+ return reinterpret_cast<CPDF_Object*>(attachment);
+}
+
+inline FPDF_BITMAP FPDFBitmapFromCFXDIBitmap(CFX_DIBitmap* bitmap) {
+ return reinterpret_cast<FPDF_BITMAP>(bitmap);
+}
+inline CFX_DIBitmap* CFXDIBitmapFromFPDFBitmap(FPDF_BITMAP bitmap) {
+ return reinterpret_cast<CFX_DIBitmap*>(bitmap);
+}
+
+inline FPDF_BOOKMARK FPDFBookmarkFromCPDFDictionary(CPDF_Dictionary* bookmark) {
+ return reinterpret_cast<FPDF_BOOKMARK>(bookmark);
+}
+inline CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark) {
+ return reinterpret_cast<CPDF_Dictionary*>(bookmark);
+}
+
+inline FPDF_CLIPPATH FPDFClipPathFromCPDFClipPath(CPDF_ClipPath* path) {
+ return reinterpret_cast<FPDF_CLIPPATH>(path);
+}
+inline CPDF_ClipPath* CPDFClipPathFromFPDFClipPath(FPDF_CLIPPATH path) {
+ return reinterpret_cast<CPDF_ClipPath*>(path);
+}
+
+inline FPDF_DEST FPDFDestFromCPDFArray(CPDF_Array* dest) {
+ return reinterpret_cast<FPDF_DEST>(dest);
+}
+inline CPDF_Array* CPDFArrayFromFPDFDest(FPDF_DEST dest) {
+ return reinterpret_cast<CPDF_Array*>(dest);
+}
+
+inline FPDF_FONT FPDFFontFromCPDFFont(CPDF_Font* font) {
+ return reinterpret_cast<FPDF_FONT>(font);
+}
+inline CPDF_Font* CPDFFontFromFPDFFont(FPDF_FONT font) {
+ return reinterpret_cast<CPDF_Font*>(font);
+}
+
+inline FPDF_LINK FPDFLinkFromCPDFDictionary(CPDF_Dictionary* link) {
+ return reinterpret_cast<FPDF_LINK>(link);
+}
+inline CPDF_Dictionary* CPDFDictionaryFromFPDFLink(FPDF_LINK link) {
+ return reinterpret_cast<CPDF_Dictionary*>(link);
+}
+
+inline FPDF_PAGELINK FPDFPageLinkFromCPDFLinkExtract(CPDF_LinkExtract* link) {
+ return reinterpret_cast<FPDF_PAGELINK>(link);
+}
+inline CPDF_LinkExtract* CPDFLinkExtractFromFPDFPageLink(FPDF_PAGELINK link) {
+ return reinterpret_cast<CPDF_LinkExtract*>(link);
+}
+
+inline FPDF_PAGEOBJECT FPDFPageObjectFromCPDFPageObject(
+ CPDF_PageObject* page_object) {
+ return reinterpret_cast<FPDF_PAGEOBJECT>(page_object);
+}
+inline CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(
+ FPDF_PAGEOBJECT page_object) {
+ return reinterpret_cast<CPDF_PageObject*>(page_object);
+}
+
+inline FPDF_PAGEOBJECTMARK FPDFPageObjectMarkFromCPDFContentMarkItem(
+ const CPDF_ContentMarkItem* mark) {
+ return reinterpret_cast<FPDF_PAGEOBJECTMARK>(mark);
+}
+inline const CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark(
+ FPDF_PAGEOBJECTMARK mark) {
+ return reinterpret_cast<const CPDF_ContentMarkItem*>(mark);
+}
+
+inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(CPDF_Array* range) {
+ return reinterpret_cast<FPDF_PAGERANGE>(range);
+}
+inline CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) {
+ return reinterpret_cast<CPDF_Array*>(range);
+}
+
+inline FPDF_PATHSEGMENT FPDFPathSegmentFromFXPathPoint(
+ const FX_PATHPOINT* segment) {
+ return reinterpret_cast<FPDF_PATHSEGMENT>(segment);
+}
+inline const FX_PATHPOINT* FXPathPointFromFPDFPathSegment(
+ FPDF_PATHSEGMENT segment) {
+ return reinterpret_cast<const FX_PATHPOINT*>(segment);
+}
+
+inline FPDF_STRUCTTREE FPDFStructTreeFromCPDFStructTree(
+ CPDF_StructTree* struct_tree) {
+ return reinterpret_cast<FPDF_STRUCTTREE>(struct_tree);
+}
+inline CPDF_StructTree* CPDFStructTreeFromFPDFStructTree(
+ FPDF_STRUCTTREE struct_tree) {
+ return reinterpret_cast<CPDF_StructTree*>(struct_tree);
+}
+
+inline FPDF_STRUCTELEMENT FPDFStructElementFromCPDFStructElement(
+ CPDF_StructElement* struct_element) {
+ return reinterpret_cast<FPDF_STRUCTELEMENT>(struct_element);
+}
+inline CPDF_StructElement* CPDFStructElementFromFPDFStructElement(
+ FPDF_STRUCTELEMENT struct_element) {
+ return reinterpret_cast<CPDF_StructElement*>(struct_element);
+}
+
+inline FPDF_TEXTPAGE FPDFTextPageFromCPDFTextPage(CPDF_TextPage* page) {
+ return reinterpret_cast<FPDF_TEXTPAGE>(page);
+}
+inline CPDF_TextPage* CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE page) {
+ return reinterpret_cast<CPDF_TextPage*>(page);
+}
+
+inline FPDF_SCHHANDLE FPDFSchHandleFromCPDFTextPageFind(
+ CPDF_TextPageFind* handle) {
+ return reinterpret_cast<FPDF_SCHHANDLE>(handle);
+}
+inline CPDF_TextPageFind* CPDFTextPageFindFromFPDFSchHandle(
+ FPDF_SCHHANDLE handle) {
+ return reinterpret_cast<CPDF_TextPageFind*>(handle);
+}
-CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page);
-CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
-CFX_DIBitmap* CFXBitmapFromFPDFBitmap(FPDF_BITMAP bitmap);
#ifdef PDF_ENABLE_XFA
+inline FPDF_WIDGET FPDFWidgetFromCXFAFFWidget(CXFA_FFWidget* widget) {
+ return reinterpret_cast<FPDF_WIDGET>(widget);
+}
+inline CXFA_FFWidget* CXFAFFWidgetFromFPDFWidget(FPDF_WIDGET widget) {
+ return reinterpret_cast<CXFA_FFWidget*>(widget);
+}
+
// Layering prevents fxcrt from knowing about FPDF_FILEHANDLER, so this can't
// be a static method of IFX_SeekableStream.
RetainPtr<IFX_SeekableStream> MakeSeekableStream(
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) {
diff --git a/fpdfsdk/fpdf_attachment.cpp b/fpdfsdk/fpdf_attachment.cpp
index 25957174bc..f2ed684e40 100644
--- a/fpdfsdk/fpdf_attachment.cpp
+++ b/fpdfsdk/fpdf_attachment.cpp
@@ -26,10 +26,6 @@ namespace {
constexpr char kChecksumKey[] = "CheckSum";
-CPDF_Object* CPDFObjectFromFPDFAttachment(FPDF_ATTACHMENT attachment) {
- return static_cast<CPDF_Object*>(attachment);
-}
-
ByteString CFXByteStringHexDecode(const ByteString& bsHex) {
uint8_t* result = nullptr;
uint32_t size = 0;
@@ -101,7 +97,7 @@ FPDFDoc_AddAttachment(FPDF_DOCUMENT document, FPDF_WIDESTRING name) {
return nullptr;
}
- return pFile;
+ return FPDFAttachmentFromCPDFObject(pFile);
}
FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV
@@ -115,7 +111,8 @@ FPDFDoc_GetAttachment(FPDF_DOCUMENT document, int index) {
return nullptr;
WideString csName;
- return nameTree.LookupValueAndName(index, &csName);
+ return FPDFAttachmentFromCPDFObject(
+ nameTree.LookupValueAndName(index, &csName));
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp
index 54718a9409..17cfce0b24 100644
--- a/fpdfsdk/fpdf_doc.cpp
+++ b/fpdfsdk/fpdf_doc.cpp
@@ -61,22 +61,6 @@ CPDF_LinkList* GetLinkList(CPDF_Page* page) {
return pHolder->get();
}
-CPDF_Array* CPDFArrayFromDest(FPDF_DEST dest) {
- return static_cast<CPDF_Array*>(dest);
-}
-
-CPDF_Dictionary* CPDFDictionaryFromFPDFAction(FPDF_ACTION action) {
- return ToDictionary(static_cast<CPDF_Object*>(action));
-}
-
-CPDF_Dictionary* CPDFDictionaryFromFPDFBookmark(FPDF_BOOKMARK bookmark) {
- return ToDictionary(static_cast<CPDF_Object*>(bookmark));
-}
-
-CPDF_Dictionary* CPDFDictionaryFromFPDFLink(FPDF_LINK link) {
- return ToDictionary(static_cast<CPDF_Object*>(link));
-}
-
} // namespace
FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
@@ -86,19 +70,22 @@ FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
return nullptr;
CPDF_BookmarkTree tree(pDoc);
CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict));
- return tree.GetFirstChild(bookmark).GetDict();
+ return FPDFBookmarkFromCPDFDictionary(tree.GetFirstChild(bookmark).GetDict());
}
FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
if (!pDict)
return nullptr;
+
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
+
CPDF_BookmarkTree tree(pDoc);
CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict));
- return tree.GetNextSibling(bookmark).GetDict();
+ return FPDFBookmarkFromCPDFDictionary(
+ tree.GetNextSibling(bookmark).GetDict());
}
FPDF_EXPORT unsigned long FPDF_CALLCONV
@@ -121,7 +108,8 @@ FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) {
size_t len = WideString::WStringLength(title);
WideString encodedTitle = WideString::FromUTF16LE(title, len);
std::set<CPDF_Dictionary*> visited;
- return FindBookmark(tree, CPDF_Bookmark(), encodedTitle, &visited).GetDict();
+ return FPDFBookmarkFromCPDFDictionary(
+ FindBookmark(tree, CPDF_Bookmark(), encodedTitle, &visited).GetDict());
}
FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFBookmark_GetDest(FPDF_DOCUMENT document,
@@ -134,13 +122,13 @@ FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFBookmark_GetDest(FPDF_DOCUMENT document,
CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict));
CPDF_Dest dest = bookmark.GetDest(pDoc);
if (dest.GetObject())
- return dest.GetObject();
+ return FPDFDestFromCPDFArray(dest.GetObject());
// If this bookmark is not directly associated with a dest, we try to get
// action
CPDF_Action action = bookmark.GetAction();
if (!action.GetDict())
return nullptr;
- return action.GetDest(pDoc).GetObject();
+ return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetObject());
}
FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV
@@ -148,7 +136,7 @@ FPDFBookmark_GetAction(FPDF_BOOKMARK pDict) {
if (!pDict)
return nullptr;
CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict));
- return bookmark.GetAction().GetDict();
+ return FPDFActionFromCPDFDictionary(bookmark.GetAction().GetDict());
}
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetType(FPDF_ACTION pDict) {
@@ -179,7 +167,7 @@ FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFAction_GetDest(FPDF_DOCUMENT document,
if (!pDoc)
return nullptr;
CPDF_Action action(CPDFDictionaryFromFPDFAction(pDict));
- return action.GetDest(pDoc).GetObject();
+ return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetObject());
}
FPDF_EXPORT unsigned long FPDF_CALLCONV
@@ -223,7 +211,7 @@ FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FPDF_DEST dest) {
if (!pDoc)
return 0;
- CPDF_Dest destination(CPDFArrayFromDest(dest));
+ CPDF_Dest destination(CPDFArrayFromFPDFDest(dest));
return destination.GetPageIndexDeprecated(pDoc);
}
@@ -236,7 +224,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFDest_GetDestPageIndex(FPDF_DOCUMENT document,
if (!pDoc)
return -1;
- CPDF_Dest destination(CPDFArrayFromDest(dest));
+ CPDF_Dest destination(CPDFArrayFromFPDFDest(dest));
return destination.GetDestPageIndex(pDoc);
}
@@ -249,7 +237,7 @@ FPDFDest_GetView(FPDF_DEST pDict,
return 0;
}
- CPDF_Dest destination(CPDFArrayFromDest(pDict));
+ CPDF_Dest destination(CPDFArrayFromFPDFDest(pDict));
unsigned long nParams = destination.GetNumParams();
ASSERT(nParams <= 4);
*pNumParams = nParams;
@@ -269,7 +257,7 @@ FPDFDest_GetLocationInPage(FPDF_DEST pDict,
if (!pDict)
return false;
- auto dest = pdfium::MakeUnique<CPDF_Dest>(CPDFArrayFromDest(pDict));
+ auto dest = pdfium::MakeUnique<CPDF_Dest>(CPDFArrayFromFPDFDest(pDict));
// FPDF_BOOL is an int, GetXYZ expects bools.
bool bHasX;
@@ -295,11 +283,10 @@ FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFLink_GetLinkAtPoint(FPDF_PAGE page,
if (!pLinkList)
return nullptr;
- return pLinkList
- ->GetLinkAtPoint(pPage,
- CFX_PointF(static_cast<float>(x), static_cast<float>(y)),
- nullptr)
- .GetDict();
+ CPDF_Link link = pLinkList->GetLinkAtPoint(
+ pPage, CFX_PointF(static_cast<float>(x), static_cast<float>(y)), nullptr);
+
+ return FPDFLinkFromCPDFDictionary(link.GetDict());
}
FPDF_EXPORT int FPDF_CALLCONV FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page,
@@ -328,14 +315,14 @@ FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFLink_GetDest(FPDF_DOCUMENT document,
if (!pDoc)
return nullptr;
CPDF_Link link(CPDFDictionaryFromFPDFLink(pDict));
- FPDF_DEST dest = link.GetDest(pDoc).GetObject();
+ FPDF_DEST dest = FPDFDestFromCPDFArray(link.GetDest(pDoc).GetObject());
if (dest)
return dest;
// If this link is not directly associated with a dest, we try to get action
CPDF_Action action = link.GetAction();
if (!action.GetDict())
return nullptr;
- return action.GetDest(pDoc).GetObject();
+ return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetObject());
}
FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK pDict) {
@@ -343,7 +330,7 @@ FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK pDict) {
return nullptr;
CPDF_Link link(CPDFDictionaryFromFPDFLink(pDict));
- return link.GetAction().GetDict();
+ return FPDFActionFromCPDFDictionary(link.GetAction().GetDict());
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_Enumerate(FPDF_PAGE page,
@@ -363,7 +350,7 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_Enumerate(FPDF_PAGE page,
continue;
if (pDict->GetStringFor("Subtype") == "Link") {
*start_pos = static_cast<int>(i + 1);
- *link_annot = static_cast<FPDF_LINK>(pDict);
+ *link_annot = FPDFLinkFromCPDFDictionary(pDict);
return true;
}
}
diff --git a/fpdfsdk/fpdf_doc_unittest.cpp b/fpdfsdk/fpdf_doc_unittest.cpp
index 0f285a14c3..0234d47833 100644
--- a/fpdfsdk/fpdf_doc_unittest.cpp
+++ b/fpdfsdk/fpdf_doc_unittest.cpp
@@ -127,11 +127,13 @@ TEST_F(PDFDocTest, FindBookmark) {
// Title with a match.
title = GetFPDFWideString(L"Chapter 2");
- EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
+ EXPECT_EQ(FPDFBookmarkFromCPDFDictionary(bookmarks[2].obj),
+ FPDFBookmark_Find(m_pDoc.get(), title.get()));
// Title match is case insensitive.
title = GetFPDFWideString(L"cHaPter 2");
- EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
+ EXPECT_EQ(FPDFBookmarkFromCPDFDictionary(bookmarks[2].obj),
+ FPDFBookmark_Find(m_pDoc.get(), title.get()));
}
{
// Circular bookmarks in depth.
@@ -166,7 +168,8 @@ TEST_F(PDFDocTest, FindBookmark) {
// Title with a match.
title = GetFPDFWideString(L"Chapter 2");
- EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
+ EXPECT_EQ(FPDFBookmarkFromCPDFDictionary(bookmarks[2].obj),
+ FPDFBookmark_Find(m_pDoc.get(), title.get()));
}
{
// Circular bookmarks in breadth.
@@ -207,7 +210,8 @@ TEST_F(PDFDocTest, FindBookmark) {
// Title with a match.
title = GetFPDFWideString(L"Chapter 3");
- EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
+ EXPECT_EQ(FPDFBookmarkFromCPDFDictionary(bookmarks[3].obj),
+ FPDFBookmark_Find(m_pDoc.get(), title.get()));
}
}
@@ -226,8 +230,9 @@ TEST_F(PDFDocTest, GetLocationInPage) {
FS_FLOAT y;
FS_FLOAT zoom;
- EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
- &x, &y, &zoom));
+ EXPECT_TRUE(FPDFDest_GetLocationInPage(FPDFDestFromCPDFArray(array.get()),
+ &hasX, &hasY, &hasZoom, &x, &y,
+ &zoom));
EXPECT_TRUE(hasX);
EXPECT_TRUE(hasY);
EXPECT_TRUE(hasZoom);
@@ -238,13 +243,15 @@ TEST_F(PDFDocTest, GetLocationInPage) {
array->SetNewAt<CPDF_Null>(2);
array->SetNewAt<CPDF_Null>(3);
array->SetNewAt<CPDF_Null>(4);
- EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
- &x, &y, &zoom));
+ EXPECT_TRUE(FPDFDest_GetLocationInPage(FPDFDestFromCPDFArray(array.get()),
+ &hasX, &hasY, &hasZoom, &x, &y,
+ &zoom));
EXPECT_FALSE(hasX);
EXPECT_FALSE(hasY);
EXPECT_FALSE(hasZoom);
array = pdfium::MakeUnique<CPDF_Array>();
- EXPECT_FALSE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
- &x, &y, &zoom));
+ EXPECT_FALSE(FPDFDest_GetLocationInPage(FPDFDestFromCPDFArray(array.get()),
+ &hasX, &hasY, &hasZoom, &x, &y,
+ &zoom));
}
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 0604cdbe71..a20faeba80 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -995,7 +995,7 @@ TEST_F(FPDFEditEmbeddertest, LoadSimpleType1Font) {
ScopedFPDFFont font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TYPE1, false));
ASSERT_TRUE(font.get());
- CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get());
+ CPDF_Font* typed_font = CPDFFontFromFPDFFont(font.get());
EXPECT_TRUE(typed_font->IsType1Font());
CPDF_Dictionary* font_dict = typed_font->GetFontDict();
@@ -1024,7 +1024,7 @@ TEST_F(FPDFEditEmbeddertest, LoadSimpleTrueTypeFont) {
ScopedFPDFFont font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, false));
ASSERT_TRUE(font.get());
- CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get());
+ CPDF_Font* typed_font = CPDFFontFromFPDFFont(font.get());
EXPECT_TRUE(typed_font->IsTrueTypeFont());
CPDF_Dictionary* font_dict = typed_font->GetFontDict();
@@ -1054,7 +1054,7 @@ TEST_F(FPDFEditEmbeddertest, LoadCIDType0Font) {
ScopedFPDFFont font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TYPE1, 1));
ASSERT_TRUE(font.get());
- CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get());
+ CPDF_Font* typed_font = CPDFFontFromFPDFFont(font.get());
EXPECT_TRUE(typed_font->IsCIDFont());
// Check font dictionary entries
@@ -1096,7 +1096,7 @@ TEST_F(FPDFEditEmbeddertest, LoadCIDType2Font) {
ScopedFPDFFont font(
FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 1));
ASSERT_TRUE(font.get());
- CPDF_Font* typed_font = static_cast<CPDF_Font*>(font.get());
+ CPDF_Font* typed_font = CPDFFontFromFPDFFont(font.get());
EXPECT_TRUE(typed_font->IsCIDFont());
// Check font dictionary entries
diff --git a/fpdfsdk/fpdf_editimg.cpp b/fpdfsdk/fpdf_editimg.cpp
index f1d90ece2d..9485a75002 100644
--- a/fpdfsdk/fpdf_editimg.cpp
+++ b/fpdfsdk/fpdf_editimg.cpp
@@ -57,8 +57,10 @@ bool LoadJpegHelper(FPDF_PAGE* pages,
if (!image_object || !fileAccess)
return false;
- RetainPtr<IFX_SeekableReadStream> pFile = MakeSeekableReadStream(fileAccess);
- CPDF_ImageObject* pImgObj = static_cast<CPDF_ImageObject*>(image_object);
+ CPDF_ImageObject* pImgObj =
+ CPDFPageObjectFromFPDFPageObject(image_object)->AsImage();
+ if (!pImgObj)
+ return false;
if (pages) {
for (int index = 0; index < nCount; index++) {
@@ -68,6 +70,7 @@ bool LoadJpegHelper(FPDF_PAGE* pages,
}
}
+ RetainPtr<IFX_SeekableReadStream> pFile = MakeSeekableReadStream(fileAccess);
if (inlineJpeg)
pImgObj->GetImage()->SetJpegImageInline(pFile);
else
@@ -86,7 +89,9 @@ FPDFPageObj_NewImageObj(FPDF_DOCUMENT document) {
auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>();
pImageObj->SetImage(pdfium::MakeRetain<CPDF_Image>(pDoc));
- return pImageObj.release();
+
+ // Caller takes ownership.
+ return FPDFPageObjectFromCPDFPageObject(pImageObj.release());
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
@@ -116,7 +121,11 @@ FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
if (!image_object)
return false;
- CPDF_ImageObject* pImgObj = static_cast<CPDF_ImageObject*>(image_object);
+ CPDF_ImageObject* pImgObj =
+ CPDFPageObjectFromFPDFPageObject(image_object)->AsImage();
+ if (!pImgObj)
+ return false;
+
pImgObj->set_matrix(CFX_Matrix(static_cast<float>(a), static_cast<float>(b),
static_cast<float>(c), static_cast<float>(d),
static_cast<float>(e), static_cast<float>(f)));
@@ -133,13 +142,17 @@ FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
if (!image_object || !bitmap || !pages)
return false;
- CPDF_ImageObject* pImgObj = static_cast<CPDF_ImageObject*>(image_object);
+ CPDF_ImageObject* pImgObj =
+ CPDFPageObjectFromFPDFPageObject(image_object)->AsImage();
+ if (!pImgObj)
+ return false;
+
for (int index = 0; index < nCount; index++) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
if (pPage)
pImgObj->GetImage()->ResetCache(pPage, nullptr);
}
- RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap));
+ RetainPtr<CFX_DIBitmap> holder(CFXDIBitmapFromFPDFBitmap(bitmap));
pImgObj->GetImage()->SetImage(holder);
pImgObj->CalcBoundingBox();
pImgObj->SetDirty(true);
@@ -170,7 +183,7 @@ FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object) {
else
pBitmap = pSource->Clone(nullptr);
- return pBitmap.Leak();
+ return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
}
FPDF_EXPORT unsigned long FPDF_CALLCONV
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index 944dbdc576..0647dc537f 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -54,11 +54,6 @@ static_assert(FPDF_PAGEOBJ_SHADING == CPDF_PageObject::SHADING,
static_assert(FPDF_PAGEOBJ_FORM == CPDF_PageObject::FORM,
"FPDF_PAGEOBJ_FORM/CPDF_PageObject::FORM mismatch");
-const CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark(
- FPDF_PAGEOBJECTMARK mark) {
- return static_cast<const CPDF_ContentMarkItem*>(mark);
-}
-
bool IsPageObject(CPDF_Page* pPage) {
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type"))
return false;
@@ -251,7 +246,7 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPage_GetObject(FPDF_PAGE page,
if (!IsPageObject(pPage))
return nullptr;
- return pPage->GetPageObjectByIndex(index);
+ return FPDFPageObjectFromCPDFPageObject(pPage->GetPageObjectByIndex(index));
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_HasTransparency(FPDF_PAGE page) {
@@ -278,15 +273,14 @@ FPDFPageObj_GetMark(FPDF_PAGEOBJECT page_object, unsigned long index) {
if (!page_object)
return nullptr;
- const auto& mark =
- CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMark;
- if (!mark.HasRef())
+ auto* mark = &CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMark;
+ if (!mark->HasRef())
return nullptr;
- if (index >= mark.CountItems())
+ if (index >= mark->CountItems())
return nullptr;
- return static_cast<FPDF_PAGEOBJECTMARK>(&mark.GetItem(index));
+ return FPDFPageObjectMarkFromCPDFContentMarkItem(&mark->GetItem(index));
}
FPDF_EXPORT unsigned long FPDF_CALLCONV
diff --git a/fpdfsdk/fpdf_editpath.cpp b/fpdfsdk/fpdf_editpath.cpp
index 82c7ca13ef..aca2bebf81 100644
--- a/fpdfsdk/fpdf_editpath.cpp
+++ b/fpdfsdk/fpdf_editpath.cpp
@@ -42,10 +42,6 @@ CPDF_PathObject* CPDFPathObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
return obj ? obj->AsPath() : nullptr;
}
-const FX_PATHPOINT* FXPathPointFromFPDFPathSegment(FPDF_PATHSEGMENT segment) {
- return static_cast<const FX_PATHPOINT*>(segment);
-}
-
unsigned int GetAlphaAsUnsignedInt(float alpha) {
return static_cast<unsigned int>(alpha * 255.f + 0.5f);
}
@@ -57,7 +53,9 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewPath(float x,
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
pPathObj->m_Path.AppendPoint(CFX_PointF(x, y), FXPT_TYPE::MoveTo, false);
pPathObj->DefaultStates();
- return pPathObj.release(); // Caller takes ownership.
+
+ // Caller takes ownership.
+ return FPDFPageObjectFromCPDFPageObject(pPathObj.release());
}
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x,
@@ -67,7 +65,9 @@ FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x,
auto pPathObj = pdfium::MakeUnique<CPDF_PathObject>();
pPathObj->m_Path.AppendRect(x, y, x + w, y + h);
pPathObj->DefaultStates();
- return pPathObj.release(); // Caller takes ownership.
+
+ // Caller takes ownership.
+ return FPDFPageObjectFromCPDFPageObject(pPathObj.release());
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
@@ -156,7 +156,10 @@ FPDFPath_GetPathSegment(FPDF_PAGEOBJECT path, int index) {
return nullptr;
const std::vector<FX_PATHPOINT>& points = pPathObj->m_Path.GetPoints();
- return pdfium::IndexInBounds(points, index) ? &points[index] : nullptr;
+ if (!pdfium::IndexInBounds(points, index))
+ return nullptr;
+
+ return FPDFPathSegmentFromFXPathPoint(&points[index]);
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_MoveTo(FPDF_PAGEOBJECT path,
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 648d1dd5d5..2996a505ee 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -416,12 +416,18 @@ FPDFPageObj_NewTextObj(FPDF_DOCUMENT document,
pTextObj->m_TextState.SetFont(pFont);
pTextObj->m_TextState.SetFontSize(font_size);
pTextObj->DefaultStates();
- return pTextObj.release(); // Caller takes ownership.
+
+ // Caller takes ownership.
+ return FPDFPageObjectFromCPDFPageObject(pTextObj.release());
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFText_SetText(FPDF_PAGEOBJECT text_object, FPDF_WIDESTRING text) {
- auto* pTextObj = static_cast<CPDF_TextObject*>(text_object);
+ if (!text_object)
+ return false;
+
+ CPDF_TextObject* pTextObj =
+ CPDFPageObjectFromFPDFPageObject(text_object)->AsText();
if (!pTextObj)
return false;
@@ -455,8 +461,9 @@ FPDF_EXPORT FPDF_FONT FPDF_CALLCONV FPDFText_LoadFont(FPDF_DOCUMENT document,
if (!pFont->LoadEmbedded(data, size))
return nullptr;
- return cid ? LoadCompositeFont(pDoc, std::move(pFont), data, size, font_type)
- : LoadSimpleFont(pDoc, std::move(pFont), data, size, font_type);
+ return FPDFFontFromCPDFFont(
+ cid ? LoadCompositeFont(pDoc, std::move(pFont), data, size, font_type)
+ : LoadSimpleFont(pDoc, std::move(pFont), data, size, font_type));
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
@@ -469,7 +476,7 @@ FPDFText_SetFillColor(FPDF_PAGEOBJECT text_object,
}
FPDF_EXPORT void FPDF_CALLCONV FPDFFont_Close(FPDF_FONT font) {
- CPDF_Font* pFont = static_cast<CPDF_Font*>(font);
+ CPDF_Font* pFont = CPDFFontFromFPDFFont(font);
if (!pFont)
return;
@@ -487,7 +494,7 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
FPDF_FONT font,
float font_size) {
CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
- CPDF_Font* pFont = static_cast<CPDF_Font*>(font);
+ CPDF_Font* pFont = CPDFFontFromFPDFFont(font);
if (!pDoc || !pFont)
return nullptr;
@@ -495,5 +502,5 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
pTextObj->m_TextState.SetFont(pDoc->LoadFont(pFont->GetFontDict()));
pTextObj->m_TextState.SetFontSize(font_size);
pTextObj->DefaultStates();
- return pTextObj.release();
+ return FPDFPageObjectFromCPDFPageObject(pTextObj.release());
}
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index b99bd5f40d..280ef62edb 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -157,7 +157,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle,
#ifdef _SKIA_SUPPORT_
pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder));
#endif
- RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap));
+ RetainPtr<CFX_DIBitmap> holder(CFXDIBitmapFromFPDFBitmap(bitmap));
pDevice->Attach(holder, false, nullptr, false);
{
CFX_RenderDevice::StateRestorer restorer(pDevice.get());
diff --git a/fpdfsdk/fpdf_progressive.cpp b/fpdfsdk/fpdf_progressive.cpp
index 6ac6686ac8..6d16bce700 100644
--- a/fpdfsdk/fpdf_progressive.cpp
+++ b/fpdfsdk/fpdf_progressive.cpp
@@ -50,7 +50,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap,
CPDF_PageRenderContext* pContext = pOwnedContext.get();
pPage->SetRenderContext(std::move(pOwnedContext));
- RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
+ RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
auto pOwnedDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>();
CFX_DefaultRenderDevice* pDevice = pOwnedDevice.get();
pContext->m_pDevice = std::move(pOwnedDevice);
diff --git a/fpdfsdk/fpdf_searchex.cpp b/fpdfsdk/fpdf_searchex.cpp
index 9d48cebf8a..dbc2d2abcd 100644
--- a/fpdfsdk/fpdf_searchex.cpp
+++ b/fpdfsdk/fpdf_searchex.cpp
@@ -7,19 +7,20 @@
#include "public/fpdf_searchex.h"
#include "core/fpdftext/cpdf_textpage.h"
+#include "fpdfsdk/cpdfsdk_helpers.h"
FPDF_EXPORT int FPDF_CALLCONV
FPDFText_GetCharIndexFromTextIndex(FPDF_TEXTPAGE text_page, int nTextIndex) {
if (!text_page)
return -1;
- return static_cast<CPDF_TextPage*>(text_page)
- ->CharIndexFromTextIndex(nTextIndex);
+ return CPDFTextPageFromFPDFTextPage(text_page)->CharIndexFromTextIndex(
+ nTextIndex);
}
FPDF_EXPORT int FPDF_CALLCONV
FPDFText_GetTextIndexFromCharIndex(FPDF_TEXTPAGE text_page, int nCharIndex) {
if (!text_page)
return -1;
- return static_cast<CPDF_TextPage*>(text_page)->TextIndexFromCharIndex(
+ return CPDFTextPageFromFPDFTextPage(text_page)->TextIndexFromCharIndex(
nCharIndex);
}
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp
index 98123d94d1..027695e36d 100644
--- a/fpdfsdk/fpdf_structtree.cpp
+++ b/fpdfsdk/fpdf_structtree.cpp
@@ -14,14 +14,6 @@
namespace {
-CPDF_StructTree* ToStructTree(FPDF_STRUCTTREE struct_tree) {
- return static_cast<CPDF_StructTree*>(struct_tree);
-}
-
-CPDF_StructElement* ToStructTreeElement(FPDF_STRUCTELEMENT struct_element) {
- return static_cast<CPDF_StructElement*>(struct_element);
-}
-
unsigned long WideStringToBuffer(const WideString& str,
void* buffer,
unsigned long buflen) {
@@ -42,19 +34,23 @@ FPDF_StructTree_GetForPage(FPDF_PAGE page) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return nullptr;
- return CPDF_StructTree::LoadPage(pPage->m_pDocument.Get(),
- pPage->m_pFormDict.Get())
- .release();
+
+ // Caller takes onwership.
+ return FPDFStructTreeFromCPDFStructTree(
+ CPDF_StructTree::LoadPage(pPage->m_pDocument.Get(),
+ pPage->m_pFormDict.Get())
+ .release());
}
FPDF_EXPORT void FPDF_CALLCONV
FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree) {
- std::unique_ptr<CPDF_StructTree>(ToStructTree(struct_tree));
+ std::unique_ptr<CPDF_StructTree>(
+ CPDFStructTreeFromFPDFStructTree(struct_tree));
}
FPDF_EXPORT int FPDF_CALLCONV
FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) {
- CPDF_StructTree* tree = ToStructTree(struct_tree);
+ CPDF_StructTree* tree = CPDFStructTreeFromFPDFStructTree(struct_tree);
if (!tree)
return -1;
@@ -64,19 +60,21 @@ FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) {
FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV
FPDF_StructTree_GetChildAtIndex(FPDF_STRUCTTREE struct_tree, int index) {
- CPDF_StructTree* tree = ToStructTree(struct_tree);
+ CPDF_StructTree* tree = CPDFStructTreeFromFPDFStructTree(struct_tree);
if (!tree || index < 0 ||
static_cast<size_t>(index) >= tree->CountTopElements()) {
return nullptr;
}
- return tree->GetTopElement(static_cast<size_t>(index));
+ return FPDFStructElementFromCPDFStructElement(
+ tree->GetTopElement(static_cast<size_t>(index)));
}
FPDF_EXPORT unsigned long FPDF_CALLCONV
FPDF_StructElement_GetAltText(FPDF_STRUCTELEMENT struct_element,
void* buffer,
unsigned long buflen) {
- CPDF_StructElement* elem = ToStructTreeElement(struct_element);
+ CPDF_StructElement* elem =
+ CPDFStructElementFromFPDFStructElement(struct_element);
return (elem && elem->GetDict())
? WideStringToBuffer(elem->GetDict()->GetUnicodeTextFor("Alt"),
buffer, buflen)
@@ -85,7 +83,8 @@ FPDF_StructElement_GetAltText(FPDF_STRUCTELEMENT struct_element,
FPDF_EXPORT int FPDF_CALLCONV
FPDF_StructElement_GetMarkedContentID(FPDF_STRUCTELEMENT struct_element) {
- CPDF_StructElement* elem = ToStructTreeElement(struct_element);
+ CPDF_StructElement* elem =
+ CPDFStructElementFromFPDFStructElement(struct_element);
CPDF_Object* p =
(elem && elem->GetDict()) ? elem->GetDict()->GetObjectFor("K") : nullptr;
return p && p->IsNumber() ? p->GetInteger() : -1;
@@ -95,7 +94,8 @@ FPDF_EXPORT unsigned long FPDF_CALLCONV
FPDF_StructElement_GetType(FPDF_STRUCTELEMENT struct_element,
void* buffer,
unsigned long buflen) {
- CPDF_StructElement* elem = ToStructTreeElement(struct_element);
+ CPDF_StructElement* elem =
+ CPDFStructElementFromFPDFStructElement(struct_element);
return elem ? WideStringToBuffer(elem->GetType().UTF8Decode(), buffer, buflen)
: 0;
}
@@ -104,7 +104,8 @@ FPDF_EXPORT unsigned long FPDF_CALLCONV
FPDF_StructElement_GetTitle(FPDF_STRUCTELEMENT struct_element,
void* buffer,
unsigned long buflen) {
- CPDF_StructElement* elem = ToStructTreeElement(struct_element);
+ CPDF_StructElement* elem =
+ CPDFStructElementFromFPDFStructElement(struct_element);
return elem
? WideStringToBuffer(elem->GetTitle().UTF8Decode(), buffer, buflen)
: 0;
@@ -112,7 +113,8 @@ FPDF_StructElement_GetTitle(FPDF_STRUCTELEMENT struct_element,
FPDF_EXPORT int FPDF_CALLCONV
FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element) {
- CPDF_StructElement* elem = ToStructTreeElement(struct_element);
+ CPDF_StructElement* elem =
+ CPDFStructElementFromFPDFStructElement(struct_element);
if (!elem)
return -1;
@@ -123,9 +125,11 @@ FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element) {
FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV
FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element,
int index) {
- CPDF_StructElement* elem = ToStructTreeElement(struct_element);
+ CPDF_StructElement* elem =
+ CPDFStructElementFromFPDFStructElement(struct_element);
if (!elem || index < 0 || static_cast<size_t>(index) >= elem->CountKids())
return nullptr;
- return elem->GetKidIfElement(static_cast<size_t>(index));
+ return FPDFStructElementFromCPDFStructElement(
+ elem->GetKidIfElement(static_cast<size_t>(index)));
}
diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp
index c06885a1a7..edca0669ab 100644
--- a/fpdfsdk/fpdf_text.cpp
+++ b/fpdfsdk/fpdf_text.cpp
@@ -7,6 +7,7 @@
#include "public/fpdf_text.h"
#include <algorithm>
+#include <memory>
#include <vector>
#include "core/fpdfapi/page/cpdf_page.h"
@@ -16,6 +17,7 @@
#include "core/fpdftext/cpdf_textpagefind.h"
#include "fpdfsdk/cpdfsdk_helpers.h"
#include "third_party/base/numerics/safe_conversions.h"
+#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
#ifdef PDF_ENABLE_XFA
@@ -31,18 +33,6 @@ namespace {
constexpr size_t kBytesPerCharacter = sizeof(unsigned short);
-CPDF_TextPage* CPDFTextPageFromFPDFTextPage(FPDF_TEXTPAGE text_page) {
- return static_cast<CPDF_TextPage*>(text_page);
-}
-
-CPDF_TextPageFind* CPDFTextPageFindFromFPDFSchHandle(FPDF_SCHHANDLE handle) {
- return static_cast<CPDF_TextPageFind*>(handle);
-}
-
-CPDF_LinkExtract* CPDFLinkExtractFromFPDFPageLink(FPDF_PAGELINK link) {
- return static_cast<CPDF_LinkExtract*>(link);
-}
-
} // namespace
FPDF_EXPORT FPDF_TEXTPAGE FPDF_CALLCONV FPDFText_LoadPage(FPDF_PAGE page) {
@@ -62,7 +52,7 @@ FPDF_EXPORT FPDF_TEXTPAGE FPDF_CALLCONV FPDFText_LoadPage(FPDF_PAGE page) {
pPDFPage, viewRef.IsDirectionR2L() ? FPDFText_Direction::Right
: FPDFText_Direction::Left);
textpage->ParseTextPage();
- return textpage;
+ return FPDFTextPageFromCPDFTextPage(textpage);
}
FPDF_EXPORT void FPDF_CALLCONV FPDFText_ClosePage(FPDF_TEXTPAGE text_page) {
@@ -269,7 +259,7 @@ FPDFText_FindStart(FPDF_TEXTPAGE text_page,
textpageFind->FindFirst(
WideString::FromUTF16LE(findwhat, len), flags,
start_index >= 0 ? Optional<size_t>(start_index) : Optional<size_t>());
- return textpageFind;
+ return FPDFSchHandleFromCPDFTextPageFind(textpageFind);
}
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_FindNext(FPDF_SCHHANDLE handle) {
@@ -309,9 +299,9 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFText_FindClose(FPDF_SCHHANDLE handle) {
if (!handle)
return;
- CPDF_TextPageFind* textpageFind = CPDFTextPageFindFromFPDFSchHandle(handle);
- delete textpageFind;
- handle = nullptr;
+ // Take ownership back from caller and destroy.
+ std::unique_ptr<CPDF_TextPageFind> textpageFind(
+ CPDFTextPageFindFromFPDFSchHandle(handle));
}
// web link
@@ -320,10 +310,12 @@ FPDFLink_LoadWebLinks(FPDF_TEXTPAGE text_page) {
if (!text_page)
return nullptr;
- CPDF_LinkExtract* pageLink =
- new CPDF_LinkExtract(CPDFTextPageFromFPDFTextPage(text_page));
+ CPDF_TextPage* pPage = CPDFTextPageFromFPDFTextPage(text_page);
+ auto pageLink = pdfium::MakeUnique<CPDF_LinkExtract>(pPage);
pageLink->ExtractLinks();
- return pageLink;
+
+ // Caller takes ownership.
+ return FPDFPageLinkFromCPDFLinkExtract(pageLink.release());
}
FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountWebLinks(FPDF_PAGELINK link_page) {
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index d2d9f8dbc4..6706a18354 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -211,12 +211,14 @@ FPDF_EXPORT FPDF_CLIPPATH FPDF_CALLCONV FPDF_CreateClipPath(float left,
auto pNewClipPath = pdfium::MakeUnique<CPDF_ClipPath>();
pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, false);
- return pNewClipPath.release(); // Caller takes ownership.
+
+ // Caller takes ownership.
+ return FPDFClipPathFromCPDFClipPath(pNewClipPath.release());
}
FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath) {
// Take ownership back from caller and destroy.
- std::unique_ptr<CPDF_ClipPath>(static_cast<CPDF_ClipPath*>(clipPath));
+ std::unique_ptr<CPDF_ClipPath>(CPDFClipPathFromFPDFClipPath(clipPath));
}
void OutputPath(std::ostringstream& buf, CPDF_Path path) {
@@ -268,7 +270,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page,
return;
std::ostringstream strClip;
- auto* pClipPath = static_cast<CPDF_ClipPath*>(clipPath);
+ CPDF_ClipPath* pClipPath = CPDFClipPathFromFPDFClipPath(clipPath);
for (size_t i = 0; i < pClipPath->GetPathCount(); ++i) {
CPDF_Path path = pClipPath->GetPath(i);
if (path.GetPoints().empty()) {
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index ea12bf9896..a31118ff10 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -648,7 +648,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
CFX_DefaultRenderDevice* pDevice = new CFX_DefaultRenderDevice;
pContext->m_pDevice.reset(pDevice);
- RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
+ RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
rotate, flags, true, nullptr);
@@ -673,13 +673,15 @@ FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
if (!pPage)
return;
- CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
- pPage->SetRenderContext(pdfium::WrapUnique(pContext));
+ auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>();
+ CPDF_PageRenderContext* pContext = pOwnedContext.get();
+ pPage->SetRenderContext(std::move(pOwnedContext));
- CFX_DefaultRenderDevice* pDevice = new CFX_DefaultRenderDevice;
- pContext->m_pDevice.reset(pDevice);
+ auto pOwnedDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>();
+ CFX_DefaultRenderDevice* pDevice = pOwnedDevice.get();
+ pContext->m_pDevice = std::move(pOwnedDevice);
- RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
+ RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
CFX_FloatRect clipping_rect;
@@ -689,7 +691,6 @@ FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
const FX_RECT rect(0, 0, pPage->GetPageWidth(), pPage->GetPageHeight());
CFX_Matrix transform_matrix = pPage->GetDisplayMatrix(rect, 0);
-
if (matrix) {
transform_matrix.Concat(CFX_Matrix(matrix->a, matrix->b, matrix->c,
matrix->d, matrix->e, matrix->f));
@@ -828,7 +829,7 @@ FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_Create(int width,
if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32))
return nullptr;
- return pBitmap.Leak();
+ return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
}
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width,
@@ -858,14 +859,14 @@ FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width,
static_cast<uint8_t*>(first_scan), stride)) {
return nullptr;
}
- return pBitmap.Leak();
+ return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
}
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetFormat(FPDF_BITMAP bitmap) {
if (!bitmap)
return FPDFBitmap_Unknown;
- FXDIB_Format format = CFXBitmapFromFPDFBitmap(bitmap)->GetFormat();
+ FXDIB_Format format = CFXDIBitmapFromFPDFBitmap(bitmap)->GetFormat();
switch (format) {
case FXDIB_8bppRgb:
case FXDIB_8bppMask:
@@ -891,7 +892,7 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
return;
CFX_DefaultRenderDevice device;
- RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
+ RetainPtr<CFX_DIBitmap> pBitmap(CFXDIBitmapFromFPDFBitmap(bitmap));
device.Attach(pBitmap, false, nullptr, false);
if (!pBitmap->HasAlpha())
color |= 0xFF000000;
@@ -899,24 +900,24 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
}
FPDF_EXPORT void* FPDF_CALLCONV FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap) {
- return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetBuffer() : nullptr;
+ return bitmap ? CFXDIBitmapFromFPDFBitmap(bitmap)->GetBuffer() : nullptr;
}
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetWidth(FPDF_BITMAP bitmap) {
- return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetWidth() : 0;
+ return bitmap ? CFXDIBitmapFromFPDFBitmap(bitmap)->GetWidth() : 0;
}
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetHeight(FPDF_BITMAP bitmap) {
- return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetHeight() : 0;
+ return bitmap ? CFXDIBitmapFromFPDFBitmap(bitmap)->GetHeight() : 0;
}
FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetStride(FPDF_BITMAP bitmap) {
- return bitmap ? CFXBitmapFromFPDFBitmap(bitmap)->GetPitch() : 0;
+ return bitmap ? CFXDIBitmapFromFPDFBitmap(bitmap)->GetPitch() : 0;
}
FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_Destroy(FPDF_BITMAP bitmap) {
RetainPtr<CFX_DIBitmap> destroyer;
- destroyer.Unleak(CFXBitmapFromFPDFBitmap(bitmap));
+ destroyer.Unleak(CFXDIBitmapFromFPDFBitmap(bitmap));
}
void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext,
@@ -996,7 +997,7 @@ FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
if (!pDoc)
return nullptr;
CPDF_ViewerPreferences viewRef(pDoc);
- return viewRef.PrintPageRange();
+ return FPDFPageRangeFromCPDFArray(viewRef.PrintPageRange());
}
FPDF_EXPORT FPDF_DUPLEXTYPE FPDF_CALLCONV
@@ -1067,7 +1068,8 @@ FPDF_GetNamedDestByName(FPDF_DOCUMENT document, FPDF_BYTESTRING name) {
return nullptr;
CPDF_NameTree name_tree(pDoc, "Dests");
- return name_tree.LookupNamedDest(pDoc, PDF_DecodeText(ByteString(name)));
+ return FPDFDestFromCPDFArray(
+ name_tree.LookupNamedDest(pDoc, PDF_DecodeText(ByteString(name))));
}
#ifdef PDF_ENABLE_XFA
@@ -1186,5 +1188,5 @@ FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDF_GetNamedDest(FPDF_DOCUMENT document,
} else {
*buflen = -1;
}
- return pDestObj;
+ return FPDFDestFromCPDFArray(pDestObj->AsArray());
}
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index dc6686548b..cc7a8898e8 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -266,7 +266,8 @@ bool CPDFXFA_DocEnvironment::PopupMenu(CXFA_FFWidget* hWidget,
if (hWidget->CanSelectAll())
menuFlag |= FXFA_MENU_SELECTALL;
- return pFormFillEnv->PopupMenu(pPage.Get(), hWidget, menuFlag, ptPopup);
+ return pFormFillEnv->PopupMenu(
+ pPage.Get(), FPDFWidgetFromCXFAFFWidget(hWidget), menuFlag, ptPopup);
}
void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView,