From 9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 4 Aug 2015 13:00:21 -0700 Subject: XFA: clang-format all pdfium code. No behavior change. Generated by: find . -name '*.cpp' -o -name '*.h' | \ grep -E -v 'third_party|thirdparties|lpng_v163|tiff_v403' | \ xargs ../../buildtools/mac/clang-format -i Then manually merged https://codereview.chromium.org/1269223002/ See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion. BUG=none --- core/include/fpdfapi/fpdf_module.h | 145 ++-- core/include/fpdfapi/fpdf_objects.h | 892 ++++++++++------------- core/include/fpdfapi/fpdf_page.h | 308 ++++---- core/include/fpdfapi/fpdf_pageobj.h | 792 +++++++++----------- core/include/fpdfapi/fpdf_parser.h | 1285 +++++++++++++++++---------------- core/include/fpdfapi/fpdf_render.h | 428 +++++------ core/include/fpdfapi/fpdf_resource.h | 1323 ++++++++++++++++------------------ core/include/fpdfapi/fpdf_serial.h | 259 +++---- 8 files changed, 2514 insertions(+), 2918 deletions(-) (limited to 'core/include/fpdfapi') diff --git a/core/include/fpdfapi/fpdf_module.h b/core/include/fpdfapi/fpdf_module.h index 5877e11372..bfa051ed4c 100644 --- a/core/include/fpdfapi/fpdf_module.h +++ b/core/include/fpdfapi/fpdf_module.h @@ -39,110 +39,95 @@ class IPDF_FontMapper; class IPDF_PageModule; class IPDF_RenderModule; -class CPDF_ModuleMgr -{ -public: - static CPDF_ModuleMgr* Get(); - static void Create(); - static void Destroy(); - static const int kFileBufSize = 512; +class CPDF_ModuleMgr { + public: + static CPDF_ModuleMgr* Get(); + static void Create(); + static void Destroy(); + static const int kFileBufSize = 512; - void SetCodecModule(CCodec_ModuleMgr* pModule) - { - m_pCodecModule = pModule; - } - CCodec_ModuleMgr* GetCodecModule() - { - return m_pCodecModule; - } + void SetCodecModule(CCodec_ModuleMgr* pModule) { m_pCodecModule = pModule; } + CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule; } - void InitPageModule(); + void InitPageModule(); - void InitRenderModule(); + void InitRenderModule(); - void SetDownloadCallback(FX_BOOL (*callback)(const FX_CHAR* module_name)); + void SetDownloadCallback(FX_BOOL (*callback)(const FX_CHAR* module_name)); - FX_BOOL DownloadModule(const FX_CHAR* module_name); + FX_BOOL DownloadModule(const FX_CHAR* module_name); - void NotifyModuleAvailable(const FX_CHAR* module_name); + void NotifyModuleAvailable(const FX_CHAR* module_name); - IPDF_RenderModule* GetRenderModule() const - { - return m_pRenderModule.get(); - } + IPDF_RenderModule* GetRenderModule() const { return m_pRenderModule.get(); } - IPDF_PageModule* GetPageModule() const - { - return m_pPageModule.get(); - } + IPDF_PageModule* GetPageModule() const { return m_pPageModule.get(); } - void LoadEmbeddedGB1CMaps(); - void LoadEmbeddedCNS1CMaps(); - void LoadEmbeddedJapan1CMaps(); - void LoadEmbeddedKorea1CMaps(); + void LoadEmbeddedGB1CMaps(); + void LoadEmbeddedCNS1CMaps(); + void LoadEmbeddedJapan1CMaps(); + void LoadEmbeddedKorea1CMaps(); - ICodec_FaxModule* GetFaxModule(); - ICodec_JpegModule* GetJpegModule(); - ICodec_JpxModule* GetJpxModule(); - ICodec_Jbig2Module* GetJbig2Module(); - ICodec_IccModule* GetIccModule(); - ICodec_FlateModule* GetFlateModule(); + ICodec_FaxModule* GetFaxModule(); + ICodec_JpegModule* GetJpegModule(); + ICodec_JpxModule* GetJpxModule(); + ICodec_Jbig2Module* GetJbig2Module(); + ICodec_IccModule* GetIccModule(); + ICodec_FlateModule* GetFlateModule(); - void RegisterSecurityHandler( - const FX_CHAR* name, - CPDF_SecurityHandler* (*CreateHandler)(void* param), - void* param); + void RegisterSecurityHandler( + const FX_CHAR* name, + CPDF_SecurityHandler* (*CreateHandler)(void* param), + void* param); - CPDF_SecurityHandler* CreateSecurityHandler(const FX_CHAR* name); + CPDF_SecurityHandler* CreateSecurityHandler(const FX_CHAR* name); - void SetPrivateData(void* module_id, - void* pData, - PD_CALLBACK_FREEDATA callback); + void SetPrivateData(void* module_id, + void* pData, + PD_CALLBACK_FREEDATA callback); - void* GetPrivateData(void* module_id); + void* GetPrivateData(void* module_id); -private: - CPDF_ModuleMgr(); - ~CPDF_ModuleMgr(); + private: + CPDF_ModuleMgr(); + ~CPDF_ModuleMgr(); - CCodec_ModuleMgr* m_pCodecModule; + CCodec_ModuleMgr* m_pCodecModule; - nonstd::unique_ptr m_pRenderModule; - nonstd::unique_ptr m_pPageModule; + nonstd::unique_ptr m_pRenderModule; + nonstd::unique_ptr m_pPageModule; - FX_BOOL (*m_pDownloadCallback)(const FX_CHAR* module_name); + FX_BOOL (*m_pDownloadCallback)(const FX_CHAR* module_name); - CFX_MapByteStringToPtr m_SecurityHandlerMap; + CFX_MapByteStringToPtr m_SecurityHandlerMap; - CFX_PrivateData m_privateData; + CFX_PrivateData m_privateData; }; -class IPDF_PageModule -{ -public: - virtual ~IPDF_PageModule() {} - - virtual CPDF_DocPageData* CreateDocData(CPDF_Document* pDoc) = 0; - virtual void ReleaseDoc(CPDF_Document*) = 0; - virtual void ClearDoc(CPDF_Document*) = 0; - virtual CPDF_FontGlobals* GetFontGlobals() = 0; - virtual void ClearStockFont(CPDF_Document* pDoc) = 0; - virtual void NotifyCJKAvailable() = 0; - virtual CPDF_ColorSpace* GetStockCS(int family) = 0; +class IPDF_PageModule { + public: + virtual ~IPDF_PageModule() {} + + virtual CPDF_DocPageData* CreateDocData(CPDF_Document* pDoc) = 0; + virtual void ReleaseDoc(CPDF_Document*) = 0; + virtual void ClearDoc(CPDF_Document*) = 0; + virtual CPDF_FontGlobals* GetFontGlobals() = 0; + virtual void ClearStockFont(CPDF_Document* pDoc) = 0; + virtual void NotifyCJKAvailable() = 0; + virtual CPDF_ColorSpace* GetStockCS(int family) = 0; }; -class IPDF_RenderModule -{ -public: - virtual ~IPDF_RenderModule() {} - - virtual CPDF_DocRenderData* CreateDocData(CPDF_Document* pDoc) = 0; - virtual void DestroyDocData(CPDF_DocRenderData*) = 0; - virtual void ClearDocData(CPDF_DocRenderData*) = 0; - virtual CPDF_DocRenderData* GetRenderData() = 0; - virtual CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) = 0; - virtual void DestroyPageCache(CPDF_PageRenderCache*) = 0; - virtual CPDF_RenderConfig* GetConfig() = 0; +class IPDF_RenderModule { + public: + virtual ~IPDF_RenderModule() {} + + virtual CPDF_DocRenderData* CreateDocData(CPDF_Document* pDoc) = 0; + virtual void DestroyDocData(CPDF_DocRenderData*) = 0; + virtual void ClearDocData(CPDF_DocRenderData*) = 0; + virtual CPDF_DocRenderData* GetRenderData() = 0; + virtual CPDF_PageRenderCache* CreatePageCache(CPDF_Page* pPage) = 0; + virtual void DestroyPageCache(CPDF_PageRenderCache*) = 0; + virtual CPDF_RenderConfig* GetConfig() = 0; }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_MODULE_H_ diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index e6336f6511..925f3efaf1 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -26,724 +26,590 @@ class CPDF_StreamFilter; class CPDF_String; class IFX_FileRead; -#define PDFOBJ_INVALID 0 -#define PDFOBJ_BOOLEAN 1 -#define PDFOBJ_NUMBER 2 -#define PDFOBJ_STRING 3 -#define PDFOBJ_NAME 4 -#define PDFOBJ_ARRAY 5 -#define PDFOBJ_DICTIONARY 6 -#define PDFOBJ_STREAM 7 -#define PDFOBJ_NULL 8 -#define PDFOBJ_REFERENCE 9 +#define PDFOBJ_INVALID 0 +#define PDFOBJ_BOOLEAN 1 +#define PDFOBJ_NUMBER 2 +#define PDFOBJ_STRING 3 +#define PDFOBJ_NAME 4 +#define PDFOBJ_ARRAY 5 +#define PDFOBJ_DICTIONARY 6 +#define PDFOBJ_STREAM 7 +#define PDFOBJ_NULL 8 +#define PDFOBJ_REFERENCE 9 -typedef IFX_FileStream* (*FPDF_LPFCloneStreamCallback)(CPDF_Stream *pStream, void* pUserData); -class CPDF_Object -{ -public: +typedef IFX_FileStream* (*FPDF_LPFCloneStreamCallback)(CPDF_Stream* pStream, + void* pUserData); +class CPDF_Object { + public: + int GetType() const { return m_Type; } - int GetType() const - { - return m_Type; - } + FX_DWORD GetObjNum() const { return m_ObjNum; } - FX_DWORD GetObjNum() const - { - return m_ObjNum; - } + FX_DWORD GetGenNum() const { return m_GenNum; } - FX_DWORD GetGenNum() const - { - return m_GenNum; - } + FX_BOOL IsIdentical(CPDF_Object* pObj) const; - FX_BOOL IsIdentical(CPDF_Object* pObj) const; + CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const; - CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const; + CPDF_Object* CloneRef(CPDF_IndirectObjects* pObjs) const; - CPDF_Object* CloneRef(CPDF_IndirectObjects* pObjs) const; + CPDF_Object* GetDirect() const; - CPDF_Object* GetDirect() const; + void Release(); - void Release(); + CFX_ByteString GetString() const; - CFX_ByteString GetString() const; + CFX_ByteStringC GetConstString() const; - CFX_ByteStringC GetConstString() const; + CFX_WideString GetUnicodeText(CFX_CharMap* pCharMap = NULL) const; + FX_FLOAT GetNumber() const; - CFX_WideString GetUnicodeText(CFX_CharMap* pCharMap = NULL) const; - FX_FLOAT GetNumber() const; + FX_FLOAT GetNumber16() const; - FX_FLOAT GetNumber16() const; + int GetInteger() const; - int GetInteger() const; + CPDF_Dictionary* GetDict() const; - CPDF_Dictionary* GetDict() const; + CPDF_Array* GetArray() const; - CPDF_Array* GetArray() const; + void SetString(const CFX_ByteString& str); - void SetString(const CFX_ByteString& str); + void SetUnicodeText(const FX_WCHAR* pUnicodes, int len = -1); - void SetUnicodeText(const FX_WCHAR* pUnicodes, int len = -1); + int GetDirectType() const; - int GetDirectType() const; + FX_BOOL IsModified() const { return FALSE; } - FX_BOOL IsModified() const - { - return FALSE; - } -protected: - CPDF_Object(FX_DWORD type) : m_Type(type), m_ObjNum(0), m_GenNum(0) { } - ~CPDF_Object() { } - void Destroy(); + protected: + CPDF_Object(FX_DWORD type) : m_Type(type), m_ObjNum(0), m_GenNum(0) {} + ~CPDF_Object() {} + void Destroy(); - static const int OBJECT_REF_MAX_DEPTH = 128; - static int s_nCurRefDepth; - FX_DWORD m_Type; - FX_DWORD m_ObjNum; - FX_DWORD m_GenNum; + static const int OBJECT_REF_MAX_DEPTH = 128; + static int s_nCurRefDepth; + FX_DWORD m_Type; + FX_DWORD m_ObjNum; + FX_DWORD m_GenNum; - friend class CPDF_IndirectObjects; - friend class CPDF_Parser; - friend class CPDF_SyntaxParser; -private: - CPDF_Object(const CPDF_Object& src) {} - CPDF_Object* CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visited) const; + friend class CPDF_IndirectObjects; + friend class CPDF_Parser; + friend class CPDF_SyntaxParser; + + private: + CPDF_Object(const CPDF_Object& src) {} + CPDF_Object* CloneInternal(FX_BOOL bDirect, CFX_MapPtrToPtr* visited) const; }; -class CPDF_Boolean : public CPDF_Object -{ -public: - - static CPDF_Boolean* Create(FX_BOOL value) - { - return FX_NEW CPDF_Boolean(value); - } - - CPDF_Boolean() : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(false) { } - CPDF_Boolean(FX_BOOL value) : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(value) { } - - FX_BOOL Identical(CPDF_Boolean* pOther) const - { - return m_bValue == pOther->m_bValue; - } -protected: - - FX_BOOL m_bValue; - friend class CPDF_Object; +class CPDF_Boolean : public CPDF_Object { + public: + static CPDF_Boolean* Create(FX_BOOL value) { + return FX_NEW CPDF_Boolean(value); + } + + CPDF_Boolean() : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(false) {} + CPDF_Boolean(FX_BOOL value) : CPDF_Object(PDFOBJ_BOOLEAN), m_bValue(value) {} + + FX_BOOL Identical(CPDF_Boolean* pOther) const { + return m_bValue == pOther->m_bValue; + } + + protected: + FX_BOOL m_bValue; + friend class CPDF_Object; }; -class CPDF_Number : public CPDF_Object -{ -public: - - static CPDF_Number* Create(int value) - { - return FX_NEW CPDF_Number(value); - } - - static CPDF_Number* Create(FX_FLOAT value) - { - return FX_NEW CPDF_Number(value); - } +class CPDF_Number : public CPDF_Object { + public: + static CPDF_Number* Create(int value) { return FX_NEW CPDF_Number(value); } - static CPDF_Number* Create(const CFX_ByteStringC& str) - { - return FX_NEW CPDF_Number(str); - } + static CPDF_Number* Create(FX_FLOAT value) { + return FX_NEW CPDF_Number(value); + } - static CPDF_Number* Create(FX_BOOL bInteger, void* pData) - { - return FX_NEW CPDF_Number(bInteger, pData); - } + static CPDF_Number* Create(const CFX_ByteStringC& str) { + return FX_NEW CPDF_Number(str); + } - CPDF_Number() : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(false), m_Integer(0) { } + static CPDF_Number* Create(FX_BOOL bInteger, void* pData) { + return FX_NEW CPDF_Number(bInteger, pData); + } - CPDF_Number(FX_BOOL bInteger, void* pData); + CPDF_Number() : CPDF_Object(PDFOBJ_NUMBER), m_bInteger(false), m_Integer(0) {} - CPDF_Number(int value); + CPDF_Number(FX_BOOL bInteger, void* pData); - CPDF_Number(FX_FLOAT value); + CPDF_Number(int value); - CPDF_Number(const CFX_ByteStringC& str); + CPDF_Number(FX_FLOAT value); - FX_BOOL Identical(CPDF_Number* pOther) const; + CPDF_Number(const CFX_ByteStringC& str); - CFX_ByteString GetString() const; + FX_BOOL Identical(CPDF_Number* pOther) const; - void SetString(const CFX_ByteStringC& str); + CFX_ByteString GetString() const; - FX_BOOL IsInteger() const - { - return m_bInteger; - } + void SetString(const CFX_ByteStringC& str); - int GetInteger() const - { - return m_bInteger ? m_Integer : (int)m_Float; - } + FX_BOOL IsInteger() const { return m_bInteger; } - FX_FLOAT GetNumber() const - { - return m_bInteger ? (FX_FLOAT)m_Integer : m_Float; - } + int GetInteger() const { return m_bInteger ? m_Integer : (int)m_Float; } - void SetNumber(FX_FLOAT value); + FX_FLOAT GetNumber() const { + return m_bInteger ? (FX_FLOAT)m_Integer : m_Float; + } - FX_FLOAT GetNumber16() const - { - return GetNumber(); - } + void SetNumber(FX_FLOAT value); - FX_FLOAT GetFloat() const - { - return m_bInteger ? (FX_FLOAT)m_Integer : m_Float; - } -protected: + FX_FLOAT GetNumber16() const { return GetNumber(); } - FX_BOOL m_bInteger; + FX_FLOAT GetFloat() const { + return m_bInteger ? (FX_FLOAT)m_Integer : m_Float; + } - union { + protected: + FX_BOOL m_bInteger; - int m_Integer; + union { + int m_Integer; - FX_FLOAT m_Float; - }; - friend class CPDF_Object; + FX_FLOAT m_Float; + }; + friend class CPDF_Object; }; -class CPDF_String : public CPDF_Object -{ -public: +class CPDF_String : public CPDF_Object { + public: + static CPDF_String* Create(const CFX_ByteString& str, FX_BOOL bHex = FALSE) { + return FX_NEW CPDF_String(str, bHex); + } - static CPDF_String* Create(const CFX_ByteString& str, FX_BOOL bHex = FALSE) - { - return FX_NEW CPDF_String(str, bHex); - } + static CPDF_String* Create(const CFX_WideString& str) { + return FX_NEW CPDF_String(str); + } - static CPDF_String* Create(const CFX_WideString& str) - { - return FX_NEW CPDF_String(str); - } + CPDF_String() : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) {} - CPDF_String() : CPDF_Object(PDFOBJ_STRING), m_bHex(FALSE) { } + CPDF_String(const CFX_ByteString& str, FX_BOOL bHex = FALSE) + : CPDF_Object(PDFOBJ_STRING), m_String(str), m_bHex(bHex) {} - CPDF_String(const CFX_ByteString& str, FX_BOOL bHex = FALSE) - : CPDF_Object(PDFOBJ_STRING), m_String(str), m_bHex(bHex) { - } + CPDF_String(const CFX_WideString& str); - CPDF_String(const CFX_WideString& str); + CFX_ByteString& GetString() { return m_String; } - CFX_ByteString& GetString() - { - return m_String; - } + FX_BOOL Identical(CPDF_String* pOther) const { + return m_String == pOther->m_String; + } - FX_BOOL Identical(CPDF_String* pOther) const - { - return m_String == pOther->m_String; - } + FX_BOOL IsHex() const { return m_bHex; } - FX_BOOL IsHex() const - { - return m_bHex; - } -protected: + protected: + CFX_ByteString m_String; - CFX_ByteString m_String; - - FX_BOOL m_bHex; - friend class CPDF_Object; -}; -class CPDF_Name : public CPDF_Object -{ -public: - - static CPDF_Name* Create(const CFX_ByteString& str) - { - return FX_NEW CPDF_Name(str); - } - - static CPDF_Name* Create(const CFX_ByteStringC& str) - { - return FX_NEW CPDF_Name(str); - } - - static CPDF_Name* Create(const FX_CHAR* str) - { - return FX_NEW CPDF_Name(str); - } - - CPDF_Name(const CFX_ByteString& str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) { } - CPDF_Name(const CFX_ByteStringC& str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) { } - CPDF_Name(const FX_CHAR* str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) { } - - CFX_ByteString& GetString() - { - return m_Name; - } - - FX_BOOL Identical(CPDF_Name* pOther) const - { - return m_Name == pOther->m_Name; - } -protected: - - CFX_ByteString m_Name; - friend class CPDF_Object; + FX_BOOL m_bHex; + friend class CPDF_Object; }; -class CPDF_Array : public CPDF_Object -{ -public: - - static CPDF_Array* Create() - { - return FX_NEW CPDF_Array(); - } - - CPDF_Array() : CPDF_Object(PDFOBJ_ARRAY) { } - - FX_DWORD GetCount() const - { - return m_Objects.GetSize(); - } - - CPDF_Object* GetElement(FX_DWORD index) const; - - CPDF_Object* GetElementValue(FX_DWORD index) const; +class CPDF_Name : public CPDF_Object { + public: + static CPDF_Name* Create(const CFX_ByteString& str) { + return FX_NEW CPDF_Name(str); + } + static CPDF_Name* Create(const CFX_ByteStringC& str) { + return FX_NEW CPDF_Name(str); + } + static CPDF_Name* Create(const FX_CHAR* str) { return FX_NEW CPDF_Name(str); } - CFX_AffineMatrix GetMatrix(); + CPDF_Name(const CFX_ByteString& str) + : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} + CPDF_Name(const CFX_ByteStringC& str) + : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} + CPDF_Name(const FX_CHAR* str) : CPDF_Object(PDFOBJ_NAME), m_Name(str) {} - CFX_FloatRect GetRect(); + CFX_ByteString& GetString() { return m_Name; } + FX_BOOL Identical(CPDF_Name* pOther) const { + return m_Name == pOther->m_Name; + } + protected: + CFX_ByteString m_Name; + friend class CPDF_Object; +}; +class CPDF_Array : public CPDF_Object { + public: + static CPDF_Array* Create() { return FX_NEW CPDF_Array(); } + CPDF_Array() : CPDF_Object(PDFOBJ_ARRAY) {} - CFX_ByteString GetString(FX_DWORD index) const; - - CFX_ByteStringC GetConstString(FX_DWORD index) const; - - int GetInteger(FX_DWORD index) const; - - FX_FLOAT GetNumber(FX_DWORD index) const; + FX_DWORD GetCount() const { return m_Objects.GetSize(); } - CPDF_Dictionary* GetDict(FX_DWORD index) const; + CPDF_Object* GetElement(FX_DWORD index) const; - CPDF_Stream* GetStream(FX_DWORD index) const; + CPDF_Object* GetElementValue(FX_DWORD index) const; - CPDF_Array* GetArray(FX_DWORD index) const; + CFX_AffineMatrix GetMatrix(); - FX_FLOAT GetFloat(FX_DWORD index) const - { - return GetNumber(index); - } + CFX_FloatRect GetRect(); + CFX_ByteString GetString(FX_DWORD index) const; + CFX_ByteStringC GetConstString(FX_DWORD index) const; + int GetInteger(FX_DWORD index) const; - void SetAt(FX_DWORD index, CPDF_Object* pObj, CPDF_IndirectObjects* pObjs = NULL); + FX_FLOAT GetNumber(FX_DWORD index) const; + CPDF_Dictionary* GetDict(FX_DWORD index) const; - void InsertAt(FX_DWORD index, CPDF_Object* pObj, CPDF_IndirectObjects* pObjs = NULL); + CPDF_Stream* GetStream(FX_DWORD index) const; - void RemoveAt(FX_DWORD index); + CPDF_Array* GetArray(FX_DWORD index) const; + FX_FLOAT GetFloat(FX_DWORD index) const { return GetNumber(index); } - void Add(CPDF_Object* pObj, CPDF_IndirectObjects* pObjs = NULL); + void SetAt(FX_DWORD index, + CPDF_Object* pObj, + CPDF_IndirectObjects* pObjs = NULL); + void InsertAt(FX_DWORD index, + CPDF_Object* pObj, + CPDF_IndirectObjects* pObjs = NULL); + void RemoveAt(FX_DWORD index); - void AddNumber(FX_FLOAT f); + void Add(CPDF_Object* pObj, CPDF_IndirectObjects* pObjs = NULL); - void AddInteger(int i); + void AddNumber(FX_FLOAT f); - void AddString(const CFX_ByteString& str); + void AddInteger(int i); - void AddName(const CFX_ByteString& str); + void AddString(const CFX_ByteString& str); - void AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum); + void AddName(const CFX_ByteString& str); - void AddReference(CPDF_IndirectObjects* pDoc, CPDF_Object* obj) - { - AddReference(pDoc, obj->GetObjNum()); - } + void AddReference(CPDF_IndirectObjects* pDoc, FX_DWORD objnum); + void AddReference(CPDF_IndirectObjects* pDoc, CPDF_Object* obj) { + AddReference(pDoc, obj->GetObjNum()); + } - FX_FLOAT GetNumber16(FX_DWORD index) const - { - return GetNumber(index); - } + FX_FLOAT GetNumber16(FX_DWORD index) const { return GetNumber(index); } - void AddNumber16(FX_FLOAT value) - { - AddNumber(value); - } + void AddNumber16(FX_FLOAT value) { AddNumber(value); } - FX_BOOL Identical(CPDF_Array* pOther) const; -protected: + FX_BOOL Identical(CPDF_Array* pOther) const; - ~CPDF_Array(); + protected: + ~CPDF_Array(); - CFX_PtrArray m_Objects; - friend class CPDF_Object; + CFX_PtrArray m_Objects; + friend class CPDF_Object; }; -class CPDF_Dictionary : public CPDF_Object -{ -public: - - static CPDF_Dictionary* Create() - { - return FX_NEW CPDF_Dictionary(); - } - - CPDF_Dictionary() : CPDF_Object(PDFOBJ_DICTIONARY) { } - - CPDF_Object* GetElement(const CFX_ByteStringC& key) const; - - CPDF_Object* GetElementValue(const CFX_ByteStringC& key) const; - +class CPDF_Dictionary : public CPDF_Object { + public: + static CPDF_Dictionary* Create() { return FX_NEW CPDF_Dictionary(); } + CPDF_Dictionary() : CPDF_Object(PDFOBJ_DICTIONARY) {} + CPDF_Object* GetElement(const CFX_ByteStringC& key) const; + CPDF_Object* GetElementValue(const CFX_ByteStringC& key) const; - CFX_ByteString GetString(const CFX_ByteStringC& key) const; + CFX_ByteString GetString(const CFX_ByteStringC& key) const; - CFX_ByteStringC GetConstString(const CFX_ByteStringC& key) const; + CFX_ByteStringC GetConstString(const CFX_ByteStringC& key) const; - CFX_ByteString GetString(const CFX_ByteStringC& key, const CFX_ByteStringC& default_str) const; + CFX_ByteString GetString(const CFX_ByteStringC& key, + const CFX_ByteStringC& default_str) const; - CFX_ByteStringC GetConstString(const CFX_ByteStringC& key, const CFX_ByteStringC& default_str) const; + CFX_ByteStringC GetConstString(const CFX_ByteStringC& key, + const CFX_ByteStringC& default_str) const; - CFX_WideString GetUnicodeText(const CFX_ByteStringC& key, CFX_CharMap* pCharMap = NULL) const; + CFX_WideString GetUnicodeText(const CFX_ByteStringC& key, + CFX_CharMap* pCharMap = NULL) const; - int GetInteger(const CFX_ByteStringC& key) const; + int GetInteger(const CFX_ByteStringC& key) const; - int GetInteger(const CFX_ByteStringC& key, int default_int) const; + int GetInteger(const CFX_ByteStringC& key, int default_int) const; - FX_BOOL GetBoolean(const CFX_ByteStringC& key, FX_BOOL bDefault = FALSE) const; + FX_BOOL GetBoolean(const CFX_ByteStringC& key, + FX_BOOL bDefault = FALSE) const; - FX_FLOAT GetNumber(const CFX_ByteStringC& key) const; + FX_FLOAT GetNumber(const CFX_ByteStringC& key) const; - CPDF_Dictionary* GetDict(const CFX_ByteStringC& key) const; + CPDF_Dictionary* GetDict(const CFX_ByteStringC& key) const; - CPDF_Stream* GetStream(const CFX_ByteStringC& key) const; + CPDF_Stream* GetStream(const CFX_ByteStringC& key) const; - CPDF_Array* GetArray(const CFX_ByteStringC& key) const; + CPDF_Array* GetArray(const CFX_ByteStringC& key) const; - CFX_FloatRect GetRect(const CFX_ByteStringC& key) const; + CFX_FloatRect GetRect(const CFX_ByteStringC& key) const; - CFX_AffineMatrix GetMatrix(const CFX_ByteStringC& key) const; + CFX_AffineMatrix GetMatrix(const CFX_ByteStringC& key) const; - FX_FLOAT GetFloat(const CFX_ByteStringC& key) const - { - return GetNumber(key); - } + FX_FLOAT GetFloat(const CFX_ByteStringC& key) const { return GetNumber(key); } + FX_BOOL KeyExist(const CFX_ByteStringC& key) const; - FX_BOOL KeyExist(const CFX_ByteStringC& key) const; + FX_POSITION GetStartPos() const; - FX_POSITION GetStartPos() const; + CPDF_Object* GetNextElement(FX_POSITION& pos, CFX_ByteString& key) const; - CPDF_Object* GetNextElement(FX_POSITION& pos, CFX_ByteString& key) const; + void SetAt(const CFX_ByteStringC& key, + CPDF_Object* pObj, + CPDF_IndirectObjects* pObjs = NULL); - void SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj, CPDF_IndirectObjects* pObjs = NULL); + void SetAtName(const CFX_ByteStringC& key, const CFX_ByteString& name); + void SetAtString(const CFX_ByteStringC& key, const CFX_ByteString& string); + void SetAtInteger(const CFX_ByteStringC& key, int i); - void SetAtName(const CFX_ByteStringC& key, const CFX_ByteString& name); + void SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f); + void SetAtReference(const CFX_ByteStringC& key, + CPDF_IndirectObjects* pDoc, + FX_DWORD objnum); - void SetAtString(const CFX_ByteStringC& key, const CFX_ByteString& string); + void SetAtReference(const CFX_ByteStringC& key, + CPDF_IndirectObjects* pDoc, + CPDF_Object* obj) { + SetAtReference(key, pDoc, obj->GetObjNum()); + } + void AddReference(const CFX_ByteStringC& key, + CPDF_IndirectObjects* pDoc, + FX_DWORD objnum); - void SetAtInteger(const CFX_ByteStringC& key, int i); + void AddReference(const CFX_ByteStringC& key, + CPDF_IndirectObjects* pDoc, + CPDF_Object* obj) { + AddReference(key, pDoc, obj->GetObjNum()); + } + void SetAtRect(const CFX_ByteStringC& key, const CFX_FloatRect& rect); - void SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f); + void SetAtMatrix(const CFX_ByteStringC& key, const CFX_AffineMatrix& matrix); - void SetAtReference(const CFX_ByteStringC& key, CPDF_IndirectObjects* pDoc, FX_DWORD objnum); + void SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue); - void SetAtReference(const CFX_ByteStringC& key, CPDF_IndirectObjects* pDoc, CPDF_Object* obj) - { - SetAtReference(key, pDoc, obj->GetObjNum()); - } + void RemoveAt(const CFX_ByteStringC& key); - void AddReference(const CFX_ByteStringC& key, CPDF_IndirectObjects* pDoc, FX_DWORD objnum); + void ReplaceKey(const CFX_ByteStringC& oldkey, const CFX_ByteStringC& newkey); - void AddReference(const CFX_ByteStringC& key, CPDF_IndirectObjects* pDoc, CPDF_Object* obj) - { - AddReference(key, pDoc, obj->GetObjNum()); - } + FX_BOOL Identical(CPDF_Dictionary* pDict) const; - void SetAtRect(const CFX_ByteStringC& key, const CFX_FloatRect& rect); + int GetCount() const { return m_Map.GetCount(); } - void SetAtMatrix(const CFX_ByteStringC& key, const CFX_AffineMatrix& matrix); + void AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj); - void SetAtBoolean(const CFX_ByteStringC& key, FX_BOOL bValue); + protected: + ~CPDF_Dictionary(); + CFX_CMapByteStringToPtr m_Map; - - void RemoveAt(const CFX_ByteStringC& key); - - - void ReplaceKey(const CFX_ByteStringC& oldkey, const CFX_ByteStringC& newkey); - - FX_BOOL Identical(CPDF_Dictionary* pDict) const; - - int GetCount() const - { - return m_Map.GetCount(); - } - - void AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj); -protected: - - ~CPDF_Dictionary(); - - CFX_CMapByteStringToPtr m_Map; - - friend class CPDF_Object; + friend class CPDF_Object; }; -class CPDF_Stream : public CPDF_Object -{ -public: - - static CPDF_Stream* Create(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) - { - return FX_NEW CPDF_Stream(pData, size, pDict); - } +class CPDF_Stream : public CPDF_Object { + public: + static CPDF_Stream* Create(uint8_t* pData, + FX_DWORD size, + CPDF_Dictionary* pDict) { + return FX_NEW CPDF_Stream(pData, size, pDict); + } - CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict); + CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict); - CPDF_Dictionary* GetDict() const - { - return m_pDict; - } + CPDF_Dictionary* GetDict() const { return m_pDict; } - void SetData(const uint8_t* pData, FX_DWORD size, FX_BOOL bCompressed, FX_BOOL bKeepBuf); + void SetData(const uint8_t* pData, + FX_DWORD size, + FX_BOOL bCompressed, + FX_BOOL bKeepBuf); - void InitStream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict); + void InitStream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict); - void InitStream(IFX_FileRead *pFile, CPDF_Dictionary* pDict); + void InitStream(IFX_FileRead* pFile, CPDF_Dictionary* pDict); - FX_BOOL Identical(CPDF_Stream* pOther) const; + FX_BOOL Identical(CPDF_Stream* pOther) const; - CPDF_StreamFilter* GetStreamFilter(FX_BOOL bRaw = FALSE) const; + CPDF_StreamFilter* GetStreamFilter(FX_BOOL bRaw = FALSE) const; + FX_DWORD GetRawSize() const { return m_dwSize; } + FX_BOOL ReadRawData(FX_FILESIZE start_pos, + uint8_t* pBuf, + FX_DWORD buf_size) const; - FX_DWORD GetRawSize() const - { - return m_dwSize; - } + FX_BOOL IsMemoryBased() const { return m_GenNum == (FX_DWORD)-1; } - FX_BOOL ReadRawData(FX_FILESIZE start_pos, uint8_t* pBuf, FX_DWORD buf_size) const; + CPDF_Stream* Clone(FX_BOOL bDirect, + FPDF_LPFCloneStreamCallback lpfCallback, + void* pUserData) const; + protected: + ~CPDF_Stream(); - FX_BOOL IsMemoryBased() const - { - return m_GenNum == (FX_DWORD) - 1; - } + CPDF_Dictionary* m_pDict; - CPDF_Stream* Clone(FX_BOOL bDirect, FPDF_LPFCloneStreamCallback lpfCallback, void* pUserData) const; -protected: + FX_DWORD m_dwSize; - ~CPDF_Stream(); + FX_DWORD m_GenNum; - CPDF_Dictionary* m_pDict; + union { + uint8_t* m_pDataBuf; - FX_DWORD m_dwSize; + IFX_FileRead* m_pFile; + }; - FX_DWORD m_GenNum; + FX_FILESIZE m_FileOffset; - union { + CPDF_CryptoHandler* m_pCryptoHandler; - uint8_t* m_pDataBuf; - - IFX_FileRead* m_pFile; - }; - - FX_FILESIZE m_FileOffset; - - CPDF_CryptoHandler* m_pCryptoHandler; - - void InitStream(CPDF_Dictionary* pDict); - friend class CPDF_Object; - friend class CPDF_StreamAcc; - friend class CPDF_AttachmentAcc; + void InitStream(CPDF_Dictionary* pDict); + friend class CPDF_Object; + friend class CPDF_StreamAcc; + friend class CPDF_AttachmentAcc; }; -class CPDF_StreamAcc -{ -public: - - CPDF_StreamAcc(); +class CPDF_StreamAcc { + public: + CPDF_StreamAcc(); - ~CPDF_StreamAcc(); + ~CPDF_StreamAcc(); - void LoadAllData(const CPDF_Stream* pStream, FX_BOOL bRawAccess = FALSE, - FX_DWORD estimated_size = 0, FX_BOOL bImageAcc = FALSE); + void LoadAllData(const CPDF_Stream* pStream, + FX_BOOL bRawAccess = FALSE, + FX_DWORD estimated_size = 0, + FX_BOOL bImageAcc = FALSE); - const CPDF_Stream* GetStream() const - { - return m_pStream; - } + const CPDF_Stream* GetStream() const { return m_pStream; } - CPDF_Dictionary* GetDict() const - { - return m_pStream? m_pStream->GetDict() : NULL; - } + CPDF_Dictionary* GetDict() const { + return m_pStream ? m_pStream->GetDict() : NULL; + } - const uint8_t* GetData() const; + const uint8_t* GetData() const; - FX_DWORD GetSize() const; + FX_DWORD GetSize() const; - uint8_t* DetachData(); + uint8_t* DetachData(); - const CFX_ByteString& GetImageDecoder() - { - return m_ImageDecoder; - } + const CFX_ByteString& GetImageDecoder() { return m_ImageDecoder; } - const CPDF_Dictionary* GetImageParam() - { - return m_pImageParam; - } -protected: + const CPDF_Dictionary* GetImageParam() { return m_pImageParam; } - uint8_t* m_pData; + protected: + uint8_t* m_pData; - FX_DWORD m_dwSize; + FX_DWORD m_dwSize; - FX_BOOL m_bNewBuf; + FX_BOOL m_bNewBuf; - CFX_ByteString m_ImageDecoder; + CFX_ByteString m_ImageDecoder; - CPDF_Dictionary* m_pImageParam; + CPDF_Dictionary* m_pImageParam; - const CPDF_Stream* m_pStream; + const CPDF_Stream* m_pStream; - uint8_t* m_pSrcData; + uint8_t* m_pSrcData; }; -CFX_DataFilter* FPDF_CreateFilter(const CFX_ByteStringC& name, const CPDF_Dictionary* pParam, int width = 0, int height = 0); -#define FPDF_FILTER_BUFFER_SIZE 20480 -class CPDF_StreamFilter -{ -public: +CFX_DataFilter* FPDF_CreateFilter(const CFX_ByteStringC& name, + const CPDF_Dictionary* pParam, + int width = 0, + int height = 0); +#define FPDF_FILTER_BUFFER_SIZE 20480 +class CPDF_StreamFilter { + public: + ~CPDF_StreamFilter(); - ~CPDF_StreamFilter(); + FX_DWORD ReadBlock(uint8_t* buffer, FX_DWORD size); - FX_DWORD ReadBlock(uint8_t* buffer, FX_DWORD size); + FX_DWORD GetSrcPos() { return m_SrcOffset; } - FX_DWORD GetSrcPos() - { - return m_SrcOffset; - } + const CPDF_Stream* GetStream() { return m_pStream; } - const CPDF_Stream* GetStream() - { - return m_pStream; - } -protected: + protected: + CPDF_StreamFilter() {} - CPDF_StreamFilter() {} + FX_DWORD ReadLeftOver(uint8_t* buffer, FX_DWORD buf_size); - FX_DWORD ReadLeftOver(uint8_t* buffer, FX_DWORD buf_size); + const CPDF_Stream* m_pStream; - const CPDF_Stream* m_pStream; + CFX_DataFilter* m_pFilter; - CFX_DataFilter* m_pFilter; + CFX_BinaryBuf* m_pBuffer; - CFX_BinaryBuf* m_pBuffer; + FX_DWORD m_BufOffset; - FX_DWORD m_BufOffset; + FX_DWORD m_SrcOffset; - FX_DWORD m_SrcOffset; - - uint8_t m_SrcBuffer[FPDF_FILTER_BUFFER_SIZE]; - friend class CPDF_Stream; + uint8_t m_SrcBuffer[FPDF_FILTER_BUFFER_SIZE]; + friend class CPDF_Stream; }; -class CPDF_Null : public CPDF_Object -{ -public: - - static CPDF_Null* Create() - { - return FX_NEW CPDF_Null(); - } +class CPDF_Null : public CPDF_Object { + public: + static CPDF_Null* Create() { return FX_NEW CPDF_Null(); } - CPDF_Null() : CPDF_Object(PDFOBJ_NULL) { } + CPDF_Null() : CPDF_Object(PDFOBJ_NULL) {} }; -class CPDF_Reference : public CPDF_Object -{ -public: +class CPDF_Reference : public CPDF_Object { + public: + static CPDF_Reference* Create(CPDF_IndirectObjects* pDoc, int objnum) { + return FX_NEW CPDF_Reference(pDoc, objnum); + } - static CPDF_Reference* Create(CPDF_IndirectObjects* pDoc, int objnum) - { - return FX_NEW CPDF_Reference(pDoc, objnum); - } + CPDF_Reference(CPDF_IndirectObjects* pDoc, int objnum) + : CPDF_Object(PDFOBJ_REFERENCE), m_pObjList(pDoc), m_RefObjNum(objnum) {} - CPDF_Reference(CPDF_IndirectObjects* pDoc, int objnum) - : CPDF_Object(PDFOBJ_REFERENCE), m_pObjList(pDoc), m_RefObjNum(objnum) { - } + CPDF_IndirectObjects* GetObjList() const { return m_pObjList; } - CPDF_IndirectObjects* GetObjList() const - { - return m_pObjList; - } + FX_DWORD GetRefObjNum() const { return m_RefObjNum; } - FX_DWORD GetRefObjNum() const - { - return m_RefObjNum; - } + void SetRef(CPDF_IndirectObjects* pDoc, FX_DWORD objnum); - void SetRef(CPDF_IndirectObjects* pDoc, FX_DWORD objnum); + FX_BOOL Identical(CPDF_Reference* pOther) const { + return m_RefObjNum == pOther->m_RefObjNum; + } - FX_BOOL Identical(CPDF_Reference* pOther) const - { - return m_RefObjNum == pOther->m_RefObjNum; - } -protected: + protected: + CPDF_IndirectObjects* m_pObjList; - CPDF_IndirectObjects* m_pObjList; - - FX_DWORD m_RefObjNum; - friend class CPDF_Object; + FX_DWORD m_RefObjNum; + friend class CPDF_Object; }; -class CPDF_IndirectObjects -{ -public: - - CPDF_IndirectObjects(CPDF_Parser* pParser); +class CPDF_IndirectObjects { + public: + CPDF_IndirectObjects(CPDF_Parser* pParser); - ~CPDF_IndirectObjects(); + ~CPDF_IndirectObjects(); - CPDF_Object* GetIndirectObject(FX_DWORD objnum, struct PARSE_CONTEXT* pContext = NULL); + CPDF_Object* GetIndirectObject(FX_DWORD objnum, + struct PARSE_CONTEXT* pContext = NULL); - int GetIndirectType(FX_DWORD objnum); + int GetIndirectType(FX_DWORD objnum); - FX_DWORD AddIndirectObject(CPDF_Object* pObj); + FX_DWORD AddIndirectObject(CPDF_Object* pObj); - void ReleaseIndirectObject(FX_DWORD objnum); + void ReleaseIndirectObject(FX_DWORD objnum); - void InsertIndirectObject(FX_DWORD objnum, CPDF_Object* pObj); + void InsertIndirectObject(FX_DWORD objnum, CPDF_Object* pObj); - FX_DWORD GetLastObjNum() const; + FX_DWORD GetLastObjNum() const; - FX_POSITION GetStartPosition() const - { - return m_IndirectObjs.GetStartPosition(); - } + FX_POSITION GetStartPosition() const { + return m_IndirectObjs.GetStartPosition(); + } - void GetNextAssoc(FX_POSITION& rPos, FX_DWORD& objnum, CPDF_Object*& pObject) const - { - m_IndirectObjs.GetNextAssoc(rPos, (void*&)objnum, (void*&)pObject); - } -protected: + void GetNextAssoc(FX_POSITION& rPos, + FX_DWORD& objnum, + CPDF_Object*& pObject) const { + m_IndirectObjs.GetNextAssoc(rPos, (void*&)objnum, (void*&)pObject); + } - CFX_MapPtrToPtr m_IndirectObjs; + protected: + CFX_MapPtrToPtr m_IndirectObjs; - CPDF_Parser* m_pParser; + CPDF_Parser* m_pParser; - FX_DWORD m_LastObjNum; + FX_DWORD m_LastObjNum; }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ diff --git a/core/include/fpdfapi/fpdf_page.h b/core/include/fpdfapi/fpdf_page.h index bd8b5c9878..5f716b2c2e 100644 --- a/core/include/fpdfapi/fpdf_page.h +++ b/core/include/fpdfapi/fpdf_page.h @@ -21,202 +21,182 @@ class CPDF_StreamFilter; class CPDF_AllStates; class CPDF_ContentParser; class CPDF_StreamContentParser; -#define PDFTRANS_GROUP 0x0100 -#define PDFTRANS_ISOLATED 0x0200 -#define PDFTRANS_KNOCKOUT 0x0400 - -class CPDF_PageObjects -{ -public: - CPDF_PageObjects(FX_BOOL bReleaseMembers = TRUE); - ~CPDF_PageObjects(); - - void ContinueParse(IFX_Pause* pPause); - - FX_BOOL IsParsed() const - { - return m_ParseState == CONTENT_PARSED; - } - - FX_POSITION GetFirstObjectPosition() const - { - return m_ObjectList.GetHeadPosition(); - } - - FX_POSITION GetLastObjectPosition() const - { - return m_ObjectList.GetTailPosition(); - } - - CPDF_PageObject* GetNextObject(FX_POSITION& pos) const - { - return (CPDF_PageObject*)m_ObjectList.GetNext(pos); - } - - CPDF_PageObject* GetPrevObject(FX_POSITION& pos) const - { - return (CPDF_PageObject*)m_ObjectList.GetPrev(pos); - } - - CPDF_PageObject* GetObjectAt(FX_POSITION pos) const - { - return (CPDF_PageObject*)m_ObjectList.GetAt(pos); - } - - FX_DWORD CountObjects() const - { - return m_ObjectList.GetCount(); - } - - int GetObjectIndex(CPDF_PageObject* pObj) const; - - CPDF_PageObject* GetObjectByIndex(int index) const; - - FX_POSITION InsertObject(FX_POSITION posInsertAfter, CPDF_PageObject* pNewObject); - - void Transform(const CFX_AffineMatrix& matrix); - - FX_BOOL BackgroundAlphaNeeded() const - { - return m_bBackgroundAlphaNeeded; - } - - CFX_FloatRect CalcBoundingBox() const; - - CPDF_Dictionary* m_pFormDict; - CPDF_Stream* m_pFormStream; - CPDF_Document* m_pDocument; - CPDF_Dictionary* m_pPageResources; - CPDF_Dictionary* m_pResources; - CFX_FloatRect m_BBox; - int m_Transparency; - -protected: - friend class CPDF_ContentParser; - friend class CPDF_StreamContentParser; - friend class CPDF_AllStates; - - enum ParseState { - CONTENT_NOT_PARSED, - CONTENT_PARSING, - CONTENT_PARSED - }; - - void LoadTransInfo(); - void ClearCacheObjects(); - - CFX_PtrList m_ObjectList; - FX_BOOL m_bBackgroundAlphaNeeded; - FX_BOOL m_bReleaseMembers; - CPDF_ContentParser* m_pParser; - ParseState m_ParseState; -}; - -class CPDF_Page : public CPDF_PageObjects, public CFX_PrivateData -{ -public: +#define PDFTRANS_GROUP 0x0100 +#define PDFTRANS_ISOLATED 0x0200 +#define PDFTRANS_KNOCKOUT 0x0400 - CPDF_Page(); +class CPDF_PageObjects { + public: + CPDF_PageObjects(FX_BOOL bReleaseMembers = TRUE); + ~CPDF_PageObjects(); - ~CPDF_Page(); + void ContinueParse(IFX_Pause* pPause); - void Load(CPDF_Document* pDocument, CPDF_Dictionary* pPageDict, FX_BOOL bPageCache = TRUE); + FX_BOOL IsParsed() const { return m_ParseState == CONTENT_PARSED; } - void StartParse(CPDF_ParseOptions* pOptions = NULL, FX_BOOL bReParse = FALSE); + FX_POSITION GetFirstObjectPosition() const { + return m_ObjectList.GetHeadPosition(); + } - void ParseContent(CPDF_ParseOptions* pOptions = NULL, FX_BOOL bReParse = FALSE); + FX_POSITION GetLastObjectPosition() const { + return m_ObjectList.GetTailPosition(); + } - void GetDisplayMatrix(CFX_AffineMatrix& matrix, int xPos, int yPos, - int xSize, int ySize, int iRotate) const; + CPDF_PageObject* GetNextObject(FX_POSITION& pos) const { + return (CPDF_PageObject*)m_ObjectList.GetNext(pos); + } - FX_FLOAT GetPageWidth() const - { - return m_PageWidth; - } + CPDF_PageObject* GetPrevObject(FX_POSITION& pos) const { + return (CPDF_PageObject*)m_ObjectList.GetPrev(pos); + } - FX_FLOAT GetPageHeight() const - { - return m_PageHeight; - } + CPDF_PageObject* GetObjectAt(FX_POSITION pos) const { + return (CPDF_PageObject*)m_ObjectList.GetAt(pos); + } - CFX_FloatRect GetPageBBox() const - { - return m_BBox; - } + FX_DWORD CountObjects() const { return m_ObjectList.GetCount(); } - const CFX_AffineMatrix& GetPageMatrix() const - { - return m_PageMatrix; - } + int GetObjectIndex(CPDF_PageObject* pObj) const; - CPDF_Object* GetPageAttr(const CFX_ByteStringC& name) const; + CPDF_PageObject* GetObjectByIndex(int index) const; + FX_POSITION InsertObject(FX_POSITION posInsertAfter, + CPDF_PageObject* pNewObject); + void Transform(const CFX_AffineMatrix& matrix); - CPDF_PageRenderCache* GetRenderCache() const - { - return m_pPageRender; - } + FX_BOOL BackgroundAlphaNeeded() const { return m_bBackgroundAlphaNeeded; } - void ClearRenderCache(); + CFX_FloatRect CalcBoundingBox() const; -protected: - friend class CPDF_ContentParser; + CPDF_Dictionary* m_pFormDict; + CPDF_Stream* m_pFormStream; + CPDF_Document* m_pDocument; + CPDF_Dictionary* m_pPageResources; + CPDF_Dictionary* m_pResources; + CFX_FloatRect m_BBox; + int m_Transparency; - FX_FLOAT m_PageWidth; + protected: + friend class CPDF_ContentParser; + friend class CPDF_StreamContentParser; + friend class CPDF_AllStates; - FX_FLOAT m_PageHeight; + enum ParseState { CONTENT_NOT_PARSED, CONTENT_PARSING, CONTENT_PARSED }; - CFX_AffineMatrix m_PageMatrix; + void LoadTransInfo(); + void ClearCacheObjects(); - CPDF_PageRenderCache* m_pPageRender; + CFX_PtrList m_ObjectList; + FX_BOOL m_bBackgroundAlphaNeeded; + FX_BOOL m_bReleaseMembers; + CPDF_ContentParser* m_pParser; + ParseState m_ParseState; }; -class CPDF_ParseOptions -{ -public: - CPDF_ParseOptions(); +class CPDF_Page : public CPDF_PageObjects, public CFX_PrivateData { + public: + CPDF_Page(); - FX_BOOL m_bTextOnly; + ~CPDF_Page(); - FX_BOOL m_bMarkedContent; + void Load(CPDF_Document* pDocument, + CPDF_Dictionary* pPageDict, + FX_BOOL bPageCache = TRUE); - FX_BOOL m_bSeparateForm; + void StartParse(CPDF_ParseOptions* pOptions = NULL, FX_BOOL bReParse = FALSE); - FX_BOOL m_bDecodeInlineImage; -}; -class CPDF_Form : public CPDF_PageObjects -{ -public: + void ParseContent(CPDF_ParseOptions* pOptions = NULL, + FX_BOOL bReParse = FALSE); + + void GetDisplayMatrix(CFX_AffineMatrix& matrix, + int xPos, + int yPos, + int xSize, + int ySize, + int iRotate) const; + + FX_FLOAT GetPageWidth() const { return m_PageWidth; } + + FX_FLOAT GetPageHeight() const { return m_PageHeight; } + + CFX_FloatRect GetPageBBox() const { return m_BBox; } + + const CFX_AffineMatrix& GetPageMatrix() const { return m_PageMatrix; } + + CPDF_Object* GetPageAttr(const CFX_ByteStringC& name) const; - CPDF_Form(CPDF_Document* pDocument, CPDF_Dictionary* pPageResources, CPDF_Stream* pFormStream, CPDF_Dictionary* pParentResources = NULL); + CPDF_PageRenderCache* GetRenderCache() const { return m_pPageRender; } - ~CPDF_Form(); + void ClearRenderCache(); - void StartParse(CPDF_AllStates* pGraphicStates, CFX_AffineMatrix* pParentMatrix, - CPDF_Type3Char* pType3Char, CPDF_ParseOptions* pOptions, int level = 0); + protected: + friend class CPDF_ContentParser; - void ParseContent(CPDF_AllStates* pGraphicStates, CFX_AffineMatrix* pParentMatrix, - CPDF_Type3Char* pType3Char, CPDF_ParseOptions* pOptions, int level = 0); + FX_FLOAT m_PageWidth; - CPDF_Form* Clone() const; + FX_FLOAT m_PageHeight; + + CFX_AffineMatrix m_PageMatrix; + + CPDF_PageRenderCache* m_pPageRender; +}; +class CPDF_ParseOptions { + public: + CPDF_ParseOptions(); + + FX_BOOL m_bTextOnly; + + FX_BOOL m_bMarkedContent; + + FX_BOOL m_bSeparateForm; + + FX_BOOL m_bDecodeInlineImage; +}; +class CPDF_Form : public CPDF_PageObjects { + public: + CPDF_Form(CPDF_Document* pDocument, + CPDF_Dictionary* pPageResources, + CPDF_Stream* pFormStream, + CPDF_Dictionary* pParentResources = NULL); + + ~CPDF_Form(); + + void StartParse(CPDF_AllStates* pGraphicStates, + CFX_AffineMatrix* pParentMatrix, + CPDF_Type3Char* pType3Char, + CPDF_ParseOptions* pOptions, + int level = 0); + + void ParseContent(CPDF_AllStates* pGraphicStates, + CFX_AffineMatrix* pParentMatrix, + CPDF_Type3Char* pType3Char, + CPDF_ParseOptions* pOptions, + int level = 0); + + CPDF_Form* Clone() const; }; -class CPDF_PageContentGenerate -{ -public: - CPDF_PageContentGenerate(CPDF_Page* pPage); - ~CPDF_PageContentGenerate(); - FX_BOOL InsertPageObject(CPDF_PageObject* pPageObject); - void GenerateContent(); - void TransformContent(CFX_Matrix& matrix); -protected: - void ProcessImage(CFX_ByteTextBuf& buf, CPDF_ImageObject* pImageObj); - void ProcessForm(CFX_ByteTextBuf& buf, const uint8_t* data, FX_DWORD size, CFX_Matrix& matrix); - CFX_ByteString RealizeResource(CPDF_Object* pResourceObj, const FX_CHAR* szType); -private: - CPDF_Page* m_pPage; - CPDF_Document* m_pDocument; - CFX_PtrArray m_pageObjects; +class CPDF_PageContentGenerate { + public: + CPDF_PageContentGenerate(CPDF_Page* pPage); + ~CPDF_PageContentGenerate(); + FX_BOOL InsertPageObject(CPDF_PageObject* pPageObject); + void GenerateContent(); + void TransformContent(CFX_Matrix& matrix); + + protected: + void ProcessImage(CFX_ByteTextBuf& buf, CPDF_ImageObject* pImageObj); + void ProcessForm(CFX_ByteTextBuf& buf, + const uint8_t* data, + FX_DWORD size, + CFX_Matrix& matrix); + CFX_ByteString RealizeResource(CPDF_Object* pResourceObj, + const FX_CHAR* szType); + + private: + CPDF_Page* m_pPage; + CPDF_Document* m_pDocument; + CFX_PtrArray m_pageObjects; }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_PAGE_H_ diff --git a/core/include/fpdfapi/fpdf_pageobj.h b/core/include/fpdfapi/fpdf_pageobj.h index 73540a3eb3..be81244ef4 100644 --- a/core/include/fpdfapi/fpdf_pageobj.h +++ b/core/include/fpdfapi/fpdf_pageobj.h @@ -31,672 +31,540 @@ class CPDF_ShadingObject; class CPDF_FormObject; typedef CFX_PathData CPDF_PathData; -class CPDF_Path : public CFX_CountRef -{ -public: - int GetPointCount() - { - return m_pObject->m_PointCount; - } - - int GetFlag(int index) - { - return m_pObject->m_pPoints[index].m_Flag; - } - - FX_FLOAT GetPointX(int index) - { - return m_pObject->m_pPoints[index].m_PointX; - } - - FX_FLOAT GetPointY(int index) - { - return m_pObject->m_pPoints[index].m_PointY; - } - - - - - FX_PATHPOINT* GetPoints() - { - return m_pObject->m_pPoints; - } - - - CFX_FloatRect GetBoundingBox() const - { - return m_pObject->GetBoundingBox(); - } - - CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, FX_FLOAT miter_limit) const - { - return m_pObject->GetBoundingBox(line_width, miter_limit); - } - - void Transform(const CFX_AffineMatrix* pMatrix) - { - GetModify()->Transform(pMatrix); - } - - void Append(CPDF_Path src, const CFX_AffineMatrix* pMatrix) - { - m_pObject->Append(src.m_pObject, pMatrix); - } - - void AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top) - { - m_pObject->AppendRect(left, bottom, right, top); - } - - FX_BOOL IsRect() const - { - return m_pObject->IsRect(); - } -}; -class CPDF_ClipPathData -{ -public: +class CPDF_Path : public CFX_CountRef { + public: + int GetPointCount() { return m_pObject->m_PointCount; } + + int GetFlag(int index) { return m_pObject->m_pPoints[index].m_Flag; } - CPDF_ClipPathData(); + FX_FLOAT GetPointX(int index) { return m_pObject->m_pPoints[index].m_PointX; } - CPDF_ClipPathData(const CPDF_ClipPathData&); + FX_FLOAT GetPointY(int index) { return m_pObject->m_pPoints[index].m_PointY; } - ~CPDF_ClipPathData(); + FX_PATHPOINT* GetPoints() { return m_pObject->m_pPoints; } - void SetCount(int path_count, int text_count); -public: + CFX_FloatRect GetBoundingBox() const { return m_pObject->GetBoundingBox(); } - int m_PathCount; + CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, + FX_FLOAT miter_limit) const { + return m_pObject->GetBoundingBox(line_width, miter_limit); + } - CPDF_Path* m_pPathList; + void Transform(const CFX_AffineMatrix* pMatrix) { + GetModify()->Transform(pMatrix); + } - uint8_t* m_pTypeList; + void Append(CPDF_Path src, const CFX_AffineMatrix* pMatrix) { + m_pObject->Append(src.m_pObject, pMatrix); + } - int m_TextCount; + void AppendRect(FX_FLOAT left, + FX_FLOAT bottom, + FX_FLOAT right, + FX_FLOAT top) { + m_pObject->AppendRect(left, bottom, right, top); + } - CPDF_TextObject** m_pTextList; + FX_BOOL IsRect() const { return m_pObject->IsRect(); } }; -class CPDF_ClipPath : public CFX_CountRef -{ -public: +class CPDF_ClipPathData { + public: + CPDF_ClipPathData(); - FX_DWORD GetPathCount() const - { - return m_pObject->m_PathCount; - } + CPDF_ClipPathData(const CPDF_ClipPathData&); - CPDF_Path GetPath(int i) const - { - return m_pObject->m_pPathList[i]; - } + ~CPDF_ClipPathData(); - int GetClipType(int i) const - { - return m_pObject->m_pTypeList[i]; - } + void SetCount(int path_count, int text_count); - FX_DWORD GetTextCount() const - { - return m_pObject->m_TextCount; - } + public: + int m_PathCount; - CPDF_TextObject* GetText(int i) const - { - return m_pObject->m_pTextList[i]; - } + CPDF_Path* m_pPathList; - CFX_FloatRect GetClipBox() const; + uint8_t* m_pTypeList; - void AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge); + int m_TextCount; - void DeletePath(int layer_index); + CPDF_TextObject** m_pTextList; +}; +class CPDF_ClipPath : public CFX_CountRef { + public: + FX_DWORD GetPathCount() const { return m_pObject->m_PathCount; } - void AppendTexts(CPDF_TextObject** pTexts, int count); + CPDF_Path GetPath(int i) const { return m_pObject->m_pPathList[i]; } - void Transform(const CFX_AffineMatrix& matrix); -}; -class CPDF_ColorStateData -{ -public: + int GetClipType(int i) const { return m_pObject->m_pTypeList[i]; } - CPDF_ColorStateData(): m_FillRGB(0), m_StrokeRGB(0) {} + FX_DWORD GetTextCount() const { return m_pObject->m_TextCount; } - CPDF_ColorStateData(const CPDF_ColorStateData& src); + CPDF_TextObject* GetText(int i) const { return m_pObject->m_pTextList[i]; } - void Default(); + CFX_FloatRect GetClipBox() const; - CPDF_Color m_FillColor; + void AppendPath(CPDF_Path path, int type, FX_BOOL bAutoMerge); - FX_DWORD m_FillRGB; + void DeletePath(int layer_index); - CPDF_Color m_StrokeColor; + void AppendTexts(CPDF_TextObject** pTexts, int count); - FX_DWORD m_StrokeRGB; + void Transform(const CFX_AffineMatrix& matrix); }; -class CPDF_ColorState : public CFX_CountRef -{ -public: +class CPDF_ColorStateData { + public: + CPDF_ColorStateData() : m_FillRGB(0), m_StrokeRGB(0) {} - CPDF_Color* GetFillColor() const - { - return m_pObject ? &m_pObject->m_FillColor : NULL; - } + CPDF_ColorStateData(const CPDF_ColorStateData& src); - CPDF_Color* GetStrokeColor() const - { - return m_pObject ? &m_pObject->m_StrokeColor : NULL; - } + void Default(); - void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); + CPDF_Color m_FillColor; - void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); + FX_DWORD m_FillRGB; - void SetFillPattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); + CPDF_Color m_StrokeColor; - void SetStrokePattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); -private: - void SetColor(CPDF_Color& color, FX_DWORD& rgb, CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); -}; -typedef CFX_GraphStateData CPDF_GraphStateData; -class CPDF_GraphState : public CFX_CountRef -{ -public: + FX_DWORD m_StrokeRGB; }; -class CPDF_TextStateData -{ -public: +class CPDF_ColorState : public CFX_CountRef { + public: + CPDF_Color* GetFillColor() const { + return m_pObject ? &m_pObject->m_FillColor : NULL; + } - CPDF_TextStateData(); + CPDF_Color* GetStrokeColor() const { + return m_pObject ? &m_pObject->m_StrokeColor : NULL; + } - CPDF_TextStateData(const CPDF_TextStateData& src); + void SetFillColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); - ~CPDF_TextStateData(); + void SetStrokeColor(CPDF_ColorSpace* pCS, FX_FLOAT* pValue, int nValues); - CPDF_Font* m_pFont; + void SetFillPattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); - CPDF_Document* m_pDocument; + void SetStrokePattern(CPDF_Pattern* pattern, FX_FLOAT* pValue, int nValues); - FX_FLOAT m_FontSize; + private: + void SetColor(CPDF_Color& color, + FX_DWORD& rgb, + CPDF_ColorSpace* pCS, + FX_FLOAT* pValue, + int nValues); +}; +typedef CFX_GraphStateData CPDF_GraphStateData; +class CPDF_GraphState : public CFX_CountRef { + public: +}; +class CPDF_TextStateData { + public: + CPDF_TextStateData(); - FX_FLOAT m_CharSpace; + CPDF_TextStateData(const CPDF_TextStateData& src); - FX_FLOAT m_WordSpace; + ~CPDF_TextStateData(); - FX_FLOAT m_Matrix[4]; + CPDF_Font* m_pFont; - int m_TextMode; + CPDF_Document* m_pDocument; - FX_FLOAT m_CTM[4]; -}; -class CPDF_TextState : public CFX_CountRef -{ -public: + FX_FLOAT m_FontSize; + + FX_FLOAT m_CharSpace; - CPDF_Font* GetFont() const - { - return m_pObject->m_pFont; - } + FX_FLOAT m_WordSpace; - void SetFont(CPDF_Font* pFont); + FX_FLOAT m_Matrix[4]; - FX_FLOAT GetFontSize() const - { - return m_pObject->m_FontSize; - } + int m_TextMode; - FX_FLOAT* GetMatrix() const - { - return m_pObject->m_Matrix; - } + FX_FLOAT m_CTM[4]; +}; +class CPDF_TextState : public CFX_CountRef { + public: + CPDF_Font* GetFont() const { return m_pObject->m_pFont; } + void SetFont(CPDF_Font* pFont); + FX_FLOAT GetFontSize() const { return m_pObject->m_FontSize; } - FX_FLOAT GetFontSizeV() const; + FX_FLOAT* GetMatrix() const { return m_pObject->m_Matrix; } - FX_FLOAT GetFontSizeH() const; + FX_FLOAT GetFontSizeV() const; - FX_FLOAT GetBaselineAngle() const; + FX_FLOAT GetFontSizeH() const; - FX_FLOAT GetShearAngle() const; + FX_FLOAT GetBaselineAngle() const; + FX_FLOAT GetShearAngle() const; }; class CPDF_TransferFunc; -class CPDF_GeneralStateData -{ -public: - - CPDF_GeneralStateData(); +class CPDF_GeneralStateData { + public: + CPDF_GeneralStateData(); - CPDF_GeneralStateData(const CPDF_GeneralStateData& src); - ~CPDF_GeneralStateData(); + CPDF_GeneralStateData(const CPDF_GeneralStateData& src); + ~CPDF_GeneralStateData(); - void SetBlendMode(const CFX_ByteStringC& blend_mode); + void SetBlendMode(const CFX_ByteStringC& blend_mode); - char m_BlendMode[16]; + char m_BlendMode[16]; - int m_BlendType; + int m_BlendType; - CPDF_Object* m_pSoftMask; + CPDF_Object* m_pSoftMask; - FX_FLOAT m_SMaskMatrix[6]; + FX_FLOAT m_SMaskMatrix[6]; - FX_FLOAT m_StrokeAlpha; + FX_FLOAT m_StrokeAlpha; - FX_FLOAT m_FillAlpha; + FX_FLOAT m_FillAlpha; - CPDF_Object* m_pTR; + CPDF_Object* m_pTR; - CPDF_TransferFunc* m_pTransferFunc; + CPDF_TransferFunc* m_pTransferFunc; - CFX_Matrix m_Matrix; + CFX_Matrix m_Matrix; - int m_RenderIntent; + int m_RenderIntent; - FX_BOOL m_StrokeAdjust; + FX_BOOL m_StrokeAdjust; - FX_BOOL m_AlphaSource; + FX_BOOL m_AlphaSource; - FX_BOOL m_TextKnockout; + FX_BOOL m_TextKnockout; - FX_BOOL m_StrokeOP; + FX_BOOL m_StrokeOP; - FX_BOOL m_FillOP; + FX_BOOL m_FillOP; - int m_OPMode; + int m_OPMode; - CPDF_Object* m_pBG; + CPDF_Object* m_pBG; - CPDF_Object* m_pUCR; + CPDF_Object* m_pUCR; - CPDF_Object* m_pHT; + CPDF_Object* m_pHT; - FX_FLOAT m_Flatness; + FX_FLOAT m_Flatness; - FX_FLOAT m_Smoothness; + FX_FLOAT m_Smoothness; }; -class CPDF_GeneralState : public CFX_CountRef -{ -public: - - void SetRenderIntent(const CFX_ByteString& ri); - - int GetBlendType() const - { - return m_pObject ? m_pObject->m_BlendType : FXDIB_BLEND_NORMAL; - } - - int GetAlpha(FX_BOOL bStroke) const - { - return m_pObject ? FXSYS_round((bStroke ? m_pObject->m_StrokeAlpha : m_pObject->m_FillAlpha) * 255) : 255; - } +class CPDF_GeneralState : public CFX_CountRef { + public: + void SetRenderIntent(const CFX_ByteString& ri); + + int GetBlendType() const { + return m_pObject ? m_pObject->m_BlendType : FXDIB_BLEND_NORMAL; + } + + int GetAlpha(FX_BOOL bStroke) const { + return m_pObject ? FXSYS_round((bStroke ? m_pObject->m_StrokeAlpha + : m_pObject->m_FillAlpha) * + 255) + : 255; + } }; -class CPDF_ContentMarkItem -{ -public: - - typedef enum { - None, - PropertiesDict, - DirectDict, - MCID - } ParamType; +class CPDF_ContentMarkItem { + public: + typedef enum { None, PropertiesDict, DirectDict, MCID } ParamType; - CPDF_ContentMarkItem(); + CPDF_ContentMarkItem(); - CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src); + CPDF_ContentMarkItem(const CPDF_ContentMarkItem& src); - ~CPDF_ContentMarkItem(); + ~CPDF_ContentMarkItem(); - inline const CFX_ByteString& GetName() const - { - return m_MarkName; - } + inline const CFX_ByteString& GetName() const { return m_MarkName; } - inline ParamType GetParamType() const - { - return m_ParamType; - } + inline ParamType GetParamType() const { return m_ParamType; } - inline void* GetParam() const - { - return m_pParam; - } + inline void* GetParam() const { return m_pParam; } - inline FX_BOOL HasMCID() const; + inline FX_BOOL HasMCID() const; - inline void SetName(const CFX_ByteString& name) - { - m_MarkName = name; - } + inline void SetName(const CFX_ByteString& name) { m_MarkName = name; } - inline void SetParam(ParamType type, void* param) - { - m_ParamType = type; - m_pParam = param; - } -private: + inline void SetParam(ParamType type, void* param) { + m_ParamType = type; + m_pParam = param; + } - CFX_ByteString m_MarkName; + private: + CFX_ByteString m_MarkName; - ParamType m_ParamType; + ParamType m_ParamType; - void* m_pParam; + void* m_pParam; }; -class CPDF_ContentMarkData -{ -public: +class CPDF_ContentMarkData { + public: + CPDF_ContentMarkData() {} - CPDF_ContentMarkData() { } + CPDF_ContentMarkData(const CPDF_ContentMarkData& src); - CPDF_ContentMarkData(const CPDF_ContentMarkData& src); + inline int CountItems() const { return m_Marks.GetSize(); } - inline int CountItems() const - { - return m_Marks.GetSize(); - } + inline CPDF_ContentMarkItem& GetItem(int index) const { + return m_Marks[index]; + } - inline CPDF_ContentMarkItem& GetItem(int index) const - { - return m_Marks[index]; - } + int GetMCID() const; - int GetMCID() const; + void AddMark(const CFX_ByteString& name, + CPDF_Dictionary* pDict, + FX_BOOL bDictNeedClone); - void AddMark(const CFX_ByteString& name, CPDF_Dictionary* pDict, FX_BOOL bDictNeedClone); + void DeleteLastMark(); - void DeleteLastMark(); -private: - - CFX_ObjectArray m_Marks; + private: + CFX_ObjectArray m_Marks; }; -class CPDF_ContentMark : public CFX_CountRef -{ -public: - - int GetMCID() const - { - return m_pObject ? m_pObject->GetMCID() : -1; - } +class CPDF_ContentMark : public CFX_CountRef { + public: + int GetMCID() const { return m_pObject ? m_pObject->GetMCID() : -1; } - FX_BOOL HasMark(const CFX_ByteStringC& mark) const; + FX_BOOL HasMark(const CFX_ByteStringC& mark) const; - FX_BOOL LookupMark(const CFX_ByteStringC& mark, CPDF_Dictionary*& pDict) const; + FX_BOOL LookupMark(const CFX_ByteStringC& mark, + CPDF_Dictionary*& pDict) const; }; -#define PDFPAGE_TEXT 1 -#define PDFPAGE_PATH 2 -#define PDFPAGE_IMAGE 3 -#define PDFPAGE_SHADING 4 -#define PDFPAGE_FORM 5 +#define PDFPAGE_TEXT 1 +#define PDFPAGE_PATH 2 +#define PDFPAGE_IMAGE 3 +#define PDFPAGE_SHADING 4 +#define PDFPAGE_FORM 5 -class CPDF_GraphicStates -{ -public: - void CopyStates(const CPDF_GraphicStates& src); +class CPDF_GraphicStates { + public: + void CopyStates(const CPDF_GraphicStates& src); - void DefaultStates(); + void DefaultStates(); - CPDF_ClipPath m_ClipPath; + CPDF_ClipPath m_ClipPath; - CPDF_GraphState m_GraphState; + CPDF_GraphState m_GraphState; - CPDF_ColorState m_ColorState; + CPDF_ColorState m_ColorState; - CPDF_TextState m_TextState; + CPDF_TextState m_TextState; - CPDF_GeneralState m_GeneralState; + CPDF_GeneralState m_GeneralState; }; -class CPDF_PageObject : public CPDF_GraphicStates -{ -public: - static CPDF_PageObject* Create(int type); - virtual ~CPDF_PageObject(); - - CPDF_PageObject* Clone() const; +class CPDF_PageObject : public CPDF_GraphicStates { + public: + static CPDF_PageObject* Create(int type); + virtual ~CPDF_PageObject(); - void Copy(const CPDF_PageObject* pSrcObject); + CPDF_PageObject* Clone() const; - virtual void Transform(const CFX_AffineMatrix& matrix) = 0; + void Copy(const CPDF_PageObject* pSrcObject); - void RemoveClipPath(); + virtual void Transform(const CFX_AffineMatrix& matrix) = 0; - void AppendClipPath(CPDF_Path path, int type, FX_BOOL bAutoMerge); + void RemoveClipPath(); - void CopyClipPath(CPDF_PageObject* pObj); + void AppendClipPath(CPDF_Path path, int type, FX_BOOL bAutoMerge); - void TransformClipPath(CFX_AffineMatrix& matrix); + void CopyClipPath(CPDF_PageObject* pObj); - void TransformGeneralState(CFX_AffineMatrix& matrix); + void TransformClipPath(CFX_AffineMatrix& matrix); - void SetColorState(CPDF_ColorState state) - { - m_ColorState = state; - } + void TransformGeneralState(CFX_AffineMatrix& matrix); - FX_RECT GetBBox(const CFX_AffineMatrix* pMatrix) const; + void SetColorState(CPDF_ColorState state) { m_ColorState = state; } - int m_Type; + FX_RECT GetBBox(const CFX_AffineMatrix* pMatrix) const; - FX_FLOAT m_Left; + int m_Type; - FX_FLOAT m_Right; + FX_FLOAT m_Left; - FX_FLOAT m_Top; + FX_FLOAT m_Right; - FX_FLOAT m_Bottom; + FX_FLOAT m_Top; - CPDF_ContentMark m_ContentMark; + FX_FLOAT m_Bottom; -protected: - virtual void CopyData(const CPDF_PageObject* pSrcObject) = 0; + CPDF_ContentMark m_ContentMark; - void RecalcBBox(); + protected: + virtual void CopyData(const CPDF_PageObject* pSrcObject) = 0; - CPDF_PageObject() {} + void RecalcBBox(); + CPDF_PageObject() {} }; struct CPDF_TextObjectItem { - FX_DWORD m_CharCode; - FX_FLOAT m_OriginX; - FX_FLOAT m_OriginY; + FX_DWORD m_CharCode; + FX_FLOAT m_OriginX; + FX_FLOAT m_OriginY; }; -class CPDF_TextObject : public CPDF_PageObject -{ -public: - CPDF_TextObject(); - ~CPDF_TextObject() override; +class CPDF_TextObject : public CPDF_PageObject { + public: + CPDF_TextObject(); + ~CPDF_TextObject() override; - int CountItems() const - { - return m_nChars; - } + int CountItems() const { return m_nChars; } - void GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const; + void GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const; - int CountChars() const; + int CountChars() const; - void GetCharInfo(int index, FX_DWORD& charcode, FX_FLOAT& kerning) const; - void GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const; + void GetCharInfo(int index, FX_DWORD& charcode, FX_FLOAT& kerning) const; + void GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const; - void GetCharRect(int index, CFX_FloatRect& rect) const; + void GetCharRect(int index, CFX_FloatRect& rect) const; - FX_FLOAT GetCharWidth(FX_DWORD charcode) const; - FX_FLOAT GetSpaceCharWidth() const; + FX_FLOAT GetCharWidth(FX_DWORD charcode) const; + FX_FLOAT GetSpaceCharWidth() const; - FX_FLOAT GetPosX() const - { - return m_PosX; - } + FX_FLOAT GetPosX() const { return m_PosX; } - FX_FLOAT GetPosY() const - { - return m_PosY; - } + FX_FLOAT GetPosY() const { return m_PosY; } - void GetTextMatrix(CFX_AffineMatrix* pMatrix) const; + void GetTextMatrix(CFX_AffineMatrix* pMatrix) const; - CPDF_Font* GetFont() const - { - return m_TextState.GetFont(); - } + CPDF_Font* GetFont() const { return m_TextState.GetFont(); } - FX_FLOAT GetFontSize() const - { - return m_TextState.GetFontSize(); - } + FX_FLOAT GetFontSize() const { return m_TextState.GetFontSize(); } - void SetEmpty(); + void SetEmpty(); - void SetText(const CFX_ByteString& text); + void SetText(const CFX_ByteString& text); - void SetText(CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs); + void SetText(CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs); - void SetText(int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pKernings); + void SetText(int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pKernings); - void SetPosition(FX_FLOAT x, FX_FLOAT y); + void SetPosition(FX_FLOAT x, FX_FLOAT y); - void SetTextState(CPDF_TextState TextState); + void SetTextState(CPDF_TextState TextState); - // CPDF_PageObject: - void Transform(const CFX_AffineMatrix& matrix) override; + // CPDF_PageObject: + void Transform(const CFX_AffineMatrix& matrix) override; - void CalcCharPos(FX_FLOAT* pPosArray) const; + void CalcCharPos(FX_FLOAT* pPosArray) const; - void SetData(int nChars, - FX_DWORD* pCharCodes, - FX_FLOAT* pCharPos, - FX_FLOAT x, - FX_FLOAT y); + void SetData(int nChars, + FX_DWORD* pCharCodes, + FX_FLOAT* pCharPos, + FX_FLOAT x, + FX_FLOAT y); - void GetData(int& nChars, FX_DWORD*& pCharCodes, FX_FLOAT*& pCharPos) - { - nChars = m_nChars; - pCharCodes = m_pCharCodes; - pCharPos = m_pCharPos; - } + void GetData(int& nChars, FX_DWORD*& pCharCodes, FX_FLOAT*& pCharPos) { + nChars = m_nChars; + pCharCodes = m_pCharCodes; + pCharPos = m_pCharPos; + } + void RecalcPositionData() { CalcPositionData(nullptr, nullptr, 1); } - void RecalcPositionData() - { - CalcPositionData(nullptr, nullptr, 1); - } + protected: + friend class CPDF_RenderStatus; + friend class CPDF_StreamContentParser; + friend class CPDF_TextRenderer; + friend class CTextPage; -protected: - friend class CPDF_RenderStatus; - friend class CPDF_StreamContentParser; - friend class CPDF_TextRenderer; - friend class CTextPage; + // CPDF_PageObject: + void CopyData(const CPDF_PageObject* pSrcObject) override; - // CPDF_PageObject: - void CopyData(const CPDF_PageObject* pSrcObject) override; + void SetSegments(const CFX_ByteString* pStrs, FX_FLOAT* pKerning, int nSegs); - void SetSegments(const CFX_ByteString* pStrs, - FX_FLOAT* pKerning, - int nSegs); + void CalcPositionData(FX_FLOAT* pTextAdvanceX, + FX_FLOAT* pTextAdvanceY, + FX_FLOAT horz_scale, + int level = 0); - void CalcPositionData(FX_FLOAT* pTextAdvanceX, - FX_FLOAT* pTextAdvanceY, - FX_FLOAT horz_scale, - int level = 0); + FX_FLOAT m_PosX; + FX_FLOAT m_PosY; - FX_FLOAT m_PosX; - FX_FLOAT m_PosY; + int m_nChars; - int m_nChars; + FX_DWORD* m_pCharCodes; - FX_DWORD* m_pCharCodes; - - FX_FLOAT* m_pCharPos; + FX_FLOAT* m_pCharPos; }; -class CPDF_PathObject : public CPDF_PageObject -{ -public: - CPDF_PathObject() - { - m_Type = PDFPAGE_PATH; - } - - virtual ~CPDF_PathObject() {} - void Transform(const CFX_AffineMatrix& maxtrix) override; +class CPDF_PathObject : public CPDF_PageObject { + public: + CPDF_PathObject() { m_Type = PDFPAGE_PATH; } - void SetGraphState(CPDF_GraphState GraphState); + virtual ~CPDF_PathObject() {} + void Transform(const CFX_AffineMatrix& maxtrix) override; - CPDF_Path m_Path; + void SetGraphState(CPDF_GraphState GraphState); - int m_FillType; + CPDF_Path m_Path; - FX_BOOL m_bStroke; + int m_FillType; - CFX_AffineMatrix m_Matrix; + FX_BOOL m_bStroke; + CFX_AffineMatrix m_Matrix; - void CalcBoundingBox(); + void CalcBoundingBox(); -protected: - void CopyData(const CPDF_PageObject* pSrcObject) override; + protected: + void CopyData(const CPDF_PageObject* pSrcObject) override; }; -class CPDF_ImageObject : public CPDF_PageObject -{ -public: - CPDF_ImageObject(); +class CPDF_ImageObject : public CPDF_PageObject { + public: + CPDF_ImageObject(); - virtual ~CPDF_ImageObject(); - void Transform(const CFX_AffineMatrix& matrix) override; + virtual ~CPDF_ImageObject(); + void Transform(const CFX_AffineMatrix& matrix) override; - CPDF_Image* m_pImage; + CPDF_Image* m_pImage; - CFX_AffineMatrix m_Matrix; + CFX_AffineMatrix m_Matrix; - void CalcBoundingBox(); + void CalcBoundingBox(); -private: - void CopyData(const CPDF_PageObject* pSrcObject) override; + private: + void CopyData(const CPDF_PageObject* pSrcObject) override; }; -class CPDF_ShadingObject : public CPDF_PageObject -{ -public: - CPDF_ShadingObject(); +class CPDF_ShadingObject : public CPDF_PageObject { + public: + CPDF_ShadingObject(); - virtual ~CPDF_ShadingObject(); + virtual ~CPDF_ShadingObject(); - CPDF_ShadingPattern* m_pShading; + CPDF_ShadingPattern* m_pShading; - CFX_AffineMatrix m_Matrix; + CFX_AffineMatrix m_Matrix; - void Transform(const CFX_AffineMatrix& matrix) override; + void Transform(const CFX_AffineMatrix& matrix) override; - void CalcBoundingBox(); + void CalcBoundingBox(); -protected: - void CopyData(const CPDF_PageObject* pSrcObject) override; + protected: + void CopyData(const CPDF_PageObject* pSrcObject) override; }; -class CPDF_FormObject : public CPDF_PageObject -{ -public: - CPDF_FormObject() - { - m_Type = PDFPAGE_FORM; - m_pForm = NULL; - } +class CPDF_FormObject : public CPDF_PageObject { + public: + CPDF_FormObject() { + m_Type = PDFPAGE_FORM; + m_pForm = NULL; + } - virtual ~CPDF_FormObject(); - void Transform(const CFX_AffineMatrix& matrix) override; + virtual ~CPDF_FormObject(); + void Transform(const CFX_AffineMatrix& matrix) override; - CPDF_Form* m_pForm; + CPDF_Form* m_pForm; - CFX_AffineMatrix m_FormMatrix; + CFX_AffineMatrix m_FormMatrix; - void CalcBoundingBox(); + void CalcBoundingBox(); -protected: - void CopyData(const CPDF_PageObject* pSrcObject) override; + protected: + void CopyData(const CPDF_PageObject* pSrcObject) override; }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_PAGEOBJ_H_ diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index 951085b33a..f80bb24a87 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -34,15 +34,15 @@ class CPDF_Pattern; class CPDF_FontEncoding; class CPDF_IccProfile; class CFX_PrivateData; -#define FPDFPERM_PRINT 0x0004 -#define FPDFPERM_MODIFY 0x0008 -#define FPDFPERM_EXTRACT 0x0010 -#define FPDFPERM_ANNOT_FORM 0x0020 -#define FPDFPERM_FILL_FORM 0x0100 -#define FPDFPERM_EXTRACT_ACCESS 0x0200 -#define FPDFPERM_ASSEMBLE 0x0400 -#define FPDFPERM_PRINT_HIGH 0x0800 -#define FPDF_PAGE_MAX_NUM 0xFFFFF +#define FPDFPERM_PRINT 0x0004 +#define FPDFPERM_MODIFY 0x0008 +#define FPDFPERM_EXTRACT 0x0010 +#define FPDFPERM_ANNOT_FORM 0x0020 +#define FPDFPERM_FILL_FORM 0x0100 +#define FPDFPERM_EXTRACT_ACCESS 0x0200 +#define FPDFPERM_ASSEMBLE 0x0400 +#define FPDFPERM_PRINT_HIGH 0x0800 +#define FPDF_PAGE_MAX_NUM 0xFFFFF // Indexed by 8-bit character code, contains either: // 'W' - for whitespace: NUL, TAB, CR, LF, FF, 0x80, 0xff @@ -51,859 +51,862 @@ class CFX_PrivateData; // 'R' - otherwise. extern const char PDF_CharType[256]; -class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjects -{ -public: - CPDF_Document(); - explicit CPDF_Document(CPDF_Parser* pParser); +class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjects { + public: + CPDF_Document(); + explicit CPDF_Document(CPDF_Parser* pParser); - ~CPDF_Document(); + ~CPDF_Document(); - CPDF_Parser* GetParser() const - { - return m_pParser; - } + CPDF_Parser* GetParser() const { return m_pParser; } - CPDF_Dictionary* GetRoot() const - { - return m_pRootDict; - } + CPDF_Dictionary* GetRoot() const { return m_pRootDict; } - CPDF_Dictionary* GetInfo() const - { - return m_pInfoDict; - } + CPDF_Dictionary* GetInfo() const { return m_pInfoDict; } - void GetID(CFX_ByteString& id1, CFX_ByteString& id2) const - { - id1 = m_ID1; - id2 = m_ID2; - } + void GetID(CFX_ByteString& id1, CFX_ByteString& id2) const { + id1 = m_ID1; + id2 = m_ID2; + } - int GetPageCount() const; + int GetPageCount() const; - CPDF_Dictionary* GetPage(int iPage); + CPDF_Dictionary* GetPage(int iPage); - int GetPageIndex(FX_DWORD objnum); + int GetPageIndex(FX_DWORD objnum); - FX_DWORD GetUserPermissions(FX_BOOL bCheckRevision = FALSE) const; + FX_DWORD GetUserPermissions(FX_BOOL bCheckRevision = FALSE) const; - FX_BOOL IsOwner() const; + FX_BOOL IsOwner() const; + CPDF_DocPageData* GetPageData() { return GetValidatePageData(); } + void ClearPageData(); - CPDF_DocPageData* GetPageData() - { - return GetValidatePageData(); - } + void RemoveColorSpaceFromPageData(CPDF_Object* pObject); - void ClearPageData(); + CPDF_DocRenderData* GetRenderData() { return GetValidateRenderData(); } - void RemoveColorSpaceFromPageData(CPDF_Object* pObject); + void ClearRenderData(); + void ClearRenderFont(); - CPDF_DocRenderData* GetRenderData() - { - return GetValidateRenderData(); - } + FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const; - void ClearRenderData(); + // |pFontDict| must not be null. + CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict); - void ClearRenderFont(); + CPDF_ColorSpace* LoadColorSpace(CPDF_Object* pCSObj, + CPDF_Dictionary* pResources = NULL); + CPDF_Pattern* LoadPattern(CPDF_Object* pObj, + FX_BOOL bShading, + const CFX_AffineMatrix* matrix = NULL); - FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const; + CPDF_Image* LoadImageF(CPDF_Object* pObj); - // |pFontDict| must not be null. - CPDF_Font* LoadFont(CPDF_Dictionary* pFontDict); + CPDF_StreamAcc* LoadFontFile(CPDF_Stream* pStream); - CPDF_ColorSpace* LoadColorSpace(CPDF_Object* pCSObj, CPDF_Dictionary* pResources = NULL); - - CPDF_Pattern* LoadPattern(CPDF_Object* pObj, FX_BOOL bShading, const CFX_AffineMatrix* matrix = NULL); - - CPDF_Image* LoadImageF(CPDF_Object* pObj); - - CPDF_StreamAcc* LoadFontFile(CPDF_Stream* pStream); - - CPDF_IccProfile* LoadIccProfile(CPDF_Stream* pStream); + CPDF_IccProfile* LoadIccProfile(CPDF_Stream* pStream); #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - CPDF_Font* AddWindowsFont(LOGFONTA* pLogFont, FX_BOOL bVert, FX_BOOL bTranslateName = FALSE); - CPDF_Font* AddWindowsFont(LOGFONTW* pLogFont, FX_BOOL bVert, FX_BOOL bTranslateName = FALSE); + CPDF_Font* AddWindowsFont(LOGFONTA* pLogFont, + FX_BOOL bVert, + FX_BOOL bTranslateName = FALSE); + CPDF_Font* AddWindowsFont(LOGFONTW* pLogFont, + FX_BOOL bVert, + FX_BOOL bTranslateName = FALSE); #endif #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - CPDF_Font* AddMacFont(CTFontRef pFont, FX_BOOL bVert, FX_BOOL bTranslateName = FALSE); + CPDF_Font* AddMacFont(CTFontRef pFont, + FX_BOOL bVert, + FX_BOOL bTranslateName = FALSE); #endif - CPDF_Font* AddStandardFont(const FX_CHAR* font, CPDF_FontEncoding* pEncoding); - - - CPDF_Font* AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert); - - void CreateNewDoc(); - - CPDF_Dictionary* CreateNewPage(int iPage); + CPDF_Font* AddStandardFont(const FX_CHAR* font, CPDF_FontEncoding* pEncoding); - void DeletePage(int iPage); + CPDF_Font* AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert); - void LoadDoc(); - void LoadAsynDoc(CPDF_Dictionary *pLinearized); - void LoadPages(); -protected: + void CreateNewDoc(); - CPDF_Dictionary* m_pRootDict; + CPDF_Dictionary* CreateNewPage(int iPage); - CPDF_Dictionary* m_pInfoDict; + void DeletePage(int iPage); - CFX_ByteString m_ID1; + void LoadDoc(); + void LoadAsynDoc(CPDF_Dictionary* pLinearized); + void LoadPages(); - CFX_ByteString m_ID2; + protected: + CPDF_Dictionary* m_pRootDict; + CPDF_Dictionary* m_pInfoDict; - FX_BOOL m_bLinearized; + CFX_ByteString m_ID1; - FX_DWORD m_dwFirstPageNo; + CFX_ByteString m_ID2; - FX_DWORD m_dwFirstPageObjNum; + FX_BOOL m_bLinearized; - CFX_DWordArray m_PageList; + FX_DWORD m_dwFirstPageNo; - int _GetPageCount() const; - CPDF_Dictionary* _FindPDFPage(CPDF_Dictionary* pPages, int iPage, int nPagesToGo, int level); - int _FindPageIndex(CPDF_Dictionary* pNode, FX_DWORD& skip_count, FX_DWORD objnum, int& index, int level = 0); - FX_BOOL IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary* pPageDict); - FX_BOOL CheckOCGVisible(CPDF_Dictionary* pOCG, FX_BOOL bPrinting); - CPDF_DocPageData* GetValidatePageData(); - CPDF_DocRenderData* GetValidateRenderData(); - friend class CPDF_Creator; - friend class CPDF_Parser; - friend class CPDF_DataAvail; - friend class CPDF_OCContext; + FX_DWORD m_dwFirstPageObjNum; + CFX_DWordArray m_PageList; + int _GetPageCount() const; + CPDF_Dictionary* _FindPDFPage(CPDF_Dictionary* pPages, + int iPage, + int nPagesToGo, + int level); + int _FindPageIndex(CPDF_Dictionary* pNode, + FX_DWORD& skip_count, + FX_DWORD objnum, + int& index, + int level = 0); + FX_BOOL IsContentUsedElsewhere(FX_DWORD objnum, CPDF_Dictionary* pPageDict); + FX_BOOL CheckOCGVisible(CPDF_Dictionary* pOCG, FX_BOOL bPrinting); + CPDF_DocPageData* GetValidatePageData(); + CPDF_DocRenderData* GetValidateRenderData(); + friend class CPDF_Creator; + friend class CPDF_Parser; + friend class CPDF_DataAvail; + friend class CPDF_OCContext; - CPDF_DocPageData* m_pDocPage; - - CPDF_DocRenderData* m_pDocRender; + CPDF_DocPageData* m_pDocPage; + CPDF_DocRenderData* m_pDocRender; }; -#define PDFWORD_EOF 0 -#define PDFWORD_NUMBER 1 -#define PDFWORD_TEXT 2 -#define PDFWORD_DELIMITER 3 -#define PDFWORD_NAME 4 -class CPDF_SimpleParser -{ -public: - - CPDF_SimpleParser(const uint8_t* pData, FX_DWORD dwSize); +#define PDFWORD_EOF 0 +#define PDFWORD_NUMBER 1 +#define PDFWORD_TEXT 2 +#define PDFWORD_DELIMITER 3 +#define PDFWORD_NAME 4 +class CPDF_SimpleParser { + public: + CPDF_SimpleParser(const uint8_t* pData, FX_DWORD dwSize); - CPDF_SimpleParser(const CFX_ByteStringC& str); + CPDF_SimpleParser(const CFX_ByteStringC& str); - CFX_ByteStringC GetWord(); + CFX_ByteStringC GetWord(); - FX_BOOL SearchToken(const CFX_ByteStringC& token); + FX_BOOL SearchToken(const CFX_ByteStringC& token); - FX_BOOL SkipWord(const CFX_ByteStringC& token); + FX_BOOL SkipWord(const CFX_ByteStringC& token); - FX_BOOL FindTagPair(const CFX_ByteStringC& start_token, const CFX_ByteStringC& end_token, - FX_DWORD& start_pos, FX_DWORD& end_pos); + FX_BOOL FindTagPair(const CFX_ByteStringC& start_token, + const CFX_ByteStringC& end_token, + FX_DWORD& start_pos, + FX_DWORD& end_pos); - FX_BOOL FindTagParam(const CFX_ByteStringC& token, int nParams); + FX_BOOL FindTagParam(const CFX_ByteStringC& token, int nParams); - FX_DWORD GetPos() - { - return m_dwCurPos; - } + FX_DWORD GetPos() { return m_dwCurPos; } - void SetPos(FX_DWORD pos) - { - ASSERT(pos <= m_dwSize); - m_dwCurPos = pos; - } -private: + void SetPos(FX_DWORD pos) { + ASSERT(pos <= m_dwSize); + m_dwCurPos = pos; + } - void ParseWord(const uint8_t*& pStart, FX_DWORD& dwSize, int& type); + private: + void ParseWord(const uint8_t*& pStart, FX_DWORD& dwSize, int& type); - const uint8_t* m_pData; + const uint8_t* m_pData; - FX_DWORD m_dwSize; + FX_DWORD m_dwSize; - FX_DWORD m_dwCurPos; + FX_DWORD m_dwCurPos; }; -class CPDF_SyntaxParser -{ -public: +class CPDF_SyntaxParser { + public: + CPDF_SyntaxParser(); + virtual ~CPDF_SyntaxParser(); - CPDF_SyntaxParser(); - virtual ~CPDF_SyntaxParser(); + void InitParser(IFX_FileRead* pFileAccess, FX_DWORD HeaderOffset); - void InitParser(IFX_FileRead* pFileAccess, FX_DWORD HeaderOffset); + FX_FILESIZE SavePos() { return m_Pos; } - FX_FILESIZE SavePos() - { - return m_Pos; - } + void RestorePos(FX_FILESIZE pos) { m_Pos = pos; } - void RestorePos(FX_FILESIZE pos) - { - m_Pos = pos; - } + CPDF_Object* GetObject(CPDF_IndirectObjects* pObjList, + FX_DWORD objnum, + FX_DWORD gennum, + struct PARSE_CONTEXT* pContext = NULL, + FX_BOOL bDecrypt = TRUE); - CPDF_Object* GetObject(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, FX_DWORD gennum, struct PARSE_CONTEXT* pContext = NULL, FX_BOOL bDecrypt = TRUE); + CPDF_Object* GetObjectByStrict(CPDF_IndirectObjects* pObjList, + FX_DWORD objnum, + FX_DWORD gennum, + struct PARSE_CONTEXT* pContext = NULL); + int GetDirectNum(); - CPDF_Object* GetObjectByStrict(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, FX_DWORD gennum, struct PARSE_CONTEXT* pContext = NULL); + CFX_ByteString GetString(FX_DWORD objnum, FX_DWORD gennum); - int GetDirectNum(); + CFX_ByteString GetName(); - CFX_ByteString GetString(FX_DWORD objnum, FX_DWORD gennum); + CFX_ByteString GetKeyword(); - CFX_ByteString GetName(); + void GetBinary(uint8_t* buffer, FX_DWORD size); - CFX_ByteString GetKeyword(); + void ToNextLine(); - void GetBinary(uint8_t* buffer, FX_DWORD size); + void ToNextWord(); - void ToNextLine(); + FX_BOOL SearchWord(const CFX_ByteStringC& word, + FX_BOOL bWholeWord, + FX_BOOL bForward, + FX_FILESIZE limit); - void ToNextWord(); + int SearchMultiWord(const CFX_ByteStringC& words, + FX_BOOL bWholeWord, + FX_FILESIZE limit); - FX_BOOL SearchWord(const CFX_ByteStringC& word, FX_BOOL bWholeWord, FX_BOOL bForward, FX_FILESIZE limit); + FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit); - int SearchMultiWord(const CFX_ByteStringC& words, FX_BOOL bWholeWord, FX_FILESIZE limit); + void SetEncrypt(CPDF_CryptoHandler* pCryptoHandler) { + m_pCryptoHandler = pCryptoHandler; + } - FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit); + FX_BOOL IsEncrypted() { return m_pCryptoHandler != NULL; } - void SetEncrypt(CPDF_CryptoHandler* pCryptoHandler) - { - m_pCryptoHandler = pCryptoHandler; - } + FX_BOOL GetCharAt(FX_FILESIZE pos, uint8_t& ch); - FX_BOOL IsEncrypted() - { - return m_pCryptoHandler != NULL; - } + FX_BOOL ReadBlock(uint8_t* pBuf, FX_DWORD size); - FX_BOOL GetCharAt(FX_FILESIZE pos, uint8_t& ch); + CFX_ByteString GetNextWord(FX_BOOL& bIsNumber); - FX_BOOL ReadBlock(uint8_t* pBuf, FX_DWORD size); + protected: + static const int kParserMaxRecursionDepth = 64; + static int s_CurrentRecursionDepth; - CFX_ByteString GetNextWord(FX_BOOL& bIsNumber); -protected: - static const int kParserMaxRecursionDepth = 64; - static int s_CurrentRecursionDepth; + virtual FX_BOOL GetNextChar(uint8_t& ch); - virtual FX_BOOL GetNextChar(uint8_t& ch); + FX_BOOL GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch); - FX_BOOL GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch); + void GetNextWord(); - void GetNextWord(); + FX_BOOL IsWholeWord(FX_FILESIZE startpos, + FX_FILESIZE limit, + const uint8_t* tag, + FX_DWORD taglen); - FX_BOOL IsWholeWord(FX_FILESIZE startpos, FX_FILESIZE limit, const uint8_t* tag, FX_DWORD taglen); + CFX_ByteString ReadString(); - CFX_ByteString ReadString(); + CFX_ByteString ReadHexString(); - CFX_ByteString ReadHexString(); + CPDF_Stream* ReadStream(CPDF_Dictionary* pDict, + PARSE_CONTEXT* pContext, + FX_DWORD objnum, + FX_DWORD gennum); - CPDF_Stream* ReadStream(CPDF_Dictionary* pDict, PARSE_CONTEXT* pContext, FX_DWORD objnum, FX_DWORD gennum); + FX_FILESIZE m_Pos; - FX_FILESIZE m_Pos; + FX_BOOL m_bFileStream; - FX_BOOL m_bFileStream; + int m_MetadataObjnum; - int m_MetadataObjnum; + IFX_FileRead* m_pFileAccess; - IFX_FileRead* m_pFileAccess; + FX_DWORD m_HeaderOffset; - FX_DWORD m_HeaderOffset; + FX_FILESIZE m_FileLen; - FX_FILESIZE m_FileLen; + uint8_t* m_pFileBuf; - uint8_t* m_pFileBuf; + FX_DWORD m_BufSize; - FX_DWORD m_BufSize; + FX_FILESIZE m_BufOffset; - FX_FILESIZE m_BufOffset; + CPDF_CryptoHandler* m_pCryptoHandler; - CPDF_CryptoHandler* m_pCryptoHandler; + uint8_t m_WordBuffer[257]; - uint8_t m_WordBuffer[257]; + FX_DWORD m_WordSize; - FX_DWORD m_WordSize; + FX_BOOL m_bIsNumber; - FX_BOOL m_bIsNumber; - - FX_FILESIZE m_dwWordPos; - friend class CPDF_Parser; - friend class CPDF_DataAvail; + FX_FILESIZE m_dwWordPos; + friend class CPDF_Parser; + friend class CPDF_DataAvail; }; -#define PDFPARSE_TYPEONLY 1 -#define PDFPARSE_NOSTREAM 2 +#define PDFPARSE_TYPEONLY 1 +#define PDFPARSE_NOSTREAM 2 struct PARSE_CONTEXT { - uint32_t m_Flags; - FX_FILESIZE m_DictStart; - FX_FILESIZE m_DictEnd; - FX_FILESIZE m_DataStart; - FX_FILESIZE m_DataEnd; + uint32_t m_Flags; + FX_FILESIZE m_DictStart; + FX_FILESIZE m_DictEnd; + FX_FILESIZE m_DataStart; + FX_FILESIZE m_DataEnd; }; -#define PDFPARSE_ERROR_SUCCESS 0 -#define PDFPARSE_ERROR_FILE 1 -#define PDFPARSE_ERROR_FORMAT 2 -#define PDFPARSE_ERROR_PASSWORD 3 -#define PDFPARSE_ERROR_HANDLER 4 -#define PDFPARSE_ERROR_CERT 5 - -class CPDF_Parser -{ -public: - CPDF_Parser(); - ~CPDF_Parser(); +#define PDFPARSE_ERROR_SUCCESS 0 +#define PDFPARSE_ERROR_FILE 1 +#define PDFPARSE_ERROR_FORMAT 2 +#define PDFPARSE_ERROR_PASSWORD 3 +#define PDFPARSE_ERROR_HANDLER 4 +#define PDFPARSE_ERROR_CERT 5 - FX_DWORD StartParse(const FX_CHAR* filename, FX_BOOL bReParse = FALSE); - FX_DWORD StartParse(const FX_WCHAR* filename, FX_BOOL bReParse = FALSE); - FX_DWORD StartParse(IFX_FileRead* pFile, FX_BOOL bReParse = FALSE, FX_BOOL bOwnFileRead = TRUE); +class CPDF_Parser { + public: + CPDF_Parser(); + ~CPDF_Parser(); - void CloseParser(FX_BOOL bReParse = FALSE); - - FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE); + FX_DWORD StartParse(const FX_CHAR* filename, FX_BOOL bReParse = FALSE); + FX_DWORD StartParse(const FX_WCHAR* filename, FX_BOOL bReParse = FALSE); + FX_DWORD StartParse(IFX_FileRead* pFile, + FX_BOOL bReParse = FALSE, + FX_BOOL bOwnFileRead = TRUE); - FX_BOOL IsOwner(); - - void SetPassword(const FX_CHAR* password) - { - m_Password = password; - } - - CFX_ByteString GetPassword() - { - return m_Password; - } + void CloseParser(FX_BOOL bReParse = FALSE); - CPDF_SecurityHandler* GetSecurityHandler() - { - return m_pSecurityHandler; - } - - CPDF_CryptoHandler* GetCryptoHandler() - { - return m_Syntax.m_pCryptoHandler; - } - - void SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, FX_BOOL bForced = FALSE); + FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE); - CFX_ByteString GetRecipient() - { - return m_bsRecipient; - } + FX_BOOL IsOwner(); - CPDF_Dictionary* GetTrailer() - { - return m_pTrailer; - } + void SetPassword(const FX_CHAR* password) { m_Password = password; } - FX_FILESIZE GetLastXRefOffset() - { - return m_LastXRefOffset; - } + CFX_ByteString GetPassword() { return m_Password; } - CPDF_Document* GetDocument() - { - return m_pDocument; - } + CPDF_SecurityHandler* GetSecurityHandler() { return m_pSecurityHandler; } - CFX_ArrayTemplate* GetOtherTrailers() - { - return &m_Trailers; - } + CPDF_CryptoHandler* GetCryptoHandler() { return m_Syntax.m_pCryptoHandler; } - FX_DWORD GetRootObjNum(); - FX_DWORD GetInfoObjNum() ; - CPDF_Array* GetIDArray() ; + void SetSecurityHandler(CPDF_SecurityHandler* pSecurityHandler, + FX_BOOL bForced = FALSE); - CPDF_Dictionary* GetEncryptDict() - { - return m_pEncryptDict; - } + CFX_ByteString GetRecipient() { return m_bsRecipient; } - FX_BOOL IsEncrypted() - { - return GetEncryptDict() != NULL; - } + CPDF_Dictionary* GetTrailer() { return m_pTrailer; } + FX_FILESIZE GetLastXRefOffset() { return m_LastXRefOffset; } - CPDF_Object* ParseIndirectObject(CPDF_IndirectObjects* pObjList, FX_DWORD objnum, PARSE_CONTEXT* pContext = NULL) ; - FX_DWORD GetLastObjNum(); - FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm); + CPDF_Document* GetDocument() { return m_pDocument; } - FX_FILESIZE GetObjectOffset(FX_DWORD objnum); + CFX_ArrayTemplate* GetOtherTrailers() { + return &m_Trailers; + } - FX_FILESIZE GetObjectSize(FX_DWORD objnum); + FX_DWORD GetRootObjNum(); + FX_DWORD GetInfoObjNum(); + CPDF_Array* GetIDArray(); - int GetObjectVersion(FX_DWORD objnum) - { - return m_ObjVersion[objnum]; - } + CPDF_Dictionary* GetEncryptDict() { return m_pEncryptDict; } - void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size); + FX_BOOL IsEncrypted() { return GetEncryptDict() != NULL; } - FX_BOOL GetFileStreamOption() - { - return m_Syntax.m_bFileStream; - } + CPDF_Object* ParseIndirectObject(CPDF_IndirectObjects* pObjList, + FX_DWORD objnum, + PARSE_CONTEXT* pContext = NULL); + FX_DWORD GetLastObjNum(); + FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm); - void SetFileStreamOption(FX_BOOL b) - { - m_Syntax.m_bFileStream = b; - } + FX_FILESIZE GetObjectOffset(FX_DWORD objnum); - IFX_FileRead* GetFileAccess() const - { - return m_Syntax.m_pFileAccess; - } + FX_FILESIZE GetObjectSize(FX_DWORD objnum); - int GetFileVersion() const - { - return m_FileVersion; - } + int GetObjectVersion(FX_DWORD objnum) { return m_ObjVersion[objnum]; } - FX_BOOL IsXRefStream() const - { - return m_bXRefStream; - } - CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, FX_FILESIZE pos, FX_DWORD objnum, - struct PARSE_CONTEXT* pContext); + void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size); - CPDF_Object* ParseIndirectObjectAtByStrict(CPDF_IndirectObjects* pObjList, FX_FILESIZE pos, FX_DWORD objnum, - struct PARSE_CONTEXT* pContext, FX_FILESIZE *pResultPos); + FX_BOOL GetFileStreamOption() { return m_Syntax.m_bFileStream; } - FX_DWORD StartAsynParse(IFX_FileRead* pFile, FX_BOOL bReParse = FALSE, FX_BOOL bOwnFileRead = TRUE); + void SetFileStreamOption(FX_BOOL b) { m_Syntax.m_bFileStream = b; } - FX_DWORD GetFirstPageNo() - { - return m_dwFirstPageNo; - } -protected: - CPDF_Document* m_pDocument; + IFX_FileRead* GetFileAccess() const { return m_Syntax.m_pFileAccess; } - CPDF_SyntaxParser m_Syntax; - FX_BOOL m_bOwnFileRead; - CPDF_Object* ParseDirect(CPDF_Object* pObj); + int GetFileVersion() const { return m_FileVersion; } - FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos); + FX_BOOL IsXRefStream() const { return m_bXRefStream; } + CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjects* pObjList, + FX_FILESIZE pos, + FX_DWORD objnum, + struct PARSE_CONTEXT* pContext); - FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos); + CPDF_Object* ParseIndirectObjectAtByStrict(CPDF_IndirectObjects* pObjList, + FX_FILESIZE pos, + FX_DWORD objnum, + struct PARSE_CONTEXT* pContext, + FX_FILESIZE* pResultPos); - FX_BOOL LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, FX_BOOL bSkip, FX_BOOL bFirst); + FX_DWORD StartAsynParse(IFX_FileRead* pFile, + FX_BOOL bReParse = FALSE, + FX_BOOL bOwnFileRead = TRUE); - FX_BOOL LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL bMainXRef); + FX_DWORD GetFirstPageNo() { return m_dwFirstPageNo; } - CPDF_Dictionary* LoadTrailerV4(); + protected: + CPDF_Document* m_pDocument; - FX_BOOL RebuildCrossRef(); + CPDF_SyntaxParser m_Syntax; + FX_BOOL m_bOwnFileRead; + CPDF_Object* ParseDirect(CPDF_Object* pObj); - FX_DWORD SetEncryptHandler(); + FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos); - void ReleaseEncryptHandler(); + FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos); - FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); + FX_BOOL LoadCrossRefV4(FX_FILESIZE pos, + FX_FILESIZE streampos, + FX_BOOL bSkip, + FX_BOOL bFirst); - FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); + FX_BOOL LoadCrossRefV5(FX_FILESIZE pos, FX_FILESIZE& prev, FX_BOOL bMainXRef); - FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); + CPDF_Dictionary* LoadTrailerV4(); - FX_DWORD LoadLinearizedMainXRefTable(); + FX_BOOL RebuildCrossRef(); - CFX_MapPtrToPtr m_ObjectStreamMap; + FX_DWORD SetEncryptHandler(); - CPDF_StreamAcc* GetObjectStream(FX_DWORD number); + void ReleaseEncryptHandler(); - FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset); + FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); + FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); + FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); - int m_FileVersion; + FX_DWORD LoadLinearizedMainXRefTable(); - CPDF_Dictionary* m_pTrailer; + CFX_MapPtrToPtr m_ObjectStreamMap; - CPDF_Dictionary* m_pEncryptDict; - void SetEncryptDictionary(CPDF_Dictionary* pDict); + CPDF_StreamAcc* GetObjectStream(FX_DWORD number); - FX_FILESIZE m_LastXRefOffset; + FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset); - FX_BOOL m_bXRefStream; + int m_FileVersion; + CPDF_Dictionary* m_pTrailer; - CPDF_SecurityHandler* m_pSecurityHandler; + CPDF_Dictionary* m_pEncryptDict; + void SetEncryptDictionary(CPDF_Dictionary* pDict); - FX_BOOL m_bForceUseSecurityHandler; + FX_FILESIZE m_LastXRefOffset; - CFX_ByteString m_bsRecipient; + FX_BOOL m_bXRefStream; - CFX_ByteString m_FilePath; + CPDF_SecurityHandler* m_pSecurityHandler; - CFX_ByteString m_Password; + FX_BOOL m_bForceUseSecurityHandler; - CFX_FileSizeArray m_CrossRef; + CFX_ByteString m_bsRecipient; - CFX_ByteArray m_V5Type; + CFX_ByteString m_FilePath; - CFX_FileSizeArray m_SortedOffset; + CFX_ByteString m_Password; - CFX_WordArray m_ObjVersion; - CFX_ArrayTemplate m_Trailers; + CFX_FileSizeArray m_CrossRef; - FX_BOOL m_bVersionUpdated; + CFX_ByteArray m_V5Type; - CPDF_Object* m_pLinearized; - - FX_DWORD m_dwFirstPageNo; - - FX_DWORD m_dwXrefStartObjNum; - friend class CPDF_Creator; - friend class CPDF_DataAvail; -}; -#define FXCIPHER_NONE 0 -#define FXCIPHER_RC4 1 -#define FXCIPHER_AES 2 -#define FXCIPHER_AES2 3 -class CPDF_SecurityHandler -{ -public: + CFX_FileSizeArray m_SortedOffset; - virtual ~CPDF_SecurityHandler() {} + CFX_WordArray m_ObjVersion; + CFX_ArrayTemplate m_Trailers; - virtual FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict) = 0; + FX_BOOL m_bVersionUpdated; - virtual FX_DWORD GetPermissions() = 0; + CPDF_Object* m_pLinearized; - virtual FX_BOOL IsOwner() = 0; + FX_DWORD m_dwFirstPageNo; - virtual FX_BOOL GetCryptInfo(int& cipher, const uint8_t*& buffer, int& keylen) = 0; - - virtual FX_BOOL IsMetadataEncrypted() - { - return TRUE; - } - - virtual CPDF_CryptoHandler* CreateCryptoHandler() = 0; - - virtual CPDF_StandardSecurityHandler* GetStandardHandler() - { - return NULL; - } -}; -#define PDF_ENCRYPT_CONTENT 0 -class CPDF_StandardSecurityHandler : public CPDF_SecurityHandler -{ -public: - CPDF_StandardSecurityHandler(); - - virtual ~CPDF_StandardSecurityHandler(); - virtual FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict); - virtual FX_DWORD GetPermissions(); - virtual FX_BOOL IsOwner() - { - return m_bOwner; - } - virtual FX_BOOL GetCryptInfo(int& cipher, const uint8_t*& buffer, int& keylen); - virtual FX_BOOL IsMetadataEncrypted(); - virtual CPDF_CryptoHandler* CreateCryptoHandler(); - virtual CPDF_StandardSecurityHandler* GetStandardHandler() - { - return this; - } - - void OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray, - const uint8_t* user_pass, FX_DWORD user_size, - const uint8_t* owner_pass, FX_DWORD owner_size, FX_DWORD type = PDF_ENCRYPT_CONTENT); - - void OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray, - const uint8_t* user_pass, FX_DWORD user_size, FX_DWORD type = PDF_ENCRYPT_CONTENT); - - CFX_ByteString GetUserPassword(const uint8_t* owner_pass, FX_DWORD pass_size); - CFX_ByteString GetUserPassword(const uint8_t* owner_pass, FX_DWORD pass_size, int32_t key_len); - int GetVersion() - { - return m_Version; - } - int GetRevision() - { - return m_Revision; - } - - int CheckPassword(const uint8_t* password, FX_DWORD pass_size, FX_BOOL bOwner, uint8_t* key); - int CheckPassword(const uint8_t* password, FX_DWORD pass_size, FX_BOOL bOwner, uint8_t* key, int key_len); -private: - - int m_Version; - - int m_Revision; - - CPDF_Parser* m_pParser; - - CPDF_Dictionary* m_pEncryptDict; - - FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict); - FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict, FX_DWORD type, int& cipher, int& key_len); - - FX_BOOL CheckUserPassword(const uint8_t* password, FX_DWORD pass_size, - FX_BOOL bIgnoreEncryptMeta, uint8_t* key, int32_t key_len); - - FX_BOOL CheckOwnerPassword(const uint8_t* password, FX_DWORD pass_size, uint8_t* key, int32_t key_len); - FX_BOOL AES256_CheckPassword(const uint8_t* password, FX_DWORD size, FX_BOOL bOwner, uint8_t* key); - void AES256_SetPassword(CPDF_Dictionary* pEncryptDict, const uint8_t* password, FX_DWORD size, FX_BOOL bOwner, const uint8_t* key); - void AES256_SetPerms(CPDF_Dictionary* pEncryptDict, FX_DWORD permission, FX_BOOL bEncryptMetadata, const uint8_t* key); - void OnCreate(CPDF_Dictionary* pEncryptDict, CPDF_Array* pIdArray, - const uint8_t* user_pass, FX_DWORD user_size, - const uint8_t* owner_pass, FX_DWORD owner_size, FX_BOOL bDefault, FX_DWORD type); - FX_BOOL CheckSecurity(int32_t key_len); - - FX_BOOL m_bOwner; - - FX_DWORD m_Permissions; - - int m_Cipher; - - uint8_t m_EncryptKey[32]; - - int m_KeyLen; + FX_DWORD m_dwXrefStartObjNum; + friend class CPDF_Creator; + friend class CPDF_DataAvail; }; -class CPDF_CryptoHandler -{ -public: - - virtual ~CPDF_CryptoHandler() {} - - virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict, CPDF_SecurityHandler* pSecurityHandler) = 0; - - virtual FX_DWORD DecryptGetSize(FX_DWORD src_size) = 0; +#define FXCIPHER_NONE 0 +#define FXCIPHER_RC4 1 +#define FXCIPHER_AES 2 +#define FXCIPHER_AES2 3 +class CPDF_SecurityHandler { + public: + virtual ~CPDF_SecurityHandler() {} - virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0; + virtual FX_BOOL OnInit(CPDF_Parser* pParser, + CPDF_Dictionary* pEncryptDict) = 0; - virtual FX_BOOL DecryptStream(void* context, const uint8_t* src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf) = 0; + virtual FX_DWORD GetPermissions() = 0; - virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf) = 0; + virtual FX_BOOL IsOwner() = 0; + virtual FX_BOOL GetCryptInfo(int& cipher, + const uint8_t*& buffer, + int& keylen) = 0; - virtual FX_DWORD EncryptGetSize(FX_DWORD objnum, FX_DWORD version, const uint8_t* src_buf, FX_DWORD src_size) = 0; + virtual FX_BOOL IsMetadataEncrypted() { return TRUE; } - virtual FX_BOOL EncryptContent(FX_DWORD objnum, FX_DWORD version, const uint8_t* src_buf, FX_DWORD src_size, - uint8_t* dest_buf, FX_DWORD& dest_size) = 0; + virtual CPDF_CryptoHandler* CreateCryptoHandler() = 0; - void Decrypt(FX_DWORD objnum, FX_DWORD version, CFX_ByteString& str); + virtual CPDF_StandardSecurityHandler* GetStandardHandler() { return NULL; } }; -class CPDF_StandardCryptoHandler : public CPDF_CryptoHandler -{ -public: +#define PDF_ENCRYPT_CONTENT 0 +class CPDF_StandardSecurityHandler : public CPDF_SecurityHandler { + public: + CPDF_StandardSecurityHandler(); + + virtual ~CPDF_StandardSecurityHandler(); + virtual FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict); + virtual FX_DWORD GetPermissions(); + virtual FX_BOOL IsOwner() { return m_bOwner; } + virtual FX_BOOL GetCryptInfo(int& cipher, + const uint8_t*& buffer, + int& keylen); + virtual FX_BOOL IsMetadataEncrypted(); + virtual CPDF_CryptoHandler* CreateCryptoHandler(); + virtual CPDF_StandardSecurityHandler* GetStandardHandler() { return this; } + + void OnCreate(CPDF_Dictionary* pEncryptDict, + CPDF_Array* pIdArray, + const uint8_t* user_pass, + FX_DWORD user_size, + const uint8_t* owner_pass, + FX_DWORD owner_size, + FX_DWORD type = PDF_ENCRYPT_CONTENT); + + void OnCreate(CPDF_Dictionary* pEncryptDict, + CPDF_Array* pIdArray, + const uint8_t* user_pass, + FX_DWORD user_size, + FX_DWORD type = PDF_ENCRYPT_CONTENT); + + CFX_ByteString GetUserPassword(const uint8_t* owner_pass, FX_DWORD pass_size); + CFX_ByteString GetUserPassword(const uint8_t* owner_pass, + FX_DWORD pass_size, + int32_t key_len); + int GetVersion() { return m_Version; } + int GetRevision() { return m_Revision; } + + int CheckPassword(const uint8_t* password, + FX_DWORD pass_size, + FX_BOOL bOwner, + uint8_t* key); + int CheckPassword(const uint8_t* password, + FX_DWORD pass_size, + FX_BOOL bOwner, + uint8_t* key, + int key_len); + + private: + int m_Version; + + int m_Revision; + + CPDF_Parser* m_pParser; + + CPDF_Dictionary* m_pEncryptDict; + + FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict); + FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict, + FX_DWORD type, + int& cipher, + int& key_len); + + FX_BOOL CheckUserPassword(const uint8_t* password, + FX_DWORD pass_size, + FX_BOOL bIgnoreEncryptMeta, + uint8_t* key, + int32_t key_len); + + FX_BOOL CheckOwnerPassword(const uint8_t* password, + FX_DWORD pass_size, + uint8_t* key, + int32_t key_len); + FX_BOOL AES256_CheckPassword(const uint8_t* password, + FX_DWORD size, + FX_BOOL bOwner, + uint8_t* key); + void AES256_SetPassword(CPDF_Dictionary* pEncryptDict, + const uint8_t* password, + FX_DWORD size, + FX_BOOL bOwner, + const uint8_t* key); + void AES256_SetPerms(CPDF_Dictionary* pEncryptDict, + FX_DWORD permission, + FX_BOOL bEncryptMetadata, + const uint8_t* key); + void OnCreate(CPDF_Dictionary* pEncryptDict, + CPDF_Array* pIdArray, + const uint8_t* user_pass, + FX_DWORD user_size, + const uint8_t* owner_pass, + FX_DWORD owner_size, + FX_BOOL bDefault, + FX_DWORD type); + FX_BOOL CheckSecurity(int32_t key_len); + + FX_BOOL m_bOwner; + + FX_DWORD m_Permissions; + + int m_Cipher; + + uint8_t m_EncryptKey[32]; + + int m_KeyLen; +}; +class CPDF_CryptoHandler { + public: + virtual ~CPDF_CryptoHandler() {} - CPDF_StandardCryptoHandler(); + virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict, + CPDF_SecurityHandler* pSecurityHandler) = 0; - virtual ~CPDF_StandardCryptoHandler(); + virtual FX_DWORD DecryptGetSize(FX_DWORD src_size) = 0; - FX_BOOL Init(int cipher, const uint8_t* key, int keylen); - virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict, CPDF_SecurityHandler* pSecurityHandler); - virtual FX_DWORD DecryptGetSize(FX_DWORD src_size); - virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum); - virtual FX_BOOL DecryptStream(void* context, const uint8_t* src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf); - virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf); - virtual FX_DWORD EncryptGetSize(FX_DWORD objnum, FX_DWORD version, const uint8_t* src_buf, FX_DWORD src_size); - virtual FX_BOOL EncryptContent(FX_DWORD objnum, FX_DWORD version, const uint8_t* src_buf, FX_DWORD src_size, - uint8_t* dest_buf, FX_DWORD& dest_size); -protected: + virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0; - virtual void CryptBlock(FX_BOOL bEncrypt, FX_DWORD objnum, FX_DWORD gennum, const uint8_t* src_buf, FX_DWORD src_size, - uint8_t* dest_buf, FX_DWORD& dest_size); - virtual void* CryptStart(FX_DWORD objnum, FX_DWORD gennum, FX_BOOL bEncrypt); - virtual FX_BOOL CryptStream(void* context, const uint8_t* src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf, FX_BOOL bEncrypt); - virtual FX_BOOL CryptFinish(void* context, CFX_BinaryBuf& dest_buf, FX_BOOL bEncrypt); + virtual FX_BOOL DecryptStream(void* context, + const uint8_t* src_buf, + FX_DWORD src_size, + CFX_BinaryBuf& dest_buf) = 0; - uint8_t m_EncryptKey[32]; + virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf) = 0; - int m_KeyLen; + virtual FX_DWORD EncryptGetSize(FX_DWORD objnum, + FX_DWORD version, + const uint8_t* src_buf, + FX_DWORD src_size) = 0; - int m_Cipher; + virtual FX_BOOL EncryptContent(FX_DWORD objnum, + FX_DWORD version, + const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t* dest_buf, + FX_DWORD& dest_size) = 0; - uint8_t* m_pAESContext; + void Decrypt(FX_DWORD objnum, FX_DWORD version, CFX_ByteString& str); }; -class CPDF_Point -{ -public: - - CPDF_Point(FX_FLOAT xx, FX_FLOAT yy) - { - x = xx; - y = yy; - } +class CPDF_StandardCryptoHandler : public CPDF_CryptoHandler { + public: + CPDF_StandardCryptoHandler(); + + virtual ~CPDF_StandardCryptoHandler(); + + FX_BOOL Init(int cipher, const uint8_t* key, int keylen); + virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict, + CPDF_SecurityHandler* pSecurityHandler); + virtual FX_DWORD DecryptGetSize(FX_DWORD src_size); + virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum); + virtual FX_BOOL DecryptStream(void* context, + const uint8_t* src_buf, + FX_DWORD src_size, + CFX_BinaryBuf& dest_buf); + virtual FX_BOOL DecryptFinish(void* context, CFX_BinaryBuf& dest_buf); + virtual FX_DWORD EncryptGetSize(FX_DWORD objnum, + FX_DWORD version, + const uint8_t* src_buf, + FX_DWORD src_size); + virtual FX_BOOL EncryptContent(FX_DWORD objnum, + FX_DWORD version, + const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t* dest_buf, + FX_DWORD& dest_size); + + protected: + virtual void CryptBlock(FX_BOOL bEncrypt, + FX_DWORD objnum, + FX_DWORD gennum, + const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t* dest_buf, + FX_DWORD& dest_size); + virtual void* CryptStart(FX_DWORD objnum, FX_DWORD gennum, FX_BOOL bEncrypt); + virtual FX_BOOL CryptStream(void* context, + const uint8_t* src_buf, + FX_DWORD src_size, + CFX_BinaryBuf& dest_buf, + FX_BOOL bEncrypt); + virtual FX_BOOL CryptFinish(void* context, + CFX_BinaryBuf& dest_buf, + FX_BOOL bEncrypt); + + uint8_t m_EncryptKey[32]; + + int m_KeyLen; + + int m_Cipher; + + uint8_t* m_pAESContext; +}; +class CPDF_Point { + public: + CPDF_Point(FX_FLOAT xx, FX_FLOAT yy) { + x = xx; + y = yy; + } - FX_FLOAT x; + FX_FLOAT x; - FX_FLOAT y; + FX_FLOAT y; }; -#define CPDF_Rect CFX_FloatRect -#define CPDF_Matrix CFX_AffineMatrix +#define CPDF_Rect CFX_FloatRect +#define CPDF_Matrix CFX_AffineMatrix CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& orig); CFX_ByteString PDF_NameDecode(const CFX_ByteString& orig); CFX_ByteString PDF_NameEncode(const CFX_ByteString& orig); -CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex = FALSE); -CFX_WideString PDF_DecodeText(const uint8_t* pData, FX_DWORD size, CFX_CharMap* pCharMap = NULL); -inline CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr, CFX_CharMap* pCharMap = NULL) { - return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength(), pCharMap); +CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, + FX_BOOL bHex = FALSE); +CFX_WideString PDF_DecodeText(const uint8_t* pData, + FX_DWORD size, + CFX_CharMap* pCharMap = NULL); +inline CFX_WideString PDF_DecodeText(const CFX_ByteString& bstr, + CFX_CharMap* pCharMap = NULL) { + return PDF_DecodeText((const uint8_t*)bstr.c_str(), bstr.GetLength(), + pCharMap); } -CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, int len = -1, CFX_CharMap* pCharMap = NULL); -inline CFX_ByteString PDF_EncodeText(const CFX_WideString& str, CFX_CharMap* pCharMap = NULL) { - return PDF_EncodeText(str.c_str(), str.GetLength(), pCharMap); +CFX_ByteString PDF_EncodeText(const FX_WCHAR* pString, + int len = -1, + CFX_CharMap* pCharMap = NULL); +inline CFX_ByteString PDF_EncodeText(const CFX_WideString& str, + CFX_CharMap* pCharMap = NULL) { + return PDF_EncodeText(str.c_str(), str.GetLength(), pCharMap); } FX_FLOAT PDF_ClipFloat(FX_FLOAT f); -class CFDF_Document : public CPDF_IndirectObjects -{ -public: - static CFDF_Document* CreateNewDoc(); - static CFDF_Document* ParseFile(IFX_FileRead *pFile, FX_BOOL bOwnFile = FALSE); - static CFDF_Document* ParseMemory(const uint8_t* pData, FX_DWORD size); - - ~CFDF_Document(); - - FX_BOOL WriteBuf(CFX_ByteTextBuf& buf) const; - - CPDF_Dictionary* GetRoot() const - { - return m_pRootDict; - } - - CFX_WideString GetWin32Path() const; -protected: - - CFDF_Document(); - void ParseStream(IFX_FileRead *pFile, FX_BOOL bOwnFile); - CPDF_Dictionary* m_pRootDict; - IFX_FileRead* m_pFile; - FX_BOOL m_bOwnFile; -}; +class CFDF_Document : public CPDF_IndirectObjects { + public: + static CFDF_Document* CreateNewDoc(); + static CFDF_Document* ParseFile(IFX_FileRead* pFile, + FX_BOOL bOwnFile = FALSE); + static CFDF_Document* ParseMemory(const uint8_t* pData, FX_DWORD size); -CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec); -void FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec, const CFX_WideString& fullpath); + ~CFDF_Document(); -void FlateEncode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, FX_DWORD& dest_size); -FX_DWORD FlateDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, FX_DWORD& dest_size); -FX_DWORD RunLengthDecode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, FX_DWORD& dest_size); -class CPDF_NumberTree -{ -public: + FX_BOOL WriteBuf(CFX_ByteTextBuf& buf) const; - CPDF_NumberTree(CPDF_Dictionary* pRoot) - { - m_pRoot = pRoot; - } + CPDF_Dictionary* GetRoot() const { return m_pRootDict; } - CPDF_Object* LookupValue(int num); -protected: + CFX_WideString GetWin32Path() const; - CPDF_Dictionary* m_pRoot; + protected: + CFDF_Document(); + void ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile); + CPDF_Dictionary* m_pRootDict; + IFX_FileRead* m_pFile; + FX_BOOL m_bOwnFile; }; -class IFX_FileAvail -{ -public: - virtual ~IFX_FileAvail() { } - virtual FX_BOOL IsDataAvail( FX_FILESIZE offset, FX_DWORD size) = 0; +CFX_WideString FPDF_FileSpec_GetWin32Path(const CPDF_Object* pFileSpec); +void FPDF_FileSpec_SetWin32Path(CPDF_Object* pFileSpec, + const CFX_WideString& fullpath); + +void FlateEncode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +FX_DWORD FlateDecode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +FX_DWORD RunLengthDecode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size); +class CPDF_NumberTree { + public: + CPDF_NumberTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; } + + CPDF_Object* LookupValue(int num); + + protected: + CPDF_Dictionary* m_pRoot; }; -class IFX_DownloadHints -{ -public: - virtual ~IFX_DownloadHints() { } - virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size) = 0; + +class IFX_FileAvail { + public: + virtual ~IFX_FileAvail() {} + virtual FX_BOOL IsDataAvail(FX_FILESIZE offset, FX_DWORD size) = 0; }; -#define PDF_IS_LINEARIZED 1 -#define PDF_NOT_LINEARIZED 0 -#define PDF_UNKNOW_LINEARIZED -1 -#define PDFFORM_NOTAVAIL 0 -#define PDFFORM_AVAIL 1 -#define PDFFORM_NOTEXIST 2 -class IPDF_DataAvail -{ -public: - static IPDF_DataAvail* Create(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); - virtual ~IPDF_DataAvail() { } - - IFX_FileAvail* GetFileAvail() const { return m_pFileAvail; } - IFX_FileRead* GetFileRead() const { return m_pFileRead; } - - virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) = 0; - virtual void SetDocument(CPDF_Document* pDoc) = 0; - virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0; - virtual FX_BOOL IsLinearized() = 0; - virtual int32_t IsFormAvail(IFX_DownloadHints *pHints) = 0; - virtual int32_t IsLinearizedPDF() = 0; - virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize) = 0; - -protected: - IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); - - IFX_FileAvail* m_pFileAvail; - IFX_FileRead* m_pFileRead; +class IFX_DownloadHints { + public: + virtual ~IFX_DownloadHints() {} + virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size) = 0; }; -class CPDF_SortObjNumArray -{ -public: - - void AddObjNum(FX_DWORD dwObjNum); +#define PDF_IS_LINEARIZED 1 +#define PDF_NOT_LINEARIZED 0 +#define PDF_UNKNOW_LINEARIZED -1 +#define PDFFORM_NOTAVAIL 0 +#define PDFFORM_AVAIL 1 +#define PDFFORM_NOTEXIST 2 +class IPDF_DataAvail { + public: + static IPDF_DataAvail* Create(IFX_FileAvail* pFileAvail, + IFX_FileRead* pFileRead); + virtual ~IPDF_DataAvail() {} + + IFX_FileAvail* GetFileAvail() const { return m_pFileAvail; } + IFX_FileRead* GetFileRead() const { return m_pFileRead; } + + virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) = 0; + virtual void SetDocument(CPDF_Document* pDoc) = 0; + virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0; + virtual FX_BOOL IsLinearized() = 0; + virtual int32_t IsFormAvail(IFX_DownloadHints* pHints) = 0; + virtual int32_t IsLinearizedPDF() = 0; + virtual void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, + FX_DWORD* pSize) = 0; + + protected: + IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); + + IFX_FileAvail* m_pFileAvail; + IFX_FileRead* m_pFileRead; +}; +class CPDF_SortObjNumArray { + public: + void AddObjNum(FX_DWORD dwObjNum); - FX_BOOL Find(FX_DWORD dwObjNum); + FX_BOOL Find(FX_DWORD dwObjNum); - void RemoveAll() - { - m_number_array.RemoveAll(); - } -protected: + void RemoveAll() { m_number_array.RemoveAll(); } - FX_BOOL BinarySearch(FX_DWORD value, int &iNext); -protected: + protected: + FX_BOOL BinarySearch(FX_DWORD value, int& iNext); - CFX_DWordArray m_number_array; + protected: + CFX_DWordArray m_number_array; }; enum PDF_PAGENODE_TYPE { - PDF_PAGENODE_UNKOWN = 0, - PDF_PAGENODE_PAGE, - PDF_PAGENODE_PAGES, - PDF_PAGENODE_ARRAY, + PDF_PAGENODE_UNKOWN = 0, + PDF_PAGENODE_PAGE, + PDF_PAGENODE_PAGES, + PDF_PAGENODE_ARRAY, }; -class CPDF_PageNode -{ -public: - CPDF_PageNode() : m_type(PDF_PAGENODE_UNKOWN) {} - ~CPDF_PageNode(); - PDF_PAGENODE_TYPE m_type; - FX_DWORD m_dwPageNo; - CFX_PtrArray m_childNode; +class CPDF_PageNode { + public: + CPDF_PageNode() : m_type(PDF_PAGENODE_UNKOWN) {} + ~CPDF_PageNode(); + PDF_PAGENODE_TYPE m_type; + FX_DWORD m_dwPageNo; + CFX_PtrArray m_childNode; }; enum PDF_DATAAVAIL_STATUS { - PDF_DATAAVAIL_HEADER = 0, - PDF_DATAAVAIL_FIRSTPAGE, - PDF_DATAAVAIL_FIRSTPAGE_PREPARE, - PDF_DATAAVAIL_END, - PDF_DATAAVAIL_CROSSREF, - PDF_DATAAVAIL_CROSSREF_ITEM, - PDF_DATAAVAIL_CROSSREF_STREAM, - PDF_DATAAVAIL_TRAILER, - PDF_DATAAVAIL_LOADALLCRSOSSREF, - PDF_DATAAVAIL_ROOT, - PDF_DATAAVAIL_INFO, - PDF_DATAAVAIL_ACROFORM, - PDF_DATAAVAIL_ACROFORM_SUBOBJECT, - PDF_DATAAVAIL_PAGETREE, - PDF_DATAAVAIL_PAGE, - PDF_DATAAVAIL_PAGE_LATERLOAD, - PDF_DATAAVAIL_RESOURCES, - PDF_DATAAVAIL_DONE, - PDF_DATAAVAIL_ERROR, - PDF_DATAAVAIL_LOADALLFILE, - PDF_DATAAVAIL_TRAILER_APPEND + PDF_DATAAVAIL_HEADER = 0, + PDF_DATAAVAIL_FIRSTPAGE, + PDF_DATAAVAIL_FIRSTPAGE_PREPARE, + PDF_DATAAVAIL_END, + PDF_DATAAVAIL_CROSSREF, + PDF_DATAAVAIL_CROSSREF_ITEM, + PDF_DATAAVAIL_CROSSREF_STREAM, + PDF_DATAAVAIL_TRAILER, + PDF_DATAAVAIL_LOADALLCRSOSSREF, + PDF_DATAAVAIL_ROOT, + PDF_DATAAVAIL_INFO, + PDF_DATAAVAIL_ACROFORM, + PDF_DATAAVAIL_ACROFORM_SUBOBJECT, + PDF_DATAAVAIL_PAGETREE, + PDF_DATAAVAIL_PAGE, + PDF_DATAAVAIL_PAGE_LATERLOAD, + PDF_DATAAVAIL_RESOURCES, + PDF_DATAAVAIL_DONE, + PDF_DATAAVAIL_ERROR, + PDF_DATAAVAIL_LOADALLFILE, + PDF_DATAAVAIL_TRAILER_APPEND }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ diff --git a/core/include/fpdfapi/fpdf_render.h b/core/include/fpdfapi/fpdf_render.h index c0792cfc35..b0302cdc11 100644 --- a/core/include/fpdfapi/fpdf_render.h +++ b/core/include/fpdfapi/fpdf_render.h @@ -23,269 +23,275 @@ class CPDF_PathObject; class CPDF_ImageObject; class CPDF_ShadingObject; class CPDF_FormObject; -class IPDF_OCContext -{ -public: +class IPDF_OCContext { + public: + virtual ~IPDF_OCContext() {} - virtual ~IPDF_OCContext() {} + virtual FX_BOOL CheckOCGVisible(const CPDF_Dictionary* pOCG) = 0; - virtual FX_BOOL CheckOCGVisible(const CPDF_Dictionary* pOCG) = 0; - - FX_BOOL CheckObjectVisible(const CPDF_PageObject* pObj); + FX_BOOL CheckObjectVisible(const CPDF_PageObject* pObj); }; -#define RENDER_COLOR_NORMAL 0 -#define RENDER_COLOR_GRAY 1 -#define RENDER_COLOR_TWOCOLOR 2 -#define RENDER_COLOR_ALPHA 3 -#define RENDER_CLEARTYPE 0x00000001 -#define RENDER_PRINTGRAPHICTEXT 0x00000002 -#define RENDER_FORCE_DOWNSAMPLE 0x00000004 -#define RENDER_PRINTPREVIEW 0x00000008 -#define RENDER_BGR_STRIPE 0x00000010 -#define RENDER_NO_NATIVETEXT 0x00000020 -#define RENDER_FORCE_HALFTONE 0x00000040 -#define RENDER_RECT_AA 0x00000080 -#define RENDER_FILL_FULLCOVER 0x00000100 -#define RENDER_PRINTIMAGETEXT 0x00000200 -#define RENDER_OVERPRINT 0x00000400 -#define RENDER_THINLINE 0x00000800 -#define RENDER_NOTEXTSMOOTH 0x10000000 -#define RENDER_NOPATHSMOOTH 0x20000000 -#define RENDER_NOIMAGESMOOTH 0x40000000 -#define RENDER_LIMITEDIMAGECACHE 0x80000000 -class CPDF_RenderOptions -{ -public: - - CPDF_RenderOptions(); +#define RENDER_COLOR_NORMAL 0 +#define RENDER_COLOR_GRAY 1 +#define RENDER_COLOR_TWOCOLOR 2 +#define RENDER_COLOR_ALPHA 3 +#define RENDER_CLEARTYPE 0x00000001 +#define RENDER_PRINTGRAPHICTEXT 0x00000002 +#define RENDER_FORCE_DOWNSAMPLE 0x00000004 +#define RENDER_PRINTPREVIEW 0x00000008 +#define RENDER_BGR_STRIPE 0x00000010 +#define RENDER_NO_NATIVETEXT 0x00000020 +#define RENDER_FORCE_HALFTONE 0x00000040 +#define RENDER_RECT_AA 0x00000080 +#define RENDER_FILL_FULLCOVER 0x00000100 +#define RENDER_PRINTIMAGETEXT 0x00000200 +#define RENDER_OVERPRINT 0x00000400 +#define RENDER_THINLINE 0x00000800 +#define RENDER_NOTEXTSMOOTH 0x10000000 +#define RENDER_NOPATHSMOOTH 0x20000000 +#define RENDER_NOIMAGESMOOTH 0x40000000 +#define RENDER_LIMITEDIMAGECACHE 0x80000000 +class CPDF_RenderOptions { + public: + CPDF_RenderOptions(); - int m_ColorMode; + int m_ColorMode; - FX_COLORREF m_BackColor; + FX_COLORREF m_BackColor; - FX_COLORREF m_ForeColor; + FX_COLORREF m_ForeColor; - FX_DWORD m_Flags; + FX_DWORD m_Flags; - int m_Interpolation; + int m_Interpolation; - FX_DWORD m_AddFlags; + FX_DWORD m_AddFlags; - IPDF_OCContext* m_pOCContext; + IPDF_OCContext* m_pOCContext; - FX_DWORD m_dwLimitCacheSize; + FX_DWORD m_dwLimitCacheSize; - int m_HalftoneLimit; + int m_HalftoneLimit; - FX_ARGB TranslateColor(FX_ARGB argb) const; + FX_ARGB TranslateColor(FX_ARGB argb) const; }; -class CPDF_RenderContext -{ -public: - - CPDF_RenderContext(); - - void Create(CPDF_Page* pPage, FX_BOOL bFirstLayer = TRUE); - - void Create(CPDF_Document* pDoc = NULL, CPDF_PageRenderCache* pPageCache = NULL, - CPDF_Dictionary* pPageResources = NULL, FX_BOOL bFirstLayer = TRUE); +class CPDF_RenderContext { + public: + CPDF_RenderContext(); - ~CPDF_RenderContext(); + void Create(CPDF_Page* pPage, FX_BOOL bFirstLayer = TRUE); - void Clear(); + void Create(CPDF_Document* pDoc = NULL, + CPDF_PageRenderCache* pPageCache = NULL, + CPDF_Dictionary* pPageResources = NULL, + FX_BOOL bFirstLayer = TRUE); - void AppendObjectList(CPDF_PageObjects* pObjs, const CFX_AffineMatrix* pObject2Device); + ~CPDF_RenderContext(); - void Render(CFX_RenderDevice* pDevice, const CPDF_RenderOptions* pOptions = NULL, - const CFX_AffineMatrix* pFinalMatrix = NULL); + void Clear(); - void DrawObjectList(CFX_RenderDevice* pDevice, CPDF_PageObjects* pObjs, - const CFX_AffineMatrix* pObject2Device, const CPDF_RenderOptions* pOptions); + void AppendObjectList(CPDF_PageObjects* pObjs, + const CFX_AffineMatrix* pObject2Device); - void GetBackground(CFX_DIBitmap* pBuffer, const CPDF_PageObject* pObj, - const CPDF_RenderOptions* pOptions, CFX_AffineMatrix* pFinalMatrix); + void Render(CFX_RenderDevice* pDevice, + const CPDF_RenderOptions* pOptions = NULL, + const CFX_AffineMatrix* pFinalMatrix = NULL); - CPDF_PageRenderCache* GetPageCache() const - { - return m_pPageCache; - } + void DrawObjectList(CFX_RenderDevice* pDevice, + CPDF_PageObjects* pObjs, + const CFX_AffineMatrix* pObject2Device, + const CPDF_RenderOptions* pOptions); + void GetBackground(CFX_DIBitmap* pBuffer, + const CPDF_PageObject* pObj, + const CPDF_RenderOptions* pOptions, + CFX_AffineMatrix* pFinalMatrix); + CPDF_PageRenderCache* GetPageCache() const { return m_pPageCache; } - CPDF_Document* m_pDocument; + CPDF_Document* m_pDocument; - CPDF_Dictionary* m_pPageResources; + CPDF_Dictionary* m_pPageResources; - CPDF_PageRenderCache* m_pPageCache; + CPDF_PageRenderCache* m_pPageCache; -protected: + protected: + CFX_ArrayTemplate m_ContentList; - CFX_ArrayTemplate m_ContentList; + FX_BOOL m_bFirstLayer; - FX_BOOL m_bFirstLayer; - - void Render(CFX_RenderDevice* pDevice, const CPDF_PageObject* pStopObj, - const CPDF_RenderOptions* pOptions, const CFX_AffineMatrix* pFinalMatrix); - friend class CPDF_RenderStatus; - friend class CPDF_ProgressiveRenderer; + void Render(CFX_RenderDevice* pDevice, + const CPDF_PageObject* pStopObj, + const CPDF_RenderOptions* pOptions, + const CFX_AffineMatrix* pFinalMatrix); + friend class CPDF_RenderStatus; + friend class CPDF_ProgressiveRenderer; }; -class CPDF_ProgressiveRenderer -{ -public: - - CPDF_ProgressiveRenderer(); - - ~CPDF_ProgressiveRenderer(); - - typedef enum { - Ready, - ToBeContinued, - Done, - Failed - } RenderStatus; - - RenderStatus GetStatus() - { - return m_Status; - } +class CPDF_ProgressiveRenderer { + public: + CPDF_ProgressiveRenderer(); + ~CPDF_ProgressiveRenderer(); + typedef enum { Ready, ToBeContinued, Done, Failed } RenderStatus; - void Start(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice, - const CPDF_RenderOptions* pOptions, class IFX_Pause* pPause, FX_BOOL bDropObjects = FALSE); + RenderStatus GetStatus() { return m_Status; } - void Continue(class IFX_Pause* pPause); + void Start(CPDF_RenderContext* pContext, + CFX_RenderDevice* pDevice, + const CPDF_RenderOptions* pOptions, + class IFX_Pause* pPause, + FX_BOOL bDropObjects = FALSE); + void Continue(class IFX_Pause* pPause); - int EstimateProgress(); + int EstimateProgress(); - void Clear(); -protected: + void Clear(); - RenderStatus m_Status; + protected: + RenderStatus m_Status; - CPDF_RenderContext* m_pContext; + CPDF_RenderContext* m_pContext; - CFX_RenderDevice* m_pDevice; + CFX_RenderDevice* m_pDevice; - const CPDF_RenderOptions* m_pOptions; + const CPDF_RenderOptions* m_pOptions; - FX_BOOL m_bDropObjects; + FX_BOOL m_bDropObjects; - class CPDF_RenderStatus* m_pRenderer; + class CPDF_RenderStatus* m_pRenderer; - CFX_FloatRect m_ClipRect; + CFX_FloatRect m_ClipRect; - FX_DWORD m_LayerIndex; + FX_DWORD m_LayerIndex; - FX_DWORD m_ObjectIndex; + FX_DWORD m_ObjectIndex; - FX_POSITION m_ObjectPos; + FX_POSITION m_ObjectPos; - FX_POSITION m_PrevLastPos; + FX_POSITION m_PrevLastPos; - void RenderStep(); + void RenderStep(); }; -class CPDF_TextRenderer -{ -public: - - static void DrawTextString(CFX_RenderDevice* pDevice, int left, int top, - CPDF_Font* pFont, - int height, - const CFX_ByteString& str, - FX_ARGB argb); - - static void DrawTextString(CFX_RenderDevice* pDevice, FX_FLOAT origin_x, FX_FLOAT origin_y, - CPDF_Font* pFont, - FX_FLOAT font_size, - const CFX_AffineMatrix* matrix, - const CFX_ByteString& str, - FX_ARGB fill_argb, - FX_ARGB stroke_argb = 0, - const CFX_GraphStateData* pGraphState = NULL, - const CPDF_RenderOptions* pOptions = NULL - ); - - static FX_BOOL DrawTextPath(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos, - CPDF_Font* pFont, FX_FLOAT font_size, - const CFX_AffineMatrix* pText2User, const CFX_AffineMatrix* pUser2Device, - const CFX_GraphStateData* pGraphState, - FX_ARGB fill_argb, FX_ARGB stroke_argb, CFX_PathData* pClippingPath, int nFlag = 0); - - static FX_BOOL DrawNormalText(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos, - CPDF_Font* pFont, FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device, - FX_ARGB fill_argb, const CPDF_RenderOptions* pOptions); - - static FX_BOOL DrawType3Text(CFX_RenderDevice* pDevice, int nChars, FX_DWORD* pCharCodes, FX_FLOAT* pCharPos, - CPDF_Font* pFont, FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device, - FX_ARGB fill_argb); +class CPDF_TextRenderer { + public: + static void DrawTextString(CFX_RenderDevice* pDevice, + int left, + int top, + CPDF_Font* pFont, + int height, + const CFX_ByteString& str, + FX_ARGB argb); + + static void DrawTextString(CFX_RenderDevice* pDevice, + FX_FLOAT origin_x, + FX_FLOAT origin_y, + CPDF_Font* pFont, + FX_FLOAT font_size, + const CFX_AffineMatrix* matrix, + const CFX_ByteString& str, + FX_ARGB fill_argb, + FX_ARGB stroke_argb = 0, + const CFX_GraphStateData* pGraphState = NULL, + const CPDF_RenderOptions* pOptions = NULL); + + static FX_BOOL DrawTextPath(CFX_RenderDevice* pDevice, + int nChars, + FX_DWORD* pCharCodes, + FX_FLOAT* pCharPos, + CPDF_Font* pFont, + FX_FLOAT font_size, + const CFX_AffineMatrix* pText2User, + const CFX_AffineMatrix* pUser2Device, + const CFX_GraphStateData* pGraphState, + FX_ARGB fill_argb, + FX_ARGB stroke_argb, + CFX_PathData* pClippingPath, + int nFlag = 0); + + static FX_BOOL DrawNormalText(CFX_RenderDevice* pDevice, + int nChars, + FX_DWORD* pCharCodes, + FX_FLOAT* pCharPos, + CPDF_Font* pFont, + FX_FLOAT font_size, + const CFX_AffineMatrix* pText2Device, + FX_ARGB fill_argb, + const CPDF_RenderOptions* pOptions); + + static FX_BOOL DrawType3Text(CFX_RenderDevice* pDevice, + int nChars, + FX_DWORD* pCharCodes, + FX_FLOAT* pCharPos, + CPDF_Font* pFont, + FX_FLOAT font_size, + const CFX_AffineMatrix* pText2Device, + FX_ARGB fill_argb); }; -class CPDF_PageRenderCache -{ -public: - CPDF_PageRenderCache(CPDF_Page* pPage) - { - m_pPage = pPage; - m_nTimeCount = 0; - m_nCacheSize = 0; - m_pCurImageCache = NULL; - m_bCurFindCache = FALSE; - m_pCurImageCaches = NULL; - } - ~CPDF_PageRenderCache() - { - ClearAll(); - } - void ClearAll(); - void ClearImageData(); - - FX_DWORD EstimateSize(); - void CacheOptimization(int32_t dwLimitCacheSize); - FX_DWORD GetCachedSize(CPDF_Stream* pStream) const; - FX_DWORD GetTimeCount() const - { - return m_nTimeCount; - } - void SetTimeCount(FX_DWORD dwTimeCount) - { - m_nTimeCount = dwTimeCount; - } - - void GetCachedBitmap(CPDF_Stream* pStream, CFX_DIBSource*& pBitmap, CFX_DIBSource*& pMask, FX_DWORD& MatteColor, - FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0, FX_BOOL bLoadMask = FALSE, - CPDF_RenderStatus* pRenderStatus = NULL, int32_t downsampleWidth = 0, int32_t downsampleHeight = 0); - - void ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap* pBitmap); - void ClearImageCache(CPDF_Stream* pStream); - CPDF_Page* GetPage() - { - return m_pPage; - } - CFX_MapPtrToPtr m_ImageCaches; -public: - FX_BOOL StartGetCachedBitmap(CPDF_Stream* pStream, FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0, - FX_BOOL bLoadMask = FALSE, CPDF_RenderStatus* pRenderStatus = NULL, - int32_t downsampleWidth = 0, int32_t downsampleHeight = 0); - - FX_BOOL Continue(IFX_Pause* pPause); - CPDF_ImageCache* m_pCurImageCache; - CFX_PtrArray* m_pCurImageCaches; -protected: - friend class CPDF_Page; - CPDF_Page* m_pPage; - - FX_DWORD m_nTimeCount; - FX_DWORD m_nCacheSize; - FX_BOOL m_bCurFindCache; +class CPDF_PageRenderCache { + public: + CPDF_PageRenderCache(CPDF_Page* pPage) { + m_pPage = pPage; + m_nTimeCount = 0; + m_nCacheSize = 0; + m_pCurImageCache = NULL; + m_bCurFindCache = FALSE; + m_pCurImageCaches = NULL; + } + ~CPDF_PageRenderCache() { ClearAll(); } + void ClearAll(); + void ClearImageData(); + + FX_DWORD EstimateSize(); + void CacheOptimization(int32_t dwLimitCacheSize); + FX_DWORD GetCachedSize(CPDF_Stream* pStream) const; + FX_DWORD GetTimeCount() const { return m_nTimeCount; } + void SetTimeCount(FX_DWORD dwTimeCount) { m_nTimeCount = dwTimeCount; } + + void GetCachedBitmap(CPDF_Stream* pStream, + CFX_DIBSource*& pBitmap, + CFX_DIBSource*& pMask, + FX_DWORD& MatteColor, + FX_BOOL bStdCS = FALSE, + FX_DWORD GroupFamily = 0, + FX_BOOL bLoadMask = FALSE, + CPDF_RenderStatus* pRenderStatus = NULL, + int32_t downsampleWidth = 0, + int32_t downsampleHeight = 0); + + void ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap* pBitmap); + void ClearImageCache(CPDF_Stream* pStream); + CPDF_Page* GetPage() { return m_pPage; } + CFX_MapPtrToPtr m_ImageCaches; + + public: + FX_BOOL StartGetCachedBitmap(CPDF_Stream* pStream, + FX_BOOL bStdCS = FALSE, + FX_DWORD GroupFamily = 0, + FX_BOOL bLoadMask = FALSE, + CPDF_RenderStatus* pRenderStatus = NULL, + int32_t downsampleWidth = 0, + int32_t downsampleHeight = 0); + + FX_BOOL Continue(IFX_Pause* pPause); + CPDF_ImageCache* m_pCurImageCache; + CFX_PtrArray* m_pCurImageCaches; + + protected: + friend class CPDF_Page; + CPDF_Page* m_pPage; + + FX_DWORD m_nTimeCount; + FX_DWORD m_nCacheSize; + FX_BOOL m_bCurFindCache; }; -class CPDF_RenderConfig -{ -public: - CPDF_RenderConfig(); - ~CPDF_RenderConfig(); - int m_HalftoneLimit; - int m_RenderStepLimit; +class CPDF_RenderConfig { + public: + CPDF_RenderConfig(); + ~CPDF_RenderConfig(); + int m_HalftoneLimit; + int m_RenderStepLimit; }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_RENDER_H_ diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h index 5c8cc85217..c41a306d54 100644 --- a/core/include/fpdfapi/fpdf_resource.h +++ b/core/include/fpdfapi/fpdf_resource.h @@ -51,911 +51,792 @@ const FX_CHAR* GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pCharNames, int charcode); -template class CPDF_CountedObject -{ -public: - explicit CPDF_CountedObject(T* ptr) : m_nCount(1), m_pObj(ptr) { } - void reset(T* ptr) { // CAUTION: tosses prior ref counts. - m_nCount = 1; - m_pObj = ptr; - } - void clear() { // Now you're all weak ptrs ... - delete m_pObj; - m_pObj = nullptr; - } - T* get() const { return m_pObj; } - T* AddRef() { FXSYS_assert(m_pObj); ++m_nCount; return m_pObj; } - void RemoveRef() { if (m_nCount) --m_nCount; } - size_t use_count() const { return m_nCount; } - -protected: - size_t m_nCount; - T* m_pObj; +template +class CPDF_CountedObject { + public: + explicit CPDF_CountedObject(T* ptr) : m_nCount(1), m_pObj(ptr) {} + void reset(T* ptr) { // CAUTION: tosses prior ref counts. + m_nCount = 1; + m_pObj = ptr; + } + void clear() { // Now you're all weak ptrs ... + delete m_pObj; + m_pObj = nullptr; + } + T* get() const { return m_pObj; } + T* AddRef() { + FXSYS_assert(m_pObj); + ++m_nCount; + return m_pObj; + } + void RemoveRef() { + if (m_nCount) + --m_nCount; + } + size_t use_count() const { return m_nCount; } + + protected: + size_t m_nCount; + T* m_pObj; }; using CPDF_CountedColorSpace = CPDF_CountedObject; using CPDF_CountedPattern = CPDF_CountedObject; -#define PDFFONT_TYPE1 1 -#define PDFFONT_TRUETYPE 2 -#define PDFFONT_TYPE3 3 -#define PDFFONT_CIDFONT 4 -#define PDFFONT_FIXEDPITCH 1 -#define PDFFONT_SERIF 2 -#define PDFFONT_SYMBOLIC 4 -#define PDFFONT_SCRIPT 8 -#define PDFFONT_NONSYMBOLIC 32 -#define PDFFONT_ITALIC 64 -#define PDFFONT_ALLCAP 0x10000 -#define PDFFONT_SMALLCAP 0x20000 -#define PDFFONT_FORCEBOLD 0x40000 -#define PDFFONT_USEEXTERNATTR 0x80000 -class CPDF_Font -{ -public: - static CPDF_Font* CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict); - static CPDF_Font* GetStockFont(CPDF_Document* pDoc, const CFX_ByteStringC& fontname); - - virtual ~CPDF_Font(); - - bool IsFontType(int fonttype) const { return fonttype == m_FontType; } - int GetFontType() const { return m_FontType; } - - CFX_ByteString GetFontTypeName() const; - - const CFX_ByteString& GetBaseFont() const - { - return m_BaseFont; - } +#define PDFFONT_TYPE1 1 +#define PDFFONT_TRUETYPE 2 +#define PDFFONT_TYPE3 3 +#define PDFFONT_CIDFONT 4 +#define PDFFONT_FIXEDPITCH 1 +#define PDFFONT_SERIF 2 +#define PDFFONT_SYMBOLIC 4 +#define PDFFONT_SCRIPT 8 +#define PDFFONT_NONSYMBOLIC 32 +#define PDFFONT_ITALIC 64 +#define PDFFONT_ALLCAP 0x10000 +#define PDFFONT_SMALLCAP 0x20000 +#define PDFFONT_FORCEBOLD 0x40000 +#define PDFFONT_USEEXTERNATTR 0x80000 +class CPDF_Font { + public: + static CPDF_Font* CreateFontF(CPDF_Document* pDoc, + CPDF_Dictionary* pFontDict); + static CPDF_Font* GetStockFont(CPDF_Document* pDoc, + const CFX_ByteStringC& fontname); - const CFX_SubstFont* GetSubstFont() const - { - return m_Font.GetSubstFont(); - } + virtual ~CPDF_Font(); - FX_DWORD GetFlags() const - { - return m_Flags; - } + bool IsFontType(int fonttype) const { return fonttype == m_FontType; } + int GetFontType() const { return m_FontType; } - virtual FX_BOOL IsVertWriting()const; + CFX_ByteString GetFontTypeName() const; + const CFX_ByteString& GetBaseFont() const { return m_BaseFont; } + const CFX_SubstFont* GetSubstFont() const { return m_Font.GetSubstFont(); } + FX_DWORD GetFlags() const { return m_Flags; } - CPDF_Type1Font* GetType1Font() const - { - return m_FontType == PDFFONT_TYPE1 ? (CPDF_Type1Font*)(void*)this : NULL; - } + virtual FX_BOOL IsVertWriting() const; - CPDF_TrueTypeFont* GetTrueTypeFont() const - { - return m_FontType == PDFFONT_TRUETYPE ? (CPDF_TrueTypeFont*)(void*)this : NULL; - } + CPDF_Type1Font* GetType1Font() const { + return m_FontType == PDFFONT_TYPE1 ? (CPDF_Type1Font*)(void*)this : NULL; + } - CPDF_CIDFont* GetCIDFont() const - { - return (m_FontType == PDFFONT_CIDFONT) ? (CPDF_CIDFont*)(void*)this : NULL; - } + CPDF_TrueTypeFont* GetTrueTypeFont() const { + return m_FontType == PDFFONT_TRUETYPE ? (CPDF_TrueTypeFont*)(void*)this + : NULL; + } - CPDF_Type3Font* GetType3Font() const - { - return (m_FontType == PDFFONT_TYPE3) ? (CPDF_Type3Font*)(void*)this : NULL; - } + CPDF_CIDFont* GetCIDFont() const { + return (m_FontType == PDFFONT_CIDFONT) ? (CPDF_CIDFont*)(void*)this : NULL; + } + CPDF_Type3Font* GetType3Font() const { + return (m_FontType == PDFFONT_TYPE3) ? (CPDF_Type3Font*)(void*)this : NULL; + } - FX_BOOL IsEmbedded() const - { - return m_FontType == PDFFONT_TYPE3 || m_pFontFile != NULL; - } + FX_BOOL IsEmbedded() const { + return m_FontType == PDFFONT_TYPE3 || m_pFontFile != NULL; + } - virtual FX_BOOL IsUnicodeCompatible() const - { - return FALSE; - } + virtual FX_BOOL IsUnicodeCompatible() const { return FALSE; } - CPDF_StreamAcc* GetFontFile() const - { - return m_pFontFile; - } + CPDF_StreamAcc* GetFontFile() const { return m_pFontFile; } - CPDF_Dictionary* GetFontDict() const - { - return m_pFontDict; - } + CPDF_Dictionary* GetFontDict() const { return m_pFontDict; } - FX_BOOL IsStandardFont() const; + FX_BOOL IsStandardFont() const; - FXFT_Face GetFace() const - { - return m_Font.GetFace(); - } + FXFT_Face GetFace() const { return m_Font.GetFace(); } - virtual FX_DWORD GetNextChar(const FX_CHAR* pString, int nStrLen, int& offset) const - { - if (offset < 0 || nStrLen < 1) { - return 0; - } - uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen-1]; - return static_cast(ch); + virtual FX_DWORD GetNextChar(const FX_CHAR* pString, + int nStrLen, + int& offset) const { + if (offset < 0 || nStrLen < 1) { + return 0; } + uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1]; + return static_cast(ch); + } - virtual int CountChar(const FX_CHAR* pString, int size) const - { - return size; - } + virtual int CountChar(const FX_CHAR* pString, int size) const { return size; } - void AppendChar(CFX_ByteString& str, FX_DWORD charcode) const; + void AppendChar(CFX_ByteString& str, FX_DWORD charcode) const; - virtual int AppendChar(FX_CHAR* buf, FX_DWORD charcode) const - { - *buf = (FX_CHAR)charcode; - return 1; - } + virtual int AppendChar(FX_CHAR* buf, FX_DWORD charcode) const { + *buf = (FX_CHAR)charcode; + return 1; + } - virtual int GetCharSize(FX_DWORD charcode) const - { - return 1; - } + virtual int GetCharSize(FX_DWORD charcode) const { return 1; } + virtual int GlyphFromCharCode(FX_DWORD charcode, + FX_BOOL* pVertGlyph = NULL) = 0; + virtual int GlyphFromCharCodeExt(FX_DWORD charcode) { + return GlyphFromCharCode(charcode); + } + CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const; + FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const; - virtual int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL) = 0; - virtual int GlyphFromCharCodeExt(FX_DWORD charcode) - { - return GlyphFromCharCode(charcode); - } + CFX_CharMap* GetCharMap() { return m_pCharMap; } - CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const; + CFX_ByteString EncodeString(const CFX_WideString& str) const; - FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const; + CFX_WideString DecodeString(const CFX_ByteString& str) const; - CFX_CharMap* GetCharMap() - { - return m_pCharMap; - } + void GetFontBBox(FX_RECT& rect) const { rect = m_FontBBox; } - CFX_ByteString EncodeString(const CFX_WideString& str) const; + int GetTypeAscent() const { return m_Ascent; } - CFX_WideString DecodeString(const CFX_ByteString& str) const; + int GetTypeDescent() const { return m_Descent; } + int GetItalicAngle() const { return m_ItalicAngle; } + int GetStemV() const { return m_StemV; } + int GetStringWidth(const FX_CHAR* pString, int size); - void GetFontBBox(FX_RECT& rect) const - { - rect = m_FontBBox; - } + virtual int GetCharWidthF(FX_DWORD charcode, int level = 0) = 0; - int GetTypeAscent() const - { - return m_Ascent; - } - - int GetTypeDescent() const - { - return m_Descent; - } - - int GetItalicAngle() const - { - return m_ItalicAngle; - } - - int GetStemV() const - { - return m_StemV; - } + virtual int GetCharTypeWidth(FX_DWORD charcode); - int GetStringWidth(const FX_CHAR* pString, int size); + virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) = 0; - virtual int GetCharWidthF(FX_DWORD charcode, int level = 0) = 0; + CPDF_Document* m_pDocument; - virtual int GetCharTypeWidth(FX_DWORD charcode); + class CFX_PathData* LoadGlyphPath(FX_DWORD charcode, int dest_width = 0); - virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) = 0; + CFX_Font m_Font; + protected: + explicit CPDF_Font(int fonttype); + FX_BOOL Initialize(); - CPDF_Document* m_pDocument; + FX_BOOL Load(); - class CFX_PathData* LoadGlyphPath(FX_DWORD charcode, int dest_width = 0); + virtual FX_BOOL _Load() = 0; - CFX_Font m_Font; + virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const = 0; -protected: - explicit CPDF_Font(int fonttype); + virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const = 0; - FX_BOOL Initialize(); + void LoadUnicodeMap(); - FX_BOOL Load(); + void LoadPDFEncoding(CPDF_Object* pEncoding, + int& iBaseEncoding, + CFX_ByteString*& pCharNames, + FX_BOOL bEmbedded, + FX_BOOL bTrueType); - virtual FX_BOOL _Load() = 0; + void LoadFontDescriptor(CPDF_Dictionary*); - virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const = 0; + void LoadCharWidths(FX_WORD* pWidths); - virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const = 0; + void CheckFontMetrics(); - void LoadUnicodeMap(); + CFX_CharMap* m_pCharMap; - void LoadPDFEncoding(CPDF_Object* pEncoding, int& iBaseEncoding, - CFX_ByteString*& pCharNames, FX_BOOL bEmbedded, FX_BOOL bTrueType); + CFX_ByteString m_BaseFont; - void LoadFontDescriptor(CPDF_Dictionary*); + CPDF_StreamAcc* m_pFontFile; - void LoadCharWidths(FX_WORD* pWidths); + CPDF_Dictionary* m_pFontDict; - void CheckFontMetrics(); + CPDF_ToUnicodeMap* m_pToUnicodeMap; - CFX_CharMap* m_pCharMap; + FX_BOOL m_bToUnicodeLoaded; + int m_Flags; + FX_RECT m_FontBBox; - CFX_ByteString m_BaseFont; + int m_StemV; - CPDF_StreamAcc* m_pFontFile; + int m_Ascent; - CPDF_Dictionary* m_pFontDict; - - CPDF_ToUnicodeMap* m_pToUnicodeMap; - - FX_BOOL m_bToUnicodeLoaded; + int m_Descent; + int m_ItalicAngle; + private: + const int m_FontType; +}; +#define PDFFONT_ENCODING_BUILTIN 0 +#define PDFFONT_ENCODING_WINANSI 1 +#define PDFFONT_ENCODING_MACROMAN 2 +#define PDFFONT_ENCODING_MACEXPERT 3 +#define PDFFONT_ENCODING_STANDARD 4 +#define PDFFONT_ENCODING_ADOBE_SYMBOL 5 +#define PDFFONT_ENCODING_ZAPFDINGBATS 6 +#define PDFFONT_ENCODING_PDFDOC 7 +#define PDFFONT_ENCODING_MS_SYMBOL 8 +#define PDFFONT_ENCODING_UNICODE 9 +class CPDF_FontEncoding { + public: + CPDF_FontEncoding(); + CPDF_FontEncoding(int PredefinedEncoding); - int m_Flags; + void LoadEncoding(CPDF_Object* pEncoding); - FX_RECT m_FontBBox; + FX_BOOL IsIdentical(CPDF_FontEncoding* pAnother) const; - int m_StemV; + FX_WCHAR UnicodeFromCharCode(uint8_t charcode) const { + return m_Unicodes[charcode]; + } - int m_Ascent; + int CharCodeFromUnicode(FX_WCHAR unicode) const; - int m_Descent; + void SetUnicode(uint8_t charcode, FX_WCHAR unicode) { + m_Unicodes[charcode] = unicode; + } - int m_ItalicAngle; + CPDF_Object* Realize(); -private: - const int m_FontType; + public: + FX_WCHAR m_Unicodes[256]; }; -#define PDFFONT_ENCODING_BUILTIN 0 -#define PDFFONT_ENCODING_WINANSI 1 -#define PDFFONT_ENCODING_MACROMAN 2 -#define PDFFONT_ENCODING_MACEXPERT 3 -#define PDFFONT_ENCODING_STANDARD 4 -#define PDFFONT_ENCODING_ADOBE_SYMBOL 5 -#define PDFFONT_ENCODING_ZAPFDINGBATS 6 -#define PDFFONT_ENCODING_PDFDOC 7 -#define PDFFONT_ENCODING_MS_SYMBOL 8 -#define PDFFONT_ENCODING_UNICODE 9 -class CPDF_FontEncoding -{ -public: - - CPDF_FontEncoding(); - - CPDF_FontEncoding(int PredefinedEncoding); - - void LoadEncoding(CPDF_Object* pEncoding); - - FX_BOOL IsIdentical(CPDF_FontEncoding* pAnother) const; - - FX_WCHAR UnicodeFromCharCode(uint8_t charcode) const - { - return m_Unicodes[charcode]; - } - int CharCodeFromUnicode(FX_WCHAR unicode) const; +class CPDF_SimpleFont : public CPDF_Font { + public: + explicit CPDF_SimpleFont(int fonttype); + ~CPDF_SimpleFont() override; - void SetUnicode(uint8_t charcode, FX_WCHAR unicode) - { - m_Unicodes[charcode] = unicode; - } - - CPDF_Object* Realize(); -public: + CPDF_FontEncoding* GetEncoding() { return &m_Encoding; } + int GetCharWidthF(FX_DWORD charcode, int level = 0) override; + void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; + int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) override; + FX_BOOL IsUnicodeCompatible() const override; - FX_WCHAR m_Unicodes[256]; -}; + protected: + FX_BOOL LoadCommon(); -class CPDF_SimpleFont : public CPDF_Font -{ -public: - explicit CPDF_SimpleFont(int fonttype); - ~CPDF_SimpleFont() override; + void LoadSubstFont(); - CPDF_FontEncoding* GetEncoding() - { - return &m_Encoding; - } - int GetCharWidthF(FX_DWORD charcode, int level = 0) override; - void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; - int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL) override; - FX_BOOL IsUnicodeCompatible() const override; + void LoadFaceMetrics(); -protected: - FX_BOOL LoadCommon(); + virtual void LoadGlyphMap() = 0; - void LoadSubstFont(); + FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override { + return m_Encoding.UnicodeFromCharCode((uint8_t)charcode); + } - void LoadFaceMetrics(); + FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override { + return m_Encoding.CharCodeFromUnicode(Unicode); + } - virtual void LoadGlyphMap() = 0; + void LoadCharMetrics(int charcode); - FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override - { - return m_Encoding.UnicodeFromCharCode((uint8_t)charcode); - } - - FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override - { - return m_Encoding.CharCodeFromUnicode(Unicode); - } - - void LoadCharMetrics(int charcode); - - CPDF_FontEncoding m_Encoding; - FX_WORD m_GlyphIndex[256]; - FX_WORD m_ExtGID[256]; - CFX_ByteString* m_pCharNames; - int m_BaseEncoding; - FX_WORD m_CharWidth[256]; - FX_SMALL_RECT m_CharBBox[256]; - FX_BOOL m_bUseFontWidth; + CPDF_FontEncoding m_Encoding; + FX_WORD m_GlyphIndex[256]; + FX_WORD m_ExtGID[256]; + CFX_ByteString* m_pCharNames; + int m_BaseEncoding; + FX_WORD m_CharWidth[256]; + FX_SMALL_RECT m_CharBBox[256]; + FX_BOOL m_bUseFontWidth; }; -class CPDF_Type1Font : public CPDF_SimpleFont -{ -public: +class CPDF_Type1Font : public CPDF_SimpleFont { + public: + CPDF_Type1Font(); - CPDF_Type1Font(); + int GetBase14Font() { return m_Base14Font; } + virtual int GlyphFromCharCodeExt(FX_DWORD charcode); - int GetBase14Font() - { - return m_Base14Font; - } - virtual int GlyphFromCharCodeExt(FX_DWORD charcode); -protected: - virtual FX_BOOL _Load(); + protected: + virtual FX_BOOL _Load(); - int m_Base14Font; - virtual void LoadGlyphMap(); -}; -class CPDF_TrueTypeFont : public CPDF_SimpleFont -{ -public: - - CPDF_TrueTypeFont(); -protected: - virtual FX_BOOL _Load(); - virtual void LoadGlyphMap(); + int m_Base14Font; + virtual void LoadGlyphMap(); }; -class CPDF_Type3Char -{ -public: - - CPDF_Type3Char(); - - ~CPDF_Type3Char(); +class CPDF_TrueTypeFont : public CPDF_SimpleFont { + public: + CPDF_TrueTypeFont(); - FX_BOOL LoadBitmap(CPDF_RenderContext* pContext); - - FX_BOOL m_bColored; + protected: + virtual FX_BOOL _Load(); + virtual void LoadGlyphMap(); +}; +class CPDF_Type3Char { + public: + CPDF_Type3Char(); - FX_BOOL m_bPageRequired; + ~CPDF_Type3Char(); + FX_BOOL LoadBitmap(CPDF_RenderContext* pContext); + FX_BOOL m_bColored; - CPDF_Form* m_pForm; + FX_BOOL m_bPageRequired; - CFX_AffineMatrix m_ImageMatrix; + CPDF_Form* m_pForm; - CFX_DIBitmap* m_pBitmap; + CFX_AffineMatrix m_ImageMatrix; + CFX_DIBitmap* m_pBitmap; - int m_Width; + int m_Width; - FX_RECT m_BBox; + FX_RECT m_BBox; }; -class CPDF_Type3Font : public CPDF_SimpleFont -{ -public: - CPDF_Type3Font(); - ~CPDF_Type3Font() override; - - void SetPageResources(CPDF_Dictionary* pResources) - { - m_pPageResources = pResources; - } - CPDF_Type3Char* LoadChar(FX_DWORD charcode, int level = 0); - int GetCharWidthF(FX_DWORD charcode, int level = 0) override; - int GetCharTypeWidth(FX_DWORD charcode) override - { - return GetCharWidthF(charcode); - } - void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; - CFX_AffineMatrix& GetFontMatrix() - { - return m_FontMatrix; - } - void CheckType3FontMetrics(); - -protected: - CFX_AffineMatrix m_FontMatrix; - -private: - FX_BOOL _Load() override; - void LoadGlyphMap() override {} - - int m_CharWidthL[256]; - CPDF_Dictionary* m_pCharProcs; - CPDF_Dictionary* m_pPageResources; - CPDF_Dictionary* m_pFontResources; - CFX_MapPtrToPtr m_CacheMap; - CFX_MapPtrToPtr m_DeletedMap; +class CPDF_Type3Font : public CPDF_SimpleFont { + public: + CPDF_Type3Font(); + ~CPDF_Type3Font() override; + + void SetPageResources(CPDF_Dictionary* pResources) { + m_pPageResources = pResources; + } + CPDF_Type3Char* LoadChar(FX_DWORD charcode, int level = 0); + int GetCharWidthF(FX_DWORD charcode, int level = 0) override; + int GetCharTypeWidth(FX_DWORD charcode) override { + return GetCharWidthF(charcode); + } + void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; + CFX_AffineMatrix& GetFontMatrix() { return m_FontMatrix; } + void CheckType3FontMetrics(); + + protected: + CFX_AffineMatrix m_FontMatrix; + + private: + FX_BOOL _Load() override; + void LoadGlyphMap() override {} + + int m_CharWidthL[256]; + CPDF_Dictionary* m_pCharProcs; + CPDF_Dictionary* m_pPageResources; + CPDF_Dictionary* m_pFontResources; + CFX_MapPtrToPtr m_CacheMap; + CFX_MapPtrToPtr m_DeletedMap; }; -#define CIDSET_UNKNOWN 0 -#define CIDSET_GB1 1 -#define CIDSET_CNS1 2 -#define CIDSET_JAPAN1 3 -#define CIDSET_KOREA1 4 -#define CIDSET_UNICODE 5 -#define NUMBER_OF_CIDSETS 6 - -class CPDF_CIDFont : public CPDF_Font -{ -public: - - CPDF_CIDFont(); - - ~CPDF_CIDFont() override; - - FX_BOOL LoadGB2312(); - int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL *pVertGlyph = NULL) override; - int GetCharWidthF(FX_DWORD charcode, int level = 0) override; - void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; - FX_WORD CIDFromCharCode(FX_DWORD charcode) const; - - FX_BOOL IsTrueType() const - { - return !m_bType1; - } - - virtual FX_DWORD GetNextChar(const FX_CHAR* pString, int nStrLen, int& offset) const override; - int CountChar(const FX_CHAR* pString, int size) const override; - int AppendChar(FX_CHAR* str, FX_DWORD charcode) const override; - int GetCharSize(FX_DWORD charcode) const override; - - int GetCharset() const - { - return m_Charset; - } - - const uint8_t* GetCIDTransform(FX_WORD CID) const; - FX_BOOL IsVertWriting() const override; - short GetVertWidth(FX_WORD CID) const; - void GetVertOrigin(FX_WORD CID, short& vx, short& vy) const; - FX_BOOL IsUnicodeCompatible() const override; - virtual FX_BOOL IsFontStyleFromCharCode(FX_DWORD charcode) const; - -protected: - friend class CPDF_Font; - - FX_BOOL _Load() override; - FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override; - FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override; - int GetGlyphIndex(FX_DWORD unicodeb, FX_BOOL *pVertGlyph); - void LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result, int nElements); - void LoadSubstFont(); - - CPDF_CMap* m_pCMap; - CPDF_CMap* m_pAllocatedCMap; - CPDF_CID2UnicodeMap* m_pCID2UnicodeMap; - int m_Charset; - FX_BOOL m_bType1; - CPDF_StreamAcc* m_pCIDToGIDMap; - FX_BOOL m_bCIDIsGID; - FX_WORD m_DefaultWidth; - FX_WORD* m_pAnsiWidths; - FX_SMALL_RECT m_CharBBox[256]; - CFX_DWordArray m_WidthList; - short m_DefaultVY; - short m_DefaultW1; - CFX_DWordArray m_VertMetrics; - FX_BOOL m_bAdobeCourierStd; - CFX_CTTGSUBTable* m_pTTGSUBTable; +#define CIDSET_UNKNOWN 0 +#define CIDSET_GB1 1 +#define CIDSET_CNS1 2 +#define CIDSET_JAPAN1 3 +#define CIDSET_KOREA1 4 +#define CIDSET_UNICODE 5 +#define NUMBER_OF_CIDSETS 6 + +class CPDF_CIDFont : public CPDF_Font { + public: + CPDF_CIDFont(); + + ~CPDF_CIDFont() override; + + FX_BOOL LoadGB2312(); + int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) override; + int GetCharWidthF(FX_DWORD charcode, int level = 0) override; + void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; + FX_WORD CIDFromCharCode(FX_DWORD charcode) const; + + FX_BOOL IsTrueType() const { return !m_bType1; } + + virtual FX_DWORD GetNextChar(const FX_CHAR* pString, + int nStrLen, + int& offset) const override; + int CountChar(const FX_CHAR* pString, int size) const override; + int AppendChar(FX_CHAR* str, FX_DWORD charcode) const override; + int GetCharSize(FX_DWORD charcode) const override; + + int GetCharset() const { return m_Charset; } + + const uint8_t* GetCIDTransform(FX_WORD CID) const; + FX_BOOL IsVertWriting() const override; + short GetVertWidth(FX_WORD CID) const; + void GetVertOrigin(FX_WORD CID, short& vx, short& vy) const; + FX_BOOL IsUnicodeCompatible() const override; + virtual FX_BOOL IsFontStyleFromCharCode(FX_DWORD charcode) const; + + protected: + friend class CPDF_Font; + + FX_BOOL _Load() override; + FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override; + FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override; + int GetGlyphIndex(FX_DWORD unicodeb, FX_BOOL* pVertGlyph); + void LoadMetricsArray(CPDF_Array* pArray, + CFX_DWordArray& result, + int nElements); + void LoadSubstFont(); + + CPDF_CMap* m_pCMap; + CPDF_CMap* m_pAllocatedCMap; + CPDF_CID2UnicodeMap* m_pCID2UnicodeMap; + int m_Charset; + FX_BOOL m_bType1; + CPDF_StreamAcc* m_pCIDToGIDMap; + FX_BOOL m_bCIDIsGID; + FX_WORD m_DefaultWidth; + FX_WORD* m_pAnsiWidths; + FX_SMALL_RECT m_CharBBox[256]; + CFX_DWordArray m_WidthList; + short m_DefaultVY; + short m_DefaultW1; + CFX_DWordArray m_VertMetrics; + FX_BOOL m_bAdobeCourierStd; + CFX_CTTGSUBTable* m_pTTGSUBTable; }; -#define PDFCS_DEVICEGRAY 1 -#define PDFCS_DEVICERGB 2 -#define PDFCS_DEVICECMYK 3 -#define PDFCS_CALGRAY 4 -#define PDFCS_CALRGB 5 -#define PDFCS_LAB 6 -#define PDFCS_ICCBASED 7 -#define PDFCS_SEPARATION 8 -#define PDFCS_DEVICEN 9 -#define PDFCS_INDEXED 10 -#define PDFCS_PATTERN 11 - -class CPDF_ColorSpace -{ -public: - - static CPDF_ColorSpace* GetStockCS(int Family); - - static CPDF_ColorSpace* Load(CPDF_Document* pDoc, CPDF_Object* pCSObj); - - void ReleaseCS(); - - int GetBufSize() const; - - FX_FLOAT* CreateBuf(); - - void GetDefaultColor(FX_FLOAT* buf) const; - - int CountComponents() const - { - return m_nComponents; - } - - int GetFamily() const - { - return m_Family; - } - - virtual void GetDefaultValue(int iComponent, FX_FLOAT& value, FX_FLOAT& min, FX_FLOAT& max) const - { - value = 0; - min = 0; - max = 1.0f; - } - - FX_BOOL sRGB() const; - - - - virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const = 0; - - virtual FX_BOOL SetRGB(FX_FLOAT* pBuf, FX_FLOAT R, FX_FLOAT G, FX_FLOAT B) const - { - return FALSE; - } - - - - - FX_BOOL GetCMYK(FX_FLOAT* pBuf, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k) const; - - FX_BOOL SetCMYK(FX_FLOAT* pBuf, FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k) const; - - - virtual void TranslateImageLine(uint8_t* dest_buf, const uint8_t* src_buf, int pixels, - int image_width, int image_height, FX_BOOL bTransMask = FALSE) const; - - CPDF_Array*& GetArray() - { - return m_pArray; - } - - int GetMaxIndex() const; - - virtual CPDF_ColorSpace* GetBaseCS() const - { - return NULL; - } - - virtual void EnableStdConversion(FX_BOOL bEnabled); - - CPDF_Document* const m_pDocument; - -protected: - CPDF_ColorSpace(CPDF_Document* pDoc, int family, int nComponents) - : m_pDocument(pDoc), - m_Family(family), - m_nComponents(nComponents), - m_pArray(nullptr), - m_dwStdConversion(0) { - } - virtual ~CPDF_ColorSpace() {} - virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) - { - return TRUE; - } - virtual FX_BOOL v_GetCMYK(FX_FLOAT* pBuf, FX_FLOAT& c, FX_FLOAT& m, FX_FLOAT& y, FX_FLOAT& k) const - { - return FALSE; - } - virtual FX_BOOL v_SetCMYK(FX_FLOAT* pBuf, FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k) const - { - return FALSE; - } - - int m_Family; - - int m_nComponents; - - CPDF_Array* m_pArray; - - FX_DWORD m_dwStdConversion; +#define PDFCS_DEVICEGRAY 1 +#define PDFCS_DEVICERGB 2 +#define PDFCS_DEVICECMYK 3 +#define PDFCS_CALGRAY 4 +#define PDFCS_CALRGB 5 +#define PDFCS_LAB 6 +#define PDFCS_ICCBASED 7 +#define PDFCS_SEPARATION 8 +#define PDFCS_DEVICEN 9 +#define PDFCS_INDEXED 10 +#define PDFCS_PATTERN 11 + +class CPDF_ColorSpace { + public: + static CPDF_ColorSpace* GetStockCS(int Family); + + static CPDF_ColorSpace* Load(CPDF_Document* pDoc, CPDF_Object* pCSObj); + + void ReleaseCS(); + + int GetBufSize() const; + + FX_FLOAT* CreateBuf(); + + void GetDefaultColor(FX_FLOAT* buf) const; + + int CountComponents() const { return m_nComponents; } + + int GetFamily() const { return m_Family; } + + virtual void GetDefaultValue(int iComponent, + FX_FLOAT& value, + FX_FLOAT& min, + FX_FLOAT& max) const { + value = 0; + min = 0; + max = 1.0f; + } + + FX_BOOL sRGB() const; + + virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, + FX_FLOAT& R, + FX_FLOAT& G, + FX_FLOAT& B) const = 0; + + virtual FX_BOOL SetRGB(FX_FLOAT* pBuf, + FX_FLOAT R, + FX_FLOAT G, + FX_FLOAT B) const { + return FALSE; + } + + FX_BOOL GetCMYK(FX_FLOAT* pBuf, + FX_FLOAT& c, + FX_FLOAT& m, + FX_FLOAT& y, + FX_FLOAT& k) const; + + FX_BOOL SetCMYK(FX_FLOAT* pBuf, + FX_FLOAT c, + FX_FLOAT m, + FX_FLOAT y, + FX_FLOAT k) const; + + virtual void TranslateImageLine(uint8_t* dest_buf, + const uint8_t* src_buf, + int pixels, + int image_width, + int image_height, + FX_BOOL bTransMask = FALSE) const; + + CPDF_Array*& GetArray() { return m_pArray; } + + int GetMaxIndex() const; + + virtual CPDF_ColorSpace* GetBaseCS() const { return NULL; } + + virtual void EnableStdConversion(FX_BOOL bEnabled); + + CPDF_Document* const m_pDocument; + + protected: + CPDF_ColorSpace(CPDF_Document* pDoc, int family, int nComponents) + : m_pDocument(pDoc), + m_Family(family), + m_nComponents(nComponents), + m_pArray(nullptr), + m_dwStdConversion(0) {} + virtual ~CPDF_ColorSpace() {} + virtual FX_BOOL v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { + return TRUE; + } + virtual FX_BOOL v_GetCMYK(FX_FLOAT* pBuf, + FX_FLOAT& c, + FX_FLOAT& m, + FX_FLOAT& y, + FX_FLOAT& k) const { + return FALSE; + } + virtual FX_BOOL v_SetCMYK(FX_FLOAT* pBuf, + FX_FLOAT c, + FX_FLOAT m, + FX_FLOAT y, + FX_FLOAT k) const { + return FALSE; + } + + int m_Family; + + int m_nComponents; + + CPDF_Array* m_pArray; + + FX_DWORD m_dwStdConversion; }; -class CPDF_Color -{ -public: +class CPDF_Color { + public: + CPDF_Color() : m_pCS(NULL), m_pBuffer(NULL) {} - CPDF_Color() :m_pCS(NULL), m_pBuffer(NULL) - { - } + CPDF_Color(int family); - CPDF_Color(int family); + ~CPDF_Color(); - ~CPDF_Color(); + FX_BOOL IsNull() const { return m_pBuffer == NULL; } - FX_BOOL IsNull() const - { - return m_pBuffer == NULL; - } + FX_BOOL IsEqual(const CPDF_Color& other) const; - FX_BOOL IsEqual(const CPDF_Color& other) const; + FX_BOOL IsPattern() const { + return m_pCS && m_pCS->GetFamily() == PDFCS_PATTERN; + } - FX_BOOL IsPattern() const - { - return m_pCS && m_pCS->GetFamily() == PDFCS_PATTERN; - } + void Copy(const CPDF_Color* pSrc); - void Copy(const CPDF_Color* pSrc); + void SetColorSpace(CPDF_ColorSpace* pCS); - void SetColorSpace(CPDF_ColorSpace* pCS); + void SetValue(FX_FLOAT* comp); - void SetValue(FX_FLOAT* comp); + void SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comp, int ncomps); - void SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comp, int ncomps); + FX_BOOL GetRGB(int& R, int& G, int& B) const; - FX_BOOL GetRGB(int& R, int& G, int& B) const; + CPDF_Pattern* GetPattern() const; - CPDF_Pattern* GetPattern() const; + CPDF_ColorSpace* GetPatternCS() const; - CPDF_ColorSpace* GetPatternCS() const; + FX_FLOAT* GetPatternColor() const; - FX_FLOAT* GetPatternColor() const; + CPDF_ColorSpace* m_pCS; - CPDF_ColorSpace* m_pCS; - -protected: - void ReleaseBuffer(); - void ReleaseColorSpace(); - FX_FLOAT* m_pBuffer; + protected: + void ReleaseBuffer(); + void ReleaseColorSpace(); + FX_FLOAT* m_pBuffer; }; -#define PATTERN_TILING 1 -#define PATTERN_SHADING 2 -class CPDF_Pattern -{ -public: - - virtual ~CPDF_Pattern(); - void SetForceClear(FX_BOOL bForceClear) { m_bForceClear = bForceClear; } +#define PATTERN_TILING 1 +#define PATTERN_SHADING 2 +class CPDF_Pattern { + public: + virtual ~CPDF_Pattern(); + void SetForceClear(FX_BOOL bForceClear) { m_bForceClear = bForceClear; } - CPDF_Object* m_pPatternObj; + CPDF_Object* m_pPatternObj; - int m_PatternType; + int m_PatternType; - CFX_AffineMatrix m_Pattern2Form; - CFX_AffineMatrix m_ParentMatrix; + CFX_AffineMatrix m_Pattern2Form; + CFX_AffineMatrix m_ParentMatrix; - CPDF_Document* m_pDocument; + CPDF_Document* m_pDocument; -protected: - CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix); - FX_BOOL m_bForceClear; + protected: + CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix); + FX_BOOL m_bForceClear; }; -class CPDF_TilingPattern : public CPDF_Pattern -{ -public: - - CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, const CFX_AffineMatrix* parentMatrix); - - virtual ~CPDF_TilingPattern(); - - FX_BOOL Load(); - +class CPDF_TilingPattern : public CPDF_Pattern { + public: + CPDF_TilingPattern(CPDF_Document* pDoc, + CPDF_Object* pPatternObj, + const CFX_AffineMatrix* parentMatrix); + virtual ~CPDF_TilingPattern(); - FX_BOOL m_bColored; + FX_BOOL Load(); - CFX_FloatRect m_BBox; + FX_BOOL m_bColored; - FX_FLOAT m_XStep; + CFX_FloatRect m_BBox; - FX_FLOAT m_YStep; + FX_FLOAT m_XStep; + FX_FLOAT m_YStep; - - CPDF_Form* m_pForm; + CPDF_Form* m_pForm; }; -class CPDF_ShadingPattern : public CPDF_Pattern -{ -public: +class CPDF_ShadingPattern : public CPDF_Pattern { + public: + CPDF_ShadingPattern(CPDF_Document* pDoc, + CPDF_Object* pPatternObj, + FX_BOOL bShading, + const CFX_AffineMatrix* parentMatrix); - CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, FX_BOOL bShading, const CFX_AffineMatrix* parentMatrix); + virtual ~CPDF_ShadingPattern(); - virtual ~CPDF_ShadingPattern(); + CPDF_Object* m_pShadingObj; - CPDF_Object* m_pShadingObj; + FX_BOOL m_bShadingObj; - FX_BOOL m_bShadingObj; + FX_BOOL Load(); - FX_BOOL Load(); + FX_BOOL Reload(); - FX_BOOL Reload(); + int m_ShadingType; - int m_ShadingType; + CPDF_ColorSpace* m_pCS; // Still keep m_pCS as some CPDF_ColorSpace (name + // object) are not managed as counted objects. Refer + // to CPDF_DocPageData::GetColorSpace. - CPDF_ColorSpace* m_pCS; // Still keep m_pCS as some CPDF_ColorSpace (name object) are not managed as counted objects. Refer to CPDF_DocPageData::GetColorSpace. + CPDF_CountedColorSpace* m_pCountedCS; - CPDF_CountedColorSpace* m_pCountedCS; + CPDF_Function* m_pFunctions[4]; - CPDF_Function* m_pFunctions[4]; + int m_nFuncs; - int m_nFuncs; -protected: - void Clear(); + protected: + void Clear(); }; struct CPDF_MeshVertex { - FX_FLOAT x, y; - FX_FLOAT r, g, b; + FX_FLOAT x, y; + FX_FLOAT r, g, b; }; -class CPDF_MeshStream -{ -public: - - FX_BOOL Load(CPDF_Stream* pShadingStream, CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpace* pCS); - - FX_DWORD GetFlag(); - - void GetCoords(FX_FLOAT& x, FX_FLOAT& y); - - void GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b); - - FX_DWORD GetVertex(CPDF_MeshVertex& vertex, CFX_AffineMatrix* pObject2Bitmap); - - FX_BOOL GetVertexRow(CPDF_MeshVertex* vertex, int count, CFX_AffineMatrix* pObject2Bitmap); - CPDF_Function** m_pFuncs; - CPDF_ColorSpace* m_pCS; - FX_DWORD m_nFuncs, m_nCoordBits, m_nCompBits, m_nFlagBits, m_nComps; - FX_DWORD m_CoordMax, m_CompMax; - FX_FLOAT m_xmin, m_xmax, m_ymin, m_ymax; - FX_FLOAT m_ColorMin[8], m_ColorMax[8]; - CPDF_StreamAcc m_Stream; - CFX_BitStream m_BitStream; +class CPDF_MeshStream { + public: + FX_BOOL Load(CPDF_Stream* pShadingStream, + CPDF_Function** pFuncs, + int nFuncs, + CPDF_ColorSpace* pCS); + + FX_DWORD GetFlag(); + + void GetCoords(FX_FLOAT& x, FX_FLOAT& y); + + void GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b); + + FX_DWORD GetVertex(CPDF_MeshVertex& vertex, CFX_AffineMatrix* pObject2Bitmap); + + FX_BOOL GetVertexRow(CPDF_MeshVertex* vertex, + int count, + CFX_AffineMatrix* pObject2Bitmap); + CPDF_Function** m_pFuncs; + CPDF_ColorSpace* m_pCS; + FX_DWORD m_nFuncs, m_nCoordBits, m_nCompBits, m_nFlagBits, m_nComps; + FX_DWORD m_CoordMax, m_CompMax; + FX_FLOAT m_xmin, m_xmax, m_ymin, m_ymax; + FX_FLOAT m_ColorMin[8], m_ColorMax[8]; + CPDF_StreamAcc m_Stream; + CFX_BitStream m_BitStream; }; -#define PDF_IMAGE_NO_COMPRESS 0x0000 -#define PDF_IMAGE_LOSSY_COMPRESS 0x0001 -#define PDF_IMAGE_LOSSLESS_COMPRESS 0x0002 -#define PDF_IMAGE_MASK_LOSSY_COMPRESS 0x0004 -#define PDF_IMAGE_MASK_LOSSLESS_COMPRESS 0x0008 -class CPDF_ImageSetParam -{ -public: - CPDF_ImageSetParam() - : pMatteColor(NULL) - , nQuality(80) - { - } - FX_ARGB* pMatteColor; - int32_t nQuality; +#define PDF_IMAGE_NO_COMPRESS 0x0000 +#define PDF_IMAGE_LOSSY_COMPRESS 0x0001 +#define PDF_IMAGE_LOSSLESS_COMPRESS 0x0002 +#define PDF_IMAGE_MASK_LOSSY_COMPRESS 0x0004 +#define PDF_IMAGE_MASK_LOSSLESS_COMPRESS 0x0008 +class CPDF_ImageSetParam { + public: + CPDF_ImageSetParam() : pMatteColor(NULL), nQuality(80) {} + FX_ARGB* pMatteColor; + int32_t nQuality; }; -class CPDF_Image -{ -public: +class CPDF_Image { + public: + CPDF_Image(CPDF_Document* pDoc); - CPDF_Image(CPDF_Document* pDoc); + ~CPDF_Image(); - ~CPDF_Image(); + FX_BOOL LoadImageF(CPDF_Stream* pImageStream, FX_BOOL bInline); - FX_BOOL LoadImageF(CPDF_Stream* pImageStream, FX_BOOL bInline); + void Release(); - void Release(); + CPDF_Image* Clone(); - CPDF_Image* Clone(); + FX_BOOL IsInline() { return m_bInline; } - FX_BOOL IsInline() - { - return m_bInline; - } + void SetInlineDict(CPDF_Dictionary* pDict) { m_pInlineDict = pDict; } - void SetInlineDict(CPDF_Dictionary* pDict) - { - m_pInlineDict = pDict; - } + CPDF_Dictionary* GetInlineDict() const { return m_pInlineDict; } - CPDF_Dictionary* GetInlineDict() const - { - return m_pInlineDict; - } + CPDF_Stream* GetStream() const { return m_pStream; } - CPDF_Stream* GetStream() const - { - return m_pStream; - } + CPDF_Dictionary* GetDict() const { + return m_pStream ? m_pStream->GetDict() : NULL; + } - CPDF_Dictionary* GetDict() const - { - return m_pStream? m_pStream->GetDict(): NULL; - } - - CPDF_Dictionary* GetOC() const - { - return m_pOC; - } - - CPDF_Document* GetDocument() const - { - return m_pDocument; - } + CPDF_Dictionary* GetOC() const { return m_pOC; } + CPDF_Document* GetDocument() const { return m_pDocument; } + int32_t GetPixelHeight() const { return m_Height; } - int32_t GetPixelHeight() const - { - return m_Height; - } - - int32_t GetPixelWidth() const - { - return m_Width; - } - - - FX_BOOL IsMask() const - { - return m_bIsMask; - } - - FX_BOOL IsInterpol() const - { - return m_bInterpolate; - } + int32_t GetPixelWidth() const { return m_Width; } - CFX_DIBSource* LoadDIBSource(CFX_DIBSource** ppMask = NULL, FX_DWORD* pMatteColor = NULL, FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0, FX_BOOL bLoadMask = FALSE) const; + FX_BOOL IsMask() const { return m_bIsMask; } + FX_BOOL IsInterpol() const { return m_bInterpolate; } + CFX_DIBSource* LoadDIBSource(CFX_DIBSource** ppMask = NULL, + FX_DWORD* pMatteColor = NULL, + FX_BOOL bStdCS = FALSE, + FX_DWORD GroupFamily = 0, + FX_BOOL bLoadMask = FALSE) const; - void SetImage(const CFX_DIBitmap* pDIBitmap, int32_t iCompress, IFX_FileWrite *pFileWrite = NULL, IFX_FileRead *pFileRead = NULL, const CFX_DIBitmap* pMask = NULL, const CPDF_ImageSetParam* pParam = NULL); + void SetImage(const CFX_DIBitmap* pDIBitmap, + int32_t iCompress, + IFX_FileWrite* pFileWrite = NULL, + IFX_FileRead* pFileRead = NULL, + const CFX_DIBitmap* pMask = NULL, + const CPDF_ImageSetParam* pParam = NULL); - void SetJpegImage(uint8_t* pImageData, FX_DWORD size); + void SetJpegImage(uint8_t* pImageData, FX_DWORD size); - void SetJpegImage(IFX_FileRead *pFile); + void SetJpegImage(IFX_FileRead* pFile); - void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap); + void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap); -public: - FX_BOOL StartLoadDIBSource(CPDF_Dictionary* pFormResource, CPDF_Dictionary* pPageResource, FX_BOOL bStdCS = FALSE, FX_DWORD GroupFamily = 0, FX_BOOL bLoadMask = FALSE); - FX_BOOL Continue(IFX_Pause* pPause); - CFX_DIBSource* DetachBitmap(); - CFX_DIBSource* DetachMask(); - CFX_DIBSource* m_pDIBSource; - CFX_DIBSource* m_pMask; - FX_DWORD m_MatteColor; -private: + public: + FX_BOOL StartLoadDIBSource(CPDF_Dictionary* pFormResource, + CPDF_Dictionary* pPageResource, + FX_BOOL bStdCS = FALSE, + FX_DWORD GroupFamily = 0, + FX_BOOL bLoadMask = FALSE); + FX_BOOL Continue(IFX_Pause* pPause); + CFX_DIBSource* DetachBitmap(); + CFX_DIBSource* DetachMask(); + CFX_DIBSource* m_pDIBSource; + CFX_DIBSource* m_pMask; + FX_DWORD m_MatteColor; - CPDF_Stream* m_pStream; - FX_BOOL m_bInline; - CPDF_Dictionary* m_pInlineDict; + private: + CPDF_Stream* m_pStream; + FX_BOOL m_bInline; + CPDF_Dictionary* m_pInlineDict; - int32_t m_Height; + int32_t m_Height; - int32_t m_Width; + int32_t m_Width; - FX_BOOL m_bIsMask; + FX_BOOL m_bIsMask; - FX_BOOL m_bInterpolate; + FX_BOOL m_bInterpolate; - CPDF_Document* m_pDocument; + CPDF_Document* m_pDocument; - CPDF_Dictionary* m_pOC; - CPDF_Dictionary* InitJPEG(uint8_t* pData, FX_DWORD size); + CPDF_Dictionary* m_pOC; + CPDF_Dictionary* InitJPEG(uint8_t* pData, FX_DWORD size); }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_ diff --git a/core/include/fpdfapi/fpdf_serial.h b/core/include/fpdfapi/fpdf_serial.h index 1877ef8866..efa30f646b 100644 --- a/core/include/fpdfapi/fpdf_serial.h +++ b/core/include/fpdfapi/fpdf_serial.h @@ -12,189 +12,196 @@ class CPDF_ObjectStream; class CPDF_XRefStream; -CFX_ByteTextBuf& operator << (CFX_ByteTextBuf& buf, const CPDF_Object* pObj); -class CPDF_ObjArchiveSaver : public CFX_ArchiveSaver -{ -public: - - friend CPDF_ObjArchiveSaver& operator << (CPDF_ObjArchiveSaver& ar, const CPDF_Object* pObj); -protected: - - CFX_MapPtrToPtr m_ObjectMap; +CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj); +class CPDF_ObjArchiveSaver : public CFX_ArchiveSaver { + public: + friend CPDF_ObjArchiveSaver& operator<<(CPDF_ObjArchiveSaver& ar, + const CPDF_Object* pObj); + + protected: + CFX_MapPtrToPtr m_ObjectMap; }; -class CPDF_ObjArchiveLoader : public CFX_ArchiveLoader -{ -public: - - CPDF_ObjArchiveLoader(const uint8_t* pData, FX_DWORD dwSize) : CFX_ArchiveLoader(pData, dwSize), - m_IndirectObjects(NULL) {} +class CPDF_ObjArchiveLoader : public CFX_ArchiveLoader { + public: + CPDF_ObjArchiveLoader(const uint8_t* pData, FX_DWORD dwSize) + : CFX_ArchiveLoader(pData, dwSize), m_IndirectObjects(NULL) {} - friend CPDF_ObjArchiveLoader& operator >> (CPDF_ObjArchiveLoader& ar, CPDF_Object*& pObj); -protected: + friend CPDF_ObjArchiveLoader& operator>>(CPDF_ObjArchiveLoader& ar, + CPDF_Object*& pObj); - CPDF_IndirectObjects m_IndirectObjects; + protected: + CPDF_IndirectObjects m_IndirectObjects; }; -class CPDF_PageArchiveSaver : public CPDF_ObjArchiveSaver -{ -public: - - CPDF_PageArchiveSaver(CPDF_PageObjects* pPageObjs); - - friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_PageObject* pObj); - +class CPDF_PageArchiveSaver : public CPDF_ObjArchiveSaver { + public: + CPDF_PageArchiveSaver(CPDF_PageObjects* pPageObjs); + friend CPDF_PageArchiveSaver& operator<<(CPDF_PageArchiveSaver& ar, + CPDF_PageObject* pObj); - friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_ClipPath clip_path); + friend CPDF_PageArchiveSaver& operator<<(CPDF_PageArchiveSaver& ar, + CPDF_ClipPath clip_path); - friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_GraphState graph_state); + friend CPDF_PageArchiveSaver& operator<<(CPDF_PageArchiveSaver& ar, + CPDF_GraphState graph_state); - friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_TextState text_state); + friend CPDF_PageArchiveSaver& operator<<(CPDF_PageArchiveSaver& ar, + CPDF_TextState text_state); - friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_ColorState color_state); + friend CPDF_PageArchiveSaver& operator<<(CPDF_PageArchiveSaver& ar, + CPDF_ColorState color_state); - friend CPDF_PageArchiveSaver& operator << (CPDF_PageArchiveSaver& ar, CPDF_GeneralState general_state); + friend CPDF_PageArchiveSaver& operator<<(CPDF_PageArchiveSaver& ar, + CPDF_GeneralState general_state); -protected: + protected: + CPDF_ClipPath m_LastClipPath; - CPDF_ClipPath m_LastClipPath; + CPDF_GraphState m_LastGraphState; - CPDF_GraphState m_LastGraphState; + CPDF_ColorState m_LastColorState; - CPDF_ColorState m_LastColorState; + CPDF_TextState m_LastTextState; - CPDF_TextState m_LastTextState; - - CPDF_GeneralState m_LastGeneralState; + CPDF_GeneralState m_LastGeneralState; }; -class CPDF_PageArchiveLoader : public CPDF_ObjArchiveLoader -{ -public: - - CPDF_PageArchiveLoader(CPDF_PageObjects* pPageObjs, const uint8_t* pData, FX_DWORD dwSize); - - friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_PageObject*& pObj); +class CPDF_PageArchiveLoader : public CPDF_ObjArchiveLoader { + public: + CPDF_PageArchiveLoader(CPDF_PageObjects* pPageObjs, + const uint8_t* pData, + FX_DWORD dwSize); + friend CPDF_PageArchiveLoader& operator>>(CPDF_PageArchiveLoader& ar, + CPDF_PageObject*& pObj); + friend CPDF_PageArchiveLoader& operator>>(CPDF_PageArchiveLoader& ar, + CPDF_ClipPath& clip_path); - friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_ClipPath& clip_path); + friend CPDF_PageArchiveLoader& operator>>(CPDF_PageArchiveLoader& ar, + CPDF_GraphState& graph_state); - friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_GraphState& graph_state); + friend CPDF_PageArchiveLoader& operator>>(CPDF_PageArchiveLoader& ar, + CPDF_TextState& text_state); - friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_TextState& text_state); + friend CPDF_PageArchiveLoader& operator>>(CPDF_PageArchiveLoader& ar, + CPDF_ColorState& color_state); - friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_ColorState& color_state); + friend CPDF_PageArchiveLoader& operator>>(CPDF_PageArchiveLoader& ar, + CPDF_GeneralState& general_state); - friend CPDF_PageArchiveLoader& operator >> (CPDF_PageArchiveLoader& ar, CPDF_GeneralState& general_state); + protected: + void PostProcColor(CPDF_Color& color); -protected: - void PostProcColor(CPDF_Color& color); + CPDF_Object* AddResource(CPDF_Object* pSrcObj, const FX_CHAR* type); - CPDF_Object* AddResource(CPDF_Object* pSrcObj, const FX_CHAR* type); + CPDF_ClipPath m_LastClipPath; - CPDF_ClipPath m_LastClipPath; + CPDF_GraphState m_LastGraphState; - CPDF_GraphState m_LastGraphState; + CPDF_ColorState m_LastColorState; - CPDF_ColorState m_LastColorState; + CPDF_TextState m_LastTextState; - CPDF_TextState m_LastTextState; + CPDF_GeneralState m_LastGeneralState; - CPDF_GeneralState m_LastGeneralState; - - CFX_MapPtrToPtr m_ObjectMap; + CFX_MapPtrToPtr m_ObjectMap; }; -#define FPDFCREATE_INCREMENTAL 1 -#define FPDFCREATE_NO_ORIGINAL 2 -#define FPDFCREATE_PROGRESSIVE 4 -#define FPDFCREATE_OBJECTSTREAM 8 -class CPDF_Creator -{ -public: - - CPDF_Creator(CPDF_Document* pDoc); +#define FPDFCREATE_INCREMENTAL 1 +#define FPDFCREATE_NO_ORIGINAL 2 +#define FPDFCREATE_PROGRESSIVE 4 +#define FPDFCREATE_OBJECTSTREAM 8 +class CPDF_Creator { + public: + CPDF_Creator(CPDF_Document* pDoc); - ~CPDF_Creator(); + ~CPDF_Creator(); - void RemoveSecurity(); + void RemoveSecurity(); - FX_BOOL Create(const FX_WCHAR* filename, FX_DWORD flags = 0); + FX_BOOL Create(const FX_WCHAR* filename, FX_DWORD flags = 0); - FX_BOOL Create(const FX_CHAR* filename, FX_DWORD flags = 0); + FX_BOOL Create(const FX_CHAR* filename, FX_DWORD flags = 0); - FX_BOOL Create(IFX_StreamWrite* pFile, FX_DWORD flags = 0); + FX_BOOL Create(IFX_StreamWrite* pFile, FX_DWORD flags = 0); - int32_t Continue(IFX_Pause *pPause = NULL); + int32_t Continue(IFX_Pause* pPause = NULL); - FX_BOOL SetFileVersion(int32_t fileVersion = 17); -protected: + FX_BOOL SetFileVersion(int32_t fileVersion = 17); - CPDF_Document* m_pDocument; + protected: + CPDF_Document* m_pDocument; - CPDF_Parser* m_pParser; + CPDF_Parser* m_pParser; - FX_BOOL m_bCompress; + FX_BOOL m_bCompress; - FX_BOOL m_bSecurityChanged; + FX_BOOL m_bSecurityChanged; - CPDF_Dictionary* m_pEncryptDict; - FX_DWORD m_dwEnryptObjNum; - FX_BOOL m_bEncryptCloned; + CPDF_Dictionary* m_pEncryptDict; + FX_DWORD m_dwEnryptObjNum; + FX_BOOL m_bEncryptCloned; - FX_BOOL m_bStandardSecurity; + FX_BOOL m_bStandardSecurity; - CPDF_CryptoHandler* m_pCryptoHandler; - FX_BOOL m_bNewCrypto; + CPDF_CryptoHandler* m_pCryptoHandler; + FX_BOOL m_bNewCrypto; - FX_BOOL m_bEncryptMetadata; + FX_BOOL m_bEncryptMetadata; - CPDF_Object* m_pMetadata; + CPDF_Object* m_pMetadata; - CPDF_XRefStream* m_pXRefStream; + CPDF_XRefStream* m_pXRefStream; - int32_t m_ObjectStreamSize; + int32_t m_ObjectStreamSize; - FX_DWORD m_dwLastObjNum; - FX_BOOL Create(FX_DWORD flags); - void ResetStandardSecurity(); - void Clear(); - int32_t WriteDoc_Stage1(IFX_Pause *pPause); - int32_t WriteDoc_Stage2(IFX_Pause *pPause); - int32_t WriteDoc_Stage3(IFX_Pause *pPause); - int32_t WriteDoc_Stage4(IFX_Pause *pPause); + FX_DWORD m_dwLastObjNum; + FX_BOOL Create(FX_DWORD flags); + void ResetStandardSecurity(); + void Clear(); + int32_t WriteDoc_Stage1(IFX_Pause* pPause); + int32_t WriteDoc_Stage2(IFX_Pause* pPause); + int32_t WriteDoc_Stage3(IFX_Pause* pPause); + int32_t WriteDoc_Stage4(IFX_Pause* pPause); - CFX_FileBufferArchive m_File; + CFX_FileBufferArchive m_File; - FX_FILESIZE m_Offset; - void InitOldObjNumOffsets(); - void InitNewObjNumOffsets(); - void AppendNewObjNum(FX_DWORD objbum); - int32_t WriteOldIndirectObject(FX_DWORD objnum); - int32_t WriteOldObjs(IFX_Pause *pPause); - int32_t WriteNewObjs(FX_BOOL bIncremental, IFX_Pause *pPause); - int32_t WriteIndirectObj(const CPDF_Object* pObj); - int32_t WriteDirectObj(FX_DWORD objnum, const CPDF_Object* pObj, FX_BOOL bEncrypt = TRUE); - int32_t WriteIndirectObjectToStream(const CPDF_Object* pObj); - int32_t WriteIndirectObj(FX_DWORD objnum, const CPDF_Object* pObj); - int32_t WriteIndirectObjectToStream(FX_DWORD objnum, const uint8_t* pBuffer, FX_DWORD dwSize); - int32_t AppendObjectNumberToXRef(FX_DWORD objnum); - void InitID(FX_BOOL bDefault = TRUE); - int32_t WriteStream(const CPDF_Object* pStream, FX_DWORD objnum, CPDF_CryptoHandler* pCrypto); + FX_FILESIZE m_Offset; + void InitOldObjNumOffsets(); + void InitNewObjNumOffsets(); + void AppendNewObjNum(FX_DWORD objbum); + int32_t WriteOldIndirectObject(FX_DWORD objnum); + int32_t WriteOldObjs(IFX_Pause* pPause); + int32_t WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause); + int32_t WriteIndirectObj(const CPDF_Object* pObj); + int32_t WriteDirectObj(FX_DWORD objnum, + const CPDF_Object* pObj, + FX_BOOL bEncrypt = TRUE); + int32_t WriteIndirectObjectToStream(const CPDF_Object* pObj); + int32_t WriteIndirectObj(FX_DWORD objnum, const CPDF_Object* pObj); + int32_t WriteIndirectObjectToStream(FX_DWORD objnum, + const uint8_t* pBuffer, + FX_DWORD dwSize); + int32_t AppendObjectNumberToXRef(FX_DWORD objnum); + void InitID(FX_BOOL bDefault = TRUE); + int32_t WriteStream(const CPDF_Object* pStream, + FX_DWORD objnum, + CPDF_CryptoHandler* pCrypto); - int32_t m_iStage; - FX_DWORD m_dwFlags; - FX_POSITION m_Pos; - FX_FILESIZE m_XrefStart; + int32_t m_iStage; + FX_DWORD m_dwFlags; + FX_POSITION m_Pos; + FX_FILESIZE m_XrefStart; - CFX_FileSizeListArray m_ObjectOffset; + CFX_FileSizeListArray m_ObjectOffset; - CFX_DWordListArray m_ObjectSize; - CFX_DWordArray m_NewObjNumArray; + CFX_DWordListArray m_ObjectSize; + CFX_DWordArray m_NewObjNumArray; - CPDF_Array* m_pIDArray; + CPDF_Array* m_pIDArray; - int32_t m_FileVersion; - friend class CPDF_ObjectStream; - friend class CPDF_XRefStream; + int32_t m_FileVersion; + friend class CPDF_ObjectStream; + friend class CPDF_XRefStream; }; #endif // CORE_INCLUDE_FPDFAPI_FPDF_SERIAL_H_ -- cgit v1.2.3