1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef FPDFSDK_INCLUDE_FSDK_DEFINE_H_ 8 #define FPDFSDK_INCLUDE_FSDK_DEFINE_H_ 9 10 #include "core/include/fpdfapi/fpdf_module.h" 11 #include "core/include/fpdfapi/fpdf_pageobj.h" 12 #include "core/include/fpdfapi/fpdf_parser.h" 13 #include "core/include/fpdfapi/fpdf_render.h" 14 #include "core/include/fpdfdoc/fpdf_doc.h" 15 #include "core/include/fpdfdoc/fpdf_vt.h" 16 #include "core/include/fxge/fx_ge.h" 17 #include "core/include/fxge/fx_ge_win32.h" 18 #include "public/fpdfview.h" 19 20 #ifdef PDF_ENABLE_XFA 21 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" 22 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" 23 #include "xfa/include/fwl/adapter/fwl_adaptertimermgr.h" 24 #include "xfa/include/fxbarcode/BC_BarCode.h" 25 #include "xfa/include/fxfa/fxfa.h" 26 #include "xfa/include/fxgraphics/fx_graphics.h" 27 #include "xfa/include/fxjse/fxjse.h" 28 #endif // PDF_ENABLE_XFA 29 30 #ifdef _WIN32 31 #include <tchar.h> 32 #include <math.h> 33 #endif 34 35 // Convert a #FX_ARGB to a #FX_COLORREF. 36 #define FX_ARGBTOCOLORREF(argb) \ 37 ((((FX_DWORD)argb & 0x00FF0000) >> 16) | ((FX_DWORD)argb & 0x0000FF00) | \ 38 (((FX_DWORD)argb & 0x000000FF) << 16)) 39 40 // Convert a #FX_COLORREF to a #FX_ARGB. 41 #define FX_COLORREFTOARGB(rgb) \ 42 ((FX_DWORD)0xFF000000 | (((FX_DWORD)rgb & 0x000000FF) << 16) | \ 43 ((FX_DWORD)rgb & 0x0000FF00) | (((FX_DWORD)rgb & 0x00FF0000) >> 16)) 44 45 typedef unsigned int FX_UINT; 46 class CRenderContext; 47 class IFSDK_PAUSE_Adapter; 48 49 class CPDF_CustomAccess final : public IFX_FileRead { 50 public: 51 explicit CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess); ~CPDF_CustomAccess()52 ~CPDF_CustomAccess() override {} 53 54 // IFX_FileRead GetSize()55 FX_FILESIZE GetSize() override { return m_FileAccess.m_FileLen; } Release()56 void Release() override { delete this; } 57 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; 58 59 #ifdef PDF_ENABLE_XFA GetFullPath()60 virtual CFX_ByteString GetFullPath() { return ""; } 61 virtual FX_BOOL GetByte(FX_DWORD pos, uint8_t& ch); 62 virtual FX_BOOL GetBlock(FX_DWORD pos, uint8_t* pBuf, FX_DWORD size); 63 #endif // PDF_ENABLE_XFA 64 65 private: 66 FPDF_FILEACCESS m_FileAccess; 67 #ifdef PDF_ENABLE_XFA 68 uint8_t m_Buffer[512]; 69 FX_DWORD m_BufferOffset; 70 #endif // PDF_ENABLE_XFA 71 }; 72 73 #ifdef PDF_ENABLE_XFA 74 class CFPDF_FileStream : public IFX_FileStream { 75 public: 76 CFPDF_FileStream(FPDF_FILEHANDLER* pFS); ~CFPDF_FileStream()77 virtual ~CFPDF_FileStream() {} 78 79 virtual IFX_FileStream* Retain(); 80 virtual void Release(); 81 82 virtual FX_FILESIZE GetSize(); 83 virtual FX_BOOL IsEOF(); GetPosition()84 virtual FX_FILESIZE GetPosition() { return m_nCurPos; } SetPosition(FX_FILESIZE pos)85 virtual void SetPosition(FX_FILESIZE pos) { m_nCurPos = pos; } 86 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size); 87 virtual size_t ReadBlock(void* buffer, size_t size); 88 virtual FX_BOOL WriteBlock(const void* buffer, 89 FX_FILESIZE offset, 90 size_t size); 91 virtual FX_BOOL Flush(); 92 93 protected: 94 FPDF_FILEHANDLER* m_pFS; 95 FX_FILESIZE m_nCurPos; 96 }; 97 #endif // PDF_ENABLE_XFA 98 99 // Object types for public FPDF_ types; these correspond to next layer down 100 // from fpdfsdk. For master, these are CPDF_ types, but for XFA, these are 101 // CPDFXFA_ types. 102 #ifndef PDF_ENABLE_XFA 103 using UnderlyingDocumentType = CPDF_Document; 104 using UnderlyingPageType = CPDF_Page; 105 #else // PDF_ENABLE_XFA 106 using UnderlyingDocumentType = CPDFXFA_Document; 107 using UnderlyingPageType = CPDFXFA_Page; 108 #endif // PDF_ENABLE_XFA 109 110 // Conversions to/from underlying types. 111 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc); 112 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc); 113 114 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page); 115 116 // Conversions to/from FPDF_ types. 117 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc); 118 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc); 119 120 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page); 121 122 void DropContext(void* data); 123 void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable); 124 FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy); 125 void FPDF_RenderPage_Retail(CRenderContext* pContext, 126 FPDF_PAGE page, 127 int start_x, 128 int start_y, 129 int size_x, 130 int size_y, 131 int rotate, 132 int flags, 133 FX_BOOL bNeedToRestore, 134 IFSDK_PAUSE_Adapter* pause); 135 136 void CheckUnSupportError(CPDF_Document* pDoc, FX_DWORD err_code); 137 void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot); 138 void ProcessParseError(FX_DWORD err_code); 139 140 #endif // FPDFSDK_INCLUDE_FSDK_DEFINE_H_ 141