From 00d47a60e4cd0974771692a9d3fdd3ca28bf6eb2 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 28 Mar 2018 18:39:04 +0000 Subject: Rename some fsdk files to cpdfsdk This CL renames fsdk_common and fsdk_define to cpdfsdk_common and cpdfsdk_helpers respectively. Change-Id: I8ee7a308561f1ff2f510954444f953b0c8fed788 Reviewed-on: https://pdfium-review.googlesource.com/29371 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- BUILD.gn | 6 +- core/fxge/skia/fx_skia_device_unittest.cpp | 2 +- fpdfsdk/cpdfsdk_annot.h | 4 +- fpdfsdk/cpdfsdk_common.h | 28 ++ fpdfsdk/cpdfsdk_formfillenvironment.h | 2 +- fpdfsdk/cpdfsdk_helpers.cpp | 462 ++++++++++++++++++++++++ fpdfsdk/cpdfsdk_helpers.h | 113 ++++++ fpdfsdk/cpdfsdk_interform.cpp | 2 +- fpdfsdk/cpdfsdk_widget.cpp | 2 +- fpdfsdk/formfiller/cffl_combobox.cpp | 2 +- fpdfsdk/formfiller/cffl_formfiller.cpp | 2 +- fpdfsdk/formfiller/cffl_interactiveformfiller.h | 2 +- fpdfsdk/formfiller/cffl_listbox.cpp | 2 +- fpdfsdk/formfiller/cffl_textfield.cpp | 2 +- fpdfsdk/fpdf_dataavail.cpp | 2 +- fpdfsdk/fpdf_ext.cpp | 2 +- fpdfsdk/fpdf_flatten.cpp | 2 +- fpdfsdk/fpdf_ppo.cpp | 2 +- fpdfsdk/fpdf_progressive.cpp | 2 +- fpdfsdk/fpdf_structtree.cpp | 2 +- fpdfsdk/fpdf_sysfontinfo.cpp | 2 +- fpdfsdk/fpdf_transformpage.cpp | 2 +- fpdfsdk/fpdfannot.cpp | 2 +- fpdfsdk/fpdfattachment.cpp | 2 +- fpdfsdk/fpdfcatalog.cpp | 2 +- fpdfsdk/fpdfdoc.cpp | 2 +- fpdfsdk/fpdfedit_embeddertest.cpp | 2 +- fpdfsdk/fpdfeditimg.cpp | 2 +- fpdfsdk/fpdfeditpage.cpp | 2 +- fpdfsdk/fpdfeditpath.cpp | 2 +- fpdfsdk/fpdfedittext.cpp | 2 +- fpdfsdk/fpdfformfill.cpp | 2 +- fpdfsdk/fpdfsave.cpp | 2 +- fpdfsdk/fpdftext.cpp | 2 +- fpdfsdk/fpdfview.cpp | 2 +- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 2 +- fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 2 +- fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp | 2 +- fpdfsdk/fsdk_actionhandler.cpp | 2 +- fpdfsdk/fsdk_baseform_embeddertest.cpp | 2 +- fpdfsdk/fsdk_common.h | 28 -- fpdfsdk/fsdk_define.cpp | 462 ------------------------ fpdfsdk/fsdk_define.h | 113 ------ fxjs/cjs_object.h | 2 +- testing/xfa_js_embedder_test.cpp | 2 +- 45 files changed, 645 insertions(+), 645 deletions(-) create mode 100644 fpdfsdk/cpdfsdk_common.h create mode 100644 fpdfsdk/cpdfsdk_helpers.cpp create mode 100644 fpdfsdk/cpdfsdk_helpers.h delete mode 100644 fpdfsdk/fsdk_common.h delete mode 100644 fpdfsdk/fsdk_define.cpp delete mode 100644 fpdfsdk/fsdk_define.h diff --git a/BUILD.gn b/BUILD.gn index d0662b374f..fbc4efbdd3 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -117,12 +117,15 @@ jumbo_static_library("pdfium") { "fpdfsdk/cpdfsdk_baannot.h", "fpdfsdk/cpdfsdk_baannothandler.cpp", "fpdfsdk/cpdfsdk_baannothandler.h", + "fpdfsdk/cpdfsdk_common.h", "fpdfsdk/cpdfsdk_customaccess.cpp", "fpdfsdk/cpdfsdk_customaccess.h", "fpdfsdk/cpdfsdk_datetime.cpp", "fpdfsdk/cpdfsdk_datetime.h", "fpdfsdk/cpdfsdk_formfillenvironment.cpp", "fpdfsdk/cpdfsdk_formfillenvironment.h", + "fpdfsdk/cpdfsdk_helpers.cpp", + "fpdfsdk/cpdfsdk_helpers.h", "fpdfsdk/cpdfsdk_interform.cpp", "fpdfsdk/cpdfsdk_interform.h", "fpdfsdk/cpdfsdk_memoryaccess.cpp", @@ -156,9 +159,6 @@ jumbo_static_library("pdfium") { "fpdfsdk/fpdfview.cpp", "fpdfsdk/fsdk_actionhandler.cpp", "fpdfsdk/fsdk_actionhandler.h", - "fpdfsdk/fsdk_common.h", - "fpdfsdk/fsdk_define.cpp", - "fpdfsdk/fsdk_define.h", "fpdfsdk/fsdk_filewriteadapter.cpp", "fpdfsdk/fsdk_filewriteadapter.h", "fpdfsdk/fsdk_pauseadapter.cpp", diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxge/skia/fx_skia_device_unittest.cpp index 66db939539..fe90fb708e 100644 --- a/core/fxge/skia/fx_skia_device_unittest.cpp +++ b/core/fxge/skia/fx_skia_device_unittest.cpp @@ -8,7 +8,7 @@ #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "public/fpdfview.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkPictureRecorder.h" diff --git a/fpdfsdk/cpdfsdk_annot.h b/fpdfsdk/cpdfsdk_annot.h index a6c4066ea5..f3311bc560 100644 --- a/fpdfsdk/cpdfsdk_annot.h +++ b/fpdfsdk/cpdfsdk_annot.h @@ -13,8 +13,8 @@ #include "core/fxcrt/observable.h" #include "core/fxcrt/unowned_ptr.h" #include "fpdfsdk/cfx_systemhandler.h" -#include "fpdfsdk/fsdk_common.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_common.h" +#include "fpdfsdk/cpdfsdk_helpers.h" class CFX_Matrix; class CFX_RenderDevice; diff --git a/fpdfsdk/cpdfsdk_common.h b/fpdfsdk/cpdfsdk_common.h new file mode 100644 index 0000000000..a5fb58f72d --- /dev/null +++ b/fpdfsdk/cpdfsdk_common.h @@ -0,0 +1,28 @@ +// Copyright 2014 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_CPDFSDK_COMMON_H_ +#define FPDFSDK_CPDFSDK_COMMON_H_ + +// for all fields +#define FIELDFLAG_READONLY 1 +#define FIELDFLAG_REQUIRED 2 +// for text fields +#define FIELDFLAG_MULTILINE (1 << 12) +#define FIELDFLAG_PASSWORD (1 << 13) +#define FIELDFLAG_FILESELECT (1 << 20) +#define FIELDFLAG_DONOTSPELLCHECK (1 << 22) +#define FIELDFLAG_DONOTSCROLL (1 << 23) +#define FIELDFLAG_COMB (1 << 24) +#define FIELDFLAG_RICHTEXT (1 << 25) +// for button fileds +#define FIELDFLAG_RADIOSINUNISON (1 << 27) +// for choice fields +#define FIELDFLAG_EDIT (1 << 18) +#define FIELDFLAG_MULTISELECT (1 << 21) +#define FIELDFLAG_COMMITONSELCHANGE (1 << 26) + +#endif // FPDFSDK_CPDFSDK_COMMON_H_ diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index f00630c18b..3c14ac06ac 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -17,7 +17,7 @@ #include "core/fxcrt/observable.h" #include "fpdfsdk/cfx_systemhandler.h" #include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "public/fpdf_formfill.h" #include "public/fpdf_fwlevent.h" diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp new file mode 100644 index 0000000000..45c2674a4d --- /dev/null +++ b/fpdfsdk/cpdfsdk_helpers.cpp @@ -0,0 +1,462 @@ +// 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/cpdfsdk_helpers.h" + +#include "core/fpdfapi/cpdf_modulemgr.h" +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/fpdf_parser_decode.h" +#include "core/fpdfdoc/cpdf_annot.h" +#include "core/fpdfdoc/cpdf_interform.h" +#include "core/fpdfdoc/cpdf_metadata.h" +#include "core/fxcrt/xml/cxml_content.h" +#include "core/fxcrt/xml/cxml_element.h" +#include "public/fpdf_ext.h" + +namespace { + +FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { + return static_cast(doc); +} + +bool RaiseUnSupportError(int nError) { + CFSDK_UnsupportInfo_Adapter* pAdapter = + CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter(); + if (!pAdapter) + return false; + + UNSUPPORT_INFO* info = static_cast(pAdapter->GetUnspInfo()); + if (info && info->FSDK_UnSupport_Handler) + info->FSDK_UnSupport_Handler(info, nError); + return true; +} + +bool CheckSharedForm(const CXML_Element* pElement, ByteString cbName) { + size_t count = pElement->CountAttrs(); + for (size_t i = 0; i < count; ++i) { + ByteString space; + ByteString name; + WideString value; + pElement->GetAttrByIndex(i, &space, &name, &value); + if (space == "xmlns" && name == "adhocwf" && + value == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") { + CXML_Element* pVersion = + pElement->GetElement("adhocwf", cbName.AsStringView(), 0); + if (!pVersion) + continue; + CXML_Content* pContent = ToContent(pVersion->GetChild(0)); + if (!pContent) + continue; + switch (pContent->m_Content.GetInteger()) { + case 1: + RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_ACROBAT); + break; + case 2: + RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM); + break; + case 0: + RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_EMAIL); + break; + } + } + } + + size_t nCount = pElement->CountChildren(); + for (size_t i = 0; i < nCount; ++i) { + CXML_Element* pChild = ToElement(pElement->GetChild(i)); + if (pChild && CheckSharedForm(pChild, cbName)) + return true; + } + return false; +} + +#ifdef PDF_ENABLE_XFA +class FPDF_FileHandlerContext : public IFX_SeekableStream { + public: + template + friend RetainPtr pdfium::MakeRetain(Args&&... args); + + ~FPDF_FileHandlerContext() override; + + // IFX_SeekableStream: + FX_FILESIZE GetSize() override; + bool IsEOF() override; + FX_FILESIZE GetPosition() override; + bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; + size_t ReadBlock(void* buffer, size_t size) override; + bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; + bool Flush() override; + + void SetPosition(FX_FILESIZE pos) { m_nCurPos = pos; } + + protected: + explicit FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS); + + FPDF_FILEHANDLER* m_pFS; + FX_FILESIZE m_nCurPos; +}; + +FPDF_FileHandlerContext::FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS) { + m_pFS = pFS; + m_nCurPos = 0; +} + +FPDF_FileHandlerContext::~FPDF_FileHandlerContext() { + if (m_pFS && m_pFS->Release) + m_pFS->Release(m_pFS->clientData); +} + +FX_FILESIZE FPDF_FileHandlerContext::GetSize() { + if (m_pFS && m_pFS->GetSize) + return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData); + return 0; +} + +bool FPDF_FileHandlerContext::IsEOF() { + return m_nCurPos >= GetSize(); +} + +FX_FILESIZE FPDF_FileHandlerContext::GetPosition() { + return m_nCurPos; +} + +bool FPDF_FileHandlerContext::ReadBlock(void* buffer, + FX_FILESIZE offset, + size_t size) { + if (!buffer || !size || !m_pFS->ReadBlock) + return false; + + if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, + (FPDF_DWORD)size) == 0) { + m_nCurPos = offset + size; + return true; + } + return false; +} + +size_t FPDF_FileHandlerContext::ReadBlock(void* buffer, size_t size) { + if (!buffer || !size || !m_pFS->ReadBlock) + return 0; + + FX_FILESIZE nSize = GetSize(); + if (m_nCurPos >= nSize) + return 0; + FX_FILESIZE dwAvail = nSize - m_nCurPos; + if (dwAvail < (FX_FILESIZE)size) + size = static_cast(dwAvail); + if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer, + (FPDF_DWORD)size) == 0) { + m_nCurPos += size; + return size; + } + + return 0; +} + +bool FPDF_FileHandlerContext::WriteBlock(const void* buffer, + FX_FILESIZE offset, + size_t size) { + if (!m_pFS || !m_pFS->WriteBlock) + return false; + + if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, + (FPDF_DWORD)size) == 0) { + m_nCurPos = offset + size; + return true; + } + return false; +} + +bool FPDF_FileHandlerContext::Flush() { + if (!m_pFS || !m_pFS->Flush) + return true; + + return m_pFS->Flush(m_pFS->clientData) == 0; +} +#endif // PDF_ENABLE_XFA + +} // namespace + +UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { + return static_cast(doc); +} + +UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { + return static_cast(page); +} + +CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { +#ifdef PDF_ENABLE_XFA + return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; +#else // PDF_ENABLE_XFA + return UnderlyingFromFPDFDocument(doc); +#endif // PDF_ENABLE_XFA +} + +FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { +#ifdef PDF_ENABLE_XFA + return doc ? FPDFDocumentFromUnderlying( + new CPDFXFA_Context(pdfium::WrapUnique(doc))) + : nullptr; +#else // PDF_ENABLE_XFA + return FPDFDocumentFromUnderlying(doc); +#endif // PDF_ENABLE_XFA +} + +CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { +#ifdef PDF_ENABLE_XFA + return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; +#else // PDF_ENABLE_XFA + return UnderlyingFromFPDFPage(page); +#endif // PDF_ENABLE_XFA +} + +CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) { + return static_cast(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(bitmap); +} + +void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) { + CPDF_Annot::Subtype nAnnotSubtype = pPDFAnnot->GetSubtype(); + if (nAnnotSubtype == CPDF_Annot::Subtype::THREED) { + RaiseUnSupportError(FPDF_UNSP_ANNOT_3DANNOT); + } else if (nAnnotSubtype == CPDF_Annot::Subtype::SCREEN) { + const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); + ByteString cbString; + if (pAnnotDict->KeyExist("IT")) + cbString = pAnnotDict->GetStringFor("IT"); + if (cbString.Compare("Img") != 0) + RaiseUnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA); + } else if (nAnnotSubtype == CPDF_Annot::Subtype::MOVIE) { + RaiseUnSupportError(FPDF_UNSP_ANNOT_MOVIE); + } else if (nAnnotSubtype == CPDF_Annot::Subtype::SOUND) { + RaiseUnSupportError(FPDF_UNSP_ANNOT_SOUND); + } else if (nAnnotSubtype == CPDF_Annot::Subtype::RICHMEDIA) { + RaiseUnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA); + } else if (nAnnotSubtype == CPDF_Annot::Subtype::FILEATTACHMENT) { + RaiseUnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT); + } else if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) { + const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); + ByteString cbString; + if (pAnnotDict->KeyExist("FT")) + cbString = pAnnotDict->GetStringFor("FT"); + if (cbString.Compare("Sig") == 0) + RaiseUnSupportError(FPDF_UNSP_ANNOT_SIG); + } +} + +void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) { + // Security + if (err_code == FPDF_ERR_SECURITY) { + RaiseUnSupportError(FPDF_UNSP_DOC_SECURITY); + return; + } + if (!pDoc) + return; + + // Portfolios and Packages + const CPDF_Dictionary* pRootDict = pDoc->GetRoot(); + if (pRootDict) { + ByteString cbString; + if (pRootDict->KeyExist("Collection")) { + RaiseUnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION); + return; + } + if (pRootDict->KeyExist("Names")) { + CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names"); + if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) { + RaiseUnSupportError(FPDF_UNSP_DOC_ATTACHMENT); + return; + } + if (pNameDict && pNameDict->KeyExist("JavaScript")) { + CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript"); + CPDF_Array* pArray = pJSDict ? pJSDict->GetArrayFor("Names") : nullptr; + if (pArray) { + for (size_t i = 0; i < pArray->GetCount(); i++) { + ByteString cbStr = pArray->GetStringAt(i); + if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) { + RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW); + return; + } + } + } + } + } + } + + // SharedForm + CPDF_Metadata metaData(pDoc); + const CXML_Element* pElement = metaData.GetRoot(); + if (pElement) + CheckSharedForm(pElement, "workflowType"); + +#ifndef PDF_ENABLE_XFA + // XFA Forms + CPDF_InterForm interform(pDoc); + if (interform.HasXFAForm()) + RaiseUnSupportError(FPDF_UNSP_DOC_XFAFORM); +#endif // PDF_ENABLE_XFA +} + +#ifndef _WIN32 +int g_LastError; +void SetLastError(int err) { + g_LastError = err; +} + +int GetLastError() { + return g_LastError; +} +#endif // _WIN32 + +void ProcessParseError(CPDF_Parser::Error err) { + uint32_t err_code = FPDF_ERR_SUCCESS; + // Translate FPDFAPI error code to FPDFVIEW error code + switch (err) { + case CPDF_Parser::SUCCESS: + err_code = FPDF_ERR_SUCCESS; + break; + case CPDF_Parser::FILE_ERROR: + err_code = FPDF_ERR_FILE; + break; + case CPDF_Parser::FORMAT_ERROR: + err_code = FPDF_ERR_FORMAT; + break; + case CPDF_Parser::PASSWORD_ERROR: + err_code = FPDF_ERR_PASSWORD; + break; + case CPDF_Parser::HANDLER_ERROR: + err_code = FPDF_ERR_SECURITY; + break; + } + SetLastError(err_code); +} + +// 0 bit: FPDF_POLICY_MACHINETIME_ACCESS +static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; + +void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { + switch (policy) { + case FPDF_POLICY_MACHINETIME_ACCESS: { + if (enable) + foxit_sandbox_policy |= 0x01; + else + foxit_sandbox_policy &= 0xFFFFFFFE; + } break; + default: + break; + } +} + +FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy) { + switch (policy) { + case FPDF_POLICY_MACHINETIME_ACCESS: + return !!(foxit_sandbox_policy & 0x01); + default: + return false; + } +} + +unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream, + void* buffer, + unsigned long buflen) { + ASSERT(stream); + uint8_t* data = stream->GetRawData(); + uint32_t len = stream->GetRawSize(); + CPDF_Dictionary* dict = stream->GetDict(); + CPDF_Object* decoder = dict ? dict->GetDirectObjectFor("Filter") : nullptr; + if (decoder && (decoder->IsArray() || decoder->IsName())) { + // Decode the stream if one or more stream filters are specified. + uint8_t* decoded_data = nullptr; + uint32_t decoded_len = 0; + ByteString dummy_last_decoder; + CPDF_Dictionary* dummy_last_param; + if (PDF_DataDecode(data, len, dict, dict->GetIntegerFor("DL"), false, + &decoded_data, &decoded_len, &dummy_last_decoder, + &dummy_last_param)) { + if (buffer && buflen >= decoded_len) + memcpy(buffer, decoded_data, decoded_len); + + // Free the buffer for the decoded data if it was allocated by + // PDF_DataDecode(). Note that for images with a single image-specific + // filter, |decoded_data| is directly assigned to be |data|, so + // |decoded_data| does not need to be freed. + if (decoded_data != data) + FX_Free(decoded_data); + + return decoded_len; + } + } + // Copy the raw data and return its length if there is no valid filter + // specified or if decoding failed. + if (buffer && buflen >= len) + memcpy(buffer, data, len); + + return len; +} + +unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text, + void* buffer, + unsigned long buflen) { + ByteString encoded_text = text.UTF16LE_Encode(); + unsigned long len = encoded_text.GetLength(); + if (buffer && len <= buflen) + memcpy(buffer, encoded_text.c_str(), len); + return len; +} + +void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect) { + out_rect->left = rect.left; + out_rect->top = rect.top; + out_rect->right = rect.right; + out_rect->bottom = rect.bottom; +} + +CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect) { + return CFX_FloatRect(rect.left, rect.bottom, rect.right, rect.top); +} + +const CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict) { + return dict ? dict->GetArrayFor("QuadPoints") : nullptr; +} + +bool GetQuadPointsFromDictionary(CPDF_Dictionary* dict, + size_t quad_index, + FS_QUADPOINTSF* quad_points) { + ASSERT(quad_points); + + const CPDF_Array* pArray = GetQuadPointsArrayFromDictionary(dict); + if (!pArray || quad_index >= pArray->GetCount() / 8) + return false; + + quad_index *= 8; + quad_points->x1 = pArray->GetNumberAt(quad_index); + quad_points->y1 = pArray->GetNumberAt(quad_index + 1); + quad_points->x2 = pArray->GetNumberAt(quad_index + 2); + quad_points->y2 = pArray->GetNumberAt(quad_index + 3); + quad_points->x3 = pArray->GetNumberAt(quad_index + 4); + quad_points->y3 = pArray->GetNumberAt(quad_index + 5); + quad_points->x4 = pArray->GetNumberAt(quad_index + 6); + quad_points->y4 = pArray->GetNumberAt(quad_index + 7); + return true; +} + +#ifdef PDF_ENABLE_XFA +RetainPtr MakeSeekableStream( + FPDF_FILEHANDLER* pFilehandler) { + return pdfium::MakeRetain(pFilehandler); +} +#endif // PDF_ENABLE_XFA diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h new file mode 100644 index 0000000000..c2f6515cf9 --- /dev/null +++ b/fpdfsdk/cpdfsdk_helpers.h @@ -0,0 +1,113 @@ +// Copyright 2014 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_CPDFSDK_HELPERS_H_ +#define FPDFSDK_CPDFSDK_HELPERS_H_ + +#include "core/fpdfapi/parser/cpdf_parser.h" +#include "core/fxge/dib/cfx_dibitmap.h" +#include "core/fxge/fx_dib.h" +#include "public/fpdf_doc.h" +#include "public/fpdfview.h" + +#ifdef PDF_ENABLE_XFA +#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" +#endif // PDF_ENABLE_XFA + +#ifdef _WIN32 +#include +#include +#endif + +class CPDF_Annot; +class CPDF_Page; +class CPDF_PageObject; +class CPDF_PageRenderContext; +class CPDF_PathObject; +class CPDF_Stream; +class IFSDK_PAUSE_Adapter; +class FX_PATHPOINT; + +// Object types for public FPDF_ types; these correspond to next layer down +// from fpdfsdk. For master, these are CPDF_ types, but for XFA, these are +// CPDFXFA_ types. +#ifndef PDF_ENABLE_XFA +using UnderlyingDocumentType = CPDF_Document; +using UnderlyingPageType = CPDF_Page; +#else // PDF_ENABLE_XFA +using UnderlyingDocumentType = CPDFXFA_Context; +using UnderlyingPageType = CPDFXFA_Page; +#endif // PDF_ENABLE_XFA + +// Conversions to/from underlying types. +UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc); + +UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page); + +// Conversions to/from FPDF_ types. +CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc); +FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc); + +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 +// Layering prevents fxcrt from knowing about FPDF_FILEHANDLER, so this can't +// be a static method of IFX_SeekableStream. +RetainPtr MakeSeekableStream( + FPDF_FILEHANDLER* pFileHandler); +#endif // PDF_ENABLE_XFA + +const CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict); +bool GetQuadPointsFromDictionary(CPDF_Dictionary* dict, + size_t quad_index, + FS_QUADPOINTSF* quad_points); + +CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect); +void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect); + +unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text, + void* buffer, + unsigned long buflen); +unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream, + void* buffer, + unsigned long buflen); + +void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable); +FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy); + +// TODO(dsinclair): Where should this live? +void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, + FPDF_PAGE page, + int start_x, + int start_y, + int size_x, + int size_y, + int rotate, + int flags, + bool bNeedToRestore, + IFSDK_PAUSE_Adapter* pause); + +void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code); +void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot); + +#ifndef _WIN32 +void SetLastError(int err); +int GetLastError(); +#endif // _WIN32 + +void ProcessParseError(CPDF_Parser::Error err); + +// TODO(dsinclair): This seems like it should be a public API? +FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A); + +#endif // FPDFSDK_CPDFSDK_HELPERS_H_ diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 9231951d33..9b1dbb75ef 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -24,11 +24,11 @@ #include "fpdfsdk/cba_annotiterator.h" #include "fpdfsdk/cpdfsdk_annot.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/fsdk_actionhandler.h" -#include "fpdfsdk/fsdk_define.h" #include "fpdfsdk/ipdfsdk_annothandler.h" #include "fxjs/ijs_event_context.h" #include "fxjs/ijs_runtime.h" diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 055ad63aa5..23241953e4 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -24,11 +24,11 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/fsdk_actionhandler.h" -#include "fpdfsdk/fsdk_define.h" #include "fpdfsdk/pwl/cpwl_appstream.h" #include "fpdfsdk/pwl/cpwl_edit.h" diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index d9b12f5d3c..92dc8d621a 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -6,11 +6,11 @@ #include "fpdfsdk/formfiller/cffl_combobox.h" +#include "fpdfsdk/cpdfsdk_common.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" -#include "fpdfsdk/fsdk_common.h" #include "fpdfsdk/pwl/cpwl_combo_box.h" #include "third_party/base/ptr_util.h" diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index 2e2aab9c8f..6ec7e266e3 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -10,11 +10,11 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fxge/cfx_renderdevice.h" +#include "fpdfsdk/cpdfsdk_common.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cba_fontmap.h" -#include "fpdfsdk/fsdk_common.h" namespace { diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.h b/fpdfsdk/formfiller/cffl_interactiveformfiller.h index 01927529f7..94ca59d284 100644 --- a/fpdfsdk/formfiller/cffl_interactiveformfiller.h +++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.h @@ -13,7 +13,7 @@ #include "core/fxcrt/unowned_ptr.h" #include "fpdfsdk/cpdfsdk_annot.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/pwl/cpwl_edit.h" class CFFL_FormFiller; diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index e628e59cb8..41e4774218 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -6,11 +6,11 @@ #include "fpdfsdk/formfiller/cffl_listbox.h" +#include "fpdfsdk/cpdfsdk_common.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" -#include "fpdfsdk/fsdk_common.h" #include "fpdfsdk/pwl/cpwl_list_box.h" #include "third_party/base/ptr_util.h" diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index ad8d27c916..6d7277c8fa 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -6,10 +6,10 @@ #include "fpdfsdk/formfiller/cffl_textfield.h" +#include "fpdfsdk/cpdfsdk_common.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cba_fontmap.h" -#include "fpdfsdk/fsdk_common.h" #include "third_party/base/ptr_util.h" CFFL_TextField::CFFL_TextField(CPDFSDK_FormFillEnvironment* pApp, diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp index b1a134d914..55d39a0d46 100644 --- a/fpdfsdk/fpdf_dataavail.cpp +++ b/fpdfsdk/fpdf_dataavail.cpp @@ -13,7 +13,7 @@ #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fxcrt/fx_stream.h" #include "core/fxcrt/retain_ptr.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "public/fpdf_formfill.h" #include "third_party/base/ptr_util.h" diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp index b972141e11..2f05fc5cdc 100644 --- a/fpdfsdk/fpdf_ext.cpp +++ b/fpdfsdk/fpdf_ext.cpp @@ -9,7 +9,7 @@ #include "core/fpdfapi/cpdf_modulemgr.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfdoc/cpdf_interform.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index 299318bd08..f1d95c7d7e 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -21,7 +21,7 @@ #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" #include "core/fpdfdoc/cpdf_annot.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "third_party/base/stl_util.h" enum FPDF_TYPE { MAX, MIN }; diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp index ceceacf01d..6daaf13704 100644 --- a/fpdfsdk/fpdf_ppo.cpp +++ b/fpdfsdk/fpdf_ppo.cpp @@ -25,7 +25,7 @@ #include "core/fpdfapi/parser/cpdf_string.h" #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "public/cpp/fpdf_deleters.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fpdf_progressive.cpp b/fpdfsdk/fpdf_progressive.cpp index 730ba48162..d53ab15d0e 100644 --- a/fpdfsdk/fpdf_progressive.cpp +++ b/fpdfsdk/fpdf_progressive.cpp @@ -14,7 +14,7 @@ #include "core/fxcrt/fx_memory.h" #include "core/fxge/cfx_defaultrenderdevice.h" #include "core/fxge/cfx_renderdevice.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/fsdk_pauseadapter.h" #include "public/fpdfview.h" #include "third_party/base/ptr_util.h" diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp index 676824ef99..98123d94d1 100644 --- a/fpdfsdk/fpdf_structtree.cpp +++ b/fpdfsdk/fpdf_structtree.cpp @@ -10,7 +10,7 @@ #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfdoc/cpdf_structelement.h" #include "core/fpdfdoc/cpdf_structtree.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" namespace { diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp index 81a749aefb..e310e4d6f7 100644 --- a/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/fpdfsdk/fpdf_sysfontinfo.cpp @@ -14,7 +14,7 @@ #include "core/fxge/cfx_gemodule.h" #include "core/fxge/fx_font.h" #include "core/fxge/systemfontinfo_iface.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/pwl/cpwl_font_map.h" #include "third_party/base/ptr_util.h" diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index 5a7e094b07..860ba42c96 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -20,7 +20,7 @@ #include "core/fpdfapi/parser/cpdf_reference.h" #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fxge/cfx_pathdata.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" namespace { diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp index c52807148e..2ab0bca454 100644 --- a/fpdfsdk/fpdfannot.cpp +++ b/fpdfsdk/fpdfannot.cpp @@ -22,7 +22,7 @@ #include "core/fpdfdoc/cpdf_interform.h" #include "core/fpdfdoc/cpvt_generateap.h" #include "core/fxge/cfx_color.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" namespace { diff --git a/fpdfsdk/fpdfattachment.cpp b/fpdfsdk/fpdfattachment.cpp index 0de01b2e8a..0bb9364834 100644 --- a/fpdfsdk/fpdfattachment.cpp +++ b/fpdfsdk/fpdfattachment.cpp @@ -19,7 +19,7 @@ #include "core/fpdfdoc/cpdf_nametree.h" #include "core/fxcrt/cfx_datetime.h" #include "core/fxcrt/fx_extension.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" namespace { diff --git a/fpdfsdk/fpdfcatalog.cpp b/fpdfsdk/fpdfcatalog.cpp index 493e5aea43..af6e40a0ad 100644 --- a/fpdfsdk/fpdfcatalog.cpp +++ b/fpdfsdk/fpdfcatalog.cpp @@ -5,7 +5,7 @@ #include "public/fpdf_catalog.h" #include "core/fpdfapi/parser/cpdf_document.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFCatalog_IsTagged(FPDF_DOCUMENT document) { diff --git a/fpdfsdk/fpdfdoc.cpp b/fpdfsdk/fpdfdoc.cpp index 2ba0053d8e..d8be12066a 100644 --- a/fpdfsdk/fpdfdoc.cpp +++ b/fpdfsdk/fpdfdoc.cpp @@ -16,7 +16,7 @@ #include "core/fpdfdoc/cpdf_bookmarktree.h" #include "core/fpdfdoc/cpdf_dest.h" #include "core/fpdfdoc/cpdf_pagelabel.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index 65e790cc32..7ea22d0aa4 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -14,7 +14,7 @@ #include "core/fpdfapi/parser/cpdf_number.h" #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fxcrt/fx_system.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "public/cpp/fpdf_deleters.h" #include "public/fpdf_annot.h" #include "public/fpdf_edit.h" diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index a98a61f147..f1d90ece2d 100644 --- a/fpdfsdk/fpdfeditimg.cpp +++ b/fpdfsdk/fpdfeditimg.cpp @@ -15,7 +15,7 @@ #include "core/fpdfapi/parser/cpdf_name.h" #include "core/fpdfapi/render/cpdf_dibsource.h" #include "fpdfsdk/cpdfsdk_customaccess.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "third_party/base/ptr_util.h" namespace { diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 92e4357b68..29cad9a752 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -24,7 +24,7 @@ #include "core/fpdfapi/parser/cpdf_string.h" #include "core/fpdfdoc/cpdf_annot.h" #include "core/fpdfdoc/cpdf_annotlist.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "public/fpdf_formfill.h" #include "third_party/base/logging.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp index 0b9ac4737c..745c3b763b 100644 --- a/fpdfsdk/fpdfeditpath.cpp +++ b/fpdfsdk/fpdfeditpath.cpp @@ -9,7 +9,7 @@ #include "core/fpdfapi/page/cpdf_path.h" #include "core/fpdfapi/page/cpdf_pathobject.h" #include "core/fxcrt/fx_system.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "third_party/base/ptr_util.h" // These checks are here because core/ and public/ cannot depend on each other. diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp index 460e852eaa..8155003a1f 100644 --- a/fpdfsdk/fpdfedittext.cpp +++ b/fpdfsdk/fpdfedittext.cpp @@ -24,7 +24,7 @@ #include "core/fxcrt/fx_extension.h" #include "core/fxge/cfx_fontmgr.h" #include "core/fxge/fx_font.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "public/fpdf_edit.h" namespace { diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 2f219f2f9d..6cf587c7ac 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -18,10 +18,10 @@ #include "core/fpdfdoc/cpdf_occontext.h" #include "core/fxge/cfx_defaultrenderdevice.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/fsdk_actionhandler.h" -#include "fpdfsdk/fsdk_define.h" #include "public/fpdfview.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index d12a66ad7d..2c615f434c 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -18,7 +18,7 @@ #include "core/fpdfapi/parser/cpdf_string.h" #include "core/fxcrt/cfx_memorystream.h" #include "core/fxcrt/fx_extension.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/fsdk_filewriteadapter.h" #include "public/fpdf_edit.h" diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp index 68bf4f83d7..7778696931 100644 --- a/fpdfsdk/fpdftext.cpp +++ b/fpdfsdk/fpdftext.cpp @@ -14,7 +14,7 @@ #include "core/fpdftext/cpdf_linkextract.h" #include "core/fpdftext/cpdf_textpage.h" #include "core/fpdftext/cpdf_textpagefind.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "third_party/base/numerics/safe_conversions.h" #include "third_party/base/stl_util.h" diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 9a334d5fe6..ff2a4633f1 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -32,9 +32,9 @@ #include "core/fxge/cfx_renderdevice.h" #include "fpdfsdk/cpdfsdk_customaccess.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_memoryaccess.h" #include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/fsdk_define.h" #include "fpdfsdk/fsdk_pauseadapter.h" #include "fxjs/ijs_runtime.h" #include "public/fpdf_formfill.h" diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 18f5f99b0e..5553025371 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -12,11 +12,11 @@ #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fxcrt/fx_fallthrough.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" -#include "fpdfsdk/fsdk_define.h" #include "fxjs/cjs_runtime.h" #include "fxjs/ijs_runtime.h" #include "public/fpdf_formfill.h" diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index 87cb4ba62a..f4f6efdd0e 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -9,9 +9,9 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fxcrt/fx_fallthrough.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" -#include "fpdfsdk/fsdk_define.h" #include "public/fpdf_formfill.h" #include "third_party/base/ptr_util.h" #include "xfa/fxfa/cxfa_ffdocview.h" diff --git a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp index c7201c3fbd..adba260041 100644 --- a/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp +++ b/fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.cpp @@ -10,7 +10,7 @@ #include #include "fpdfsdk/cpdfsdk_formfillenvironment.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" namespace { diff --git a/fpdfsdk/fsdk_actionhandler.cpp b/fpdfsdk/fsdk_actionhandler.cpp index 305d905c85..73c7d84f69 100644 --- a/fpdfsdk/fsdk_actionhandler.cpp +++ b/fpdfsdk/fsdk_actionhandler.cpp @@ -13,8 +13,8 @@ #include "core/fpdfdoc/cpdf_formfield.h" #include "core/fpdfdoc/cpdf_interform.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_interform.h" -#include "fpdfsdk/fsdk_define.h" #include "fxjs/ijs_event_context.h" #include "fxjs/ijs_runtime.h" #include "third_party/base/logging.h" diff --git a/fpdfsdk/fsdk_baseform_embeddertest.cpp b/fpdfsdk/fsdk_baseform_embeddertest.cpp index 13efe86789..9f2c606309 100644 --- a/fpdfsdk/fsdk_baseform_embeddertest.cpp +++ b/fpdfsdk/fsdk_baseform_embeddertest.cpp @@ -5,7 +5,7 @@ #include "fpdfsdk/cba_annotiterator.h" #include "fpdfsdk/cpdfsdk_annot.h" #include "fpdfsdk/cpdfsdk_formfillenvironment.h" -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "testing/embedder_test.h" #include "testing/embedder_test_mock_delegate.h" #include "testing/embedder_test_timer_handling_delegate.h" diff --git a/fpdfsdk/fsdk_common.h b/fpdfsdk/fsdk_common.h deleted file mode 100644 index 78ecd98b4a..0000000000 --- a/fpdfsdk/fsdk_common.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2014 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_FSDK_COMMON_H_ -#define FPDFSDK_FSDK_COMMON_H_ - -// for all fields -#define FIELDFLAG_READONLY 1 -#define FIELDFLAG_REQUIRED 2 -// for text fields -#define FIELDFLAG_MULTILINE (1 << 12) -#define FIELDFLAG_PASSWORD (1 << 13) -#define FIELDFLAG_FILESELECT (1 << 20) -#define FIELDFLAG_DONOTSPELLCHECK (1 << 22) -#define FIELDFLAG_DONOTSCROLL (1 << 23) -#define FIELDFLAG_COMB (1 << 24) -#define FIELDFLAG_RICHTEXT (1 << 25) -// for button fileds -#define FIELDFLAG_RADIOSINUNISON (1 << 27) -// for choice fields -#define FIELDFLAG_EDIT (1 << 18) -#define FIELDFLAG_MULTISELECT (1 << 21) -#define FIELDFLAG_COMMITONSELCHANGE (1 << 26) - -#endif // FPDFSDK_FSDK_COMMON_H_ diff --git a/fpdfsdk/fsdk_define.cpp b/fpdfsdk/fsdk_define.cpp deleted file mode 100644 index 917d36d88e..0000000000 --- a/fpdfsdk/fsdk_define.cpp +++ /dev/null @@ -1,462 +0,0 @@ -// 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/fsdk_define.h" - -#include "core/fpdfapi/cpdf_modulemgr.h" -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/parser/fpdf_parser_decode.h" -#include "core/fpdfdoc/cpdf_annot.h" -#include "core/fpdfdoc/cpdf_interform.h" -#include "core/fpdfdoc/cpdf_metadata.h" -#include "core/fxcrt/xml/cxml_content.h" -#include "core/fxcrt/xml/cxml_element.h" -#include "public/fpdf_ext.h" - -namespace { - -FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { - return static_cast(doc); -} - -bool RaiseUnSupportError(int nError) { - CFSDK_UnsupportInfo_Adapter* pAdapter = - CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter(); - if (!pAdapter) - return false; - - UNSUPPORT_INFO* info = static_cast(pAdapter->GetUnspInfo()); - if (info && info->FSDK_UnSupport_Handler) - info->FSDK_UnSupport_Handler(info, nError); - return true; -} - -bool CheckSharedForm(const CXML_Element* pElement, ByteString cbName) { - size_t count = pElement->CountAttrs(); - for (size_t i = 0; i < count; ++i) { - ByteString space; - ByteString name; - WideString value; - pElement->GetAttrByIndex(i, &space, &name, &value); - if (space == "xmlns" && name == "adhocwf" && - value == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") { - CXML_Element* pVersion = - pElement->GetElement("adhocwf", cbName.AsStringView(), 0); - if (!pVersion) - continue; - CXML_Content* pContent = ToContent(pVersion->GetChild(0)); - if (!pContent) - continue; - switch (pContent->m_Content.GetInteger()) { - case 1: - RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_ACROBAT); - break; - case 2: - RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM); - break; - case 0: - RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_EMAIL); - break; - } - } - } - - size_t nCount = pElement->CountChildren(); - for (size_t i = 0; i < nCount; ++i) { - CXML_Element* pChild = ToElement(pElement->GetChild(i)); - if (pChild && CheckSharedForm(pChild, cbName)) - return true; - } - return false; -} - -#ifdef PDF_ENABLE_XFA -class FPDF_FileHandlerContext : public IFX_SeekableStream { - public: - template - friend RetainPtr pdfium::MakeRetain(Args&&... args); - - ~FPDF_FileHandlerContext() override; - - // IFX_SeekableStream: - FX_FILESIZE GetSize() override; - bool IsEOF() override; - FX_FILESIZE GetPosition() override; - bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; - size_t ReadBlock(void* buffer, size_t size) override; - bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; - bool Flush() override; - - void SetPosition(FX_FILESIZE pos) { m_nCurPos = pos; } - - protected: - explicit FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS); - - FPDF_FILEHANDLER* m_pFS; - FX_FILESIZE m_nCurPos; -}; - -FPDF_FileHandlerContext::FPDF_FileHandlerContext(FPDF_FILEHANDLER* pFS) { - m_pFS = pFS; - m_nCurPos = 0; -} - -FPDF_FileHandlerContext::~FPDF_FileHandlerContext() { - if (m_pFS && m_pFS->Release) - m_pFS->Release(m_pFS->clientData); -} - -FX_FILESIZE FPDF_FileHandlerContext::GetSize() { - if (m_pFS && m_pFS->GetSize) - return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData); - return 0; -} - -bool FPDF_FileHandlerContext::IsEOF() { - return m_nCurPos >= GetSize(); -} - -FX_FILESIZE FPDF_FileHandlerContext::GetPosition() { - return m_nCurPos; -} - -bool FPDF_FileHandlerContext::ReadBlock(void* buffer, - FX_FILESIZE offset, - size_t size) { - if (!buffer || !size || !m_pFS->ReadBlock) - return false; - - if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, - (FPDF_DWORD)size) == 0) { - m_nCurPos = offset + size; - return true; - } - return false; -} - -size_t FPDF_FileHandlerContext::ReadBlock(void* buffer, size_t size) { - if (!buffer || !size || !m_pFS->ReadBlock) - return 0; - - FX_FILESIZE nSize = GetSize(); - if (m_nCurPos >= nSize) - return 0; - FX_FILESIZE dwAvail = nSize - m_nCurPos; - if (dwAvail < (FX_FILESIZE)size) - size = static_cast(dwAvail); - if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer, - (FPDF_DWORD)size) == 0) { - m_nCurPos += size; - return size; - } - - return 0; -} - -bool FPDF_FileHandlerContext::WriteBlock(const void* buffer, - FX_FILESIZE offset, - size_t size) { - if (!m_pFS || !m_pFS->WriteBlock) - return false; - - if (m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, - (FPDF_DWORD)size) == 0) { - m_nCurPos = offset + size; - return true; - } - return false; -} - -bool FPDF_FileHandlerContext::Flush() { - if (!m_pFS || !m_pFS->Flush) - return true; - - return m_pFS->Flush(m_pFS->clientData) == 0; -} -#endif // PDF_ENABLE_XFA - -} // namespace - -UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { - return static_cast(doc); -} - -UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { - return static_cast(page); -} - -CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { -#ifdef PDF_ENABLE_XFA - return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; -#else // PDF_ENABLE_XFA - return UnderlyingFromFPDFDocument(doc); -#endif // PDF_ENABLE_XFA -} - -FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { -#ifdef PDF_ENABLE_XFA - return doc ? FPDFDocumentFromUnderlying( - new CPDFXFA_Context(pdfium::WrapUnique(doc))) - : nullptr; -#else // PDF_ENABLE_XFA - return FPDFDocumentFromUnderlying(doc); -#endif // PDF_ENABLE_XFA -} - -CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { -#ifdef PDF_ENABLE_XFA - return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; -#else // PDF_ENABLE_XFA - return UnderlyingFromFPDFPage(page); -#endif // PDF_ENABLE_XFA -} - -CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) { - return static_cast(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(bitmap); -} - -void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) { - CPDF_Annot::Subtype nAnnotSubtype = pPDFAnnot->GetSubtype(); - if (nAnnotSubtype == CPDF_Annot::Subtype::THREED) { - RaiseUnSupportError(FPDF_UNSP_ANNOT_3DANNOT); - } else if (nAnnotSubtype == CPDF_Annot::Subtype::SCREEN) { - const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); - ByteString cbString; - if (pAnnotDict->KeyExist("IT")) - cbString = pAnnotDict->GetStringFor("IT"); - if (cbString.Compare("Img") != 0) - RaiseUnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA); - } else if (nAnnotSubtype == CPDF_Annot::Subtype::MOVIE) { - RaiseUnSupportError(FPDF_UNSP_ANNOT_MOVIE); - } else if (nAnnotSubtype == CPDF_Annot::Subtype::SOUND) { - RaiseUnSupportError(FPDF_UNSP_ANNOT_SOUND); - } else if (nAnnotSubtype == CPDF_Annot::Subtype::RICHMEDIA) { - RaiseUnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA); - } else if (nAnnotSubtype == CPDF_Annot::Subtype::FILEATTACHMENT) { - RaiseUnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT); - } else if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) { - const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); - ByteString cbString; - if (pAnnotDict->KeyExist("FT")) - cbString = pAnnotDict->GetStringFor("FT"); - if (cbString.Compare("Sig") == 0) - RaiseUnSupportError(FPDF_UNSP_ANNOT_SIG); - } -} - -void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) { - // Security - if (err_code == FPDF_ERR_SECURITY) { - RaiseUnSupportError(FPDF_UNSP_DOC_SECURITY); - return; - } - if (!pDoc) - return; - - // Portfolios and Packages - const CPDF_Dictionary* pRootDict = pDoc->GetRoot(); - if (pRootDict) { - ByteString cbString; - if (pRootDict->KeyExist("Collection")) { - RaiseUnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION); - return; - } - if (pRootDict->KeyExist("Names")) { - CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names"); - if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) { - RaiseUnSupportError(FPDF_UNSP_DOC_ATTACHMENT); - return; - } - if (pNameDict && pNameDict->KeyExist("JavaScript")) { - CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript"); - CPDF_Array* pArray = pJSDict ? pJSDict->GetArrayFor("Names") : nullptr; - if (pArray) { - for (size_t i = 0; i < pArray->GetCount(); i++) { - ByteString cbStr = pArray->GetStringAt(i); - if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) { - RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW); - return; - } - } - } - } - } - } - - // SharedForm - CPDF_Metadata metaData(pDoc); - const CXML_Element* pElement = metaData.GetRoot(); - if (pElement) - CheckSharedForm(pElement, "workflowType"); - -#ifndef PDF_ENABLE_XFA - // XFA Forms - CPDF_InterForm interform(pDoc); - if (interform.HasXFAForm()) - RaiseUnSupportError(FPDF_UNSP_DOC_XFAFORM); -#endif // PDF_ENABLE_XFA -} - -#ifndef _WIN32 -int g_LastError; -void SetLastError(int err) { - g_LastError = err; -} - -int GetLastError() { - return g_LastError; -} -#endif // _WIN32 - -void ProcessParseError(CPDF_Parser::Error err) { - uint32_t err_code = FPDF_ERR_SUCCESS; - // Translate FPDFAPI error code to FPDFVIEW error code - switch (err) { - case CPDF_Parser::SUCCESS: - err_code = FPDF_ERR_SUCCESS; - break; - case CPDF_Parser::FILE_ERROR: - err_code = FPDF_ERR_FILE; - break; - case CPDF_Parser::FORMAT_ERROR: - err_code = FPDF_ERR_FORMAT; - break; - case CPDF_Parser::PASSWORD_ERROR: - err_code = FPDF_ERR_PASSWORD; - break; - case CPDF_Parser::HANDLER_ERROR: - err_code = FPDF_ERR_SECURITY; - break; - } - SetLastError(err_code); -} - -// 0 bit: FPDF_POLICY_MACHINETIME_ACCESS -static uint32_t foxit_sandbox_policy = 0xFFFFFFFF; - -void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable) { - switch (policy) { - case FPDF_POLICY_MACHINETIME_ACCESS: { - if (enable) - foxit_sandbox_policy |= 0x01; - else - foxit_sandbox_policy &= 0xFFFFFFFE; - } break; - default: - break; - } -} - -FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy) { - switch (policy) { - case FPDF_POLICY_MACHINETIME_ACCESS: - return !!(foxit_sandbox_policy & 0x01); - default: - return false; - } -} - -unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream, - void* buffer, - unsigned long buflen) { - ASSERT(stream); - uint8_t* data = stream->GetRawData(); - uint32_t len = stream->GetRawSize(); - CPDF_Dictionary* dict = stream->GetDict(); - CPDF_Object* decoder = dict ? dict->GetDirectObjectFor("Filter") : nullptr; - if (decoder && (decoder->IsArray() || decoder->IsName())) { - // Decode the stream if one or more stream filters are specified. - uint8_t* decoded_data = nullptr; - uint32_t decoded_len = 0; - ByteString dummy_last_decoder; - CPDF_Dictionary* dummy_last_param; - if (PDF_DataDecode(data, len, dict, dict->GetIntegerFor("DL"), false, - &decoded_data, &decoded_len, &dummy_last_decoder, - &dummy_last_param)) { - if (buffer && buflen >= decoded_len) - memcpy(buffer, decoded_data, decoded_len); - - // Free the buffer for the decoded data if it was allocated by - // PDF_DataDecode(). Note that for images with a single image-specific - // filter, |decoded_data| is directly assigned to be |data|, so - // |decoded_data| does not need to be freed. - if (decoded_data != data) - FX_Free(decoded_data); - - return decoded_len; - } - } - // Copy the raw data and return its length if there is no valid filter - // specified or if decoding failed. - if (buffer && buflen >= len) - memcpy(buffer, data, len); - - return len; -} - -unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text, - void* buffer, - unsigned long buflen) { - ByteString encoded_text = text.UTF16LE_Encode(); - unsigned long len = encoded_text.GetLength(); - if (buffer && len <= buflen) - memcpy(buffer, encoded_text.c_str(), len); - return len; -} - -void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect) { - out_rect->left = rect.left; - out_rect->top = rect.top; - out_rect->right = rect.right; - out_rect->bottom = rect.bottom; -} - -CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect) { - return CFX_FloatRect(rect.left, rect.bottom, rect.right, rect.top); -} - -const CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict) { - return dict ? dict->GetArrayFor("QuadPoints") : nullptr; -} - -bool GetQuadPointsFromDictionary(CPDF_Dictionary* dict, - size_t quad_index, - FS_QUADPOINTSF* quad_points) { - ASSERT(quad_points); - - const CPDF_Array* pArray = GetQuadPointsArrayFromDictionary(dict); - if (!pArray || quad_index >= pArray->GetCount() / 8) - return false; - - quad_index *= 8; - quad_points->x1 = pArray->GetNumberAt(quad_index); - quad_points->y1 = pArray->GetNumberAt(quad_index + 1); - quad_points->x2 = pArray->GetNumberAt(quad_index + 2); - quad_points->y2 = pArray->GetNumberAt(quad_index + 3); - quad_points->x3 = pArray->GetNumberAt(quad_index + 4); - quad_points->y3 = pArray->GetNumberAt(quad_index + 5); - quad_points->x4 = pArray->GetNumberAt(quad_index + 6); - quad_points->y4 = pArray->GetNumberAt(quad_index + 7); - return true; -} - -#ifdef PDF_ENABLE_XFA -RetainPtr MakeSeekableStream( - FPDF_FILEHANDLER* pFilehandler) { - return pdfium::MakeRetain(pFilehandler); -} -#endif // PDF_ENABLE_XFA diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h deleted file mode 100644 index c864f05046..0000000000 --- a/fpdfsdk/fsdk_define.h +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2014 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_FSDK_DEFINE_H_ -#define FPDFSDK_FSDK_DEFINE_H_ - -#include "core/fpdfapi/parser/cpdf_parser.h" -#include "core/fxge/dib/cfx_dibitmap.h" -#include "core/fxge/fx_dib.h" -#include "public/fpdf_doc.h" -#include "public/fpdfview.h" - -#ifdef PDF_ENABLE_XFA -#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" -#endif // PDF_ENABLE_XFA - -#ifdef _WIN32 -#include -#include -#endif - -class CPDF_Annot; -class CPDF_Page; -class CPDF_PageObject; -class CPDF_PageRenderContext; -class CPDF_PathObject; -class CPDF_Stream; -class IFSDK_PAUSE_Adapter; -class FX_PATHPOINT; - -// Object types for public FPDF_ types; these correspond to next layer down -// from fpdfsdk. For master, these are CPDF_ types, but for XFA, these are -// CPDFXFA_ types. -#ifndef PDF_ENABLE_XFA -using UnderlyingDocumentType = CPDF_Document; -using UnderlyingPageType = CPDF_Page; -#else // PDF_ENABLE_XFA -using UnderlyingDocumentType = CPDFXFA_Context; -using UnderlyingPageType = CPDFXFA_Page; -#endif // PDF_ENABLE_XFA - -// Conversions to/from underlying types. -UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc); - -UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page); - -// Conversions to/from FPDF_ types. -CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc); -FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc); - -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 -// Layering prevents fxcrt from knowing about FPDF_FILEHANDLER, so this can't -// be a static method of IFX_SeekableStream. -RetainPtr MakeSeekableStream( - FPDF_FILEHANDLER* pFileHandler); -#endif // PDF_ENABLE_XFA - -const CPDF_Array* GetQuadPointsArrayFromDictionary(CPDF_Dictionary* dict); -bool GetQuadPointsFromDictionary(CPDF_Dictionary* dict, - size_t quad_index, - FS_QUADPOINTSF* quad_points); - -CFX_FloatRect CFXFloatRectFromFSRECTF(const FS_RECTF& rect); -void FSRECTFFromCFXFloatRect(const CFX_FloatRect& rect, FS_RECTF* out_rect); - -unsigned long Utf16EncodeMaybeCopyAndReturnLength(const WideString& text, - void* buffer, - unsigned long buflen); -unsigned long DecodeStreamMaybeCopyAndReturnLength(const CPDF_Stream* stream, - void* buffer, - unsigned long buflen); - -void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable); -FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy); - -// TODO(dsinclair): Where should this live? -void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, - FPDF_PAGE page, - int start_x, - int start_y, - int size_x, - int size_y, - int rotate, - int flags, - bool bNeedToRestore, - IFSDK_PAUSE_Adapter* pause); - -void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code); -void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot); - -#ifndef _WIN32 -void SetLastError(int err); -int GetLastError(); -#endif // _WIN32 - -void ProcessParseError(CPDF_Parser::Error err); - -// TODO(dsinclair): This seems like it should be a public API? -FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, - unsigned int R, - unsigned int G, - unsigned int B, - unsigned int A); - -#endif // FPDFSDK_FSDK_DEFINE_H_ diff --git a/fxjs/cjs_object.h b/fxjs/cjs_object.h index 7b26fba527..8254af98de 100644 --- a/fxjs/cjs_object.h +++ b/fxjs/cjs_object.h @@ -10,7 +10,7 @@ #include #include -#include "fpdfsdk/fsdk_define.h" +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fxjs/cfxjs_engine.h" #include "fxjs/cjs_runtime.h" diff --git a/testing/xfa_js_embedder_test.cpp b/testing/xfa_js_embedder_test.cpp index 133a938643..0fe4b7a624 100644 --- a/testing/xfa_js_embedder_test.cpp +++ b/testing/xfa_js_embedder_test.cpp @@ -6,8 +6,8 @@ #include +#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" -#include "fpdfsdk/fsdk_define.h" #include "fxjs/cfxjse_engine.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/base/ptr_util.h" -- cgit v1.2.3