diff options
author | Nico Weber <thakis@chromium.org> | 2015-08-04 13:00:21 -0700 |
---|---|---|
committer | Nico Weber <thakis@chromium.org> | 2015-08-04 13:00:21 -0700 |
commit | 9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f (patch) | |
tree | c97037f398d714665aefccb6eb54d0969ad7030c /core/include | |
parent | 780cee82236d1b3b0f9b01a22424e4b8ec9a6f12 (diff) | |
download | pdfium-9d8ec5a6e37e8d1d4d4edca9040de234e2d4728f.tar.xz |
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
Diffstat (limited to 'core/include')
35 files changed, 9225 insertions, 10199 deletions
diff --git a/core/include/fdrm/fx_crypt.h b/core/include/fdrm/fx_crypt.h index f820999b28..e3b21c5175 100644 --- a/core/include/fdrm/fx_crypt.h +++ b/core/include/fdrm/fx_crypt.h @@ -13,13 +13,26 @@ extern "C" { #endif -void CRYPT_ArcFourCryptBlock(uint8_t* data, FX_DWORD size, const uint8_t* key, FX_DWORD keylen); +void CRYPT_ArcFourCryptBlock(uint8_t* data, + FX_DWORD size, + const uint8_t* key, + FX_DWORD keylen); void CRYPT_ArcFourSetup(void* context, const uint8_t* key, FX_DWORD length); void CRYPT_ArcFourCrypt(void* context, uint8_t* data, FX_DWORD size); -void CRYPT_AESSetKey(void* context, FX_DWORD blocklen, const uint8_t* key, FX_DWORD keylen, FX_BOOL bEncrypt); +void CRYPT_AESSetKey(void* context, + FX_DWORD blocklen, + const uint8_t* key, + FX_DWORD keylen, + FX_BOOL bEncrypt); void CRYPT_AESSetIV(void* context, const uint8_t* iv); -void CRYPT_AESDecrypt(void* context, uint8_t* dest, const uint8_t* src, FX_DWORD size); -void CRYPT_AESEncrypt(void* context, uint8_t* dest, const uint8_t* src, FX_DWORD size); +void CRYPT_AESDecrypt(void* context, + uint8_t* dest, + const uint8_t* src, + FX_DWORD size); +void CRYPT_AESEncrypt(void* context, + uint8_t* dest, + const uint8_t* src, + FX_DWORD size); void CRYPT_MD5Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[16]); void CRYPT_MD5Start(void* context); void CRYPT_MD5Update(void* context, const uint8_t* data, FX_DWORD size); @@ -28,19 +41,28 @@ void CRYPT_SHA1Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[20]); void CRYPT_SHA1Start(void* context); void CRYPT_SHA1Update(void* context, const uint8_t* data, FX_DWORD size); void CRYPT_SHA1Finish(void* context, uint8_t digest[20]); -void CRYPT_SHA256Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[32]); +void CRYPT_SHA256Generate(const uint8_t* data, + FX_DWORD size, + uint8_t digest[32]); void CRYPT_SHA256Start(void* context); void CRYPT_SHA256Update(void* context, const uint8_t* data, FX_DWORD size); void CRYPT_SHA256Finish(void* context, uint8_t digest[32]); void CRYPT_SHA384Start(void* context); void CRYPT_SHA384Update(void* context, const uint8_t* data, FX_DWORD size); void CRYPT_SHA384Finish(void* context, uint8_t digest[48]); -void CRYPT_SHA384Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[48]); +void CRYPT_SHA384Generate(const uint8_t* data, + FX_DWORD size, + uint8_t digest[48]); void CRYPT_SHA512Start(void* context); void CRYPT_SHA512Update(void* context, const uint8_t* data, FX_DWORD size); void CRYPT_SHA512Finish(void* context, uint8_t digest[64]); -void CRYPT_SHA512Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[64]); -void CRYPT_SetPubKeyDecryptor(FX_BOOL (*func)(const uint8_t* pData, FX_DWORD size, uint8_t* data_buf, FX_DWORD& data_len)); +void CRYPT_SHA512Generate(const uint8_t* data, + FX_DWORD size, + uint8_t digest[64]); +void CRYPT_SetPubKeyDecryptor(FX_BOOL (*func)(const uint8_t* pData, + FX_DWORD size, + uint8_t* data_buf, + FX_DWORD& data_len)); #ifdef __cplusplus }; 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<IPDF_RenderModule> m_pRenderModule; - nonstd::unique_ptr<IPDF_PageModule> m_pPageModule; + nonstd::unique_ptr<IPDF_RenderModule> m_pRenderModule; + nonstd::unique_ptr<IPDF_PageModule> 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<CFX_PathData> -{ -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<CFX_PathData> { + 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<CPDF_ClipPathData> -{ -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<CPDF_ClipPathData> { + 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<CPDF_ColorStateData> -{ -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<CFX_GraphStateData> -{ -public: + FX_DWORD m_StrokeRGB; }; -class CPDF_TextStateData -{ -public: +class CPDF_ColorState : public CFX_CountRef<CPDF_ColorStateData> { + 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<CFX_GraphStateData> { + 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<CPDF_TextStateData> -{ -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<CPDF_TextStateData> { + 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<CPDF_GeneralStateData> -{ -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<CPDF_GeneralStateData> { + 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<CPDF_ContentMarkItem> m_Marks; + private: + CFX_ObjectArray<CPDF_ContentMarkItem> m_Marks; }; -class CPDF_ContentMark : public CFX_CountRef<CPDF_ContentMarkData> -{ -public: - - int GetMCID() const - { - return m_pObject ? m_pObject->GetMCID() : -1; - } +class CPDF_ContentMark : public CFX_CountRef<CPDF_ContentMarkData> { + 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<CPDF_Dictionary*>* 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<CPDF_Dictionary*>* 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<CPDF_Dictionary *> 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<CPDF_Dictionary*> 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<struct _PDF_RenderItem> m_ContentList; - CFX_ArrayTemplate<struct _PDF_RenderItem> 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 T> 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 T> +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<CPDF_ColorSpace>; using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern>; -#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<FX_DWORD>(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<FX_DWORD>(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_ diff --git a/core/include/fpdfdoc/fpdf_ap.h b/core/include/fpdfdoc/fpdf_ap.h index 7cfaed4685..43452fdb47 100644 --- a/core/include/fpdfdoc/fpdf_ap.h +++ b/core/include/fpdfdoc/fpdf_ap.h @@ -10,86 +10,98 @@ #include "../fpdfapi/fpdf_parser.h" #include "fpdf_vt.h" -class IPVT_FontMap -{ -public: - virtual ~IPVT_FontMap() { } - virtual CPDF_Font* GetPDFFont(int32_t nFontIndex) = 0; - virtual CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) = 0; +class IPVT_FontMap { + public: + virtual ~IPVT_FontMap() {} + virtual CPDF_Font* GetPDFFont(int32_t nFontIndex) = 0; + virtual CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) = 0; }; struct CPVT_Dash { + CPVT_Dash(int32_t dash, int32_t gap, int32_t phase) + : nDash(dash), nGap(gap), nPhase(phase) {} - CPVT_Dash(int32_t dash, int32_t gap, int32_t phase) : nDash(dash), nGap(gap), nPhase(phase) - {} + int32_t nDash; - int32_t nDash; + int32_t nGap; - int32_t nGap; - - int32_t nPhase; + int32_t nPhase; }; -#define CT_TRANSPARENT 0 -#define CT_GRAY 1 -#define CT_RGB 2 -#define CT_CMYK 3 +#define CT_TRANSPARENT 0 +#define CT_GRAY 1 +#define CT_RGB 2 +#define CT_CMYK 3 struct CPVT_Color { - - CPVT_Color(int32_t type = 0, FX_FLOAT color1 = 0.0f, FX_FLOAT color2 = 0.0f, FX_FLOAT color3 = 0.0f, FX_FLOAT color4 = 0.0f) - : nColorType(type), fColor1(color1), fColor2(color2), fColor3(color3), fColor4(color4) - {} - - int32_t nColorType; - FX_FLOAT fColor1; - FX_FLOAT fColor2; - FX_FLOAT fColor3; - FX_FLOAT fColor4; + CPVT_Color(int32_t type = 0, + FX_FLOAT color1 = 0.0f, + FX_FLOAT color2 = 0.0f, + FX_FLOAT color3 = 0.0f, + FX_FLOAT color4 = 0.0f) + : nColorType(type), + fColor1(color1), + fColor2(color2), + fColor3(color3), + fColor4(color4) {} + + int32_t nColorType; + FX_FLOAT fColor1; + FX_FLOAT fColor2; + FX_FLOAT fColor3; + FX_FLOAT fColor4; }; -class CPVT_Provider : public IPDF_VariableText_Provider -{ -public: +class CPVT_Provider : public IPDF_VariableText_Provider { + public: + CPVT_Provider(IPVT_FontMap* pFontMap); - CPVT_Provider(IPVT_FontMap * pFontMap); + virtual ~CPVT_Provider(); - virtual ~CPVT_Provider(); + int32_t GetCharWidth(int32_t nFontIndex, FX_WORD word, int32_t nWordStyle); - int32_t GetCharWidth(int32_t nFontIndex, FX_WORD word, int32_t nWordStyle); + int32_t GetTypeAscent(int32_t nFontIndex); - int32_t GetTypeAscent(int32_t nFontIndex); + int32_t GetTypeDescent(int32_t nFontIndex); - int32_t GetTypeDescent(int32_t nFontIndex); + int32_t GetWordFontIndex(FX_WORD word, int32_t charset, int32_t nFontIndex); - int32_t GetWordFontIndex(FX_WORD word, int32_t charset, int32_t nFontIndex); + FX_BOOL IsLatinWord(FX_WORD word); - FX_BOOL IsLatinWord(FX_WORD word); + int32_t GetDefaultFontIndex(); - int32_t GetDefaultFontIndex(); -private: - - IPVT_FontMap * m_pFontMap; + private: + IPVT_FontMap* m_pFontMap; }; -#define PBS_SOLID 0 -#define PBS_DASH 1 -#define PBS_BEVELED 2 -#define PBS_INSET 3 -#define PBS_UNDERLINED 4 -class CPVT_GenerateAP -{ -public: - - static FX_BOOL GenerateTextFieldAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); - - static FX_BOOL GenerateComboBoxAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); - - static FX_BOOL GenerateListBoxAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); - - static CFX_ByteString GenerateEditAP(IPVT_FontMap * pFontMap, IPDF_VariableText_Iterator * pIterator, - const CPDF_Point & ptOffset, FX_BOOL bContinuous, FX_WORD SubWord = 0, const CPVT_WordRange * pVisible = NULL); - - static CFX_ByteString GenerateBorderAP(const CPDF_Rect & rect, FX_FLOAT fWidth, - const CPVT_Color & color, const CPVT_Color & crLeftTop, const CPVT_Color & crRightBottom, - int32_t nStyle, const CPVT_Dash & dash); - - static CFX_ByteString GenerateColorAP(const CPVT_Color & color, const FX_BOOL & bFillOrStroke); +#define PBS_SOLID 0 +#define PBS_DASH 1 +#define PBS_BEVELED 2 +#define PBS_INSET 3 +#define PBS_UNDERLINED 4 +class CPVT_GenerateAP { + public: + static FX_BOOL GenerateTextFieldAP(CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict); + + static FX_BOOL GenerateComboBoxAP(CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict); + + static FX_BOOL GenerateListBoxAP(CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict); + + static CFX_ByteString GenerateEditAP(IPVT_FontMap* pFontMap, + IPDF_VariableText_Iterator* pIterator, + const CPDF_Point& ptOffset, + FX_BOOL bContinuous, + FX_WORD SubWord = 0, + const CPVT_WordRange* pVisible = NULL); + + static CFX_ByteString GenerateBorderAP(const CPDF_Rect& rect, + FX_FLOAT fWidth, + const CPVT_Color& color, + const CPVT_Color& crLeftTop, + const CPVT_Color& crRightBottom, + int32_t nStyle, + const CPVT_Dash& dash); + + static CFX_ByteString GenerateColorAP(const CPVT_Color& color, + const FX_BOOL& bFillOrStroke); }; #endif // CORE_INCLUDE_FPDFDOC_FPDF_AP_H_ diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index 57d1790377..22fdf546da 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -42,1664 +42,1226 @@ class CPDF_TextObject; class CPDF_ViewerPreferences; class CXML_Element; -class CPDF_NameTree -{ -public: +class CPDF_NameTree { + public: + CPDF_NameTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; } - CPDF_NameTree(CPDF_Dictionary* pRoot) - { - m_pRoot = pRoot; - } + CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteStringC& category); - CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteStringC& category); + CPDF_Object* LookupValue(int nIndex, CFX_ByteString& csName) const; - CPDF_Object* LookupValue(int nIndex, CFX_ByteString& csName) const; + CPDF_Object* LookupValue(const CFX_ByteString& csName) const; - CPDF_Object* LookupValue(const CFX_ByteString& csName) const; + CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, + const CFX_ByteStringC& sName); - CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, const CFX_ByteStringC& sName); + int GetIndex(const CFX_ByteString& csName) const; - int GetIndex(const CFX_ByteString& csName) const; + int GetCount() const; - int GetCount() const; + CPDF_Dictionary* GetRoot() const { return m_pRoot; } - - CPDF_Dictionary* GetRoot() const - { - return m_pRoot; - } - -protected: - - CPDF_Dictionary* m_pRoot; + protected: + CPDF_Dictionary* m_pRoot; }; -class CPDF_BookmarkTree -{ -public: - CPDF_BookmarkTree(CPDF_Document* pDoc) : m_pDocument(pDoc) {} +class CPDF_BookmarkTree { + public: + CPDF_BookmarkTree(CPDF_Document* pDoc) : m_pDocument(pDoc) {} - CPDF_Bookmark GetFirstChild(const CPDF_Bookmark& parent) const; + CPDF_Bookmark GetFirstChild(const CPDF_Bookmark& parent) const; - CPDF_Bookmark GetNextSibling(const CPDF_Bookmark& bookmark) const; + CPDF_Bookmark GetNextSibling(const CPDF_Bookmark& bookmark) const; - CPDF_Document* GetDocument() const { return m_pDocument; } + CPDF_Document* GetDocument() const { return m_pDocument; } -protected: - CPDF_Document* m_pDocument; + protected: + CPDF_Document* m_pDocument; }; -#define PDFBOOKMARK_ITALIC 1 -#define PDFBOOKMARK_BOLD 2 -class CPDF_Bookmark -{ -public: - - CPDF_Bookmark() : m_pDict(NULL) {} +#define PDFBOOKMARK_ITALIC 1 +#define PDFBOOKMARK_BOLD 2 +class CPDF_Bookmark { + public: + CPDF_Bookmark() : m_pDict(NULL) {} - explicit CPDF_Bookmark(CPDF_Dictionary* pDict) : m_pDict(pDict) {} + explicit CPDF_Bookmark(CPDF_Dictionary* pDict) : m_pDict(pDict) {} - CPDF_Dictionary* GetDict() const { return m_pDict; } + CPDF_Dictionary* GetDict() const { return m_pDict; } - operator bool() const { return m_pDict != NULL; } + operator bool() const { return m_pDict != NULL; } - FX_DWORD GetColorRef() const; + FX_DWORD GetColorRef() const; - FX_DWORD GetFontStyle() const; + FX_DWORD GetFontStyle() const; - CFX_WideString GetTitle() const; + CFX_WideString GetTitle() const; - CPDF_Dest GetDest(CPDF_Document* pDocument) const; + CPDF_Dest GetDest(CPDF_Document* pDocument) const; - CPDF_Action GetAction() const; + CPDF_Action GetAction() const; - CPDF_Dictionary* m_pDict; + CPDF_Dictionary* m_pDict; }; -#define PDFZOOM_XYZ 1 -#define PDFZOOM_FITPAGE 2 -#define PDFZOOM_FITHORZ 3 -#define PDFZOOM_FITVERT 4 -#define PDFZOOM_FITRECT 5 -#define PDFZOOM_FITBBOX 6 -#define PDFZOOM_FITBHORZ 7 -#define PDFZOOM_FITBVERT 8 -class CPDF_Dest -{ -public: - CPDF_Dest() : m_pObj(nullptr) { } - explicit CPDF_Dest(CPDF_Object* pObj) : m_pObj(pObj) { } - - operator bool () const { return m_pObj != NULL; } - CPDF_Object* GetObject() const { return m_pObj; } - - CFX_ByteString GetRemoteName(); - int GetPageIndex(CPDF_Document* pDoc); - FX_DWORD GetPageObjNum(); - int GetZoomMode(); - FX_FLOAT GetParam(int index); - -protected: - CPDF_Object* m_pObj; +#define PDFZOOM_XYZ 1 +#define PDFZOOM_FITPAGE 2 +#define PDFZOOM_FITHORZ 3 +#define PDFZOOM_FITVERT 4 +#define PDFZOOM_FITRECT 5 +#define PDFZOOM_FITBBOX 6 +#define PDFZOOM_FITBHORZ 7 +#define PDFZOOM_FITBVERT 8 +class CPDF_Dest { + public: + CPDF_Dest() : m_pObj(nullptr) {} + explicit CPDF_Dest(CPDF_Object* pObj) : m_pObj(pObj) {} + + operator bool() const { return m_pObj != NULL; } + CPDF_Object* GetObject() const { return m_pObj; } + + CFX_ByteString GetRemoteName(); + int GetPageIndex(CPDF_Document* pDoc); + FX_DWORD GetPageObjNum(); + int GetZoomMode(); + FX_FLOAT GetParam(int index); + + protected: + CPDF_Object* m_pObj; }; -class CPDF_OCContext : public IPDF_OCContext -{ -public: +class CPDF_OCContext : public IPDF_OCContext { + public: + enum UsageType { View = 0, Design, Print, Export }; - enum UsageType { - View = 0, - Design, - Print, - Export - }; + CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType = View); - CPDF_OCContext(CPDF_Document *pDoc, UsageType eUsageType = View); + virtual ~CPDF_OCContext(); - virtual ~CPDF_OCContext(); + CPDF_Document* GetDocument() const { return m_pDocument; } - CPDF_Document* GetDocument() const - { - return m_pDocument; - } + UsageType GetUsageType() const { return m_eUsageType; } - UsageType GetUsageType() const - { - return m_eUsageType; - } + FX_BOOL CheckOCGVisible(const CPDF_Dictionary* pOCGDict); - FX_BOOL CheckOCGVisible(const CPDF_Dictionary *pOCGDict); + void ResetOCContext(); - void ResetOCContext(); -protected: + protected: + FX_BOOL LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, + const CPDF_Dictionary* pOCGDict, + FX_BOOL& bValidConfig) const; - FX_BOOL LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, const CPDF_Dictionary *pOCGDict, FX_BOOL &bValidConfig) const; + FX_BOOL LoadOCGState(const CPDF_Dictionary* pOCGDict) const; - FX_BOOL LoadOCGState(const CPDF_Dictionary *pOCGDict) const; + FX_BOOL GetOCGVisible(const CPDF_Dictionary* pOCGDict); - FX_BOOL GetOCGVisible(const CPDF_Dictionary *pOCGDict); + FX_BOOL GetOCGVE(CPDF_Array* pExpression, + FX_BOOL bFromConfig, + int nLevel = 0); - FX_BOOL GetOCGVE(CPDF_Array *pExpression, FX_BOOL bFromConfig, int nLevel = 0); + FX_BOOL LoadOCMDState(const CPDF_Dictionary* pOCMDDict, FX_BOOL bFromConfig); - FX_BOOL LoadOCMDState(const CPDF_Dictionary *pOCMDDict, FX_BOOL bFromConfig); + CPDF_Document* m_pDocument; - CPDF_Document *m_pDocument; + UsageType m_eUsageType; - UsageType m_eUsageType; - - std::map<const CPDF_Dictionary*, FX_BOOL> m_OCGStates; + std::map<const CPDF_Dictionary*, FX_BOOL> m_OCGStates; }; -class CPDF_LWinParam -{ -public: - - CPDF_LWinParam(CPDF_Dictionary* pDict) - { - m_pDict = pDict; - } - - operator CPDF_Dictionary* () const - { - return m_pDict; - } - - inline CFX_ByteString GetFileName() - { - return m_pDict->GetString("F"); - } +class CPDF_LWinParam { + public: + CPDF_LWinParam(CPDF_Dictionary* pDict) { m_pDict = pDict; } + operator CPDF_Dictionary*() const { return m_pDict; } - inline CFX_ByteString GetDefaultDirectory() - { - return m_pDict->GetString("D"); - } + inline CFX_ByteString GetFileName() { return m_pDict->GetString("F"); } + inline CFX_ByteString GetDefaultDirectory() { + return m_pDict->GetString("D"); + } - inline CFX_ByteString GetOperation() - { - return m_pDict->GetString("O"); - } + inline CFX_ByteString GetOperation() { return m_pDict->GetString("O"); } + inline CFX_ByteString GetParameter() { return m_pDict->GetString("P"); } - inline CFX_ByteString GetParameter() - { - return m_pDict->GetString("P"); - } - - CPDF_Dictionary* m_pDict; + CPDF_Dictionary* m_pDict; }; -class CPDF_ActionFields -{ -public: - - CPDF_ActionFields(const CPDF_Action* pAction) - { - m_pAction = (CPDF_Action*)pAction; - } - - operator CPDF_Action*() const - { - return m_pAction; - } - - FX_DWORD GetFieldsCount() const; +class CPDF_ActionFields { + public: + CPDF_ActionFields(const CPDF_Action* pAction) { + m_pAction = (CPDF_Action*)pAction; + } - void GetAllFields(CFX_PtrArray& fieldObjects) const; - - CPDF_Object* GetField(FX_DWORD iIndex) const; - - CPDF_Action* m_pAction; -}; + operator CPDF_Action*() const { return m_pAction; } -#define PDFNAMED_NEXTPAGE 1 -#define PDFNAMED_PREVPAGE 2 -#define PDFNAMED_FIRSTPAGE 3 -#define PDFNAMED_LASTPAGE 4 -#define PDFJS_MAXLENGTH 64 -class CPDF_Action -{ -public: - enum ActionType { - Unknown = 0, - GoTo, - GoToR, - GoToE, - Launch, - Thread, - URI, - Sound, - Movie, - Hide, - Named, - SubmitForm, - ResetForm, - ImportData, - JavaScript, - SetOCGState, - Rendition, - Trans, - GoTo3DView - }; - - CPDF_Action() : m_pDict(nullptr) { } - explicit CPDF_Action(CPDF_Dictionary* pDict) : m_pDict(pDict) { } - - operator bool () const { return m_pDict != NULL; } - - CPDF_Dictionary* GetDict() const { return m_pDict; } - - CFX_ByteString GetTypeName() const - { - return m_pDict->GetString("S"); - } - - ActionType GetType() const; - - CPDF_Dest GetDest(CPDF_Document* pDoc) const; - - CFX_WideString GetFilePath() const; - - FX_BOOL GetNewWindow() const - { - return m_pDict->GetBoolean("NewWindow"); - } - - CPDF_LWinParam GetWinParam() const; - - CFX_ByteString GetURI(CPDF_Document* pDoc) const; - - FX_BOOL GetMouseMap() const - { - return m_pDict->GetBoolean("IsMap"); - } - - CPDF_ActionFields GetWidgets() const - { - return this; - } - - FX_BOOL GetHideStatus() const - { - return m_pDict->GetBoolean("H", TRUE); - } - - CFX_ByteString GetNamedAction() const - { - return m_pDict->GetString("N"); - } - - FX_DWORD GetFlags() const - { - return m_pDict->GetInteger("Flags"); - } - - CFX_WideString GetJavaScript() const; - - CPDF_Dictionary* GetAnnot() const; - - int32_t GetOperationType() const; - - CPDF_Stream* GetSoundStream() const - { - return m_pDict->GetStream("Sound"); - } - - FX_FLOAT GetVolume() const - { - return m_pDict->GetNumber("Volume"); - } - - FX_BOOL IsSynchronous() const - { - return m_pDict->GetBoolean("Synchronous"); - } - - FX_BOOL IsRepeat() const - { - return m_pDict->GetBoolean("Repeat"); - } - - FX_BOOL IsMixPlay() const - { - return m_pDict->GetBoolean("Mix"); - } + FX_DWORD GetFieldsCount() const; - FX_DWORD GetSubActionsCount() const; + void GetAllFields(CFX_PtrArray& fieldObjects) const; - CPDF_Action GetSubAction(FX_DWORD iIndex) const; + CPDF_Object* GetField(FX_DWORD iIndex) const; -protected: - CPDF_Dictionary* m_pDict; + CPDF_Action* m_pAction; }; -class CPDF_AAction -{ -public: - - CPDF_AAction(CPDF_Dictionary* pDict = NULL) - { - m_pDict = pDict; - } - - operator CPDF_Dictionary*() const - { - return m_pDict; - } - - enum AActionType { - CursorEnter = 0, - CursorExit, - ButtonDown, - ButtonUp, - GetFocus, - LoseFocus, - PageOpen, - PageClose, - PageVisible, - PageInvisible, - OpenPage, - ClosePage, - KeyStroke, - Format, - Validate, - Calculate, - CloseDocument, - SaveDocument, - DocumentSaved, - PrintDocument, - DocumentPrinted - }; - - FX_BOOL ActionExist(AActionType eType) const; - - CPDF_Action GetAction(AActionType eType) const; - - FX_POSITION GetStartPos() const; - - CPDF_Action GetNextAction(FX_POSITION& pos, AActionType& eType) const; - - CPDF_Dictionary* m_pDict; -}; -class CPDF_DocJSActions -{ -public: - CPDF_DocJSActions(CPDF_Document* pDoc); +#define PDFNAMED_NEXTPAGE 1 +#define PDFNAMED_PREVPAGE 2 +#define PDFNAMED_FIRSTPAGE 3 +#define PDFNAMED_LASTPAGE 4 +#define PDFJS_MAXLENGTH 64 +class CPDF_Action { + public: + enum ActionType { + Unknown = 0, + GoTo, + GoToR, + GoToE, + Launch, + Thread, + URI, + Sound, + Movie, + Hide, + Named, + SubmitForm, + ResetForm, + ImportData, + JavaScript, + SetOCGState, + Rendition, + Trans, + GoTo3DView + }; - int CountJSActions() const; + CPDF_Action() : m_pDict(nullptr) {} + explicit CPDF_Action(CPDF_Dictionary* pDict) : m_pDict(pDict) {} - CPDF_Action GetJSAction(int index, CFX_ByteString& csName) const; + operator bool() const { return m_pDict != NULL; } - CPDF_Action GetJSAction(const CFX_ByteString& csName) const; + CPDF_Dictionary* GetDict() const { return m_pDict; } - int FindJSAction(const CFX_ByteString& csName) const; + CFX_ByteString GetTypeName() const { return m_pDict->GetString("S"); } + ActionType GetType() const; - CPDF_Document* GetDocument() const - { - return m_pDocument; - } + CPDF_Dest GetDest(CPDF_Document* pDoc) const; -protected: + CFX_WideString GetFilePath() const; - CPDF_Document* m_pDocument; -}; -class CPDF_FileSpec -{ -public: + FX_BOOL GetNewWindow() const { return m_pDict->GetBoolean("NewWindow"); } - CPDF_FileSpec(); + CPDF_LWinParam GetWinParam() const; - CPDF_FileSpec(CPDF_Object *pObj) - { - m_pObj = pObj; - } + CFX_ByteString GetURI(CPDF_Document* pDoc) const; - operator CPDF_Object*() const - { - return m_pObj; - } + FX_BOOL GetMouseMap() const { return m_pDict->GetBoolean("IsMap"); } - FX_BOOL IsURL() const; + CPDF_ActionFields GetWidgets() const { return this; } - FX_BOOL GetFileName(CFX_WideString &wsFileName) const; + FX_BOOL GetHideStatus() const { return m_pDict->GetBoolean("H", TRUE); } - CPDF_Stream* GetFileStream() const; + CFX_ByteString GetNamedAction() const { return m_pDict->GetString("N"); } - void SetFileName(const CFX_WideStringC& wsFileName, FX_BOOL bURL = FALSE); -protected: + FX_DWORD GetFlags() const { return m_pDict->GetInteger("Flags"); } - CPDF_Object *m_pObj; -}; -class CPDF_LinkList -{ -public: + CFX_WideString GetJavaScript() const; - CPDF_LinkList(CPDF_Document* pDoc) - { - m_pDocument = pDoc; - } + CPDF_Dictionary* GetAnnot() const; - ~CPDF_LinkList(); + int32_t GetOperationType() const; - CPDF_Link GetLinkAtPoint(CPDF_Page* pPage, FX_FLOAT pdf_x, FX_FLOAT pdf_y); + CPDF_Stream* GetSoundStream() const { return m_pDict->GetStream("Sound"); } - int CountLinks(CPDF_Page* pPage); + FX_FLOAT GetVolume() const { return m_pDict->GetNumber("Volume"); } - CPDF_Link GetLink(CPDF_Page* pPage, int index); + FX_BOOL IsSynchronous() const { return m_pDict->GetBoolean("Synchronous"); } - CPDF_Document* GetDocument() const - { - return m_pDocument; - } -protected: + FX_BOOL IsRepeat() const { return m_pDict->GetBoolean("Repeat"); } - CPDF_Document* m_pDocument; + FX_BOOL IsMixPlay() const { return m_pDict->GetBoolean("Mix"); } - CFX_MapPtrToPtr m_PageMap; + FX_DWORD GetSubActionsCount() const; - CFX_PtrArray* GetPageLinks(CPDF_Page* pPage); + CPDF_Action GetSubAction(FX_DWORD iIndex) const; - void LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList); + protected: + CPDF_Dictionary* m_pDict; }; -class CPDF_Link -{ -public: - CPDF_Link() : m_pDict(nullptr) { } - explicit CPDF_Link(CPDF_Dictionary* pDict) : m_pDict(pDict) { } - - CPDF_Dictionary* GetDict() const { return m_pDict; } - - CFX_FloatRect GetRect(); - CPDF_Dest GetDest(CPDF_Document* pDoc); - CPDF_Action GetAction(); - -protected: - CPDF_Dictionary* m_pDict; +class CPDF_AAction { + public: + CPDF_AAction(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; } + + operator CPDF_Dictionary*() const { return m_pDict; } + + enum AActionType { + CursorEnter = 0, + CursorExit, + ButtonDown, + ButtonUp, + GetFocus, + LoseFocus, + PageOpen, + PageClose, + PageVisible, + PageInvisible, + OpenPage, + ClosePage, + KeyStroke, + Format, + Validate, + Calculate, + CloseDocument, + SaveDocument, + DocumentSaved, + PrintDocument, + DocumentPrinted + }; + + FX_BOOL ActionExist(AActionType eType) const; + + CPDF_Action GetAction(AActionType eType) const; + + FX_POSITION GetStartPos() const; + + CPDF_Action GetNextAction(FX_POSITION& pos, AActionType& eType) const; + + CPDF_Dictionary* m_pDict; }; +class CPDF_DocJSActions { + public: + CPDF_DocJSActions(CPDF_Document* pDoc); -#define ANNOTFLAG_INVISIBLE 0x0001 -#define ANNOTFLAG_HIDDEN 0x0002 -#define ANNOTFLAG_PRINT 0x0004 -#define ANNOTFLAG_NOZOOM 0x0008 -#define ANNOTFLAG_NOROTATE 0x0010 -#define ANNOTFLAG_NOVIEW 0x0020 -#define ANNOTFLAG_READONLY 0x0040 -#define ANNOTFLAG_LOCKED 0x0080 -#define ANNOTFLAG_TOGGLENOVIEW 0x0100 - -class CPDF_Annot : public CFX_PrivateData -{ - public: - enum AppearanceMode { - Normal, - Rollover, - Down - }; - - CPDF_Annot(CPDF_Dictionary* pDict, CPDF_AnnotList* pList); - ~CPDF_Annot(); - - CFX_ByteString GetSubType() const; - - FX_DWORD GetFlags() const; - - void GetRect(CFX_FloatRect& rect) const; - - CPDF_Dictionary* GetAnnotDict(); - - FX_BOOL DrawAppearance(const CPDF_Page* pPage, - CFX_RenderDevice* pDevice, - const CFX_AffineMatrix* pUser2Device, - AppearanceMode mode, - const CPDF_RenderOptions* pOptions); - - FX_BOOL DrawInContext(const CPDF_Page* pPage, - const CPDF_RenderContext* pContext, - const CFX_AffineMatrix* pUser2Device, - AppearanceMode mode); - - void ClearCachedAP(); + int CountJSActions() const; - void DrawBorder(CFX_RenderDevice* pDevice, - const CFX_AffineMatrix* pUser2Device, - const CPDF_RenderOptions* pOptions); + CPDF_Action GetJSAction(int index, CFX_ByteString& csName) const; - CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode); + CPDF_Action GetJSAction(const CFX_ByteString& csName) const; - private: - CPDF_Dictionary* const m_pAnnotDict; + int FindJSAction(const CFX_ByteString& csName) const; - CPDF_AnnotList* const m_pList; + CPDF_Document* GetDocument() const { return m_pDocument; } - const CFX_ByteString m_sSubtype; - - CFX_MapPtrToPtr m_APMap; + protected: + CPDF_Document* m_pDocument; }; +class CPDF_FileSpec { + public: + CPDF_FileSpec(); -class CPDF_AnnotList -{ -public: - - CPDF_AnnotList(CPDF_Page* pPage); - - ~CPDF_AnnotList(); - - void GetAnnotMatrix(const CPDF_Dictionary* pAnnotDict, const CFX_Matrix* pUser2Device, CFX_Matrix &matrix) const; - - void GetAnnotRect(const CPDF_Dictionary* pAnnotDict, const CFX_Matrix* pUser2Device, CPDF_Rect &rtAnnot) const; - - void DisplayAnnots(const CPDF_Page* pPage, CFX_RenderDevice* pDevice, - CFX_AffineMatrix* pMatrix, FX_BOOL bShowWidget, - CPDF_RenderOptions* pOptions); - - void DisplayAnnots(const CPDF_Page* pPage, CPDF_RenderContext* pContext, - FX_BOOL bPrinting, CFX_AffineMatrix* pMatrix, FX_BOOL bShowWidget, - CPDF_RenderOptions* pOptions) - { - DisplayAnnots(pPage, NULL, pContext, bPrinting, pMatrix, bShowWidget ? 3 : 1, pOptions, NULL); - } - - void DisplayAnnots(const CPDF_Page* pPage, CPDF_RenderContext* pContext, - FX_BOOL bPrinting, CFX_AffineMatrix* pMatrix, FX_BOOL bShowWidget, - CPDF_RenderOptions* pOptions, FX_RECT *pClipRect) - { - DisplayAnnots(pPage, NULL, pContext, bPrinting, pMatrix, bShowWidget ? 3 : 1, pOptions, pClipRect); - } - - void DisplayAnnots(const CPDF_Page* pPage, CFX_RenderDevice* pDevice, CPDF_RenderContext* pContext, - FX_BOOL bPrinting, CFX_AffineMatrix* pMatrix, FX_DWORD dwAnnotFlags, - CPDF_RenderOptions* pOptions, FX_RECT* pClipRect); - - - - CPDF_Annot* GetAt(int index) - { - return (CPDF_Annot*)m_AnnotList.GetAt(index); - } - - int Count() - { - return m_AnnotList.GetSize(); - } - - int GetIndex(CPDF_Annot* pAnnot); - + CPDF_FileSpec(CPDF_Object* pObj) { m_pObj = pObj; } - CPDF_Document* GetDocument() const - { - return m_pDocument; - } -protected: + operator CPDF_Object*() const { return m_pObj; } - CFX_PtrArray m_AnnotList; + FX_BOOL IsURL() const; - CPDF_Dictionary* m_pPageDict; + FX_BOOL GetFileName(CFX_WideString& wsFileName) const; - CPDF_Document* m_pDocument; + CPDF_Stream* GetFileStream() const; - CFX_PtrArray m_Borders; + void SetFileName(const CFX_WideStringC& wsFileName, FX_BOOL bURL = FALSE); - void DisplayPass(const CPDF_Page* pPage, CFX_RenderDevice* pDevice, - CPDF_RenderContext* pContext, FX_BOOL bPrinting, CFX_AffineMatrix* pMatrix, - FX_BOOL bWidget, CPDF_RenderOptions* pOptions, FX_RECT* clip_rect); - friend class CPDF_Annot; + protected: + CPDF_Object* m_pObj; }; -#define COLORTYPE_TRANSPARENT 0 -#define COLORTYPE_GRAY 1 -#define COLORTYPE_RGB 2 -#define COLORTYPE_CMYK 3 -class CPDF_DefaultAppearance -{ -public: - - CPDF_DefaultAppearance(const CFX_ByteString& csDA = "") - { - m_csDA = csDA; - } - - CPDF_DefaultAppearance(const CPDF_DefaultAppearance& cDA) - { - m_csDA = (CFX_ByteString)(CPDF_DefaultAppearance&)cDA; - } - - - operator CFX_ByteString() const - { - return m_csDA; - } - - const CPDF_DefaultAppearance& operator =(const CFX_ByteString& csDA) - { - m_csDA = csDA; - return *this; - } - - const CPDF_DefaultAppearance& operator =(const CPDF_DefaultAppearance& cDA) - { - m_csDA = (CFX_ByteString)(CPDF_DefaultAppearance&)cDA; - return *this; - } - - - - FX_BOOL HasFont(); - - CFX_ByteString GetFontString(); - - void GetFont(CFX_ByteString& csFontNameTag, FX_FLOAT& fFontSize); - - - - - FX_BOOL HasColor(FX_BOOL bStrokingOperation = FALSE); +class CPDF_LinkList { + public: + CPDF_LinkList(CPDF_Document* pDoc) { m_pDocument = pDoc; } - CFX_ByteString GetColorString(FX_BOOL bStrokingOperation = FALSE); + ~CPDF_LinkList(); - void GetColor(int& iColorType, FX_FLOAT fc[4], FX_BOOL bStrokingOperation = FALSE); + CPDF_Link GetLinkAtPoint(CPDF_Page* pPage, FX_FLOAT pdf_x, FX_FLOAT pdf_y); - void GetColor(FX_ARGB& color, int& iColorType, FX_BOOL bStrokingOperation = FALSE); + int CountLinks(CPDF_Page* pPage); + CPDF_Link GetLink(CPDF_Page* pPage, int index); + CPDF_Document* GetDocument() const { return m_pDocument; } + protected: + CPDF_Document* m_pDocument; - FX_BOOL HasTextMatrix(); + CFX_MapPtrToPtr m_PageMap; - CFX_ByteString GetTextMatrixString(); + CFX_PtrArray* GetPageLinks(CPDF_Page* pPage); - CFX_AffineMatrix GetTextMatrix(); - -protected: - - CFX_ByteString m_csDA; + void LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList); }; -#define FIELDTYPE_UNKNOWN 0 -#define FIELDTYPE_PUSHBUTTON 1 -#define FIELDTYPE_CHECKBOX 2 -#define FIELDTYPE_RADIOBUTTON 3 -#define FIELDTYPE_COMBOBOX 4 -#define FIELDTYPE_LISTBOX 5 -#define FIELDTYPE_TEXTFIELD 6 -#define FIELDTYPE_SIGNATURE 7 -class CPDF_InterForm : public CFX_PrivateData -{ -public: - - CPDF_InterForm(CPDF_Document* pDocument, FX_BOOL bUpdateAP); - - ~CPDF_InterForm(); - - - - static void EnableUpdateAP(FX_BOOL bUpdateAP); - - static FX_BOOL UpdatingAPEnabled(); - - - static CFX_ByteString GenerateNewResourceName(const CPDF_Dictionary* pResDict, const FX_CHAR* csType, int iMinLen = 2, const FX_CHAR* csPrefix = ""); - - - - static CPDF_Font* AddSystemDefaultFont(const CPDF_Document* pDocument); - - static CPDF_Font* AddSystemFont(const CPDF_Document* pDocument, CFX_ByteString csFontName, uint8_t iCharSet = 1); - - static CPDF_Font* AddSystemFont(const CPDF_Document* pDocument, CFX_WideString csFontName, uint8_t iCharSet = 1); +class CPDF_Link { + public: + CPDF_Link() : m_pDict(nullptr) {} + explicit CPDF_Link(CPDF_Dictionary* pDict) : m_pDict(pDict) {} - static CPDF_Font* AddStandardFont(const CPDF_Document* pDocument, CFX_ByteString csFontName); + CPDF_Dictionary* GetDict() const { return m_pDict; } - static CFX_ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont = NULL); + CFX_FloatRect GetRect(); + CPDF_Dest GetDest(CPDF_Document* pDoc); + CPDF_Action GetAction(); - static CFX_ByteString GetNativeFont(void* pLogFont = NULL); - - static uint8_t GetNativeCharSet(); - - static CPDF_Font* AddNativeFont(uint8_t iCharSet, const CPDF_Document* pDocument); - - static CPDF_Font* AddNativeFont(const CPDF_Document* pDocument); + protected: + CPDF_Dictionary* m_pDict; +}; +#define ANNOTFLAG_INVISIBLE 0x0001 +#define ANNOTFLAG_HIDDEN 0x0002 +#define ANNOTFLAG_PRINT 0x0004 +#define ANNOTFLAG_NOZOOM 0x0008 +#define ANNOTFLAG_NOROTATE 0x0010 +#define ANNOTFLAG_NOVIEW 0x0020 +#define ANNOTFLAG_READONLY 0x0040 +#define ANNOTFLAG_LOCKED 0x0080 +#define ANNOTFLAG_TOGGLENOVIEW 0x0100 +class CPDF_Annot : public CFX_PrivateData { + public: + enum AppearanceMode { Normal, Rollover, Down }; + CPDF_Annot(CPDF_Dictionary* pDict, CPDF_AnnotList* pList); + ~CPDF_Annot(); - FX_BOOL ValidateFieldName(CFX_WideString& csNewFieldName, int iType); + CFX_ByteString GetSubType() const; - FX_BOOL ValidateFieldName(const CPDF_FormField* pField, CFX_WideString& csNewFieldName); + FX_DWORD GetFlags() const; - FX_BOOL ValidateFieldName(const CPDF_FormControl* pControl, CFX_WideString& csNewFieldName); + void GetRect(CFX_FloatRect& rect) const; + CPDF_Dictionary* GetAnnotDict(); + FX_BOOL DrawAppearance(const CPDF_Page* pPage, + CFX_RenderDevice* pDevice, + const CFX_AffineMatrix* pUser2Device, + AppearanceMode mode, + const CPDF_RenderOptions* pOptions); + FX_BOOL DrawInContext(const CPDF_Page* pPage, + const CPDF_RenderContext* pContext, + const CFX_AffineMatrix* pUser2Device, + AppearanceMode mode); - FX_DWORD CountFields(const CFX_WideString &csFieldName = L""); + void ClearCachedAP(); - CPDF_FormField* GetField(FX_DWORD index, const CFX_WideString &csFieldName = L""); + void DrawBorder(CFX_RenderDevice* pDevice, + const CFX_AffineMatrix* pUser2Device, + const CPDF_RenderOptions* pOptions); - void GetAllFieldNames(CFX_WideStringArray& allFieldNames); + CPDF_Form* GetAPForm(const CPDF_Page* pPage, AppearanceMode mode); - FX_BOOL IsValidFormField(const void* pField); + private: + CPDF_Dictionary* const m_pAnnotDict; - CPDF_FormField* GetFieldByDict(CPDF_Dictionary* pFieldDict) const; + CPDF_AnnotList* const m_pList; + const CFX_ByteString m_sSubtype; + CFX_MapPtrToPtr m_APMap; +}; +class CPDF_AnnotList { + public: + CPDF_AnnotList(CPDF_Page* pPage); + + ~CPDF_AnnotList(); + + void GetAnnotMatrix(const CPDF_Dictionary* pAnnotDict, + const CFX_Matrix* pUser2Device, + CFX_Matrix& matrix) const; + + void GetAnnotRect(const CPDF_Dictionary* pAnnotDict, + const CFX_Matrix* pUser2Device, + CPDF_Rect& rtAnnot) const; + + void DisplayAnnots(const CPDF_Page* pPage, + CFX_RenderDevice* pDevice, + CFX_AffineMatrix* pMatrix, + FX_BOOL bShowWidget, + CPDF_RenderOptions* pOptions); + + void DisplayAnnots(const CPDF_Page* pPage, + CPDF_RenderContext* pContext, + FX_BOOL bPrinting, + CFX_AffineMatrix* pMatrix, + FX_BOOL bShowWidget, + CPDF_RenderOptions* pOptions) { + DisplayAnnots(pPage, NULL, pContext, bPrinting, pMatrix, + bShowWidget ? 3 : 1, pOptions, NULL); + } + + void DisplayAnnots(const CPDF_Page* pPage, + CPDF_RenderContext* pContext, + FX_BOOL bPrinting, + CFX_AffineMatrix* pMatrix, + FX_BOOL bShowWidget, + CPDF_RenderOptions* pOptions, + FX_RECT* pClipRect) { + DisplayAnnots(pPage, NULL, pContext, bPrinting, pMatrix, + bShowWidget ? 3 : 1, pOptions, pClipRect); + } + + void DisplayAnnots(const CPDF_Page* pPage, + CFX_RenderDevice* pDevice, + CPDF_RenderContext* pContext, + FX_BOOL bPrinting, + CFX_AffineMatrix* pMatrix, + FX_DWORD dwAnnotFlags, + CPDF_RenderOptions* pOptions, + FX_RECT* pClipRect); + + CPDF_Annot* GetAt(int index) { return (CPDF_Annot*)m_AnnotList.GetAt(index); } + + int Count() { return m_AnnotList.GetSize(); } + + int GetIndex(CPDF_Annot* pAnnot); + + CPDF_Document* GetDocument() const { return m_pDocument; } + + protected: + CFX_PtrArray m_AnnotList; + + CPDF_Dictionary* m_pPageDict; + + CPDF_Document* m_pDocument; + + CFX_PtrArray m_Borders; + + void DisplayPass(const CPDF_Page* pPage, + CFX_RenderDevice* pDevice, + CPDF_RenderContext* pContext, + FX_BOOL bPrinting, + CFX_AffineMatrix* pMatrix, + FX_BOOL bWidget, + CPDF_RenderOptions* pOptions, + FX_RECT* clip_rect); + friend class CPDF_Annot; +}; +#define COLORTYPE_TRANSPARENT 0 +#define COLORTYPE_GRAY 1 +#define COLORTYPE_RGB 2 +#define COLORTYPE_CMYK 3 +class CPDF_DefaultAppearance { + public: + CPDF_DefaultAppearance(const CFX_ByteString& csDA = "") { m_csDA = csDA; } - FX_DWORD CountControls(CFX_WideString csFieldName = L""); + CPDF_DefaultAppearance(const CPDF_DefaultAppearance& cDA) { + m_csDA = (CFX_ByteString)(CPDF_DefaultAppearance&)cDA; + } - CPDF_FormControl* GetControl(FX_DWORD index, CFX_WideString csFieldName = L""); + operator CFX_ByteString() const { return m_csDA; } - FX_BOOL IsValidFormControl(const void* pControl); + const CPDF_DefaultAppearance& operator=(const CFX_ByteString& csDA) { + m_csDA = csDA; + return *this; + } - int CountPageControls(CPDF_Page* pPage) const; + const CPDF_DefaultAppearance& operator=(const CPDF_DefaultAppearance& cDA) { + m_csDA = (CFX_ByteString)(CPDF_DefaultAppearance&)cDA; + return *this; + } - CPDF_FormControl* GetPageControl(CPDF_Page* pPage, int index) const; + FX_BOOL HasFont(); + CFX_ByteString GetFontString(); - CPDF_FormControl* GetControlAtPoint(CPDF_Page* pPage, FX_FLOAT pdf_x, FX_FLOAT pdf_y) const; + void GetFont(CFX_ByteString& csFontNameTag, FX_FLOAT& fFontSize); - CPDF_FormControl* GetControlByDict(CPDF_Dictionary* pWidgetDict) const; + FX_BOOL HasColor(FX_BOOL bStrokingOperation = FALSE); + CFX_ByteString GetColorString(FX_BOOL bStrokingOperation = FALSE); + void GetColor(int& iColorType, + FX_FLOAT fc[4], + FX_BOOL bStrokingOperation = FALSE); + void GetColor(FX_ARGB& color, + int& iColorType, + FX_BOOL bStrokingOperation = FALSE); - FX_DWORD CountInternalFields(const CFX_WideString& csFieldName = L"") const; + FX_BOOL HasTextMatrix(); - CPDF_Dictionary* GetInternalField(FX_DWORD index, const CFX_WideString& csFieldName = L"") const; + CFX_ByteString GetTextMatrixString(); + CFX_AffineMatrix GetTextMatrix(); + protected: + CFX_ByteString m_csDA; +}; +#define FIELDTYPE_UNKNOWN 0 +#define FIELDTYPE_PUSHBUTTON 1 +#define FIELDTYPE_CHECKBOX 2 +#define FIELDTYPE_RADIOBUTTON 3 +#define FIELDTYPE_COMBOBOX 4 +#define FIELDTYPE_LISTBOX 5 +#define FIELDTYPE_TEXTFIELD 6 +#define FIELDTYPE_SIGNATURE 7 +class CPDF_InterForm : public CFX_PrivateData { + public: + CPDF_InterForm(CPDF_Document* pDocument, FX_BOOL bUpdateAP); + ~CPDF_InterForm(); + static void EnableUpdateAP(FX_BOOL bUpdateAP); - CPDF_Document* GetDocument() const - { - return m_pDocument; - } + static FX_BOOL UpdatingAPEnabled(); - CPDF_Dictionary* GetFormDict() const - { - return m_pFormDict; - } + static CFX_ByteString GenerateNewResourceName(const CPDF_Dictionary* pResDict, + const FX_CHAR* csType, + int iMinLen = 2, + const FX_CHAR* csPrefix = ""); + static CPDF_Font* AddSystemDefaultFont(const CPDF_Document* pDocument); + static CPDF_Font* AddSystemFont(const CPDF_Document* pDocument, + CFX_ByteString csFontName, + uint8_t iCharSet = 1); + static CPDF_Font* AddSystemFont(const CPDF_Document* pDocument, + CFX_WideString csFontName, + uint8_t iCharSet = 1); - FX_BOOL NeedConstructAP(); + static CPDF_Font* AddStandardFont(const CPDF_Document* pDocument, + CFX_ByteString csFontName); - void NeedConstructAP(FX_BOOL bNeedAP); + static CFX_ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont = NULL); + static CFX_ByteString GetNativeFont(void* pLogFont = NULL); + static uint8_t GetNativeCharSet(); + static CPDF_Font* AddNativeFont(uint8_t iCharSet, + const CPDF_Document* pDocument); - int CountFieldsInCalculationOrder(); + static CPDF_Font* AddNativeFont(const CPDF_Document* pDocument); - CPDF_FormField* GetFieldInCalculationOrder(int index); + FX_BOOL ValidateFieldName(CFX_WideString& csNewFieldName, int iType); - int FindFieldInCalculationOrder(const CPDF_FormField* pField); + FX_BOOL ValidateFieldName(const CPDF_FormField* pField, + CFX_WideString& csNewFieldName); + FX_BOOL ValidateFieldName(const CPDF_FormControl* pControl, + CFX_WideString& csNewFieldName); + FX_DWORD CountFields(const CFX_WideString& csFieldName = L""); + CPDF_FormField* GetField(FX_DWORD index, + const CFX_WideString& csFieldName = L""); - FX_DWORD CountFormFonts(); + void GetAllFieldNames(CFX_WideStringArray& allFieldNames); - CPDF_Font* GetFormFont(FX_DWORD index, CFX_ByteString& csNameTag); + FX_BOOL IsValidFormField(const void* pField); - CPDF_Font* GetFormFont(CFX_ByteString csNameTag); + CPDF_FormField* GetFieldByDict(CPDF_Dictionary* pFieldDict) const; - CPDF_Font* GetFormFont(CFX_ByteString csFontName, CFX_ByteString& csNameTag); + FX_DWORD CountControls(CFX_WideString csFieldName = L""); - CPDF_Font* GetNativeFormFont(uint8_t iCharSet, CFX_ByteString& csNameTag); + CPDF_FormControl* GetControl(FX_DWORD index, + CFX_WideString csFieldName = L""); - CPDF_Font* GetNativeFormFont(CFX_ByteString& csNameTag); + FX_BOOL IsValidFormControl(const void* pControl); - FX_BOOL FindFormFont(const CPDF_Font* pFont, CFX_ByteString& csNameTag); + int CountPageControls(CPDF_Page* pPage) const; - FX_BOOL FindFormFont(CFX_ByteString csFontName, CPDF_Font*& pFont, CFX_ByteString& csNameTag); + CPDF_FormControl* GetPageControl(CPDF_Page* pPage, int index) const; - inline FX_BOOL FindFormFont(CFX_WideString csFontName, CPDF_Font*& pFont, CFX_ByteString& csNameTag) - { - return FindFormFont(PDF_EncodeText(csFontName), pFont, csNameTag); - } + CPDF_FormControl* GetControlAtPoint(CPDF_Page* pPage, + FX_FLOAT pdf_x, + FX_FLOAT pdf_y) const; + CPDF_FormControl* GetControlByDict(CPDF_Dictionary* pWidgetDict) const; + FX_DWORD CountInternalFields(const CFX_WideString& csFieldName = L"") const; + CPDF_Dictionary* GetInternalField( + FX_DWORD index, + const CFX_WideString& csFieldName = L"") const; + CPDF_Document* GetDocument() const { return m_pDocument; } - void AddFormFont(const CPDF_Font* pFont, CFX_ByteString& csNameTag); + CPDF_Dictionary* GetFormDict() const { return m_pFormDict; } - CPDF_Font* AddNativeFormFont(uint8_t iCharSet, CFX_ByteString& csNameTag); + FX_BOOL NeedConstructAP(); - CPDF_Font* AddNativeFormFont(CFX_ByteString& csNameTag); + void NeedConstructAP(FX_BOOL bNeedAP); - void RemoveFormFont(const CPDF_Font* pFont); + int CountFieldsInCalculationOrder(); - void RemoveFormFont(CFX_ByteString csNameTag); + CPDF_FormField* GetFieldInCalculationOrder(int index); + int FindFieldInCalculationOrder(const CPDF_FormField* pField); + FX_DWORD CountFormFonts(); + CPDF_Font* GetFormFont(FX_DWORD index, CFX_ByteString& csNameTag); - CPDF_DefaultAppearance GetDefaultAppearance(); + CPDF_Font* GetFormFont(CFX_ByteString csNameTag); - CPDF_Font* GetDefaultFormFont(); + CPDF_Font* GetFormFont(CFX_ByteString csFontName, CFX_ByteString& csNameTag); + CPDF_Font* GetNativeFormFont(uint8_t iCharSet, CFX_ByteString& csNameTag); + CPDF_Font* GetNativeFormFont(CFX_ByteString& csNameTag); - int GetFormAlignment(); + FX_BOOL FindFormFont(const CPDF_Font* pFont, CFX_ByteString& csNameTag); + FX_BOOL FindFormFont(CFX_ByteString csFontName, + CPDF_Font*& pFont, + CFX_ByteString& csNameTag); + inline FX_BOOL FindFormFont(CFX_WideString csFontName, + CPDF_Font*& pFont, + CFX_ByteString& csNameTag) { + return FindFormFont(PDF_EncodeText(csFontName), pFont, csNameTag); + } + void AddFormFont(const CPDF_Font* pFont, CFX_ByteString& csNameTag); - CPDF_FormField* CheckRequiredFields(const CFX_PtrArray *fields = NULL, FX_BOOL bIncludeOrExclude = TRUE) const; + CPDF_Font* AddNativeFormFont(uint8_t iCharSet, CFX_ByteString& csNameTag); - CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, FX_BOOL bSimpleFileSpec = FALSE) const; + CPDF_Font* AddNativeFormFont(CFX_ByteString& csNameTag); - CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, CFX_PtrArray& fields, FX_BOOL bIncludeOrExclude = TRUE, FX_BOOL bSimpleFileSpec = FALSE) const; + void RemoveFormFont(const CPDF_Font* pFont); - FX_BOOL ImportFromFDF(const CFDF_Document* pFDFDoc, FX_BOOL bNotify = FALSE); + void RemoveFormFont(CFX_ByteString csNameTag); + CPDF_DefaultAppearance GetDefaultAppearance(); + CPDF_Font* GetDefaultFormFont(); + int GetFormAlignment(); - FX_BOOL ResetForm(const CFX_PtrArray& fields, FX_BOOL bIncludeOrExclude = TRUE, FX_BOOL bNotify = FALSE); + CPDF_FormField* CheckRequiredFields(const CFX_PtrArray* fields = NULL, + FX_BOOL bIncludeOrExclude = TRUE) const; - FX_BOOL ResetForm(FX_BOOL bNotify = FALSE); + CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, + FX_BOOL bSimpleFileSpec = FALSE) const; - void ReloadForm(); + CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, + CFX_PtrArray& fields, + FX_BOOL bIncludeOrExclude = TRUE, + FX_BOOL bSimpleFileSpec = FALSE) const; - CPDF_FormNotify* GetFormNotify() const - { - return m_pFormNotify; - } + FX_BOOL ImportFromFDF(const CFDF_Document* pFDFDoc, FX_BOOL bNotify = FALSE); - void SetFormNotify(const CPDF_FormNotify* pNotify); + FX_BOOL ResetForm(const CFX_PtrArray& fields, + FX_BOOL bIncludeOrExclude = TRUE, + FX_BOOL bNotify = FALSE); + FX_BOOL ResetForm(FX_BOOL bNotify = FALSE); - int GetPageWithWidget(int iCurPage, FX_BOOL bNext); + void ReloadForm(); + CPDF_FormNotify* GetFormNotify() const { return m_pFormNotify; } + void SetFormNotify(const CPDF_FormNotify* pNotify); - FX_BOOL IsUpdated() - { - return m_bUpdated; - } + int GetPageWithWidget(int iCurPage, FX_BOOL bNext); - void ClearUpdatedFlag() - { - m_bUpdated = FALSE; - } + FX_BOOL IsUpdated() { return m_bUpdated; } + void ClearUpdatedFlag() { m_bUpdated = FALSE; } - FX_BOOL HasXFAForm() const; + FX_BOOL HasXFAForm() const; - void FixPageFields(const CPDF_Page* pPage); -protected: + void FixPageFields(const CPDF_Page* pPage); - static FX_BOOL m_bUpdateAP; + protected: + static FX_BOOL m_bUpdateAP; - void LoadField(CPDF_Dictionary* pFieldDict, int nLevel = 0); + void LoadField(CPDF_Dictionary* pFieldDict, int nLevel = 0); - CPDF_Object* GetFieldAttr(CPDF_Dictionary* pFieldDict, const FX_CHAR* name); + CPDF_Object* GetFieldAttr(CPDF_Dictionary* pFieldDict, const FX_CHAR* name); - CPDF_FormField* AddTerminalField(const CPDF_Dictionary* pFieldDict); + CPDF_FormField* AddTerminalField(const CPDF_Dictionary* pFieldDict); - CPDF_FormControl* AddControl(const CPDF_FormField* pField, const CPDF_Dictionary* pWidgetDict); + CPDF_FormControl* AddControl(const CPDF_FormField* pField, + const CPDF_Dictionary* pWidgetDict); - void FDF_ImportField(CPDF_Dictionary* pField, const CFX_WideString& parent_name, FX_BOOL bNotify = FALSE, int nLevel = 0); + void FDF_ImportField(CPDF_Dictionary* pField, + const CFX_WideString& parent_name, + FX_BOOL bNotify = FALSE, + int nLevel = 0); - FX_BOOL ValidateFieldName(CFX_WideString& csNewFieldName, int iType, const CPDF_FormField* pExcludedField, const CPDF_FormControl* pExcludedControl); + FX_BOOL ValidateFieldName(CFX_WideString& csNewFieldName, + int iType, + const CPDF_FormField* pExcludedField, + const CPDF_FormControl* pExcludedControl); - int CompareFieldName(const CFX_WideString& name1, const CFX_WideString& name2); + int CompareFieldName(const CFX_WideString& name1, + const CFX_WideString& name2); - int CompareFieldName(const CFX_ByteString& name1, const CFX_ByteString& name2); + int CompareFieldName(const CFX_ByteString& name1, + const CFX_ByteString& name2); - CPDF_Document* m_pDocument; + CPDF_Document* m_pDocument; - FX_BOOL m_bGenerateAP; + FX_BOOL m_bGenerateAP; - CPDF_Dictionary* m_pFormDict; + CPDF_Dictionary* m_pFormDict; - CFX_MapPtrToPtr m_ControlMap; + CFX_MapPtrToPtr m_ControlMap; - CFieldTree *m_pFieldTree; + CFieldTree* m_pFieldTree; - CFX_ByteString m_bsEncoding; + CFX_ByteString m_bsEncoding; - CPDF_FormNotify* m_pFormNotify; + CPDF_FormNotify* m_pFormNotify; - FX_BOOL m_bUpdated; - friend class CPDF_FormControl; - friend class CPDF_FormField; + FX_BOOL m_bUpdated; + friend class CPDF_FormControl; + friend class CPDF_FormField; }; -#define FORMFIELD_READONLY 0x01 -#define FORMFIELD_REQUIRED 0x02 -#define FORMFIELD_NOEXPORT 0x04 -#define FORMRADIO_NOTOGGLEOFF 0x100 -#define FORMRADIO_UNISON 0x200 -#define FORMTEXT_MULTILINE 0x100 -#define FORMTEXT_PASSWORD 0x200 -#define FORMTEXT_NOSCROLL 0x400 -#define FORMTEXT_COMB 0x800 -#define FORMCOMBO_EDIT 0x100 -#define FORMLIST_MULTISELECT 0x100 -class CPDF_FormField -{ -public: - - enum Type { - Unknown, - PushButton, - RadioButton, - CheckBox, - Text, - RichText, - File, - ListBox, - ComboBox, - Sign - }; - - CFX_WideString GetFullName(); - - Type GetType() - { - return m_Type; - } - - FX_DWORD GetFlags() - { - return m_Flags; - } - - CPDF_InterForm* GetInterForm() const - { - return m_pForm; - } - - CPDF_Dictionary* GetFieldDict() const - { - return m_pDict; - } - - void SetFieldDict(CPDF_Dictionary* pDict) - { - m_pDict = pDict; - } - - FX_BOOL ResetField(FX_BOOL bNotify = FALSE); - - - - int CountControls() - { - return m_ControlList.GetSize(); - } - - CPDF_FormControl* GetControl(int index) - { - return (CPDF_FormControl*)m_ControlList.GetAt(index); - } - - int GetControlIndex(const CPDF_FormControl* pControl); - - - - - int GetFieldType(); - - - - - CPDF_AAction GetAdditionalAction(); - - - - - CFX_WideString GetAlternateName(); - - - - - CFX_WideString GetMappingName(); - - - - - FX_DWORD GetFieldFlags(); - - - - - CFX_ByteString GetDefaultStyle(); +#define FORMFIELD_READONLY 0x01 +#define FORMFIELD_REQUIRED 0x02 +#define FORMFIELD_NOEXPORT 0x04 +#define FORMRADIO_NOTOGGLEOFF 0x100 +#define FORMRADIO_UNISON 0x200 +#define FORMTEXT_MULTILINE 0x100 +#define FORMTEXT_PASSWORD 0x200 +#define FORMTEXT_NOSCROLL 0x400 +#define FORMTEXT_COMB 0x800 +#define FORMCOMBO_EDIT 0x100 +#define FORMLIST_MULTISELECT 0x100 +class CPDF_FormField { + public: + enum Type { + Unknown, + PushButton, + RadioButton, + CheckBox, + Text, + RichText, + File, + ListBox, + ComboBox, + Sign + }; + CFX_WideString GetFullName(); + Type GetType() { return m_Type; } + FX_DWORD GetFlags() { return m_Flags; } - CFX_WideString GetRichTextString(); + CPDF_InterForm* GetInterForm() const { return m_pForm; } + CPDF_Dictionary* GetFieldDict() const { return m_pDict; } + void SetFieldDict(CPDF_Dictionary* pDict) { m_pDict = pDict; } - CFX_WideString GetValue(); + FX_BOOL ResetField(FX_BOOL bNotify = FALSE); - CFX_WideString GetDefaultValue(); + int CountControls() { return m_ControlList.GetSize(); } - FX_BOOL SetValue(const CFX_WideString& value, FX_BOOL bNotify = FALSE); + CPDF_FormControl* GetControl(int index) { + return (CPDF_FormControl*)m_ControlList.GetAt(index); + } + int GetControlIndex(const CPDF_FormControl* pControl); + int GetFieldType(); + CPDF_AAction GetAdditionalAction(); + CFX_WideString GetAlternateName(); - int GetMaxLen(); + CFX_WideString GetMappingName(); + FX_DWORD GetFieldFlags(); + CFX_ByteString GetDefaultStyle(); + CFX_WideString GetRichTextString(); - int CountSelectedItems(); + CFX_WideString GetValue(); - int GetSelectedIndex(int index); + CFX_WideString GetDefaultValue(); - FX_BOOL ClearSelection(FX_BOOL bNotify = FALSE); + FX_BOOL SetValue(const CFX_WideString& value, FX_BOOL bNotify = FALSE); - FX_BOOL IsItemSelected(int index); + int GetMaxLen(); - FX_BOOL SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify = FALSE); + int CountSelectedItems(); - FX_BOOL IsItemDefaultSelected(int index); + int GetSelectedIndex(int index); - int GetDefaultSelectedItem(); + FX_BOOL ClearSelection(FX_BOOL bNotify = FALSE); + FX_BOOL IsItemSelected(int index); + FX_BOOL SetItemSelection(int index, + FX_BOOL bSelected, + FX_BOOL bNotify = FALSE); + FX_BOOL IsItemDefaultSelected(int index); - int CountOptions(); + int GetDefaultSelectedItem(); - CFX_WideString GetOptionLabel(int index); + int CountOptions(); - CFX_WideString GetOptionValue(int index); + CFX_WideString GetOptionLabel(int index); - int FindOption(CFX_WideString csOptLabel); + CFX_WideString GetOptionValue(int index); - int FindOptionValue(const CFX_WideString& csOptValue, int iStartIndex = 0); + int FindOption(CFX_WideString csOptLabel); + int FindOptionValue(const CFX_WideString& csOptValue, int iStartIndex = 0); + FX_BOOL CheckControl(int iControlIndex, + FX_BOOL bChecked, + FX_BOOL bNotify = FALSE); + int GetTopVisibleIndex(); - FX_BOOL CheckControl(int iControlIndex, FX_BOOL bChecked, FX_BOOL bNotify = FALSE); + int CountSelectedOptions(); + int GetSelectedOptionIndex(int index); + FX_BOOL IsOptionSelected(int iOptIndex); + FX_BOOL SelectOption(int iOptIndex, + FX_BOOL bSelected, + FX_BOOL bNotify = FALSE); - int GetTopVisibleIndex(); + FX_BOOL ClearSelectedOptions(FX_BOOL bNotify = FALSE); + FX_BOOL ClearOptions(FX_BOOL bNotify = FALSE); + int InsertOption(CFX_WideString csOptLabel, + int index = -1, + FX_BOOL bNotify = FALSE); + FX_FLOAT GetFontSize() { return m_FontSize; } - int CountSelectedOptions(); + CPDF_Font* GetFont() { return m_pFont; } - int GetSelectedOptionIndex(int index); + protected: + CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict); - FX_BOOL IsOptionSelected(int iOptIndex); + ~CPDF_FormField(); - FX_BOOL SelectOption(int iOptIndex, FX_BOOL bSelected, FX_BOOL bNotify = FALSE); + CPDF_FormField::Type m_Type; - FX_BOOL ClearSelectedOptions(FX_BOOL bNotify = FALSE); + FX_DWORD m_Flags; - FX_BOOL ClearOptions(FX_BOOL bNotify = FALSE);
+ CPDF_InterForm* m_pForm; - int InsertOption(CFX_WideString csOptLabel, int index = -1, FX_BOOL bNotify = FALSE);
+ CPDF_Dictionary* m_pDict; - FX_FLOAT GetFontSize() - { - return m_FontSize; - } + CFX_PtrArray m_ControlList; + friend class CPDF_InterForm; + friend class CPDF_FormControl; - CPDF_Font* GetFont() - { - return m_pFont; - } + CFX_WideString GetValue(FX_BOOL bDefault); -protected: + FX_BOOL SetValue(const CFX_WideString& value, + FX_BOOL bDefault, + FX_BOOL bNotify); - CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict); + void SyncFieldFlags(); - ~CPDF_FormField(); + int FindListSel(CPDF_String* str); - CPDF_FormField::Type m_Type; + CFX_WideString GetOptionText(int index, int sub_index); - FX_DWORD m_Flags; + void LoadDA(); - CPDF_InterForm* m_pForm; + void UpdateAP(CPDF_FormControl* pControl); - CPDF_Dictionary* m_pDict; + CFX_WideString GetCheckValue(FX_BOOL bDefault); - CFX_PtrArray m_ControlList; - friend class CPDF_InterForm; - friend class CPDF_FormControl; + FX_BOOL SetCheckValue(const CFX_WideString& value, + FX_BOOL bDefault, + FX_BOOL bNotify); + FX_FLOAT m_FontSize; - - CFX_WideString GetValue(FX_BOOL bDefault); - - FX_BOOL SetValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify); - - - void SyncFieldFlags(); - - int FindListSel(CPDF_String* str); - - CFX_WideString GetOptionText(int index, int sub_index); - - void LoadDA(); - - void UpdateAP(CPDF_FormControl* pControl); - - - - CFX_WideString GetCheckValue(FX_BOOL bDefault); - - FX_BOOL SetCheckValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify); - - - FX_FLOAT m_FontSize; - - CPDF_Font* m_pFont; + CPDF_Font* m_pFont; }; -CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, const FX_CHAR* name, int nLevel = 0); -class CPDF_IconFit -{ -public: +CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, + const FX_CHAR* name, + int nLevel = 0); +class CPDF_IconFit { + public: + CPDF_IconFit(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; } - CPDF_IconFit(CPDF_Dictionary* pDict = NULL) - { - m_pDict = pDict; - } + operator CPDF_Dictionary*() const { return m_pDict; } - operator CPDF_Dictionary*() const - { - return m_pDict; - } + enum ScaleMethod { Always = 0, Bigger, Smaller, Never }; + ScaleMethod GetScaleMethod(); + FX_BOOL IsProportionalScale(); + void GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom); - enum ScaleMethod { - Always = 0, - Bigger, - Smaller, - Never - }; + FX_BOOL GetFittingBounds(); - ScaleMethod GetScaleMethod(); - - - - - FX_BOOL IsProportionalScale(); - - - - - void GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom); - - - - - FX_BOOL GetFittingBounds(); - - - CPDF_Dictionary* m_pDict; + CPDF_Dictionary* m_pDict; }; -#define TEXTPOS_CAPTION 0 -#define TEXTPOS_ICON 1 -#define TEXTPOS_BELOW 2 -#define TEXTPOS_ABOVE 3 -#define TEXTPOS_RIGHT 4 -#define TEXTPOS_LEFT 5 -#define TEXTPOS_OVERLAID 6 -class CPDF_FormControl -{ -public: - - CPDF_FormField::Type GetType() - { - return m_pField->GetType(); - } - - CPDF_InterForm* GetInterForm() const - { - return m_pForm; - } - - CPDF_FormField* GetField() const - { - return m_pField; - } - - CPDF_Dictionary* GetWidget() const - { - return m_pWidgetDict; - } - - CFX_FloatRect GetRect(); - - void DrawControl(CFX_RenderDevice* pDevice, CFX_AffineMatrix* pMatrix, - CPDF_Page* pPage, CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions = NULL); - - - - CFX_ByteString GetCheckedAPState(); - - CFX_WideString GetExportValue(); - - FX_BOOL IsChecked(); - - FX_BOOL IsDefaultChecked(); - - - - - enum HighlightingMode { - None = 0, - Invert, - Outline, - Push, - Toggle - }; - - HighlightingMode GetHighlightingMode(); - - - - - FX_BOOL HasMKEntry(CFX_ByteString csEntry); - - - - - int GetRotation(); - - - - - inline FX_ARGB GetBorderColor(int& iColorType) - { - return GetColor(iColorType, "BC"); - } - - inline FX_FLOAT GetOriginalBorderColor(int index) - { - return GetOriginalColor(index, "BC"); - } - - inline void GetOriginalBorderColor(int& iColorType, FX_FLOAT fc[4]) - { - GetOriginalColor(iColorType, fc, "BC"); - } +#define TEXTPOS_CAPTION 0 +#define TEXTPOS_ICON 1 +#define TEXTPOS_BELOW 2 +#define TEXTPOS_ABOVE 3 +#define TEXTPOS_RIGHT 4 +#define TEXTPOS_LEFT 5 +#define TEXTPOS_OVERLAID 6 +class CPDF_FormControl { + public: + CPDF_FormField::Type GetType() { return m_pField->GetType(); } + CPDF_InterForm* GetInterForm() const { return m_pForm; } + CPDF_FormField* GetField() const { return m_pField; } + CPDF_Dictionary* GetWidget() const { return m_pWidgetDict; } - inline FX_ARGB GetBackgroundColor(int& iColorType) - { - return GetColor(iColorType, "BG"); - } + CFX_FloatRect GetRect(); - inline FX_FLOAT GetOriginalBackgroundColor(int index) - { - return GetOriginalColor(index, "BG"); - } + void DrawControl(CFX_RenderDevice* pDevice, + CFX_AffineMatrix* pMatrix, + CPDF_Page* pPage, + CPDF_Annot::AppearanceMode mode, + const CPDF_RenderOptions* pOptions = NULL); - inline void GetOriginalBackgroundColor(int& iColorType, FX_FLOAT fc[4]) - { - GetOriginalColor(iColorType, fc, "BG"); - } + CFX_ByteString GetCheckedAPState(); + CFX_WideString GetExportValue(); + FX_BOOL IsChecked(); + FX_BOOL IsDefaultChecked(); - inline CFX_WideString GetNormalCaption() - { - return GetCaption("CA"); - } + enum HighlightingMode { None = 0, Invert, Outline, Push, Toggle }; + HighlightingMode GetHighlightingMode(); + FX_BOOL HasMKEntry(CFX_ByteString csEntry); + int GetRotation(); - inline CFX_WideString GetRolloverCaption() - { - return GetCaption("RC"); - } + inline FX_ARGB GetBorderColor(int& iColorType) { + return GetColor(iColorType, "BC"); + } + inline FX_FLOAT GetOriginalBorderColor(int index) { + return GetOriginalColor(index, "BC"); + } + inline void GetOriginalBorderColor(int& iColorType, FX_FLOAT fc[4]) { + GetOriginalColor(iColorType, fc, "BC"); + } + inline FX_ARGB GetBackgroundColor(int& iColorType) { + return GetColor(iColorType, "BG"); + } - inline CFX_WideString GetDownCaption() - { - return GetCaption("AC"); - } + inline FX_FLOAT GetOriginalBackgroundColor(int index) { + return GetOriginalColor(index, "BG"); + } + inline void GetOriginalBackgroundColor(int& iColorType, FX_FLOAT fc[4]) { + GetOriginalColor(iColorType, fc, "BG"); + } + inline CFX_WideString GetNormalCaption() { return GetCaption("CA"); } + inline CFX_WideString GetRolloverCaption() { return GetCaption("RC"); } - inline CPDF_Stream* GetNormalIcon() - { - return GetIcon("I"); - } + inline CFX_WideString GetDownCaption() { return GetCaption("AC"); } + inline CPDF_Stream* GetNormalIcon() { return GetIcon("I"); } + inline CPDF_Stream* GetRolloverIcon() { return GetIcon("RI"); } + inline CPDF_Stream* GetDownIcon() { return GetIcon("IX"); } - inline CPDF_Stream* GetRolloverIcon() - { - return GetIcon("RI"); - } + CPDF_IconFit GetIconFit(); + int GetTextPosition(); + CPDF_Action GetAction(); + CPDF_AAction GetAdditionalAction(); - inline CPDF_Stream* GetDownIcon() - { - return GetIcon("IX"); - } + CPDF_DefaultAppearance GetDefaultAppearance(); + CPDF_Font* GetDefaultControlFont(); + int GetControlAlignment(); + protected: + CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict); - CPDF_IconFit GetIconFit(); + CFX_ByteString GetOnStateName(); + void SetOnStateName(const CFX_ByteString& csOn); + void CheckControl(FX_BOOL bChecked); + FX_ARGB GetColor(int& iColorType, CFX_ByteString csEntry); - int GetTextPosition(); + FX_FLOAT GetOriginalColor(int index, CFX_ByteString csEntry); + void GetOriginalColor(int& iColorType, + FX_FLOAT fc[4], + CFX_ByteString csEntry); + CFX_WideString GetCaption(CFX_ByteString csEntry); + CPDF_Stream* GetIcon(CFX_ByteString csEntry); - CPDF_Action GetAction(); + CPDF_ApSettings GetMK(FX_BOOL bCreate); + CPDF_InterForm* m_pForm; + CPDF_FormField* m_pField; + CPDF_Dictionary* m_pWidgetDict; + friend class CPDF_InterForm; + friend class CPDF_FormField; +}; +class CPDF_FormNotify { + public: + virtual ~CPDF_FormNotify() {} - CPDF_AAction GetAdditionalAction(); - - - - - CPDF_DefaultAppearance GetDefaultAppearance(); - - CPDF_Font* GetDefaultControlFont(); - - - - - int GetControlAlignment(); - -protected: - - CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict); - - CFX_ByteString GetOnStateName(); - - void SetOnStateName(const CFX_ByteString& csOn); - - void CheckControl(FX_BOOL bChecked); - - FX_ARGB GetColor(int& iColorType, CFX_ByteString csEntry); + virtual int BeforeValueChange(const CPDF_FormField* pField, + CFX_WideString& csValue) { + return 0; + } - FX_FLOAT GetOriginalColor(int index, CFX_ByteString csEntry); + virtual int AfterValueChange(const CPDF_FormField* pField) { return 0; } - void GetOriginalColor(int& iColorType, FX_FLOAT fc[4], CFX_ByteString csEntry); + virtual int BeforeSelectionChange(const CPDF_FormField* pField, + CFX_WideString& csValue) { + return 0; + } - CFX_WideString GetCaption(CFX_ByteString csEntry); + virtual int AfterSelectionChange(const CPDF_FormField* pField) { return 0; } - CPDF_Stream* GetIcon(CFX_ByteString csEntry); + virtual int AfterCheckedStatusChange(const CPDF_FormField* pField, + const CFX_ByteArray& statusArray) { + return 0; + } - CPDF_ApSettings GetMK(FX_BOOL bCreate); + virtual int BeforeFormReset(const CPDF_InterForm* pForm) { return 0; } - CPDF_InterForm* m_pForm; + virtual int AfterFormReset(const CPDF_InterForm* pForm) { return 0; } - CPDF_FormField* m_pField; + virtual int BeforeFormImportData(const CPDF_InterForm* pForm) { return 0; } - CPDF_Dictionary* m_pWidgetDict; - friend class CPDF_InterForm; - friend class CPDF_FormField; -}; -class CPDF_FormNotify -{ -public: - - virtual ~CPDF_FormNotify() {} - - virtual int BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue) - { - return 0; - } - - virtual int AfterValueChange(const CPDF_FormField* pField) - { - return 0; - } - - virtual int BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue) - { - return 0; - } - - virtual int AfterSelectionChange(const CPDF_FormField* pField) - { - return 0; - } - - virtual int AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray) - { - return 0; - } - - virtual int BeforeFormReset(const CPDF_InterForm* pForm) - { - return 0; - } - - virtual int AfterFormReset(const CPDF_InterForm* pForm) - { - return 0; - } - - virtual int BeforeFormImportData(const CPDF_InterForm* pForm) - { - return 0; - } - - virtual int AfterFormImportData(const CPDF_InterForm* pForm) - { - return 0; - } + virtual int AfterFormImportData(const CPDF_InterForm* pForm) { return 0; } }; -FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); -class CPDF_PageLabel -{ -public: - - CPDF_PageLabel(CPDF_Document* pDocument) - { - m_pDocument = pDocument; - } - +FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); +class CPDF_PageLabel { + public: + CPDF_PageLabel(CPDF_Document* pDocument) { m_pDocument = pDocument; } - CFX_WideString GetLabel(int nPage) const; + CFX_WideString GetLabel(int nPage) const; - int32_t GetPageByLabel(const CFX_ByteStringC& bsLabel) const; + int32_t GetPageByLabel(const CFX_ByteStringC& bsLabel) const; + int32_t GetPageByLabel(const CFX_WideStringC& wsLabel) const; - int32_t GetPageByLabel(const CFX_WideStringC& wsLabel) const; - -protected: - CPDF_Document* m_pDocument; + protected: + CPDF_Document* m_pDocument; }; -class CPDF_Metadata -{ -public: - - CPDF_Metadata(); - - - ~CPDF_Metadata(); +class CPDF_Metadata { + public: + CPDF_Metadata(); - void LoadDoc(CPDF_Document *pDoc); + ~CPDF_Metadata(); + void LoadDoc(CPDF_Document* pDoc); - int32_t GetString(const CFX_ByteStringC& bsItem, CFX_WideString &wsStr); + int32_t GetString(const CFX_ByteStringC& bsItem, CFX_WideString& wsStr); - CXML_Element* GetRoot() const; + CXML_Element* GetRoot() const; - CXML_Element* GetRDF() const; + CXML_Element* GetRDF() const; -protected: - void* m_pData; + protected: + void* m_pData; }; -class CPDF_ViewerPreferences -{ -public: +class CPDF_ViewerPreferences { + public: + CPDF_ViewerPreferences(CPDF_Document* pDoc); - CPDF_ViewerPreferences(CPDF_Document *pDoc); + ~CPDF_ViewerPreferences(); + FX_BOOL IsDirectionR2L() const; - ~CPDF_ViewerPreferences(); + FX_BOOL PrintScaling() const; + int32_t NumCopies() const; - FX_BOOL IsDirectionR2L() const; + CPDF_Array* PrintPageRange() const; - FX_BOOL PrintScaling() const; + CFX_ByteString Duplex() const; - int32_t NumCopies() const; - - CPDF_Array* PrintPageRange() const; - - CFX_ByteString Duplex() const; - -protected: - CPDF_Document* m_pDoc; + protected: + CPDF_Document* m_pDoc; }; -class CPDF_ApSettings -{ -public: - - CPDF_ApSettings(CPDF_Dictionary* pDict = NULL) - { - m_pDict = pDict; - } - - operator CPDF_Dictionary* () const - { - return m_pDict; - } - - FX_BOOL HasMKEntry(const CFX_ByteStringC& csEntry); - - - - int GetRotation(); - - - - - inline FX_ARGB GetBorderColor(int& iColorType) - { - return GetColor(iColorType, FX_BSTRC("BC")); - } - - inline FX_FLOAT GetOriginalBorderColor(int index) - { - return GetOriginalColor(index, FX_BSTRC("BC")); - } - - inline void GetOriginalBorderColor(int& iColorType, FX_FLOAT fc[4]) - { - GetOriginalColor(iColorType, fc, FX_BSTRC("BC")); - } - - - - - inline FX_ARGB GetBackgroundColor(int& iColorType) - { - return GetColor(iColorType, FX_BSTRC("BG")); - } - - inline FX_FLOAT GetOriginalBackgroundColor(int index) - { - return GetOriginalColor(index, FX_BSTRC("BG")); - } - - inline void GetOriginalBackgroundColor(int& iColorType, FX_FLOAT fc[4]) - { - GetOriginalColor(iColorType, fc, FX_BSTRC("BG")); - } - - - - - inline CFX_WideString GetNormalCaption() - { - return GetCaption(FX_BSTRC("CA")); - } - - - - - inline CFX_WideString GetRolloverCaption() - { - return GetCaption(FX_BSTRC("RC")); - } - - - - - inline CFX_WideString GetDownCaption() - { - return GetCaption(FX_BSTRC("AC")); - } - - - +class CPDF_ApSettings { + public: + CPDF_ApSettings(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; } - inline CPDF_Stream* GetNormalIcon() - { - return GetIcon(FX_BSTRC("I")); - } + operator CPDF_Dictionary*() const { return m_pDict; } + FX_BOOL HasMKEntry(const CFX_ByteStringC& csEntry); + int GetRotation(); + inline FX_ARGB GetBorderColor(int& iColorType) { + return GetColor(iColorType, FX_BSTRC("BC")); + } - inline CPDF_Stream* GetRolloverIcon() - { - return GetIcon(FX_BSTRC("RI")); - } + inline FX_FLOAT GetOriginalBorderColor(int index) { + return GetOriginalColor(index, FX_BSTRC("BC")); + } + inline void GetOriginalBorderColor(int& iColorType, FX_FLOAT fc[4]) { + GetOriginalColor(iColorType, fc, FX_BSTRC("BC")); + } + inline FX_ARGB GetBackgroundColor(int& iColorType) { + return GetColor(iColorType, FX_BSTRC("BG")); + } + inline FX_FLOAT GetOriginalBackgroundColor(int index) { + return GetOriginalColor(index, FX_BSTRC("BG")); + } - inline CPDF_Stream* GetDownIcon() - { - return GetIcon(FX_BSTRC("IX")); - } + inline void GetOriginalBackgroundColor(int& iColorType, FX_FLOAT fc[4]) { + GetOriginalColor(iColorType, fc, FX_BSTRC("BG")); + } + inline CFX_WideString GetNormalCaption() { + return GetCaption(FX_BSTRC("CA")); + } + inline CFX_WideString GetRolloverCaption() { + return GetCaption(FX_BSTRC("RC")); + } + inline CFX_WideString GetDownCaption() { return GetCaption(FX_BSTRC("AC")); } - CPDF_IconFit GetIconFit(); + inline CPDF_Stream* GetNormalIcon() { return GetIcon(FX_BSTRC("I")); } + inline CPDF_Stream* GetRolloverIcon() { return GetIcon(FX_BSTRC("RI")); } + inline CPDF_Stream* GetDownIcon() { return GetIcon(FX_BSTRC("IX")); } + CPDF_IconFit GetIconFit(); - int GetTextPosition(); + int GetTextPosition(); - CPDF_Dictionary* m_pDict; -protected: + CPDF_Dictionary* m_pDict; - FX_ARGB GetColor(int& iColorType, const CFX_ByteStringC& csEntry); + protected: + FX_ARGB GetColor(int& iColorType, const CFX_ByteStringC& csEntry); - FX_FLOAT GetOriginalColor(int index, const CFX_ByteStringC& csEntry); + FX_FLOAT GetOriginalColor(int index, const CFX_ByteStringC& csEntry); - void GetOriginalColor(int& iColorType, FX_FLOAT fc[4], const CFX_ByteStringC& csEntry); + void GetOriginalColor(int& iColorType, + FX_FLOAT fc[4], + const CFX_ByteStringC& csEntry); - CFX_WideString GetCaption(const CFX_ByteStringC& csEntry); + CFX_WideString GetCaption(const CFX_ByteStringC& csEntry); - CPDF_Stream* GetIcon(const CFX_ByteStringC& csEntry); - friend class CPDF_FormControl; + CPDF_Stream* GetIcon(const CFX_ByteStringC& csEntry); + friend class CPDF_FormControl; }; #endif // CORE_INCLUDE_FPDFDOC_FPDF_DOC_H_ diff --git a/core/include/fpdfdoc/fpdf_tagged.h b/core/include/fpdfdoc/fpdf_tagged.h index 706f5c04d7..3de6041dc1 100644 --- a/core/include/fpdfdoc/fpdf_tagged.h +++ b/core/include/fpdfdoc/fpdf_tagged.h @@ -14,89 +14,93 @@ class CPDF_StructTree; class IPDF_ReflowedPage; struct CPDF_StructKid; -class CPDF_StructTree -{ -public: +class CPDF_StructTree { + public: + static CPDF_StructTree* LoadDoc(const CPDF_Document* pDoc); - static CPDF_StructTree* LoadDoc(const CPDF_Document* pDoc); + static CPDF_StructTree* LoadPage(const CPDF_Document* pDoc, + const CPDF_Dictionary* pPageDict); - static CPDF_StructTree* LoadPage(const CPDF_Document* pDoc, const CPDF_Dictionary* pPageDict); + virtual ~CPDF_StructTree() {} - virtual ~CPDF_StructTree() {} + virtual int CountTopElements() const = 0; - virtual int CountTopElements() const = 0; - - virtual CPDF_StructElement* GetTopElement(int i) const = 0; + virtual CPDF_StructElement* GetTopElement(int i) const = 0; }; struct CPDF_StructKid { - enum { - Invalid, - Element, - PageContent, - StreamContent, - Object - } m_Type; - - union { - struct { - - CPDF_StructElement* m_pElement; - - CPDF_Dictionary* m_pDict; - } m_Element; - struct { + enum { Invalid, Element, PageContent, StreamContent, Object } m_Type; - FX_DWORD m_PageObjNum; + union { + struct { + CPDF_StructElement* m_pElement; - FX_DWORD m_ContentId; - } m_PageContent; - struct { + CPDF_Dictionary* m_pDict; + } m_Element; + struct { + FX_DWORD m_PageObjNum; - FX_DWORD m_PageObjNum; + FX_DWORD m_ContentId; + } m_PageContent; + struct { + FX_DWORD m_PageObjNum; - FX_DWORD m_ContentId; + FX_DWORD m_ContentId; - FX_DWORD m_RefObjNum; - } m_StreamContent; - struct { + FX_DWORD m_RefObjNum; + } m_StreamContent; + struct { + FX_DWORD m_PageObjNum; - FX_DWORD m_PageObjNum; - - FX_DWORD m_RefObjNum; - } m_Object; - }; + FX_DWORD m_RefObjNum; + } m_Object; + }; }; -class CPDF_StructElement -{ -public: - virtual ~CPDF_StructElement() { } - - virtual CPDF_StructTree* GetTree() const = 0; - - virtual const CFX_ByteString& GetType() const = 0; - - virtual CPDF_StructElement* GetParent() const = 0; +class CPDF_StructElement { + public: + virtual ~CPDF_StructElement() {} - virtual CPDF_Dictionary * GetDict() const = 0; + virtual CPDF_StructTree* GetTree() const = 0; - virtual int CountKids() const = 0; + virtual const CFX_ByteString& GetType() const = 0; - virtual const CPDF_StructKid& GetKid(int index) const = 0; + virtual CPDF_StructElement* GetParent() const = 0; - virtual CFX_PtrArray* GetObjectArray() = 0; + virtual CPDF_Dictionary* GetDict() const = 0; - virtual CPDF_Object* GetAttr(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_BOOL bInheritable = FALSE, FX_FLOAT fLevel = 0.0F) = 0; + virtual int CountKids() const = 0; + virtual const CPDF_StructKid& GetKid(int index) const = 0; + virtual CFX_PtrArray* GetObjectArray() = 0; - virtual CFX_ByteString GetName(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, const CFX_ByteStringC& default_value, FX_BOOL bInheritable = FALSE, int subindex = -1) = 0; + virtual CPDF_Object* GetAttr(const CFX_ByteStringC& owner, + const CFX_ByteStringC& name, + FX_BOOL bInheritable = FALSE, + FX_FLOAT fLevel = 0.0F) = 0; - virtual FX_ARGB GetColor(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_ARGB default_value, FX_BOOL bInheritable = FALSE, int subindex = -1) = 0; + virtual CFX_ByteString GetName(const CFX_ByteStringC& owner, + const CFX_ByteStringC& name, + const CFX_ByteStringC& default_value, + FX_BOOL bInheritable = FALSE, + int subindex = -1) = 0; - virtual FX_FLOAT GetNumber(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_FLOAT default_value, FX_BOOL bInheritable = FALSE, int subindex = -1) = 0; + virtual FX_ARGB GetColor(const CFX_ByteStringC& owner, + const CFX_ByteStringC& name, + FX_ARGB default_value, + FX_BOOL bInheritable = FALSE, + int subindex = -1) = 0; - virtual int GetInteger(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, int default_value, FX_BOOL bInheritable = FALSE, int subindex = -1) = 0; + virtual FX_FLOAT GetNumber(const CFX_ByteStringC& owner, + const CFX_ByteStringC& name, + FX_FLOAT default_value, + FX_BOOL bInheritable = FALSE, + int subindex = -1) = 0; + virtual int GetInteger(const CFX_ByteStringC& owner, + const CFX_ByteStringC& name, + int default_value, + FX_BOOL bInheritable = FALSE, + int subindex = -1) = 0; }; #endif // CORE_INCLUDE_FPDFDOC_FPDF_TAGGED_H_ diff --git a/core/include/fpdfdoc/fpdf_vt.h b/core/include/fpdfdoc/fpdf_vt.h index 4baba41348..62a6019793 100644 --- a/core/include/fpdfdoc/fpdf_vt.h +++ b/core/include/fpdfdoc/fpdf_vt.h @@ -20,434 +20,443 @@ struct CPVT_WordPlace; struct CPVT_WordRange; struct CPVT_WordPlace { - - CPVT_WordPlace() : nSecIndex(-1), nLineIndex(-1), nWordIndex(-1) - { + CPVT_WordPlace() : nSecIndex(-1), nLineIndex(-1), nWordIndex(-1) {} + + CPVT_WordPlace(int32_t other_nSecIndex, + int32_t other_nLineIndex, + int32_t other_nWordIndex) { + nSecIndex = other_nSecIndex; + nLineIndex = other_nLineIndex; + nWordIndex = other_nWordIndex; + } + + void Default() { nSecIndex = nLineIndex = nWordIndex = -1; } + + FX_BOOL operator==(const CPVT_WordPlace& wp) const { + return wp.nSecIndex == nSecIndex && wp.nLineIndex == nLineIndex && + wp.nWordIndex == nWordIndex; + } + + FX_BOOL operator!=(const CPVT_WordPlace& wp) const { + return wp.nSecIndex != nSecIndex || wp.nLineIndex != nLineIndex || + wp.nWordIndex != nWordIndex; + } + + inline int32_t WordCmp(const CPVT_WordPlace& wp) const { + if (nSecIndex > wp.nSecIndex) { + return 1; } - - CPVT_WordPlace(int32_t other_nSecIndex, - int32_t other_nLineIndex, - int32_t other_nWordIndex) - { - nSecIndex = other_nSecIndex; - nLineIndex = other_nLineIndex; - nWordIndex = other_nWordIndex; + if (nSecIndex < wp.nSecIndex) { + return -1; } - - void Default() - { - nSecIndex = nLineIndex = nWordIndex = -1; + if (nLineIndex > wp.nLineIndex) { + return 1; } - - FX_BOOL operator == (const CPVT_WordPlace & wp) const - { - return wp.nSecIndex == nSecIndex && wp.nLineIndex == nLineIndex && wp.nWordIndex == nWordIndex; + if (nLineIndex < wp.nLineIndex) { + return -1; } - - FX_BOOL operator != (const CPVT_WordPlace & wp) const - { - return wp.nSecIndex != nSecIndex || wp.nLineIndex != nLineIndex || wp.nWordIndex != nWordIndex; + if (nWordIndex > wp.nWordIndex) { + return 1; } - - inline int32_t WordCmp(const CPVT_WordPlace & wp) const - { - if (nSecIndex > wp.nSecIndex) { - return 1; - } - if (nSecIndex < wp.nSecIndex) { - return -1; - } - if (nLineIndex > wp.nLineIndex) { - return 1; - } - if (nLineIndex < wp.nLineIndex) { - return -1; - } - if (nWordIndex > wp.nWordIndex) { - return 1; - } - if (nWordIndex < wp.nWordIndex) { - return -1; - } - return 0; + if (nWordIndex < wp.nWordIndex) { + return -1; } + return 0; + } - inline int32_t LineCmp(const CPVT_WordPlace & wp) const - { - if (nSecIndex > wp.nSecIndex) { - return 1; - } - if (nSecIndex < wp.nSecIndex) { - return -1; - } - if (nLineIndex > wp.nLineIndex) { - return 1; - } - if (nLineIndex < wp.nLineIndex) { - return -1; - } - return 0; + inline int32_t LineCmp(const CPVT_WordPlace& wp) const { + if (nSecIndex > wp.nSecIndex) { + return 1; } - - inline int32_t SecCmp(const CPVT_WordPlace & wp) const - { - if (nSecIndex > wp.nSecIndex) { - return 1; - } - if (nSecIndex < wp.nSecIndex) { - return -1; - } - return 0; + if (nSecIndex < wp.nSecIndex) { + return -1; } - - int32_t nSecIndex; - - int32_t nLineIndex; - - int32_t nWordIndex; -}; -struct CPVT_WordRange { - - CPVT_WordRange() - { - } - - CPVT_WordRange(const CPVT_WordPlace & begin, const CPVT_WordPlace & end) - { - Set(begin, end); + if (nLineIndex > wp.nLineIndex) { + return 1; } - - void Default() - { - BeginPos.Default(); - EndPos.Default(); + if (nLineIndex < wp.nLineIndex) { + return -1; } + return 0; + } - void Set(const CPVT_WordPlace & begin, const CPVT_WordPlace & end) - { - BeginPos = begin; - EndPos = end; - SwapWordPlace(); + inline int32_t SecCmp(const CPVT_WordPlace& wp) const { + if (nSecIndex > wp.nSecIndex) { + return 1; } - - void SetBeginPos(const CPVT_WordPlace & begin) - { - BeginPos = begin; - SwapWordPlace(); + if (nSecIndex < wp.nSecIndex) { + return -1; } + return 0; + } - void SetEndPos(const CPVT_WordPlace & end) - { - EndPos = end; - SwapWordPlace(); - } + int32_t nSecIndex; - FX_BOOL IsExist() const - { - return BeginPos != EndPos; - } - - FX_BOOL operator != (const CPVT_WordRange & wr) const - { - return wr.BeginPos != BeginPos || wr.EndPos != EndPos; - } - - void SwapWordPlace() - { - if (BeginPos.WordCmp(EndPos) > 0) { - CPVT_WordPlace place = EndPos; - EndPos = BeginPos; - BeginPos = place; - } - } + int32_t nLineIndex; - CPVT_WordPlace BeginPos; - - CPVT_WordPlace EndPos; + int32_t nWordIndex; }; -struct CPVT_SecProps { - - CPVT_SecProps() : fLineLeading(0.0f), fLineIndent(0.0f), nAlignment(0) - { - } - - CPVT_SecProps(FX_FLOAT lineLeading, FX_FLOAT lineIndent, int32_t alignment) : - fLineLeading(lineLeading), fLineIndent(lineIndent), nAlignment(alignment) - { - } - - CPVT_SecProps(const CPVT_SecProps & other) : - fLineLeading(other.fLineLeading), fLineIndent(other.fLineIndent), nAlignment(other.nAlignment) - { +struct CPVT_WordRange { + CPVT_WordRange() {} + + CPVT_WordRange(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) { + Set(begin, end); + } + + void Default() { + BeginPos.Default(); + EndPos.Default(); + } + + void Set(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) { + BeginPos = begin; + EndPos = end; + SwapWordPlace(); + } + + void SetBeginPos(const CPVT_WordPlace& begin) { + BeginPos = begin; + SwapWordPlace(); + } + + void SetEndPos(const CPVT_WordPlace& end) { + EndPos = end; + SwapWordPlace(); + } + + FX_BOOL IsExist() const { return BeginPos != EndPos; } + + FX_BOOL operator!=(const CPVT_WordRange& wr) const { + return wr.BeginPos != BeginPos || wr.EndPos != EndPos; + } + + void SwapWordPlace() { + if (BeginPos.WordCmp(EndPos) > 0) { + CPVT_WordPlace place = EndPos; + EndPos = BeginPos; + BeginPos = place; } + } - FX_FLOAT fLineLeading; - - FX_FLOAT fLineIndent; + CPVT_WordPlace BeginPos; - int32_t nAlignment; + CPVT_WordPlace EndPos; }; -struct CPVT_WordProps { - - CPVT_WordProps() : nFontIndex(-1), fFontSize(0.0f), dwWordColor(0), nScriptType(0), nWordStyle(0), - fCharSpace(0.0f), nHorzScale(0) - { - } - - CPVT_WordProps(int32_t fontIndex, FX_FLOAT fontSize, FX_COLORREF wordColor = 0, int32_t scriptType = 0, int32_t wordStyle = 0, - FX_FLOAT charSpace = 0, int32_t horzScale = 100) : - nFontIndex(fontIndex), fFontSize(fontSize), dwWordColor(wordColor), nScriptType(scriptType), - nWordStyle(wordStyle), fCharSpace(charSpace), nHorzScale(horzScale) - { - } - - CPVT_WordProps(const CPVT_WordProps & other) : - nFontIndex(other.nFontIndex), fFontSize(other.fFontSize), dwWordColor(other.dwWordColor), - nScriptType(other.nScriptType), nWordStyle(other.nWordStyle), fCharSpace(other.fCharSpace), - nHorzScale(other.nHorzScale) - { - } +struct CPVT_SecProps { + CPVT_SecProps() : fLineLeading(0.0f), fLineIndent(0.0f), nAlignment(0) {} - int32_t nFontIndex; + CPVT_SecProps(FX_FLOAT lineLeading, FX_FLOAT lineIndent, int32_t alignment) + : fLineLeading(lineLeading), + fLineIndent(lineIndent), + nAlignment(alignment) {} - FX_FLOAT fFontSize; + CPVT_SecProps(const CPVT_SecProps& other) + : fLineLeading(other.fLineLeading), + fLineIndent(other.fLineIndent), + nAlignment(other.nAlignment) {} - FX_COLORREF dwWordColor; + FX_FLOAT fLineLeading; - int32_t nScriptType; + FX_FLOAT fLineIndent; - int32_t nWordStyle; - - FX_FLOAT fCharSpace; - - int32_t nHorzScale; + int32_t nAlignment; +}; +struct CPVT_WordProps { + CPVT_WordProps() + : nFontIndex(-1), + fFontSize(0.0f), + dwWordColor(0), + nScriptType(0), + nWordStyle(0), + fCharSpace(0.0f), + nHorzScale(0) {} + + CPVT_WordProps(int32_t fontIndex, + FX_FLOAT fontSize, + FX_COLORREF wordColor = 0, + int32_t scriptType = 0, + int32_t wordStyle = 0, + FX_FLOAT charSpace = 0, + int32_t horzScale = 100) + : nFontIndex(fontIndex), + fFontSize(fontSize), + dwWordColor(wordColor), + nScriptType(scriptType), + nWordStyle(wordStyle), + fCharSpace(charSpace), + nHorzScale(horzScale) {} + + CPVT_WordProps(const CPVT_WordProps& other) + : nFontIndex(other.nFontIndex), + fFontSize(other.fFontSize), + dwWordColor(other.dwWordColor), + nScriptType(other.nScriptType), + nWordStyle(other.nWordStyle), + fCharSpace(other.fCharSpace), + nHorzScale(other.nHorzScale) {} + + int32_t nFontIndex; + + FX_FLOAT fFontSize; + + FX_COLORREF dwWordColor; + + int32_t nScriptType; + + int32_t nWordStyle; + + FX_FLOAT fCharSpace; + + int32_t nHorzScale; }; struct CPVT_Word { + CPVT_Word() + : Word(0), + nCharset(0), + ptWord(0, 0), + fAscent(0.0f), + fDescent(0.0f), + fWidth(0.0f), + fFontSize(0), + WordProps() {} - CPVT_Word() : Word(0), nCharset(0), ptWord(0, 0), fAscent(0.0f), fDescent(0.0f), fWidth(0.0f), - fFontSize(0), WordProps() - { - } - - FX_WORD Word; + FX_WORD Word; - int32_t nCharset; + int32_t nCharset; - CPVT_WordPlace WordPlace; + CPVT_WordPlace WordPlace; - CPDF_Point ptWord; + CPDF_Point ptWord; - FX_FLOAT fAscent; + FX_FLOAT fAscent; - FX_FLOAT fDescent; + FX_FLOAT fDescent; - FX_FLOAT fWidth; + FX_FLOAT fWidth; - int32_t nFontIndex; + int32_t nFontIndex; - FX_FLOAT fFontSize; + FX_FLOAT fFontSize; - CPVT_WordProps WordProps; + CPVT_WordProps WordProps; }; struct CPVT_Line { + CPVT_Line() + : ptLine(0, 0), fLineWidth(0.0f), fLineAscent(0.0f), fLineDescent(0.0f) {} - CPVT_Line() : ptLine(0, 0), fLineWidth(0.0f), fLineAscent(0.0f), fLineDescent(0.0f) - { - } + CPVT_WordPlace lineplace; - CPVT_WordPlace lineplace; + CPVT_WordPlace lineEnd; - CPVT_WordPlace lineEnd; + CPDF_Point ptLine; - CPDF_Point ptLine; + FX_FLOAT fLineWidth; - FX_FLOAT fLineWidth; + FX_FLOAT fLineAscent; - FX_FLOAT fLineAscent; - - FX_FLOAT fLineDescent; + FX_FLOAT fLineDescent; }; struct CPVT_Section { + CPVT_WordPlace secplace; - CPVT_WordPlace secplace; - - CPDF_Rect rcSection; + CPDF_Rect rcSection; - CPVT_SecProps SecProps; + CPVT_SecProps SecProps; - CPVT_WordProps WordProps; + CPVT_WordProps WordProps; }; -class IPDF_VariableText_Provider -{ -public: - virtual ~IPDF_VariableText_Provider() { } +class IPDF_VariableText_Provider { + public: + virtual ~IPDF_VariableText_Provider() {} - virtual int32_t GetCharWidth(int32_t nFontIndex, FX_WORD word, int32_t nWordStyle) = 0; + virtual int32_t GetCharWidth(int32_t nFontIndex, + FX_WORD word, + int32_t nWordStyle) = 0; - virtual int32_t GetTypeAscent(int32_t nFontIndex) = 0; + virtual int32_t GetTypeAscent(int32_t nFontIndex) = 0; - virtual int32_t GetTypeDescent(int32_t nFontIndex) = 0; + virtual int32_t GetTypeDescent(int32_t nFontIndex) = 0; - virtual int32_t GetWordFontIndex(FX_WORD word, int32_t charset, int32_t nFontIndex) = 0; + virtual int32_t GetWordFontIndex(FX_WORD word, + int32_t charset, + int32_t nFontIndex) = 0; - virtual FX_BOOL IsLatinWord(FX_WORD word) = 0; + virtual FX_BOOL IsLatinWord(FX_WORD word) = 0; - virtual int32_t GetDefaultFontIndex() = 0; + virtual int32_t GetDefaultFontIndex() = 0; }; -class IPDF_VariableText_Iterator -{ -public: - virtual ~IPDF_VariableText_Iterator() { } +class IPDF_VariableText_Iterator { + public: + virtual ~IPDF_VariableText_Iterator() {} - virtual FX_BOOL NextWord() = 0; + virtual FX_BOOL NextWord() = 0; - virtual FX_BOOL PrevWord() = 0; + virtual FX_BOOL PrevWord() = 0; - virtual FX_BOOL NextLine() = 0; + virtual FX_BOOL NextLine() = 0; - virtual FX_BOOL PrevLine() = 0; + virtual FX_BOOL PrevLine() = 0; - virtual FX_BOOL NextSection() = 0; + virtual FX_BOOL NextSection() = 0; - virtual FX_BOOL PrevSection() = 0; + virtual FX_BOOL PrevSection() = 0; - virtual FX_BOOL GetWord(CPVT_Word & word) const = 0; + virtual FX_BOOL GetWord(CPVT_Word& word) const = 0; - virtual FX_BOOL SetWord(const CPVT_Word & word) = 0; + virtual FX_BOOL SetWord(const CPVT_Word& word) = 0; - virtual FX_BOOL GetLine(CPVT_Line & line) const = 0; + virtual FX_BOOL GetLine(CPVT_Line& line) const = 0; - virtual FX_BOOL GetSection(CPVT_Section & section) const = 0; + virtual FX_BOOL GetSection(CPVT_Section& section) const = 0; - virtual FX_BOOL SetSection(const CPVT_Section & section) = 0; + virtual FX_BOOL SetSection(const CPVT_Section& section) = 0; - virtual void SetAt(int32_t nWordIndex) = 0; + virtual void SetAt(int32_t nWordIndex) = 0; - virtual void SetAt(const CPVT_WordPlace & place) = 0; + virtual void SetAt(const CPVT_WordPlace& place) = 0; - virtual const CPVT_WordPlace & GetAt() const = 0; + virtual const CPVT_WordPlace& GetAt() const = 0; }; -class IPDF_VariableText -{ -public: - static IPDF_VariableText* NewVariableText(); +class IPDF_VariableText { + public: + static IPDF_VariableText* NewVariableText(); - static void DelVariableText(IPDF_VariableText* pVT); + static void DelVariableText(IPDF_VariableText* pVT); - virtual IPDF_VariableText_Provider* SetProvider(IPDF_VariableText_Provider * pProvider) = 0; + virtual IPDF_VariableText_Provider* SetProvider( + IPDF_VariableText_Provider* pProvider) = 0; - virtual IPDF_VariableText_Iterator* GetIterator() = 0; + virtual IPDF_VariableText_Iterator* GetIterator() = 0; - virtual void SetPlateRect(const CPDF_Rect & rect) = 0; + virtual void SetPlateRect(const CPDF_Rect& rect) = 0; - virtual void SetAlignment(int32_t nFormat = 0) = 0; + virtual void SetAlignment(int32_t nFormat = 0) = 0; - virtual void SetPasswordChar(FX_WORD wSubWord = '*') = 0; + virtual void SetPasswordChar(FX_WORD wSubWord = '*') = 0; - virtual void SetLimitChar(int32_t nLimitChar = 0) = 0; + virtual void SetLimitChar(int32_t nLimitChar = 0) = 0; - virtual void SetCharArray(int32_t nCharArray = 0) = 0; + virtual void SetCharArray(int32_t nCharArray = 0) = 0; - virtual void SetCharSpace(FX_FLOAT fCharSpace = 0.0f) = 0; + virtual void SetCharSpace(FX_FLOAT fCharSpace = 0.0f) = 0; - virtual void SetHorzScale(int32_t nHorzScale = 100) = 0; + virtual void SetHorzScale(int32_t nHorzScale = 100) = 0; - virtual void SetMultiLine(FX_BOOL bMultiLine = TRUE) = 0; + virtual void SetMultiLine(FX_BOOL bMultiLine = TRUE) = 0; - virtual void SetAutoReturn(FX_BOOL bAuto = TRUE) = 0; + virtual void SetAutoReturn(FX_BOOL bAuto = TRUE) = 0; - virtual void SetAutoFontSize(FX_BOOL bAuto = TRUE) = 0; + virtual void SetAutoFontSize(FX_BOOL bAuto = TRUE) = 0; - virtual void SetFontSize(FX_FLOAT fFontSize) = 0; + virtual void SetFontSize(FX_FLOAT fFontSize) = 0; - virtual void SetLineLeading(FX_FLOAT fLineLeading) = 0; + virtual void SetLineLeading(FX_FLOAT fLineLeading) = 0; - virtual void SetRichText(FX_BOOL bRichText) = 0; + virtual void SetRichText(FX_BOOL bRichText) = 0; - virtual void Initialize() = 0; + virtual void Initialize() = 0; - virtual FX_BOOL IsValid() const = 0; + virtual FX_BOOL IsValid() const = 0; - virtual FX_BOOL IsRichText() const = 0; + virtual FX_BOOL IsRichText() const = 0; - virtual void RearrangeAll() = 0; + virtual void RearrangeAll() = 0; - virtual void RearrangePart(const CPVT_WordRange & PlaceRange) = 0; + virtual void RearrangePart(const CPVT_WordRange& PlaceRange) = 0; - virtual void ResetAll() = 0; + virtual void ResetAll() = 0; - virtual void SetText(const FX_WCHAR* text, int32_t charset = 1, const CPVT_SecProps * pSecProps = NULL, - const CPVT_WordProps * pWordProps = NULL) = 0; + virtual void SetText(const FX_WCHAR* text, + int32_t charset = 1, + const CPVT_SecProps* pSecProps = NULL, + const CPVT_WordProps* pWordProps = NULL) = 0; - virtual CPVT_WordPlace InsertWord(const CPVT_WordPlace & place, FX_WORD word, int32_t charset = 1, - const CPVT_WordProps * pWordProps = NULL) = 0; + virtual CPVT_WordPlace InsertWord( + const CPVT_WordPlace& place, + FX_WORD word, + int32_t charset = 1, + const CPVT_WordProps* pWordProps = NULL) = 0; - virtual CPVT_WordPlace InsertSection(const CPVT_WordPlace & place, const CPVT_SecProps * pSecProps = NULL, - const CPVT_WordProps * pWordProps = NULL) = 0; + virtual CPVT_WordPlace InsertSection( + const CPVT_WordPlace& place, + const CPVT_SecProps* pSecProps = NULL, + const CPVT_WordProps* pWordProps = NULL) = 0; - virtual CPVT_WordPlace InsertText(const CPVT_WordPlace & place, const FX_WCHAR* text, int32_t charset = 1, - const CPVT_SecProps * pSecProps = NULL, const CPVT_WordProps * pWordProps = NULL) = 0; + virtual CPVT_WordPlace InsertText( + const CPVT_WordPlace& place, + const FX_WCHAR* text, + int32_t charset = 1, + const CPVT_SecProps* pSecProps = NULL, + const CPVT_WordProps* pWordProps = NULL) = 0; - virtual CPVT_WordPlace DeleteWords(const CPVT_WordRange & PlaceRange) = 0; + virtual CPVT_WordPlace DeleteWords(const CPVT_WordRange& PlaceRange) = 0; - virtual CPVT_WordPlace DeleteWord(const CPVT_WordPlace & place) = 0; + virtual CPVT_WordPlace DeleteWord(const CPVT_WordPlace& place) = 0; - virtual CPVT_WordPlace BackSpaceWord(const CPVT_WordPlace & place) = 0; + virtual CPVT_WordPlace BackSpaceWord(const CPVT_WordPlace& place) = 0; - virtual const CPDF_Rect & GetPlateRect() const = 0; + virtual const CPDF_Rect& GetPlateRect() const = 0; - virtual CPDF_Rect GetContentRect() const = 0; + virtual CPDF_Rect GetContentRect() const = 0; - virtual int32_t GetTotalWords() const = 0; + virtual int32_t GetTotalWords() const = 0; - virtual FX_FLOAT GetFontSize() const = 0; + virtual FX_FLOAT GetFontSize() const = 0; - virtual int32_t GetAlignment() const = 0; + virtual int32_t GetAlignment() const = 0; - virtual FX_WORD GetPasswordChar() const = 0; + virtual FX_WORD GetPasswordChar() const = 0; - virtual int32_t GetCharArray() const = 0; + virtual int32_t GetCharArray() const = 0; - virtual int32_t GetLimitChar() const = 0; + virtual int32_t GetLimitChar() const = 0; - virtual FX_BOOL IsMultiLine() const = 0; + virtual FX_BOOL IsMultiLine() const = 0; - virtual int32_t GetHorzScale() const = 0; + virtual int32_t GetHorzScale() const = 0; - virtual FX_FLOAT GetCharSpace() const = 0; + virtual FX_FLOAT GetCharSpace() const = 0; - virtual CPVT_WordPlace GetBeginWordPlace() const = 0; + virtual CPVT_WordPlace GetBeginWordPlace() const = 0; - virtual CPVT_WordPlace GetEndWordPlace() const = 0; + virtual CPVT_WordPlace GetEndWordPlace() const = 0; - virtual CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace & place) const = 0; + virtual CPVT_WordPlace GetPrevWordPlace( + const CPVT_WordPlace& place) const = 0; - virtual CPVT_WordPlace GetNextWordPlace(const CPVT_WordPlace & place) const = 0; + virtual CPVT_WordPlace GetNextWordPlace( + const CPVT_WordPlace& place) const = 0; - virtual CPVT_WordPlace SearchWordPlace(const CPDF_Point & point) const = 0; + virtual CPVT_WordPlace SearchWordPlace(const CPDF_Point& point) const = 0; - virtual CPVT_WordPlace GetUpWordPlace(const CPVT_WordPlace & place, const CPDF_Point & point) const = 0; + virtual CPVT_WordPlace GetUpWordPlace(const CPVT_WordPlace& place, + const CPDF_Point& point) const = 0; - virtual CPVT_WordPlace GetDownWordPlace(const CPVT_WordPlace & place, const CPDF_Point & point) const = 0; + virtual CPVT_WordPlace GetDownWordPlace(const CPVT_WordPlace& place, + const CPDF_Point& point) const = 0; - virtual CPVT_WordPlace GetLineBeginPlace(const CPVT_WordPlace & place) const = 0; + virtual CPVT_WordPlace GetLineBeginPlace( + const CPVT_WordPlace& place) const = 0; - virtual CPVT_WordPlace GetLineEndPlace(const CPVT_WordPlace & place) const = 0; + virtual CPVT_WordPlace GetLineEndPlace(const CPVT_WordPlace& place) const = 0; - virtual CPVT_WordPlace GetSectionBeginPlace(const CPVT_WordPlace & place) const = 0; + virtual CPVT_WordPlace GetSectionBeginPlace( + const CPVT_WordPlace& place) const = 0; - virtual CPVT_WordPlace GetSectionEndPlace(const CPVT_WordPlace & place) const = 0; + virtual CPVT_WordPlace GetSectionEndPlace( + const CPVT_WordPlace& place) const = 0; - virtual void UpdateWordPlace(CPVT_WordPlace & place) const = 0; + virtual void UpdateWordPlace(CPVT_WordPlace& place) const = 0; - virtual CPVT_WordPlace AjustLineHeader(const CPVT_WordPlace & place, FX_BOOL bPrevOrNext) const = 0; + virtual CPVT_WordPlace AjustLineHeader(const CPVT_WordPlace& place, + FX_BOOL bPrevOrNext) const = 0; - virtual int32_t WordPlaceToWordIndex(const CPVT_WordPlace & place) const = 0; + virtual int32_t WordPlaceToWordIndex(const CPVT_WordPlace& place) const = 0; - virtual CPVT_WordPlace WordIndexToWordPlace(int32_t index) const = 0; + virtual CPVT_WordPlace WordIndexToWordPlace(int32_t index) const = 0; -protected: - ~IPDF_VariableText() { } + protected: + ~IPDF_VariableText() {} }; #endif // CORE_INCLUDE_FPDFDOC_FPDF_VT_H_ diff --git a/core/include/fpdftext/fpdf_text.h b/core/include/fpdftext/fpdf_text.h index 04922c4b7f..eb16ca9a90 100644 --- a/core/include/fpdftext/fpdf_text.h +++ b/core/include/fpdftext/fpdf_text.h @@ -17,153 +17,168 @@ class IPDF_ReflowedPage; class IPDF_TextPage; class IPDF_TextPageFind; -#define PDF2TXT_AUTO_ROTATE 1 -#define PDF2TXT_AUTO_WIDTH 2 -#define PDF2TXT_KEEP_COLUMN 4 -#define PDF2TXT_USE_OCR 8 -#define PDF2TXT_INCLUDE_INVISIBLE 16 -void PDF_GetPageText(CFX_ByteStringArray& lines, CPDF_Document* pDoc, CPDF_Dictionary* pPage, - int iMinWidth, FX_DWORD flags); -void PDF_GetPageText_Unicode(CFX_WideStringArray& lines, CPDF_Document* pDoc, CPDF_Dictionary* pPage, - int iMinWidth, FX_DWORD flags); -void PDF_GetTextStream_Unicode(CFX_WideTextBuf& buffer, CPDF_Document* pDoc, CPDF_Dictionary* pPage, +#define PDF2TXT_AUTO_ROTATE 1 +#define PDF2TXT_AUTO_WIDTH 2 +#define PDF2TXT_KEEP_COLUMN 4 +#define PDF2TXT_USE_OCR 8 +#define PDF2TXT_INCLUDE_INVISIBLE 16 +void PDF_GetPageText(CFX_ByteStringArray& lines, + CPDF_Document* pDoc, + CPDF_Dictionary* pPage, + int iMinWidth, + FX_DWORD flags); +void PDF_GetPageText_Unicode(CFX_WideStringArray& lines, + CPDF_Document* pDoc, + CPDF_Dictionary* pPage, + int iMinWidth, + FX_DWORD flags); +void PDF_GetTextStream_Unicode(CFX_WideTextBuf& buffer, + CPDF_Document* pDoc, + CPDF_Dictionary* pPage, FX_DWORD flags); -CFX_WideString PDF_GetFirstTextLine_Unicode(CPDF_Document* pDoc, CPDF_Dictionary* pPage); -#define CHAR_ERROR -1 -#define CHAR_NORMAL 0 -#define CHAR_GENERATED 1 -#define CHAR_UNUNICODE 2 +CFX_WideString PDF_GetFirstTextLine_Unicode(CPDF_Document* pDoc, + CPDF_Dictionary* pPage); +#define CHAR_ERROR -1 +#define CHAR_NORMAL 0 +#define CHAR_GENERATED 1 +#define CHAR_UNUNICODE 2 typedef struct { - FX_WCHAR m_Unicode; - FX_WCHAR m_Charcode; - int32_t m_Flag; - FX_FLOAT m_FontSize; - FX_FLOAT m_OriginX; - FX_FLOAT m_OriginY; - CFX_FloatRect m_CharBox; - CPDF_TextObject* m_pTextObj; - CFX_AffineMatrix m_Matrix; + FX_WCHAR m_Unicode; + FX_WCHAR m_Charcode; + int32_t m_Flag; + FX_FLOAT m_FontSize; + FX_FLOAT m_OriginX; + FX_FLOAT m_OriginY; + CFX_FloatRect m_CharBox; + CPDF_TextObject* m_pTextObj; + CFX_AffineMatrix m_Matrix; } FPDF_CHAR_INFO; -typedef CFX_ArrayTemplate<CFX_FloatRect> CFX_RectArray; -#define FPDFTEXT_LRTB 0 -#define FPDFTEXT_RLTB 1 -#define FPDFTEXT_TBRL 2 -#define FPDFTEXT_LEFT -1 -#define FPDFTEXT_RIGHT 1 -#define FPDFTEXT_UP -2 -#define FPDFTEXT_DOWN 2 -#define FPDFTEXT_WRITINGMODE_UNKNOW 0 -#define FPDFTEXT_WRITINGMODE_LRTB 1 -#define FPDFTEXT_WRITINGMODE_RLTB 2 -#define FPDFTEXT_WRITINGMODE_TBRL 3 -class CPDFText_ParseOptions -{ -public: - - CPDFText_ParseOptions(); - FX_BOOL m_bGetCharCodeOnly; - FX_BOOL m_bNormalizeObjs; - FX_BOOL m_bOutputHyphen; +typedef CFX_ArrayTemplate<CFX_FloatRect> CFX_RectArray; +#define FPDFTEXT_LRTB 0 +#define FPDFTEXT_RLTB 1 +#define FPDFTEXT_TBRL 2 +#define FPDFTEXT_LEFT -1 +#define FPDFTEXT_RIGHT 1 +#define FPDFTEXT_UP -2 +#define FPDFTEXT_DOWN 2 +#define FPDFTEXT_WRITINGMODE_UNKNOW 0 +#define FPDFTEXT_WRITINGMODE_LRTB 1 +#define FPDFTEXT_WRITINGMODE_RLTB 2 +#define FPDFTEXT_WRITINGMODE_TBRL 3 +class CPDFText_ParseOptions { + public: + CPDFText_ParseOptions(); + FX_BOOL m_bGetCharCodeOnly; + FX_BOOL m_bNormalizeObjs; + FX_BOOL m_bOutputHyphen; }; -class IPDF_TextPage -{ -public: +class IPDF_TextPage { + public: + virtual ~IPDF_TextPage() {} + static IPDF_TextPage* CreateTextPage(const CPDF_Page* pPage, + CPDFText_ParseOptions ParserOptions); + static IPDF_TextPage* CreateTextPage(const CPDF_Page* pPage, int flags = 0); + static IPDF_TextPage* CreateTextPage(const CPDF_PageObjects* pObjs, + int flags = 0); + static IPDF_TextPage* CreateReflowTextPage(IPDF_ReflowedPage* pRefPage); - virtual ~IPDF_TextPage() {} - static IPDF_TextPage* CreateTextPage(const CPDF_Page* pPage, CPDFText_ParseOptions ParserOptions); - static IPDF_TextPage* CreateTextPage(const CPDF_Page* pPage, int flags = 0); - static IPDF_TextPage* CreateTextPage(const CPDF_PageObjects* pObjs, int flags = 0); - static IPDF_TextPage* CreateReflowTextPage(IPDF_ReflowedPage* pRefPage); + virtual void NormalizeObjects(FX_BOOL bNormalize) = 0; - virtual void NormalizeObjects(FX_BOOL bNormalize) = 0; + virtual FX_BOOL ParseTextPage() = 0; - virtual FX_BOOL ParseTextPage() = 0; + virtual FX_BOOL IsParsered() const = 0; + public: + virtual int CharIndexFromTextIndex(int TextIndex) const = 0; - virtual FX_BOOL IsParsered() const = 0; -public: + virtual int TextIndexFromCharIndex(int CharIndex) const = 0; - virtual int CharIndexFromTextIndex(int TextIndex) const = 0; + virtual int CountChars() const = 0; - virtual int TextIndexFromCharIndex(int CharIndex) const = 0; + virtual void GetCharInfo(int index, FPDF_CHAR_INFO& info) const = 0; + virtual void GetRectArray(int start, + int nCount, + CFX_RectArray& rectArray) const = 0; - virtual int CountChars() const = 0; + virtual int GetIndexAtPos(CPDF_Point point, + FX_FLOAT xTorelance, + FX_FLOAT yTorelance) const = 0; - virtual void GetCharInfo(int index, FPDF_CHAR_INFO & info) const = 0; + virtual int GetIndexAtPos(FX_FLOAT x, + FX_FLOAT y, + FX_FLOAT xTorelance, + FX_FLOAT yTorelance) const = 0; - virtual void GetRectArray(int start, int nCount, CFX_RectArray& rectArray) const = 0; + virtual CFX_WideString GetTextByRect(const CFX_FloatRect& rect) const = 0; + virtual void GetRectsArrayByRect(const CFX_FloatRect& rect, + CFX_RectArray& resRectArray) const = 0; + virtual int CountRects(int start, int nCount) = 0; - virtual int GetIndexAtPos(CPDF_Point point, FX_FLOAT xTorelance, FX_FLOAT yTorelance) const = 0; + virtual void GetRect(int rectIndex, + FX_FLOAT& left, + FX_FLOAT& top, + FX_FLOAT& right, + FX_FLOAT& bottom) const = 0; - virtual int GetIndexAtPos(FX_FLOAT x, FX_FLOAT y, FX_FLOAT xTorelance, FX_FLOAT yTorelance) const = 0; + virtual FX_BOOL GetBaselineRotate(int rectIndex, int& Rotate) = 0; - virtual CFX_WideString GetTextByRect(const CFX_FloatRect& rect) const = 0; + virtual FX_BOOL GetBaselineRotate(const CFX_FloatRect& rect, int& Rotate) = 0; - virtual void GetRectsArrayByRect(const CFX_FloatRect& rect, CFX_RectArray& resRectArray) const = 0; + virtual int CountBoundedSegments(FX_FLOAT left, + FX_FLOAT top, + FX_FLOAT right, + FX_FLOAT bottom, + FX_BOOL bContains = FALSE) = 0; + virtual void GetBoundedSegment(int index, int& start, int& count) const = 0; - virtual int CountRects(int start, int nCount) = 0; + virtual int GetWordBreak(int index, int direction) const = 0; - virtual void GetRect(int rectIndex, FX_FLOAT& left, FX_FLOAT& top, FX_FLOAT& right, FX_FLOAT &bottom) const = 0; - - virtual FX_BOOL GetBaselineRotate(int rectIndex, int& Rotate) = 0; - - virtual FX_BOOL GetBaselineRotate(const CFX_FloatRect& rect, int& Rotate) = 0; - - virtual int CountBoundedSegments(FX_FLOAT left, FX_FLOAT top, FX_FLOAT right, FX_FLOAT bottom, FX_BOOL bContains = FALSE) = 0; - - virtual void GetBoundedSegment(int index, int& start, int& count) const = 0; - - - virtual int GetWordBreak(int index, int direction) const = 0; - - virtual CFX_WideString GetPageText(int start = 0, int nCount = -1 ) const = 0; + virtual CFX_WideString GetPageText(int start = 0, int nCount = -1) const = 0; }; -#define FPDFTEXT_MATCHCASE 0x00000001 +#define FPDFTEXT_MATCHCASE 0x00000001 #define FPDFTEXT_MATCHWHOLEWORD 0x00000002 -#define FPDFTEXT_CONSECUTIVE 0x00000004 -class IPDF_TextPageFind -{ -public: +#define FPDFTEXT_CONSECUTIVE 0x00000004 +class IPDF_TextPageFind { + public: + virtual ~IPDF_TextPageFind() {} - virtual ~IPDF_TextPageFind() {} + static IPDF_TextPageFind* CreatePageFind(const IPDF_TextPage* pTextPage); - static IPDF_TextPageFind* CreatePageFind(const IPDF_TextPage* pTextPage); -public: + public: + virtual FX_BOOL FindFirst(const CFX_WideString& findwhat, + int flags, + int startPos = 0) = 0; - virtual FX_BOOL FindFirst(const CFX_WideString& findwhat, int flags, int startPos = 0) = 0; + virtual FX_BOOL FindNext() = 0; - virtual FX_BOOL FindNext() = 0; + virtual FX_BOOL FindPrev() = 0; - virtual FX_BOOL FindPrev() = 0; + virtual void GetRectArray(CFX_RectArray& rects) const = 0; - virtual void GetRectArray(CFX_RectArray& rects) const = 0; + virtual int GetCurOrder() const = 0; - virtual int GetCurOrder() const = 0; - - virtual int GetMatchedCount() const = 0; + virtual int GetMatchedCount() const = 0; }; -class IPDF_LinkExtract -{ -public: - - virtual ~IPDF_LinkExtract() {} +class IPDF_LinkExtract { + public: + virtual ~IPDF_LinkExtract() {} - static IPDF_LinkExtract* CreateLinkExtract(); + static IPDF_LinkExtract* CreateLinkExtract(); - virtual FX_BOOL ExtractLinks(const IPDF_TextPage* pTextPage) = 0; -public: + virtual FX_BOOL ExtractLinks(const IPDF_TextPage* pTextPage) = 0; - virtual int CountLinks() const = 0; + public: + virtual int CountLinks() const = 0; - virtual CFX_WideString GetURL(int index) const = 0; + virtual CFX_WideString GetURL(int index) const = 0; - virtual void GetBoundedSegment(int index, int& start, int& count) const = 0; + virtual void GetBoundedSegment(int index, int& start, int& count) const = 0; - virtual void GetRects(int index, CFX_RectArray& rects) const = 0; + virtual void GetRects(int index, CFX_RectArray& rects) const = 0; }; #endif // CORE_INCLUDE_FPDFTEXT_FPDF_TEXT_H_ diff --git a/core/include/fxcodec/fx_codec.h b/core/include/fxcodec/fx_codec.h index 5b0092a6ff..9fc19edd53 100644 --- a/core/include/fxcodec/fx_codec.h +++ b/core/include/fxcodec/fx_codec.h @@ -31,396 +31,523 @@ class ICodec_TiffModule; class CFX_DIBAttribute; class ICodec_ScanlineDecoder; -class CCodec_ModuleMgr -{ -public: - CCodec_ModuleMgr(); - ICodec_ProgressiveDecoder* CreateProgressiveDecoder(); - ICodec_Jbig2Encoder* CreateJbig2Encoder(); - ICodec_BasicModule* GetBasicModule() const { return m_pBasicModule.get(); } - ICodec_FaxModule* GetFaxModule() const { return m_pFaxModule.get(); } - ICodec_JpegModule* GetJpegModule() const { return m_pJpegModule.get(); } - ICodec_JpxModule* GetJpxModule() const { return m_pJpxModule.get(); } - ICodec_Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); } - ICodec_IccModule* GetIccModule() const { return m_pIccModule.get(); } - ICodec_FlateModule* GetFlateModule() const { return m_pFlateModule.get(); } - ICodec_PngModule* GetPngModule() const { return m_pPngModule.get(); } - ICodec_GifModule* GetGifModule() const { return m_pGifModule.get(); } - ICodec_BmpModule* GetBmpModule() const { return m_pBmpModule.get(); } - ICodec_TiffModule* GetTiffModule() const { return m_pTiffModule.get(); } - -protected: - nonstd::unique_ptr<ICodec_BasicModule> m_pBasicModule; - nonstd::unique_ptr<ICodec_FaxModule> m_pFaxModule; - nonstd::unique_ptr<ICodec_JpegModule> m_pJpegModule; - nonstd::unique_ptr<ICodec_JpxModule> m_pJpxModule; - nonstd::unique_ptr<ICodec_Jbig2Module> m_pJbig2Module; - nonstd::unique_ptr<ICodec_IccModule> m_pIccModule; - nonstd::unique_ptr<ICodec_FlateModule> m_pFlateModule; - nonstd::unique_ptr<ICodec_PngModule> m_pPngModule; - nonstd::unique_ptr<ICodec_GifModule> m_pGifModule; - nonstd::unique_ptr<ICodec_BmpModule> m_pBmpModule; - nonstd::unique_ptr<ICodec_TiffModule> m_pTiffModule; +class CCodec_ModuleMgr { + public: + CCodec_ModuleMgr(); + ICodec_ProgressiveDecoder* CreateProgressiveDecoder(); + ICodec_Jbig2Encoder* CreateJbig2Encoder(); + ICodec_BasicModule* GetBasicModule() const { return m_pBasicModule.get(); } + ICodec_FaxModule* GetFaxModule() const { return m_pFaxModule.get(); } + ICodec_JpegModule* GetJpegModule() const { return m_pJpegModule.get(); } + ICodec_JpxModule* GetJpxModule() const { return m_pJpxModule.get(); } + ICodec_Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); } + ICodec_IccModule* GetIccModule() const { return m_pIccModule.get(); } + ICodec_FlateModule* GetFlateModule() const { return m_pFlateModule.get(); } + ICodec_PngModule* GetPngModule() const { return m_pPngModule.get(); } + ICodec_GifModule* GetGifModule() const { return m_pGifModule.get(); } + ICodec_BmpModule* GetBmpModule() const { return m_pBmpModule.get(); } + ICodec_TiffModule* GetTiffModule() const { return m_pTiffModule.get(); } + + protected: + nonstd::unique_ptr<ICodec_BasicModule> m_pBasicModule; + nonstd::unique_ptr<ICodec_FaxModule> m_pFaxModule; + nonstd::unique_ptr<ICodec_JpegModule> m_pJpegModule; + nonstd::unique_ptr<ICodec_JpxModule> m_pJpxModule; + nonstd::unique_ptr<ICodec_Jbig2Module> m_pJbig2Module; + nonstd::unique_ptr<ICodec_IccModule> m_pIccModule; + nonstd::unique_ptr<ICodec_FlateModule> m_pFlateModule; + nonstd::unique_ptr<ICodec_PngModule> m_pPngModule; + nonstd::unique_ptr<ICodec_GifModule> m_pGifModule; + nonstd::unique_ptr<ICodec_BmpModule> m_pBmpModule; + nonstd::unique_ptr<ICodec_TiffModule> m_pTiffModule; }; -class ICodec_BasicModule -{ -public: - - virtual ~ICodec_BasicModule() {} - virtual FX_BOOL RunLengthEncode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, - FX_DWORD& dest_size) = 0; - virtual FX_BOOL A85Encode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, - FX_DWORD& dest_size) = 0; - virtual ICodec_ScanlineDecoder* CreateRunLengthDecoder(const uint8_t* src_buf, FX_DWORD src_size, int width, int height, - int nComps, int bpc) = 0; +class ICodec_BasicModule { + public: + virtual ~ICodec_BasicModule() {} + virtual FX_BOOL RunLengthEncode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size) = 0; + virtual FX_BOOL A85Encode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size) = 0; + virtual ICodec_ScanlineDecoder* CreateRunLengthDecoder(const uint8_t* src_buf, + FX_DWORD src_size, + int width, + int height, + int nComps, + int bpc) = 0; }; -class ICodec_ScanlineDecoder -{ -public: - - virtual ~ICodec_ScanlineDecoder() {} +class ICodec_ScanlineDecoder { + public: + virtual ~ICodec_ScanlineDecoder() {} - virtual FX_DWORD GetSrcOffset() = 0; + virtual FX_DWORD GetSrcOffset() = 0; - virtual void DownScale(int dest_width, int dest_height) = 0; + virtual void DownScale(int dest_width, int dest_height) = 0; - virtual uint8_t* GetScanline(int line) = 0; + virtual uint8_t* GetScanline(int line) = 0; - virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) = 0; + virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) = 0; - virtual int GetWidth() = 0; + virtual int GetWidth() = 0; - virtual int GetHeight() = 0; + virtual int GetHeight() = 0; - virtual int CountComps() = 0; + virtual int CountComps() = 0; - virtual int GetBPC() = 0; + virtual int GetBPC() = 0; - virtual FX_BOOL IsColorTransformed() = 0; + virtual FX_BOOL IsColorTransformed() = 0; - virtual void ClearImageData() = 0; + virtual void ClearImageData() = 0; +}; +class ICodec_FlateModule { + public: + virtual ~ICodec_FlateModule() {} + virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, + FX_DWORD src_size, + int width, + int height, + int nComps, + int bpc, + int predictor, + int Colors, + int BitsPerComponent, + int Columns) = 0; + virtual FX_DWORD FlateOrLZWDecode(FX_BOOL bLZW, + const uint8_t* src_buf, + FX_DWORD src_size, + FX_BOOL bEarlyChange, + int predictor, + int Colors, + int BitsPerComponent, + int Columns, + FX_DWORD estimated_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size) = 0; + virtual FX_BOOL Encode(const uint8_t* src_buf, + FX_DWORD src_size, + int predictor, + int Colors, + int BitsPerComponent, + int Columns, + uint8_t*& dest_buf, + FX_DWORD& dest_size) = 0; + virtual FX_BOOL Encode(const uint8_t* src_buf, + FX_DWORD src_size, + uint8_t*& dest_buf, + FX_DWORD& dest_size) = 0; +}; +class ICodec_FaxModule { + public: + virtual ~ICodec_FaxModule() {} + + virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, + FX_DWORD src_size, + int width, + int height, + int K, + FX_BOOL EndOfLine, + FX_BOOL EncodedByteAlign, + FX_BOOL BlackIs1, + int Columns, + int Rows) = 0; + + virtual FX_BOOL Encode(const uint8_t* src_buf, + int width, + int height, + int pitch, + uint8_t*& dest_buf, + FX_DWORD& dest_size) = 0; }; -class ICodec_FlateModule -{ -public: - - virtual ~ICodec_FlateModule() {} - virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, FX_DWORD src_size, int width, int height, - int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, int Columns) = 0; - virtual FX_DWORD FlateOrLZWDecode(FX_BOOL bLZW, const uint8_t* src_buf, FX_DWORD src_size, FX_BOOL bEarlyChange, - int predictor, int Colors, int BitsPerComponent, int Columns, - FX_DWORD estimated_size, uint8_t*& dest_buf, FX_DWORD& dest_size) = 0; - virtual FX_BOOL Encode(const uint8_t* src_buf, FX_DWORD src_size, - int predictor, int Colors, int BitsPerComponent, int Columns, - uint8_t*& dest_buf, FX_DWORD& dest_size) = 0; - virtual FX_BOOL Encode(const uint8_t* src_buf, FX_DWORD src_size, uint8_t*& dest_buf, FX_DWORD& dest_size) = 0; +class ICodec_JpegModule { + public: + virtual ~ICodec_JpegModule() {} + + virtual void SetPovider(IFX_JpegProvider* pJP) = 0; + + virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, + FX_DWORD src_size, + int width, + int height, + int nComps, + FX_BOOL ColorTransform) = 0; + + virtual FX_BOOL LoadInfo(const uint8_t* src_buf, + FX_DWORD src_size, + int& width, + int& height, + int& num_components, + int& bits_per_components, + FX_BOOL& color_transform, + uint8_t** icc_buf_ptr = NULL, + FX_DWORD* icc_length = NULL) = 0; + + virtual FX_BOOL Encode(const class CFX_DIBSource* pSource, + uint8_t*& dest_buf, + FX_STRSIZE& dest_size, + int quality = 75, + const uint8_t* icc_buf = NULL, + FX_DWORD icc_length = 0) = 0; + + virtual void* Start() = 0; + + virtual void Finish(void* pContext) = 0; + + virtual void Input(void* pContext, + const uint8_t* src_buf, + FX_DWORD src_size) = 0; + + virtual int ReadHeader(void* pContext, + int* width, + int* height, + int* nComps, + CFX_DIBAttribute* pAttribute = NULL) = 0; + + virtual int StartScanline(void* pContext, int down_scale) = 0; + + virtual FX_BOOL ReadScanline(void* pContext, uint8_t* dest_buf) = 0; + + virtual FX_DWORD GetAvailInput(void* pContext, + uint8_t** avail_buf_ptr = NULL) = 0; }; -class ICodec_FaxModule -{ -public: +class ICodec_JpxModule { + public: + virtual ~ICodec_JpxModule() {} + + virtual void* CreateDecoder(const uint8_t* src_buf, + FX_DWORD src_size, + FX_BOOL useColorSpace = FALSE) = 0; + + virtual void GetImageInfo(void* ctx, + FX_DWORD& width, + FX_DWORD& height, + FX_DWORD& codestream_nComps, + FX_DWORD& output_nComps) = 0; + + virtual FX_BOOL Decode(void* ctx, + uint8_t* dest_data, + int pitch, + FX_BOOL bTranslateColor, + uint8_t* offsets) = 0; + + virtual void DestroyDecoder(void* ctx) = 0; +}; +class ICodec_PngModule { + public: + virtual ~ICodec_PngModule() {} + + virtual void* Start(void* pModule) = 0; + + virtual void Finish(void* pContext) = 0; - virtual ~ICodec_FaxModule() {} + virtual FX_BOOL Input(void* pContext, + const uint8_t* src_buf, + FX_DWORD src_size, + CFX_DIBAttribute* pAttribute = NULL) = 0; - virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, FX_DWORD src_size, int width, int height, - int K, FX_BOOL EndOfLine, FX_BOOL EncodedByteAlign, FX_BOOL BlackIs1, int Columns, int Rows) = 0; + FX_BOOL (*ReadHeaderCallback)(void* pModule, int width, int height, int bpc, int pass, int* color_type, double* gamma); + FX_BOOL (*AskScanlineBufCallback)(void* pModule, int line, uint8_t*& src_buf); - virtual FX_BOOL Encode(const uint8_t* src_buf, int width, int height, int pitch, - uint8_t*& dest_buf, FX_DWORD& dest_size) = 0; + void (*FillScanlineBufCompletedCallback)(void* pModule, int pass, int line); }; -class ICodec_JpegModule -{ -public: +class ICodec_GifModule { + public: + virtual ~ICodec_GifModule() {} - virtual ~ICodec_JpegModule() {} + virtual void* Start(void* pModule) = 0; - virtual void SetPovider(IFX_JpegProvider* pJP) = 0; + virtual void Finish(void* pContext) = 0; - virtual ICodec_ScanlineDecoder* CreateDecoder(const uint8_t* src_buf, FX_DWORD src_size, - int width, int height, int nComps, FX_BOOL ColorTransform) = 0; + virtual FX_DWORD GetAvailInput(void* pContext, + uint8_t** avail_buf_ptr = NULL) = 0; - virtual FX_BOOL LoadInfo(const uint8_t* src_buf, FX_DWORD src_size, int& width, int& height, - int& num_components, int& bits_per_components, FX_BOOL& color_transform, - uint8_t** icc_buf_ptr = NULL, FX_DWORD* icc_length = NULL) = 0; + virtual void Input(void* pContext, + const uint8_t* src_buf, + FX_DWORD src_size) = 0; - virtual FX_BOOL Encode(const class CFX_DIBSource* pSource, uint8_t*& dest_buf, FX_STRSIZE& dest_size, int quality = 75, - const uint8_t* icc_buf = NULL, FX_DWORD icc_length = 0) = 0; + virtual int32_t ReadHeader(void* pContext, + int* width, + int* height, + int* pal_num, + void** pal_pp, + int* bg_index, + CFX_DIBAttribute* pAttribute = NULL) = 0; - virtual void* Start() = 0; + virtual int32_t LoadFrameInfo(void* pContext, int* frame_num) = 0; - virtual void Finish(void* pContext) = 0; + void (*RecordCurrentPositionCallback)(void* pModule, FX_DWORD& cur_pos); - virtual void Input(void* pContext, const uint8_t* src_buf, FX_DWORD src_size) = 0; + uint8_t* (*AskLocalPaletteBufCallback)(void* pModule, + int32_t frame_num, + int32_t pal_size); - virtual int ReadHeader(void* pContext, int* width, int* height, int* nComps, CFX_DIBAttribute* pAttribute = NULL) = 0;
+ virtual int32_t LoadFrame(void* pContext, + int frame_num, + CFX_DIBAttribute* pAttribute = NULL) = 0; + FX_BOOL (*InputRecordPositionBufCallback)(void* pModule, FX_DWORD rcd_pos, const FX_RECT& img_rc,
+ int32_t pal_num, void* pal_ptr,
+ int32_t delay_time, FX_BOOL user_input,
+ int32_t trans_index, int32_t disposal_method, FX_BOOL interlace); - virtual int StartScanline(void* pContext, int down_scale) = 0; + void (*ReadScanlineCallback)(void* pModule, + int32_t row_num, + uint8_t* row_buf); +}; +class ICodec_BmpModule { + public: + virtual ~ICodec_BmpModule() {} + + virtual void* Start(void* pModule) = 0; + + virtual void Finish(void* pContext) = 0; + + virtual FX_DWORD GetAvailInput(void* pContext, + uint8_t** avail_buf_ptr = NULL) = 0; + + virtual void Input(void* pContext, + const uint8_t* src_buf, + FX_DWORD src_size) = 0; + virtual int32_t ReadHeader(void* pContext, + int32_t* width, + int32_t* height, + FX_BOOL* tb_flag, + int32_t* components, + int* pal_num, + FX_DWORD** pal_pp, + CFX_DIBAttribute* pAttribute = NULL) = 0; - virtual FX_BOOL ReadScanline(void* pContext, uint8_t* dest_buf) = 0; + virtual int32_t LoadImage(void* pContext) = 0; + FX_BOOL (*InputImagePositionBufCallback)(void* pModule, FX_DWORD rcd_pos); - virtual FX_DWORD GetAvailInput(void* pContext, uint8_t** avail_buf_ptr = NULL) = 0; + void (*ReadScanlineCallback)(void* pModule, + int32_t row_num, + uint8_t* row_buf); }; -class ICodec_JpxModule -{ -public: +class ICodec_TiffModule { + public: + virtual ~ICodec_TiffModule() {} - virtual ~ICodec_JpxModule() {} + virtual void* CreateDecoder(IFX_FileRead* file_ptr) = 0; - virtual void* CreateDecoder(const uint8_t* src_buf, FX_DWORD src_size, FX_BOOL useColorSpace = FALSE) = 0; + virtual void GetFrames(void* ctx, int32_t& frames) = 0; - virtual void GetImageInfo(void* ctx, FX_DWORD& width, FX_DWORD& height, - FX_DWORD& codestream_nComps, FX_DWORD& output_nComps) = 0; + virtual FX_BOOL LoadFrameInfo(void* ctx, + int32_t frame, + FX_DWORD& width, + FX_DWORD& height, + FX_DWORD& comps, + FX_DWORD& bpc, + CFX_DIBAttribute* pAttribute = NULL) = 0; - virtual FX_BOOL Decode(void* ctx, uint8_t* dest_data, int pitch, - FX_BOOL bTranslateColor, uint8_t* offsets) = 0; + virtual FX_BOOL Decode(void* ctx, class CFX_DIBitmap* pDIBitmap) = 0; - virtual void DestroyDecoder(void* ctx) = 0; + virtual void DestroyDecoder(void* ctx) = 0; }; -class ICodec_PngModule -{
-public:
-
- virtual ~ICodec_PngModule() {}
-
- virtual void* Start(void* pModule) = 0;
-
- virtual void Finish(void* pContext) = 0;
-
- virtual FX_BOOL Input(void* pContext, const uint8_t* src_buf, FX_DWORD src_size, CFX_DIBAttribute* pAttribute = NULL) = 0;
-
- FX_BOOL (*ReadHeaderCallback)(void* pModule, int width, int height, int bpc, int pass, int* color_type, double* gamma);
-
- FX_BOOL (*AskScanlineBufCallback)(void* pModule, int line, uint8_t*& src_buf);
-
- void (*FillScanlineBufCompletedCallback)(void* pModule, int pass, int line);
-};
-class ICodec_GifModule -{
-public:
-
- virtual ~ICodec_GifModule() {}
-
- virtual void* Start(void* pModule) = 0;
-
- virtual void Finish(void* pContext) = 0;
-
- virtual FX_DWORD GetAvailInput(void* pContext, uint8_t** avail_buf_ptr = NULL) = 0;
-
- virtual void Input(void* pContext, const uint8_t* src_buf, FX_DWORD src_size) = 0;
-
- virtual int32_t ReadHeader(void* pContext, int* width, int* height,
- int* pal_num, void** pal_pp, int* bg_index, CFX_DIBAttribute* pAttribute = NULL) = 0;
-
- virtual int32_t LoadFrameInfo(void* pContext, int* frame_num) = 0;
-
- void (*RecordCurrentPositionCallback)(void* pModule, FX_DWORD& cur_pos);
-
- uint8_t* (*AskLocalPaletteBufCallback)(void* pModule, int32_t frame_num, int32_t pal_size);
-
- virtual int32_t LoadFrame(void* pContext, int frame_num, CFX_DIBAttribute* pAttribute = NULL) = 0;
-
- FX_BOOL (*InputRecordPositionBufCallback)(void* pModule, FX_DWORD rcd_pos, const FX_RECT& img_rc,
- int32_t pal_num, void* pal_ptr,
- int32_t delay_time, FX_BOOL user_input,
- int32_t trans_index, int32_t disposal_method, FX_BOOL interlace);
-
- void (*ReadScanlineCallback)(void* pModule, int32_t row_num, uint8_t* row_buf);
-};
-class ICodec_BmpModule -{
-public:
-
- virtual ~ICodec_BmpModule() {}
-
- virtual void* Start(void* pModule) = 0;
-
- virtual void Finish(void* pContext) = 0;
-
- virtual FX_DWORD GetAvailInput(void* pContext, uint8_t** avail_buf_ptr = NULL) = 0;
-
- virtual void Input(void* pContext, const uint8_t* src_buf, FX_DWORD src_size) = 0;
-
- virtual int32_t ReadHeader(void* pContext, int32_t* width, int32_t* height, FX_BOOL* tb_flag, int32_t* components,
- int* pal_num, FX_DWORD** pal_pp, CFX_DIBAttribute* pAttribute = NULL) = 0;
-
- virtual int32_t LoadImage(void* pContext) = 0;
-
- FX_BOOL (*InputImagePositionBufCallback)(void* pModule, FX_DWORD rcd_pos);
-
- void (*ReadScanlineCallback)(void* pModule, int32_t row_num, uint8_t* row_buf);
-};
-class ICodec_TiffModule -{
-public:
-
- virtual ~ICodec_TiffModule() {}
-
- virtual void* CreateDecoder(IFX_FileRead* file_ptr) = 0;
-
-
- virtual void GetFrames(void* ctx, int32_t& frames) = 0;
-
- virtual FX_BOOL LoadFrameInfo(void* ctx, int32_t frame, FX_DWORD& width, FX_DWORD& height, FX_DWORD& comps, FX_DWORD& bpc, CFX_DIBAttribute* pAttribute = NULL) = 0;
-
-
- virtual FX_BOOL Decode(void* ctx, class CFX_DIBitmap* pDIBitmap) = 0;
-
- virtual void DestroyDecoder(void* ctx) = 0;
-};
-class ICodec_Jbig2Module -{ -public: - - virtual ~ICodec_Jbig2Module() {} - - virtual FX_BOOL Decode(FX_DWORD width, FX_DWORD height, const uint8_t* src_buf, FX_DWORD src_size, - const uint8_t* global_data, FX_DWORD global_size, uint8_t* dest_buf, FX_DWORD dest_pitch) = 0; - - virtual FX_BOOL Decode(IFX_FileRead* file_ptr, FX_DWORD& width, FX_DWORD& height, - FX_DWORD& pitch, uint8_t*& dest_buf) = 0; - virtual void* CreateJbig2Context() = 0; - - virtual FXCODEC_STATUS StartDecode(void* pJbig2Context, FX_DWORD width, FX_DWORD height, const uint8_t* src_buf, FX_DWORD src_size, - const uint8_t* global_data, FX_DWORD global_size, uint8_t* dest_buf, FX_DWORD dest_pitch, IFX_Pause* pPause) = 0; - - virtual FXCODEC_STATUS StartDecode(void* pJbig2Context, IFX_FileRead* file_ptr, - FX_DWORD& width, FX_DWORD& height, FX_DWORD& pitch, uint8_t*& dest_buf, IFX_Pause* pPause) = 0; - virtual FXCODEC_STATUS ContinueDecode(void* pJbig2Content, IFX_Pause* pPause) = 0; - virtual void DestroyJbig2Context(void* pJbig2Content) = 0; +class ICodec_Jbig2Module { + public: + virtual ~ICodec_Jbig2Module() {} + + virtual FX_BOOL Decode(FX_DWORD width, + FX_DWORD height, + const uint8_t* src_buf, + FX_DWORD src_size, + const uint8_t* global_data, + FX_DWORD global_size, + uint8_t* dest_buf, + FX_DWORD dest_pitch) = 0; + + virtual FX_BOOL Decode(IFX_FileRead* file_ptr, + FX_DWORD& width, + FX_DWORD& height, + FX_DWORD& pitch, + uint8_t*& dest_buf) = 0; + virtual void* CreateJbig2Context() = 0; + + virtual FXCODEC_STATUS StartDecode(void* pJbig2Context, + FX_DWORD width, + FX_DWORD height, + const uint8_t* src_buf, + FX_DWORD src_size, + const uint8_t* global_data, + FX_DWORD global_size, + uint8_t* dest_buf, + FX_DWORD dest_pitch, + IFX_Pause* pPause) = 0; + + virtual FXCODEC_STATUS StartDecode(void* pJbig2Context, + IFX_FileRead* file_ptr, + FX_DWORD& width, + FX_DWORD& height, + FX_DWORD& pitch, + uint8_t*& dest_buf, + IFX_Pause* pPause) = 0; + virtual FXCODEC_STATUS ContinueDecode(void* pJbig2Content, + IFX_Pause* pPause) = 0; + virtual void DestroyJbig2Context(void* pJbig2Content) = 0; }; -class ICodec_ProgressiveDecoder -{
-public:
-
- virtual ~ICodec_ProgressiveDecoder() {}
-
- virtual FXCODEC_STATUS LoadImageInfo(IFX_FileRead* pFile, FXCODEC_IMAGE_TYPE imageType = FXCODEC_IMAGE_UNKNOWN, CFX_DIBAttribute* pAttribute = NULL) = 0;
-
- virtual FXCODEC_IMAGE_TYPE GetType() = 0;
-
- virtual int32_t GetWidth() = 0;
-
- virtual int32_t GetHeight() = 0;
-
- virtual int32_t GetNumComponents() = 0;
-
- virtual int32_t GetBPC() = 0;
-
- virtual void SetClipBox(FX_RECT* clip) = 0;
-
- virtual FXCODEC_STATUS GetFrames(int32_t& frames, IFX_Pause* pPause = NULL) = 0;
-
- virtual FXCODEC_STATUS StartDecode(class CFX_DIBitmap* pDIBitmap,
- int32_t start_x, int32_t start_y, int32_t size_x, int32_t size_y,
- int32_t frames = 0, FX_BOOL bInterpol = TRUE) = 0;
-
- virtual FXCODEC_STATUS ContinueDecode(IFX_Pause* pPause = NULL) = 0;
-};
-class ICodec_Jbig2Encoder -{ -public: - - virtual ~ICodec_Jbig2Encoder() {} +class ICodec_ProgressiveDecoder { + public: + virtual ~ICodec_ProgressiveDecoder() {} + + virtual FXCODEC_STATUS LoadImageInfo( + IFX_FileRead* pFile, + FXCODEC_IMAGE_TYPE imageType = FXCODEC_IMAGE_UNKNOWN, + CFX_DIBAttribute* pAttribute = NULL) = 0; + + virtual FXCODEC_IMAGE_TYPE GetType() = 0; + + virtual int32_t GetWidth() = 0; + + virtual int32_t GetHeight() = 0; + + virtual int32_t GetNumComponents() = 0; + + virtual int32_t GetBPC() = 0; + + virtual void SetClipBox(FX_RECT* clip) = 0; + + virtual FXCODEC_STATUS GetFrames(int32_t& frames, + IFX_Pause* pPause = NULL) = 0; + + virtual FXCODEC_STATUS StartDecode(class CFX_DIBitmap* pDIBitmap, + int32_t start_x, + int32_t start_y, + int32_t size_x, + int32_t size_y, + int32_t frames = 0, + FX_BOOL bInterpol = TRUE) = 0; + + virtual FXCODEC_STATUS ContinueDecode(IFX_Pause* pPause = NULL) = 0; +}; +class ICodec_Jbig2Encoder { + public: + virtual ~ICodec_Jbig2Encoder() {} }; -class ICodec_IccModule -{ -public: - typedef enum { - IccCS_Unknown = 0, - IccCS_XYZ, - IccCS_Lab, - IccCS_Luv, - IccCS_YCbCr, - IccCS_Yxy, - IccCS_Hsv, - IccCS_Hls, - IccCS_Gray, - IccCS_Rgb, - IccCS_Cmyk, - IccCS_Cmy - } IccCS; - typedef struct _IccParam { - FX_DWORD Version; - IccCS ColorSpace; - FX_DWORD dwProfileType; - FX_DWORD dwFormat; - uint8_t* pProfileData; - FX_DWORD dwProfileSize; - double Gamma; - } IccParam; - - virtual ~ICodec_IccModule() {} - - virtual IccCS GetProfileCS(const uint8_t* pProfileData, unsigned int dwProfileSize) = 0; - - virtual IccCS GetProfileCS(IFX_FileRead* pFile) = 0; - - virtual void* CreateTransform(ICodec_IccModule::IccParam* pInputParam, - ICodec_IccModule::IccParam* pOutputParam, - ICodec_IccModule::IccParam* pProofParam = NULL, - FX_DWORD dwIntent = Icc_INTENT_PERCEPTUAL, - FX_DWORD dwFlag = Icc_FLAGS_DEFAULT, - FX_DWORD dwPrfIntent = Icc_INTENT_ABSOLUTE_COLORIMETRIC, - FX_DWORD dwPrfFlag = Icc_FLAGS_SOFTPROOFING - ) = 0; - - - virtual void* CreateTransform_sRGB(const uint8_t* pProfileData, FX_DWORD dwProfileSize, int32_t& nComponents, int32_t intent = 0, - FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT) = 0; - - virtual void* CreateTransform_CMYK(const uint8_t* pSrcProfileData, FX_DWORD dwSrcProfileSize, int32_t& nSrcComponents, - const uint8_t* pDstProfileData, FX_DWORD dwDstProfileSize, int32_t intent = 0, - FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT, - FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT - ) = 0; - - virtual void DestroyTransform(void* pTransform) = 0; - - virtual void Translate(void* pTransform, FX_FLOAT* pSrcValues, FX_FLOAT* pDestValues) = 0; - - virtual void TranslateScanline(void* pTransform, uint8_t* pDest, const uint8_t* pSrc, int pixels) = 0; - virtual void SetComponents(FX_DWORD nComponents) = 0; +class ICodec_IccModule { + public: + typedef enum { + IccCS_Unknown = 0, + IccCS_XYZ, + IccCS_Lab, + IccCS_Luv, + IccCS_YCbCr, + IccCS_Yxy, + IccCS_Hsv, + IccCS_Hls, + IccCS_Gray, + IccCS_Rgb, + IccCS_Cmyk, + IccCS_Cmy + } IccCS; + typedef struct _IccParam { + FX_DWORD Version; + IccCS ColorSpace; + FX_DWORD dwProfileType; + FX_DWORD dwFormat; + uint8_t* pProfileData; + FX_DWORD dwProfileSize; + double Gamma; + } IccParam; + + virtual ~ICodec_IccModule() {} + + virtual IccCS GetProfileCS(const uint8_t* pProfileData, + unsigned int dwProfileSize) = 0; + + virtual IccCS GetProfileCS(IFX_FileRead* pFile) = 0; + + virtual void* CreateTransform( + ICodec_IccModule::IccParam* pInputParam, + ICodec_IccModule::IccParam* pOutputParam, + ICodec_IccModule::IccParam* pProofParam = NULL, + FX_DWORD dwIntent = Icc_INTENT_PERCEPTUAL, + FX_DWORD dwFlag = Icc_FLAGS_DEFAULT, + FX_DWORD dwPrfIntent = Icc_INTENT_ABSOLUTE_COLORIMETRIC, + FX_DWORD dwPrfFlag = Icc_FLAGS_SOFTPROOFING) = 0; + + virtual void* CreateTransform_sRGB( + const uint8_t* pProfileData, + FX_DWORD dwProfileSize, + int32_t& nComponents, + int32_t intent = 0, + FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT) = 0; + + virtual void* CreateTransform_CMYK( + const uint8_t* pSrcProfileData, + FX_DWORD dwSrcProfileSize, + int32_t& nSrcComponents, + const uint8_t* pDstProfileData, + FX_DWORD dwDstProfileSize, + int32_t intent = 0, + FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT, + FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT) = 0; + + virtual void DestroyTransform(void* pTransform) = 0; + + virtual void Translate(void* pTransform, + FX_FLOAT* pSrcValues, + FX_FLOAT* pDestValues) = 0; + + virtual void TranslateScanline(void* pTransform, + uint8_t* pDest, + const uint8_t* pSrc, + int pixels) = 0; + virtual void SetComponents(FX_DWORD nComponents) = 0; }; -void AdobeCMYK_to_sRGB(FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B); -void AdobeCMYK_to_sRGB1(uint8_t c, uint8_t m, uint8_t y, uint8_t k, uint8_t& R, uint8_t& G, uint8_t& B); +void AdobeCMYK_to_sRGB(FX_FLOAT c, + FX_FLOAT m, + FX_FLOAT y, + FX_FLOAT k, + FX_FLOAT& R, + FX_FLOAT& G, + FX_FLOAT& B); +void AdobeCMYK_to_sRGB1(uint8_t c, + uint8_t m, + uint8_t y, + uint8_t k, + uint8_t& R, + uint8_t& G, + uint8_t& B); FX_BOOL MD5ComputeID(const void* buf, FX_DWORD dwSize, uint8_t ID[16]); -class CFX_DIBAttribute -{
-public:
- CFX_DIBAttribute();
- ~CFX_DIBAttribute();
-
- int32_t m_nXDPI;
-
- int32_t m_nYDPI;
-
- FX_FLOAT m_fAspectRatio;
-
- FX_WORD m_wDPIUnit;
-
- CFX_ByteString m_strAuthor;
-
- uint8_t m_strTime[20];
-
- int32_t m_nGifLeft;
- int32_t m_nGifTop;
-
- FX_DWORD* m_pGifLocalPalette;
-
- FX_DWORD m_nGifLocalPalNum;
-
- int32_t m_nBmpCompressType;
- class IFX_DIBAttributeExif* m_pExif;
-};
-class IFX_DIBAttributeExif -{
-public:
- virtual ~IFX_DIBAttributeExif() {};
- virtual FX_BOOL GetInfo(FX_WORD tag, void* val) = 0;
-};
+class CFX_DIBAttribute { + public: + CFX_DIBAttribute(); + ~CFX_DIBAttribute(); + + int32_t m_nXDPI; + + int32_t m_nYDPI; + + FX_FLOAT m_fAspectRatio; + + FX_WORD m_wDPIUnit; + + CFX_ByteString m_strAuthor; + + uint8_t m_strTime[20]; + + int32_t m_nGifLeft; + int32_t m_nGifTop; + + FX_DWORD* m_pGifLocalPalette; + + FX_DWORD m_nGifLocalPalNum; + + int32_t m_nBmpCompressType; + class IFX_DIBAttributeExif* m_pExif; +}; +class IFX_DIBAttributeExif { + public: + virtual ~IFX_DIBAttributeExif(){}; + virtual FX_BOOL GetInfo(FX_WORD tag, void* val) = 0; +}; #endif // CORE_INCLUDE_FXCODEC_FX_CODEC_H_ diff --git a/core/include/fxcodec/fx_codec_def.h b/core/include/fxcodec/fx_codec_def.h index 36a5e0d2c2..1cb5909658 100644 --- a/core/include/fxcodec/fx_codec_def.h +++ b/core/include/fxcodec/fx_codec_def.h @@ -8,81 +8,81 @@ #define CORE_INCLUDE_FXCODEC_FX_CODEC_DEF_H_ enum FXCODEC_IMAGE_TYPE { - FXCODEC_IMAGE_UNKNOWN = 0, - FXCODEC_IMAGE_BMP, - FXCODEC_IMAGE_JPG, - FXCODEC_IMAGE_PNG, - FXCODEC_IMAGE_GIF, - FXCODEC_IMAGE_TIF, - FXCODEC_IMAGE_MAX + FXCODEC_IMAGE_UNKNOWN = 0, + FXCODEC_IMAGE_BMP, + FXCODEC_IMAGE_JPG, + FXCODEC_IMAGE_PNG, + FXCODEC_IMAGE_GIF, + FXCODEC_IMAGE_TIF, + FXCODEC_IMAGE_MAX }; enum FXCODEC_STATUS { - FXCODEC_STATUS_ERROR = -1, - FXCODEC_STATUS_FRAME_READY, - FXCODEC_STATUS_FRAME_TOBECONTINUE, - FXCODEC_STATUS_DECODE_READY, - FXCODEC_STATUS_DECODE_TOBECONTINUE, - FXCODEC_STATUS_DECODE_FINISH, - FXCODEC_STATUS_ERR_MEMORY, - FXCODEC_STATUS_ERR_READ, - FXCODEC_STATUS_ERR_FLUSH, - FXCODEC_STATUS_ERR_FORMAT, - FXCODEC_STATUS_ERR_PARAMS + FXCODEC_STATUS_ERROR = -1, + FXCODEC_STATUS_FRAME_READY, + FXCODEC_STATUS_FRAME_TOBECONTINUE, + FXCODEC_STATUS_DECODE_READY, + FXCODEC_STATUS_DECODE_TOBECONTINUE, + FXCODEC_STATUS_DECODE_FINISH, + FXCODEC_STATUS_ERR_MEMORY, + FXCODEC_STATUS_ERR_READ, + FXCODEC_STATUS_ERR_FLUSH, + FXCODEC_STATUS_ERR_FORMAT, + FXCODEC_STATUS_ERR_PARAMS }; -#define JP2_SPACE_INVALID -1 -#define JPX_SPACE_INVALID -1 -#define JP2_SPACE_bilevel1 0 -#define JP2_SPACE_YCbCr1 1 -#define JP2_SPACE_YCbCr2 3 -#define JP2_SPACE_YCbCr3 4 -#define JP2_SPACE_PhotoYCC 9 -#define JP2_SPACE_CMY 11 -#define JP2_SPACE_CMYK 12 -#define JP2_SPACE_YCCK 13 -#define JP2_SPACE_CIELab 14 -#define JP2_SPACE_bilevel2 15 -#define JP2_SPACE_sRGB 16 -#define JP2_SPACE_sLUM 17 -#define JP2_SPACE_sYCC 18 -#define JP2_SPACE_CIEJab 19 -#define JP2_SPACE_esRGB 20 -#define JP2_SPACE_ROMMRGB 21 -#define JP2_SPACE_YPbPr60 22 -#define JP2_SPACE_YPbPr50 23 -#define JP2_SPACE_esYCC 24 -#define JP2_SPACE_iccLUM 100 -#define JP2_SPACE_iccRGB 101 -#define Icc_INTENT_PERCEPTUAL 0 -#define Icc_INTENT_RELATIVE_COLORIMETRIC 1 -#define Icc_INTENT_SATURATION 2 -#define Icc_INTENT_ABSOLUTE_COLORIMETRIC 3 -#define Icc_FORMAT_DEFAULT 0 -#define Icc_FORMAT_SWAP (1<<10) -#define Icc_FLAGS_DEFAULT 0x0000 -#define Icc_FLAGS_BLACKPOINTCOMPENSATION 0x2000 -#define Icc_FLAGS_NOWHITEONWHITEFIXUP 0x0004 -#define Icc_FLAGS_HIGHRESPRECALC 0x0400 -#define Icc_FLAGS_LOWRESPRECALC 0x0800 -#define Icc_FLAGS_GAMUTCHECK 0x1000 -#define Icc_FLAGS_SOFTPROOFING 0x4000 -#define Icc_PARAMTYPE_NONE 0 -#define Icc_PARAMTYPE_BUFFER 1 -#define Icc_PARAMTYPE_PARAM 2 +#define JP2_SPACE_INVALID -1 +#define JPX_SPACE_INVALID -1 +#define JP2_SPACE_bilevel1 0 +#define JP2_SPACE_YCbCr1 1 +#define JP2_SPACE_YCbCr2 3 +#define JP2_SPACE_YCbCr3 4 +#define JP2_SPACE_PhotoYCC 9 +#define JP2_SPACE_CMY 11 +#define JP2_SPACE_CMYK 12 +#define JP2_SPACE_YCCK 13 +#define JP2_SPACE_CIELab 14 +#define JP2_SPACE_bilevel2 15 +#define JP2_SPACE_sRGB 16 +#define JP2_SPACE_sLUM 17 +#define JP2_SPACE_sYCC 18 +#define JP2_SPACE_CIEJab 19 +#define JP2_SPACE_esRGB 20 +#define JP2_SPACE_ROMMRGB 21 +#define JP2_SPACE_YPbPr60 22 +#define JP2_SPACE_YPbPr50 23 +#define JP2_SPACE_esYCC 24 +#define JP2_SPACE_iccLUM 100 +#define JP2_SPACE_iccRGB 101 +#define Icc_INTENT_PERCEPTUAL 0 +#define Icc_INTENT_RELATIVE_COLORIMETRIC 1 +#define Icc_INTENT_SATURATION 2 +#define Icc_INTENT_ABSOLUTE_COLORIMETRIC 3 +#define Icc_FORMAT_DEFAULT 0 +#define Icc_FORMAT_SWAP (1 << 10) +#define Icc_FLAGS_DEFAULT 0x0000 +#define Icc_FLAGS_BLACKPOINTCOMPENSATION 0x2000 +#define Icc_FLAGS_NOWHITEONWHITEFIXUP 0x0004 +#define Icc_FLAGS_HIGHRESPRECALC 0x0400 +#define Icc_FLAGS_LOWRESPRECALC 0x0800 +#define Icc_FLAGS_GAMUTCHECK 0x1000 +#define Icc_FLAGS_SOFTPROOFING 0x4000 +#define Icc_PARAMTYPE_NONE 0 +#define Icc_PARAMTYPE_BUFFER 1 +#define Icc_PARAMTYPE_PARAM 2 enum FXCODEC_RESUNIT { - FXCODEC_RESUNIT_NONE = 0, - FXCODEC_RESUNIT_INCH, - FXCODEC_RESUNIT_CENTIMETER, - FXCODEC_RESUNIT_METER + FXCODEC_RESUNIT_NONE = 0, + FXCODEC_RESUNIT_INCH, + FXCODEC_RESUNIT_CENTIMETER, + FXCODEC_RESUNIT_METER }; -#define EXIFTAG_USHORT_RESUNIT 296 -#define EXIFTAG_FLOAT_DPIX 282 -#define EXIFTAG_FLOAT_DPIY 283 -#define EXIFTAG_USHORT_ORIENTATION 274 -#define EXIFTAG_STRING_MANUFACTURER 271 -#define EXIFTAG_STRING_MODULE 272 -#define EXIFTAG_STRING_SOFTWARE 305 -#define EXIFTAG_STRING_IAMGEDESCRIPTION 270 -#define EXIFTAG_STRING_DATETIME 306 -#define EXIFTAG_STRING_COPYRIGHT 33432 +#define EXIFTAG_USHORT_RESUNIT 296 +#define EXIFTAG_FLOAT_DPIX 282 +#define EXIFTAG_FLOAT_DPIY 283 +#define EXIFTAG_USHORT_ORIENTATION 274 +#define EXIFTAG_STRING_MANUFACTURER 271 +#define EXIFTAG_STRING_MODULE 272 +#define EXIFTAG_STRING_SOFTWARE 305 +#define EXIFTAG_STRING_IAMGEDESCRIPTION 270 +#define EXIFTAG_STRING_DATETIME 306 +#define EXIFTAG_STRING_COPYRIGHT 33432 #endif // CORE_INCLUDE_FXCODEC_FX_CODEC_DEF_H_ diff --git a/core/include/fxcodec/fx_codec_flate.h b/core/include/fxcodec/fx_codec_flate.h index 8495a37496..7d0106139e 100644 --- a/core/include/fxcodec/fx_codec_flate.h +++ b/core/include/fxcodec/fx_codec_flate.h @@ -13,9 +13,11 @@ extern "C" { // Note: Some of these return Z_* status codes from zlib.h. void* FPDFAPI_FlateInit(void* (*alloc_func)(void*, unsigned int, unsigned int), void (*free_func)(void*, void*)); -void FPDFAPI_FlateInput(void* context, const unsigned char* src_buf, +void FPDFAPI_FlateInput(void* context, + const unsigned char* src_buf, unsigned int src_size); -int FPDFAPI_FlateOutput(void* context, unsigned char* dest_buf, +int FPDFAPI_FlateOutput(void* context, + unsigned char* dest_buf, unsigned int dest_size); int FPDFAPI_FlateGetAvailIn(void* context); int FPDFAPI_FlateGetAvailOut(void* context); diff --git a/core/include/fxcodec/fx_codec_provider.h b/core/include/fxcodec/fx_codec_provider.h index a465fe2460..bd4db44c89 100644 --- a/core/include/fxcodec/fx_codec_provider.h +++ b/core/include/fxcodec/fx_codec_provider.h @@ -11,50 +11,67 @@ class CFX_DIBAttribute; -class IFX_JpegProvider -{ -public: - virtual void Release() = 0; +class IFX_JpegProvider { + public: + virtual void Release() = 0; - virtual void* CreateDecoder(const uint8_t* src_buf, FX_DWORD src_size, int width, int height, int nComps, FX_BOOL ColorTransform) = 0; + virtual void* CreateDecoder(const uint8_t* src_buf, + FX_DWORD src_size, + int width, + int height, + int nComps, + FX_BOOL ColorTransform) = 0; + virtual void DestroyDecoder(void* pDecoder) = 0; - virtual void DestroyDecoder(void* pDecoder) = 0; + virtual void DownScale(void* pDecoder, int dest_width, int dest_height) = 0; - virtual void DownScale(void* pDecoder, int dest_width, int dest_height) = 0; + virtual FX_BOOL Rewind(void* pDecoder) = 0; - virtual FX_BOOL Rewind(void* pDecoder) = 0; + virtual uint8_t* GetNextLine(void* pDecoder) = 0; - virtual uint8_t* GetNextLine(void* pDecoder) = 0; + virtual FX_DWORD GetSrcOffset(void* pDecoder) = 0; - virtual FX_DWORD GetSrcOffset(void* pDecoder) = 0; + virtual FX_BOOL LoadInfo(const uint8_t* src_buf, + FX_DWORD src_size, + int& width, + int& height, + int& num_components, + int& bits_per_components, + FX_BOOL& color_transform, + uint8_t** icc_buf_ptr = NULL, + FX_DWORD* icc_length = NULL) = 0; + virtual FX_BOOL Encode(const class CFX_DIBSource* pSource, + uint8_t*& dest_buf, + FX_STRSIZE& dest_size, + int quality = 75, + const uint8_t* icc_buf = NULL, + FX_DWORD icc_length = 0) = 0; - virtual FX_BOOL LoadInfo(const uint8_t* src_buf, FX_DWORD src_size, int& width, int& height, - int& num_components, int& bits_per_components, FX_BOOL& color_transform, - uint8_t** icc_buf_ptr = NULL, FX_DWORD* icc_length = NULL) = 0; + virtual void* Start() = 0; - virtual FX_BOOL Encode(const class CFX_DIBSource* pSource, uint8_t*& dest_buf, FX_STRSIZE& dest_size, int quality = 75, - const uint8_t* icc_buf = NULL, FX_DWORD icc_length = 0) = 0; + virtual void Finish(void* pContext) = 0; - virtual void* Start() = 0; + virtual void Input(void* pContext, + const uint8_t* src_buf, + FX_DWORD src_size) = 0; - virtual void Finish(void* pContext) = 0; + virtual int ReadHeader(void* pContext, + int* width, + int* height, + int* nComps, + CFX_DIBAttribute* pAttribute = NULL) = 0; - virtual void Input(void* pContext, const uint8_t* src_buf, FX_DWORD src_size) = 0; + virtual int StartScanline(void* pContext, int down_scale) = 0; - virtual int ReadHeader(void* pContext, int* width, int* height, int* nComps, CFX_DIBAttribute* pAttribute = NULL) = 0; + virtual FX_BOOL ReadScanline(void* pContext, uint8_t* dest_buf) = 0; - virtual int StartScanline(void* pContext, int down_scale) = 0; + virtual FX_DWORD GetAvailInput(void* pContext, + uint8_t** avail_buf_ptr = NULL) = 0; - - virtual FX_BOOL ReadScanline(void* pContext, uint8_t* dest_buf) = 0; - - - virtual FX_DWORD GetAvailInput(void* pContext, uint8_t** avail_buf_ptr = NULL) = 0; - -protected: - ~IFX_JpegProvider() { } + protected: + ~IFX_JpegProvider() {} }; #endif // CORE_INCLUDE_FXCODEC_FX_CODEC_PROVIDER_H_ diff --git a/core/include/fxcrt/fx_arb.h b/core/include/fxcrt/fx_arb.h index 3886ac3aae..d3612db4e7 100644 --- a/core/include/fxcrt/fx_arb.h +++ b/core/include/fxcrt/fx_arb.h @@ -13,26 +13,25 @@ class IFX_ArabicChar; class IFX_BidiChar; #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif typedef struct _FX_ARBFORMTABLE { - FX_WCHAR wIsolated; - FX_WCHAR wFinal; - FX_WCHAR wInitial; - FX_WCHAR wMedial; -} FX_ARBFORMTABLE, * FX_LPARBFORMTABLE; -typedef FX_ARBFORMTABLE const * FX_LPCARBFORMTABLE; + FX_WCHAR wIsolated; + FX_WCHAR wFinal; + FX_WCHAR wInitial; + FX_WCHAR wMedial; +} FX_ARBFORMTABLE, *FX_LPARBFORMTABLE; +typedef FX_ARBFORMTABLE const* FX_LPCARBFORMTABLE; typedef struct _FX_ARAALEF { - FX_WCHAR wAlef; - FX_WCHAR wIsolated; -} FX_ARAALEF, * FX_LPARAALEF; -typedef FX_ARAALEF const * FX_LPCARAALEF; + FX_WCHAR wAlef; + FX_WCHAR wIsolated; +} FX_ARAALEF, *FX_LPARAALEF; +typedef FX_ARAALEF const* FX_LPCARAALEF; typedef struct _FX_ARASHADDA { - FX_WCHAR wShadda; - FX_WCHAR wIsolated; -} FX_ARASHADDA, * FX_LPARASHADDA; -typedef FX_ARASHADDA const * FX_LPCARASHADDA; + FX_WCHAR wShadda; + FX_WCHAR wIsolated; +} FX_ARASHADDA, *FX_LPARASHADDA; +typedef FX_ARASHADDA const* FX_LPCARASHADDA; FX_LPCARBFORMTABLE FX_GetArabicFormTable(FX_WCHAR unicode); FX_WCHAR FX_GetArabicFromAlefTable(FX_WCHAR alef); FX_WCHAR FX_GetArabicFromShaddaTable(FX_WCHAR shadda); @@ -40,36 +39,42 @@ FX_WCHAR FX_GetArabicFromShaddaTable(FX_WCHAR shadda); }; #endif enum FX_ARBPOSITION { - FX_ARBPOSITION_Isolated = 0, - FX_ARBPOSITION_Final, - FX_ARBPOSITION_Initial, - FX_ARBPOSITION_Medial, + FX_ARBPOSITION_Isolated = 0, + FX_ARBPOSITION_Final, + FX_ARBPOSITION_Initial, + FX_ARBPOSITION_Medial, }; -class IFX_ArabicChar -{ -public: - static IFX_ArabicChar* Create(); - virtual ~IFX_ArabicChar() {} - virtual void Release() = 0; - virtual FX_BOOL IsArabicChar(FX_WCHAR wch) const = 0; - virtual FX_BOOL IsArabicFormChar(FX_WCHAR wch) const = 0; - virtual FX_WCHAR GetFormChar(FX_WCHAR wch, FX_WCHAR prev = 0, FX_WCHAR next = 0) const = 0; - virtual FX_WCHAR GetFormChar(const CFX_Char *cur, const CFX_Char *prev, const CFX_Char *next) const = 0; +class IFX_ArabicChar { + public: + static IFX_ArabicChar* Create(); + virtual ~IFX_ArabicChar() {} + virtual void Release() = 0; + virtual FX_BOOL IsArabicChar(FX_WCHAR wch) const = 0; + virtual FX_BOOL IsArabicFormChar(FX_WCHAR wch) const = 0; + virtual FX_WCHAR GetFormChar(FX_WCHAR wch, + FX_WCHAR prev = 0, + FX_WCHAR next = 0) const = 0; + virtual FX_WCHAR GetFormChar(const CFX_Char* cur, + const CFX_Char* prev, + const CFX_Char* next) const = 0; }; -void FX_BidiLine(CFX_WideString &wsText, int32_t iBaseLevel = 0); -void FX_BidiLine(CFX_TxtCharArray &chars, int32_t iCount, int32_t iBaseLevel = 0); -void FX_BidiLine(CFX_RTFCharArray &chars, int32_t iCount, int32_t iBaseLevel = 0); -class IFX_BidiChar -{ -public: - static IFX_BidiChar* Create(); - virtual ~IFX_BidiChar() {} +void FX_BidiLine(CFX_WideString& wsText, int32_t iBaseLevel = 0); +void FX_BidiLine(CFX_TxtCharArray& chars, + int32_t iCount, + int32_t iBaseLevel = 0); +void FX_BidiLine(CFX_RTFCharArray& chars, + int32_t iCount, + int32_t iBaseLevel = 0); +class IFX_BidiChar { + public: + static IFX_BidiChar* Create(); + virtual ~IFX_BidiChar() {} - virtual void SetPolicy(FX_BOOL bSeparateNeutral = TRUE) = 0; - virtual FX_BOOL AppendChar(FX_WCHAR wch) = 0; - virtual FX_BOOL EndChar() = 0; - virtual int32_t GetBidiInfo(int32_t &iStart, int32_t &iCount) = 0; - virtual void Reset() = 0; + virtual void SetPolicy(FX_BOOL bSeparateNeutral = TRUE) = 0; + virtual FX_BOOL AppendChar(FX_WCHAR wch) = 0; + virtual FX_BOOL EndChar() = 0; + virtual int32_t GetBidiInfo(int32_t& iStart, int32_t& iCount) = 0; + virtual void Reset() = 0; }; #endif // CORE_INCLUDE_FXCRT_FX_ARB_H_ diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h index dcc1081f44..0079acdd5e 100644 --- a/core/include/fxcrt/fx_basic.h +++ b/core/include/fxcrt/fx_basic.h @@ -25,1609 +25,1375 @@ // Note that the function doesn't need an implementation, as we only // use its type. template <typename T, size_t N> -char (&ArraySizeHelper(T (&array)[N]))[N]; +char(&ArraySizeHelper(T(&array)[N]))[N]; -class CFX_BinaryBuf -{ -public: - CFX_BinaryBuf(); - CFX_BinaryBuf(FX_STRSIZE size); +class CFX_BinaryBuf { + public: + CFX_BinaryBuf(); + CFX_BinaryBuf(FX_STRSIZE size); - ~CFX_BinaryBuf(); + ~CFX_BinaryBuf(); - void Clear(); + void Clear(); - void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0); + void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0); - void AppendBlock(const void* pBuf, FX_STRSIZE size); + void AppendBlock(const void* pBuf, FX_STRSIZE size); - void AppendFill(uint8_t byte, FX_STRSIZE count); + void AppendFill(uint8_t byte, FX_STRSIZE count); - void AppendString(const CFX_ByteStringC& str) - { - AppendBlock(str.GetPtr(), str.GetLength()); - } + void AppendString(const CFX_ByteStringC& str) { + AppendBlock(str.GetPtr(), str.GetLength()); + } - inline void AppendByte(uint8_t byte) - { - if (m_AllocSize <= m_DataSize) { - ExpandBuf(1); - } - m_pBuffer[m_DataSize++] = byte; + inline void AppendByte(uint8_t byte) { + if (m_AllocSize <= m_DataSize) { + ExpandBuf(1); } + m_pBuffer[m_DataSize++] = byte; + } - void InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size); + void InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size); - void AttachData(void* pBuf, FX_STRSIZE size); + void AttachData(void* pBuf, FX_STRSIZE size); - void CopyData(const void* pBuf, FX_STRSIZE size); + void CopyData(const void* pBuf, FX_STRSIZE size); - void TakeOver(CFX_BinaryBuf& other); + void TakeOver(CFX_BinaryBuf& other); - void Delete(int start_index, int count); + void Delete(int start_index, int count); - uint8_t* GetBuffer() const - { - return m_pBuffer; - } + uint8_t* GetBuffer() const { return m_pBuffer; } - FX_STRSIZE GetSize() const - { - return m_DataSize; - } + FX_STRSIZE GetSize() const { return m_DataSize; } - CFX_ByteStringC GetByteString() const; + CFX_ByteStringC GetByteString() const; - void DetachBuffer(); -protected: + void DetachBuffer(); - FX_STRSIZE m_AllocStep; + protected: + FX_STRSIZE m_AllocStep; - uint8_t* m_pBuffer; + uint8_t* m_pBuffer; - FX_STRSIZE m_DataSize; + FX_STRSIZE m_DataSize; - FX_STRSIZE m_AllocSize; + FX_STRSIZE m_AllocSize; - void ExpandBuf(FX_STRSIZE size); + void ExpandBuf(FX_STRSIZE size); }; -class CFX_ByteTextBuf : public CFX_BinaryBuf -{ -public: +class CFX_ByteTextBuf : public CFX_BinaryBuf { + public: + void operator=(const CFX_ByteStringC& str); - void operator = (const CFX_ByteStringC& str); + void AppendChar(int ch) { AppendByte((uint8_t)ch); } - void AppendChar(int ch) - { - AppendByte((uint8_t)ch); - } - - CFX_ByteTextBuf& operator << (int i); + CFX_ByteTextBuf& operator<<(int i); - CFX_ByteTextBuf& operator << (FX_DWORD i); + CFX_ByteTextBuf& operator<<(FX_DWORD i); - CFX_ByteTextBuf& operator << (double f); + CFX_ByteTextBuf& operator<<(double f); - CFX_ByteTextBuf& operator << (const CFX_ByteStringC& lpsz); + CFX_ByteTextBuf& operator<<(const CFX_ByteStringC& lpsz); - CFX_ByteTextBuf& operator << (const CFX_ByteTextBuf& buf); + CFX_ByteTextBuf& operator<<(const CFX_ByteTextBuf& buf); - FX_STRSIZE GetLength() const - { - return m_DataSize; - } + FX_STRSIZE GetLength() const { return m_DataSize; } }; -class CFX_WideTextBuf : public CFX_BinaryBuf -{ -public: +class CFX_WideTextBuf : public CFX_BinaryBuf { + public: + void operator=(const FX_WCHAR* lpsz); - void operator = (const FX_WCHAR* lpsz); + void operator=(const CFX_WideStringC& str); - void operator = (const CFX_WideStringC& str); + void AppendChar(FX_WCHAR wch); - void AppendChar(FX_WCHAR wch); + CFX_WideTextBuf& operator<<(int i); - CFX_WideTextBuf& operator << (int i); + CFX_WideTextBuf& operator<<(double f); - CFX_WideTextBuf& operator << (double f); + CFX_WideTextBuf& operator<<(const FX_WCHAR* lpsz); - CFX_WideTextBuf& operator << (const FX_WCHAR* lpsz); + CFX_WideTextBuf& operator<<(const CFX_WideStringC& str); + CFX_WideTextBuf& operator<<(const CFX_WideString& str); - CFX_WideTextBuf& operator << (const CFX_WideStringC& str); - CFX_WideTextBuf& operator << (const CFX_WideString &str); + CFX_WideTextBuf& operator<<(const CFX_WideTextBuf& buf); - CFX_WideTextBuf& operator << (const CFX_WideTextBuf& buf); + FX_STRSIZE GetLength() const { return m_DataSize / sizeof(FX_WCHAR); } - FX_STRSIZE GetLength() const - { - return m_DataSize / sizeof(FX_WCHAR); - } - - FX_WCHAR* GetBuffer() const - { - return (FX_WCHAR*)m_pBuffer; - } + FX_WCHAR* GetBuffer() const { return (FX_WCHAR*)m_pBuffer; } - void Delete(int start_index, int count) - { - CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), count * sizeof(FX_WCHAR)); - } + void Delete(int start_index, int count) { + CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), + count * sizeof(FX_WCHAR)); + } - CFX_WideStringC GetWideString() const; + CFX_WideStringC GetWideString() const; }; -class CFX_ArchiveSaver -{ -public: - CFX_ArchiveSaver() : m_pStream(NULL) {} +class CFX_ArchiveSaver { + public: + CFX_ArchiveSaver() : m_pStream(NULL) {} - CFX_ArchiveSaver& operator << (uint8_t i); + CFX_ArchiveSaver& operator<<(uint8_t i); - CFX_ArchiveSaver& operator << (int i); + CFX_ArchiveSaver& operator<<(int i); - CFX_ArchiveSaver& operator << (FX_DWORD i); + CFX_ArchiveSaver& operator<<(FX_DWORD i); - CFX_ArchiveSaver& operator << (FX_FLOAT i); + CFX_ArchiveSaver& operator<<(FX_FLOAT i); - CFX_ArchiveSaver& operator << (double i); + CFX_ArchiveSaver& operator<<(double i); - CFX_ArchiveSaver& operator << (const CFX_ByteStringC& bstr); + CFX_ArchiveSaver& operator<<(const CFX_ByteStringC& bstr); - CFX_ArchiveSaver& operator << (const FX_WCHAR* bstr); + CFX_ArchiveSaver& operator<<(const FX_WCHAR* bstr); - CFX_ArchiveSaver& operator << (const CFX_WideString& wstr); + CFX_ArchiveSaver& operator<<(const CFX_WideString& wstr); - void Write(const void* pData, FX_STRSIZE dwSize); + void Write(const void* pData, FX_STRSIZE dwSize); - intptr_t GetLength() - { - return m_SavingBuf.GetSize(); - } + intptr_t GetLength() { return m_SavingBuf.GetSize(); } - const uint8_t* GetBuffer() - { - return m_SavingBuf.GetBuffer(); - } + const uint8_t* GetBuffer() { return m_SavingBuf.GetBuffer(); } - void SetStream(IFX_FileStream* pStream) - { - m_pStream = pStream; - } -protected: + void SetStream(IFX_FileStream* pStream) { m_pStream = pStream; } - CFX_BinaryBuf m_SavingBuf; + protected: + CFX_BinaryBuf m_SavingBuf; - IFX_FileStream* m_pStream; + IFX_FileStream* m_pStream; }; -class CFX_ArchiveLoader -{ -public: +class CFX_ArchiveLoader { + public: + CFX_ArchiveLoader(const uint8_t* pData, FX_DWORD dwSize); - CFX_ArchiveLoader(const uint8_t* pData, FX_DWORD dwSize); + CFX_ArchiveLoader& operator>>(uint8_t& i); - CFX_ArchiveLoader& operator >> (uint8_t& i); + CFX_ArchiveLoader& operator>>(int& i); - CFX_ArchiveLoader& operator >> (int& i); + CFX_ArchiveLoader& operator>>(FX_DWORD& i); - CFX_ArchiveLoader& operator >> (FX_DWORD& i); + CFX_ArchiveLoader& operator>>(FX_FLOAT& i); - CFX_ArchiveLoader& operator >> (FX_FLOAT& i); + CFX_ArchiveLoader& operator>>(double& i); - CFX_ArchiveLoader& operator >> (double& i); + CFX_ArchiveLoader& operator>>(CFX_ByteString& bstr); - CFX_ArchiveLoader& operator >> (CFX_ByteString& bstr); + CFX_ArchiveLoader& operator>>(CFX_WideString& wstr); - CFX_ArchiveLoader& operator >> (CFX_WideString& wstr); + FX_BOOL IsEOF(); - FX_BOOL IsEOF(); + FX_BOOL Read(void* pBuf, FX_DWORD dwSize); - FX_BOOL Read(void* pBuf, FX_DWORD dwSize); -protected: + protected: + FX_DWORD m_LoadingPos; - FX_DWORD m_LoadingPos; - - const uint8_t* m_pLoadingBuf; - - FX_DWORD m_LoadingSize; + const uint8_t* m_pLoadingBuf; + FX_DWORD m_LoadingSize; }; -class IFX_BufferArchive -{ -public: - IFX_BufferArchive(FX_STRSIZE size); - virtual ~IFX_BufferArchive() {} - - virtual void Clear(); - - FX_BOOL Flush(); +class IFX_BufferArchive { + public: + IFX_BufferArchive(FX_STRSIZE size); + virtual ~IFX_BufferArchive() {} - int32_t AppendBlock(const void* pBuf, size_t size); + virtual void Clear(); - int32_t AppendByte(uint8_t byte); + FX_BOOL Flush(); - int32_t AppendDWord(FX_DWORD i); + int32_t AppendBlock(const void* pBuf, size_t size); + int32_t AppendByte(uint8_t byte); - int32_t AppendString(const CFX_ByteStringC& lpsz); + int32_t AppendDWord(FX_DWORD i); -protected: + int32_t AppendString(const CFX_ByteStringC& lpsz); - virtual FX_BOOL DoWork(const void* pBuf, size_t size) = 0; + protected: + virtual FX_BOOL DoWork(const void* pBuf, size_t size) = 0; - FX_STRSIZE m_BufSize; + FX_STRSIZE m_BufSize; - uint8_t* m_pBuffer; + uint8_t* m_pBuffer; - FX_STRSIZE m_Length; + FX_STRSIZE m_Length; }; -class CFX_FileBufferArchive : public IFX_BufferArchive -{ -public: - CFX_FileBufferArchive(FX_STRSIZE size = 32768); - ~CFX_FileBufferArchive() override; +class CFX_FileBufferArchive : public IFX_BufferArchive { + public: + CFX_FileBufferArchive(FX_STRSIZE size = 32768); + ~CFX_FileBufferArchive() override; - void Clear() override; + void Clear() override; - FX_BOOL AttachFile(IFX_StreamWrite *pFile, FX_BOOL bTakeover = FALSE); + FX_BOOL AttachFile(IFX_StreamWrite* pFile, FX_BOOL bTakeover = FALSE); - FX_BOOL AttachFile(const FX_WCHAR* filename); + FX_BOOL AttachFile(const FX_WCHAR* filename); - FX_BOOL AttachFile(const FX_CHAR* filename); + FX_BOOL AttachFile(const FX_CHAR* filename); -private: - FX_BOOL DoWork(const void* pBuf, size_t size) override; + private: + FX_BOOL DoWork(const void* pBuf, size_t size) override; - IFX_StreamWrite* m_pFile; + IFX_StreamWrite* m_pFile; - FX_BOOL m_bTakeover; + FX_BOOL m_bTakeover; }; struct CFX_CharMap { + static CFX_CharMap* GetDefaultMapper(int32_t codepage = 0); - static CFX_CharMap* GetDefaultMapper(int32_t codepage = 0); + CFX_WideString (*m_GetWideString)(CFX_CharMap* pMap, + const CFX_ByteString& bstr); + CFX_ByteString (*m_GetByteString)(CFX_CharMap* pMap, + const CFX_WideString& wstr); - CFX_WideString (*m_GetWideString)(CFX_CharMap* pMap, const CFX_ByteString& bstr); - - CFX_ByteString (*m_GetByteString)(CFX_CharMap* pMap, const CFX_WideString& wstr); - - int32_t (*m_GetCodePage)(); + int32_t (*m_GetCodePage)(); }; -class CFX_UTF8Decoder -{ -public: - CFX_UTF8Decoder() - { - m_PendingBytes = 0; - } +class CFX_UTF8Decoder { + public: + CFX_UTF8Decoder() { m_PendingBytes = 0; } - void Clear(); + void Clear(); - void Input(uint8_t byte); + void Input(uint8_t byte); - void AppendChar(FX_DWORD ch); + void AppendChar(FX_DWORD ch); - void ClearStatus() - { - m_PendingBytes = 0; - } + void ClearStatus() { m_PendingBytes = 0; } - CFX_WideStringC GetResult() const - { - return m_Buffer.GetWideString(); - } -protected: + CFX_WideStringC GetResult() const { return m_Buffer.GetWideString(); } - int m_PendingBytes; + protected: + int m_PendingBytes; - FX_DWORD m_PendingChar; + FX_DWORD m_PendingChar; - CFX_WideTextBuf m_Buffer; + CFX_WideTextBuf m_Buffer; }; -class CFX_UTF8Encoder -{ -public: - CFX_UTF8Encoder() - { - m_UTF16First = 0; - } +class CFX_UTF8Encoder { + public: + CFX_UTF8Encoder() { m_UTF16First = 0; } - void Input(FX_WCHAR unicode); + void Input(FX_WCHAR unicode); - void AppendStr(const CFX_ByteStringC& str) - { - m_UTF16First = 0; - m_Buffer << str; - } + void AppendStr(const CFX_ByteStringC& str) { + m_UTF16First = 0; + m_Buffer << str; + } - CFX_ByteStringC GetResult() const - { - return m_Buffer.GetByteString(); - } -protected: + CFX_ByteStringC GetResult() const { return m_Buffer.GetByteString(); } - CFX_ByteTextBuf m_Buffer; + protected: + CFX_ByteTextBuf m_Buffer; - FX_DWORD m_UTF16First; + FX_DWORD m_UTF16First; }; CFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl); CFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl); CFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI); CFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI); -class CFX_BasicArray -{ -protected: - CFX_BasicArray(int unit_size); +class CFX_BasicArray { + protected: + CFX_BasicArray(int unit_size); - ~CFX_BasicArray(); + ~CFX_BasicArray(); - FX_BOOL SetSize(int nNewSize); + FX_BOOL SetSize(int nNewSize); - FX_BOOL Append(const CFX_BasicArray& src); + FX_BOOL Append(const CFX_BasicArray& src); - FX_BOOL Copy(const CFX_BasicArray& src); + FX_BOOL Copy(const CFX_BasicArray& src); - uint8_t* InsertSpaceAt(int nIndex, int nCount); + uint8_t* InsertSpaceAt(int nIndex, int nCount); - FX_BOOL RemoveAt(int nIndex, int nCount); + FX_BOOL RemoveAt(int nIndex, int nCount); - FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray); + FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray); - const void* GetDataPtr(int index) const; -protected: + const void* GetDataPtr(int index) const; - uint8_t* m_pData; + protected: + uint8_t* m_pData; - int m_nSize; + int m_nSize; - int m_nMaxSize; + int m_nMaxSize; - int m_nUnitSize; + int m_nUnitSize; }; -template<class TYPE> -class CFX_ArrayTemplate : public CFX_BasicArray -{ -public: - CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {} - - int GetSize() const - { - return m_nSize; - } +template <class TYPE> +class CFX_ArrayTemplate : public CFX_BasicArray { + public: + CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {} - int GetUpperBound() const - { - return m_nSize - 1; - } + int GetSize() const { return m_nSize; } - FX_BOOL SetSize(int nNewSize) - { - return CFX_BasicArray::SetSize(nNewSize); - } + int GetUpperBound() const { return m_nSize - 1; } - void RemoveAll() - { - SetSize(0); - } + FX_BOOL SetSize(int nNewSize) { return CFX_BasicArray::SetSize(nNewSize); } - const TYPE GetAt(int nIndex) const - { - if (nIndex < 0 || nIndex >= m_nSize) { - return (const TYPE&)(*(volatile const TYPE*)NULL); - } - return ((const TYPE*)m_pData)[nIndex]; - } + void RemoveAll() { SetSize(0); } - FX_BOOL SetAt(int nIndex, TYPE newElement) - { - if (nIndex < 0 || nIndex >= m_nSize) { - return FALSE; - } - ((TYPE*)m_pData)[nIndex] = newElement; - return TRUE; + const TYPE GetAt(int nIndex) const { + if (nIndex < 0 || nIndex >= m_nSize) { + return (const TYPE&)(*(volatile const TYPE*)NULL); } + return ((const TYPE*)m_pData)[nIndex]; + } - TYPE& ElementAt(int nIndex) - { - if (nIndex < 0 || nIndex >= m_nSize) { - return *(TYPE*)NULL; - } - return ((TYPE*)m_pData)[nIndex]; + FX_BOOL SetAt(int nIndex, TYPE newElement) { + if (nIndex < 0 || nIndex >= m_nSize) { + return FALSE; } + ((TYPE*)m_pData)[nIndex] = newElement; + return TRUE; + } - const TYPE* GetData() const - { - return (const TYPE*)m_pData; + TYPE& ElementAt(int nIndex) { + if (nIndex < 0 || nIndex >= m_nSize) { + return *(TYPE*)NULL; } + return ((TYPE*)m_pData)[nIndex]; + } - TYPE* GetData() - { - return (TYPE*)m_pData; - } + const TYPE* GetData() const { return (const TYPE*)m_pData; } - FX_BOOL SetAtGrow(int nIndex, TYPE newElement) - { - if (nIndex < 0) { - return FALSE; - } - if (nIndex >= m_nSize) - if (!SetSize(nIndex + 1)) { - return FALSE; - } - ((TYPE*)m_pData)[nIndex] = newElement; - return TRUE; - } + TYPE* GetData() { return (TYPE*)m_pData; } - FX_BOOL Add(TYPE newElement) - { - if (m_nSize < m_nMaxSize) { - m_nSize ++; - } else if (!SetSize(m_nSize + 1)) { - return FALSE; - } - ((TYPE*)m_pData)[m_nSize - 1] = newElement; - return TRUE; + FX_BOOL SetAtGrow(int nIndex, TYPE newElement) { + if (nIndex < 0) { + return FALSE; } + if (nIndex >= m_nSize) + if (!SetSize(nIndex + 1)) { + return FALSE; + } + ((TYPE*)m_pData)[nIndex] = newElement; + return TRUE; + } - FX_BOOL Append(const CFX_ArrayTemplate& src) - { - return CFX_BasicArray::Append(src); + FX_BOOL Add(TYPE newElement) { + if (m_nSize < m_nMaxSize) { + m_nSize++; + } else if (!SetSize(m_nSize + 1)) { + return FALSE; } + ((TYPE*)m_pData)[m_nSize - 1] = newElement; + return TRUE; + } - FX_BOOL Copy(const CFX_ArrayTemplate& src) - { - return CFX_BasicArray::Copy(src); - } + FX_BOOL Append(const CFX_ArrayTemplate& src) { + return CFX_BasicArray::Append(src); + } - TYPE* GetDataPtr(int index) - { - return (TYPE*)CFX_BasicArray::GetDataPtr(index); - } + FX_BOOL Copy(const CFX_ArrayTemplate& src) { + return CFX_BasicArray::Copy(src); + } - TYPE* AddSpace() - { - return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1); - } + TYPE* GetDataPtr(int index) { + return (TYPE*)CFX_BasicArray::GetDataPtr(index); + } - TYPE* InsertSpaceAt(int nIndex, int nCount) - { - return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount); - } + TYPE* AddSpace() { return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1); } - const TYPE operator[](int nIndex) const - { - if (nIndex < 0 || nIndex >= m_nSize) { - *(volatile char*)0 = '\0'; - } - return ((const TYPE*)m_pData)[nIndex]; - } + TYPE* InsertSpaceAt(int nIndex, int nCount) { + return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount); + } - TYPE& operator[](int nIndex) - { - if (nIndex < 0 || nIndex >= m_nSize) { - *(volatile char*)0 = '\0'; - } - return ((TYPE*)m_pData)[nIndex]; + const TYPE operator[](int nIndex) const { + if (nIndex < 0 || nIndex >= m_nSize) { + *(volatile char*)0 = '\0'; } + return ((const TYPE*)m_pData)[nIndex]; + } - FX_BOOL InsertAt(int nIndex, TYPE newElement, int nCount = 1) - { - if (!InsertSpaceAt(nIndex, nCount)) { - return FALSE; - } - while (nCount--) { - ((TYPE*)m_pData)[nIndex++] = newElement; - } - return TRUE; + TYPE& operator[](int nIndex) { + if (nIndex < 0 || nIndex >= m_nSize) { + *(volatile char*)0 = '\0'; } + return ((TYPE*)m_pData)[nIndex]; + } - FX_BOOL RemoveAt(int nIndex, int nCount = 1) - { - return CFX_BasicArray::RemoveAt(nIndex, nCount); + FX_BOOL InsertAt(int nIndex, TYPE newElement, int nCount = 1) { + if (!InsertSpaceAt(nIndex, nCount)) { + return FALSE; } - - FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray) - { - return CFX_BasicArray::InsertAt(nStartIndex, pNewArray); + while (nCount--) { + ((TYPE*)m_pData)[nIndex++] = newElement; } + return TRUE; + } - int Find(TYPE data, int iStart = 0) const - { - if (iStart < 0) { - return -1; - } - for (; iStart < (int)m_nSize; iStart ++) - if (((TYPE*)m_pData)[iStart] == data) { - return iStart; - } - return -1; + FX_BOOL RemoveAt(int nIndex, int nCount = 1) { + return CFX_BasicArray::RemoveAt(nIndex, nCount); + } + + FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray) { + return CFX_BasicArray::InsertAt(nStartIndex, pNewArray); + } + + int Find(TYPE data, int iStart = 0) const { + if (iStart < 0) { + return -1; } + for (; iStart < (int)m_nSize; iStart++) + if (((TYPE*)m_pData)[iStart] == data) { + return iStart; + } + return -1; + } }; -typedef CFX_ArrayTemplate<uint8_t> CFX_ByteArray; -typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray; -typedef CFX_ArrayTemplate<FX_DWORD> CFX_DWordArray; -typedef CFX_ArrayTemplate<void*> CFX_PtrArray; -typedef CFX_ArrayTemplate<FX_FILESIZE> CFX_FileSizeArray; -typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray; -typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array; +typedef CFX_ArrayTemplate<uint8_t> CFX_ByteArray; +typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray; +typedef CFX_ArrayTemplate<FX_DWORD> CFX_DWordArray; +typedef CFX_ArrayTemplate<void*> CFX_PtrArray; +typedef CFX_ArrayTemplate<FX_FILESIZE> CFX_FileSizeArray; +typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray; +typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array; template <class ObjectClass> -class CFX_ObjectArray : public CFX_BasicArray -{ -public: - CFX_ObjectArray() : CFX_BasicArray(sizeof(ObjectClass)) {} - - ~CFX_ObjectArray() - { - RemoveAll(); - } +class CFX_ObjectArray : public CFX_BasicArray { + public: + CFX_ObjectArray() : CFX_BasicArray(sizeof(ObjectClass)) {} - void Add(const ObjectClass& data) - { - new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data); - } + ~CFX_ObjectArray() { RemoveAll(); } - ObjectClass& Add() - { - return *(ObjectClass*) new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(); - } + void Add(const ObjectClass& data) { + new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data); + } - void* AddSpace() - { - return InsertSpaceAt(m_nSize, 1); - } + ObjectClass& Add() { + return *(ObjectClass*)new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(); + } - int32_t Append(const CFX_ObjectArray& src, int32_t nStart = 0, int32_t nCount = -1) - { - if (nCount == 0) { - return 0; - } - int32_t nSize = src.GetSize(); - if (!nSize) { - return 0; - } - FXSYS_assert(nStart > -1 && nStart < nSize); - if (nCount < 0) { - nCount = nSize; - } - if (nStart + nCount > nSize) { - nCount = nSize - nStart; - } - if (nCount < 1) { - return 0; - } - nSize = m_nSize; - InsertSpaceAt(m_nSize, nCount); - ObjectClass* pStartObj = (ObjectClass*)GetDataPtr(nSize); - nSize = nStart + nCount; - for (int32_t i = nStart; i < nSize; i ++, pStartObj++) { - new ((void*)pStartObj) ObjectClass(src[i]); - } - return nCount; - } + void* AddSpace() { return InsertSpaceAt(m_nSize, 1); } - int32_t Copy(const CFX_ObjectArray& src, int32_t nStart = 0, int32_t nCount = -1) - { - if (nCount == 0) { - return 0; - } - int32_t nSize = src.GetSize(); - if (!nSize) { - return 0; - } - FXSYS_assert(nStart > -1 && nStart < nSize); - if (nCount < 0) { - nCount = nSize; - } - if (nStart + nCount > nSize) { - nCount = nSize - nStart; - } - if (nCount < 1) { - return 0; - } - RemoveAll(); - SetSize(nCount); - ObjectClass* pStartObj = (ObjectClass*)m_pData; - nSize = nStart + nCount; - for (int32_t i = nStart; i < nSize; i ++, pStartObj++) { - new ((void*)pStartObj) ObjectClass(src[i]); - } - return nCount; + int32_t Append(const CFX_ObjectArray& src, + int32_t nStart = 0, + int32_t nCount = -1) { + if (nCount == 0) { + return 0; } - - int GetSize() const - { - return m_nSize; + int32_t nSize = src.GetSize(); + if (!nSize) { + return 0; } - - ObjectClass& operator[] (int index) const - { - FXSYS_assert(index < m_nSize); - return *(ObjectClass*)CFX_BasicArray::GetDataPtr(index); + FXSYS_assert(nStart > -1 && nStart < nSize); + if (nCount < 0) { + nCount = nSize; } - - ObjectClass* GetDataPtr(int index) - { - return (ObjectClass*)CFX_BasicArray::GetDataPtr(index); + if (nStart + nCount > nSize) { + nCount = nSize - nStart; + } + if (nCount < 1) { + return 0; + } + nSize = m_nSize; + InsertSpaceAt(m_nSize, nCount); + ObjectClass* pStartObj = (ObjectClass*)GetDataPtr(nSize); + nSize = nStart + nCount; + for (int32_t i = nStart; i < nSize; i++, pStartObj++) { + new ((void*)pStartObj) ObjectClass(src[i]); } + return nCount; + } - void RemoveAt(int index) - { - FXSYS_assert(index < m_nSize); - ((ObjectClass*)GetDataPtr(index))->~ObjectClass(); - CFX_BasicArray::RemoveAt(index, 1); + int32_t Copy(const CFX_ObjectArray& src, + int32_t nStart = 0, + int32_t nCount = -1) { + if (nCount == 0) { + return 0; + } + int32_t nSize = src.GetSize(); + if (!nSize) { + return 0; + } + FXSYS_assert(nStart > -1 && nStart < nSize); + if (nCount < 0) { + nCount = nSize; + } + if (nStart + nCount > nSize) { + nCount = nSize - nStart; } + if (nCount < 1) { + return 0; + } + RemoveAll(); + SetSize(nCount); + ObjectClass* pStartObj = (ObjectClass*)m_pData; + nSize = nStart + nCount; + for (int32_t i = nStart; i < nSize; i++, pStartObj++) { + new ((void*)pStartObj) ObjectClass(src[i]); + } + return nCount; + } - void RemoveAll() - { - for (int i = 0; i < m_nSize; i ++) { - ((ObjectClass*)GetDataPtr(i))->~ObjectClass(); - } - CFX_BasicArray::SetSize(0); + int GetSize() const { return m_nSize; } + + ObjectClass& operator[](int index) const { + FXSYS_assert(index < m_nSize); + return *(ObjectClass*)CFX_BasicArray::GetDataPtr(index); + } + + ObjectClass* GetDataPtr(int index) { + return (ObjectClass*)CFX_BasicArray::GetDataPtr(index); + } + + void RemoveAt(int index) { + FXSYS_assert(index < m_nSize); + ((ObjectClass*)GetDataPtr(index))->~ObjectClass(); + CFX_BasicArray::RemoveAt(index, 1); + } + + void RemoveAll() { + for (int i = 0; i < m_nSize; i++) { + ((ObjectClass*)GetDataPtr(i))->~ObjectClass(); } + CFX_BasicArray::SetSize(0); + } }; typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray; typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray; -class CFX_BaseSegmentedArray -{ -public: - CFX_BaseSegmentedArray(int unit_size = 1, int segment_units = 512, int index_size = 8); +class CFX_BaseSegmentedArray { + public: + CFX_BaseSegmentedArray(int unit_size = 1, + int segment_units = 512, + int index_size = 8); - ~CFX_BaseSegmentedArray(); + ~CFX_BaseSegmentedArray(); - void SetUnitSize(int unit_size, int segment_units, int index_size = 8); + void SetUnitSize(int unit_size, int segment_units, int index_size = 8); - void* Add(); + void* Add(); - void* GetAt(int index) const; + void* GetAt(int index) const; - void RemoveAll(); + void RemoveAll(); - void Delete(int index, int count = 1); + void Delete(int index, int count = 1); - int GetSize() const - { - return m_DataSize; - } + int GetSize() const { return m_DataSize; } - int GetSegmentSize() const - { - return m_SegmentSize; - } + int GetSegmentSize() const { return m_SegmentSize; } - int GetUnitSize() const - { - return m_UnitSize; - } + int GetUnitSize() const { return m_UnitSize; } - void* Iterate(FX_BOOL (*callback)(void* param, void* pData), void* param) const; -private: + void* Iterate(FX_BOOL (*callback)(void* param, void* pData), + void* param) const; - int m_UnitSize; + private: + int m_UnitSize; - short m_SegmentSize; + short m_SegmentSize; - uint8_t m_IndexSize; + uint8_t m_IndexSize; - uint8_t m_IndexDepth; + uint8_t m_IndexDepth; - int m_DataSize; + int m_DataSize; - void* m_pIndex; - void** GetIndex(int seg_index) const; - void* IterateIndex(int level, int& start, void** pIndex, FX_BOOL (*callback)(void* param, void* pData), void* param) const; - void* IterateSegment(const uint8_t* pSegment, int count, FX_BOOL (*callback)(void* param, void* pData), void* param) const; + void* m_pIndex; + void** GetIndex(int seg_index) const; + void* IterateIndex(int level, + int& start, + void** pIndex, + FX_BOOL (*callback)(void* param, void* pData), + void* param) const; + void* IterateSegment(const uint8_t* pSegment, + int count, + FX_BOOL (*callback)(void* param, void* pData), + void* param) const; }; template <class ElementType> -class CFX_SegmentedArray : public CFX_BaseSegmentedArray -{ -public: - CFX_SegmentedArray(int segment_units, int index_size = 8) - : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size) - {} - - void Add(ElementType data) - { - *(ElementType*)CFX_BaseSegmentedArray::Add() = data; - } - - ElementType& operator [] (int index) - { - return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index); - } +class CFX_SegmentedArray : public CFX_BaseSegmentedArray { + public: + CFX_SegmentedArray(int segment_units, int index_size = 8) + : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size) { + } + + void Add(ElementType data) { + *(ElementType*)CFX_BaseSegmentedArray::Add() = data; + } + + ElementType& operator[](int index) { + return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index); + } }; template <class DataType, int FixedSize> -class CFX_FixedBufGrow -{ -public: - CFX_FixedBufGrow() : m_pData(NULL) - {} - CFX_FixedBufGrow(int data_size) : m_pData(NULL) - { - if (data_size > FixedSize) { - m_pData = FX_Alloc(DataType, data_size); - } else { - FXSYS_memset(m_Data, 0, sizeof(DataType)*FixedSize); - } - } - void SetDataSize(int data_size) - { - if (m_pData) { - FX_Free(m_pData); - } - m_pData = NULL; - if (data_size > FixedSize) { - m_pData = FX_Alloc(DataType, data_size); - } else { - FXSYS_memset(m_Data, 0, sizeof(DataType)*FixedSize); - } - } - ~CFX_FixedBufGrow() - { - if (m_pData) { - FX_Free(m_pData); - } - } - operator DataType*() - { - return m_pData ? m_pData : m_Data; - } -private: - DataType m_Data[FixedSize]; - DataType* m_pData; +class CFX_FixedBufGrow { + public: + CFX_FixedBufGrow() : m_pData(NULL) {} + CFX_FixedBufGrow(int data_size) : m_pData(NULL) { + if (data_size > FixedSize) { + m_pData = FX_Alloc(DataType, data_size); + } else { + FXSYS_memset(m_Data, 0, sizeof(DataType) * FixedSize); + } + } + void SetDataSize(int data_size) { + if (m_pData) { + FX_Free(m_pData); + } + m_pData = NULL; + if (data_size > FixedSize) { + m_pData = FX_Alloc(DataType, data_size); + } else { + FXSYS_memset(m_Data, 0, sizeof(DataType) * FixedSize); + } + } + ~CFX_FixedBufGrow() { + if (m_pData) { + FX_Free(m_pData); + } + } + operator DataType*() { return m_pData ? m_pData : m_Data; } + + private: + DataType m_Data[FixedSize]; + DataType* m_pData; }; -class CFX_MapPtrToPtr -{ -protected: - - struct CAssoc { +class CFX_MapPtrToPtr { + protected: + struct CAssoc { + CAssoc* pNext; - CAssoc* pNext; + void* key; - void* key; + void* value; + }; - void* value; - }; -public: - CFX_MapPtrToPtr(int nBlockSize = 10); + public: + CFX_MapPtrToPtr(int nBlockSize = 10); - ~CFX_MapPtrToPtr(); + ~CFX_MapPtrToPtr(); - int GetCount() const - { - return m_nCount; - } + int GetCount() const { return m_nCount; } - FX_BOOL IsEmpty() const - { - return m_nCount == 0; - } + FX_BOOL IsEmpty() const { return m_nCount == 0; } - FX_BOOL Lookup(void* key, void*& rValue) const; + FX_BOOL Lookup(void* key, void*& rValue) const; - void* GetValueAt(void* key) const; + void* GetValueAt(void* key) const; - void*& operator[](void* key); + void*& operator[](void* key); - void SetAt(void* key, void* newValue) - { - (*this)[key] = newValue; - } + void SetAt(void* key, void* newValue) { (*this)[key] = newValue; } - FX_BOOL RemoveKey(void* key); + FX_BOOL RemoveKey(void* key); - void RemoveAll(); + void RemoveAll(); - FX_POSITION GetStartPosition() const - { - return (m_nCount == 0) ? NULL : (FX_POSITION) - 1; - } + FX_POSITION GetStartPosition() const { + return (m_nCount == 0) ? NULL : (FX_POSITION)-1; + } - void GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void*& rValue) const; + void GetNextAssoc(FX_POSITION& rNextPosition, + void*& rKey, + void*& rValue) const; - FX_DWORD GetHashTableSize() const - { - return m_nHashTableSize; - } + FX_DWORD GetHashTableSize() const { return m_nHashTableSize; } - void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); -protected: + void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); - CAssoc** m_pHashTable; + protected: + CAssoc** m_pHashTable; - FX_DWORD m_nHashTableSize; + FX_DWORD m_nHashTableSize; - int m_nCount; + int m_nCount; - CAssoc* m_pFreeList; + CAssoc* m_pFreeList; - struct CFX_Plex* m_pBlocks; + struct CFX_Plex* m_pBlocks; - int m_nBlockSize; + int m_nBlockSize; - FX_DWORD HashKey(void* key) const; + FX_DWORD HashKey(void* key) const; - CAssoc* NewAssoc(); + CAssoc* NewAssoc(); - void FreeAssoc(CAssoc* pAssoc); + void FreeAssoc(CAssoc* pAssoc); - CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const; + CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const; }; template <class KeyType, class ValueType> -class CFX_MapPtrTemplate : public CFX_MapPtrToPtr -{ -public: - CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {} - - FX_BOOL Lookup(KeyType key, ValueType& rValue) const - { - void* pValue = NULL; - if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) { - return FALSE; - } - rValue = (ValueType)(uintptr_t)pValue; - return TRUE; - } - - ValueType& operator[](KeyType key) - { - return (ValueType&)CFX_MapPtrToPtr::operator []((void*)(uintptr_t)key); - } - - void SetAt(KeyType key, ValueType newValue) - { - CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue); - } - - FX_BOOL RemoveKey(KeyType key) - { - return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key); - } - - void GetNextAssoc(FX_POSITION& rNextPosition, KeyType& rKey, ValueType& rValue) const - { - void* pKey = NULL; - void* pValue = NULL; - CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue); - rKey = (KeyType)(uintptr_t)pKey; - rValue = (ValueType)(uintptr_t)pValue; - } +class CFX_MapPtrTemplate : public CFX_MapPtrToPtr { + public: + CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {} + + FX_BOOL Lookup(KeyType key, ValueType& rValue) const { + void* pValue = NULL; + if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) { + return FALSE; + } + rValue = (ValueType)(uintptr_t)pValue; + return TRUE; + } + + ValueType& operator[](KeyType key) { + return (ValueType&)CFX_MapPtrToPtr::operator[]((void*)(uintptr_t)key); + } + + void SetAt(KeyType key, ValueType newValue) { + CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue); + } + + FX_BOOL RemoveKey(KeyType key) { + return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key); + } + + void GetNextAssoc(FX_POSITION& rNextPosition, + KeyType& rKey, + ValueType& rValue) const { + void* pKey = NULL; + void* pValue = NULL; + CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue); + rKey = (KeyType)(uintptr_t)pKey; + rValue = (ValueType)(uintptr_t)pValue; + } }; -class CFX_CMapDWordToDWord -{ -public: - - FX_BOOL Lookup(FX_DWORD key, FX_DWORD& value) const; +class CFX_CMapDWordToDWord { + public: + FX_BOOL Lookup(FX_DWORD key, FX_DWORD& value) const; - void SetAt(FX_DWORD key, FX_DWORD value); + void SetAt(FX_DWORD key, FX_DWORD value); - void EstimateSize(FX_DWORD size, FX_DWORD grow_by); + void EstimateSize(FX_DWORD size, FX_DWORD grow_by); - FX_POSITION GetStartPosition() const; + FX_POSITION GetStartPosition() const; - void GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX_DWORD& value) const; -protected: + void GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX_DWORD& value) const; - CFX_BinaryBuf m_Buffer; + protected: + CFX_BinaryBuf m_Buffer; }; -class CFX_MapByteStringToPtr -{ -protected: +class CFX_MapByteStringToPtr { + protected: + struct CAssoc { + CAssoc* pNext; - struct CAssoc { + FX_DWORD nHashValue; - CAssoc* pNext; + CFX_ByteString key; - FX_DWORD nHashValue; + void* value; + }; - CFX_ByteString key; + public: + CFX_MapByteStringToPtr(int nBlockSize = 10); - void* value; - }; -public: - CFX_MapByteStringToPtr(int nBlockSize = 10); + int GetCount() const { return m_nCount; } - int GetCount() const - { - return m_nCount; - } + FX_BOOL IsEmpty() const { return m_nCount == 0; } - FX_BOOL IsEmpty() const - { - return m_nCount == 0; - } + FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue) const; - FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue) const; + void*& operator[](const CFX_ByteStringC& key); - void*& operator[](const CFX_ByteStringC& key); + void SetAt(const CFX_ByteStringC& key, void* newValue) { + (*this)[key] = newValue; + } - void SetAt(const CFX_ByteStringC& key, void* newValue) - { - (*this)[key] = newValue; - } + FX_BOOL RemoveKey(const CFX_ByteStringC& key); - FX_BOOL RemoveKey(const CFX_ByteStringC& key); + void RemoveAll(); - void RemoveAll(); + FX_POSITION GetStartPosition() const { + return (m_nCount == 0) ? NULL : (FX_POSITION)-1; + } - FX_POSITION GetStartPosition() const - { - return (m_nCount == 0) ? NULL : (FX_POSITION) - 1; - } + void GetNextAssoc(FX_POSITION& rNextPosition, + CFX_ByteString& rKey, + void*& rValue) const; - void GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const; + void* GetNextValue(FX_POSITION& rNextPosition) const; - void* GetNextValue(FX_POSITION& rNextPosition) const; + FX_DWORD GetHashTableSize() const { return m_nHashTableSize; } - FX_DWORD GetHashTableSize() const - { - return m_nHashTableSize; - } - - void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); + void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); - FX_DWORD HashKey(const CFX_ByteStringC& key) const; -protected: + FX_DWORD HashKey(const CFX_ByteStringC& key) const; - CAssoc** m_pHashTable; + protected: + CAssoc** m_pHashTable; - FX_DWORD m_nHashTableSize; + FX_DWORD m_nHashTableSize; - int m_nCount; + int m_nCount; - CAssoc* m_pFreeList; + CAssoc* m_pFreeList; - struct CFX_Plex* m_pBlocks; + struct CFX_Plex* m_pBlocks; - int m_nBlockSize; + int m_nBlockSize; - CAssoc* NewAssoc(); + CAssoc* NewAssoc(); - void FreeAssoc(CAssoc* pAssoc); + void FreeAssoc(CAssoc* pAssoc); - CAssoc* GetAssocAt(const CFX_ByteStringC& key, FX_DWORD& hash) const; -public: + CAssoc* GetAssocAt(const CFX_ByteStringC& key, FX_DWORD& hash) const; - ~CFX_MapByteStringToPtr(); + public: + ~CFX_MapByteStringToPtr(); }; -class CFX_CMapByteStringToPtr -{ -public: - CFX_CMapByteStringToPtr(); +class CFX_CMapByteStringToPtr { + public: + CFX_CMapByteStringToPtr(); - ~CFX_CMapByteStringToPtr(); + ~CFX_CMapByteStringToPtr(); - void RemoveAll(); + void RemoveAll(); - FX_POSITION GetStartPosition() const; + FX_POSITION GetStartPosition() const; - void GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const; + void GetNextAssoc(FX_POSITION& rNextPosition, + CFX_ByteString& rKey, + void*& rValue) const; - void* GetNextValue(FX_POSITION& rNextPosition) const; + void* GetNextValue(FX_POSITION& rNextPosition) const; - FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue) const; + FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue) const; - void SetAt(const CFX_ByteStringC& key, void* value); + void SetAt(const CFX_ByteStringC& key, void* value); - void RemoveKey(const CFX_ByteStringC& key); + void RemoveKey(const CFX_ByteStringC& key); - int GetCount() const; + int GetCount() const; - void AddValue(const CFX_ByteStringC& key, void* pValue); -private: + void AddValue(const CFX_ByteStringC& key, void* pValue); - CFX_BaseSegmentedArray m_Buffer; + private: + CFX_BaseSegmentedArray m_Buffer; }; -class CFX_PtrList -{ -protected: +class CFX_PtrList { + protected: + struct CNode { + CNode* pNext; - struct CNode { + CNode* pPrev; - CNode* pNext; + void* data; + }; - CNode* pPrev; + public: + CFX_PtrList(int nBlockSize = 10); - void* data; - }; -public: - CFX_PtrList(int nBlockSize = 10); + FX_POSITION GetHeadPosition() const { return (FX_POSITION)m_pNodeHead; } - FX_POSITION GetHeadPosition() const - { - return (FX_POSITION)m_pNodeHead; - } + FX_POSITION GetTailPosition() const { return (FX_POSITION)m_pNodeTail; } - FX_POSITION GetTailPosition() const - { - return (FX_POSITION)m_pNodeTail; - } - - void* GetNext(FX_POSITION& rPosition) const - { - CNode* pNode = (CNode*) rPosition; - rPosition = (FX_POSITION) pNode->pNext; - return pNode->data; - } + void* GetNext(FX_POSITION& rPosition) const { + CNode* pNode = (CNode*)rPosition; + rPosition = (FX_POSITION)pNode->pNext; + return pNode->data; + } - void* GetPrev(FX_POSITION& rPosition) const - { - CNode* pNode = (CNode*) rPosition; - rPosition = (FX_POSITION) pNode->pPrev; - return pNode->data; - } + void* GetPrev(FX_POSITION& rPosition) const { + CNode* pNode = (CNode*)rPosition; + rPosition = (FX_POSITION)pNode->pPrev; + return pNode->data; + } - FX_POSITION GetNextPosition(FX_POSITION pos) const - { - return ((CNode*)pos)->pNext; - } + FX_POSITION GetNextPosition(FX_POSITION pos) const { + return ((CNode*)pos)->pNext; + } - FX_POSITION GetPrevPosition(FX_POSITION pos) const - { - return ((CNode*)pos)->pPrev; - } + FX_POSITION GetPrevPosition(FX_POSITION pos) const { + return ((CNode*)pos)->pPrev; + } - void* GetAt(FX_POSITION rPosition) const - { - CNode* pNode = (CNode*) rPosition; - return pNode->data; - } + void* GetAt(FX_POSITION rPosition) const { + CNode* pNode = (CNode*)rPosition; + return pNode->data; + } - int GetCount() const - { - return m_nCount; - } + int GetCount() const { return m_nCount; } - FX_POSITION AddTail(void* newElement); + FX_POSITION AddTail(void* newElement); - FX_POSITION AddHead(void* newElement); + FX_POSITION AddHead(void* newElement); - void SetAt(FX_POSITION pos, void* newElement) - { - CNode* pNode = (CNode*) pos; - pNode->data = newElement; - } + void SetAt(FX_POSITION pos, void* newElement) { + CNode* pNode = (CNode*)pos; + pNode->data = newElement; + } - FX_POSITION InsertAfter(FX_POSITION pos, void* newElement); + FX_POSITION InsertAfter(FX_POSITION pos, void* newElement); - FX_POSITION Find(void* searchValue, FX_POSITION startAfter = NULL ) const; + FX_POSITION Find(void* searchValue, FX_POSITION startAfter = NULL) const; - FX_POSITION FindIndex(int index) const; + FX_POSITION FindIndex(int index) const; - void RemoveAt(FX_POSITION pos); + void RemoveAt(FX_POSITION pos); - void RemoveAll(); -protected: + void RemoveAll(); - CNode* m_pNodeHead; + protected: + CNode* m_pNodeHead; - CNode* m_pNodeTail; + CNode* m_pNodeTail; - int m_nCount; + int m_nCount; - CNode* m_pNodeFree; + CNode* m_pNodeFree; - struct CFX_Plex* m_pBlocks; + struct CFX_Plex* m_pBlocks; - int m_nBlockSize; + int m_nBlockSize; - CNode* NewNode(CNode* pPrev, CNode* pNext); + CNode* NewNode(CNode* pPrev, CNode* pNext); - void FreeNode(CNode* pNode); -public: + void FreeNode(CNode* pNode); - ~CFX_PtrList(); + public: + ~CFX_PtrList(); }; typedef void (*PD_CALLBACK_FREEDATA)(void* pData); struct FX_PRIVATEDATA { + void FreeData(); - void FreeData(); - - void* m_pModuleId; + void* m_pModuleId; - void* m_pData; + void* m_pData; - PD_CALLBACK_FREEDATA m_pCallback; + PD_CALLBACK_FREEDATA m_pCallback; - FX_BOOL m_bSelfDestruct; + FX_BOOL m_bSelfDestruct; }; -class CFX_PrivateData -{ -public: +class CFX_PrivateData { + public: + ~CFX_PrivateData(); - ~CFX_PrivateData(); + void ClearAll(); - void ClearAll(); + void SetPrivateData(void* module_id, + void* pData, + PD_CALLBACK_FREEDATA callback); - void SetPrivateData(void* module_id, void* pData, PD_CALLBACK_FREEDATA callback); + void SetPrivateObj(void* module_id, CFX_DestructObject* pObj); - void SetPrivateObj(void* module_id, CFX_DestructObject* pObj); + void* GetPrivateData(void* module_id); - void* GetPrivateData(void* module_id); - - FX_BOOL LookupPrivateData(void* module_id, void* &pData) const - { - if (!module_id) { - return FALSE; - } - FX_DWORD nCount = m_DataList.GetSize(); - for (FX_DWORD n = 0; n < nCount; n ++) { - if (m_DataList[n].m_pModuleId == module_id) { - pData = m_DataList[n].m_pData; - return TRUE; - } - } - return FALSE; + FX_BOOL LookupPrivateData(void* module_id, void*& pData) const { + if (!module_id) { + return FALSE; + } + FX_DWORD nCount = m_DataList.GetSize(); + for (FX_DWORD n = 0; n < nCount; n++) { + if (m_DataList[n].m_pModuleId == module_id) { + pData = m_DataList[n].m_pData; + return TRUE; + } } + return FALSE; + } - FX_BOOL RemovePrivateData(void* module_id); -protected: + FX_BOOL RemovePrivateData(void* module_id); - CFX_ArrayTemplate<FX_PRIVATEDATA> m_DataList; + protected: + CFX_ArrayTemplate<FX_PRIVATEDATA> m_DataList; - void AddData(void* module_id, void* pData, PD_CALLBACK_FREEDATA callback, FX_BOOL bSelfDestruct); + void AddData(void* module_id, + void* pData, + PD_CALLBACK_FREEDATA callback, + FX_BOOL bSelfDestruct); }; -class CFX_BitStream -{ -public: +class CFX_BitStream { + public: + void Init(const uint8_t* pData, FX_DWORD dwSize); - void Init(const uint8_t* pData, FX_DWORD dwSize); + FX_DWORD GetBits(FX_DWORD nBits); + void ByteAlign(); - FX_DWORD GetBits(FX_DWORD nBits); + FX_BOOL IsEOF() { return m_BitPos >= m_BitSize; } - void ByteAlign(); + void SkipBits(FX_DWORD nBits) { m_BitPos += nBits; } - FX_BOOL IsEOF() - { - return m_BitPos >= m_BitSize; - } + void Rewind() { m_BitPos = 0; } - void SkipBits(FX_DWORD nBits) - { - m_BitPos += nBits; - } - - void Rewind() - { - m_BitPos = 0; - } -protected: + protected: + FX_DWORD m_BitPos; - FX_DWORD m_BitPos; + FX_DWORD m_BitSize; - FX_DWORD m_BitSize; - - const uint8_t* m_pData; + const uint8_t* m_pData; }; -template <class ObjClass> class CFX_CountRef -{ -public: - - typedef CFX_CountRef<ObjClass> Ref; +template <class ObjClass> +class CFX_CountRef { + public: + typedef CFX_CountRef<ObjClass> Ref; - class CountedObj : public ObjClass - { - public: + class CountedObj : public ObjClass { + public: + CountedObj() {} - CountedObj() {} + CountedObj(const CountedObj& src) : ObjClass(src) {} - CountedObj(const CountedObj& src) : ObjClass(src) {} + int m_RefCount; + }; - int m_RefCount; - }; + CFX_CountRef() { m_pObject = NULL; } - CFX_CountRef() - { - m_pObject = NULL; + CFX_CountRef(const Ref& ref) { + m_pObject = ref.m_pObject; + if (m_pObject) { + m_pObject->m_RefCount++; } + } - CFX_CountRef(const Ref& ref) - { - m_pObject = ref.m_pObject; - if (m_pObject) { - m_pObject->m_RefCount ++; - } + ~CFX_CountRef() { + if (!m_pObject) { + return; } - - ~CFX_CountRef() - { - if (!m_pObject) { - return; - } - m_pObject->m_RefCount --; - if (m_pObject->m_RefCount <= 0) { - delete m_pObject; - } + m_pObject->m_RefCount--; + if (m_pObject->m_RefCount <= 0) { + delete m_pObject; } + } - ObjClass* New() - { - if (m_pObject) { - m_pObject->m_RefCount --; - if (m_pObject->m_RefCount <= 0) { - delete m_pObject; - } - m_pObject = NULL; - } - m_pObject = FX_NEW CountedObj; - if (!m_pObject) { - return NULL; - } - m_pObject->m_RefCount = 1; - return m_pObject; + ObjClass* New() { + if (m_pObject) { + m_pObject->m_RefCount--; + if (m_pObject->m_RefCount <= 0) { + delete m_pObject; + } + m_pObject = NULL; } - - void operator = (const Ref& ref) - { - if (ref.m_pObject) { - ref.m_pObject->m_RefCount ++; - } - if (m_pObject) { - m_pObject->m_RefCount --; - if (m_pObject->m_RefCount <= 0) { - delete m_pObject; - } - } - m_pObject = ref.m_pObject; + m_pObject = FX_NEW CountedObj; + if (!m_pObject) { + return NULL; } + m_pObject->m_RefCount = 1; + return m_pObject; + } - void operator = (void* p) - { - FXSYS_assert(p == 0); - if (m_pObject == NULL) { - return; - } - m_pObject->m_RefCount --; - if (m_pObject->m_RefCount <= 0) { - delete m_pObject; - } - m_pObject = NULL; + void operator=(const Ref& ref) { + if (ref.m_pObject) { + ref.m_pObject->m_RefCount++; } - - const ObjClass* GetObject() const - { - return m_pObject; + if (m_pObject) { + m_pObject->m_RefCount--; + if (m_pObject->m_RefCount <= 0) { + delete m_pObject; + } } + m_pObject = ref.m_pObject; + } - operator const ObjClass*() const - { - return m_pObject; + void operator=(void* p) { + FXSYS_assert(p == 0); + if (m_pObject == NULL) { + return; } - - FX_BOOL IsNull() const - { - return m_pObject == NULL; + m_pObject->m_RefCount--; + if (m_pObject->m_RefCount <= 0) { + delete m_pObject; } + m_pObject = NULL; + } - FX_BOOL NotNull() const - { - return m_pObject != NULL; - } + const ObjClass* GetObject() const { return m_pObject; } - ObjClass* GetModify() - { - if (m_pObject == NULL) { - m_pObject = FX_NEW CountedObj; - if (m_pObject) { - m_pObject->m_RefCount = 1; - } - } else if (m_pObject->m_RefCount > 1) { - m_pObject->m_RefCount --; - CountedObj* pOldObject = m_pObject; - m_pObject = NULL; - m_pObject = FX_NEW CountedObj(*pOldObject); - if (m_pObject) { - m_pObject->m_RefCount = 1; - } - } - return m_pObject; - } + operator const ObjClass*() const { return m_pObject; } - void SetNull() - { - if (m_pObject == NULL) { - return; - } - m_pObject->m_RefCount --; - if (m_pObject->m_RefCount <= 0) { - delete m_pObject; - } - m_pObject = NULL; + FX_BOOL IsNull() const { return m_pObject == NULL; } + + FX_BOOL NotNull() const { return m_pObject != NULL; } + + ObjClass* GetModify() { + if (m_pObject == NULL) { + m_pObject = FX_NEW CountedObj; + if (m_pObject) { + m_pObject->m_RefCount = 1; + } + } else if (m_pObject->m_RefCount > 1) { + m_pObject->m_RefCount--; + CountedObj* pOldObject = m_pObject; + m_pObject = NULL; + m_pObject = FX_NEW CountedObj(*pOldObject); + if (m_pObject) { + m_pObject->m_RefCount = 1; + } } + return m_pObject; + } - FX_BOOL operator == (const Ref& ref) const - { - return m_pObject == ref.m_pObject; + void SetNull() { + if (m_pObject == NULL) { + return; + } + m_pObject->m_RefCount--; + if (m_pObject->m_RefCount <= 0) { + delete m_pObject; } -protected: + m_pObject = NULL; + } + + FX_BOOL operator==(const Ref& ref) const { + return m_pObject == ref.m_pObject; + } - CountedObj* m_pObject; + protected: + CountedObj* m_pObject; }; -class IFX_Pause -{ -public: - virtual ~IFX_Pause() { } - virtual FX_BOOL NeedToPauseNow() = 0; +class IFX_Pause { + public: + virtual ~IFX_Pause() {} + virtual FX_BOOL NeedToPauseNow() = 0; }; -class CFX_DataFilter -{ -public: +class CFX_DataFilter { + public: + virtual ~CFX_DataFilter(); - virtual ~CFX_DataFilter(); + void SetDestFilter(CFX_DataFilter* pFilter); - void SetDestFilter(CFX_DataFilter* pFilter); + FX_BOOL IsEOF() const { return m_bEOF; } - FX_BOOL IsEOF() const - { - return m_bEOF; - } - - FX_DWORD GetSrcPos() - { - return m_SrcPos; - } + FX_DWORD GetSrcPos() { return m_SrcPos; } - void FilterIn(const uint8_t* src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf); + void FilterIn(const uint8_t* src_buf, + FX_DWORD src_size, + CFX_BinaryBuf& dest_buf); - void FilterFinish(CFX_BinaryBuf& dest_buf); -protected: + void FilterFinish(CFX_BinaryBuf& dest_buf); - CFX_DataFilter(); - virtual void v_FilterIn(const uint8_t* src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf) = 0; - virtual void v_FilterFinish(CFX_BinaryBuf& dest_buf) = 0; - void ReportEOF(FX_DWORD left_input); + protected: + CFX_DataFilter(); + virtual void v_FilterIn(const uint8_t* src_buf, + FX_DWORD src_size, + CFX_BinaryBuf& dest_buf) = 0; + virtual void v_FilterFinish(CFX_BinaryBuf& dest_buf) = 0; + void ReportEOF(FX_DWORD left_input); - FX_BOOL m_bEOF; + FX_BOOL m_bEOF; - FX_DWORD m_SrcPos; + FX_DWORD m_SrcPos; - CFX_DataFilter* m_pDestFilter; + CFX_DataFilter* m_pDestFilter; }; -template<typename T> +template <typename T> class CFX_AutoRestorer { -public: - explicit CFX_AutoRestorer(T* location) { - m_Location = location; - m_OldValue = *location; - } - ~CFX_AutoRestorer() { *m_Location = m_OldValue; } - -private: + public: + explicit CFX_AutoRestorer(T* location) { + m_Location = location; + m_OldValue = *location; + } + ~CFX_AutoRestorer() { *m_Location = m_OldValue; } + + private: T* m_Location; T m_OldValue; }; template <class T> -class CFX_SmartPointer -{ -public: - CFX_SmartPointer(T *pObj) : m_pObj(pObj) {} - ~CFX_SmartPointer() - { - m_pObj->Release(); - } - T* Get(void) - { - return m_pObj; - } - T& operator *(void) - { - return *m_pObj; - } - T* operator ->(void) - { - return m_pObj; - } -protected: - T *m_pObj; +class CFX_SmartPointer { + public: + CFX_SmartPointer(T* pObj) : m_pObj(pObj) {} + ~CFX_SmartPointer() { m_pObj->Release(); } + T* Get(void) { return m_pObj; } + T& operator*(void) { return *m_pObj; } + T* operator->(void) { return m_pObj; } + + protected: + T* m_pObj; }; -#define FX_DATALIST_LENGTH 1024 -template<size_t unit> -class CFX_SortListArray -{ -protected: - - struct DataList { - - int32_t start; - - int32_t count; - uint8_t* data; - }; -public: - - CFX_SortListArray() : m_CurList(0) {} - - ~CFX_SortListArray() - { - Clear(); - } - - - void Clear() - { - for (int32_t i = m_DataLists.GetUpperBound(); i >= 0; i--) { - DataList list = m_DataLists.ElementAt(i); - if (list.data) { - FX_Free(list.data); - } - } - m_DataLists.RemoveAll(); - m_CurList = 0; - } - - void Append(int32_t nStart, int32_t nCount) - { - if (nStart < 0) { - return; - } - while (nCount > 0) { - int32_t temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH); - DataList list; - list.data = FX_Alloc2D(uint8_t, temp_count, unit); - list.start = nStart; - list.count = temp_count; - Append(list); - nCount -= temp_count; - nStart += temp_count; - } - } - - uint8_t* GetAt(int32_t nIndex) - { - if (nIndex < 0) { - return NULL; - } - if (m_CurList < 0 || m_CurList >= m_DataLists.GetSize()) { - return NULL; +#define FX_DATALIST_LENGTH 1024 +template <size_t unit> +class CFX_SortListArray { + protected: + struct DataList { + int32_t start; + + int32_t count; + uint8_t* data; + }; + + public: + CFX_SortListArray() : m_CurList(0) {} + + ~CFX_SortListArray() { Clear(); } + + void Clear() { + for (int32_t i = m_DataLists.GetUpperBound(); i >= 0; i--) { + DataList list = m_DataLists.ElementAt(i); + if (list.data) { + FX_Free(list.data); + } + } + m_DataLists.RemoveAll(); + m_CurList = 0; + } + + void Append(int32_t nStart, int32_t nCount) { + if (nStart < 0) { + return; + } + while (nCount > 0) { + int32_t temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH); + DataList list; + list.data = FX_Alloc2D(uint8_t, temp_count, unit); + list.start = nStart; + list.count = temp_count; + Append(list); + nCount -= temp_count; + nStart += temp_count; + } + } + + uint8_t* GetAt(int32_t nIndex) { + if (nIndex < 0) { + return NULL; + } + if (m_CurList < 0 || m_CurList >= m_DataLists.GetSize()) { + return NULL; + } + DataList* pCurList = m_DataLists.GetDataPtr(m_CurList); + if (!pCurList || nIndex < pCurList->start || + nIndex >= pCurList->start + pCurList->count) { + pCurList = NULL; + int32_t iStart = 0; + int32_t iEnd = m_DataLists.GetUpperBound(); + int32_t iMid = 0; + while (iStart <= iEnd) { + iMid = (iStart + iEnd) / 2; + DataList* list = m_DataLists.GetDataPtr(iMid); + if (nIndex < list->start) { + iEnd = iMid - 1; + } else if (nIndex >= list->start + list->count) { + iStart = iMid + 1; + } else { + pCurList = list; + m_CurList = iMid; + break; } - DataList *pCurList = m_DataLists.GetDataPtr(m_CurList); - if (!pCurList || nIndex < pCurList->start || nIndex >= pCurList->start + pCurList->count) { - pCurList = NULL; - int32_t iStart = 0; - int32_t iEnd = m_DataLists.GetUpperBound(); - int32_t iMid = 0; - while (iStart <= iEnd) { - iMid = (iStart + iEnd) / 2; - DataList* list = m_DataLists.GetDataPtr(iMid); - if (nIndex < list->start) { - iEnd = iMid - 1; - } else if (nIndex >= list->start + list->count) { - iStart = iMid + 1; - } else { - pCurList = list; - m_CurList = iMid; - break; - } - } + } + } + return pCurList ? pCurList->data + (nIndex - pCurList->start) * unit : NULL; + } + + protected: + void Append(const DataList& list) { + int32_t iStart = 0; + int32_t iEnd = m_DataLists.GetUpperBound(); + int32_t iFind = 0; + while (iStart <= iEnd) { + int32_t iMid = (iStart + iEnd) / 2; + DataList* cur_list = m_DataLists.GetDataPtr(iMid); + if (list.start < cur_list->start + cur_list->count) { + iEnd = iMid - 1; + } else { + if (iMid == iEnd) { + iFind = iMid + 1; + break; } - return pCurList ? pCurList->data + (nIndex - pCurList->start) * unit : NULL; - } -protected: - void Append(const DataList& list) - { - int32_t iStart = 0; - int32_t iEnd = m_DataLists.GetUpperBound(); - int32_t iFind = 0; - while (iStart <= iEnd) { - int32_t iMid = (iStart + iEnd) / 2; - DataList* cur_list = m_DataLists.GetDataPtr(iMid); - if (list.start < cur_list->start + cur_list->count) { - iEnd = iMid - 1; - } else { - if (iMid == iEnd) { - iFind = iMid + 1; - break; - } - DataList* next_list = m_DataLists.GetDataPtr(iMid + 1); - if (list.start < next_list->start) { - iFind = iMid + 1; - break; - } else { - iStart = iMid + 1; - } - } + DataList* next_list = m_DataLists.GetDataPtr(iMid + 1); + if (list.start < next_list->start) { + iFind = iMid + 1; + break; + } else { + iStart = iMid + 1; } - m_DataLists.InsertAt(iFind, list); + } } - int32_t m_CurList; - CFX_ArrayTemplate<DataList> m_DataLists; + m_DataLists.InsertAt(iFind, list); + } + int32_t m_CurList; + CFX_ArrayTemplate<DataList> m_DataLists; }; -template<typename T1, typename T2> -class CFX_ListArrayTemplate -{ -public: - - void Clear() - { - m_Data.Clear(); - } +template <typename T1, typename T2> +class CFX_ListArrayTemplate { + public: + void Clear() { m_Data.Clear(); } - void Add(int32_t nStart, int32_t nCount) - { - m_Data.Append(nStart, nCount); - } + void Add(int32_t nStart, int32_t nCount) { m_Data.Append(nStart, nCount); } - T2& operator [] (int32_t nIndex) - { - uint8_t* data = m_Data.GetAt(nIndex); - FXSYS_assert(data != NULL); - return (T2&)(*(volatile T2*)data); - } + T2& operator[](int32_t nIndex) { + uint8_t* data = m_Data.GetAt(nIndex); + FXSYS_assert(data != NULL); + return (T2&)(*(volatile T2*)data); + } - T2* GetPtrAt(int32_t nIndex) - { - return (T2*)m_Data.GetAt(nIndex); - } -protected: - T1 m_Data; + T2* GetPtrAt(int32_t nIndex) { return (T2*)m_Data.GetAt(nIndex); } + + protected: + T1 m_Data; }; -typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_FILESIZE)>, FX_FILESIZE> CFX_FileSizeListArray; -typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_DWORD)>, FX_DWORD> CFX_DWordListArray; +typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_FILESIZE)>, + FX_FILESIZE> CFX_FileSizeListArray; +typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_DWORD)>, FX_DWORD> + CFX_DWordListArray; typedef enum { - Ready, - ToBeContinued, - Found, - NotFound, - Failed, - Done + Ready, + ToBeContinued, + Found, + NotFound, + Failed, + Done } FX_ProgressiveStatus; -#define ProgressiveStatus FX_ProgressiveStatus -#define FX_NAMESPACE_DECLARE(namespace, type) namespace::type -class IFX_Unknown -{ -public: - virtual ~IFX_Unknown() {} - virtual FX_DWORD Release() = 0; - virtual FX_DWORD AddRef() = 0; +#define ProgressiveStatus FX_ProgressiveStatus +#define FX_NAMESPACE_DECLARE(namespace, type) namespace ::type +class IFX_Unknown { + public: + virtual ~IFX_Unknown() {} + virtual FX_DWORD Release() = 0; + virtual FX_DWORD AddRef() = 0; }; -#define FX_IsOdd(a) ((a) & 1) - -class CFX_Vector_3by1 -{ -public: +#define FX_IsOdd(a) ((a)&1) - CFX_Vector_3by1() : - a(0.0f), b(0.0f), c(0.0f) - {} +class CFX_Vector_3by1 { + public: + CFX_Vector_3by1() : a(0.0f), b(0.0f), c(0.0f) {} - CFX_Vector_3by1(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1): - a(a1), b(b1), c(c1) - {} + CFX_Vector_3by1(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1) + : a(a1), b(b1), c(c1) {} - FX_FLOAT a; - FX_FLOAT b; - FX_FLOAT c; + FX_FLOAT a; + FX_FLOAT b; + FX_FLOAT c; }; -class CFX_Matrix_3by3 -{ -public: - - CFX_Matrix_3by3(): - a(0.0f), b(0.0f), c(0.0f), d(0.0f), e(0.0f), f(0.0f), g(0.0f), h(0.0f), i(0.0f) - {} - - CFX_Matrix_3by3(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1, FX_FLOAT d1, FX_FLOAT e1, FX_FLOAT f1, FX_FLOAT g1, FX_FLOAT h1, FX_FLOAT i1) : - a(a1), b(b1), c(c1), d(d1), e(e1), f(f1), g(g1), h(h1), i(i1) - {} - - CFX_Matrix_3by3 Inverse(); - - CFX_Matrix_3by3 Multiply(const CFX_Matrix_3by3 &m); - - CFX_Vector_3by1 TransformVector(const CFX_Vector_3by1 &v); - - FX_FLOAT a; - FX_FLOAT b; - FX_FLOAT c; - FX_FLOAT d; - FX_FLOAT e; - FX_FLOAT f; - FX_FLOAT g; - FX_FLOAT h; - FX_FLOAT i; +class CFX_Matrix_3by3 { + public: + CFX_Matrix_3by3() + : a(0.0f), + b(0.0f), + c(0.0f), + d(0.0f), + e(0.0f), + f(0.0f), + g(0.0f), + h(0.0f), + i(0.0f) {} + + CFX_Matrix_3by3(FX_FLOAT a1, + FX_FLOAT b1, + FX_FLOAT c1, + FX_FLOAT d1, + FX_FLOAT e1, + FX_FLOAT f1, + FX_FLOAT g1, + FX_FLOAT h1, + FX_FLOAT i1) + : a(a1), b(b1), c(c1), d(d1), e(e1), f(f1), g(g1), h(h1), i(i1) {} + + CFX_Matrix_3by3 Inverse(); + + CFX_Matrix_3by3 Multiply(const CFX_Matrix_3by3& m); + + CFX_Vector_3by1 TransformVector(const CFX_Vector_3by1& v); + + FX_FLOAT a; + FX_FLOAT b; + FX_FLOAT c; + FX_FLOAT d; + FX_FLOAT e; + FX_FLOAT f; + FX_FLOAT g; + FX_FLOAT h; + FX_FLOAT i; }; #endif // CORE_INCLUDE_FXCRT_FX_BASIC_H_ diff --git a/core/include/fxcrt/fx_coordinates.h b/core/include/fxcrt/fx_coordinates.h index 3689a4b270..ddd0f572c8 100644 --- a/core/include/fxcrt/fx_coordinates.h +++ b/core/include/fxcrt/fx_coordinates.h @@ -9,905 +9,744 @@ #include "fx_basic.h" -template<class baseType> class CFX_PSVTemplate; -template<class baseType> class CFX_VTemplate; -template<class baseType> class CFX_PRLTemplate; -template<class baseType> class CFX_RTemplate; -template<class baseType> class CFX_ETemplate; -template<class baseType> class CFX_ATemplate; -template<class baseType> class CFX_RRTemplate; +template <class baseType> +class CFX_PSVTemplate; +template <class baseType> +class CFX_VTemplate; +template <class baseType> +class CFX_PRLTemplate; +template <class baseType> +class CFX_RTemplate; +template <class baseType> +class CFX_ETemplate; +template <class baseType> +class CFX_ATemplate; +template <class baseType> +class CFX_RRTemplate; class CFX_Matrix; -template<class baseType> -class CFX_PSVTemplate -{ -public: - typedef CFX_PSVTemplate<baseType> FXT_PSV; - typedef CFX_PSVTemplate<baseType> FXT_POINT; - typedef CFX_PSVTemplate<baseType> FXT_SIZE; - void Set(baseType x, baseType y) - { - FXT_PSV::x = x, FXT_PSV::y = y; - } - void Set(const FXT_PSV &psv) - { - FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; - } - void Add(baseType x, baseType y) - { - FXT_PSV::x += x, FXT_PSV::y += y; - } - void Subtract(baseType x, baseType y) - { - FXT_PSV::x -= x, FXT_PSV::y -= y; - } - void Reset() - { - FXT_PSV::x = FXT_PSV::y = 0; - } - FXT_PSV& operator += (const FXT_PSV &obj) - { - x += obj.x; - y += obj.y; - return *this; - } - FXT_PSV& operator -= (const FXT_PSV &obj) - { - x -= obj.x; - y -= obj.y; - return *this; - } - FXT_PSV& operator *= (baseType lamda) - { - x *= lamda; - y *= lamda; - return *this; - } - FXT_PSV& operator /= (baseType lamda) - { - x /= lamda; - y /= lamda; - return *this; - } - friend FX_BOOL operator == (const FXT_PSV &obj1, const FXT_PSV &obj2) - { - return obj1.x == obj2.x && obj1.y == obj2.y; - } - friend FX_BOOL operator != (const FXT_PSV &obj1, const FXT_PSV &obj2) - { - return obj1.x != obj2.x || obj1.y != obj2.y; - } - friend FXT_PSV operator + (const FXT_PSV &obj1, const FXT_PSV &obj2) - { - CFX_PSVTemplate obj; - obj.x = obj1.x + obj2.x; - obj.y = obj1.y + obj2.y; - return obj; - } - friend FXT_PSV operator - (const FXT_PSV &obj1, const FXT_PSV &obj2) - { - CFX_PSVTemplate obj; - obj.x = obj1.x - obj2.x; - obj.y = obj1.y - obj2.y; - return obj; - } - friend FXT_PSV operator * (const FXT_PSV &obj, baseType lamda) - { - CFX_PSVTemplate t; - t.x = obj.x * lamda; - t.y = obj.y * lamda; - return t; - } - friend FXT_PSV operator * (baseType lamda, const FXT_PSV &obj) - { - CFX_PSVTemplate t; - t.x = lamda * obj.x; - t.y = lamda * obj.y; - return t; - } - friend FXT_PSV operator / (const FXT_PSV &obj, baseType lamda) - { - CFX_PSVTemplate t; - t.x = obj.x / lamda; - t.y = obj.y / lamda; - return t; - } - baseType x, y; +template <class baseType> +class CFX_PSVTemplate { + public: + typedef CFX_PSVTemplate<baseType> FXT_PSV; + typedef CFX_PSVTemplate<baseType> FXT_POINT; + typedef CFX_PSVTemplate<baseType> FXT_SIZE; + void Set(baseType x, baseType y) { FXT_PSV::x = x, FXT_PSV::y = y; } + void Set(const FXT_PSV& psv) { FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; } + void Add(baseType x, baseType y) { FXT_PSV::x += x, FXT_PSV::y += y; } + void Subtract(baseType x, baseType y) { FXT_PSV::x -= x, FXT_PSV::y -= y; } + void Reset() { FXT_PSV::x = FXT_PSV::y = 0; } + FXT_PSV& operator+=(const FXT_PSV& obj) { + x += obj.x; + y += obj.y; + return *this; + } + FXT_PSV& operator-=(const FXT_PSV& obj) { + x -= obj.x; + y -= obj.y; + return *this; + } + FXT_PSV& operator*=(baseType lamda) { + x *= lamda; + y *= lamda; + return *this; + } + FXT_PSV& operator/=(baseType lamda) { + x /= lamda; + y /= lamda; + return *this; + } + friend FX_BOOL operator==(const FXT_PSV& obj1, const FXT_PSV& obj2) { + return obj1.x == obj2.x && obj1.y == obj2.y; + } + friend FX_BOOL operator!=(const FXT_PSV& obj1, const FXT_PSV& obj2) { + return obj1.x != obj2.x || obj1.y != obj2.y; + } + friend FXT_PSV operator+(const FXT_PSV& obj1, const FXT_PSV& obj2) { + CFX_PSVTemplate obj; + obj.x = obj1.x + obj2.x; + obj.y = obj1.y + obj2.y; + return obj; + } + friend FXT_PSV operator-(const FXT_PSV& obj1, const FXT_PSV& obj2) { + CFX_PSVTemplate obj; + obj.x = obj1.x - obj2.x; + obj.y = obj1.y - obj2.y; + return obj; + } + friend FXT_PSV operator*(const FXT_PSV& obj, baseType lamda) { + CFX_PSVTemplate t; + t.x = obj.x * lamda; + t.y = obj.y * lamda; + return t; + } + friend FXT_PSV operator*(baseType lamda, const FXT_PSV& obj) { + CFX_PSVTemplate t; + t.x = lamda * obj.x; + t.y = lamda * obj.y; + return t; + } + friend FXT_PSV operator/(const FXT_PSV& obj, baseType lamda) { + CFX_PSVTemplate t; + t.x = obj.x / lamda; + t.y = obj.y / lamda; + return t; + } + baseType x, y; }; -typedef CFX_PSVTemplate<int32_t> CFX_Point; -typedef CFX_PSVTemplate<FX_FLOAT> CFX_PointF; -typedef CFX_PSVTemplate<int32_t> CFX_Size; -typedef CFX_PSVTemplate<FX_FLOAT> CFX_SizeF; -typedef CFX_ArrayTemplate<CFX_Point> CFX_Points; -typedef CFX_ArrayTemplate<CFX_PointF> CFX_PointsF; -typedef CFX_PSVTemplate<int32_t> * FX_LPPOINT; -typedef CFX_PSVTemplate<FX_FLOAT> * FX_LPPOINTF; -typedef CFX_PSVTemplate<int32_t> const * FX_LPCPOINT; -typedef CFX_PSVTemplate<FX_FLOAT> const * FX_LPCPOINTF; -#define CFX_FloatPoint CFX_PointF -template<class baseType> -class CFX_VTemplate: public CFX_PSVTemplate<baseType> -{ -public: - typedef CFX_PSVTemplate<baseType> FXT_PSV; - typedef CFX_PSVTemplate<baseType> FXT_POINT; - typedef CFX_PSVTemplate<baseType> FXT_SIZE; - typedef CFX_VTemplate<baseType> FXT_VECTOR; - void Set(baseType newx, baseType newy) - { - FXT_PSV::x = newx; - FXT_PSV::y = newy; - } - void Set(const FXT_PSV &psv) - { - FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; - } - void Set(const FXT_POINT &p1, const FXT_POINT &p2) - { - FXT_PSV::x = p2.x - p1.x, FXT_PSV::y = p2.y - p1.y; - } - void Reset() - { - FXT_PSV::x = FXT_PSV::y = 0; - } - baseType SquareLength() const - { - return FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y; - } - baseType Length() const - { - return FXSYS_sqrt(FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y); - } - void Normalize() - { - FX_FLOAT fLen = FXSYS_sqrt(FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y); - if (fLen < 0.0001f) { - return; - } - FXT_PSV::x = ((baseType)FXT_PSV::x) / fLen; - FXT_PSV::y = ((baseType)FXT_PSV::y) / fLen; - } - baseType DotProduct(baseType otherx, baseType othery) const - { - return FXT_PSV::x * otherx + FXT_PSV::y * othery; - } - baseType DotProduct(const FXT_VECTOR &v) const - { - return FXT_PSV::x * v.x + FXT_PSV::y * v.y; - } - FX_BOOL IsParallel(baseType otherx, baseType othery) const - { - baseType t = FXT_PSV::x * othery - FXT_PSV::y * otherx; - return FXSYS_fabs(t) < 0x0001f; - } - FX_BOOL IsParallel(const FXT_VECTOR &v) const - { - return IsParallel(v.x, v.y); - } - FX_BOOL IsPerpendicular(baseType otherx, baseType othery) const - { - baseType t = DotProduct(otherx, othery); - return FXSYS_fabs(t) < 0x0001f; - } - FX_BOOL IsPerpendicular(const FXT_VECTOR &v) const - { - return IsPerpendicular(v.x, v.y); - } - void Translate(baseType dx, baseType dy) - { - FXT_PSV::x += dx, FXT_PSV::y += dy; - } - void Scale(baseType sx, baseType sy) - { - FXT_PSV::x *= sx, FXT_PSV::y *= sy; - } - void Rotate(FX_FLOAT fRadian) - { - FX_FLOAT xx = (FX_FLOAT)FXT_PSV::x; - FX_FLOAT yy = (FX_FLOAT)FXT_PSV::y; - FX_FLOAT cosValue = FXSYS_cos(fRadian); - FX_FLOAT sinValue = FXSYS_sin(fRadian); - FXT_PSV::x = xx * cosValue - yy * sinValue; - FXT_PSV::y = xx * sinValue + yy * cosValue; - } - friend FX_FLOAT Cosine(const FXT_VECTOR &v1, const FXT_VECTOR &v2) - { - FXSYS_assert(v1.SquareLength() != 0 && v2.SquareLength() != 0); - FX_FLOAT dotProduct = v1.DotProduct(v2); - return dotProduct / (FX_FLOAT)FXSYS_sqrt(v1.SquareLength() * v2.SquareLength()); - } - friend FX_FLOAT ArcCosine(const FXT_VECTOR &v1, const FXT_VECTOR &v2) - { - return (FX_FLOAT)FXSYS_acos(Cosine(v1, v2)); - } - friend FX_FLOAT SlopeAngle(const FXT_VECTOR &v) - { - CFX_VTemplate vx; - vx.Set(1, 0); - FX_FLOAT fSlope = ArcCosine(v, vx); - return v.y < 0 ? -fSlope : fSlope; - } +typedef CFX_PSVTemplate<int32_t> CFX_Point; +typedef CFX_PSVTemplate<FX_FLOAT> CFX_PointF; +typedef CFX_PSVTemplate<int32_t> CFX_Size; +typedef CFX_PSVTemplate<FX_FLOAT> CFX_SizeF; +typedef CFX_ArrayTemplate<CFX_Point> CFX_Points; +typedef CFX_ArrayTemplate<CFX_PointF> CFX_PointsF; +typedef CFX_PSVTemplate<int32_t>* FX_LPPOINT; +typedef CFX_PSVTemplate<FX_FLOAT>* FX_LPPOINTF; +typedef CFX_PSVTemplate<int32_t> const* FX_LPCPOINT; +typedef CFX_PSVTemplate<FX_FLOAT> const* FX_LPCPOINTF; +#define CFX_FloatPoint CFX_PointF +template <class baseType> +class CFX_VTemplate : public CFX_PSVTemplate<baseType> { + public: + typedef CFX_PSVTemplate<baseType> FXT_PSV; + typedef CFX_PSVTemplate<baseType> FXT_POINT; + typedef CFX_PSVTemplate<baseType> FXT_SIZE; + typedef CFX_VTemplate<baseType> FXT_VECTOR; + void Set(baseType newx, baseType newy) { + FXT_PSV::x = newx; + FXT_PSV::y = newy; + } + void Set(const FXT_PSV& psv) { FXT_PSV::x = psv.x, FXT_PSV::y = psv.y; } + void Set(const FXT_POINT& p1, const FXT_POINT& p2) { + FXT_PSV::x = p2.x - p1.x, FXT_PSV::y = p2.y - p1.y; + } + void Reset() { FXT_PSV::x = FXT_PSV::y = 0; } + baseType SquareLength() const { + return FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y; + } + baseType Length() const { + return FXSYS_sqrt(FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y); + } + void Normalize() { + FX_FLOAT fLen = + FXSYS_sqrt(FXT_PSV::x * FXT_PSV::x + FXT_PSV::y * FXT_PSV::y); + if (fLen < 0.0001f) { + return; + } + FXT_PSV::x = ((baseType)FXT_PSV::x) / fLen; + FXT_PSV::y = ((baseType)FXT_PSV::y) / fLen; + } + baseType DotProduct(baseType otherx, baseType othery) const { + return FXT_PSV::x * otherx + FXT_PSV::y * othery; + } + baseType DotProduct(const FXT_VECTOR& v) const { + return FXT_PSV::x * v.x + FXT_PSV::y * v.y; + } + FX_BOOL IsParallel(baseType otherx, baseType othery) const { + baseType t = FXT_PSV::x * othery - FXT_PSV::y * otherx; + return FXSYS_fabs(t) < 0x0001f; + } + FX_BOOL IsParallel(const FXT_VECTOR& v) const { return IsParallel(v.x, v.y); } + FX_BOOL IsPerpendicular(baseType otherx, baseType othery) const { + baseType t = DotProduct(otherx, othery); + return FXSYS_fabs(t) < 0x0001f; + } + FX_BOOL IsPerpendicular(const FXT_VECTOR& v) const { + return IsPerpendicular(v.x, v.y); + } + void Translate(baseType dx, baseType dy) { + FXT_PSV::x += dx, FXT_PSV::y += dy; + } + void Scale(baseType sx, baseType sy) { FXT_PSV::x *= sx, FXT_PSV::y *= sy; } + void Rotate(FX_FLOAT fRadian) { + FX_FLOAT xx = (FX_FLOAT)FXT_PSV::x; + FX_FLOAT yy = (FX_FLOAT)FXT_PSV::y; + FX_FLOAT cosValue = FXSYS_cos(fRadian); + FX_FLOAT sinValue = FXSYS_sin(fRadian); + FXT_PSV::x = xx * cosValue - yy * sinValue; + FXT_PSV::y = xx * sinValue + yy * cosValue; + } + friend FX_FLOAT Cosine(const FXT_VECTOR& v1, const FXT_VECTOR& v2) { + FXSYS_assert(v1.SquareLength() != 0 && v2.SquareLength() != 0); + FX_FLOAT dotProduct = v1.DotProduct(v2); + return dotProduct / + (FX_FLOAT)FXSYS_sqrt(v1.SquareLength() * v2.SquareLength()); + } + friend FX_FLOAT ArcCosine(const FXT_VECTOR& v1, const FXT_VECTOR& v2) { + return (FX_FLOAT)FXSYS_acos(Cosine(v1, v2)); + } + friend FX_FLOAT SlopeAngle(const FXT_VECTOR& v) { + CFX_VTemplate vx; + vx.Set(1, 0); + FX_FLOAT fSlope = ArcCosine(v, vx); + return v.y < 0 ? -fSlope : fSlope; + } }; typedef CFX_VTemplate<int32_t> CFX_Vector; typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; -template<class baseType> -class CFX_RTemplate -{ -public: - typedef CFX_PSVTemplate<baseType> FXT_POINT; - typedef CFX_PSVTemplate<baseType> FXT_SIZE; - typedef CFX_VTemplate<baseType> FXT_VECTOR; - typedef CFX_PRLTemplate<baseType> FXT_PARAL; - typedef CFX_RTemplate<baseType> FXT_RECT; - void Set(baseType left, baseType top, baseType width, baseType height) - { - FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, FXT_RECT::height = height; - } - void Set(baseType left, baseType top, const FXT_SIZE &size) - { - FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::Size(size); - } - void Set(const FXT_POINT &p, baseType width, baseType height) - { - TopLeft(p), FXT_RECT::width = width, FXT_RECT::height = height; - } - void Set(const FXT_POINT &p1, const FXT_POINT &p2) - { - TopLeft(p1), FXT_RECT::width = p2.x - p1.x, FXT_RECT::height = p2.y - p1.y, FXT_RECT::Normalize(); - } - void Set(const FXT_POINT &p, const FXT_VECTOR &v) - { - TopLeft(p), FXT_RECT::width = v.x, FXT_RECT::height = v.y, FXT_RECT::Normalize(); - } - void Reset() - { - FXT_RECT::left = FXT_RECT::top = FXT_RECT::width = FXT_RECT::height = 0; - } - FXT_RECT& operator += (const FXT_POINT &p) - { - left += p.x, top += p.y; - return *this; - } - FXT_RECT& operator -= (const FXT_POINT &p) - { - left -= p.x, top -= p.y; - return *this; - } - baseType right() const - { - return left + width; - } - baseType bottom() const - { - return top + height; - } - void Normalize() - { - if (width < 0) { - left += width; - width = -width; - } - if (height < 0) { - top += height; - height = -height; - } - } - void Offset(baseType dx, baseType dy) - { - left += dx; - top += dy; - } - void Inflate(baseType x, baseType y) - { - left -= x; - width += x * 2; - top -= y; - height += y * 2; - } - void Inflate(const FXT_POINT &p) - { - Inflate(p.x, p.y); - } - void Inflate(baseType left, baseType top, baseType right, baseType bottom) - { - FXT_RECT::left -= left; - FXT_RECT::top -= top; - FXT_RECT::width += left + right; - FXT_RECT::height += top + bottom; - } - void Inflate(const FXT_RECT &rt) - { - Inflate(rt.left, rt.top, rt.left + rt.width, rt.top + rt.height); - } - void Deflate(baseType x, baseType y) - { - left += x; - width -= x * 2; - top += y; - height -= y * 2; - } - void Deflate(const FXT_POINT &p) - { - Deflate(p.x, p.y); - } - void Deflate(baseType left, baseType top, baseType right, baseType bottom) - { - FXT_RECT::left += left; - FXT_RECT::top += top; - FXT_RECT::width -= left + right; - FXT_RECT::height -= top + bottom; - } - void Deflate(const FXT_RECT &rt) - { - Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); - } - FX_BOOL IsEmpty() const - { - return width <= 0 || height <= 0; - } - FX_BOOL IsEmpty(FX_FLOAT fEpsilon) const - { - return width <= fEpsilon || height <= fEpsilon; - } - void Empty() - { - width = height = 0; - } - FX_BOOL Contains(baseType x, baseType y) const - { - return x >= left && x < left + width && y >= top && y < top + height; - } - FX_BOOL Contains(const FXT_POINT &p) const - { - return Contains(p.x, p.y); - } - FX_BOOL Contains(const FXT_RECT &rt) const - { - return rt.left >= left && rt.right() <= right() && rt.top >= top && rt.bottom() <= bottom(); - } - baseType Width() const - { - return width; - } - baseType Height() const - { - return height; - } - FXT_SIZE Size() const - { - FXT_SIZE size; - size.Set(width, height); - return size; - } - void Size(FXT_SIZE s) - { - width = s.x, height = s.y; - } - FXT_POINT TopLeft() const - { - FXT_POINT p; - p.x = left; - p.y = top; - return p; - } - FXT_POINT TopRight() const - { - FXT_POINT p; - p.x = left + width; - p.y = top; - return p; - } - FXT_POINT BottomLeft() const - { - FXT_POINT p; - p.x = left; - p.y = top + height; - return p; - } - FXT_POINT BottomRight() const - { - FXT_POINT p; - p.x = left + width; - p.y = top + height; - return p; - } - void TopLeft(FXT_POINT tl) - { - left = tl.x; - top = tl.y; - } - void TopRight(FXT_POINT tr) - { - width = tr.x - left; - top = tr.y; - } - void BottomLeft(FXT_POINT bl) - { - left = bl.x; - height = bl.y - top; - } - void BottomRight(FXT_POINT br) - { - width = br.x - left; - height = br.y - top; - } - FXT_POINT Center() const - { - FXT_POINT p; - p.x = left + width / 2; - p.y = top + height / 2; - return p; - } - void GetParallelogram(FXT_PARAL &pg) const - { - pg.x = left, pg.y = top; - pg.x1 = width, pg.y1 = 0; - pg.x2 = 0, pg.y2 = height; - } - void Union(baseType x, baseType y) - { - baseType r = right(), b = bottom(); - if (left > x) { - left = x; - } - if (r < x) { - r = x; - } - if (top > y) { - top = y; - } - if (b < y) { - b = y; - } - width = r - left; - height = b - top; - } - void Union(const FXT_POINT &p) - { - Union(p.x, p.y); - } - void Union(const FXT_RECT &rt) - { - baseType r = right(), b = bottom(); - if (left > rt.left) { - left = rt.left; - } - if (r < rt.right()) { - r = rt.right(); - } - if (top > rt.top) { - top = rt.top; - } - if (b < rt.bottom()) { - b = rt.bottom(); - } - width = r - left; - height = b - top; - } - void Intersect(const FXT_RECT &rt) - { - baseType r = right(), b = bottom(); - if (left < rt.left) { - left = rt.left; - } - if (r > rt.right()) { - r = rt.right(); - } - if (top < rt.top) { - top = rt.top; - } - if (b > rt.bottom()) { - b = rt.bottom(); - } - width = r - left; - height = b - top; - } - FX_BOOL IntersectWith(const FXT_RECT &rt) const - { - FXT_RECT rect = rt; - rect.Intersect(*this); - return !rect.IsEmpty(); - } - FX_BOOL IntersectWith(const FXT_RECT &rt, FX_FLOAT fEpsilon) const - { - FXT_RECT rect = rt; - rect.Intersect(*this); - return !rect.IsEmpty(fEpsilon); - } - friend FX_BOOL operator == (const FXT_RECT &rc1, const FXT_RECT &rc2) - { - return rc1.left == rc2.left && rc1.top == rc2.top && rc1.width == rc2.width && rc1.height == rc2.height; - } - friend FX_BOOL operator != (const FXT_RECT &rc1, const FXT_RECT &rc2) - { - return rc1.left != rc2.left || rc1.top != rc2.top || rc1.width != rc2.width || rc1.height != rc2.height; - } - baseType left, top; - baseType width, height; +template <class baseType> +class CFX_RTemplate { + public: + typedef CFX_PSVTemplate<baseType> FXT_POINT; + typedef CFX_PSVTemplate<baseType> FXT_SIZE; + typedef CFX_VTemplate<baseType> FXT_VECTOR; + typedef CFX_PRLTemplate<baseType> FXT_PARAL; + typedef CFX_RTemplate<baseType> FXT_RECT; + void Set(baseType left, baseType top, baseType width, baseType height) { + FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, + FXT_RECT::height = height; + } + void Set(baseType left, baseType top, const FXT_SIZE& size) { + FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::Size(size); + } + void Set(const FXT_POINT& p, baseType width, baseType height) { + TopLeft(p), FXT_RECT::width = width, FXT_RECT::height = height; + } + void Set(const FXT_POINT& p1, const FXT_POINT& p2) { + TopLeft(p1), FXT_RECT::width = p2.x - p1.x, FXT_RECT::height = p2.y - p1.y, + FXT_RECT::Normalize(); + } + void Set(const FXT_POINT& p, const FXT_VECTOR& v) { + TopLeft(p), FXT_RECT::width = v.x, FXT_RECT::height = v.y, + FXT_RECT::Normalize(); + } + void Reset() { + FXT_RECT::left = FXT_RECT::top = FXT_RECT::width = FXT_RECT::height = 0; + } + FXT_RECT& operator+=(const FXT_POINT& p) { + left += p.x, top += p.y; + return *this; + } + FXT_RECT& operator-=(const FXT_POINT& p) { + left -= p.x, top -= p.y; + return *this; + } + baseType right() const { return left + width; } + baseType bottom() const { return top + height; } + void Normalize() { + if (width < 0) { + left += width; + width = -width; + } + if (height < 0) { + top += height; + height = -height; + } + } + void Offset(baseType dx, baseType dy) { + left += dx; + top += dy; + } + void Inflate(baseType x, baseType y) { + left -= x; + width += x * 2; + top -= y; + height += y * 2; + } + void Inflate(const FXT_POINT& p) { Inflate(p.x, p.y); } + void Inflate(baseType left, baseType top, baseType right, baseType bottom) { + FXT_RECT::left -= left; + FXT_RECT::top -= top; + FXT_RECT::width += left + right; + FXT_RECT::height += top + bottom; + } + void Inflate(const FXT_RECT& rt) { + Inflate(rt.left, rt.top, rt.left + rt.width, rt.top + rt.height); + } + void Deflate(baseType x, baseType y) { + left += x; + width -= x * 2; + top += y; + height -= y * 2; + } + void Deflate(const FXT_POINT& p) { Deflate(p.x, p.y); } + void Deflate(baseType left, baseType top, baseType right, baseType bottom) { + FXT_RECT::left += left; + FXT_RECT::top += top; + FXT_RECT::width -= left + right; + FXT_RECT::height -= top + bottom; + } + void Deflate(const FXT_RECT& rt) { + Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); + } + FX_BOOL IsEmpty() const { return width <= 0 || height <= 0; } + FX_BOOL IsEmpty(FX_FLOAT fEpsilon) const { + return width <= fEpsilon || height <= fEpsilon; + } + void Empty() { width = height = 0; } + FX_BOOL Contains(baseType x, baseType y) const { + return x >= left && x < left + width && y >= top && y < top + height; + } + FX_BOOL Contains(const FXT_POINT& p) const { return Contains(p.x, p.y); } + FX_BOOL Contains(const FXT_RECT& rt) const { + return rt.left >= left && rt.right() <= right() && rt.top >= top && + rt.bottom() <= bottom(); + } + baseType Width() const { return width; } + baseType Height() const { return height; } + FXT_SIZE Size() const { + FXT_SIZE size; + size.Set(width, height); + return size; + } + void Size(FXT_SIZE s) { width = s.x, height = s.y; } + FXT_POINT TopLeft() const { + FXT_POINT p; + p.x = left; + p.y = top; + return p; + } + FXT_POINT TopRight() const { + FXT_POINT p; + p.x = left + width; + p.y = top; + return p; + } + FXT_POINT BottomLeft() const { + FXT_POINT p; + p.x = left; + p.y = top + height; + return p; + } + FXT_POINT BottomRight() const { + FXT_POINT p; + p.x = left + width; + p.y = top + height; + return p; + } + void TopLeft(FXT_POINT tl) { + left = tl.x; + top = tl.y; + } + void TopRight(FXT_POINT tr) { + width = tr.x - left; + top = tr.y; + } + void BottomLeft(FXT_POINT bl) { + left = bl.x; + height = bl.y - top; + } + void BottomRight(FXT_POINT br) { + width = br.x - left; + height = br.y - top; + } + FXT_POINT Center() const { + FXT_POINT p; + p.x = left + width / 2; + p.y = top + height / 2; + return p; + } + void GetParallelogram(FXT_PARAL& pg) const { + pg.x = left, pg.y = top; + pg.x1 = width, pg.y1 = 0; + pg.x2 = 0, pg.y2 = height; + } + void Union(baseType x, baseType y) { + baseType r = right(), b = bottom(); + if (left > x) { + left = x; + } + if (r < x) { + r = x; + } + if (top > y) { + top = y; + } + if (b < y) { + b = y; + } + width = r - left; + height = b - top; + } + void Union(const FXT_POINT& p) { Union(p.x, p.y); } + void Union(const FXT_RECT& rt) { + baseType r = right(), b = bottom(); + if (left > rt.left) { + left = rt.left; + } + if (r < rt.right()) { + r = rt.right(); + } + if (top > rt.top) { + top = rt.top; + } + if (b < rt.bottom()) { + b = rt.bottom(); + } + width = r - left; + height = b - top; + } + void Intersect(const FXT_RECT& rt) { + baseType r = right(), b = bottom(); + if (left < rt.left) { + left = rt.left; + } + if (r > rt.right()) { + r = rt.right(); + } + if (top < rt.top) { + top = rt.top; + } + if (b > rt.bottom()) { + b = rt.bottom(); + } + width = r - left; + height = b - top; + } + FX_BOOL IntersectWith(const FXT_RECT& rt) const { + FXT_RECT rect = rt; + rect.Intersect(*this); + return !rect.IsEmpty(); + } + FX_BOOL IntersectWith(const FXT_RECT& rt, FX_FLOAT fEpsilon) const { + FXT_RECT rect = rt; + rect.Intersect(*this); + return !rect.IsEmpty(fEpsilon); + } + friend FX_BOOL operator==(const FXT_RECT& rc1, const FXT_RECT& rc2) { + return rc1.left == rc2.left && rc1.top == rc2.top && + rc1.width == rc2.width && rc1.height == rc2.height; + } + friend FX_BOOL operator!=(const FXT_RECT& rc1, const FXT_RECT& rc2) { + return rc1.left != rc2.left || rc1.top != rc2.top || + rc1.width != rc2.width || rc1.height != rc2.height; + } + baseType left, top; + baseType width, height; }; -typedef CFX_RTemplate<int32_t> CFX_Rect; -typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; -typedef CFX_RTemplate<int32_t> * FX_LPRECT; -typedef CFX_RTemplate<FX_FLOAT> * FX_LPRECTF; -typedef CFX_RTemplate<int32_t> const * FX_LPCRECT; -typedef CFX_RTemplate<FX_FLOAT> const * FX_LPCRECTF; -typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray; +typedef CFX_RTemplate<int32_t> CFX_Rect; +typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; +typedef CFX_RTemplate<int32_t>* FX_LPRECT; +typedef CFX_RTemplate<FX_FLOAT>* FX_LPRECTF; +typedef CFX_RTemplate<int32_t> const* FX_LPCRECT; +typedef CFX_RTemplate<FX_FLOAT> const* FX_LPCRECTF; +typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray; struct FX_RECT { + int left; - int left; + int top; - int top; + int right; - int right; + int bottom; - int bottom; + FX_RECT() : left(0), top(0), right(0), bottom(0) {} - FX_RECT(): left(0), top(0), right(0), bottom(0) { } + FX_RECT(int left1, int top1, int right1, int bottom1) { + left = left1; + top = top1; + right = right1; + bottom = bottom1; + } - FX_RECT(int left1, int top1, int right1, int bottom1) - { - left = left1; - top = top1; - right = right1; - bottom = bottom1; - } + int Width() const { return right - left; } - int Width() const - { - return right - left; - } + int Height() const { return bottom - top; } - int Height() const - { - return bottom - top; - } + FX_BOOL IsEmpty() const { return right <= left || bottom <= top; } - FX_BOOL IsEmpty() const - { - return right <= left || bottom <= top; - } + void Normalize(); - void Normalize(); + void Intersect(const FX_RECT& src); - void Intersect(const FX_RECT& src); + void Intersect(int left1, int top1, int right1, int bottom1) { + Intersect(FX_RECT(left1, top1, right1, bottom1)); + } - void Intersect(int left1, int top1, int right1, int bottom1) - { - Intersect(FX_RECT(left1, top1, right1, bottom1)); - } + void Union(const FX_RECT& other_rect); - void Union(const FX_RECT& other_rect); + FX_BOOL operator==(const FX_RECT& src) const { + return left == src.left && right == src.right && top == src.top && + bottom == src.bottom; + } - FX_BOOL operator == (const FX_RECT& src) const - { - return left == src.left && right == src.right && top == src.top && bottom == src.bottom; - } + void Offset(int dx, int dy) { + left += dx; + right += dx; + top += dy; + bottom += dy; + } - void Offset(int dx, int dy) - { - left += dx; - right += dx; - top += dy; - bottom += dy; - } - - FX_BOOL Contains(const FX_RECT& other_rect) const - { - return other_rect.left >= left && other_rect.right <= right && other_rect.top >= top && other_rect.bottom <= bottom; - } + FX_BOOL Contains(const FX_RECT& other_rect) const { + return other_rect.left >= left && other_rect.right <= right && + other_rect.top >= top && other_rect.bottom <= bottom; + } - FX_BOOL Contains(int x, int y) const - { - return x >= left && x < right && y >= top && y < bottom; - } + FX_BOOL Contains(int x, int y) const { + return x >= left && x < right && y >= top && y < bottom; + } }; struct FX_SMALL_RECT { + int16_t Left; - int16_t Left; + int16_t Top; - int16_t Top; + int16_t Right; - int16_t Right; - - int16_t Bottom; + int16_t Bottom; }; -class CFX_FloatRect -{ -public: +class CFX_FloatRect { + public: + CFX_FloatRect() { left = right = bottom = top = 0; } - CFX_FloatRect() - { - left = right = bottom = top = 0; - } + CFX_FloatRect(FX_FLOAT left1, + FX_FLOAT bottom1, + FX_FLOAT right1, + FX_FLOAT top1) { + left = left1; + bottom = bottom1; + right = right1; + top = top1; + } - CFX_FloatRect(FX_FLOAT left1, FX_FLOAT bottom1, FX_FLOAT right1, FX_FLOAT top1) - { - left = left1; - bottom = bottom1; - right = right1; - top = top1; - } + CFX_FloatRect(const FX_FLOAT* pArray) { + left = pArray[0]; + bottom = pArray[1]; + right = pArray[2]; + top = pArray[3]; + } - CFX_FloatRect(const FX_FLOAT* pArray) - { - left = pArray[0]; - bottom = pArray[1]; - right = pArray[2]; - top = pArray[3]; - } + CFX_FloatRect(const FX_RECT& rect); - CFX_FloatRect(const FX_RECT& rect); + FX_BOOL IsEmpty() const { return left >= right || bottom >= top; } - FX_BOOL IsEmpty() const - { - return left >= right || bottom >= top; - } + void Normalize(); - void Normalize(); + void Reset() { left = right = bottom = top = 0; } - void Reset() - { - left = right = bottom = top = 0; - } - - FX_BOOL Contains(const CFX_FloatRect& other_rect) const; + FX_BOOL Contains(const CFX_FloatRect& other_rect) const; - FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const; + FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const; - void Transform(const CFX_Matrix* pMatrix); + void Transform(const CFX_Matrix* pMatrix); - void Intersect(const CFX_FloatRect& other_rect); + void Intersect(const CFX_FloatRect& other_rect); - void Union(const CFX_FloatRect& other_rect); + void Union(const CFX_FloatRect& other_rect); - FX_RECT GetInnerRect() const; + FX_RECT GetInnerRect() const; - FX_RECT GetOutterRect() const; + FX_RECT GetOutterRect() const; - FX_RECT GetClosestRect() const; + FX_RECT GetClosestRect() const; - int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); + int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); - void InitRect(FX_FLOAT x, FX_FLOAT y) - { - left = right = x; - bottom = top = y; - } + void InitRect(FX_FLOAT x, FX_FLOAT y) { + left = right = x; + bottom = top = y; + } - void UpdateRect(FX_FLOAT x, FX_FLOAT y); + void UpdateRect(FX_FLOAT x, FX_FLOAT y); - FX_FLOAT Width() const - { - return right - left; - } + FX_FLOAT Width() const { return right - left; } - FX_FLOAT Height() const - { - return top - bottom; - } + FX_FLOAT Height() const { return top - bottom; } - void Inflate(FX_FLOAT x, FX_FLOAT y) - { - Normalize(); - left -= x; - right += x; - bottom -= y; - top += y; - } + void Inflate(FX_FLOAT x, FX_FLOAT y) { + Normalize(); + left -= x; + right += x; + bottom -= y; + top += y; + } - void Inflate(FX_FLOAT other_left, - FX_FLOAT other_bottom, - FX_FLOAT other_right, - FX_FLOAT other_top) - { - Normalize(); - left -= other_left; - bottom -= other_bottom; - right += other_right; - top += other_top; - } + void Inflate(FX_FLOAT other_left, + FX_FLOAT other_bottom, + FX_FLOAT other_right, + FX_FLOAT other_top) { + Normalize(); + left -= other_left; + bottom -= other_bottom; + right += other_right; + top += other_top; + } - void Inflate(const CFX_FloatRect &rt) - { - Inflate(rt.left, rt.bottom, rt.right, rt.top); - } + void Inflate(const CFX_FloatRect& rt) { + Inflate(rt.left, rt.bottom, rt.right, rt.top); + } - void Deflate(FX_FLOAT x, FX_FLOAT y) - { - Normalize(); - left += x; - right -= x; - bottom += y; - top -= y; - } + void Deflate(FX_FLOAT x, FX_FLOAT y) { + Normalize(); + left += x; + right -= x; + bottom += y; + top -= y; + } - void Deflate(FX_FLOAT other_left, - FX_FLOAT other_bottom, - FX_FLOAT other_right, - FX_FLOAT other_top) - { - Normalize(); - left += other_left; - bottom += other_bottom; - right -= other_right; - top -= other_top; - } + void Deflate(FX_FLOAT other_left, + FX_FLOAT other_bottom, + FX_FLOAT other_right, + FX_FLOAT other_top) { + Normalize(); + left += other_left; + bottom += other_bottom; + right -= other_right; + top -= other_top; + } - void Deflate(const CFX_FloatRect &rt) - { - Deflate(rt.left, rt.bottom, rt.right, rt.top); - } + void Deflate(const CFX_FloatRect& rt) { + Deflate(rt.left, rt.bottom, rt.right, rt.top); + } - void Translate(FX_FLOAT e, FX_FLOAT f) - { - left += e; - right += e; - top += f; - bottom += f; - } + void Translate(FX_FLOAT e, FX_FLOAT f) { + left += e; + right += e; + top += f; + bottom += f; + } - static CFX_FloatRect GetBBox(const CFX_FloatPoint* pPoints, int nPoints); + static CFX_FloatRect GetBBox(const CFX_FloatPoint* pPoints, int nPoints); - FX_FLOAT left; + FX_FLOAT left; - FX_FLOAT right; + FX_FLOAT right; - FX_FLOAT bottom; + FX_FLOAT bottom; - FX_FLOAT top; + FX_FLOAT top; }; -class CFX_Matrix -{ -public: - - CFX_Matrix() - { - a = d = 1; - b = c = e = f = 0; - } +class CFX_Matrix { + public: + CFX_Matrix() { + a = d = 1; + b = c = e = f = 0; + } + + CFX_Matrix(FX_FLOAT a1, + FX_FLOAT b1, + FX_FLOAT c1, + FX_FLOAT d1, + FX_FLOAT e1, + FX_FLOAT f1) { + a = a1; + b = b1; + c = c1; + d = d1; + e = e1; + f = f1; + } + + void Set(FX_FLOAT a, + FX_FLOAT b, + FX_FLOAT c, + FX_FLOAT d, + FX_FLOAT e, + FX_FLOAT f); + void Set(const FX_FLOAT n[6]); + + void SetIdentity() { + a = d = 1; + b = c = e = f = 0; + } - CFX_Matrix(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1, FX_FLOAT d1, FX_FLOAT e1, FX_FLOAT f1) - { - a = a1; - b = b1; - c = c1; - d = d1; - e = e1; - f = f1; - } - - void Set(FX_FLOAT a, FX_FLOAT b, FX_FLOAT c, FX_FLOAT d, FX_FLOAT e, FX_FLOAT f); - void Set(const FX_FLOAT n[6]); - - void SetIdentity() - { - a = d = 1; - b = c = e = f = 0; - } - - void SetReverse(const CFX_Matrix &m); - - void Concat(FX_FLOAT a, FX_FLOAT b, FX_FLOAT c, FX_FLOAT d, FX_FLOAT e, FX_FLOAT f, FX_BOOL bPrepended = FALSE); - - void Concat(const CFX_Matrix &m, FX_BOOL bPrepended = FALSE); - - void ConcatInverse(const CFX_Matrix& m, FX_BOOL bPrepended = FALSE); - void Reset() - { - SetIdentity(); - } - - void Copy(const CFX_Matrix& m) - { - *this = m; - } - - FX_BOOL IsIdentity() const - { - return a == 1 && b == 0 && c == 0 && d == 1 && e == 0 && f == 0; - } - FX_BOOL IsInvertible() const; - - FX_BOOL Is90Rotated() const; - - FX_BOOL IsScaled() const; - - void Translate(FX_FLOAT x, FX_FLOAT y, FX_BOOL bPrepended = FALSE); - - void TranslateI(int32_t x, int32_t y, FX_BOOL bPrepended = FALSE) - { - Translate((FX_FLOAT)x, (FX_FLOAT)y, bPrepended); - } + void SetReverse(const CFX_Matrix& m); - void Scale(FX_FLOAT sx, FX_FLOAT sy, FX_BOOL bPrepended = FALSE); + void Concat(FX_FLOAT a, + FX_FLOAT b, + FX_FLOAT c, + FX_FLOAT d, + FX_FLOAT e, + FX_FLOAT f, + FX_BOOL bPrepended = FALSE); + + void Concat(const CFX_Matrix& m, FX_BOOL bPrepended = FALSE); + + void ConcatInverse(const CFX_Matrix& m, FX_BOOL bPrepended = FALSE); + void Reset() { SetIdentity(); } + + void Copy(const CFX_Matrix& m) { *this = m; } + + FX_BOOL IsIdentity() const { + return a == 1 && b == 0 && c == 0 && d == 1 && e == 0 && f == 0; + } + FX_BOOL IsInvertible() const; + + FX_BOOL Is90Rotated() const; + + FX_BOOL IsScaled() const; + + void Translate(FX_FLOAT x, FX_FLOAT y, FX_BOOL bPrepended = FALSE); + + void TranslateI(int32_t x, int32_t y, FX_BOOL bPrepended = FALSE) { + Translate((FX_FLOAT)x, (FX_FLOAT)y, bPrepended); + } + + void Scale(FX_FLOAT sx, FX_FLOAT sy, FX_BOOL bPrepended = FALSE); + + void Rotate(FX_FLOAT fRadian, FX_BOOL bPrepended = FALSE); + + void RotateAt(FX_FLOAT fRadian, + FX_FLOAT x, + FX_FLOAT y, + FX_BOOL bPrepended = FALSE); + + void Shear(FX_FLOAT fAlphaRadian, + FX_FLOAT fBetaRadian, + FX_BOOL bPrepended = FALSE); + + void MatchRect(const CFX_FloatRect& dest, const CFX_FloatRect& src); + + FX_FLOAT GetXUnit() const; + + FX_FLOAT GetYUnit() const; + void GetUnitRect(CFX_RectF& rect) const; + + CFX_FloatRect GetUnitRect() const; + + FX_FLOAT GetUnitArea() const; + FX_FLOAT TransformXDistance(FX_FLOAT dx) const; + int32_t TransformXDistance(int32_t dx) const; + FX_FLOAT TransformYDistance(FX_FLOAT dy) const; + int32_t TransformYDistance(int32_t dy) const; + FX_FLOAT TransformDistance(FX_FLOAT dx, FX_FLOAT dy) const; + int32_t TransformDistance(int32_t dx, int32_t dy) const; + + FX_FLOAT TransformDistance(FX_FLOAT distance) const; + void TransformPoint(FX_FLOAT& x, FX_FLOAT& y) const; + void TransformPoint(int32_t& x, int32_t& y) const; + void TransformPoints(CFX_PointF* points, int32_t iCount) const; + void TransformPoints(CFX_Point* points, int32_t iCount) const; + + void Transform(FX_FLOAT& x, FX_FLOAT& y) const { TransformPoint(x, y); } - void Rotate(FX_FLOAT fRadian, FX_BOOL bPrepended = FALSE); + void Transform(FX_FLOAT x, FX_FLOAT y, FX_FLOAT& x1, FX_FLOAT& y1) const { + x1 = x, y1 = y; + TransformPoint(x1, y1); + } + void TransformVector(CFX_VectorF& v) const; + void TransformVector(CFX_Vector& v) const; + void TransformRect(CFX_RectF& rect) const; + void TransformRect(CFX_Rect& rect) const; - void RotateAt(FX_FLOAT fRadian, FX_FLOAT x, FX_FLOAT y, FX_BOOL bPrepended = FALSE); + void TransformRect(FX_FLOAT& left, + FX_FLOAT& right, + FX_FLOAT& top, + FX_FLOAT& bottom) const; - void Shear(FX_FLOAT fAlphaRadian, FX_FLOAT fBetaRadian, FX_BOOL bPrepended = FALSE); + void TransformRect(CFX_FloatRect& rect) const { + TransformRect(rect.left, rect.right, rect.top, rect.bottom); + } - void MatchRect(const CFX_FloatRect &dest, const CFX_FloatRect &src); + FX_FLOAT GetA() const { return a; } - FX_FLOAT GetXUnit() const; + FX_FLOAT GetB() const { return b; } - FX_FLOAT GetYUnit() const; - void GetUnitRect(CFX_RectF &rect) const; + FX_FLOAT GetC() const { return c; } - CFX_FloatRect GetUnitRect() const; + FX_FLOAT GetD() const { return d; } - FX_FLOAT GetUnitArea() const; - FX_FLOAT TransformXDistance(FX_FLOAT dx) const; - int32_t TransformXDistance(int32_t dx) const; - FX_FLOAT TransformYDistance(FX_FLOAT dy) const; - int32_t TransformYDistance(int32_t dy) const; - FX_FLOAT TransformDistance(FX_FLOAT dx, FX_FLOAT dy) const; - int32_t TransformDistance(int32_t dx, int32_t dy) const; + FX_FLOAT GetE() const { return e; } - FX_FLOAT TransformDistance(FX_FLOAT distance) const; - void TransformPoint(FX_FLOAT &x, FX_FLOAT &y) const; - void TransformPoint(int32_t &x, int32_t &y) const; - void TransformPoints(CFX_PointF *points, int32_t iCount) const; - void TransformPoints(CFX_Point *points, int32_t iCount) const; + FX_FLOAT GetF() const { return f; } - void Transform(FX_FLOAT& x, FX_FLOAT& y) const - { - TransformPoint(x, y); - } - - void Transform(FX_FLOAT x, FX_FLOAT y, FX_FLOAT& x1, FX_FLOAT& y1) const - { - x1 = x, y1 = y; - TransformPoint(x1, y1); - } - void TransformVector(CFX_VectorF &v) const; - void TransformVector(CFX_Vector &v) const; - void TransformRect(CFX_RectF &rect) const; - void TransformRect(CFX_Rect &rect) const; - - void TransformRect(FX_FLOAT& left, FX_FLOAT& right, FX_FLOAT& top, FX_FLOAT& bottom) const; - - void TransformRect(CFX_FloatRect& rect) const - { - TransformRect(rect.left, rect.right, rect.top, rect.bottom); - } - - FX_FLOAT GetA() const - { - return a; - } - - FX_FLOAT GetB() const - { - return b; - } - - FX_FLOAT GetC() const - { - return c; - } - - FX_FLOAT GetD() const - { - return d; - } - - FX_FLOAT GetE() const - { - return e; - } - - FX_FLOAT GetF() const - { - return f; - } -public: - FX_FLOAT a; - FX_FLOAT b; - FX_FLOAT c; - FX_FLOAT d; - FX_FLOAT e; - FX_FLOAT f; + public: + FX_FLOAT a; + FX_FLOAT b; + FX_FLOAT c; + FX_FLOAT d; + FX_FLOAT e; + FX_FLOAT f; }; -#define CFX_AffineMatrix CFX_Matrix +#define CFX_AffineMatrix CFX_Matrix #endif // CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ diff --git a/core/include/fxcrt/fx_ext.h b/core/include/fxcrt/fx_ext.h index 55e522ad1a..0853c89531 100644 --- a/core/include/fxcrt/fx_ext.h +++ b/core/include/fxcrt/fx_ext.h @@ -14,33 +14,37 @@ extern "C" { #endif -FX_FLOAT FXSYS_tan(FX_FLOAT a); -FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); -FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, int32_t iLength = -1, int32_t *pUsedLen = NULL); -FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, int32_t iLength = -1, int32_t *pUsedLen = NULL); -FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); -int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); -int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); - -inline FX_BOOL FXSYS_islower(int32_t ch) -{ - return ch >= 'a' && ch <= 'z'; +FX_FLOAT FXSYS_tan(FX_FLOAT a); +FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); +FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, + int32_t iLength = -1, + int32_t* pUsedLen = NULL); +FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, + int32_t iLength = -1, + int32_t* pUsedLen = NULL); +FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); +int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); +int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); + +inline FX_BOOL FXSYS_islower(int32_t ch) { + return ch >= 'a' && ch <= 'z'; } -inline FX_BOOL FXSYS_isupper(int32_t ch) -{ - return ch >= 'A' && ch <= 'Z'; +inline FX_BOOL FXSYS_isupper(int32_t ch) { + return ch >= 'A' && ch <= 'Z'; } -inline int32_t FXSYS_tolower(int32_t ch) -{ - return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); +inline int32_t FXSYS_tolower(int32_t ch) { + return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); } -inline int32_t FXSYS_toupper(int32_t ch) -{ - return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); +inline int32_t FXSYS_toupper(int32_t ch) { + return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); } -FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, int32_t iLength, FX_BOOL bIgnoreCase = FALSE); -FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, int32_t iLength, FX_BOOL bIgnoreCase = FALSE); +FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, + int32_t iLength, + FX_BOOL bIgnoreCase = FALSE); +FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, + int32_t iLength, + FX_BOOL bIgnoreCase = FALSE); #ifdef __cplusplus } @@ -49,17 +53,17 @@ FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, int32_t iLength, FX_BOOL extern "C" { #endif -void* FX_Random_MT_Start(FX_DWORD dwSeed); +void* FX_Random_MT_Start(FX_DWORD dwSeed); -FX_DWORD FX_Random_MT_Generate(void* pContext); +FX_DWORD FX_Random_MT_Generate(void* pContext); -void FX_Random_MT_Close(void* pContext); +void FX_Random_MT_Close(void* pContext); -void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); +void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); -void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); +void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); -void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); +void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); #ifdef __cplusplus } #endif @@ -68,42 +72,42 @@ extern "C" { #endif typedef struct FX_GUID { - FX_DWORD data1; - FX_WORD data2; - FX_WORD data3; - uint8_t data4[8]; -} FX_GUID, * FX_LPGUID; -typedef FX_GUID const * FX_LPCGUID; - -void FX_GUID_CreateV4(FX_LPGUID pGUID); - -void FX_GUID_ToString(FX_LPCGUID pGUID, CFX_ByteString &bsStr, FX_BOOL bSeparator = TRUE); + FX_DWORD data1; + FX_WORD data2; + FX_WORD data3; + uint8_t data4[8]; +} FX_GUID, *FX_LPGUID; +typedef FX_GUID const* FX_LPCGUID; + +void FX_GUID_CreateV4(FX_LPGUID pGUID); + +void FX_GUID_ToString(FX_LPCGUID pGUID, + CFX_ByteString& bsStr, + FX_BOOL bSeparator = TRUE); #ifdef __cplusplus } #endif -template<class baseType> -class CFX_SSortTemplate -{ -public: - void ShellSort(baseType *pArray, int32_t iCount) - { - FXSYS_assert(pArray != NULL && iCount > 0); - int32_t i, j, gap; - baseType v1, v2; - gap = iCount >> 1; - while (gap > 0) { - for (i = gap; i < iCount; i ++) { - j = i - gap; - v1 = pArray[i]; - while (j > -1 && (v2 = pArray[j]) > v1) { - pArray[j + gap] = v2; - j -= gap; - } - pArray[j + gap] = v1; - } - gap >>= 1; +template <class baseType> +class CFX_SSortTemplate { + public: + void ShellSort(baseType* pArray, int32_t iCount) { + FXSYS_assert(pArray != NULL && iCount > 0); + int32_t i, j, gap; + baseType v1, v2; + gap = iCount >> 1; + while (gap > 0) { + for (i = gap; i < iCount; i++) { + j = i - gap; + v1 = pArray[i]; + while (j > -1 && (v2 = pArray[j]) > v1) { + pArray[j + gap] = v2; + j -= gap; } + pArray[j + gap] = v1; + } + gap >>= 1; } + } }; #endif // CORE_INCLUDE_FXCRT_FX_EXT_H_ diff --git a/core/include/fxcrt/fx_memory.h b/core/include/fxcrt/fx_memory.h index d19a3b32ab..e24aa3ecf4 100644 --- a/core/include/fxcrt/fx_memory.h +++ b/core/include/fxcrt/fx_memory.h @@ -13,9 +13,9 @@ extern "C" { #endif // For external C libraries to malloc through PDFium. These may return NULL. -void* FXMEM_DefaultAlloc(size_t byte_size, int flags); -void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags); -void FXMEM_DefaultFree(void* pointer, int flags); +void* FXMEM_DefaultAlloc(size_t byte_size, int flags); +void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags); +void FXMEM_DefaultFree(void* pointer, int flags); #ifdef __cplusplus } // extern "C" @@ -28,94 +28,84 @@ void FXMEM_DefaultFree(void* pointer, int flags); NEVER_INLINE void FX_OutOfMemoryTerminate(); inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { - if (num_members < std::numeric_limits<size_t>::max() / member_size) { - return realloc(ptr, num_members * member_size); - } - return nullptr; + if (num_members < std::numeric_limits<size_t>::max() / member_size) { + return realloc(ptr, num_members * member_size); + } + return nullptr; } inline void* FX_AllocOrDie(size_t num_members, size_t member_size) { - // TODO(tsepez): See if we can avoid the implicit memset(0). - if (void* result = calloc(num_members, member_size)) { - return result; - } - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. + // TODO(tsepez): See if we can avoid the implicit memset(0). + if (void* result = calloc(num_members, member_size)) { + return result; + } + FX_OutOfMemoryTerminate(); // Never returns. + return nullptr; // Suppress compiler warning. } inline void* FX_AllocOrDie2D(size_t w, size_t h, size_t member_size) { - if (w < std::numeric_limits<size_t>::max() / h) { - return FX_AllocOrDie(w * h, member_size); - } - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. + if (w < std::numeric_limits<size_t>::max() / h) { + return FX_AllocOrDie(w * h, member_size); + } + FX_OutOfMemoryTerminate(); // Never returns. + return nullptr; // Suppress compiler warning. } -inline void* FX_ReallocOrDie(void* ptr, size_t num_members, size_t member_size) { - if (void* result = FX_SafeRealloc(ptr, num_members, member_size)) { - return result; - } - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. +inline void* FX_ReallocOrDie(void* ptr, + size_t num_members, + size_t member_size) { + if (void* result = FX_SafeRealloc(ptr, num_members, member_size)) { + return result; + } + FX_OutOfMemoryTerminate(); // Never returns. + return nullptr; // Suppress compiler warning. } // Never returns NULL. -#define FX_Alloc(type, size) (type*)FX_AllocOrDie(size, sizeof(type)) -#define FX_Alloc2D(type, w, h) (type*)FX_AllocOrDie2D(w, h, sizeof(type)) +#define FX_Alloc(type, size) (type*) FX_AllocOrDie(size, sizeof(type)) +#define FX_Alloc2D(type, w, h) (type*) FX_AllocOrDie2D(w, h, sizeof(type)) #define FX_Realloc(type, ptr, size) \ - (type*)FX_ReallocOrDie(ptr, size, sizeof(type)) + (type*) FX_ReallocOrDie(ptr, size, sizeof(type)) // May return NULL. -#define FX_TryAlloc(type, size) (type*)calloc(size, sizeof(type)) +#define FX_TryAlloc(type, size) (type*) calloc(size, sizeof(type)) #define FX_TryRealloc(type, ptr, size) \ - (type*)FX_SafeRealloc(ptr, size, sizeof(type)) + (type*) FX_SafeRealloc(ptr, size, sizeof(type)) #define FX_Free(ptr) free(ptr) -class CFX_DestructObject -{ -public: - - virtual ~CFX_DestructObject() {} +class CFX_DestructObject { + public: + virtual ~CFX_DestructObject() {} }; -class CFX_GrowOnlyPool -{ -public: - - CFX_GrowOnlyPool(size_t trunk_size = 16384); +class CFX_GrowOnlyPool { + public: + CFX_GrowOnlyPool(size_t trunk_size = 16384); - ~CFX_GrowOnlyPool(); + ~CFX_GrowOnlyPool(); - void SetTrunkSize(size_t trunk_size) - { - m_TrunkSize = trunk_size; - } + void SetTrunkSize(size_t trunk_size) { m_TrunkSize = trunk_size; } - void* AllocDebug(size_t size, const FX_CHAR* file, int line) - { - return Alloc(size); - } + void* AllocDebug(size_t size, const FX_CHAR* file, int line) { + return Alloc(size); + } - void* Alloc(size_t size); + void* Alloc(size_t size); - void* ReallocDebug(void* p, size_t new_size, const FX_CHAR* file, int line) - { - return NULL; - } + void* ReallocDebug(void* p, size_t new_size, const FX_CHAR* file, int line) { + return NULL; + } - void* Realloc(void* p, size_t new_size) - { - return NULL; - } + void* Realloc(void* p, size_t new_size) { return NULL; } - void Free(void*) {} + void Free(void*) {} - void FreeAll(); -private: + void FreeAll(); - size_t m_TrunkSize; + private: + size_t m_TrunkSize; - void* m_pFirstTrunk; + void* m_pFirstTrunk; }; #endif // __cplusplus diff --git a/core/include/fxcrt/fx_stream.h b/core/include/fxcrt/fx_stream.h index b6fdcfcb6a..e51c2bd244 100644 --- a/core/include/fxcrt/fx_stream.h +++ b/core/include/fxcrt/fx_stream.h @@ -11,187 +11,179 @@ void* FX_OpenFolder(const FX_CHAR* path); void* FX_OpenFolder(const FX_WCHAR* path); -FX_BOOL FX_GetNextFile(void* handle, CFX_ByteString& filename, FX_BOOL& bFolder); -FX_BOOL FX_GetNextFile(void* handle, CFX_WideString& filename, FX_BOOL& bFolder); +FX_BOOL FX_GetNextFile(void* handle, + CFX_ByteString& filename, + FX_BOOL& bFolder); +FX_BOOL FX_GetNextFile(void* handle, + CFX_WideString& filename, + FX_BOOL& bFolder); void FX_CloseFolder(void* handle); FX_WCHAR FX_GetFolderSeparator(); #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -#define FX_FILESIZE int32_t +#define FX_FILESIZE int32_t #else #include <fcntl.h> #include <unistd.h> #include <sys/stat.h> #ifndef O_BINARY -#define O_BINARY 0 +#define O_BINARY 0 #endif #ifndef O_LARGEFILE -#define O_LARGEFILE 0 +#define O_LARGEFILE 0 #endif -#define FX_FILESIZE off_t +#define FX_FILESIZE off_t #endif -#define FX_GETBYTEOFFSET32(a) 0 -#define FX_GETBYTEOFFSET40(a) 0 -#define FX_GETBYTEOFFSET48(a) 0 -#define FX_GETBYTEOFFSET56(a) 0 -#define FX_GETBYTEOFFSET24(a) ((uint8_t)(a>>24)) -#define FX_GETBYTEOFFSET16(a) ((uint8_t)(a>>16)) -#define FX_GETBYTEOFFSET8(a) ((uint8_t)(a>>8)) -#define FX_GETBYTEOFFSET0(a) ((uint8_t)(a)) -#define FX_FILEMODE_Write 0 -#define FX_FILEMODE_ReadOnly 1 -#define FX_FILEMODE_Truncate 2 -FX_BOOL FX_File_Exist(const CFX_ByteStringC& fileName); -FX_BOOL FX_File_Exist(const CFX_WideStringC& fileName); -FX_BOOL FX_File_Delete(const CFX_ByteStringC& fileName); -FX_BOOL FX_File_Delete(const CFX_WideStringC& fileName); -FX_BOOL FX_File_Copy(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC& fileNameDst); -FX_BOOL FX_File_Copy(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC& fileNameDst); -FX_BOOL FX_File_Move(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC& fileNameDst); -FX_BOOL FX_File_Move(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC& fileNameDst); -class IFX_StreamWrite -{ -public: - virtual ~IFX_StreamWrite() {} - virtual void Release() = 0; - virtual FX_BOOL WriteBlock(const void* pData, size_t size) = 0; +#define FX_GETBYTEOFFSET32(a) 0 +#define FX_GETBYTEOFFSET40(a) 0 +#define FX_GETBYTEOFFSET48(a) 0 +#define FX_GETBYTEOFFSET56(a) 0 +#define FX_GETBYTEOFFSET24(a) ((uint8_t)(a >> 24)) +#define FX_GETBYTEOFFSET16(a) ((uint8_t)(a >> 16)) +#define FX_GETBYTEOFFSET8(a) ((uint8_t)(a >> 8)) +#define FX_GETBYTEOFFSET0(a) ((uint8_t)(a)) +#define FX_FILEMODE_Write 0 +#define FX_FILEMODE_ReadOnly 1 +#define FX_FILEMODE_Truncate 2 +FX_BOOL FX_File_Exist(const CFX_ByteStringC& fileName); +FX_BOOL FX_File_Exist(const CFX_WideStringC& fileName); +FX_BOOL FX_File_Delete(const CFX_ByteStringC& fileName); +FX_BOOL FX_File_Delete(const CFX_WideStringC& fileName); +FX_BOOL FX_File_Copy(const CFX_ByteStringC& fileNameSrc, + const CFX_ByteStringC& fileNameDst); +FX_BOOL FX_File_Copy(const CFX_WideStringC& fileNameSrc, + const CFX_WideStringC& fileNameDst); +FX_BOOL FX_File_Move(const CFX_ByteStringC& fileNameSrc, + const CFX_ByteStringC& fileNameDst); +FX_BOOL FX_File_Move(const CFX_WideStringC& fileNameSrc, + const CFX_WideStringC& fileNameDst); +class IFX_StreamWrite { + public: + virtual ~IFX_StreamWrite() {} + virtual void Release() = 0; + virtual FX_BOOL WriteBlock(const void* pData, size_t size) = 0; }; -class IFX_FileWrite : public IFX_StreamWrite -{ -public: +class IFX_FileWrite : public IFX_StreamWrite { + public: + virtual void Release() = 0; - virtual void Release() = 0; + virtual FX_FILESIZE GetSize() = 0; - virtual FX_FILESIZE GetSize() = 0; + virtual FX_BOOL Flush() = 0; - virtual FX_BOOL Flush() = 0; - - virtual FX_BOOL WriteBlock(const void* pData, FX_FILESIZE offset, size_t size) = 0; - virtual FX_BOOL WriteBlock(const void* pData, size_t size) - { - return WriteBlock(pData, GetSize(), size); - } + virtual FX_BOOL WriteBlock(const void* pData, + FX_FILESIZE offset, + size_t size) = 0; + virtual FX_BOOL WriteBlock(const void* pData, size_t size) { + return WriteBlock(pData, GetSize(), size); + } }; IFX_FileWrite* FX_CreateFileWrite(const FX_CHAR* filename); IFX_FileWrite* FX_CreateFileWrite(const FX_WCHAR* filename); -class IFX_StreamRead -{ -public: - virtual ~IFX_StreamRead() { } +class IFX_StreamRead { + public: + virtual ~IFX_StreamRead() {} - virtual void Release() = 0; + virtual void Release() = 0; - virtual FX_BOOL IsEOF() = 0; + virtual FX_BOOL IsEOF() = 0; - virtual FX_FILESIZE GetPosition() = 0; + virtual FX_FILESIZE GetPosition() = 0; - virtual size_t ReadBlock(void* buffer, size_t size) = 0; + virtual size_t ReadBlock(void* buffer, size_t size) = 0; }; -class IFX_FileRead : IFX_StreamRead -{ -public: - virtual void Release() = 0; +class IFX_FileRead : IFX_StreamRead { + public: + virtual void Release() = 0; - virtual FX_FILESIZE GetSize() = 0; + virtual FX_FILESIZE GetSize() = 0; - virtual FX_BOOL IsEOF() - { - return FALSE; - } + virtual FX_BOOL IsEOF() { return FALSE; } - virtual FX_FILESIZE GetPosition() - { - return 0; - } + virtual FX_FILESIZE GetPosition() { return 0; } - virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_FILESIZE size) - { - return FALSE; - } + virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_FILESIZE size) { + return FALSE; + } - virtual void ClearRange() {} + virtual void ClearRange() {} - virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; + virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; - virtual size_t ReadBlock(void* buffer, size_t size) - { - return 0; - } + virtual size_t ReadBlock(void* buffer, size_t size) { return 0; } }; IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename); IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename); -class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite -{ -public: - - virtual IFX_FileStream* Retain() = 0; +class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite { + public: + virtual IFX_FileStream* Retain() = 0; - virtual void Release() = 0; + virtual void Release() = 0; - virtual FX_FILESIZE GetSize() = 0; + virtual FX_FILESIZE GetSize() = 0; - virtual FX_BOOL IsEOF() = 0; + virtual FX_BOOL IsEOF() = 0; - virtual FX_FILESIZE GetPosition() = 0; + virtual FX_FILESIZE GetPosition() = 0; - virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; + virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; - virtual size_t ReadBlock(void* buffer, size_t size) = 0; + virtual size_t ReadBlock(void* buffer, size_t size) = 0; - virtual FX_BOOL WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) = 0; - virtual FX_BOOL WriteBlock(const void* buffer, size_t size) - { - return WriteBlock(buffer, GetSize(), size); - } + virtual FX_BOOL WriteBlock(const void* buffer, + FX_FILESIZE offset, + size_t size) = 0; + virtual FX_BOOL WriteBlock(const void* buffer, size_t size) { + return WriteBlock(buffer, GetSize(), size); + } - virtual FX_BOOL Flush() = 0; + virtual FX_BOOL Flush() = 0; }; -IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, FX_DWORD dwModes); -IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, FX_DWORD dwModes); -class IFX_FileAccess -{ -public: - virtual ~IFX_FileAccess() {} - virtual void Release() = 0; - virtual IFX_FileAccess* Retain() = 0; - virtual void GetPath(CFX_WideString& wsPath) = 0; - virtual IFX_FileStream* CreateFileStream(FX_DWORD dwModes) = 0; +IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, FX_DWORD dwModes); +IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, FX_DWORD dwModes); +class IFX_FileAccess { + public: + virtual ~IFX_FileAccess() {} + virtual void Release() = 0; + virtual IFX_FileAccess* Retain() = 0; + virtual void GetPath(CFX_WideString& wsPath) = 0; + virtual IFX_FileStream* CreateFileStream(FX_DWORD dwModes) = 0; }; IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath); -class IFX_MemoryStream : public IFX_FileStream -{ -public: +class IFX_MemoryStream : public IFX_FileStream { + public: + virtual FX_BOOL IsConsecutive() const = 0; - virtual FX_BOOL IsConsecutive() const = 0; + virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0; - virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0; + virtual uint8_t* GetBuffer() const = 0; - virtual uint8_t* GetBuffer() const = 0; + virtual void AttachBuffer(uint8_t* pBuffer, + size_t nSize, + FX_BOOL bTakeOver = FALSE) = 0; - virtual void AttachBuffer(uint8_t* pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) = 0; - - virtual void DetachBuffer() = 0; + virtual void DetachBuffer() = 0; }; -IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE); -IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE); -class IFX_BufferRead : public IFX_StreamRead -{ -public: - - virtual void Release() = 0; +IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, + size_t nSize, + FX_BOOL bTakeOver = FALSE); +IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE); +class IFX_BufferRead : public IFX_StreamRead { + public: + virtual void Release() = 0; - virtual FX_BOOL IsEOF() = 0; + virtual FX_BOOL IsEOF() = 0; - virtual FX_FILESIZE GetPosition() = 0; + virtual FX_FILESIZE GetPosition() = 0; - virtual size_t ReadBlock(void* buffer, size_t size) = 0; + virtual size_t ReadBlock(void* buffer, size_t size) = 0; - virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) = 0; + virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) = 0; - virtual const uint8_t* GetBlockBuffer() = 0; + virtual const uint8_t* GetBlockBuffer() = 0; - virtual size_t GetBlockSize() = 0; + virtual size_t GetBlockSize() = 0; - virtual FX_FILESIZE GetBlockOffset() = 0; + virtual FX_FILESIZE GetBlockOffset() = 0; }; #endif // CORE_INCLUDE_FXCRT_FX_STREAM_H_ diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h index 8d73555814..f493c53ed9 100644 --- a/core/include/fxcrt/fx_string.h +++ b/core/include/fxcrt/fx_string.h @@ -20,891 +20,790 @@ struct CFX_CharMap; // An immutable string with caller-provided storage which must outlive the // string itself. -class CFX_ByteStringC -{ -public: - typedef FX_CHAR value_type; - - CFX_ByteStringC() - { - m_Ptr = NULL; - m_Length = 0; - } - - CFX_ByteStringC(const uint8_t* ptr, FX_STRSIZE size) - { - m_Ptr = ptr; - m_Length = size; - } - - CFX_ByteStringC(const FX_CHAR* ptr) - { - m_Ptr = (const uint8_t*)ptr; - m_Length = ptr ? FXSYS_strlen(ptr) : 0; - } - - // |ch| must be an lvalue that outlives the the CFX_ByteStringC. However, - // the use of char rvalues are not caught at compile time. They are - // implicitly promoted to CFX_ByteString (see below) and then the - // CFX_ByteStringC is constructed from the CFX_ByteString via the alternate - // constructor below. The CFX_ByteString then typically goes out of scope - // and |m_Ptr| may be left pointing to invalid memory. Beware. - // TODO(tsepez): Mark single-argument string constructors as explicit. - CFX_ByteStringC(FX_CHAR& ch) - { - m_Ptr = (const uint8_t*)&ch; - m_Length = 1; - } - - CFX_ByteStringC(const FX_CHAR* ptr, FX_STRSIZE len) - { - m_Ptr = (const uint8_t*)ptr; - m_Length = (len == -1) ? FXSYS_strlen(ptr) : len; - } - - CFX_ByteStringC(const CFX_ByteStringC& src) - { - m_Ptr = src.m_Ptr; - m_Length = src.m_Length; - } +class CFX_ByteStringC { + public: + typedef FX_CHAR value_type; + + CFX_ByteStringC() { + m_Ptr = NULL; + m_Length = 0; + } + + CFX_ByteStringC(const uint8_t* ptr, FX_STRSIZE size) { + m_Ptr = ptr; + m_Length = size; + } + + CFX_ByteStringC(const FX_CHAR* ptr) { + m_Ptr = (const uint8_t*)ptr; + m_Length = ptr ? FXSYS_strlen(ptr) : 0; + } + + // |ch| must be an lvalue that outlives the the CFX_ByteStringC. However, + // the use of char rvalues are not caught at compile time. They are + // implicitly promoted to CFX_ByteString (see below) and then the + // CFX_ByteStringC is constructed from the CFX_ByteString via the alternate + // constructor below. The CFX_ByteString then typically goes out of scope + // and |m_Ptr| may be left pointing to invalid memory. Beware. + // TODO(tsepez): Mark single-argument string constructors as explicit. + CFX_ByteStringC(FX_CHAR& ch) { + m_Ptr = (const uint8_t*)&ch; + m_Length = 1; + } + + CFX_ByteStringC(const FX_CHAR* ptr, FX_STRSIZE len) { + m_Ptr = (const uint8_t*)ptr; + m_Length = (len == -1) ? FXSYS_strlen(ptr) : len; + } + + CFX_ByteStringC(const CFX_ByteStringC& src) { + m_Ptr = src.m_Ptr; + m_Length = src.m_Length; + } + + CFX_ByteStringC(const CFX_ByteString& src); + + CFX_ByteStringC& operator=(const FX_CHAR* src) { + m_Ptr = (const uint8_t*)src; + m_Length = m_Ptr ? FXSYS_strlen(src) : 0; + return *this; + } - CFX_ByteStringC(const CFX_ByteString& src); + CFX_ByteStringC& operator=(const CFX_ByteStringC& src) { + m_Ptr = src.m_Ptr; + m_Length = src.m_Length; + return *this; + } - CFX_ByteStringC& operator = (const FX_CHAR* src) - { - m_Ptr = (const uint8_t*)src; - m_Length = m_Ptr ? FXSYS_strlen(src) : 0; - return *this; - } + CFX_ByteStringC& operator=(const CFX_ByteString& src); - CFX_ByteStringC& operator = (const CFX_ByteStringC& src) - { - m_Ptr = src.m_Ptr; - m_Length = src.m_Length; - return *this; - } + bool operator==(const char* ptr) const { + return FXSYS_strlen(ptr) == m_Length && + FXSYS_memcmp(ptr, m_Ptr, m_Length) == 0; + } + bool operator==(const CFX_ByteStringC& other) const { + return other.m_Length == m_Length && + FXSYS_memcmp(other.m_Ptr, m_Ptr, m_Length) == 0; + } + bool operator!=(const char* ptr) const { return !(*this == ptr); } + bool operator!=(const CFX_ByteStringC& other) const { + return !(*this == other); + } - CFX_ByteStringC& operator = (const CFX_ByteString& src); + FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; - bool operator== (const char* ptr) const { - return FXSYS_strlen(ptr) == m_Length && - FXSYS_memcmp(ptr, m_Ptr, m_Length) == 0; - } - bool operator== (const CFX_ByteStringC& other) const { - return other.m_Length == m_Length && - FXSYS_memcmp(other.m_Ptr, m_Ptr, m_Length) == 0; - } - bool operator!= (const char* ptr) const { return !(*this == ptr); } - bool operator!= (const CFX_ByteStringC& other) const { - return !(*this == other); - } + const uint8_t* GetPtr() const { return m_Ptr; } - FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; + const FX_CHAR* GetCStr() const { return (const FX_CHAR*)m_Ptr; } - const uint8_t* GetPtr() const - { - return m_Ptr; - } + FX_STRSIZE GetLength() const { return m_Length; } - const FX_CHAR* GetCStr() const - { - return (const FX_CHAR*)m_Ptr; - } + bool IsEmpty() const { return m_Length == 0; } - FX_STRSIZE GetLength() const - { - return m_Length; - } + uint8_t GetAt(FX_STRSIZE index) const { return m_Ptr[index]; } - bool IsEmpty() const - { - return m_Length == 0; + CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const { + if (index < 0) { + index = 0; } - - uint8_t GetAt(FX_STRSIZE index) const - { - return m_Ptr[index]; + if (index > m_Length) { + return CFX_ByteStringC(); } - - CFX_ByteStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const - { - if (index < 0) { - index = 0; - } - if (index > m_Length) { - return CFX_ByteStringC(); - } - if (count < 0 || count > m_Length - index) { - count = m_Length - index; - } - return CFX_ByteStringC(m_Ptr + index, count); + if (count < 0 || count > m_Length - index) { + count = m_Length - index; } + return CFX_ByteStringC(m_Ptr + index, count); + } - const uint8_t& operator[] (size_t index) const - { - return m_Ptr[index]; - } + const uint8_t& operator[](size_t index) const { return m_Ptr[index]; } - bool operator< (const CFX_ByteStringC& that) const - { - int result = memcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length)); - return result < 0 || (result == 0 && m_Length < that.m_Length); - } + bool operator<(const CFX_ByteStringC& that) const { + int result = memcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length)); + return result < 0 || (result == 0 && m_Length < that.m_Length); + } -protected: - const uint8_t* m_Ptr; - FX_STRSIZE m_Length; + protected: + const uint8_t* m_Ptr; + FX_STRSIZE m_Length; -private: - void* operator new (size_t) throw() - { - return NULL; - } + private: + void* operator new(size_t) throw() { return NULL; } }; -inline bool operator== (const char* lhs, const CFX_ByteStringC& rhs) { - return rhs == lhs; +inline bool operator==(const char* lhs, const CFX_ByteStringC& rhs) { + return rhs == lhs; } -inline bool operator!= (const char* lhs, const CFX_ByteStringC& rhs) { - return rhs != lhs; +inline bool operator!=(const char* lhs, const CFX_ByteStringC& rhs) { + return rhs != lhs; } -#define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1) +#define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str - 1) #define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4)) // A mutable string with shared buffers using copy-on-write semantics that // avoids the cost of std::string's iterator stability guarantees. -class CFX_ByteString -{ -public: - typedef FX_CHAR value_type; +class CFX_ByteString { + public: + typedef FX_CHAR value_type; - CFX_ByteString() : m_pData(nullptr) { } + CFX_ByteString() : m_pData(nullptr) {} - // Copy constructor. - CFX_ByteString(const CFX_ByteString& str); + // Copy constructor. + CFX_ByteString(const CFX_ByteString& str); - // Move constructor. - inline CFX_ByteString(CFX_ByteString&& other) { - m_pData = other.m_pData; - other.m_pData = nullptr; - } + // Move constructor. + inline CFX_ByteString(CFX_ByteString&& other) { + m_pData = other.m_pData; + other.m_pData = nullptr; + } - CFX_ByteString(char ch); - CFX_ByteString(const FX_CHAR* ptr) - : CFX_ByteString(ptr, ptr ? FXSYS_strlen(ptr) : 0) { } + CFX_ByteString(char ch); + CFX_ByteString(const FX_CHAR* ptr) + : CFX_ByteString(ptr, ptr ? FXSYS_strlen(ptr) : 0) {} - CFX_ByteString(const FX_CHAR* ptr, FX_STRSIZE len); - CFX_ByteString(const uint8_t* ptr, FX_STRSIZE len); + CFX_ByteString(const FX_CHAR* ptr, FX_STRSIZE len); + CFX_ByteString(const uint8_t* ptr, FX_STRSIZE len); - CFX_ByteString(const CFX_ByteStringC& bstrc); - CFX_ByteString(const CFX_ByteStringC& bstrc1, const CFX_ByteStringC& bstrc2); + CFX_ByteString(const CFX_ByteStringC& bstrc); + CFX_ByteString(const CFX_ByteStringC& bstrc1, const CFX_ByteStringC& bstrc2); - ~CFX_ByteString(); + ~CFX_ByteString(); - static CFX_ByteString FromUnicode(const FX_WCHAR* ptr, FX_STRSIZE len = -1); + static CFX_ByteString FromUnicode(const FX_WCHAR* ptr, FX_STRSIZE len = -1); - static CFX_ByteString FromUnicode(const CFX_WideString& str); + static CFX_ByteString FromUnicode(const CFX_WideString& str); - // Explicit conversion to raw string - const FX_CHAR* c_str() const - { - return m_pData ? m_pData->m_String : ""; - } + // Explicit conversion to raw string + const FX_CHAR* c_str() const { return m_pData ? m_pData->m_String : ""; } - // Implicit conversion to C-style string -- deprecated - operator const FX_CHAR*() const - { - return m_pData ? m_pData->m_String : ""; - } + // Implicit conversion to C-style string -- deprecated + operator const FX_CHAR*() const { return m_pData ? m_pData->m_String : ""; } - operator const uint8_t*() const - { - return m_pData ? (const uint8_t*)m_pData->m_String : NULL; - } + operator const uint8_t*() const { + return m_pData ? (const uint8_t*)m_pData->m_String : NULL; + } - FX_STRSIZE GetLength() const - { - return m_pData ? m_pData->m_nDataLength : 0; - } - - bool IsEmpty() const - { - return !GetLength(); - } - - int Compare(const CFX_ByteStringC& str) const; + FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } + bool IsEmpty() const { return !GetLength(); } - bool Equal(const char* ptr) const; - bool Equal(const CFX_ByteStringC& str) const; - bool Equal(const CFX_ByteString& other) const; + int Compare(const CFX_ByteStringC& str) const; - bool EqualNoCase(const CFX_ByteStringC& str) const; + bool Equal(const char* ptr) const; + bool Equal(const CFX_ByteStringC& str) const; + bool Equal(const CFX_ByteString& other) const; - bool operator== (const char* ptr) const { return Equal(ptr); } - bool operator== (const CFX_ByteStringC& str) const { return Equal(str); } - bool operator== (const CFX_ByteString& other) const { return Equal(other); } - - bool operator!= (const char* ptr) const { return !(*this == ptr); } - bool operator!= (const CFX_ByteStringC& str) const { - return !(*this == str); - } - bool operator!= (const CFX_ByteString& other) const { - return !(*this == other); - } + bool EqualNoCase(const CFX_ByteStringC& str) const; - bool operator< (const CFX_ByteString& str) const - { - int result = FXSYS_memcmp(c_str(), str.c_str(), std::min(GetLength(), str.GetLength())); - return result < 0 || (result == 0 && GetLength() < str.GetLength()); - } + bool operator==(const char* ptr) const { return Equal(ptr); } + bool operator==(const CFX_ByteStringC& str) const { return Equal(str); } + bool operator==(const CFX_ByteString& other) const { return Equal(other); } - void Empty(); + bool operator!=(const char* ptr) const { return !(*this == ptr); } + bool operator!=(const CFX_ByteStringC& str) const { return !(*this == str); } + bool operator!=(const CFX_ByteString& other) const { + return !(*this == other); + } - const CFX_ByteString& operator = (const FX_CHAR* str); + bool operator<(const CFX_ByteString& str) const { + int result = FXSYS_memcmp(c_str(), str.c_str(), + std::min(GetLength(), str.GetLength())); + return result < 0 || (result == 0 && GetLength() < str.GetLength()); + } - const CFX_ByteString& operator = (const CFX_ByteStringC& bstrc); + void Empty(); - const CFX_ByteString& operator = (const CFX_ByteString& stringSrc); + const CFX_ByteString& operator=(const FX_CHAR* str); - const CFX_ByteString& operator = (const CFX_BinaryBuf& buf); + const CFX_ByteString& operator=(const CFX_ByteStringC& bstrc); - void Load(const uint8_t* str, FX_STRSIZE len); + const CFX_ByteString& operator=(const CFX_ByteString& stringSrc); - const CFX_ByteString& operator += (FX_CHAR ch); + const CFX_ByteString& operator=(const CFX_BinaryBuf& buf); - const CFX_ByteString& operator += (const FX_CHAR* str); + void Load(const uint8_t* str, FX_STRSIZE len); - const CFX_ByteString& operator += (const CFX_ByteString& str); + const CFX_ByteString& operator+=(FX_CHAR ch); - const CFX_ByteString& operator += (const CFX_ByteStringC& bstrc); + const CFX_ByteString& operator+=(const FX_CHAR* str); - uint8_t GetAt(FX_STRSIZE nIndex) const - { - return m_pData ? m_pData->m_String[nIndex] : 0; - } + const CFX_ByteString& operator+=(const CFX_ByteString& str); - uint8_t operator[](FX_STRSIZE nIndex) const - { - return m_pData ? m_pData->m_String[nIndex] : 0; - } + const CFX_ByteString& operator+=(const CFX_ByteStringC& bstrc); - void SetAt(FX_STRSIZE nIndex, FX_CHAR ch); + uint8_t GetAt(FX_STRSIZE nIndex) const { + return m_pData ? m_pData->m_String[nIndex] : 0; + } - FX_STRSIZE Insert(FX_STRSIZE index, FX_CHAR ch); + uint8_t operator[](FX_STRSIZE nIndex) const { + return m_pData ? m_pData->m_String[nIndex] : 0; + } - FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1); + void SetAt(FX_STRSIZE nIndex, FX_CHAR ch); + FX_STRSIZE Insert(FX_STRSIZE index, FX_CHAR ch); - void Format(const FX_CHAR* lpszFormat, ... ); + FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1); - void FormatV(const FX_CHAR* lpszFormat, va_list argList); + void Format(const FX_CHAR* lpszFormat, ...); + void FormatV(const FX_CHAR* lpszFormat, va_list argList); - void Reserve(FX_STRSIZE len); + void Reserve(FX_STRSIZE len); - FX_CHAR* GetBuffer(FX_STRSIZE len); + FX_CHAR* GetBuffer(FX_STRSIZE len); - void ReleaseBuffer(FX_STRSIZE len = -1); + void ReleaseBuffer(FX_STRSIZE len = -1); - CFX_ByteString Mid(FX_STRSIZE first) const; + CFX_ByteString Mid(FX_STRSIZE first) const; - CFX_ByteString Mid(FX_STRSIZE first, FX_STRSIZE count) const; + CFX_ByteString Mid(FX_STRSIZE first, FX_STRSIZE count) const; - CFX_ByteString Left(FX_STRSIZE count) const; + CFX_ByteString Left(FX_STRSIZE count) const; - CFX_ByteString Right(FX_STRSIZE count) const; + CFX_ByteString Right(FX_STRSIZE count) const; - FX_STRSIZE Find(const CFX_ByteStringC& lpszSub, FX_STRSIZE start = 0) const; + FX_STRSIZE Find(const CFX_ByteStringC& lpszSub, FX_STRSIZE start = 0) const; - FX_STRSIZE Find(FX_CHAR ch, FX_STRSIZE start = 0) const; + FX_STRSIZE Find(FX_CHAR ch, FX_STRSIZE start = 0) const; - FX_STRSIZE ReverseFind(FX_CHAR ch) const; + FX_STRSIZE ReverseFind(FX_CHAR ch) const; - void MakeLower(); + void MakeLower(); - void MakeUpper(); + void MakeUpper(); - void TrimRight(); + void TrimRight(); - void TrimRight(FX_CHAR chTarget); + void TrimRight(FX_CHAR chTarget); - void TrimRight(const CFX_ByteStringC& lpszTargets); + void TrimRight(const CFX_ByteStringC& lpszTargets); - void TrimLeft(); + void TrimLeft(); - void TrimLeft(FX_CHAR chTarget); + void TrimLeft(FX_CHAR chTarget); - void TrimLeft(const CFX_ByteStringC& lpszTargets); + void TrimLeft(const CFX_ByteStringC& lpszTargets); - FX_STRSIZE Replace(const CFX_ByteStringC& lpszOld, const CFX_ByteStringC& lpszNew); + FX_STRSIZE Replace(const CFX_ByteStringC& lpszOld, + const CFX_ByteStringC& lpszNew); - FX_STRSIZE Remove(FX_CHAR ch); + FX_STRSIZE Remove(FX_CHAR ch); - CFX_WideString UTF8Decode() const; + CFX_WideString UTF8Decode() const; - void ConvertFrom(const CFX_WideString& str, CFX_CharMap* pCharMap = NULL); + void ConvertFrom(const CFX_WideString& str, CFX_CharMap* pCharMap = NULL); - FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; + FX_DWORD GetID(FX_STRSIZE start_pos = 0) const; -#define FXFORMAT_SIGNED 1 -#define FXFORMAT_HEX 2 -#define FXFORMAT_CAPITAL 4 +#define FXFORMAT_SIGNED 1 +#define FXFORMAT_HEX 2 +#define FXFORMAT_CAPITAL 4 - static CFX_ByteString FormatInteger(int i, FX_DWORD flags = 0); - static CFX_ByteString FormatFloat(FX_FLOAT f, int precision = 0); + static CFX_ByteString FormatInteger(int i, FX_DWORD flags = 0); + static CFX_ByteString FormatFloat(FX_FLOAT f, int precision = 0); -protected: - // To ensure ref counts do not overflow, consider the worst possible case: - // the entire address space contains nothing but pointers to this object. - // Since the count increments with each new pointer, the largest value is - // the number of pointers that can fit into the address space. The size of - // the address space itself is a good upper bound on it; we need not go - // larger. - class StringData { - public: - static StringData* Create(int nLen); - void Retain() { ++m_nRefs; } - void Release() { if (--m_nRefs <= 0) FX_Free(this); } + protected: + // To ensure ref counts do not overflow, consider the worst possible case: + // the entire address space contains nothing but pointers to this object. + // Since the count increments with each new pointer, the largest value is + // the number of pointers that can fit into the address space. The size of + // the address space itself is a good upper bound on it; we need not go + // larger. + class StringData { + public: + static StringData* Create(int nLen); + void Retain() { ++m_nRefs; } + void Release() { + if (--m_nRefs <= 0) + FX_Free(this); + } - intptr_t m_nRefs; // Would prefer ssize_t, but no windows support. - FX_STRSIZE m_nDataLength; - FX_STRSIZE m_nAllocLength; - FX_CHAR m_String[1]; + intptr_t m_nRefs; // Would prefer ssize_t, but no windows support. + FX_STRSIZE m_nDataLength; + FX_STRSIZE m_nAllocLength; + FX_CHAR m_String[1]; - private: - StringData(FX_STRSIZE dataLen, FX_STRSIZE allocLen) - : m_nRefs(1), m_nDataLength(dataLen), m_nAllocLength(allocLen) { - FXSYS_assert(dataLen >= 0); - FXSYS_assert(allocLen >= 0); - FXSYS_assert(dataLen <= allocLen); - m_String[dataLen] = 0; - } - ~StringData() = delete; - }; + private: + StringData(FX_STRSIZE dataLen, FX_STRSIZE allocLen) + : m_nRefs(1), m_nDataLength(dataLen), m_nAllocLength(allocLen) { + FXSYS_assert(dataLen >= 0); + FXSYS_assert(allocLen >= 0); + FXSYS_assert(dataLen <= allocLen); + m_String[dataLen] = 0; + } + ~StringData() = delete; + }; - void AllocCopy(CFX_ByteString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const; - void AssignCopy(FX_STRSIZE nSrcLen, const FX_CHAR* lpszSrcData); - void ConcatCopy(FX_STRSIZE nSrc1Len, const FX_CHAR* lpszSrc1Data, FX_STRSIZE nSrc2Len, const FX_CHAR* lpszSrc2Data); - void ConcatInPlace(FX_STRSIZE nSrcLen, const FX_CHAR* lpszSrcData); - void CopyBeforeWrite(); - void AllocBeforeWrite(FX_STRSIZE nLen); + void AllocCopy(CFX_ByteString& dest, + FX_STRSIZE nCopyLen, + FX_STRSIZE nCopyIndex) const; + void AssignCopy(FX_STRSIZE nSrcLen, const FX_CHAR* lpszSrcData); + void ConcatCopy(FX_STRSIZE nSrc1Len, + const FX_CHAR* lpszSrc1Data, + FX_STRSIZE nSrc2Len, + const FX_CHAR* lpszSrc2Data); + void ConcatInPlace(FX_STRSIZE nSrcLen, const FX_CHAR* lpszSrcData); + void CopyBeforeWrite(); + void AllocBeforeWrite(FX_STRSIZE nLen); - StringData* m_pData; - friend class fxcrt_ByteStringConcatInPlace_Test; + StringData* m_pData; + friend class fxcrt_ByteStringConcatInPlace_Test; }; -inline CFX_ByteStringC::CFX_ByteStringC(const CFX_ByteString& src) -{ - m_Ptr = (const uint8_t*)src; - m_Length = src.GetLength(); +inline CFX_ByteStringC::CFX_ByteStringC(const CFX_ByteString& src) { + m_Ptr = (const uint8_t*)src; + m_Length = src.GetLength(); } -inline CFX_ByteStringC& CFX_ByteStringC::operator = (const CFX_ByteString& src) -{ - m_Ptr = (const uint8_t*)src; - m_Length = src.GetLength(); - return *this; +inline CFX_ByteStringC& CFX_ByteStringC::operator=(const CFX_ByteString& src) { + m_Ptr = (const uint8_t*)src; + m_Length = src.GetLength(); + return *this; } -inline bool operator== (const char* lhs, const CFX_ByteString& rhs) { - return rhs == lhs; +inline bool operator==(const char* lhs, const CFX_ByteString& rhs) { + return rhs == lhs; } -inline bool operator== (const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { - return rhs == lhs; +inline bool operator==(const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { + return rhs == lhs; } -inline bool operator!= (const char* lhs, const CFX_ByteString& rhs) { - return rhs != lhs; +inline bool operator!=(const char* lhs, const CFX_ByteString& rhs) { + return rhs != lhs; } -inline bool operator!= (const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { - return rhs != lhs; +inline bool operator!=(const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { + return rhs != lhs; } -inline CFX_ByteString operator + (const CFX_ByteStringC& str1, const CFX_ByteStringC& str2) -{ - return CFX_ByteString(str1, str2); +inline CFX_ByteString operator+(const CFX_ByteStringC& str1, + const CFX_ByteStringC& str2) { + return CFX_ByteString(str1, str2); } -inline CFX_ByteString operator + (const CFX_ByteStringC& str1, const FX_CHAR* str2) -{ - return CFX_ByteString(str1, str2); +inline CFX_ByteString operator+(const CFX_ByteStringC& str1, + const FX_CHAR* str2) { + return CFX_ByteString(str1, str2); } -inline CFX_ByteString operator + (const FX_CHAR* str1, const CFX_ByteStringC& str2) -{ - return CFX_ByteString(str1, str2); +inline CFX_ByteString operator+(const FX_CHAR* str1, + const CFX_ByteStringC& str2) { + return CFX_ByteString(str1, str2); } -inline CFX_ByteString operator + (const CFX_ByteStringC& str1, FX_CHAR ch) -{ - return CFX_ByteString(str1, CFX_ByteStringC(ch)); +inline CFX_ByteString operator+(const CFX_ByteStringC& str1, FX_CHAR ch) { + return CFX_ByteString(str1, CFX_ByteStringC(ch)); } -inline CFX_ByteString operator + (FX_CHAR ch, const CFX_ByteStringC& str2) -{ - return CFX_ByteString(ch, str2); +inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteStringC& str2) { + return CFX_ByteString(ch, str2); } -inline CFX_ByteString operator + (const CFX_ByteString& str1, const CFX_ByteString& str2) -{ - return CFX_ByteString(str1, str2); +inline CFX_ByteString operator+(const CFX_ByteString& str1, + const CFX_ByteString& str2) { + return CFX_ByteString(str1, str2); } -inline CFX_ByteString operator + (const CFX_ByteString& str1, FX_CHAR ch) -{ - return CFX_ByteString(str1, CFX_ByteStringC(ch)); +inline CFX_ByteString operator+(const CFX_ByteString& str1, FX_CHAR ch) { + return CFX_ByteString(str1, CFX_ByteStringC(ch)); } -inline CFX_ByteString operator + (FX_CHAR ch, const CFX_ByteString& str2) -{ - return CFX_ByteString(ch, str2); +inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteString& str2) { + return CFX_ByteString(ch, str2); } -inline CFX_ByteString operator + (const CFX_ByteString& str1, const FX_CHAR* str2) -{ - return CFX_ByteString(str1, str2); +inline CFX_ByteString operator+(const CFX_ByteString& str1, + const FX_CHAR* str2) { + return CFX_ByteString(str1, str2); } -inline CFX_ByteString operator + (const FX_CHAR* str1, const CFX_ByteString& str2) -{ - return CFX_ByteString(str1, str2); +inline CFX_ByteString operator+(const FX_CHAR* str1, + const CFX_ByteString& str2) { + return CFX_ByteString(str1, str2); } -inline CFX_ByteString operator + (const CFX_ByteString& str1, const CFX_ByteStringC& str2) -{ - return CFX_ByteString(str1, str2); +inline CFX_ByteString operator+(const CFX_ByteString& str1, + const CFX_ByteStringC& str2) { + return CFX_ByteString(str1, str2); } -inline CFX_ByteString operator + (const CFX_ByteStringC& str1, const CFX_ByteString& str2) -{ - return CFX_ByteString(str1, str2); +inline CFX_ByteString operator+(const CFX_ByteStringC& str1, + const CFX_ByteString& str2) { + return CFX_ByteString(str1, str2); } -class CFX_WideStringC -{ -public: - typedef FX_WCHAR value_type; +class CFX_WideStringC { + public: + typedef FX_WCHAR value_type; - CFX_WideStringC() - { - m_Ptr = NULL; - m_Length = 0; - } + CFX_WideStringC() { + m_Ptr = NULL; + m_Length = 0; + } - CFX_WideStringC(const FX_WCHAR* ptr) - { - m_Ptr = ptr; - m_Length = ptr ? FXSYS_wcslen(ptr) : 0; - } + CFX_WideStringC(const FX_WCHAR* ptr) { + m_Ptr = ptr; + m_Length = ptr ? FXSYS_wcslen(ptr) : 0; + } - CFX_WideStringC(FX_WCHAR& ch) - { - m_Ptr = &ch; - m_Length = 1; - } + CFX_WideStringC(FX_WCHAR& ch) { + m_Ptr = &ch; + m_Length = 1; + } - CFX_WideStringC(const FX_WCHAR* ptr, FX_STRSIZE len) - { - m_Ptr = ptr; - m_Length = (len == -1) ? FXSYS_wcslen(ptr) : len; - } + CFX_WideStringC(const FX_WCHAR* ptr, FX_STRSIZE len) { + m_Ptr = ptr; + m_Length = (len == -1) ? FXSYS_wcslen(ptr) : len; + } - CFX_WideStringC(const CFX_WideStringC& src) - { - m_Ptr = src.m_Ptr; - m_Length = src.m_Length; - } + CFX_WideStringC(const CFX_WideStringC& src) { + m_Ptr = src.m_Ptr; + m_Length = src.m_Length; + } - CFX_WideStringC(const CFX_WideString& src); + CFX_WideStringC(const CFX_WideString& src); - CFX_WideStringC& operator = (const FX_WCHAR* src) - { - m_Ptr = src; - m_Length = FXSYS_wcslen(src); - return *this; - } + CFX_WideStringC& operator=(const FX_WCHAR* src) { + m_Ptr = src; + m_Length = FXSYS_wcslen(src); + return *this; + } - CFX_WideStringC& operator = (const CFX_WideStringC& src) - { - m_Ptr = src.m_Ptr; - m_Length = src.m_Length; - return *this; - } + CFX_WideStringC& operator=(const CFX_WideStringC& src) { + m_Ptr = src.m_Ptr; + m_Length = src.m_Length; + return *this; + } - CFX_WideStringC& operator = (const CFX_WideString& src); + CFX_WideStringC& operator=(const CFX_WideString& src); - bool operator== (const wchar_t* ptr) const { - return FXSYS_wcslen(ptr) == m_Length && - wmemcmp(ptr, m_Ptr, m_Length) == 0; - } - bool operator== (const CFX_WideStringC& str) const { - return str.m_Length == m_Length && - wmemcmp(str.m_Ptr, m_Ptr, m_Length) == 0; - } - bool operator!= (const wchar_t* ptr) const { return !(*this == ptr); } - bool operator!= (const CFX_WideStringC& str) const { - return !(*this == str); - } + bool operator==(const wchar_t* ptr) const { + return FXSYS_wcslen(ptr) == m_Length && wmemcmp(ptr, m_Ptr, m_Length) == 0; + } + bool operator==(const CFX_WideStringC& str) const { + return str.m_Length == m_Length && wmemcmp(str.m_Ptr, m_Ptr, m_Length) == 0; + } + bool operator!=(const wchar_t* ptr) const { return !(*this == ptr); } + bool operator!=(const CFX_WideStringC& str) const { return !(*this == str); } - const FX_WCHAR* GetPtr() const - { - return m_Ptr; - } + const FX_WCHAR* GetPtr() const { return m_Ptr; } - FX_STRSIZE GetLength() const - { - return m_Length; - } + FX_STRSIZE GetLength() const { return m_Length; } - bool IsEmpty() const - { - return m_Length == 0; - } + bool IsEmpty() const { return m_Length == 0; } - FX_WCHAR GetAt(FX_STRSIZE index) const - { - return m_Ptr[index]; - } + FX_WCHAR GetAt(FX_STRSIZE index) const { return m_Ptr[index]; } - CFX_WideStringC Left(FX_STRSIZE count) const - { - if (count < 1) { - return CFX_WideStringC(); - } - if (count > m_Length) { - count = m_Length; - } - return CFX_WideStringC(m_Ptr, count); + CFX_WideStringC Left(FX_STRSIZE count) const { + if (count < 1) { + return CFX_WideStringC(); } - - CFX_WideStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const - { - if (index < 0) { - index = 0; - } - if (index > m_Length) { - return CFX_WideStringC(); - } - if (count < 0 || count > m_Length - index) { - count = m_Length - index; - } - return CFX_WideStringC(m_Ptr + index, count); + if (count > m_Length) { + count = m_Length; } + return CFX_WideStringC(m_Ptr, count); + } - CFX_WideStringC Right(FX_STRSIZE count) const - { - if (count < 1) { - return CFX_WideStringC(); - } - if (count > m_Length) { - count = m_Length; - } - return CFX_WideStringC(m_Ptr + m_Length - count, count); + CFX_WideStringC Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const { + if (index < 0) { + index = 0; } + if (index > m_Length) { + return CFX_WideStringC(); + } + if (count < 0 || count > m_Length - index) { + count = m_Length - index; + } + return CFX_WideStringC(m_Ptr + index, count); + } - const FX_WCHAR& operator[] (size_t index) const - { - return m_Ptr[index]; + CFX_WideStringC Right(FX_STRSIZE count) const { + if (count < 1) { + return CFX_WideStringC(); + } + if (count > m_Length) { + count = m_Length; } + return CFX_WideStringC(m_Ptr + m_Length - count, count); + } - bool operator< (const CFX_WideStringC& that) const - { - int result = wmemcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length)); - return result < 0 || (result == 0 && m_Length < that.m_Length); - } + const FX_WCHAR& operator[](size_t index) const { return m_Ptr[index]; } -protected: - const FX_WCHAR* m_Ptr; - FX_STRSIZE m_Length; + bool operator<(const CFX_WideStringC& that) const { + int result = wmemcmp(m_Ptr, that.m_Ptr, std::min(m_Length, that.m_Length)); + return result < 0 || (result == 0 && m_Length < that.m_Length); + } -private: - void* operator new (size_t) throw() - { - return NULL; - } + protected: + const FX_WCHAR* m_Ptr; + FX_STRSIZE m_Length; + + private: + void* operator new(size_t) throw() { return NULL; } }; -inline bool operator== (const wchar_t* lhs, const CFX_WideStringC& rhs) { - return rhs == lhs; +inline bool operator==(const wchar_t* lhs, const CFX_WideStringC& rhs) { + return rhs == lhs; } -inline bool operator!= (const wchar_t* lhs, const CFX_WideStringC& rhs) { - return rhs != lhs; +inline bool operator!=(const wchar_t* lhs, const CFX_WideStringC& rhs) { + return rhs != lhs; } #define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) // A mutable string with shared buffers using copy-on-write semantics that // avoids the cost of std::string's iterator stability guarantees. -class CFX_WideString -{ -public: - typedef FX_WCHAR value_type; +class CFX_WideString { + public: + typedef FX_WCHAR value_type; - CFX_WideString() : m_pData(nullptr) { } + CFX_WideString() : m_pData(nullptr) {} - // Copy constructor. - CFX_WideString(const CFX_WideString& str); + // Copy constructor. + CFX_WideString(const CFX_WideString& str); - // Move constructor. - inline CFX_WideString(CFX_WideString&& other) { - m_pData = other.m_pData; - other.m_pData = nullptr; - } + // Move constructor. + inline CFX_WideString(CFX_WideString&& other) { + m_pData = other.m_pData; + other.m_pData = nullptr; + } - CFX_WideString(const FX_WCHAR* ptr) - : CFX_WideString(ptr, ptr ? FXSYS_wcslen(ptr) : 0) { } + CFX_WideString(const FX_WCHAR* ptr) + : CFX_WideString(ptr, ptr ? FXSYS_wcslen(ptr) : 0) {} - CFX_WideString(const FX_WCHAR* ptr, FX_STRSIZE len); + CFX_WideString(const FX_WCHAR* ptr, FX_STRSIZE len); - CFX_WideString(FX_WCHAR ch); + CFX_WideString(FX_WCHAR ch); - CFX_WideString(const CFX_WideStringC& str); + CFX_WideString(const CFX_WideStringC& str); - CFX_WideString(const CFX_WideStringC& str1, const CFX_WideStringC& str2); + CFX_WideString(const CFX_WideStringC& str1, const CFX_WideStringC& str2); - ~CFX_WideString(); + ~CFX_WideString(); - static CFX_WideString FromLocal(const char* str, FX_STRSIZE len = -1); + static CFX_WideString FromLocal(const char* str, FX_STRSIZE len = -1); - static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len); + static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len); - static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len); + static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len); - static FX_STRSIZE WStringLength(const unsigned short* str); + static FX_STRSIZE WStringLength(const unsigned short* str); - // Explicit conversion to raw string - const FX_WCHAR* c_str() const - { - return m_pData ? m_pData->m_String : L""; - } + // Explicit conversion to raw string + const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; } - // Implicit conversion to C-style wide string -- deprecated - operator const FX_WCHAR*() const - { - return m_pData ? m_pData->m_String : L""; - } + // Implicit conversion to C-style wide string -- deprecated + operator const FX_WCHAR*() const { return m_pData ? m_pData->m_String : L""; } - void Empty(); + void Empty(); + FX_BOOL IsEmpty() const { return !GetLength(); } - FX_BOOL IsEmpty() const - { - return !GetLength(); - } + FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } - FX_STRSIZE GetLength() const - { - return m_pData ? m_pData->m_nDataLength : 0; - } + const CFX_WideString& operator=(const FX_WCHAR* str); - const CFX_WideString& operator = (const FX_WCHAR* str); + const CFX_WideString& operator=(const CFX_WideString& stringSrc); - const CFX_WideString& operator =(const CFX_WideString& stringSrc); + const CFX_WideString& operator=(const CFX_WideStringC& stringSrc); - const CFX_WideString& operator =(const CFX_WideStringC& stringSrc); + const CFX_WideString& operator+=(const FX_WCHAR* str); - const CFX_WideString& operator += (const FX_WCHAR* str); + const CFX_WideString& operator+=(FX_WCHAR ch); - const CFX_WideString& operator += (FX_WCHAR ch); + const CFX_WideString& operator+=(const CFX_WideString& str); - const CFX_WideString& operator += (const CFX_WideString& str); + const CFX_WideString& operator+=(const CFX_WideStringC& str); - const CFX_WideString& operator += (const CFX_WideStringC& str); + bool operator==(const wchar_t* ptr) const { return Equal(ptr); } + bool operator==(const CFX_WideStringC& str) const { return Equal(str); } + bool operator==(const CFX_WideString& other) const { return Equal(other); } - bool operator== (const wchar_t* ptr) const { return Equal(ptr); } - bool operator== (const CFX_WideStringC& str) const { return Equal(str); } - bool operator== (const CFX_WideString& other) const { return Equal(other); } + bool operator!=(const wchar_t* ptr) const { return !(*this == ptr); } + bool operator!=(const CFX_WideStringC& str) const { return !(*this == str); } + bool operator!=(const CFX_WideString& other) const { + return !(*this == other); + } - bool operator!= (const wchar_t* ptr) const { return !(*this == ptr); } - bool operator!= (const CFX_WideStringC& str) const { - return !(*this == str); - } - bool operator!= (const CFX_WideString& other) const { - return !(*this == other); - } + bool operator<(const CFX_WideString& str) const { + int result = + wmemcmp(c_str(), str.c_str(), std::min(GetLength(), str.GetLength())); + return result < 0 || (result == 0 && GetLength() < str.GetLength()); + } - bool operator< (const CFX_WideString& str) const { - int result = wmemcmp(c_str(), str.c_str(), std::min(GetLength(), str.GetLength())); - return result < 0 || (result == 0 && GetLength() < str.GetLength()); - } + FX_WCHAR GetAt(FX_STRSIZE nIndex) const { + return m_pData ? m_pData->m_String[nIndex] : 0; + } - FX_WCHAR GetAt(FX_STRSIZE nIndex) const - { - return m_pData ? m_pData->m_String[nIndex] : 0; - } - - FX_WCHAR operator[](FX_STRSIZE nIndex) const - { - return m_pData ? m_pData->m_String[nIndex] : 0; - } + FX_WCHAR operator[](FX_STRSIZE nIndex) const { + return m_pData ? m_pData->m_String[nIndex] : 0; + } - void SetAt(FX_STRSIZE nIndex, FX_WCHAR ch); + void SetAt(FX_STRSIZE nIndex, FX_WCHAR ch); - int Compare(const FX_WCHAR* str) const; + int Compare(const FX_WCHAR* str) const; - int Compare(const CFX_WideString& str) const; + int Compare(const CFX_WideString& str) const; - int CompareNoCase(const FX_WCHAR* str) const; + int CompareNoCase(const FX_WCHAR* str) const; - bool Equal(const wchar_t* ptr) const; - bool Equal(const CFX_WideStringC& str) const; - bool Equal(const CFX_WideString& other) const; + bool Equal(const wchar_t* ptr) const; + bool Equal(const CFX_WideStringC& str) const; + bool Equal(const CFX_WideString& other) const; - CFX_WideString Mid(FX_STRSIZE first) const; + CFX_WideString Mid(FX_STRSIZE first) const; - CFX_WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const; + CFX_WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const; - CFX_WideString Left(FX_STRSIZE count) const; + CFX_WideString Left(FX_STRSIZE count) const; - CFX_WideString Right(FX_STRSIZE count) const; + CFX_WideString Right(FX_STRSIZE count) const; - FX_STRSIZE Insert(FX_STRSIZE index, FX_WCHAR ch); + FX_STRSIZE Insert(FX_STRSIZE index, FX_WCHAR ch); - FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1); + FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1); - void Format(const FX_WCHAR* lpszFormat, ... ); + void Format(const FX_WCHAR* lpszFormat, ...); - void FormatV(const FX_WCHAR* lpszFormat, va_list argList); + void FormatV(const FX_WCHAR* lpszFormat, va_list argList); - void MakeLower(); + void MakeLower(); - void MakeUpper(); + void MakeUpper(); - void TrimRight(); + void TrimRight(); - void TrimRight(FX_WCHAR chTarget); + void TrimRight(FX_WCHAR chTarget); - void TrimRight(const FX_WCHAR* lpszTargets); + void TrimRight(const FX_WCHAR* lpszTargets); - void TrimLeft(); + void TrimLeft(); - void TrimLeft(FX_WCHAR chTarget); + void TrimLeft(FX_WCHAR chTarget); - void TrimLeft(const FX_WCHAR* lpszTargets); + void TrimLeft(const FX_WCHAR* lpszTargets); - void Reserve(FX_STRSIZE len); + void Reserve(FX_STRSIZE len); - FX_WCHAR* GetBuffer(FX_STRSIZE len); + FX_WCHAR* GetBuffer(FX_STRSIZE len); - void ReleaseBuffer(FX_STRSIZE len = -1); + void ReleaseBuffer(FX_STRSIZE len = -1); - int GetInteger() const; + int GetInteger() const; - FX_FLOAT GetFloat() const; + FX_FLOAT GetFloat() const; - FX_STRSIZE Find(const FX_WCHAR* lpszSub, FX_STRSIZE start = 0) const; + FX_STRSIZE Find(const FX_WCHAR* lpszSub, FX_STRSIZE start = 0) const; - FX_STRSIZE Find(FX_WCHAR ch, FX_STRSIZE start = 0) const; + FX_STRSIZE Find(FX_WCHAR ch, FX_STRSIZE start = 0) const; - FX_STRSIZE Replace(const FX_WCHAR* lpszOld, const FX_WCHAR* lpszNew); + FX_STRSIZE Replace(const FX_WCHAR* lpszOld, const FX_WCHAR* lpszNew); - FX_STRSIZE Remove(FX_WCHAR ch); + FX_STRSIZE Remove(FX_WCHAR ch); - CFX_ByteString UTF8Encode() const; + CFX_ByteString UTF8Encode() const; - CFX_ByteString UTF16LE_Encode() const; + CFX_ByteString UTF16LE_Encode() const; - void ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMap = NULL); + void ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMap = NULL); -protected: - class StringData { - public: - static StringData* Create(int nLen); - void Retain() { ++m_nRefs; } - void Release() { if (--m_nRefs <= 0) FX_Free(this); } + protected: + class StringData { + public: + static StringData* Create(int nLen); + void Retain() { ++m_nRefs; } + void Release() { + if (--m_nRefs <= 0) + FX_Free(this); + } - intptr_t m_nRefs; // Would prefer ssize_t, but no windows support. - FX_STRSIZE m_nDataLength; - FX_STRSIZE m_nAllocLength; - FX_WCHAR m_String[1]; + intptr_t m_nRefs; // Would prefer ssize_t, but no windows support. + FX_STRSIZE m_nDataLength; + FX_STRSIZE m_nAllocLength; + FX_WCHAR m_String[1]; - private: - StringData(FX_STRSIZE dataLen, FX_STRSIZE allocLen) - : m_nRefs(1), m_nDataLength(dataLen), m_nAllocLength(allocLen) { - FXSYS_assert(dataLen >= 0); - FXSYS_assert(allocLen >= 0); - FXSYS_assert(dataLen <= allocLen); - m_String[dataLen] = 0; - } - ~StringData() = delete; - }; + private: + StringData(FX_STRSIZE dataLen, FX_STRSIZE allocLen) + : m_nRefs(1), m_nDataLength(dataLen), m_nAllocLength(allocLen) { + FXSYS_assert(dataLen >= 0); + FXSYS_assert(allocLen >= 0); + FXSYS_assert(dataLen <= allocLen); + m_String[dataLen] = 0; + } + ~StringData() = delete; + }; - void CopyBeforeWrite(); - void AllocBeforeWrite(FX_STRSIZE nLen); - void ConcatInPlace(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData); - void ConcatCopy(FX_STRSIZE nSrc1Len, const FX_WCHAR* lpszSrc1Data, FX_STRSIZE nSrc2Len, const FX_WCHAR* lpszSrc2Data); - void AssignCopy(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData); - void AllocCopy(CFX_WideString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex) const; + void CopyBeforeWrite(); + void AllocBeforeWrite(FX_STRSIZE nLen); + void ConcatInPlace(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData); + void ConcatCopy(FX_STRSIZE nSrc1Len, + const FX_WCHAR* lpszSrc1Data, + FX_STRSIZE nSrc2Len, + const FX_WCHAR* lpszSrc2Data); + void AssignCopy(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData); + void AllocCopy(CFX_WideString& dest, + FX_STRSIZE nCopyLen, + FX_STRSIZE nCopyIndex) const; - StringData* m_pData; - friend class fxcrt_WideStringConcatInPlace_Test; + StringData* m_pData; + friend class fxcrt_WideStringConcatInPlace_Test; }; -inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src) -{ - m_Ptr = src.c_str(); - m_Length = src.GetLength(); -} -inline CFX_WideStringC& CFX_WideStringC::operator = (const CFX_WideString& src) -{ - m_Ptr = src.c_str(); - m_Length = src.GetLength(); - return *this; +inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src) { + m_Ptr = src.c_str(); + m_Length = src.GetLength(); +} +inline CFX_WideStringC& CFX_WideStringC::operator=(const CFX_WideString& src) { + m_Ptr = src.c_str(); + m_Length = src.GetLength(); + return *this; } -inline CFX_WideString operator + (const CFX_WideStringC& str1, const CFX_WideStringC& str2) -{ - return CFX_WideString(str1, str2); +inline CFX_WideString operator+(const CFX_WideStringC& str1, + const CFX_WideStringC& str2) { + return CFX_WideString(str1, str2); } -inline CFX_WideString operator + (const CFX_WideStringC& str1, const FX_WCHAR* str2) -{ - return CFX_WideString(str1, str2); +inline CFX_WideString operator+(const CFX_WideStringC& str1, + const FX_WCHAR* str2) { + return CFX_WideString(str1, str2); } -inline CFX_WideString operator + (const FX_WCHAR* str1, const CFX_WideStringC& str2) -{ - return CFX_WideString(str1, str2); +inline CFX_WideString operator+(const FX_WCHAR* str1, + const CFX_WideStringC& str2) { + return CFX_WideString(str1, str2); } -inline CFX_WideString operator + (const CFX_WideStringC& str1, FX_WCHAR ch) -{ - return CFX_WideString(str1, CFX_WideStringC(ch)); +inline CFX_WideString operator+(const CFX_WideStringC& str1, FX_WCHAR ch) { + return CFX_WideString(str1, CFX_WideStringC(ch)); } -inline CFX_WideString operator + (FX_WCHAR ch, const CFX_WideStringC& str2) -{ - return CFX_WideString(ch, str2); +inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideStringC& str2) { + return CFX_WideString(ch, str2); } -inline CFX_WideString operator + (const CFX_WideString& str1, const CFX_WideString& str2) -{ - return CFX_WideString(str1, str2); +inline CFX_WideString operator+(const CFX_WideString& str1, + const CFX_WideString& str2) { + return CFX_WideString(str1, str2); } -inline CFX_WideString operator + (const CFX_WideString& str1, FX_WCHAR ch) -{ - return CFX_WideString(str1, CFX_WideStringC(ch)); +inline CFX_WideString operator+(const CFX_WideString& str1, FX_WCHAR ch) { + return CFX_WideString(str1, CFX_WideStringC(ch)); } -inline CFX_WideString operator + (FX_WCHAR ch, const CFX_WideString& str2) -{ - return CFX_WideString(ch, str2); +inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideString& str2) { + return CFX_WideString(ch, str2); } -inline CFX_WideString operator + (const CFX_WideString& str1, const FX_WCHAR* str2) -{ - return CFX_WideString(str1, str2); +inline CFX_WideString operator+(const CFX_WideString& str1, + const FX_WCHAR* str2) { + return CFX_WideString(str1, str2); } -inline CFX_WideString operator + (const FX_WCHAR* str1, const CFX_WideString& str2) -{ - return CFX_WideString(str1, str2); +inline CFX_WideString operator+(const FX_WCHAR* str1, + const CFX_WideString& str2) { + return CFX_WideString(str1, str2); } -inline CFX_WideString operator + (const CFX_WideString& str1, const CFX_WideStringC& str2) -{ - return CFX_WideString(str1, str2); +inline CFX_WideString operator+(const CFX_WideString& str1, + const CFX_WideStringC& str2) { + return CFX_WideString(str1, str2); } -inline CFX_WideString operator + (const CFX_WideStringC& str1, const CFX_WideString& str2) -{ - return CFX_WideString(str1, str2); +inline CFX_WideString operator+(const CFX_WideStringC& str1, + const CFX_WideString& str2) { + return CFX_WideString(str1, str2); } -inline bool operator== (const wchar_t* lhs, const CFX_WideString& rhs) { - return rhs == lhs; +inline bool operator==(const wchar_t* lhs, const CFX_WideString& rhs) { + return rhs == lhs; } -inline bool operator== (const CFX_WideStringC& lhs, const CFX_WideString& rhs) { - return rhs == lhs; +inline bool operator==(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { + return rhs == lhs; } -inline bool operator!= (const wchar_t* lhs, const CFX_WideString& rhs) { - return rhs != lhs; +inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { + return rhs != lhs; } -inline bool operator!= (const CFX_WideStringC& lhs, const CFX_WideString& rhs) { - return rhs != lhs; +inline bool operator!=(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { + return rhs != lhs; } FX_FLOAT FX_atof(const CFX_ByteStringC& str); void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); -CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len); -inline CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) -{ - return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); -} -inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr) -{ - return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); +CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len); +inline CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { + return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()); +} +inline CFX_ByteString FX_UTF8Encode(const CFX_WideString& wsStr) { + return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); } #endif // CORE_INCLUDE_FXCRT_FX_STRING_H_ diff --git a/core/include/fxcrt/fx_system.h b/core/include/fxcrt/fx_system.h index 8bc2b4ab2a..f0d403501c 100644 --- a/core/include/fxcrt/fx_system.h +++ b/core/include/fxcrt/fx_system.h @@ -18,17 +18,17 @@ #include <wchar.h> // _FX_OS_ values: -#define _FX_WIN32_DESKTOP_ 1 -#define _FX_WIN64_DESKTOP_ 2 -#define _FX_LINUX_DESKTOP_ 4 -#define _FX_MACOSX_ 7 -#define _FX_ANDROID_ 12 +#define _FX_WIN32_DESKTOP_ 1 +#define _FX_WIN64_DESKTOP_ 2 +#define _FX_LINUX_DESKTOP_ 4 +#define _FX_MACOSX_ 7 +#define _FX_ANDROID_ 12 // _FXM_PLATFORM_ values; -#define _FXM_PLATFORM_WINDOWS_ 1 // _FX_WIN32_DESKTOP_ or _FX_WIN64_DESKTOP_. -#define _FXM_PLATFORM_LINUX_ 2 // _FX_LINUX_DESKTOP_ always. -#define _FXM_PLATFORM_APPLE_ 3 // _FX_MACOSX_ always. -#define _FXM_PLATFORM_ANDROID_ 4 // _FX_ANDROID_ always. +#define _FXM_PLATFORM_WINDOWS_ 1 // _FX_WIN32_DESKTOP_ or _FX_WIN64_DESKTOP_. +#define _FXM_PLATFORM_LINUX_ 2 // _FX_LINUX_DESKTOP_ always. +#define _FXM_PLATFORM_APPLE_ 3 // _FX_MACOSX_ always. +#define _FXM_PLATFORM_ANDROID_ 4 // _FX_ANDROID_ always. #ifndef _FX_OS_ #if defined(__ANDROID__) @@ -67,13 +67,13 @@ #ifdef __cplusplus extern "C" { #endif -typedef void* FX_POSITION; // Keep until fxcrt containers gone -typedef unsigned short FX_WORD; // Keep - "an efficient small type" -typedef unsigned int FX_DWORD; // Keep - "an efficient type" -typedef float FX_FLOAT; // Keep, allow upgrade to doubles. -typedef int FX_BOOL; // Keep, sadly not always 0 or 1. -typedef char FX_CHAR; // Keep, questionable signedness. -typedef wchar_t FX_WCHAR; // Keep, maybe bad platform wchars. +typedef void* FX_POSITION; // Keep until fxcrt containers gone +typedef unsigned short FX_WORD; // Keep - "an efficient small type" +typedef unsigned int FX_DWORD; // Keep - "an efficient type" +typedef float FX_FLOAT; // Keep, allow upgrade to doubles. +typedef int FX_BOOL; // Keep, sadly not always 0 or 1. +typedef char FX_CHAR; // Keep, questionable signedness. +typedef wchar_t FX_WCHAR; // Keep, maybe bad platform wchars. // PDFium string sizes are limited to 2^31-1, and the value is signed to // allow -1 as a placeholder for "unknown". @@ -85,15 +85,15 @@ typedef int FX_STRSIZE; #endif #ifndef TRUE -#define TRUE 1 +#define TRUE 1 #endif #ifndef FALSE -#define FALSE 0 +#define FALSE 0 #endif #ifndef NULL -#define NULL 0 +#define NULL 0 #endif #define FXSYS_assert assert @@ -107,38 +107,41 @@ typedef int FX_STRSIZE; #define FX_MAX(a, b) (((a) > (b)) ? (a) : (b)) #define FX_MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define FX_PI 3.1415926535897932384626433832795f +#define FX_PI 3.1415926535897932384626433832795f // NOTE: prevent use of the return value from snprintf() since some platforms // have different return values (e.g. windows _vsnprintf()), and provide // versions that always NUL-terminate. #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 -void FXSYS_snprintf(char *str, size_t size, _Printf_format_string_ const char* fmt, ...); -void FXSYS_vsnprintf(char *str, size_t size, const char* fmt, va_list ap); +void FXSYS_snprintf(char* str, + size_t size, + _Printf_format_string_ const char* fmt, + ...); +void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap); #else -#define FXSYS_snprintf (void) snprintf -#define FXSYS_vsnprintf (void) vsnprintf +#define FXSYS_snprintf (void) snprintf +#define FXSYS_vsnprintf (void) vsnprintf #endif -#define FXSYS_sprintf DO_NOT_USE_SPRINTF_DIE_DIE_DIE -#define FXSYS_vsprintf DO_NOT_USE_VSPRINTF_DIE_DIE_DIE -#define FXSYS_strchr strchr -#define FXSYS_strncmp strncmp -#define FXSYS_strcmp strcmp -#define FXSYS_strcpy strcpy -#define FXSYS_strncpy strncpy -#define FXSYS_strstr strstr -#define FXSYS_FILE FILE -#define FXSYS_fopen fopen -#define FXSYS_fclose fclose -#define FXSYS_SEEK_END SEEK_END -#define FXSYS_SEEK_SET SEEK_SET -#define FXSYS_fseek fseek -#define FXSYS_ftell ftell -#define FXSYS_fread fread -#define FXSYS_fwrite fwrite -#define FXSYS_fprintf fprintf -#define FXSYS_fflush fflush +#define FXSYS_sprintf DO_NOT_USE_SPRINTF_DIE_DIE_DIE +#define FXSYS_vsprintf DO_NOT_USE_VSPRINTF_DIE_DIE_DIE +#define FXSYS_strchr strchr +#define FXSYS_strncmp strncmp +#define FXSYS_strcmp strcmp +#define FXSYS_strcpy strcpy +#define FXSYS_strncpy strncpy +#define FXSYS_strstr strstr +#define FXSYS_FILE FILE +#define FXSYS_fopen fopen +#define FXSYS_fclose fclose +#define FXSYS_SEEK_END SEEK_END +#define FXSYS_SEEK_SET SEEK_SET +#define FXSYS_fseek fseek +#define FXSYS_ftell ftell +#define FXSYS_fread fread +#define FXSYS_fwrite fwrite +#define FXSYS_fprintf fprintf +#define FXSYS_fflush fflush #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #ifdef _NATIVE_WCHAR_T_DEFINED @@ -151,7 +154,7 @@ FXSYS_FILE* FXSYS_wfopen(const FX_WCHAR* filename, const FX_WCHAR* mode); #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #ifdef __cplusplus -} // extern "C" +} // extern "C" #include "../../../third_party/base/numerics/safe_conversions.h" #define FXSYS_strlen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(strlen(ptr)) #define FXSYS_wcslen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(wcslen(ptr)) @@ -161,20 +164,20 @@ extern "C" { #define FXSYS_wcslen(ptr) ((FX_STRSIZE)wcslen(ptr)) #endif -#define FXSYS_wcscmp wcscmp -#define FXSYS_wcschr wcschr -#define FXSYS_wcsstr wcsstr -#define FXSYS_wcsncmp wcsncmp -#define FXSYS_vswprintf vswprintf -#define FXSYS_mbstowcs mbstowcs -#define FXSYS_wcstombs wcstombs -#define FXSYS_memcmp memcmp -#define FXSYS_memcpy memcpy -#define FXSYS_memmove memmove -#define FXSYS_memset memset -#define FXSYS_memchr memchr -#define FXSYS_qsort qsort -#define FXSYS_bsearch bsearch +#define FXSYS_wcscmp wcscmp +#define FXSYS_wcschr wcschr +#define FXSYS_wcsstr wcsstr +#define FXSYS_wcsncmp wcsncmp +#define FXSYS_vswprintf vswprintf +#define FXSYS_mbstowcs mbstowcs +#define FXSYS_wcstombs wcstombs +#define FXSYS_memcmp memcmp +#define FXSYS_memcpy memcpy +#define FXSYS_memmove memmove +#define FXSYS_memset memset +#define FXSYS_memchr memchr +#define FXSYS_qsort qsort +#define FXSYS_bsearch bsearch #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #define FXSYS_GetACP GetACP @@ -184,8 +187,10 @@ extern "C" { #define FXSYS_stricmp _stricmp #ifdef _NATIVE_WCHAR_T_DEFINED #define FXSYS_wcsicmp(str1, str2) _wcsicmp((wchar_t*)(str1), (wchar_t*)(str2)) -#define FXSYS_WideCharToMultiByte(p1, p2, p3, p4, p5, p6, p7, p8) WideCharToMultiByte(p1, p2, (const wchar_t*)(p3), p4, p5, p6, p7, p8) -#define FXSYS_MultiByteToWideChar(p1, p2, p3, p4, p5, p6) MultiByteToWideChar(p1, p2, p3, p4, (wchar_t*)(p5), p6) +#define FXSYS_WideCharToMultiByte(p1, p2, p3, p4, p5, p6, p7, p8) \ + WideCharToMultiByte(p1, p2, (const wchar_t*)(p3), p4, p5, p6, p7, p8) +#define FXSYS_MultiByteToWideChar(p1, p2, p3, p4, p5, p6) \ + MultiByteToWideChar(p1, p2, p3, p4, (wchar_t*)(p5), p6) #define FXSYS_wcslwr(str) _wcslwr((wchar_t*)(str)) #define FXSYS_wcsupr(str) _wcsupr((wchar_t*)(str)) #else @@ -198,58 +203,77 @@ extern "C" { #define FXSYS_GetFullPathName GetFullPathName #define FXSYS_GetModuleFileName GetModuleFileName #else -int FXSYS_GetACP(void); -char* FXSYS_itoa(int value, char* string, int radix); -int FXSYS_WideCharToMultiByte(FX_DWORD codepage, FX_DWORD dwFlags, const wchar_t* wstr, int wlen, - char* buf, int buflen, const char* default_str, int* pUseDefault); -int FXSYS_MultiByteToWideChar(FX_DWORD codepage, FX_DWORD dwFlags, const char* bstr, int blen, - wchar_t* buf, int buflen); -FX_DWORD FXSYS_GetFullPathName(const char* filename, FX_DWORD buflen, char* buf, char** filepart); -FX_DWORD FXSYS_GetModuleFileName(void* hModule, char* buf, FX_DWORD bufsize); -char* FXSYS_strlwr(char* str); -char* FXSYS_strupr(char* str); -int FXSYS_stricmp(const char*, const char*); -int FXSYS_wcsicmp(const wchar_t *string1, const wchar_t *string2); -wchar_t* FXSYS_wcslwr(wchar_t* str); -wchar_t* FXSYS_wcsupr(wchar_t* str); +int FXSYS_GetACP(void); +char* FXSYS_itoa(int value, char* string, int radix); +int FXSYS_WideCharToMultiByte(FX_DWORD codepage, + FX_DWORD dwFlags, + const wchar_t* wstr, + int wlen, + char* buf, + int buflen, + const char* default_str, + int* pUseDefault); +int FXSYS_MultiByteToWideChar(FX_DWORD codepage, + FX_DWORD dwFlags, + const char* bstr, + int blen, + wchar_t* buf, + int buflen); +FX_DWORD FXSYS_GetFullPathName(const char* filename, + FX_DWORD buflen, + char* buf, + char** filepart); +FX_DWORD FXSYS_GetModuleFileName(void* hModule, char* buf, FX_DWORD bufsize); +char* FXSYS_strlwr(char* str); +char* FXSYS_strupr(char* str); +int FXSYS_stricmp(const char*, const char*); +int FXSYS_wcsicmp(const wchar_t* string1, const wchar_t* string2); +wchar_t* FXSYS_wcslwr(wchar_t* str); +wchar_t* FXSYS_wcsupr(wchar_t* str); #endif // _FXM_PLATFORM == _FXM_PLATFORM_WINDOWS_ #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -#define FXSYS_pow(a, b) (FX_FLOAT)powf(a, b) +#define FXSYS_pow(a, b) (FX_FLOAT) powf(a, b) #else -#define FXSYS_pow(a, b) (FX_FLOAT)pow(a, b) +#define FXSYS_pow(a, b) (FX_FLOAT) pow(a, b) #endif -#define FXSYS_sqrt(a) (FX_FLOAT)sqrt(a) -#define FXSYS_fabs(a) (FX_FLOAT)fabs(a) -#define FXSYS_atan2(a, b) (FX_FLOAT)atan2(a, b) -#define FXSYS_ceil(a) (FX_FLOAT)ceil(a) -#define FXSYS_floor(a) (FX_FLOAT)floor(a) -#define FXSYS_cos(a) (FX_FLOAT)cos(a) -#define FXSYS_acos(a) (FX_FLOAT)acos(a) -#define FXSYS_sin(a) (FX_FLOAT)sin(a) -#define FXSYS_log(a) (FX_FLOAT)log(a) -#define FXSYS_log10(a) (FX_FLOAT)log10(a) -#define FXSYS_fmod(a, b) (FX_FLOAT)fmod(a, b) -#define FXSYS_abs abs -#define FXDWORD_FROM_LSBFIRST(i) (i) -#define FXDWORD_FROM_MSBFIRST(i) (((uint8_t)(i) << 24) | ((uint8_t)((i) >> 8) << 16) | ((uint8_t)((i) >> 16) << 8) | (uint8_t)((i) >> 24)) -#define FXDWORD_GET_LSBFIRST(p) ((((uint8_t*)(p))[3] << 24) | (((uint8_t*)(p))[2] << 16) | (((uint8_t*)(p))[1] << 8) | (((uint8_t*)(p))[0])) -#define FXDWORD_GET_MSBFIRST(p) ((((uint8_t*)(p))[0] << 24) | (((uint8_t*)(p))[1] << 16) | (((uint8_t*)(p))[2] << 8) | (((uint8_t*)(p))[3])) -#define FXSYS_HIBYTE(word) ((uint8_t)((word) >> 8)) -#define FXSYS_LOBYTE(word) ((uint8_t)(word)) -#define FXSYS_HIWORD(dword) ((FX_WORD)((dword) >> 16)) -#define FXSYS_LOWORD(dword) ((FX_WORD)(dword)) -int32_t FXSYS_atoi(const FX_CHAR* str); -int32_t FXSYS_wtoi(const FX_WCHAR* str); -int64_t FXSYS_atoi64(const FX_CHAR* str); -int64_t FXSYS_wtoi64(const FX_WCHAR* str); -const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix); -const FX_WCHAR* FXSYS_i64tow(int64_t value, FX_WCHAR* str, int radix); -int FXSYS_round(FX_FLOAT f); -#define FXSYS_Mul(a, b) ((a) * (b)) -#define FXSYS_Div(a, b) ((a) / (b)) -#define FXSYS_MulDiv(a, b, c) ((a) * (b) / (c)) -#define FXSYS_sqrt2(a, b) (FX_FLOAT)FXSYS_sqrt((a)*(a) + (b)*(b)) +#define FXSYS_sqrt(a) (FX_FLOAT) sqrt(a) +#define FXSYS_fabs(a) (FX_FLOAT) fabs(a) +#define FXSYS_atan2(a, b) (FX_FLOAT) atan2(a, b) +#define FXSYS_ceil(a) (FX_FLOAT) ceil(a) +#define FXSYS_floor(a) (FX_FLOAT) floor(a) +#define FXSYS_cos(a) (FX_FLOAT) cos(a) +#define FXSYS_acos(a) (FX_FLOAT) acos(a) +#define FXSYS_sin(a) (FX_FLOAT) sin(a) +#define FXSYS_log(a) (FX_FLOAT) log(a) +#define FXSYS_log10(a) (FX_FLOAT) log10(a) +#define FXSYS_fmod(a, b) (FX_FLOAT) fmod(a, b) +#define FXSYS_abs abs +#define FXDWORD_FROM_LSBFIRST(i) (i) +#define FXDWORD_FROM_MSBFIRST(i) \ + (((uint8_t)(i) << 24) | ((uint8_t)((i) >> 8) << 16) | \ + ((uint8_t)((i) >> 16) << 8) | (uint8_t)((i) >> 24)) +#define FXDWORD_GET_LSBFIRST(p) \ + ((((uint8_t*)(p))[3] << 24) | (((uint8_t*)(p))[2] << 16) | \ + (((uint8_t*)(p))[1] << 8) | (((uint8_t*)(p))[0])) +#define FXDWORD_GET_MSBFIRST(p) \ + ((((uint8_t*)(p))[0] << 24) | (((uint8_t*)(p))[1] << 16) | \ + (((uint8_t*)(p))[2] << 8) | (((uint8_t*)(p))[3])) +#define FXSYS_HIBYTE(word) ((uint8_t)((word) >> 8)) +#define FXSYS_LOBYTE(word) ((uint8_t)(word)) +#define FXSYS_HIWORD(dword) ((FX_WORD)((dword) >> 16)) +#define FXSYS_LOWORD(dword) ((FX_WORD)(dword)) +int32_t FXSYS_atoi(const FX_CHAR* str); +int32_t FXSYS_wtoi(const FX_WCHAR* str); +int64_t FXSYS_atoi64(const FX_CHAR* str); +int64_t FXSYS_wtoi64(const FX_WCHAR* str); +const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix); +const FX_WCHAR* FXSYS_i64tow(int64_t value, FX_WCHAR* str, int radix); +int FXSYS_round(FX_FLOAT f); +#define FXSYS_Mul(a, b) ((a) * (b)) +#define FXSYS_Div(a, b) ((a) / (b)) +#define FXSYS_MulDiv(a, b, c) ((a) * (b) / (c)) +#define FXSYS_sqrt2(a, b) (FX_FLOAT) FXSYS_sqrt((a) * (a) + (b) * (b)) #ifdef __cplusplus }; #endif @@ -286,7 +310,7 @@ int FXSYS_round(FX_FLOAT f); // Prevent a function from ever being inlined, typically because we'd // like it to appear in stack traces. -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ +#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #define NEVER_INLINE __declspec(noinline) #else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ #define NEVER_INLINE __attribute__((__noinline__)) diff --git a/core/include/fxcrt/fx_ucd.h b/core/include/fxcrt/fx_ucd.h index 84f6169d7e..fb417189a1 100644 --- a/core/include/fxcrt/fx_ucd.h +++ b/core/include/fxcrt/fx_ucd.h @@ -10,192 +10,184 @@ #include "fx_basic.h" enum FX_CHARBREAKPROP { - FX_CBP_OP = 0, - FX_CBP_CL = 1, - FX_CBP_QU = 2, - FX_CBP_GL = 3, - FX_CBP_NS = 4, - FX_CBP_EX = 5, - FX_CBP_SY = 6, - FX_CBP_IS = 7, - FX_CBP_PR = 8, - FX_CBP_PO = 9, - FX_CBP_NU = 10, - FX_CBP_AL = 11, - FX_CBP_ID = 12, - FX_CBP_IN = 13, - FX_CBP_HY = 14, - FX_CBP_BA = 15, - FX_CBP_BB = 16, - FX_CBP_B2 = 17, - FX_CBP_ZW = 18, - FX_CBP_CM = 19, - FX_CBP_WJ = 20, - FX_CBP_H2 = 21, - FX_CBP_H3 = 22, - FX_CBP_JL = 23, - FX_CBP_JV = 24, - FX_CBP_JT = 25, + FX_CBP_OP = 0, + FX_CBP_CL = 1, + FX_CBP_QU = 2, + FX_CBP_GL = 3, + FX_CBP_NS = 4, + FX_CBP_EX = 5, + FX_CBP_SY = 6, + FX_CBP_IS = 7, + FX_CBP_PR = 8, + FX_CBP_PO = 9, + FX_CBP_NU = 10, + FX_CBP_AL = 11, + FX_CBP_ID = 12, + FX_CBP_IN = 13, + FX_CBP_HY = 14, + FX_CBP_BA = 15, + FX_CBP_BB = 16, + FX_CBP_B2 = 17, + FX_CBP_ZW = 18, + FX_CBP_CM = 19, + FX_CBP_WJ = 20, + FX_CBP_H2 = 21, + FX_CBP_H3 = 22, + FX_CBP_JL = 23, + FX_CBP_JV = 24, + FX_CBP_JT = 25, - FX_CBP_BK = 26, - FX_CBP_CR = 27, - FX_CBP_LF = 28, - FX_CBP_NL = 29, - FX_CBP_SA = 30, - FX_CBP_SG = 31, - FX_CBP_CB = 32, - FX_CBP_XX = 33, - FX_CBP_AI = 34, - FX_CBP_SP = 35, - FX_CBP_TB = 37, - FX_CBP_NONE = 36, + FX_CBP_BK = 26, + FX_CBP_CR = 27, + FX_CBP_LF = 28, + FX_CBP_NL = 29, + FX_CBP_SA = 30, + FX_CBP_SG = 31, + FX_CBP_CB = 32, + FX_CBP_XX = 33, + FX_CBP_AI = 34, + FX_CBP_SP = 35, + FX_CBP_TB = 37, + FX_CBP_NONE = 36, }; -#define FX_BIDICLASSBITS 6 -#define FX_BIDICLASSBITSMASK (31 << FX_BIDICLASSBITS) +#define FX_BIDICLASSBITS 6 +#define FX_BIDICLASSBITSMASK (31 << FX_BIDICLASSBITS) enum FX_BIDICLASS { - FX_BIDICLASS_ON = 0, - FX_BIDICLASS_L = 1, - FX_BIDICLASS_R = 2, - FX_BIDICLASS_AN = 3, - FX_BIDICLASS_EN = 4, - FX_BIDICLASS_AL = 5, - FX_BIDICLASS_NSM = 6, - FX_BIDICLASS_CS = 7, - FX_BIDICLASS_ES = 8, - FX_BIDICLASS_ET = 9, - FX_BIDICLASS_BN = 10, - FX_BIDICLASS_S = 11, - FX_BIDICLASS_WS = 12, - FX_BIDICLASS_B = 13, - FX_BIDICLASS_RLO = 14, - FX_BIDICLASS_RLE = 15, - FX_BIDICLASS_LRO = 16, - FX_BIDICLASS_LRE = 17, - FX_BIDICLASS_PDF = 18, - FX_BIDICLASS_N = FX_BIDICLASS_ON, + FX_BIDICLASS_ON = 0, + FX_BIDICLASS_L = 1, + FX_BIDICLASS_R = 2, + FX_BIDICLASS_AN = 3, + FX_BIDICLASS_EN = 4, + FX_BIDICLASS_AL = 5, + FX_BIDICLASS_NSM = 6, + FX_BIDICLASS_CS = 7, + FX_BIDICLASS_ES = 8, + FX_BIDICLASS_ET = 9, + FX_BIDICLASS_BN = 10, + FX_BIDICLASS_S = 11, + FX_BIDICLASS_WS = 12, + FX_BIDICLASS_B = 13, + FX_BIDICLASS_RLO = 14, + FX_BIDICLASS_RLE = 15, + FX_BIDICLASS_LRO = 16, + FX_BIDICLASS_LRE = 17, + FX_BIDICLASS_PDF = 18, + FX_BIDICLASS_N = FX_BIDICLASS_ON, }; -#define FX_CHARTYPEBITS 11 -#define FX_CHARTYPEBITSMASK (15 << FX_CHARTYPEBITS) +#define FX_CHARTYPEBITS 11 +#define FX_CHARTYPEBITSMASK (15 << FX_CHARTYPEBITS) enum FX_CHARTYPE { - FX_CHARTYPE_Unknown = 0, - FX_CHARTYPE_Tab = (1 << FX_CHARTYPEBITS), - FX_CHARTYPE_Space = (2 << FX_CHARTYPEBITS), - FX_CHARTYPE_Control = (3 << FX_CHARTYPEBITS), - FX_CHARTYPE_Combination = (4 << FX_CHARTYPEBITS), - FX_CHARTYPE_Numeric = (5 << FX_CHARTYPEBITS), - FX_CHARTYPE_Normal = (6 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicAlef = (7 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicSpecial = (8 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicDistortion = (9 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicNormal = (10 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicForm = (11 << FX_CHARTYPEBITS), - FX_CHARTYPE_Arabic = (12 << FX_CHARTYPEBITS), + FX_CHARTYPE_Unknown = 0, + FX_CHARTYPE_Tab = (1 << FX_CHARTYPEBITS), + FX_CHARTYPE_Space = (2 << FX_CHARTYPEBITS), + FX_CHARTYPE_Control = (3 << FX_CHARTYPEBITS), + FX_CHARTYPE_Combination = (4 << FX_CHARTYPEBITS), + FX_CHARTYPE_Numeric = (5 << FX_CHARTYPEBITS), + FX_CHARTYPE_Normal = (6 << FX_CHARTYPEBITS), + FX_CHARTYPE_ArabicAlef = (7 << FX_CHARTYPEBITS), + FX_CHARTYPE_ArabicSpecial = (8 << FX_CHARTYPEBITS), + FX_CHARTYPE_ArabicDistortion = (9 << FX_CHARTYPEBITS), + FX_CHARTYPE_ArabicNormal = (10 << FX_CHARTYPEBITS), + FX_CHARTYPE_ArabicForm = (11 << FX_CHARTYPEBITS), + FX_CHARTYPE_Arabic = (12 << FX_CHARTYPEBITS), }; -typedef struct _FX_CHARPROPERTIES {
- union FX_CHARPROPERTIES_UNION{
- struct FX_CHARPROPERTIES_BIT{
- FX_DWORD dwBreakType : 6;
- FX_DWORD dwBidiClass : 5;
- FX_DWORD dwCharType : 4;
- FX_DWORD dwRotation : 1;
- FX_DWORD dwCJKSpecial : 1;
- FX_DWORD dwVertIndex : 6;
- FX_DWORD dwBidiIndex : 9;
- };
- FX_DWORD dwCharProps;
- };
-} FX_CHARPROPERTIES;
+typedef struct _FX_CHARPROPERTIES { + union FX_CHARPROPERTIES_UNION { + struct FX_CHARPROPERTIES_BIT { + FX_DWORD dwBreakType : 6; + FX_DWORD dwBidiClass : 5; + FX_DWORD dwCharType : 4; + FX_DWORD dwRotation : 1; + FX_DWORD dwCJKSpecial : 1; + FX_DWORD dwVertIndex : 6; + FX_DWORD dwBidiIndex : 9; + }; + FX_DWORD dwCharProps; + }; +} FX_CHARPROPERTIES; FX_DWORD FX_GetUnicodeProperties(FX_WCHAR wch); -FX_BOOL FX_IsCtrlCode(FX_WCHAR ch); -FX_BOOL FX_IsRotationCode(FX_WCHAR ch); +FX_BOOL FX_IsCtrlCode(FX_WCHAR ch); +FX_BOOL FX_IsRotationCode(FX_WCHAR ch); FX_BOOL FX_IsCombinationChar(FX_WCHAR wch); -FX_BOOL FX_IsBidiChar(FX_WCHAR wch); +FX_BOOL FX_IsBidiChar(FX_WCHAR wch); FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bRTL, FX_BOOL bVertical); -FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_DWORD dwProps, FX_BOOL bRTL, FX_BOOL bVertical); -class CFX_Char -{
-public:
- CFX_Char() : m_wCharCode(0)
- , m_nBreakType(0)
- , m_nRotation(0)
- , m_dwCharProps(0)
- , m_dwCharStyles(0)
- , m_iCharWidth(0)
- , m_iHorizontalScale(100)
- , m_iVertialScale(100)
- {
- }
- CFX_Char(FX_WORD wCharCode, FX_DWORD dwCharProps)
- : m_wCharCode(wCharCode)
- , m_nBreakType(0)
- , m_nRotation(0)
- , m_dwCharProps(dwCharProps)
- , m_dwCharStyles(0)
- , m_iCharWidth(0)
- , m_iHorizontalScale(100)
- , m_iVertialScale(100)
- {
- }
- FX_DWORD GetCharType() const
- {
- return m_dwCharProps & FX_CHARTYPEBITSMASK;
- }
- FX_WORD m_wCharCode;
- uint8_t m_nBreakType;
- int8_t m_nRotation;
- FX_DWORD m_dwCharProps;
- FX_DWORD m_dwCharStyles;
- int32_t m_iCharWidth;
- int32_t m_iHorizontalScale;
- int32_t m_iVertialScale;
-};
-typedef CFX_ArrayTemplate<CFX_Char> CFX_CharArray;
-class CFX_TxtChar : public CFX_Char
-{
-public:
- CFX_TxtChar() : CFX_Char()
- , m_dwStatus(0)
- , m_iBidiClass(0)
- , m_iBidiLevel(0)
- , m_iBidiPos(0)
- , m_iBidiOrder(0)
- , m_pUserData(NULL)
- {
- }
- FX_DWORD m_dwStatus;
- int16_t m_iBidiClass;
- int16_t m_iBidiLevel;
- int16_t m_iBidiPos;
- int16_t m_iBidiOrder;
- void* m_pUserData;
-};
-typedef CFX_ArrayTemplate<CFX_TxtChar> CFX_TxtCharArray;
-class CFX_RTFChar : public CFX_Char
-{
-public:
- CFX_RTFChar() : CFX_Char()
- , m_dwStatus(0)
- , m_iFontSize(0)
- , m_iFontHeight(0)
- , m_iBidiClass(0)
- , m_iBidiLevel(0)
- , m_iBidiPos(0)
- , m_dwLayoutStyles(0)
- , m_dwIdentity(0)
- , m_pUserData(NULL)
- {
- }
- FX_DWORD m_dwStatus;
- int32_t m_iFontSize;
- int32_t m_iFontHeight;
- int16_t m_iBidiClass;
- int16_t m_iBidiLevel;
- int16_t m_iBidiPos;
- int16_t m_iBidiOrder;
- FX_DWORD m_dwLayoutStyles;
- FX_DWORD m_dwIdentity;
- IFX_Unknown *m_pUserData;
-};
-typedef CFX_ArrayTemplate<CFX_RTFChar> CFX_RTFCharArray;
+FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, + FX_DWORD dwProps, + FX_BOOL bRTL, + FX_BOOL bVertical); +class CFX_Char { + public: + CFX_Char() + : m_wCharCode(0), + m_nBreakType(0), + m_nRotation(0), + m_dwCharProps(0), + m_dwCharStyles(0), + m_iCharWidth(0), + m_iHorizontalScale(100), + m_iVertialScale(100) {} + CFX_Char(FX_WORD wCharCode, FX_DWORD dwCharProps) + : m_wCharCode(wCharCode), + m_nBreakType(0), + m_nRotation(0), + m_dwCharProps(dwCharProps), + m_dwCharStyles(0), + m_iCharWidth(0), + m_iHorizontalScale(100), + m_iVertialScale(100) {} + FX_DWORD GetCharType() const { return m_dwCharProps & FX_CHARTYPEBITSMASK; } + FX_WORD m_wCharCode; + uint8_t m_nBreakType; + int8_t m_nRotation; + FX_DWORD m_dwCharProps; + FX_DWORD m_dwCharStyles; + int32_t m_iCharWidth; + int32_t m_iHorizontalScale; + int32_t m_iVertialScale; +}; +typedef CFX_ArrayTemplate<CFX_Char> CFX_CharArray; +class CFX_TxtChar : public CFX_Char { + public: + CFX_TxtChar() + : CFX_Char(), + m_dwStatus(0), + m_iBidiClass(0), + m_iBidiLevel(0), + m_iBidiPos(0), + m_iBidiOrder(0), + m_pUserData(NULL) {} + FX_DWORD m_dwStatus; + int16_t m_iBidiClass; + int16_t m_iBidiLevel; + int16_t m_iBidiPos; + int16_t m_iBidiOrder; + void* m_pUserData; +}; +typedef CFX_ArrayTemplate<CFX_TxtChar> CFX_TxtCharArray; +class CFX_RTFChar : public CFX_Char { + public: + CFX_RTFChar() + : CFX_Char(), + m_dwStatus(0), + m_iFontSize(0), + m_iFontHeight(0), + m_iBidiClass(0), + m_iBidiLevel(0), + m_iBidiPos(0), + m_dwLayoutStyles(0), + m_dwIdentity(0), + m_pUserData(NULL) {} + FX_DWORD m_dwStatus; + int32_t m_iFontSize; + int32_t m_iFontHeight; + int16_t m_iBidiClass; + int16_t m_iBidiLevel; + int16_t m_iBidiPos; + int16_t m_iBidiOrder; + FX_DWORD m_dwLayoutStyles; + FX_DWORD m_dwIdentity; + IFX_Unknown* m_pUserData; +}; +typedef CFX_ArrayTemplate<CFX_RTFChar> CFX_RTFCharArray; #endif // CORE_INCLUDE_FXCRT_FX_UCD_H_ diff --git a/core/include/fxcrt/fx_xml.h b/core/include/fxcrt/fx_xml.h index ba33b2083a..eaf872c164 100644 --- a/core/include/fxcrt/fx_xml.h +++ b/core/include/fxcrt/fx_xml.h @@ -9,172 +9,168 @@ #include "fx_basic.h" -class CXML_AttrItem -{ -public: - CFX_ByteString m_QSpaceName; - CFX_ByteString m_AttrName; - CFX_WideString m_Value; +class CXML_AttrItem { + public: + CFX_ByteString m_QSpaceName; + CFX_ByteString m_AttrName; + CFX_WideString m_Value; }; -class CXML_AttrMap -{ -public: - CXML_AttrMap() - { - m_pMap = NULL; - } - ~CXML_AttrMap() - { - RemoveAll(); - } - const CFX_WideString* Lookup(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const; - void SetAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name, const CFX_WideStringC& value); - void RemoveAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name); - void RemoveAll(); - int GetSize() const; - CXML_AttrItem& GetAt(int index) const; - CFX_ObjectArray<CXML_AttrItem>* m_pMap; +class CXML_AttrMap { + public: + CXML_AttrMap() { m_pMap = NULL; } + ~CXML_AttrMap() { RemoveAll(); } + const CFX_WideString* Lookup(const CFX_ByteStringC& space, + const CFX_ByteStringC& name) const; + void SetAt(const CFX_ByteStringC& space, + const CFX_ByteStringC& name, + const CFX_WideStringC& value); + void RemoveAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name); + void RemoveAll(); + int GetSize() const; + CXML_AttrItem& GetAt(int index) const; + CFX_ObjectArray<CXML_AttrItem>* m_pMap; }; -class CXML_Content -{ -public: - CXML_Content() : m_bCDATA(FALSE), m_Content() {} - void Set(FX_BOOL bCDATA, const CFX_WideStringC& content) - { - m_bCDATA = bCDATA; - m_Content = content; - } - FX_BOOL m_bCDATA; - CFX_WideString m_Content; +class CXML_Content { + public: + CXML_Content() : m_bCDATA(FALSE), m_Content() {} + void Set(FX_BOOL bCDATA, const CFX_WideStringC& content) { + m_bCDATA = bCDATA; + m_Content = content; + } + FX_BOOL m_bCDATA; + CFX_WideString m_Content; }; -class CXML_Element -{ -public: - static CXML_Element* Parse(const void* pBuffer, size_t size, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL); - static CXML_Element* Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL); - static CXML_Element* Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL); - CXML_Element(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagName); - CXML_Element(const CFX_ByteStringC& qTagName); - CXML_Element(); +class CXML_Element { + public: + static CXML_Element* Parse(const void* pBuffer, + size_t size, + FX_BOOL bSaveSpaceChars = FALSE, + FX_FILESIZE* pParsedSize = NULL); + static CXML_Element* Parse(IFX_FileRead* pFile, + FX_BOOL bSaveSpaceChars = FALSE, + FX_FILESIZE* pParsedSize = NULL); + static CXML_Element* Parse(IFX_BufferRead* pBuffer, + FX_BOOL bSaveSpaceChars = FALSE, + FX_FILESIZE* pParsedSize = NULL); + CXML_Element(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagName); + CXML_Element(const CFX_ByteStringC& qTagName); + CXML_Element(); + + ~CXML_Element(); + + void Empty(); + + CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const; + + CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const; + + CFX_ByteString GetNamespaceURI(const CFX_ByteStringC& qName) const; + + CXML_Element* GetParent() const { return m_pParent; } + + FX_DWORD CountAttrs() const { return m_AttrMap.GetSize(); } + + void GetAttrByIndex(int index, + CFX_ByteString& space, + CFX_ByteString& name, + CFX_WideString& value) const; + + FX_BOOL HasAttr(const CFX_ByteStringC& qName) const; + + FX_BOOL GetAttrValue(const CFX_ByteStringC& name, + CFX_WideString& attribute) const; + CFX_WideString GetAttrValue(const CFX_ByteStringC& name) const { + CFX_WideString attr; + GetAttrValue(name, attr); + return attr; + } + + FX_BOOL GetAttrValue(const CFX_ByteStringC& space, + const CFX_ByteStringC& name, + CFX_WideString& attribute) const; + CFX_WideString GetAttrValue(const CFX_ByteStringC& space, + const CFX_ByteStringC& name) const { + CFX_WideString attr; + GetAttrValue(space, name, attr); + return attr; + } + + FX_BOOL GetAttrInteger(const CFX_ByteStringC& name, int& attribute) const; + int GetAttrInteger(const CFX_ByteStringC& name) const { + int attr = 0; + GetAttrInteger(name, attr); + return attr; + } + + FX_BOOL GetAttrInteger(const CFX_ByteStringC& space, + const CFX_ByteStringC& name, + int& attribute) const; + int GetAttrInteger(const CFX_ByteStringC& space, + const CFX_ByteStringC& name) const { + int attr = 0; + GetAttrInteger(space, name, attr); + return attr; + } + + FX_BOOL GetAttrFloat(const CFX_ByteStringC& name, FX_FLOAT& attribute) const; + FX_FLOAT GetAttrFloat(const CFX_ByteStringC& name) const { + FX_FLOAT attr = 0; + GetAttrFloat(name, attr); + return attr; + } + + FX_BOOL GetAttrFloat(const CFX_ByteStringC& space, + const CFX_ByteStringC& name, + FX_FLOAT& attribute) const; + FX_FLOAT GetAttrFloat(const CFX_ByteStringC& space, + const CFX_ByteStringC& name) const { + FX_FLOAT attr = 0; + GetAttrFloat(space, name, attr); + return attr; + } + + FX_DWORD CountChildren() const; + + enum ChildType { Invalid, Element, Content }; + + ChildType GetChildType(FX_DWORD index) const; + + CFX_WideString GetContent(FX_DWORD index) const; + + CXML_Element* GetElement(FX_DWORD index) const; + + CXML_Element* GetElement(const CFX_ByteStringC& space, + const CFX_ByteStringC& tag) const { + return GetElement(space, tag, 0); + } + + FX_DWORD CountElements(const CFX_ByteStringC& space, + const CFX_ByteStringC& tag) const; - ~CXML_Element(); + CXML_Element* GetElement(const CFX_ByteStringC& space, + const CFX_ByteStringC& tag, + int index) const; - void Empty(); + FX_DWORD FindElement(CXML_Element* pChild) const; + void SetTag(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagname); + void SetTag(const CFX_ByteStringC& qTagName); - CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const; + void RemoveChildren(); - CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const; + void RemoveChild(FX_DWORD index); - CFX_ByteString GetNamespaceURI(const CFX_ByteStringC& qName) const; + protected: + CXML_Element* m_pParent; + CFX_ByteString m_QSpaceName; + CFX_ByteString m_TagName; - CXML_Element* GetParent() const - { - return m_pParent; - } - - FX_DWORD CountAttrs() const - { - return m_AttrMap.GetSize(); - } - - void GetAttrByIndex(int index, CFX_ByteString &space, CFX_ByteString &name, CFX_WideString &value) const; - - FX_BOOL HasAttr(const CFX_ByteStringC& qName) const; - - FX_BOOL GetAttrValue(const CFX_ByteStringC& name, CFX_WideString& attribute) const; - CFX_WideString GetAttrValue(const CFX_ByteStringC& name) const - { - CFX_WideString attr; - GetAttrValue(name, attr); - return attr; - } - - FX_BOOL GetAttrValue(const CFX_ByteStringC& space, const CFX_ByteStringC& name, CFX_WideString& attribute) const; - CFX_WideString GetAttrValue(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const - { - CFX_WideString attr; - GetAttrValue(space, name, attr); - return attr; - } - - FX_BOOL GetAttrInteger(const CFX_ByteStringC& name, int& attribute) const; - int GetAttrInteger(const CFX_ByteStringC& name) const - { - int attr = 0; - GetAttrInteger(name, attr); - return attr; - } - - FX_BOOL GetAttrInteger(const CFX_ByteStringC& space, const CFX_ByteStringC& name, int& attribute) const; - int GetAttrInteger(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const - { - int attr = 0; - GetAttrInteger(space, name, attr); - return attr; - } - - FX_BOOL GetAttrFloat(const CFX_ByteStringC& name, FX_FLOAT& attribute) const; - FX_FLOAT GetAttrFloat(const CFX_ByteStringC& name) const - { - FX_FLOAT attr = 0; - GetAttrFloat(name, attr); - return attr; - } - - FX_BOOL GetAttrFloat(const CFX_ByteStringC& space, const CFX_ByteStringC& name, FX_FLOAT& attribute) const; - FX_FLOAT GetAttrFloat(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const - { - FX_FLOAT attr = 0; - GetAttrFloat(space, name, attr); - return attr; - } - - FX_DWORD CountChildren() const; - - enum ChildType { Invalid, Element, Content}; - - ChildType GetChildType(FX_DWORD index) const; - - CFX_WideString GetContent(FX_DWORD index) const; - - CXML_Element* GetElement(FX_DWORD index) const; - - CXML_Element* GetElement(const CFX_ByteStringC& space, const CFX_ByteStringC& tag) const - { - return GetElement(space, tag, 0); - } - - FX_DWORD CountElements(const CFX_ByteStringC& space, const CFX_ByteStringC& tag) const; - - CXML_Element* GetElement(const CFX_ByteStringC& space, const CFX_ByteStringC& tag, int index) const; - - FX_DWORD FindElement(CXML_Element *pChild) const; - - - - - void SetTag(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagname); - - void SetTag(const CFX_ByteStringC& qTagName); - - void RemoveChildren(); - - void RemoveChild(FX_DWORD index); - - -protected: - - CXML_Element* m_pParent; - CFX_ByteString m_QSpaceName; - CFX_ByteString m_TagName; - - CXML_AttrMap m_AttrMap; - - CFX_PtrArray m_Children; - friend class CXML_Parser; - friend class CXML_Composer; + CXML_AttrMap m_AttrMap; + + CFX_PtrArray m_Children; + friend class CXML_Parser; + friend class CXML_Composer; }; #endif // CORE_INCLUDE_FXCRT_FX_XML_H_ diff --git a/core/include/fxge/fpf.h b/core/include/fxge/fpf.h index fb9bf4d111..efa001e916 100644 --- a/core/include/fxge/fpf.h +++ b/core/include/fxge/fpf.h @@ -12,55 +12,55 @@ class IFPF_DeviceModule; class IFPF_FontMgr; class IFPF_Font; -class IFPF_DeviceModule -{ -public: - virtual ~IFPF_DeviceModule() { } - virtual void Destroy() = 0; - virtual IFPF_FontMgr* GetFontMgr() = 0; +class IFPF_DeviceModule { + public: + virtual ~IFPF_DeviceModule() {} + virtual void Destroy() = 0; + virtual IFPF_FontMgr* GetFontMgr() = 0; }; -IFPF_DeviceModule* FPF_GetDeviceModule(); -#define FPF_MATCHFONT_REPLACEANSI 1 -typedef struct FPF_HFONT_ { - void* pData; -}* FPF_HFONT; -class IFPF_Font -{ -public: - virtual void Release() = 0; - virtual IFPF_Font* Retain() = 0; - virtual FPF_HFONT GetHandle() = 0; - virtual CFX_ByteString GetFamilyName() = 0; - virtual CFX_WideString GetPsName() = 0; - virtual FX_DWORD GetFontStyle() const = 0; - virtual uint8_t GetCharset() const = 0; +IFPF_DeviceModule* FPF_GetDeviceModule(); +#define FPF_MATCHFONT_REPLACEANSI 1 +typedef struct FPF_HFONT_ { void* pData; } * FPF_HFONT; +class IFPF_Font { + public: + virtual void Release() = 0; + virtual IFPF_Font* Retain() = 0; + virtual FPF_HFONT GetHandle() = 0; + virtual CFX_ByteString GetFamilyName() = 0; + virtual CFX_WideString GetPsName() = 0; + virtual FX_DWORD GetFontStyle() const = 0; + virtual uint8_t GetCharset() const = 0; - virtual int32_t GetGlyphIndex(FX_WCHAR wUnicode) = 0; - virtual int32_t GetGlyphWidth(int32_t iGlyphIndex) = 0; + virtual int32_t GetGlyphIndex(FX_WCHAR wUnicode) = 0; + virtual int32_t GetGlyphWidth(int32_t iGlyphIndex) = 0; - virtual int32_t GetAscent() const = 0; - virtual int32_t GetDescent() const = 0; + virtual int32_t GetAscent() const = 0; + virtual int32_t GetDescent() const = 0; - virtual FX_BOOL GetGlyphBBox(int32_t iGlyphIndex, FX_RECT &rtBBox) = 0; - virtual FX_BOOL GetBBox(FX_RECT &rtBBox) = 0; + virtual FX_BOOL GetGlyphBBox(int32_t iGlyphIndex, FX_RECT& rtBBox) = 0; + virtual FX_BOOL GetBBox(FX_RECT& rtBBox) = 0; - virtual int32_t GetHeight() const = 0; - virtual int32_t GetItalicAngle() const = 0; - virtual FX_DWORD GetFontData(FX_DWORD dwTable, uint8_t* pBuffer, FX_DWORD dwSize) = 0; + virtual int32_t GetHeight() const = 0; + virtual int32_t GetItalicAngle() const = 0; + virtual FX_DWORD GetFontData(FX_DWORD dwTable, + uint8_t* pBuffer, + FX_DWORD dwSize) = 0; -protected: - ~IFPF_Font() { } + protected: + ~IFPF_Font() {} }; -class IFPF_FontMgr -{ -public: - virtual ~IFPF_FontMgr() { } - virtual void LoadSystemFonts() = 0; - virtual void LoadPrivateFont(IFX_FileRead* pFontFile) = 0; - virtual void LoadPrivateFont(const CFX_ByteStringC& bsFileName) = 0; - virtual void LoadPrivateFont(void* pBuffer, size_t szBuffer) = 0; +class IFPF_FontMgr { + public: + virtual ~IFPF_FontMgr() {} + virtual void LoadSystemFonts() = 0; + virtual void LoadPrivateFont(IFX_FileRead* pFontFile) = 0; + virtual void LoadPrivateFont(const CFX_ByteStringC& bsFileName) = 0; + virtual void LoadPrivateFont(void* pBuffer, size_t szBuffer) = 0; - virtual IFPF_Font* CreateFont(const CFX_ByteStringC& bsFamilyname, uint8_t charset, FX_DWORD dwStyle, FX_DWORD dwMatch = 0) = 0; + virtual IFPF_Font* CreateFont(const CFX_ByteStringC& bsFamilyname, + uint8_t charset, + FX_DWORD dwStyle, + FX_DWORD dwMatch = 0) = 0; }; #endif // CORE_INCLUDE_FXGE_FPF_H_ diff --git a/core/include/fxge/fx_dib.h b/core/include/fxge/fx_dib.h index 27fc2f987d..ddc47d3db5 100644 --- a/core/include/fxge/fx_dib.h +++ b/core/include/fxge/fx_dib.h @@ -11,595 +11,681 @@ #include "../fxcrt/fx_coordinates.h" enum FXDIB_Format { - FXDIB_Invalid = 0, - FXDIB_1bppMask = 0x101, - FXDIB_1bppRgb = 0x001, - FXDIB_1bppCmyk = 0x401, - FXDIB_8bppMask = 0x108, - FXDIB_8bppRgb = 0x008, - FXDIB_8bppRgba = 0x208, - FXDIB_8bppCmyk = 0x408, - FXDIB_8bppCmyka = 0x608, - FXDIB_Rgb = 0x018, - FXDIB_Rgba = 0x218, - FXDIB_Rgb32 = 0x020, - FXDIB_Argb = 0x220, - FXDIB_Cmyk = 0x420, - FXDIB_Cmyka = 0x620, + FXDIB_Invalid = 0, + FXDIB_1bppMask = 0x101, + FXDIB_1bppRgb = 0x001, + FXDIB_1bppCmyk = 0x401, + FXDIB_8bppMask = 0x108, + FXDIB_8bppRgb = 0x008, + FXDIB_8bppRgba = 0x208, + FXDIB_8bppCmyk = 0x408, + FXDIB_8bppCmyka = 0x608, + FXDIB_Rgb = 0x018, + FXDIB_Rgba = 0x218, + FXDIB_Rgb32 = 0x020, + FXDIB_Argb = 0x220, + FXDIB_Cmyk = 0x420, + FXDIB_Cmyka = 0x620, }; enum FXDIB_Channel { - FXDIB_Red = 1, - FXDIB_Green, - FXDIB_Blue, - FXDIB_Cyan, - FXDIB_Magenta, - FXDIB_Yellow, - FXDIB_Black, - FXDIB_Alpha + FXDIB_Red = 1, + FXDIB_Green, + FXDIB_Blue, + FXDIB_Cyan, + FXDIB_Magenta, + FXDIB_Yellow, + FXDIB_Black, + FXDIB_Alpha }; -#define FXDIB_DOWNSAMPLE 0x04 -#define FXDIB_INTERPOL 0x20 -#define FXDIB_BICUBIC_INTERPOL 0x80 -#define FXDIB_NOSMOOTH 0x100 -#define FXDIB_PALETTE_LOC 0x01 -#define FXDIB_PALETTE_WIN 0x02 -#define FXDIB_PALETTE_MAC 0x04 -#define FXDIB_BLEND_NORMAL 0 -#define FXDIB_BLEND_MULTIPLY 1 -#define FXDIB_BLEND_SCREEN 2 -#define FXDIB_BLEND_OVERLAY 3 -#define FXDIB_BLEND_DARKEN 4 -#define FXDIB_BLEND_LIGHTEN 5 - -#define FXDIB_BLEND_COLORDODGE 6 -#define FXDIB_BLEND_COLORBURN 7 -#define FXDIB_BLEND_HARDLIGHT 8 -#define FXDIB_BLEND_SOFTLIGHT 9 -#define FXDIB_BLEND_DIFFERENCE 10 -#define FXDIB_BLEND_EXCLUSION 11 -#define FXDIB_BLEND_NONSEPARABLE 21 -#define FXDIB_BLEND_HUE 21 -#define FXDIB_BLEND_SATURATION 22 -#define FXDIB_BLEND_COLOR 23 -#define FXDIB_BLEND_LUMINOSITY 24 -#define FXDIB_BLEND_UNSUPPORTED -1 -typedef FX_DWORD FX_ARGB; -typedef FX_DWORD FX_COLORREF; -typedef FX_DWORD FX_CMYK; +#define FXDIB_DOWNSAMPLE 0x04 +#define FXDIB_INTERPOL 0x20 +#define FXDIB_BICUBIC_INTERPOL 0x80 +#define FXDIB_NOSMOOTH 0x100 +#define FXDIB_PALETTE_LOC 0x01 +#define FXDIB_PALETTE_WIN 0x02 +#define FXDIB_PALETTE_MAC 0x04 +#define FXDIB_BLEND_NORMAL 0 +#define FXDIB_BLEND_MULTIPLY 1 +#define FXDIB_BLEND_SCREEN 2 +#define FXDIB_BLEND_OVERLAY 3 +#define FXDIB_BLEND_DARKEN 4 +#define FXDIB_BLEND_LIGHTEN 5 + +#define FXDIB_BLEND_COLORDODGE 6 +#define FXDIB_BLEND_COLORBURN 7 +#define FXDIB_BLEND_HARDLIGHT 8 +#define FXDIB_BLEND_SOFTLIGHT 9 +#define FXDIB_BLEND_DIFFERENCE 10 +#define FXDIB_BLEND_EXCLUSION 11 +#define FXDIB_BLEND_NONSEPARABLE 21 +#define FXDIB_BLEND_HUE 21 +#define FXDIB_BLEND_SATURATION 22 +#define FXDIB_BLEND_COLOR 23 +#define FXDIB_BLEND_LUMINOSITY 24 +#define FXDIB_BLEND_UNSUPPORTED -1 +typedef FX_DWORD FX_ARGB; +typedef FX_DWORD FX_COLORREF; +typedef FX_DWORD FX_CMYK; class CFX_ClipRgn; class CFX_DIBSource; class CFX_DIBitmap; -#define FXSYS_RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16)) -#define FXSYS_GetRValue(rgb) ((rgb) & 0xff) +#define FXSYS_RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16)) +#define FXSYS_GetRValue(rgb) ((rgb)&0xff) #define FXSYS_GetGValue(rgb) (((rgb) >> 8) & 0xff) #define FXSYS_GetBValue(rgb) (((rgb) >> 16) & 0xff) -#define FX_CCOLOR(val) (255-(val)) +#define FX_CCOLOR(val) (255 - (val)) #define FXSYS_CMYK(c, m, y, k) (((c) << 24) | ((m) << 16) | ((y) << 8) | (k)) #define FXSYS_GetCValue(cmyk) ((uint8_t)((cmyk) >> 24) & 0xff) #define FXSYS_GetMValue(cmyk) ((uint8_t)((cmyk) >> 16) & 0xff) #define FXSYS_GetYValue(cmyk) ((uint8_t)((cmyk) >> 8) & 0xff) -#define FXSYS_GetKValue(cmyk) ((uint8_t)(cmyk) & 0xff) +#define FXSYS_GetKValue(cmyk) ((uint8_t)(cmyk)&0xff) void CmykDecode(FX_CMYK cmyk, int& c, int& m, int& y, int& k); -inline FX_CMYK CmykEncode(int c, int m, int y, int k) -{ - return (c << 24) | (m << 16) | (y << 8) | k; +inline FX_CMYK CmykEncode(int c, int m, int y, int k) { + return (c << 24) | (m << 16) | (y << 8) | k; } -void ArgbDecode(FX_ARGB argb, int& a, int& r, int&g, int& b); +void ArgbDecode(FX_ARGB argb, int& a, int& r, int& g, int& b); void ArgbDecode(FX_ARGB argb, int& a, FX_COLORREF& rgb); -inline FX_ARGB ArgbEncode(int a, int r, int g, int b) -{ - return (a << 24) | (r << 16) | (g << 8) | b; +inline FX_ARGB ArgbEncode(int a, int r, int g, int b) { + return (a << 24) | (r << 16) | (g << 8) | b; } FX_ARGB ArgbEncode(int a, FX_COLORREF rgb); #define FXARGB_A(argb) ((uint8_t)((argb) >> 24)) #define FXARGB_R(argb) ((uint8_t)((argb) >> 16)) #define FXARGB_G(argb) ((uint8_t)((argb) >> 8)) #define FXARGB_B(argb) ((uint8_t)(argb)) -#define FXARGB_MAKE(a,r,g,b) (((FX_DWORD)(a) << 24) | ((r) << 16) | ((g) << 8) | (b)) -#define FXARGB_MUL_ALPHA(argb, alpha) (((((argb) >> 24) * (alpha) / 255) << 24) | ((argb) & 0xffffff)) -#define FXRGB2GRAY(r,g,b) (((b) * 11 + (g) * 59 + (r) * 30) / 100) -#define FXCMYK2GRAY(c,m,y,k) (((255-(c)) * (255-(k)) * 30 + (255-(m)) * (255-(k)) * 59 + (255-(y)) * (255-(k)) * 11) / 25500) -#define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha) (((backdrop) * (255-(source_alpha)) + (source)*(source_alpha))/255) -#define FXDIB_ALPHA_UNION(dest, src) ((dest) + (src) - (dest)*(src)/255) -#define FXCMYK_GETDIB(p) ((((uint8_t*)(p))[0] << 24 | (((uint8_t*)(p))[1] << 16) | (((uint8_t*)(p))[2] << 8) | ((uint8_t*)(p))[3])) +#define FXARGB_MAKE(a, r, g, b) \ + (((FX_DWORD)(a) << 24) | ((r) << 16) | ((g) << 8) | (b)) +#define FXARGB_MUL_ALPHA(argb, alpha) \ + (((((argb) >> 24) * (alpha) / 255) << 24) | ((argb)&0xffffff)) +#define FXRGB2GRAY(r, g, b) (((b)*11 + (g)*59 + (r)*30) / 100) +#define FXCMYK2GRAY(c, m, y, k) \ + (((255 - (c)) * (255 - (k)) * 30 + (255 - (m)) * (255 - (k)) * 59 + \ + (255 - (y)) * (255 - (k)) * 11) / \ + 25500) +#define FXDIB_ALPHA_MERGE(backdrop, source, source_alpha) \ + (((backdrop) * (255 - (source_alpha)) + (source) * (source_alpha)) / 255) +#define FXDIB_ALPHA_UNION(dest, src) ((dest) + (src) - (dest) * (src) / 255) +#define FXCMYK_GETDIB(p) \ + ((((uint8_t*)(p))[0] << 24 | (((uint8_t*)(p))[1] << 16) | \ + (((uint8_t*)(p))[2] << 8) | ((uint8_t*)(p))[3])) #define FXCMYK_SETDIB(p, cmyk) ((uint8_t*)(p))[0] = (uint8_t)((cmyk) >> 24), \ ((uint8_t*)(p))[1] = (uint8_t)((cmyk) >> 16), \ ((uint8_t*)(p))[2] = (uint8_t)((cmyk) >> 8), \ ((uint8_t*)(p))[3] = (uint8_t)(cmyk)) -#define FXARGB_GETDIB(p) ((((uint8_t*)(p))[0]) | (((uint8_t*)(p))[1] << 8) | (((uint8_t*)(p))[2] << 16) | (((uint8_t*)(p))[3] << 24)) -#define FXARGB_SETDIB(p, argb) ((uint8_t*)(p))[0] = (uint8_t)(argb), \ - ((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8), \ - ((uint8_t*)(p))[2] = (uint8_t)((argb) >> 16), \ - ((uint8_t*)(p))[3] = (uint8_t)((argb) >> 24) -#define FXARGB_COPY(dest, src) *(uint8_t*)(dest) = *(uint8_t*)(src), \ - *((uint8_t*)(dest)+1) = *((uint8_t*)(src)+1), \ - *((uint8_t*)(dest)+2) = *((uint8_t*)(src)+2), \ - *((uint8_t*)(dest)+3) = *((uint8_t*)(src)+3) -#define FXCMYK_COPY(dest, src) *(uint8_t*)(dest) = *(uint8_t*)(src), \ - *((uint8_t*)(dest)+1) = *((uint8_t*)(src)+1), \ - *((uint8_t*)(dest)+2) = *((uint8_t*)(src)+2), \ - *((uint8_t*)(dest)+3) = *((uint8_t*)(src)+3) -#define FXARGB_SETRGBORDERDIB(p, argb) ((uint8_t*)(p))[3] = (uint8_t)(argb>>24), \ - ((uint8_t*)(p))[0] = (uint8_t)((argb) >> 16), \ - ((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8), \ - ((uint8_t*)(p))[2] = (uint8_t)(argb) -#define FXARGB_GETRGBORDERDIB(p) (((uint8_t*)(p))[2]) | (((uint8_t*)(p))[1] << 8) | (((uint8_t*)(p))[0] << 16) | (((uint8_t*)(p))[3] << 24) -#define FXARGB_RGBORDERCOPY(dest, src) *((uint8_t*)(dest)+3) = *((uint8_t*)(src)+3), \ - *(uint8_t*)(dest) = *((uint8_t*)(src)+2), \ - *((uint8_t*)(dest)+1) = *((uint8_t*)(src)+1), \ - *((uint8_t*)(dest)+2) = *((uint8_t*)(src)) +#define FXARGB_GETDIB(p) \ + ((((uint8_t*)(p))[0]) | (((uint8_t*)(p))[1] << 8) | \ + (((uint8_t*)(p))[2] << 16) | (((uint8_t*)(p))[3] << 24)) +#define FXARGB_SETDIB(p, argb) \ + ((uint8_t*)(p))[0] = (uint8_t)(argb), \ + ((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8), \ + ((uint8_t*)(p))[2] = (uint8_t)((argb) >> 16), \ + ((uint8_t*)(p))[3] = (uint8_t)((argb) >> 24) +#define FXARGB_COPY(dest, src) \ + *(uint8_t*)(dest) = *(uint8_t*)(src), \ + *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \ + *((uint8_t*)(dest) + 2) = *((uint8_t*)(src) + 2), \ + *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3) +#define FXCMYK_COPY(dest, src) \ + *(uint8_t*)(dest) = *(uint8_t*)(src), \ + *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \ + *((uint8_t*)(dest) + 2) = *((uint8_t*)(src) + 2), \ + *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3) +#define FXARGB_SETRGBORDERDIB(p, argb) \ + ((uint8_t*)(p))[3] = (uint8_t)(argb >> 24), \ + ((uint8_t*)(p))[0] = (uint8_t)((argb) >> 16), \ + ((uint8_t*)(p))[1] = (uint8_t)((argb) >> 8), \ + ((uint8_t*)(p))[2] = (uint8_t)(argb) +#define FXARGB_GETRGBORDERDIB(p) \ + (((uint8_t*)(p))[2]) | (((uint8_t*)(p))[1] << 8) | \ + (((uint8_t*)(p))[0] << 16) | (((uint8_t*)(p))[3] << 24) +#define FXARGB_RGBORDERCOPY(dest, src) \ + *((uint8_t*)(dest) + 3) = *((uint8_t*)(src) + 3), \ + *(uint8_t*)(dest) = *((uint8_t*)(src) + 2), \ + *((uint8_t*)(dest) + 1) = *((uint8_t*)(src) + 1), \ + *((uint8_t*)(dest) + 2) = *((uint8_t*)(src)) #define FXARGB_TODIB(argb) (argb) -#define FXCMYK_TODIB(cmyk) ((uint8_t)((cmyk) >> 24) | ((uint8_t)((cmyk) >> 16)) << 8 | ((uint8_t)((cmyk) >> 8)) << 16 | ((uint8_t)(cmyk) << 24)) -#define FXARGB_TOBGRORDERDIB(argb) ((uint8_t)(argb>>16) | ((uint8_t)(argb>>8)) << 8 | ((uint8_t)(argb)) << 16 | ((uint8_t)(argb>>24) << 24)) -#define FXGETFLAG_COLORTYPE(flag) (uint8_t)((flag)>>8) -#define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag) -#define FXGETFLAG_ALPHA_STROKE(flag) (uint8_t)((flag)>>16) -#define FXSETFLAG_COLORTYPE(flag, val) flag = (((val)<<8)|(flag&0xffff00ff)) -#define FXSETFLAG_ALPHA_FILL(flag, val) flag = ((val)|(flag&0xffffff00)) -#define FXSETFLAG_ALPHA_STROKE(flag, val) flag = (((val)<<16)|(flag&0xff00ffff)) -class CFX_DIBSource -{ -public: +#define FXCMYK_TODIB(cmyk) \ + ((uint8_t)((cmyk) >> 24) | ((uint8_t)((cmyk) >> 16)) << 8 | \ + ((uint8_t)((cmyk) >> 8)) << 16 | ((uint8_t)(cmyk) << 24)) +#define FXARGB_TOBGRORDERDIB(argb) \ + ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 | \ + ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24)) +#define FXGETFLAG_COLORTYPE(flag) (uint8_t)((flag) >> 8) +#define FXGETFLAG_ALPHA_FILL(flag) (uint8_t)(flag) +#define FXGETFLAG_ALPHA_STROKE(flag) (uint8_t)((flag) >> 16) +#define FXSETFLAG_COLORTYPE(flag, val) \ + flag = (((val) << 8) | (flag & 0xffff00ff)) +#define FXSETFLAG_ALPHA_FILL(flag, val) flag = ((val) | (flag & 0xffffff00)) +#define FXSETFLAG_ALPHA_STROKE(flag, val) \ + flag = (((val) << 16) | (flag & 0xff00ffff)) +class CFX_DIBSource { + public: + virtual ~CFX_DIBSource(); - virtual ~CFX_DIBSource(); + int GetWidth() const { return m_Width; } + int GetHeight() const { return m_Height; } + FXDIB_Format GetFormat() const { + return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp); + } - int GetWidth() const - { - return m_Width; - } + FX_DWORD GetPitch() const { return m_Pitch; } - int GetHeight() const - { - return m_Height; - } + FX_DWORD* GetPalette() const { return m_pPalette; } - FXDIB_Format GetFormat() const - { - return (FXDIB_Format)(m_AlphaFlag * 0x100 + m_bpp); - } + virtual uint8_t* GetBuffer() const { return NULL; } - FX_DWORD GetPitch() const - { - return m_Pitch; - } + virtual const uint8_t* GetScanline(int line) const = 0; - FX_DWORD* GetPalette() const - { - return m_pPalette; - } + virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const { + return FALSE; + } + virtual void DownSampleScanline(int line, + uint8_t* dest_scan, + int dest_bpp, + int dest_width, + FX_BOOL bFlipX, + int clip_left, + int clip_width) const = 0; + virtual void SetDownSampleSize(int width, int height) const {} - virtual uint8_t* GetBuffer() const - { - return NULL; - } + int GetBPP() const { return m_bpp; } - virtual const uint8_t* GetScanline(int line) const = 0; + FX_BOOL IsAlphaMask() const { return m_AlphaFlag == 1; } - virtual FX_BOOL SkipToScanline(int line, IFX_Pause* pPause) const - { - return FALSE; - } + FX_BOOL HasAlpha() const { return m_AlphaFlag & 2 ? TRUE : FALSE; } - virtual void DownSampleScanline(int line, uint8_t* dest_scan, int dest_bpp, - int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const = 0; + FX_BOOL IsOpaqueImage() const { return !(m_AlphaFlag & 3); } - virtual void SetDownSampleSize(int width, int height) const {} + FX_BOOL IsCmykImage() const { return m_AlphaFlag & 4 ? TRUE : FALSE; } - int GetBPP() const - { - return m_bpp; - } + int GetPaletteSize() const { + return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); + } - FX_BOOL IsAlphaMask() const - { - return m_AlphaFlag == 1; - } + FX_DWORD GetPaletteEntry(int index) const; - FX_BOOL HasAlpha() const - { - return m_AlphaFlag & 2 ? TRUE : FALSE; - } + void SetPaletteEntry(int index, FX_DWORD color); + FX_DWORD GetPaletteArgb(int index) const { return GetPaletteEntry(index); } + void SetPaletteArgb(int index, FX_DWORD color) { + SetPaletteEntry(index, color); + } - FX_BOOL IsOpaqueImage() const - { - return !(m_AlphaFlag & 3); - } + void CopyPalette(const FX_DWORD* pSrcPal, FX_DWORD size = 256); - FX_BOOL IsCmykImage() const - { - return m_AlphaFlag & 4 ? TRUE : FALSE; - } + CFX_DIBitmap* Clone(const FX_RECT* pClip = NULL) const; + CFX_DIBitmap* CloneConvert(FXDIB_Format format, + const FX_RECT* pClip = NULL, + void* pIccTransform = NULL) const; + CFX_DIBitmap* StretchTo(int dest_width, + int dest_height, + FX_DWORD flags = 0, + const FX_RECT* pClip = NULL) const; - int GetPaletteSize() const - { - return IsAlphaMask() ? 0 : (m_bpp == 1 ? 2 : (m_bpp == 8 ? 256 : 0)); - } + CFX_DIBitmap* TransformTo(const CFX_AffineMatrix* pMatrix, + int& left, + int& top, + FX_DWORD flags = 0, + const FX_RECT* pClip = NULL) const; - FX_DWORD GetPaletteEntry(int index) const; + CFX_DIBitmap* GetAlphaMask(const FX_RECT* pClip = NULL) const; - void SetPaletteEntry(int index, FX_DWORD color); - FX_DWORD GetPaletteArgb(int index) const - { - return GetPaletteEntry(index); - } - void SetPaletteArgb(int index, FX_DWORD color) - { - SetPaletteEntry(index, color); - } + FX_BOOL CopyAlphaMask(const CFX_DIBSource* pAlphaMask, + const FX_RECT* pClip = NULL); - void CopyPalette(const FX_DWORD* pSrcPal, FX_DWORD size = 256); + CFX_DIBitmap* SwapXY(FX_BOOL bXFlip, + FX_BOOL bYFlip, + const FX_RECT* pClip = NULL) const; + CFX_DIBitmap* FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const; - CFX_DIBitmap* Clone(const FX_RECT* pClip = NULL) const; + void GetOverlapRect(int& dest_left, + int& dest_top, + int& width, + int& height, + int src_width, + int src_height, + int& src_left, + int& src_top, + const CFX_ClipRgn* pClipRgn); - CFX_DIBitmap* CloneConvert(FXDIB_Format format, const FX_RECT* pClip = NULL, void* pIccTransform = NULL) const; + CFX_DIBitmap* m_pAlphaMask; - CFX_DIBitmap* StretchTo(int dest_width, int dest_height, FX_DWORD flags = 0, const FX_RECT* pClip = NULL) const; + protected: + CFX_DIBSource(); + int m_Width; - CFX_DIBitmap* TransformTo(const CFX_AffineMatrix* pMatrix, int& left, int &top, - FX_DWORD flags = 0, const FX_RECT* pClip = NULL) const; + int m_Height; - CFX_DIBitmap* GetAlphaMask(const FX_RECT* pClip = NULL) const; + int m_bpp; - FX_BOOL CopyAlphaMask(const CFX_DIBSource* pAlphaMask, const FX_RECT* pClip = NULL); + FX_DWORD m_AlphaFlag; - CFX_DIBitmap* SwapXY(FX_BOOL bXFlip, FX_BOOL bYFlip, const FX_RECT* pClip = NULL) const; + FX_DWORD m_Pitch; - CFX_DIBitmap* FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const; + FX_DWORD* m_pPalette; - void GetOverlapRect(int& dest_left, int& dest_top, int& width, int& height, int src_width, - int src_height, int& src_left, int& src_top, const CFX_ClipRgn* pClipRgn); + void BuildPalette(); - CFX_DIBitmap* m_pAlphaMask; -protected: + FX_BOOL BuildAlphaMask(); - CFX_DIBSource(); + int FindPalette(FX_DWORD color) const; - int m_Width; - - int m_Height; - - int m_bpp; - - FX_DWORD m_AlphaFlag; - - FX_DWORD m_Pitch; - - FX_DWORD* m_pPalette; - - void BuildPalette(); - - FX_BOOL BuildAlphaMask(); - - int FindPalette(FX_DWORD color) const; - - void GetPalette(FX_DWORD* pal, int alpha) const; + void GetPalette(FX_DWORD* pal, int alpha) const; }; -class CFX_DIBitmap : public CFX_DIBSource -{ -public: - - virtual ~CFX_DIBitmap(); - - CFX_DIBitmap(); - - CFX_DIBitmap(const CFX_DIBitmap& src); - - FX_BOOL Create(int width, int height, FXDIB_Format format, uint8_t* pBuffer = NULL, int pitch = 0); - - FX_BOOL Copy(const CFX_DIBSource* pSrc); - - virtual uint8_t* GetBuffer() const - { - return m_pBuffer; - } - - virtual const uint8_t* GetScanline(int line) const - { - return m_pBuffer ? m_pBuffer + line * m_Pitch : NULL; - } - - virtual void DownSampleScanline(int line, uint8_t* dest_scan, int dest_bpp, - int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const; - - void TakeOver(CFX_DIBitmap* pSrcBitmap); - - FX_BOOL ConvertFormat(FXDIB_Format format, void* pIccTransform = NULL); - - void Clear(FX_DWORD color); - - FX_DWORD GetPixel(int x, int y) const; - - void SetPixel(int x, int y, FX_DWORD color); - - FX_BOOL LoadChannel(FXDIB_Channel destChannel, const CFX_DIBSource* pSrcBitmap, FXDIB_Channel srcChannel); - - FX_BOOL LoadChannel(FXDIB_Channel destChannel, int value); - - FX_BOOL MultiplyAlpha(int alpha); - - FX_BOOL MultiplyAlpha(const CFX_DIBSource* pAlphaMask); - - FX_BOOL TransferBitmap(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, void* pIccTransform = NULL); - - FX_BOOL CompositeBitmap(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, - int blend_type = FXDIB_BLEND_NORMAL, const CFX_ClipRgn* pClipRgn = NULL, FX_BOOL bRgbByteOrder = FALSE, void* pIccTransform = NULL); - - FX_BOOL TransferMask(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top, int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL CompositeMask(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pMask, FX_DWORD color, int src_left, int src_top, - int blend_type = FXDIB_BLEND_NORMAL, const CFX_ClipRgn* pClipRgn = NULL, FX_BOOL bRgbByteOrder = FALSE, int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL CompositeRect(int dest_left, int dest_top, int width, int height, FX_DWORD color, int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL ConvertColorScale(FX_DWORD forecolor, FX_DWORD backcolor); - - FX_BOOL DitherFS(const FX_DWORD* pPalette, int pal_size, const FX_RECT* pRect = NULL); -protected: - - uint8_t* m_pBuffer; - - FX_BOOL m_bExtBuf; - - FX_BOOL GetGrayData(void* pIccTransform = NULL); +class CFX_DIBitmap : public CFX_DIBSource { + public: + virtual ~CFX_DIBitmap(); + + CFX_DIBitmap(); + + CFX_DIBitmap(const CFX_DIBitmap& src); + + FX_BOOL Create(int width, + int height, + FXDIB_Format format, + uint8_t* pBuffer = NULL, + int pitch = 0); + + FX_BOOL Copy(const CFX_DIBSource* pSrc); + + virtual uint8_t* GetBuffer() const { return m_pBuffer; } + + virtual const uint8_t* GetScanline(int line) const { + return m_pBuffer ? m_pBuffer + line * m_Pitch : NULL; + } + + virtual void DownSampleScanline(int line, + uint8_t* dest_scan, + int dest_bpp, + int dest_width, + FX_BOOL bFlipX, + int clip_left, + int clip_width) const; + + void TakeOver(CFX_DIBitmap* pSrcBitmap); + + FX_BOOL ConvertFormat(FXDIB_Format format, void* pIccTransform = NULL); + + void Clear(FX_DWORD color); + + FX_DWORD GetPixel(int x, int y) const; + + void SetPixel(int x, int y, FX_DWORD color); + + FX_BOOL LoadChannel(FXDIB_Channel destChannel, + const CFX_DIBSource* pSrcBitmap, + FXDIB_Channel srcChannel); + + FX_BOOL LoadChannel(FXDIB_Channel destChannel, int value); + + FX_BOOL MultiplyAlpha(int alpha); + + FX_BOOL MultiplyAlpha(const CFX_DIBSource* pAlphaMask); + + FX_BOOL TransferBitmap(int dest_left, + int dest_top, + int width, + int height, + const CFX_DIBSource* pSrcBitmap, + int src_left, + int src_top, + void* pIccTransform = NULL); + + FX_BOOL CompositeBitmap(int dest_left, + int dest_top, + int width, + int height, + const CFX_DIBSource* pSrcBitmap, + int src_left, + int src_top, + int blend_type = FXDIB_BLEND_NORMAL, + const CFX_ClipRgn* pClipRgn = NULL, + FX_BOOL bRgbByteOrder = FALSE, + void* pIccTransform = NULL); + + FX_BOOL TransferMask(int dest_left, + int dest_top, + int width, + int height, + const CFX_DIBSource* pMask, + FX_DWORD color, + int src_left, + int src_top, + int alpha_flag = 0, + void* pIccTransform = NULL); + + FX_BOOL CompositeMask(int dest_left, + int dest_top, + int width, + int height, + const CFX_DIBSource* pMask, + FX_DWORD color, + int src_left, + int src_top, + int blend_type = FXDIB_BLEND_NORMAL, + const CFX_ClipRgn* pClipRgn = NULL, + FX_BOOL bRgbByteOrder = FALSE, + int alpha_flag = 0, + void* pIccTransform = NULL); + + FX_BOOL CompositeRect(int dest_left, + int dest_top, + int width, + int height, + FX_DWORD color, + int alpha_flag = 0, + void* pIccTransform = NULL); + + FX_BOOL ConvertColorScale(FX_DWORD forecolor, FX_DWORD backcolor); + + FX_BOOL DitherFS(const FX_DWORD* pPalette, + int pal_size, + const FX_RECT* pRect = NULL); + + protected: + uint8_t* m_pBuffer; + + FX_BOOL m_bExtBuf; + + FX_BOOL GetGrayData(void* pIccTransform = NULL); }; -class CFX_DIBExtractor -{ -public: +class CFX_DIBExtractor { + public: + CFX_DIBExtractor(const CFX_DIBSource* pSrc); - CFX_DIBExtractor(const CFX_DIBSource* pSrc); + ~CFX_DIBExtractor(); - ~CFX_DIBExtractor(); + operator CFX_DIBitmap*() { return m_pBitmap; } - operator CFX_DIBitmap*() - { - return m_pBitmap; - } -private: - - CFX_DIBitmap* m_pBitmap; + private: + CFX_DIBitmap* m_pBitmap; }; typedef CFX_CountRef<CFX_DIBitmap> CFX_DIBitmapRef; -class CFX_FilteredDIB : public CFX_DIBSource -{ -public: - - CFX_FilteredDIB(); +class CFX_FilteredDIB : public CFX_DIBSource { + public: + CFX_FilteredDIB(); - ~CFX_FilteredDIB(); + ~CFX_FilteredDIB(); - void LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc = FALSE); + void LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc = FALSE); - virtual FXDIB_Format GetDestFormat() = 0; + virtual FXDIB_Format GetDestFormat() = 0; - virtual FX_DWORD* GetDestPalette() = 0; + virtual FX_DWORD* GetDestPalette() = 0; + virtual void TranslateScanline(uint8_t* dest_buf, + const uint8_t* src_buf) const = 0; - virtual void TranslateScanline(uint8_t* dest_buf, const uint8_t* src_buf) const = 0; + virtual void TranslateDownSamples(uint8_t* dest_buf, + const uint8_t* src_buf, + int pixels, + int Bpp) const = 0; - virtual void TranslateDownSamples(uint8_t* dest_buf, const uint8_t* src_buf, int pixels, int Bpp) const = 0; -protected: - virtual const uint8_t* GetScanline(int line) const; - virtual void DownSampleScanline(int line, uint8_t* dest_scan, int dest_bpp, - int dest_width, FX_BOOL bFlipX, int clip_left, int clip_width) const; + protected: + virtual const uint8_t* GetScanline(int line) const; + virtual void DownSampleScanline(int line, + uint8_t* dest_scan, + int dest_bpp, + int dest_width, + FX_BOOL bFlipX, + int clip_left, + int clip_width) const; - const CFX_DIBSource* m_pSrc; + const CFX_DIBSource* m_pSrc; - FX_BOOL m_bAutoDropSrc; + FX_BOOL m_bAutoDropSrc; - uint8_t* m_pScanline; + uint8_t* m_pScanline; }; -class IFX_ScanlineComposer -{ -public: - virtual ~IFX_ScanlineComposer() { } - - virtual void ComposeScanline(int line, const uint8_t* scanline, const uint8_t* scan_extra_alpha = NULL) = 0; - - virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette) = 0; +class IFX_ScanlineComposer { + public: + virtual ~IFX_ScanlineComposer() {} + + virtual void ComposeScanline(int line, + const uint8_t* scanline, + const uint8_t* scan_extra_alpha = NULL) = 0; + + virtual FX_BOOL SetInfo(int width, + int height, + FXDIB_Format src_format, + FX_DWORD* pSrcPalette) = 0; }; -class CFX_ScanlineCompositor -{ -public: - CFX_ScanlineCompositor(); - - ~CFX_ScanlineCompositor(); - - FX_BOOL Init(FXDIB_Format dest_format, FXDIB_Format src_format, int32_t width, FX_DWORD* pSrcPalette, - FX_DWORD mask_color, int blend_type, FX_BOOL bClip, FX_BOOL bRgbByteOrder = FALSE, int alpha_flag = 0, void* pIccTransform = NULL); - - - void CompositeRgbBitmapLine(uint8_t* dest_scan, const uint8_t* src_scan, int width, const uint8_t* clip_scan, - const uint8_t* src_extra_alpha = NULL, uint8_t* dst_extra_alpha = NULL); - - - void CompositePalBitmapLine(uint8_t* dest_scan, const uint8_t* src_scan, int src_left, int width, const uint8_t* clip_scan, - const uint8_t* src_extra_alpha = NULL, uint8_t* dst_extra_alpha = NULL); - - - void CompositeByteMaskLine(uint8_t* dest_scan, const uint8_t* src_scan, int width, const uint8_t* clip_scan, - uint8_t* dst_extra_alpha = NULL); - - - void CompositeBitMaskLine(uint8_t* dest_scan, const uint8_t* src_scan, int src_left, int width, const uint8_t* clip_scan, - uint8_t* dst_extra_alpha = NULL); -protected: - int m_Transparency; - FXDIB_Format m_SrcFormat, - m_DestFormat; - FX_DWORD* m_pSrcPalette; - - int m_MaskAlpha, - m_MaskRed, - m_MaskGreen, - m_MaskBlue, - m_MaskBlack; - int m_BlendType; - void* m_pIccTransform; - uint8_t* m_pCacheScanline; - int m_CacheSize; - FX_BOOL m_bRgbByteOrder; +class CFX_ScanlineCompositor { + public: + CFX_ScanlineCompositor(); + + ~CFX_ScanlineCompositor(); + + FX_BOOL Init(FXDIB_Format dest_format, + FXDIB_Format src_format, + int32_t width, + FX_DWORD* pSrcPalette, + FX_DWORD mask_color, + int blend_type, + FX_BOOL bClip, + FX_BOOL bRgbByteOrder = FALSE, + int alpha_flag = 0, + void* pIccTransform = NULL); + + void CompositeRgbBitmapLine(uint8_t* dest_scan, + const uint8_t* src_scan, + int width, + const uint8_t* clip_scan, + const uint8_t* src_extra_alpha = NULL, + uint8_t* dst_extra_alpha = NULL); + + void CompositePalBitmapLine(uint8_t* dest_scan, + const uint8_t* src_scan, + int src_left, + int width, + const uint8_t* clip_scan, + const uint8_t* src_extra_alpha = NULL, + uint8_t* dst_extra_alpha = NULL); + + void CompositeByteMaskLine(uint8_t* dest_scan, + const uint8_t* src_scan, + int width, + const uint8_t* clip_scan, + uint8_t* dst_extra_alpha = NULL); + + void CompositeBitMaskLine(uint8_t* dest_scan, + const uint8_t* src_scan, + int src_left, + int width, + const uint8_t* clip_scan, + uint8_t* dst_extra_alpha = NULL); + + protected: + int m_Transparency; + FXDIB_Format m_SrcFormat, m_DestFormat; + FX_DWORD* m_pSrcPalette; + + int m_MaskAlpha, m_MaskRed, m_MaskGreen, m_MaskBlue, m_MaskBlack; + int m_BlendType; + void* m_pIccTransform; + uint8_t* m_pCacheScanline; + int m_CacheSize; + FX_BOOL m_bRgbByteOrder; }; -class CFX_BitmapComposer : public IFX_ScanlineComposer -{ -public: - - CFX_BitmapComposer(); - - ~CFX_BitmapComposer(); - - - void Compose(CFX_DIBitmap* pDest, const CFX_ClipRgn* pClipRgn, int bitmap_alpha, - FX_DWORD mask_color, FX_RECT& dest_rect, FX_BOOL bVertical, - FX_BOOL bFlipX, FX_BOOL bFlipY, FX_BOOL bRgbByteOrder = FALSE, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette); - - - virtual void ComposeScanline(int line, const uint8_t* scanline, const uint8_t* scan_extra_alpha); -protected: - - void DoCompose(uint8_t* dest_scan, const uint8_t* src_scan, int dest_width, const uint8_t* clip_scan, - const uint8_t* src_extra_alpha = NULL, uint8_t* dst_extra_alpha = NULL); - CFX_DIBitmap* m_pBitmap; - const CFX_ClipRgn* m_pClipRgn; - FXDIB_Format m_SrcFormat; - int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha; - FX_DWORD m_MaskColor; - const CFX_DIBitmap* m_pClipMask; - CFX_ScanlineCompositor m_Compositor; - FX_BOOL m_bVertical, m_bFlipX, m_bFlipY; - int m_AlphaFlag; - void* m_pIccTransform; - FX_BOOL m_bRgbByteOrder; - int m_BlendType; - void ComposeScanlineV(int line, const uint8_t* scanline, const uint8_t* scan_extra_alpha = NULL); - uint8_t* m_pScanlineV; - uint8_t* m_pClipScanV; - uint8_t* m_pAddClipScan; - uint8_t* m_pScanlineAlphaV; +class CFX_BitmapComposer : public IFX_ScanlineComposer { + public: + CFX_BitmapComposer(); + + ~CFX_BitmapComposer(); + + void Compose(CFX_DIBitmap* pDest, + const CFX_ClipRgn* pClipRgn, + int bitmap_alpha, + FX_DWORD mask_color, + FX_RECT& dest_rect, + FX_BOOL bVertical, + FX_BOOL bFlipX, + FX_BOOL bFlipY, + FX_BOOL bRgbByteOrder = FALSE, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + + virtual FX_BOOL SetInfo(int width, + int height, + FXDIB_Format src_format, + FX_DWORD* pSrcPalette); + + virtual void ComposeScanline(int line, + const uint8_t* scanline, + const uint8_t* scan_extra_alpha); + + protected: + void DoCompose(uint8_t* dest_scan, + const uint8_t* src_scan, + int dest_width, + const uint8_t* clip_scan, + const uint8_t* src_extra_alpha = NULL, + uint8_t* dst_extra_alpha = NULL); + CFX_DIBitmap* m_pBitmap; + const CFX_ClipRgn* m_pClipRgn; + FXDIB_Format m_SrcFormat; + int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha; + FX_DWORD m_MaskColor; + const CFX_DIBitmap* m_pClipMask; + CFX_ScanlineCompositor m_Compositor; + FX_BOOL m_bVertical, m_bFlipX, m_bFlipY; + int m_AlphaFlag; + void* m_pIccTransform; + FX_BOOL m_bRgbByteOrder; + int m_BlendType; + void ComposeScanlineV(int line, + const uint8_t* scanline, + const uint8_t* scan_extra_alpha = NULL); + uint8_t* m_pScanlineV; + uint8_t* m_pClipScanV; + uint8_t* m_pAddClipScan; + uint8_t* m_pScanlineAlphaV; }; -class CFX_BitmapStorer : public IFX_ScanlineComposer -{ -public: +class CFX_BitmapStorer : public IFX_ScanlineComposer { + public: + CFX_BitmapStorer(); - CFX_BitmapStorer(); + ~CFX_BitmapStorer(); - ~CFX_BitmapStorer(); + virtual void ComposeScanline(int line, + const uint8_t* scanline, + const uint8_t* scan_extra_alpha); - virtual void ComposeScanline(int line, const uint8_t* scanline, const uint8_t* scan_extra_alpha); + virtual FX_BOOL SetInfo(int width, + int height, + FXDIB_Format src_format, + FX_DWORD* pSrcPalette); - virtual FX_BOOL SetInfo(int width, int height, FXDIB_Format src_format, FX_DWORD* pSrcPalette); + CFX_DIBitmap* GetBitmap() { return m_pBitmap; } - CFX_DIBitmap* GetBitmap() - { - return m_pBitmap; - } + CFX_DIBitmap* Detach(); - CFX_DIBitmap* Detach(); + void Replace(CFX_DIBitmap* pBitmap); - void Replace(CFX_DIBitmap* pBitmap); -private: - CFX_DIBitmap* m_pBitmap; + private: + CFX_DIBitmap* m_pBitmap; }; class CStretchEngine; -class CFX_ImageStretcher -{ -public: - CFX_ImageStretcher(); - ~CFX_ImageStretcher(); - - FX_BOOL Start(IFX_ScanlineComposer* pDest, const CFX_DIBSource* pBitmap, - int dest_width, int dest_height, const FX_RECT& bitmap_rect, - FX_DWORD flags); - - FX_BOOL Continue(IFX_Pause* pPause); - FX_BOOL StartQuickStretch(); - FX_BOOL StartStretch(); - FX_BOOL ContinueQuickStretch(IFX_Pause* pPause); - FX_BOOL ContinueStretch(IFX_Pause* pPause); - - IFX_ScanlineComposer* m_pDest; - const CFX_DIBSource* m_pSource; - CStretchEngine* m_pStretchEngine; - FX_DWORD m_Flags; - FX_BOOL m_bFlipX; - FX_BOOL m_bFlipY; - int m_DestWidth; - int m_DestHeight; - FX_RECT m_ClipRect; - int m_LineIndex; - int m_DestBPP; - uint8_t* m_pScanline; - uint8_t* m_pMaskScanline; - FXDIB_Format m_DestFormat; +class CFX_ImageStretcher { + public: + CFX_ImageStretcher(); + ~CFX_ImageStretcher(); + + FX_BOOL Start(IFX_ScanlineComposer* pDest, + const CFX_DIBSource* pBitmap, + int dest_width, + int dest_height, + const FX_RECT& bitmap_rect, + FX_DWORD flags); + + FX_BOOL Continue(IFX_Pause* pPause); + FX_BOOL StartQuickStretch(); + FX_BOOL StartStretch(); + FX_BOOL ContinueQuickStretch(IFX_Pause* pPause); + FX_BOOL ContinueStretch(IFX_Pause* pPause); + + IFX_ScanlineComposer* m_pDest; + const CFX_DIBSource* m_pSource; + CStretchEngine* m_pStretchEngine; + FX_DWORD m_Flags; + FX_BOOL m_bFlipX; + FX_BOOL m_bFlipY; + int m_DestWidth; + int m_DestHeight; + FX_RECT m_ClipRect; + int m_LineIndex; + int m_DestBPP; + uint8_t* m_pScanline; + uint8_t* m_pMaskScanline; + FXDIB_Format m_DestFormat; }; -class CFX_ImageTransformer -{ -public: - CFX_ImageTransformer(); - ~CFX_ImageTransformer(); - - FX_BOOL Start(const CFX_DIBSource* pSrc, const CFX_AffineMatrix* pMatrix, - int flags, const FX_RECT* pClip); - - FX_BOOL Continue(IFX_Pause* pPause); - - CFX_AffineMatrix* m_pMatrix; - FX_RECT m_StretchClip; - int m_ResultLeft; - int m_ResultTop; - int m_ResultWidth; - int m_ResultHeight; - CFX_AffineMatrix m_dest2stretch; - CFX_ImageStretcher m_Stretcher; - CFX_BitmapStorer m_Storer; - FX_DWORD m_Flags; - int m_Status; +class CFX_ImageTransformer { + public: + CFX_ImageTransformer(); + ~CFX_ImageTransformer(); + + FX_BOOL Start(const CFX_DIBSource* pSrc, + const CFX_AffineMatrix* pMatrix, + int flags, + const FX_RECT* pClip); + + FX_BOOL Continue(IFX_Pause* pPause); + + CFX_AffineMatrix* m_pMatrix; + FX_RECT m_StretchClip; + int m_ResultLeft; + int m_ResultTop; + int m_ResultWidth; + int m_ResultHeight; + CFX_AffineMatrix m_dest2stretch; + CFX_ImageStretcher m_Stretcher; + CFX_BitmapStorer m_Storer; + FX_DWORD m_Flags; + int m_Status; }; -class CFX_ImageRenderer -{ -public: - CFX_ImageRenderer(); - ~CFX_ImageRenderer(); - - FX_BOOL Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClipRgn, - const CFX_DIBSource* pSource, int bitmap_alpha, - FX_DWORD mask_color, const CFX_AffineMatrix* pMatrix, - FX_DWORD dib_flags, FX_BOOL bRgbByteOrder = FALSE, - int alpha_flag = 0, void* pIccTransform = NULL, - int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL Continue(IFX_Pause* pPause); - -protected: - CFX_DIBitmap* m_pDevice; - const CFX_ClipRgn* m_pClipRgn; - int m_BitmapAlpha; - FX_DWORD m_MaskColor; - CFX_AffineMatrix m_Matrix; - CFX_ImageTransformer* m_pTransformer; - CFX_ImageStretcher m_Stretcher; - CFX_BitmapComposer m_Composer; - int m_Status; - FX_RECT m_ClipBox; - FX_DWORD m_Flags; - int m_AlphaFlag; - void* m_pIccTransform; - FX_BOOL m_bRgbByteOrder; - int m_BlendType; +class CFX_ImageRenderer { + public: + CFX_ImageRenderer(); + ~CFX_ImageRenderer(); + + FX_BOOL Start(CFX_DIBitmap* pDevice, + const CFX_ClipRgn* pClipRgn, + const CFX_DIBSource* pSource, + int bitmap_alpha, + FX_DWORD mask_color, + const CFX_AffineMatrix* pMatrix, + FX_DWORD dib_flags, + FX_BOOL bRgbByteOrder = FALSE, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL Continue(IFX_Pause* pPause); + + protected: + CFX_DIBitmap* m_pDevice; + const CFX_ClipRgn* m_pClipRgn; + int m_BitmapAlpha; + FX_DWORD m_MaskColor; + CFX_AffineMatrix m_Matrix; + CFX_ImageTransformer* m_pTransformer; + CFX_ImageStretcher m_Stretcher; + CFX_BitmapComposer m_Composer; + int m_Status; + FX_RECT m_ClipBox; + FX_DWORD m_Flags; + int m_AlphaFlag; + void* m_pIccTransform; + FX_BOOL m_bRgbByteOrder; + int m_BlendType; }; #endif // CORE_INCLUDE_FXGE_FX_DIB_H_ diff --git a/core/include/fxge/fx_font.h b/core/include/fxge/fx_font.h index c1e135730b..cbc888515f 100644 --- a/core/include/fxge/fx_font.h +++ b/core/include/fxge/fx_font.h @@ -21,448 +21,491 @@ class CFX_FaceCache; class CFX_FontMapper; class IFX_SystemFontInfo; class CFontFileFaceInfo; -#define FXFONT_FIXED_PITCH 0x01 -#define FXFONT_SERIF 0x02 -#define FXFONT_SYMBOLIC 0x04 -#define FXFONT_SCRIPT 0x08 -#define FXFONT_ITALIC 0x40 -#define FXFONT_BOLD 0x40000 -#define FXFONT_USEEXTERNATTR 0x80000 -#define FXFONT_EXACTMATCH 0x80000000
-#define FXFONT_CIDFONT 0x100000 -#define FXFONT_ANSI_CHARSET 0 -#define FXFONT_DEFAULT_CHARSET 1 -#define FXFONT_SYMBOL_CHARSET 2 -#define FXFONT_SHIFTJIS_CHARSET 128 -#define FXFONT_HANGEUL_CHARSET 129 -#define FXFONT_GB2312_CHARSET 134 -#define FXFONT_CHINESEBIG5_CHARSET 136 -#define FXFONT_THAI_CHARSET 222 -#define FXFONT_EASTEUROPE_CHARSET 238 -#define FXFONT_RUSSIAN_CHARSET 204 -#define FXFONT_GREEK_CHARSET 161 -#define FXFONT_TURKISH_CHARSET 162 -#define FXFONT_HEBREW_CHARSET 177 -#define FXFONT_ARABIC_CHARSET 178 -#define FXFONT_BALTIC_CHARSET 186 -#define FXFONT_FF_FIXEDPITCH 1 -#define FXFONT_FF_ROMAN (1<<4) -#define FXFONT_FF_SCRIPT (4<<4) -#define FXFONT_FW_NORMAL 400 -#define FXFONT_FW_BOLD 700 -class CFX_Font -{ -public: - CFX_Font(); - ~CFX_Font(); +#define FXFONT_FIXED_PITCH 0x01 +#define FXFONT_SERIF 0x02 +#define FXFONT_SYMBOLIC 0x04 +#define FXFONT_SCRIPT 0x08 +#define FXFONT_ITALIC 0x40 +#define FXFONT_BOLD 0x40000 +#define FXFONT_USEEXTERNATTR 0x80000 +#define FXFONT_EXACTMATCH 0x80000000 +#define FXFONT_CIDFONT 0x100000 +#define FXFONT_ANSI_CHARSET 0 +#define FXFONT_DEFAULT_CHARSET 1 +#define FXFONT_SYMBOL_CHARSET 2 +#define FXFONT_SHIFTJIS_CHARSET 128 +#define FXFONT_HANGEUL_CHARSET 129 +#define FXFONT_GB2312_CHARSET 134 +#define FXFONT_CHINESEBIG5_CHARSET 136 +#define FXFONT_THAI_CHARSET 222 +#define FXFONT_EASTEUROPE_CHARSET 238 +#define FXFONT_RUSSIAN_CHARSET 204 +#define FXFONT_GREEK_CHARSET 161 +#define FXFONT_TURKISH_CHARSET 162 +#define FXFONT_HEBREW_CHARSET 177 +#define FXFONT_ARABIC_CHARSET 178 +#define FXFONT_BALTIC_CHARSET 186 +#define FXFONT_FF_FIXEDPITCH 1 +#define FXFONT_FF_ROMAN (1 << 4) +#define FXFONT_FF_SCRIPT (4 << 4) +#define FXFONT_FW_NORMAL 400 +#define FXFONT_FW_BOLD 700 +class CFX_Font { + public: + CFX_Font(); + ~CFX_Font(); - FX_BOOL LoadSubst(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, - int weight, int italic_angle, int CharsetCP, FX_BOOL bVertical = FALSE); + FX_BOOL LoadSubst(const CFX_ByteString& face_name, + FX_BOOL bTrueType, + FX_DWORD flags, + int weight, + int italic_angle, + int CharsetCP, + FX_BOOL bVertical = FALSE); - FX_BOOL LoadEmbedded(const uint8_t* data, FX_DWORD size); + FX_BOOL LoadEmbedded(const uint8_t* data, FX_DWORD size); - FX_BOOL LoadFile(IFX_FileRead* pFile, int nFaceIndex = 0, int* pFaceCount = NULL);
-
- FX_BOOL LoadClone(const CFX_Font* pFont);
-
+ FX_BOOL LoadFile(IFX_FileRead* pFile, + int nFaceIndex = 0, + int* pFaceCount = NULL); - FXFT_Face GetFace() const - { - return m_Face; - } + FX_BOOL LoadClone(const CFX_Font* pFont); + FXFT_Face GetFace() const { return m_Face; } - const CFX_SubstFont* GetSubstFont() const - { - return m_pSubstFont; - } + const CFX_SubstFont* GetSubstFont() const { return m_pSubstFont; } - CFX_PathData* LoadGlyphPath(FX_DWORD glyph_index, int dest_width = 0); + CFX_PathData* LoadGlyphPath(FX_DWORD glyph_index, int dest_width = 0); - int GetGlyphWidth(FX_DWORD glyph_index); + int GetGlyphWidth(FX_DWORD glyph_index); - int GetAscent() const; + int GetAscent() const; - int GetDescent() const; + int GetDescent() const; - FX_BOOL GetGlyphBBox(FX_DWORD glyph_index, FX_RECT &bbox); + FX_BOOL GetGlyphBBox(FX_DWORD glyph_index, FX_RECT& bbox); - FX_BOOL IsItalic(); + FX_BOOL IsItalic(); - FX_BOOL IsBold(); + FX_BOOL IsBold(); - FX_BOOL IsFixedWidth(); + FX_BOOL IsFixedWidth(); - FX_BOOL IsVertical() const - { - return m_bVertical; - } + FX_BOOL IsVertical() const { return m_bVertical; } - CFX_WideString GetPsName() const; + CFX_WideString GetPsName() const; + CFX_ByteString GetFamilyName() const; - CFX_ByteString GetFamilyName() const; + CFX_ByteString GetFaceName() const; - CFX_ByteString GetFaceName() const; + FX_BOOL IsTTFont(); + FX_BOOL GetBBox(FX_RECT& bbox); - FX_BOOL IsTTFont(); + int GetHeight(); - FX_BOOL GetBBox(FX_RECT &bbox); + int GetULPos(); - int GetHeight(); + int GetULthickness(); - int GetULPos(); + int GetMaxAdvanceWidth(); - int GetULthickness(); + FXFT_Face m_Face; - int GetMaxAdvanceWidth(); + CFX_SubstFont* m_pSubstFont; + FX_BOOL IsEmbedded() { return m_bEmbedded; } - FXFT_Face m_Face; + void AdjustMMParams(int glyph_index, int width, int weight); + uint8_t* m_pFontDataAllocation; + uint8_t* m_pFontData; + uint8_t* m_pGsubData; + FX_DWORD m_dwSize; + CFX_BinaryBuf m_OtfFontData; + void* m_hHandle; + void* m_pPlatformFont; + void* m_pPlatformFontCollection; + void* m_pDwFont; + FX_BOOL m_bDwLoaded; + void ReleasePlatformResource(); - CFX_SubstFont* m_pSubstFont; - FX_BOOL IsEmbedded() - { - return m_bEmbedded; - } + void DeleteFace(); - void AdjustMMParams(int glyph_index, int width, int weight); - uint8_t* m_pFontDataAllocation; - uint8_t* m_pFontData; - uint8_t* m_pGsubData; - FX_DWORD m_dwSize; - CFX_BinaryBuf m_OtfFontData; - void* m_hHandle; - void* m_pPlatformFont; - void* m_pPlatformFontCollection; - void* m_pDwFont; - FX_BOOL m_bDwLoaded; - void ReleasePlatformResource(); - - void DeleteFace(); -protected: - - FX_BOOL m_bEmbedded; - FX_BOOL m_bVertical; - FX_BOOL m_bLogic;
- void* m_pOwnedStream; + protected: + FX_BOOL m_bEmbedded; + FX_BOOL m_bVertical; + FX_BOOL m_bLogic; + void* m_pOwnedStream; }; -#define ENCODING_INTERNAL 0 -#define ENCODING_UNICODE 1 -class IFX_FontEncoding -{ -public: - virtual ~IFX_FontEncoding() {} +#define ENCODING_INTERNAL 0 +#define ENCODING_UNICODE 1 +class IFX_FontEncoding { + public: + virtual ~IFX_FontEncoding() {} - virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode) = 0; + virtual FX_DWORD GlyphFromCharCode(FX_DWORD charcode) = 0; - virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const = 0; + virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const = 0; - virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const = 0; + virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const = 0; }; IFX_FontEncoding* FXGE_CreateUnicodeEncoding(CFX_Font* pFont); -#define FXFM_ENC_TAG(a, b, c, d) (((FX_DWORD)(a) << 24) | ((FX_DWORD)(b) << 16) | ((FX_DWORD)(c) << 8) | (FX_DWORD)(d))
-#define FXFM_ENCODING_NONE FXFM_ENC_TAG(0, 0, 0, 0)
-#define FXFM_ENCODING_MS_SYMBOL FXFM_ENC_TAG('s', 'y', 'm', 'b')
-#define FXFM_ENCODING_UNICODE FXFM_ENC_TAG('u', 'n', 'i', 'c')
-#define FXFM_ENCODING_MS_SJIS FXFM_ENC_TAG('s', 'j', 'i', 's')
-#define FXFM_ENCODING_MS_GB2312 FXFM_ENC_TAG('g', 'b', ' ', ' ')
-#define FXFM_ENCODING_MS_BIG5 FXFM_ENC_TAG('b', 'i', 'g', '5')
-#define FXFM_ENCODING_MS_WANSUNG FXFM_ENC_TAG('w', 'a', 'n', 's')
-#define FXFM_ENCODING_MS_JOHAB FXFM_ENC_TAG('j', 'o', 'h', 'a')
-#define FXFM_ENCODING_ADOBE_STANDARD FXFM_ENC_TAG('A', 'D', 'O', 'B')
-#define FXFM_ENCODING_ADOBE_EXPERT FXFM_ENC_TAG('A', 'D', 'B', 'E')
-#define FXFM_ENCODING_ADOBE_CUSTOM FXFM_ENC_TAG('A', 'D', 'B', 'C')
-#define FXFM_ENCODING_ADOBE_LATIN_1 FXFM_ENC_TAG('l', 'a', 't', '1')
-#define FXFM_ENCODING_OLD_LATIN_2 FXFM_ENC_TAG('l', 'a', 't', '2')
-#define FXFM_ENCODING_APPLE_ROMAN FXFM_ENC_TAG('a', 'r', 'm', 'n')
-class IFX_FontEncodingEx : public IFX_FontEncoding
-{
-public:
-
- virtual FX_DWORD GlyphIndexFromName(const FX_CHAR* pStrName) = 0;
-
- virtual CFX_ByteString NameFromGlyphIndex(FX_DWORD dwGlyphIndex) = 0;
-
- virtual FX_DWORD CharCodeFromGlyphIndex(FX_DWORD dwGlyphIndex) = 0;
-};
-IFX_FontEncodingEx* FX_CreateFontEncodingEx(CFX_Font* pFont, FX_DWORD nEncodingID = FXFM_ENCODING_NONE);
-#define FXFONT_SUBST_MM 0x01 -#define FXFONT_SUBST_GLYPHPATH 0x04 -#define FXFONT_SUBST_CLEARTYPE 0x08 -#define FXFONT_SUBST_TRANSFORM 0x10 -#define FXFONT_SUBST_NONSYMBOL 0x20 -#define FXFONT_SUBST_EXACT 0x40 -#define FXFONT_SUBST_STANDARD 0x80 -class CFX_SubstFont -{ -public: - - CFX_SubstFont(); - - void* m_ExtHandle; - - CFX_ByteString m_Family; - - int m_Charset; - - FX_DWORD m_SubstFlags; - - int m_Weight; - - int m_ItalicAngle; - - FX_BOOL m_bSubstOfCJK; - - int m_WeightCJK; - - FX_BOOL m_bItlicCJK; +#define FXFM_ENC_TAG(a, b, c, d) \ + (((FX_DWORD)(a) << 24) | ((FX_DWORD)(b) << 16) | ((FX_DWORD)(c) << 8) | \ + (FX_DWORD)(d)) +#define FXFM_ENCODING_NONE FXFM_ENC_TAG(0, 0, 0, 0) +#define FXFM_ENCODING_MS_SYMBOL FXFM_ENC_TAG('s', 'y', 'm', 'b') +#define FXFM_ENCODING_UNICODE FXFM_ENC_TAG('u', 'n', 'i', 'c') +#define FXFM_ENCODING_MS_SJIS FXFM_ENC_TAG('s', 'j', 'i', 's') +#define FXFM_ENCODING_MS_GB2312 FXFM_ENC_TAG('g', 'b', ' ', ' ') +#define FXFM_ENCODING_MS_BIG5 FXFM_ENC_TAG('b', 'i', 'g', '5') +#define FXFM_ENCODING_MS_WANSUNG FXFM_ENC_TAG('w', 'a', 'n', 's') +#define FXFM_ENCODING_MS_JOHAB FXFM_ENC_TAG('j', 'o', 'h', 'a') +#define FXFM_ENCODING_ADOBE_STANDARD FXFM_ENC_TAG('A', 'D', 'O', 'B') +#define FXFM_ENCODING_ADOBE_EXPERT FXFM_ENC_TAG('A', 'D', 'B', 'E') +#define FXFM_ENCODING_ADOBE_CUSTOM FXFM_ENC_TAG('A', 'D', 'B', 'C') +#define FXFM_ENCODING_ADOBE_LATIN_1 FXFM_ENC_TAG('l', 'a', 't', '1') +#define FXFM_ENCODING_OLD_LATIN_2 FXFM_ENC_TAG('l', 'a', 't', '2') +#define FXFM_ENCODING_APPLE_ROMAN FXFM_ENC_TAG('a', 'r', 'm', 'n') +class IFX_FontEncodingEx : public IFX_FontEncoding { + public: + virtual FX_DWORD GlyphIndexFromName(const FX_CHAR* pStrName) = 0; + + virtual CFX_ByteString NameFromGlyphIndex(FX_DWORD dwGlyphIndex) = 0; + + virtual FX_DWORD CharCodeFromGlyphIndex(FX_DWORD dwGlyphIndex) = 0; +}; +IFX_FontEncodingEx* FX_CreateFontEncodingEx( + CFX_Font* pFont, + FX_DWORD nEncodingID = FXFM_ENCODING_NONE); +#define FXFONT_SUBST_MM 0x01 +#define FXFONT_SUBST_GLYPHPATH 0x04 +#define FXFONT_SUBST_CLEARTYPE 0x08 +#define FXFONT_SUBST_TRANSFORM 0x10 +#define FXFONT_SUBST_NONSYMBOL 0x20 +#define FXFONT_SUBST_EXACT 0x40 +#define FXFONT_SUBST_STANDARD 0x80 +class CFX_SubstFont { + public: + CFX_SubstFont(); + + void* m_ExtHandle; + + CFX_ByteString m_Family; + + int m_Charset; + + FX_DWORD m_SubstFlags; + + int m_Weight; + + int m_ItalicAngle; + + FX_BOOL m_bSubstOfCJK; + + int m_WeightCJK; + + FX_BOOL m_bItlicCJK; }; -#define FX_FONT_FLAG_SERIF 0x01 -#define FX_FONT_FLAG_FIXEDPITCH 0x02 -#define FX_FONT_FLAG_ITALIC 0x04 -#define FX_FONT_FLAG_BOLD 0x08 -#define FX_FONT_FLAG_SYMBOLIC_SYMBOL 0x10 -#define FX_FONT_FLAG_SYMBOLIC_DINGBATS 0x20 -#define FX_FONT_FLAG_MULTIPLEMASTER 0x40 +#define FX_FONT_FLAG_SERIF 0x01 +#define FX_FONT_FLAG_FIXEDPITCH 0x02 +#define FX_FONT_FLAG_ITALIC 0x04 +#define FX_FONT_FLAG_BOLD 0x08 +#define FX_FONT_FLAG_SYMBOLIC_SYMBOL 0x10 +#define FX_FONT_FLAG_SYMBOLIC_DINGBATS 0x20 +#define FX_FONT_FLAG_MULTIPLEMASTER 0x40 typedef struct { - const uint8_t* m_pFontData; - FX_DWORD m_dwSize; + const uint8_t* m_pFontData; + FX_DWORD m_dwSize; } FoxitFonts; -class CFX_FontMgr -{ -public: - CFX_FontMgr(); - ~CFX_FontMgr(); - void InitFTLibrary(); - FXFT_Face GetCachedFace(const CFX_ByteString& face_name, - int weight, FX_BOOL bItalic, uint8_t*& pFontData); - FXFT_Face AddCachedFace(const CFX_ByteString& face_name, - int weight, FX_BOOL bItalic, uint8_t* pData, FX_DWORD size, int face_index); - FXFT_Face GetCachedTTCFace(int ttc_size, FX_DWORD checksum, - int font_offset, uint8_t*& pFontData); - FXFT_Face AddCachedTTCFace(int ttc_size, FX_DWORD checksum, - uint8_t* pData, FX_DWORD size, int font_offset); - FXFT_Face GetFileFace(const FX_CHAR* filename, int face_index); - FXFT_Face GetFixedFace(const uint8_t* pData, FX_DWORD size, int face_index); - void ReleaseFace(FXFT_Face face); - void SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo); - FXFT_Face FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, - int weight, int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont); - - void FreeCache(); - - FX_BOOL GetStandardFont(const uint8_t*& pFontData, FX_DWORD& size, int index); - CFX_FontMapper* m_pBuiltinMapper; - CFX_MapByteStringToPtr m_FaceMap; - FXFT_Library m_FTLibrary; - FoxitFonts m_ExternalFonts[16]; +class CFX_FontMgr { + public: + CFX_FontMgr(); + ~CFX_FontMgr(); + void InitFTLibrary(); + FXFT_Face GetCachedFace(const CFX_ByteString& face_name, + int weight, + FX_BOOL bItalic, + uint8_t*& pFontData); + FXFT_Face AddCachedFace(const CFX_ByteString& face_name, + int weight, + FX_BOOL bItalic, + uint8_t* pData, + FX_DWORD size, + int face_index); + FXFT_Face GetCachedTTCFace(int ttc_size, + FX_DWORD checksum, + int font_offset, + uint8_t*& pFontData); + FXFT_Face AddCachedTTCFace(int ttc_size, + FX_DWORD checksum, + uint8_t* pData, + FX_DWORD size, + int font_offset); + FXFT_Face GetFileFace(const FX_CHAR* filename, int face_index); + FXFT_Face GetFixedFace(const uint8_t* pData, FX_DWORD size, int face_index); + void ReleaseFace(FXFT_Face face); + void SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo); + FXFT_Face FindSubstFont(const CFX_ByteString& face_name, + FX_BOOL bTrueType, + FX_DWORD flags, + int weight, + int italic_angle, + int CharsetCP, + CFX_SubstFont* pSubstFont); + + void FreeCache(); + + FX_BOOL GetStandardFont(const uint8_t*& pFontData, FX_DWORD& size, int index); + CFX_FontMapper* m_pBuiltinMapper; + CFX_MapByteStringToPtr m_FaceMap; + FXFT_Library m_FTLibrary; + FoxitFonts m_ExternalFonts[16]; }; -class IFX_FontEnumerator -{ -public: - virtual ~IFX_FontEnumerator() { } +class IFX_FontEnumerator { + public: + virtual ~IFX_FontEnumerator() {} - virtual void HitFont() = 0; + virtual void HitFont() = 0; - virtual void Finish() = 0; + virtual void Finish() = 0; }; -class IFX_AdditionalFontEnum -{ -public: - virtual ~IFX_AdditionalFontEnum() { } - virtual int CountFiles() = 0; - virtual IFX_FileStream* GetFontFile(int index) = 0; +class IFX_AdditionalFontEnum { + public: + virtual ~IFX_AdditionalFontEnum() {} + virtual int CountFiles() = 0; + virtual IFX_FileStream* GetFontFile(int index) = 0; }; -class CFX_FontMapper -{ -public: - - CFX_FontMapper(CFX_FontMgr* mgr); - ~CFX_FontMapper(); - - void SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo); - IFX_SystemFontInfo* GetSystemFontInfo() - { - return m_pFontInfo; - } - void AddInstalledFont(const CFX_ByteString& name, int charset); - void LoadInstalledFonts(); - CFX_ByteStringArray m_InstalledTTFonts; - void SetFontEnumerator(IFX_FontEnumerator* pFontEnumerator) - { - m_pFontEnumerator = pFontEnumerator; - } - IFX_FontEnumerator* GetFontEnumerator() const - { - return m_pFontEnumerator; - } - - FXFT_Face FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bTrueType, FX_DWORD flags, - int weight, int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont); - FXFT_Face FindSubstFontByUnicode(FX_DWORD dwUnicode, FX_DWORD flags, int weight, int italic_angle);
- FX_BOOL IsBuiltinFace(const FXFT_Face face) const; - -private: - static const size_t MM_FACE_COUNT = 2; - static const size_t FOXIT_FACE_COUNT = 14; - - CFX_ByteString GetPSNameFromTT(void* hFont); - CFX_ByteString MatchInstalledFonts(const CFX_ByteString& norm_name); - FXFT_Face UseInternalSubst(CFX_SubstFont* pSubstFont, int iBaseFont, int italic_angle, int weight, int picthfamily); - - FX_BOOL m_bListLoaded; - FXFT_Face m_MMFaces[MM_FACE_COUNT]; - CFX_ByteString m_LastFamily; - CFX_DWordArray m_CharsetArray; - CFX_ByteStringArray m_FaceArray; - IFX_SystemFontInfo* m_pFontInfo; - FXFT_Face m_FoxitFaces[FOXIT_FACE_COUNT]; - IFX_FontEnumerator* m_pFontEnumerator; - CFX_FontMgr* const m_pFontMgr; +class CFX_FontMapper { + public: + CFX_FontMapper(CFX_FontMgr* mgr); + ~CFX_FontMapper(); + + void SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo); + IFX_SystemFontInfo* GetSystemFontInfo() { return m_pFontInfo; } + void AddInstalledFont(const CFX_ByteString& name, int charset); + void LoadInstalledFonts(); + CFX_ByteStringArray m_InstalledTTFonts; + void SetFontEnumerator(IFX_FontEnumerator* pFontEnumerator) { + m_pFontEnumerator = pFontEnumerator; + } + IFX_FontEnumerator* GetFontEnumerator() const { return m_pFontEnumerator; } + + FXFT_Face FindSubstFont(const CFX_ByteString& face_name, + FX_BOOL bTrueType, + FX_DWORD flags, + int weight, + int italic_angle, + int CharsetCP, + CFX_SubstFont* pSubstFont); + FXFT_Face FindSubstFontByUnicode(FX_DWORD dwUnicode, + FX_DWORD flags, + int weight, + int italic_angle); + FX_BOOL IsBuiltinFace(const FXFT_Face face) const; + + private: + static const size_t MM_FACE_COUNT = 2; + static const size_t FOXIT_FACE_COUNT = 14; + + CFX_ByteString GetPSNameFromTT(void* hFont); + CFX_ByteString MatchInstalledFonts(const CFX_ByteString& norm_name); + FXFT_Face UseInternalSubst(CFX_SubstFont* pSubstFont, + int iBaseFont, + int italic_angle, + int weight, + int picthfamily); + + FX_BOOL m_bListLoaded; + FXFT_Face m_MMFaces[MM_FACE_COUNT]; + CFX_ByteString m_LastFamily; + CFX_DWordArray m_CharsetArray; + CFX_ByteStringArray m_FaceArray; + IFX_SystemFontInfo* m_pFontInfo; + FXFT_Face m_FoxitFaces[FOXIT_FACE_COUNT]; + IFX_FontEnumerator* m_pFontEnumerator; + CFX_FontMgr* const m_pFontMgr; }; -class IFX_SystemFontInfo -{ -public: - static IFX_SystemFontInfo* CreateDefault(); - virtual void Release() = 0; - - virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) = 0; - virtual void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, const FX_CHAR* face, int& iExact) = 0; - virtual void* MapFontByUnicode(FX_DWORD dwUnicode, int weight, FX_BOOL bItalic, int pitch_family) - { - return NULL; - } - virtual void* GetFont(const FX_CHAR* face) = 0; - virtual FX_DWORD GetFontData(void* hFont, FX_DWORD table, uint8_t* buffer, FX_DWORD size) = 0; - virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) = 0; - virtual FX_BOOL GetFontCharset(void* hFont, int& charset) = 0; - virtual int GetFaceIndex(void* hFont) - { - return 0; - } - virtual void DeleteFont(void* hFont) = 0; - virtual void* RetainFont(void* hFont) - { - return NULL; - } -protected: - ~IFX_SystemFontInfo() { } +class IFX_SystemFontInfo { + public: + static IFX_SystemFontInfo* CreateDefault(); + virtual void Release() = 0; + + virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper) = 0; + virtual void* MapFont(int weight, + FX_BOOL bItalic, + int charset, + int pitch_family, + const FX_CHAR* face, + int& iExact) = 0; + virtual void* MapFontByUnicode(FX_DWORD dwUnicode, + int weight, + FX_BOOL bItalic, + int pitch_family) { + return NULL; + } + virtual void* GetFont(const FX_CHAR* face) = 0; + virtual FX_DWORD GetFontData(void* hFont, + FX_DWORD table, + uint8_t* buffer, + FX_DWORD size) = 0; + virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) = 0; + virtual FX_BOOL GetFontCharset(void* hFont, int& charset) = 0; + virtual int GetFaceIndex(void* hFont) { return 0; } + virtual void DeleteFont(void* hFont) = 0; + virtual void* RetainFont(void* hFont) { return NULL; } + + protected: + ~IFX_SystemFontInfo() {} }; -class CFX_FolderFontInfo : public IFX_SystemFontInfo -{ -public: - CFX_FolderFontInfo(); - virtual ~CFX_FolderFontInfo(); - - void AddPath(const CFX_ByteStringC& path); - - // IFX_SytemFontInfo: - void Release() override; - FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override; - void* MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, - const FX_CHAR* face, int& bExact) override; - void* MapFontByUnicode(FX_DWORD dwUnicode, int weight, FX_BOOL bItalic, - int pitch_family) override; - void* GetFont(const FX_CHAR* face) override; - FX_DWORD GetFontData(void* hFont, FX_DWORD table, - uint8_t* buffer, FX_DWORD size) override; - void DeleteFont(void* hFont) override; - FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) override; - FX_BOOL GetFontCharset(void* hFont, int& charset) override; - -protected: - CFX_MapByteStringToPtr m_FontList; - CFX_ByteStringArray m_PathList; - CFX_FontMapper* m_pMapper; - void ScanPath(CFX_ByteString& path); - void ScanFile(CFX_ByteString& path); - void ReportFace(CFX_ByteString& path, FXSYS_FILE* pFile, FX_DWORD filesize, FX_DWORD offset); +class CFX_FolderFontInfo : public IFX_SystemFontInfo { + public: + CFX_FolderFontInfo(); + virtual ~CFX_FolderFontInfo(); + + void AddPath(const CFX_ByteStringC& path); + + // IFX_SytemFontInfo: + void Release() override; + FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override; + void* MapFont(int weight, + FX_BOOL bItalic, + int charset, + int pitch_family, + const FX_CHAR* face, + int& bExact) override; + void* MapFontByUnicode(FX_DWORD dwUnicode, + int weight, + FX_BOOL bItalic, + int pitch_family) override; + void* GetFont(const FX_CHAR* face) override; + FX_DWORD GetFontData(void* hFont, + FX_DWORD table, + uint8_t* buffer, + FX_DWORD size) override; + void DeleteFont(void* hFont) override; + FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) override; + FX_BOOL GetFontCharset(void* hFont, int& charset) override; + + protected: + CFX_MapByteStringToPtr m_FontList; + CFX_ByteStringArray m_PathList; + CFX_FontMapper* m_pMapper; + void ScanPath(CFX_ByteString& path); + void ScanFile(CFX_ByteString& path); + void ReportFace(CFX_ByteString& path, + FXSYS_FILE* pFile, + FX_DWORD filesize, + FX_DWORD offset); }; -class CFX_CountedFaceCache -{ -public: - CFX_FaceCache* m_Obj; - FX_DWORD m_nCount; +class CFX_CountedFaceCache { + public: + CFX_FaceCache* m_Obj; + FX_DWORD m_nCount; }; -class CFX_FontCache -{ -public: - ~CFX_FontCache(); - CFX_FaceCache* GetCachedFace(CFX_Font* pFont); - void ReleaseCachedFace(CFX_Font* pFont); - void FreeCache(FX_BOOL bRelease = FALSE); - -private: - using CFX_FTCacheMap = std::map<FXFT_Face, CFX_CountedFaceCache*>; - CFX_FTCacheMap m_FTFaceMap; - CFX_FTCacheMap m_ExtFaceMap; +class CFX_FontCache { + public: + ~CFX_FontCache(); + CFX_FaceCache* GetCachedFace(CFX_Font* pFont); + void ReleaseCachedFace(CFX_Font* pFont); + void FreeCache(FX_BOOL bRelease = FALSE); + + private: + using CFX_FTCacheMap = std::map<FXFT_Face, CFX_CountedFaceCache*>; + CFX_FTCacheMap m_FTFaceMap; + CFX_FTCacheMap m_ExtFaceMap; }; -class CFX_AutoFontCache -{ -public: - CFX_AutoFontCache(CFX_FontCache* pFontCache, CFX_Font* pFont) - : m_pFontCache(pFontCache) - , m_pFont(pFont) - { - } - ~CFX_AutoFontCache() - { - m_pFontCache->ReleaseCachedFace(m_pFont); - } - CFX_FontCache* m_pFontCache; - CFX_Font* m_pFont; +class CFX_AutoFontCache { + public: + CFX_AutoFontCache(CFX_FontCache* pFontCache, CFX_Font* pFont) + : m_pFontCache(pFontCache), m_pFont(pFont) {} + ~CFX_AutoFontCache() { m_pFontCache->ReleaseCachedFace(m_pFont); } + CFX_FontCache* m_pFontCache; + CFX_Font* m_pFont; }; -#define FX_FONTCACHE_DEFINE(pFontCache, pFont) CFX_AutoFontCache autoFontCache((pFontCache), (pFont)) -class CFX_GlyphBitmap -{ -public: - int m_Top; - int m_Left; - CFX_DIBitmap m_Bitmap; +#define FX_FONTCACHE_DEFINE(pFontCache, pFont) \ + CFX_AutoFontCache autoFontCache((pFontCache), (pFont)) +class CFX_GlyphBitmap { + public: + int m_Top; + int m_Left; + CFX_DIBitmap m_Bitmap; }; -class CFX_FaceCache -{ -public: - ~CFX_FaceCache(); - const CFX_GlyphBitmap* LoadGlyphBitmap(CFX_Font* pFont, FX_DWORD glyph_index, FX_BOOL bFontStyle, const CFX_AffineMatrix* pMatrix, - int dest_width, int anti_alias, int& text_flags); - const CFX_PathData* LoadGlyphPath(CFX_Font* pFont, FX_DWORD glyph_index, int dest_width); - - - CFX_FaceCache(FXFT_Face face); -private: - FXFT_Face m_Face; - CFX_GlyphBitmap* RenderGlyph(CFX_Font* pFont, FX_DWORD glyph_index, FX_BOOL bFontStyle, - const CFX_AffineMatrix* pMatrix, int dest_width, int anti_alias); - CFX_GlyphBitmap* RenderGlyph_Nativetext(CFX_Font* pFont, FX_DWORD glyph_index, - const CFX_AffineMatrix* pMatrix, int dest_width, int anti_alias); - CFX_GlyphBitmap* LookUpGlyphBitmap(CFX_Font* pFont, const CFX_AffineMatrix* pMatrix, CFX_ByteStringC& FaceGlyphsKey, - FX_DWORD glyph_index, FX_BOOL bFontStyle, int dest_width, int anti_alias); - CFX_MapByteStringToPtr m_SizeMap; - CFX_MapPtrToPtr m_PathMap; - CFX_DIBitmap* m_pBitmap; - - void InitPlatform(); - void DestroyPlatform(); +class CFX_FaceCache { + public: + ~CFX_FaceCache(); + const CFX_GlyphBitmap* LoadGlyphBitmap(CFX_Font* pFont, + FX_DWORD glyph_index, + FX_BOOL bFontStyle, + const CFX_AffineMatrix* pMatrix, + int dest_width, + int anti_alias, + int& text_flags); + const CFX_PathData* LoadGlyphPath(CFX_Font* pFont, + FX_DWORD glyph_index, + int dest_width); + + CFX_FaceCache(FXFT_Face face); + + private: + FXFT_Face m_Face; + CFX_GlyphBitmap* RenderGlyph(CFX_Font* pFont, + FX_DWORD glyph_index, + FX_BOOL bFontStyle, + const CFX_AffineMatrix* pMatrix, + int dest_width, + int anti_alias); + CFX_GlyphBitmap* RenderGlyph_Nativetext(CFX_Font* pFont, + FX_DWORD glyph_index, + const CFX_AffineMatrix* pMatrix, + int dest_width, + int anti_alias); + CFX_GlyphBitmap* LookUpGlyphBitmap(CFX_Font* pFont, + const CFX_AffineMatrix* pMatrix, + CFX_ByteStringC& FaceGlyphsKey, + FX_DWORD glyph_index, + FX_BOOL bFontStyle, + int dest_width, + int anti_alias); + CFX_MapByteStringToPtr m_SizeMap; + CFX_MapPtrToPtr m_PathMap; + CFX_DIBitmap* m_pBitmap; + + void InitPlatform(); + void DestroyPlatform(); }; typedef struct { - const CFX_GlyphBitmap* m_pGlyph; - int m_OriginX, m_OriginY; - FX_FLOAT m_fOriginX, m_fOriginY; + const CFX_GlyphBitmap* m_pGlyph; + int m_OriginX, m_OriginY; + FX_FLOAT m_fOriginX, m_fOriginY; } FXTEXT_GLYPHPOS; -FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, int nChars, int anti_alias, FX_FLOAT retinaScaleX = 1.0f, FX_FLOAT retinaScaleY = 1.0f); -FX_BOOL OutputGlyph(void* dib, int x, int y, CFX_Font* pFont, double font_size, - CFX_AffineMatrix* pMatrix, unsigned long glyph_index, unsigned long argb); -FX_BOOL OutputText(void* dib, int x, int y, CFX_Font* pFont, double font_size, - CFX_AffineMatrix* pText_matrix, unsigned short const* text, unsigned long argb); -class IFX_GSUBTable -{ -public: - static IFX_GSUBTable* Create(CFX_Font* pFont); - virtual ~IFX_GSUBTable() { } - virtual FX_BOOL GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum) = 0; +FX_RECT FXGE_GetGlyphsBBox(FXTEXT_GLYPHPOS* pGlyphAndPos, + int nChars, + int anti_alias, + FX_FLOAT retinaScaleX = 1.0f, + FX_FLOAT retinaScaleY = 1.0f); +FX_BOOL OutputGlyph(void* dib, + int x, + int y, + CFX_Font* pFont, + double font_size, + CFX_AffineMatrix* pMatrix, + unsigned long glyph_index, + unsigned long argb); +FX_BOOL OutputText(void* dib, + int x, + int y, + CFX_Font* pFont, + double font_size, + CFX_AffineMatrix* pText_matrix, + unsigned short const* text, + unsigned long argb); +class IFX_GSUBTable { + public: + static IFX_GSUBTable* Create(CFX_Font* pFont); + virtual ~IFX_GSUBTable() {} + virtual FX_BOOL GetVerticalGlyph(FX_DWORD glyphnum, FX_DWORD* vglyphnum) = 0; }; #endif // CORE_INCLUDE_FXGE_FX_FONT_H_ diff --git a/core/include/fxge/fx_freetype.h b/core/include/fxge/fx_freetype.h index 77f30d51a4..c7c8295961 100644 --- a/core/include/fxge/fx_freetype.h +++ b/core/include/fxge/fx_freetype.h @@ -30,7 +30,8 @@ extern "C" { #define FXFT_ENCODING_JOHAB FT_ENCODING_JOHAB #define FXFT_ENCODING_WANSUNG FT_ENCODING_WANSUNG #define FXFT_LOAD_NO_SCALE FT_LOAD_NO_SCALE -#define FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH +#define FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH \ + FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH #define FXFT_RENDER_MODE_LCD FT_RENDER_MODE_LCD #define FXFT_RENDER_MODE_MONO FT_RENDER_MODE_MONO #define FXFT_RENDER_MODE_NORMAL FT_RENDER_MODE_NORMAL @@ -41,57 +42,73 @@ extern "C" { #define FXFT_STYLE_FLAG_ITALIC FT_STYLE_FLAG_ITALIC #define FXFT_STYLE_FLAG_BOLD FT_STYLE_FLAG_BOLD #define FXFT_FACE_FLAG_SFNT FT_FACE_FLAG_SFNT -#define FXFT_FACE_FLAG_TRICKY ( 1L << 13 ) -typedef FT_MM_Var* FXFT_MM_Var; -typedef FT_Bitmap* FXFT_Bitmap; -#define FXFT_Matrix FT_Matrix -#define FXFT_Vector FT_Vector +#define FXFT_FACE_FLAG_TRICKY (1L << 13) +typedef FT_MM_Var* FXFT_MM_Var; +typedef FT_Bitmap* FXFT_Bitmap; +#define FXFT_Matrix FT_Matrix +#define FXFT_Vector FT_Vector #define FXFT_Outline_Funcs FT_Outline_Funcs -typedef FT_Open_Args FXFT_Open_Args; -typedef FT_StreamRec FXFT_StreamRec; -typedef FT_StreamRec* FXFT_Stream; -typedef FT_BBox FXFT_BBox; -typedef FT_Glyph FXFT_Glyph; -typedef FT_CharMap FXFT_CharMap; -#define FXFT_GLYPH_BBOX_PIXELS FT_GLYPH_BBOX_PIXELS +typedef FT_Open_Args FXFT_Open_Args; +typedef FT_StreamRec FXFT_StreamRec; +typedef FT_StreamRec* FXFT_Stream; +typedef FT_BBox FXFT_BBox; +typedef FT_Glyph FXFT_Glyph; +typedef FT_CharMap FXFT_CharMap; +#define FXFT_GLYPH_BBOX_PIXELS FT_GLYPH_BBOX_PIXELS #define FXFT_Open_Face(library, args, index, face) \ - FT_Open_Face((FT_Library)(library), args, index, (FT_Face*)(face)) + FT_Open_Face((FT_Library)(library), args, index, (FT_Face*)(face)) #define FXFT_Done_Face(face) FT_Done_Face((FT_Face)(face)) #define FXFT_Done_FreeType(library) FT_Done_FreeType((FT_Library)(library)) #define FXFT_Init_FreeType(library) FT_Init_FreeType((FT_Library*)(library)) #define FXFT_New_Memory_Face(library, base, size, index, face) \ - FT_New_Memory_Face((FT_Library)(library), base, size, index, (FT_Face*)(face)) + FT_New_Memory_Face((FT_Library)(library), base, size, index, (FT_Face*)(face)) #define FXFT_New_Face(library, filename, index, face) \ - FT_New_Face((FT_Library)(library), filename, index, (FT_Face*)(face)) + FT_New_Face((FT_Library)(library), filename, index, (FT_Face*)(face)) #define FXFT_Get_Face_FreeType(face) ((FT_Face)face)->driver->root.library -#define FXFT_Select_Charmap(face, encoding) FT_Select_Charmap((FT_Face)face, (FT_Encoding)encoding) -#define FXFT_Set_Charmap(face, charmap) FT_Set_Charmap((FT_Face)face, (FT_CharMap)charmap) -#define FXFT_Load_Glyph(face, glyph_index, flags) FT_Load_Glyph((FT_Face)face, glyph_index, flags) +#define FXFT_Select_Charmap(face, encoding) \ + FT_Select_Charmap((FT_Face)face, (FT_Encoding)encoding) +#define FXFT_Set_Charmap(face, charmap) \ + FT_Set_Charmap((FT_Face)face, (FT_CharMap)charmap) +#define FXFT_Load_Glyph(face, glyph_index, flags) \ + FT_Load_Glyph((FT_Face)face, glyph_index, flags) #define FXFT_Get_Char_Index(face, code) FT_Get_Char_Index((FT_Face)face, code) -#define FXFT_Get_Glyph_Name(face, index, buffer, size) FT_Get_Glyph_Name((FT_Face)face, index, buffer, size) +#define FXFT_Get_Glyph_Name(face, index, buffer, size) \ + FT_Get_Glyph_Name((FT_Face)face, index, buffer, size) #define FXFT_Get_Name_Index(face, name) FT_Get_Name_Index((FT_Face)face, name) -#define FXFT_Has_Glyph_Names(face) (((FT_Face)face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES) +#define FXFT_Has_Glyph_Names(face) \ + (((FT_Face)face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES) #define FXFT_Get_Postscript_Name(face) FT_Get_Postscript_Name((FT_Face)face) #define FXFT_Load_Sfnt_Table(face, tag, offset, buffer, length) \ - FT_Load_Sfnt_Table((FT_Face)face, tag, offset, buffer, length) -#define FXFT_Get_First_Char(face, glyph_index) FT_Get_First_Char((FT_Face)face, glyph_index) -#define FXFT_Get_Next_Char(face, code, glyph_index) FT_Get_Next_Char((FT_Face)face, code, glyph_index) -#define FXFT_Clear_Face_External_Stream(face) (((FT_Face)face)->face_flags&=~FT_FACE_FLAG_EXTERNAL_STREAM) -#define FXFT_Get_Face_External_Stream(face) (((FT_Face)face)->face_flags&FT_FACE_FLAG_EXTERNAL_STREAM) -#define FXFT_Is_Face_TT_OT(face) (((FT_Face)face)->face_flags&FT_FACE_FLAG_SFNT) -#define FXFT_Is_Face_Tricky(face) (((FT_Face)face)->face_flags&FXFT_FACE_FLAG_TRICKY) -#define FXFT_Is_Face_fixedwidth(face) (((FT_Face)face)->face_flags & FT_FACE_FLAG_FIXED_WIDTH) + FT_Load_Sfnt_Table((FT_Face)face, tag, offset, buffer, length) +#define FXFT_Get_First_Char(face, glyph_index) \ + FT_Get_First_Char((FT_Face)face, glyph_index) +#define FXFT_Get_Next_Char(face, code, glyph_index) \ + FT_Get_Next_Char((FT_Face)face, code, glyph_index) +#define FXFT_Clear_Face_External_Stream(face) \ + (((FT_Face)face)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM) +#define FXFT_Get_Face_External_Stream(face) \ + (((FT_Face)face)->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM) +#define FXFT_Is_Face_TT_OT(face) \ + (((FT_Face)face)->face_flags & FT_FACE_FLAG_SFNT) +#define FXFT_Is_Face_Tricky(face) \ + (((FT_Face)face)->face_flags & FXFT_FACE_FLAG_TRICKY) +#define FXFT_Is_Face_fixedwidth(face) \ + (((FT_Face)face)->face_flags & FT_FACE_FLAG_FIXED_WIDTH) #define FXFT_Get_Face_Stream_Base(face) ((FT_Face)face)->stream->base #define FXFT_Get_Face_Stream_Size(face) ((FT_Face)face)->stream->size #define FXFT_Get_Face_Family_Name(face) ((FT_Face)face)->family_name #define FXFT_Get_Face_Style_Name(face) ((FT_Face)face)->style_name #define FXFT_Get_Face_Numfaces(face) ((FT_Face)face)->num_faces #define FXFT_Get_Face_Faceindex(face) ((FT_Face)face)->face_index -#define FXFT_Is_Face_Italic(face) (((FT_Face)face)->style_flags&FT_STYLE_FLAG_ITALIC) -#define FXFT_Is_Face_Bold(face) (((FT_Face)face)->style_flags&FT_STYLE_FLAG_BOLD) +#define FXFT_Is_Face_Italic(face) \ + (((FT_Face)face)->style_flags & FT_STYLE_FLAG_ITALIC) +#define FXFT_Is_Face_Bold(face) \ + (((FT_Face)face)->style_flags & FT_STYLE_FLAG_BOLD) #define FXFT_Get_Face_Charmaps(face) ((FT_Face)face)->charmaps -#define FXFT_Get_Glyph_HoriBearingX(face) ((FT_Face)face)->glyph->metrics.horiBearingX -#define FXFT_Get_Glyph_HoriBearingY(face) ((FT_Face)face)->glyph->metrics.horiBearingY +#define FXFT_Get_Glyph_HoriBearingX(face) \ + ((FT_Face)face)->glyph->metrics.horiBearingX +#define FXFT_Get_Glyph_HoriBearingY(face) \ + ((FT_Face)face)->glyph->metrics.horiBearingY #define FXFT_Get_Glyph_Width(face) ((FT_Face)face)->glyph->metrics.width #define FXFT_Get_Glyph_Height(face) ((FT_Face)face)->glyph->metrics.height #define FXFT_Get_Face_CharmapCount(face) ((FT_Face)face)->num_charmaps @@ -105,23 +122,30 @@ typedef FT_CharMap FXFT_CharMap; #define FXFT_Get_Face_yMin(face) ((FT_Face)face)->bbox.yMin #define FXFT_Get_Face_yMax(face) ((FT_Face)face)->bbox.yMax #define FXFT_Get_Face_Height(face) ((FT_Face)face)->height -#define FXFT_Get_Face_UnderLineThickness(face) ((FT_Face)face)->underline_thickness -#define FXFT_Get_Face_UnderLinePosition(face) ((FT_Face)face)->underline_position +#define FXFT_Get_Face_UnderLineThickness(face) \ + ((FT_Face)face)->underline_thickness +#define FXFT_Get_Face_UnderLinePosition(face) \ + ((FT_Face)face)->underline_position #define FXFT_Get_Face_MaxAdvanceWidth(face) ((FT_Face)face)->max_advance_width #define FXFT_Get_Face_Ascender(face) ((FT_Face)face)->ascender #define FXFT_Get_Face_Descender(face) ((FT_Face)face)->descender -#define FXFT_Get_Glyph_HoriAdvance(face) ((FT_Face)face)->glyph->metrics.horiAdvance +#define FXFT_Get_Glyph_HoriAdvance(face) \ + ((FT_Face)face)->glyph->metrics.horiAdvance #define FXFT_Get_MM_Axis(var, index) &((FT_MM_Var*)var)->axis[index] #define FXFT_Get_MM_Axis_Min(axis) ((FT_Var_Axis*)axis)->minimum #define FXFT_Get_MM_Axis_Max(axis) ((FT_Var_Axis*)axis)->maximum #define FXFT_Get_MM_Axis_Def(axis) ((FT_Var_Axis*)axis)->def -#define FXFT_Alloc(library, size) ((FT_Library)library)->memory->alloc(((FT_Library)library)->memory, size) -#define FXFT_Free(face, p) ((FT_Face)face)->memory->free(((FT_Face)face)->memory, p) +#define FXFT_Alloc(library, size) \ + ((FT_Library)library)->memory->alloc(((FT_Library)library)->memory, size) +#define FXFT_Free(face, p) \ + ((FT_Face)face)->memory->free(((FT_Face)face)->memory, p) #define FXFT_Get_Glyph_Outline(face) &((FT_Face)face)->glyph->outline -#define FXFT_Get_Outline_Bbox(outline, cbox) FT_Outline_Get_CBox(outline, cbox) -#define FXFT_Render_Glyph(face, mode) FT_Render_Glyph(((FT_Face)face)->glyph, (enum FT_Render_Mode_)mode) +#define FXFT_Get_Outline_Bbox(outline, cbox) FT_Outline_Get_CBox(outline, cbox) +#define FXFT_Render_Glyph(face, mode) \ + FT_Render_Glyph(((FT_Face)face)->glyph, (enum FT_Render_Mode_)mode) #define FXFT_Get_MM_Var(face, p) FT_Get_MM_Var((FT_Face)face, p) -#define FXFT_Set_MM_Design_Coordinates(face, n, p) FT_Set_MM_Design_Coordinates((FT_Face)face, n, p) +#define FXFT_Set_MM_Design_Coordinates(face, n, p) \ + FT_Set_MM_Design_Coordinates((FT_Face)face, n, p) #define FXFT_Set_Pixel_Sizes(face, w, h) FT_Set_Pixel_Sizes((FT_Face)face, w, h) #define FXFT_Set_Transform(face, m, d) FT_Set_Transform((FT_Face)face, m, d) #define FXFT_Outline_Embolden(outline, s) FT_Outline_Embolden(outline, s) @@ -133,13 +157,19 @@ typedef FT_CharMap FXFT_CharMap; #define FXFT_Get_Bitmap_Buffer(bitmap) ((FT_Bitmap*)bitmap)->buffer #define FXFT_Get_Glyph_BitmapLeft(face) ((FT_Face)face)->glyph->bitmap_left #define FXFT_Get_Glyph_BitmapTop(face) ((FT_Face)face)->glyph->bitmap_top -#define FXFT_Outline_Decompose(outline, funcs, params) FT_Outline_Decompose(outline, funcs, params) -#define FXFT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution) FT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution) +#define FXFT_Outline_Decompose(outline, funcs, params) \ + FT_Outline_Decompose(outline, funcs, params) +#define FXFT_Set_Char_Size(face, char_width, char_height, horz_resolution, \ + vert_resolution) \ + FT_Set_Char_Size(face, char_width, char_height, horz_resolution, \ + vert_resolution) #define FXFT_Get_Glyph(slot, aglyph) FT_Get_Glyph(slot, aglyph) -#define FXFT_Glyph_Get_CBox(glyph, bbox_mode, acbox) FT_Glyph_Get_CBox(glyph, bbox_mode, acbox) -#define FXFT_Done_Glyph(glyph) FT_Done_Glyph(glyph) -#define FXFT_Library_SetLcdFilter(library, filter) FT_Library_SetLcdFilter((FT_Library)(library), filter) -int FXFT_unicode_from_adobe_name(const char* glyph_name); +#define FXFT_Glyph_Get_CBox(glyph, bbox_mode, acbox) \ + FT_Glyph_Get_CBox(glyph, bbox_mode, acbox) +#define FXFT_Done_Glyph(glyph) FT_Done_Glyph(glyph) +#define FXFT_Library_SetLcdFilter(library, filter) \ + FT_Library_SetLcdFilter((FT_Library)(library), filter) +int FXFT_unicode_from_adobe_name(const char* glyph_name); void FXFT_adobe_name_from_unicode(char* name, wchar_t unicode); #ifdef __cplusplus }; diff --git a/core/include/fxge/fx_ge.h b/core/include/fxge/fx_ge.h index dd349adb29..0aa3f17d4d 100644 --- a/core/include/fxge/fx_ge.h +++ b/core/include/fxge/fx_ge.h @@ -22,708 +22,712 @@ class IFX_RenderDeviceDriver; class CCodec_ModuleMgr; class IFXG_PaintModuleMgr; -class CFX_GEModule -{ -public: - - static void Create(); - - static void Use(CFX_GEModule* pMgr); - - static CFX_GEModule* Get(); - - static void Destroy(); -public: - - CFX_FontCache* GetFontCache(); - CFX_FontMgr* GetFontMgr() - { - return m_pFontMgr; - } - void SetTextGamma(FX_FLOAT gammaValue); - const uint8_t* GetTextGammaTable(); - - void SetCodecModule(CCodec_ModuleMgr* pCodecModule) - { - m_pCodecModule = pCodecModule; - } - CCodec_ModuleMgr* GetCodecModule() - { - return m_pCodecModule; - } - FXFT_Library m_FTLibrary; - void* GetPlatformData() - { - return m_pPlatformData; - } -protected: - - CFX_GEModule(); - - ~CFX_GEModule(); - void InitPlatform(); - void DestroyPlatform(); -private: - uint8_t m_GammaValue[256]; - CFX_FontCache* m_pFontCache; - CFX_FontMgr* m_pFontMgr; - CCodec_ModuleMgr* m_pCodecModule; - void* m_pPlatformData; +class CFX_GEModule { + public: + static void Create(); + + static void Use(CFX_GEModule* pMgr); + + static CFX_GEModule* Get(); + + static void Destroy(); + + public: + CFX_FontCache* GetFontCache(); + CFX_FontMgr* GetFontMgr() { return m_pFontMgr; } + void SetTextGamma(FX_FLOAT gammaValue); + const uint8_t* GetTextGammaTable(); + + void SetCodecModule(CCodec_ModuleMgr* pCodecModule) { + m_pCodecModule = pCodecModule; + } + CCodec_ModuleMgr* GetCodecModule() { return m_pCodecModule; } + FXFT_Library m_FTLibrary; + void* GetPlatformData() { return m_pPlatformData; } + + protected: + CFX_GEModule(); + + ~CFX_GEModule(); + void InitPlatform(); + void DestroyPlatform(); + + private: + uint8_t m_GammaValue[256]; + CFX_FontCache* m_pFontCache; + CFX_FontMgr* m_pFontMgr; + CCodec_ModuleMgr* m_pCodecModule; + void* m_pPlatformData; }; typedef struct { + FX_FLOAT m_PointX; - FX_FLOAT m_PointX; + FX_FLOAT m_PointY; - FX_FLOAT m_PointY; - - int m_Flag; + int m_Flag; } FX_PATHPOINT; -#define FXPT_CLOSEFIGURE 0x01 -#define FXPT_LINETO 0x02 -#define FXPT_BEZIERTO 0x04 -#define FXPT_MOVETO 0x06 -#define FXPT_TYPE 0x06 -#define FXFILL_ALTERNATE 1 -#define FXFILL_WINDING 2 -class CFX_ClipRgn -{ -public: - - CFX_ClipRgn(int device_width, int device_height); +#define FXPT_CLOSEFIGURE 0x01 +#define FXPT_LINETO 0x02 +#define FXPT_BEZIERTO 0x04 +#define FXPT_MOVETO 0x06 +#define FXPT_TYPE 0x06 +#define FXFILL_ALTERNATE 1 +#define FXFILL_WINDING 2 +class CFX_ClipRgn { + public: + CFX_ClipRgn(int device_width, int device_height); - CFX_ClipRgn(const FX_RECT& rect); + CFX_ClipRgn(const FX_RECT& rect); - CFX_ClipRgn(const CFX_ClipRgn& src); + CFX_ClipRgn(const CFX_ClipRgn& src); - ~CFX_ClipRgn(); + ~CFX_ClipRgn(); - typedef enum { - RectI, - MaskF - } ClipType; + typedef enum { RectI, MaskF } ClipType; - void Reset(const FX_RECT& rect); + void Reset(const FX_RECT& rect); - ClipType GetType() const - { - return m_Type; - } + ClipType GetType() const { return m_Type; } - const FX_RECT& GetBox() const - { - return m_Box; - } + const FX_RECT& GetBox() const { return m_Box; } - CFX_DIBitmapRef GetMask() const - { - return m_Mask; - } + CFX_DIBitmapRef GetMask() const { return m_Mask; } - void IntersectRect(const FX_RECT& rect); + void IntersectRect(const FX_RECT& rect); - void IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask); -protected: + void IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask); - ClipType m_Type; + protected: + ClipType m_Type; - FX_RECT m_Box; + FX_RECT m_Box; - CFX_DIBitmapRef m_Mask; + CFX_DIBitmapRef m_Mask; - void IntersectMaskRect(FX_RECT rect, FX_RECT mask_box, CFX_DIBitmapRef Mask); + void IntersectMaskRect(FX_RECT rect, FX_RECT mask_box, CFX_DIBitmapRef Mask); }; -#define FX_GAMMA(value) (value) -#define FX_GAMMA_INVERSE(value) (value) -inline FX_ARGB ArgbGamma(FX_ARGB argb) -{ - return argb; +#define FX_GAMMA(value) (value) +#define FX_GAMMA_INVERSE(value) (value) +inline FX_ARGB ArgbGamma(FX_ARGB argb) { + return argb; } -inline FX_ARGB ArgbGammaInverse(FX_ARGB argb) -{ - return argb; +inline FX_ARGB ArgbGammaInverse(FX_ARGB argb) { + return argb; } -class CFX_PathData -{ -public: - - CFX_PathData(); - - CFX_PathData(const CFX_PathData& src); - - ~CFX_PathData(); +class CFX_PathData { + public: + CFX_PathData(); + CFX_PathData(const CFX_PathData& src); + ~CFX_PathData(); + int GetPointCount() const { return m_PointCount; } - int GetPointCount() const - { - return m_PointCount; - } + int GetFlag(int index) const { return m_pPoints[index].m_Flag; } - int GetFlag(int index) const - { - return m_pPoints[index].m_Flag; - } + FX_FLOAT GetPointX(int index) const { return m_pPoints[index].m_PointX; } - FX_FLOAT GetPointX(int index) const - { - return m_pPoints[index].m_PointX; - } + FX_FLOAT GetPointY(int index) const { return m_pPoints[index].m_PointY; } - FX_FLOAT GetPointY(int index) const - { - return m_pPoints[index].m_PointY; - } + FX_PATHPOINT* GetPoints() const { return m_pPoints; } + void SetPointCount(int nPoints); + void AllocPointCount(int nPoints); + void AddPointCount(int addPoints); + CFX_FloatRect GetBoundingBox() const; - FX_PATHPOINT* GetPoints() const - { - return m_pPoints; - } + CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, FX_FLOAT miter_limit) const; - void SetPointCount(int nPoints); - void AllocPointCount(int nPoints); - void AddPointCount(int addPoints); + void Transform(const CFX_AffineMatrix* pMatrix); - CFX_FloatRect GetBoundingBox() const; + FX_BOOL IsRect() const; - CFX_FloatRect GetBoundingBox(FX_FLOAT line_width, FX_FLOAT miter_limit) const; + FX_BOOL GetZeroAreaPath(CFX_PathData& NewPath, + CFX_AffineMatrix* pMatrix, + FX_BOOL& bThin, + FX_BOOL bAdjust) const; - void Transform(const CFX_AffineMatrix* pMatrix); + FX_BOOL IsRect(const CFX_AffineMatrix* pMatrix, CFX_FloatRect* rect) const; - FX_BOOL IsRect() const; + void Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMatrix); + void AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top); - FX_BOOL GetZeroAreaPath(CFX_PathData& NewPath, CFX_AffineMatrix* pMatrix, FX_BOOL&bThin, FX_BOOL bAdjust) const; + void SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag); - FX_BOOL IsRect(const CFX_AffineMatrix* pMatrix, CFX_FloatRect* rect) const; + void TrimPoints(int nPoints); - void Append(const CFX_PathData* pSrc, const CFX_AffineMatrix* pMatrix); - void AppendRect(FX_FLOAT left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top); + void Copy(const CFX_PathData& src); - void SetPoint(int index, FX_FLOAT x, FX_FLOAT y, int flag); + protected: + friend class CPDF_Path; - void TrimPoints(int nPoints); + int m_PointCount; - void Copy(const CFX_PathData &src); -protected: - friend class CPDF_Path; + FX_PATHPOINT* m_pPoints; - int m_PointCount; - - FX_PATHPOINT* m_pPoints; - - int m_AllocCount; + int m_AllocCount; }; -class CFX_GraphStateData -{ -public: - - CFX_GraphStateData(); - - CFX_GraphStateData(const CFX_GraphStateData& src); +class CFX_GraphStateData { + public: + CFX_GraphStateData(); - ~CFX_GraphStateData(); + CFX_GraphStateData(const CFX_GraphStateData& src); - void Copy(const CFX_GraphStateData& src); + ~CFX_GraphStateData(); - void SetDashCount(int count); + void Copy(const CFX_GraphStateData& src); + void SetDashCount(int count); + typedef enum { LineCapButt = 0, LineCapRound = 1, LineCapSquare = 2 } LineCap; + LineCap m_LineCap; + int m_DashCount; + FX_FLOAT* m_DashArray; + FX_FLOAT m_DashPhase; - typedef enum { - LineCapButt = 0, - LineCapRound = 1, - LineCapSquare = 2 - } LineCap; - LineCap m_LineCap; - int m_DashCount; - FX_FLOAT* m_DashArray; - FX_FLOAT m_DashPhase; - - typedef enum { - LineJoinMiter = 0, - LineJoinRound = 1, - LineJoinBevel = 2, - } LineJoin; - LineJoin m_LineJoin; - FX_FLOAT m_MiterLimit; - FX_FLOAT m_LineWidth; - + typedef enum { + LineJoinMiter = 0, + LineJoinRound = 1, + LineJoinBevel = 2, + } LineJoin; + LineJoin m_LineJoin; + FX_FLOAT m_MiterLimit; + FX_FLOAT m_LineWidth; }; -#define FXDC_DEVICE_CLASS 1 -#define FXDC_PIXEL_WIDTH 2 -#define FXDC_PIXEL_HEIGHT 3 -#define FXDC_BITS_PIXEL 4 -#define FXDC_HORZ_SIZE 5 -#define FXDC_VERT_SIZE 6 -#define FXDC_RENDER_CAPS 7 -#define FXDC_DITHER_BITS 8 -#define FXDC_DISPLAY 1 -#define FXDC_PRINTER 2 -#define FXRC_GET_BITS 0x01 -#define FXRC_BIT_MASK 0x02 -#define FXRC_ALPHA_MASK 0x04 -#define FXRC_ALPHA_PATH 0x10 -#define FXRC_ALPHA_IMAGE 0x20 -#define FXRC_ALPHA_OUTPUT 0x40 -#define FXRC_BLEND_MODE 0x80 -#define FXRC_SOFT_CLIP 0x100 -#define FXRC_CMYK_OUTPUT 0x200 -#define FXRC_BITMASK_OUTPUT 0x400 -#define FXRC_BYTEMASK_OUTPUT 0x800 -#define FXRENDER_IMAGE_LOSSY 0x1000 -#define FXFILL_ALTERNATE 1 -#define FXFILL_WINDING 2 -#define FXFILL_FULLCOVER 4 -#define FXFILL_RECT_AA 8 -#define FX_FILL_STROKE 16 -#define FX_STROKE_ADJUST 32 -#define FX_STROKE_TEXT_MODE 64 -#define FX_FILL_TEXT_MODE 128 -#define FX_ZEROAREA_FILL 256 -#define FXFILL_NOPATHSMOOTH 512 -#define FXTEXT_CLEARTYPE 0x01 -#define FXTEXT_BGR_STRIPE 0x02 -#define FXTEXT_PRINTGRAPHICTEXT 0x04 -#define FXTEXT_NO_NATIVETEXT 0x08 -#define FXTEXT_PRINTIMAGETEXT 0x10 -#define FXTEXT_NOSMOOTH 0x20 +#define FXDC_DEVICE_CLASS 1 +#define FXDC_PIXEL_WIDTH 2 +#define FXDC_PIXEL_HEIGHT 3 +#define FXDC_BITS_PIXEL 4 +#define FXDC_HORZ_SIZE 5 +#define FXDC_VERT_SIZE 6 +#define FXDC_RENDER_CAPS 7 +#define FXDC_DITHER_BITS 8 +#define FXDC_DISPLAY 1 +#define FXDC_PRINTER 2 +#define FXRC_GET_BITS 0x01 +#define FXRC_BIT_MASK 0x02 +#define FXRC_ALPHA_MASK 0x04 +#define FXRC_ALPHA_PATH 0x10 +#define FXRC_ALPHA_IMAGE 0x20 +#define FXRC_ALPHA_OUTPUT 0x40 +#define FXRC_BLEND_MODE 0x80 +#define FXRC_SOFT_CLIP 0x100 +#define FXRC_CMYK_OUTPUT 0x200 +#define FXRC_BITMASK_OUTPUT 0x400 +#define FXRC_BYTEMASK_OUTPUT 0x800 +#define FXRENDER_IMAGE_LOSSY 0x1000 +#define FXFILL_ALTERNATE 1 +#define FXFILL_WINDING 2 +#define FXFILL_FULLCOVER 4 +#define FXFILL_RECT_AA 8 +#define FX_FILL_STROKE 16 +#define FX_STROKE_ADJUST 32 +#define FX_STROKE_TEXT_MODE 64 +#define FX_FILL_TEXT_MODE 128 +#define FX_ZEROAREA_FILL 256 +#define FXFILL_NOPATHSMOOTH 512 +#define FXTEXT_CLEARTYPE 0x01 +#define FXTEXT_BGR_STRIPE 0x02 +#define FXTEXT_PRINTGRAPHICTEXT 0x04 +#define FXTEXT_NO_NATIVETEXT 0x08 +#define FXTEXT_PRINTIMAGETEXT 0x10 +#define FXTEXT_NOSMOOTH 0x20 typedef struct { - FX_DWORD m_GlyphIndex; - FX_FLOAT m_OriginX, m_OriginY; - int m_FontCharWidth; - FX_BOOL m_bGlyphAdjust; - FX_FLOAT m_AdjustMatrix[4]; - FX_DWORD m_ExtGID; - FX_BOOL m_bFontStyle; + FX_DWORD m_GlyphIndex; + FX_FLOAT m_OriginX, m_OriginY; + int m_FontCharWidth; + FX_BOOL m_bGlyphAdjust; + FX_FLOAT m_AdjustMatrix[4]; + FX_DWORD m_ExtGID; + FX_BOOL m_bFontStyle; } FXTEXT_CHARPOS; -class CFX_RenderDevice -{ -public: - CFX_RenderDevice(); - - virtual ~CFX_RenderDevice(); - - void SetDeviceDriver(IFX_RenderDeviceDriver* pDriver); +class CFX_RenderDevice { + public: + CFX_RenderDevice(); - IFX_RenderDeviceDriver* GetDeviceDriver() const - { - return m_pDeviceDriver; - } + virtual ~CFX_RenderDevice(); - FX_BOOL StartRendering(); + void SetDeviceDriver(IFX_RenderDeviceDriver* pDriver); - void EndRendering(); + IFX_RenderDeviceDriver* GetDeviceDriver() const { return m_pDeviceDriver; } + FX_BOOL StartRendering(); + void EndRendering(); - void SaveState(); + void SaveState(); - void RestoreState(FX_BOOL bKeepSaved = FALSE); + void RestoreState(FX_BOOL bKeepSaved = FALSE); + int GetWidth() const { return m_Width; } + int GetHeight() const { return m_Height; } + int GetDeviceClass() const { return m_DeviceClass; } - int GetWidth() const - { - return m_Width; - } + int GetBPP() const { return m_bpp; } - int GetHeight() const - { - return m_Height; - } + int GetRenderCaps() const { return m_RenderCaps; } - int GetDeviceClass() const - { - return m_DeviceClass; - } + int GetDeviceCaps(int id) const; - int GetBPP() const - { - return m_bpp; - } + CFX_Matrix GetCTM() const; - int GetRenderCaps() const - { - return m_RenderCaps; - } + CFX_DIBitmap* GetBitmap() const { return m_pBitmap; } + void SetBitmap(CFX_DIBitmap* pBitmap) { m_pBitmap = pBitmap; } - int GetDeviceCaps(int id) const; + FX_BOOL CreateCompatibleBitmap(CFX_DIBitmap* pDIB, + int width, + int height) const; - CFX_Matrix GetCTM() const; + const FX_RECT& GetClipBox() const { return m_ClipBox; } + FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + int fill_mode); - CFX_DIBitmap* GetBitmap() const - { - return m_pBitmap; - } - void SetBitmap(CFX_DIBitmap* pBitmap) - { - m_pBitmap = pBitmap; - } - - FX_BOOL CreateCompatibleBitmap(CFX_DIBitmap* pDIB, int width, int height) const; - - const FX_RECT& GetClipBox() const - { - return m_ClipBox; - } - - FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - int fill_mode - ); + FX_BOOL SetClip_Rect(const FX_RECT* pRect); - FX_BOOL SetClip_Rect(const FX_RECT* pRect); - - FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState - ); - - FX_BOOL DrawPath(const CFX_PathData* pPathData, + FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState, - FX_DWORD fill_color, - FX_DWORD stroke_color, - int fill_mode, - int alpha_flag = 0, - void* pIccTransform = NULL, - int blend_type = FXDIB_BLEND_NORMAL - ); - - FX_BOOL SetPixel(int x, int y, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL FillRect(const FX_RECT* pRect, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_DWORD color, - int fill_mode = 0, int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform = NULL); - - CFX_DIBitmap* GetBackDrop(); - - FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, int left, int top, int blend_type = FXDIB_BLEND_NORMAL, - void* pIccTransform = NULL); - - FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, int dest_height, - FX_DWORD flags = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL SetBitMask(const CFX_DIBSource* pBitmap, int left, int top, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL StretchBitMask(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, int dest_height, - FX_DWORD color, FX_DWORD flags = 0, int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, - const CFX_AffineMatrix* pMatrix, FX_DWORD flags, void*& handle, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - - FX_BOOL ContinueDIBits(void* handle, IFX_Pause* pPause); - - void CancelDIBits(void* handle); - - FX_BOOL DrawNormalText(int nChars, const FXTEXT_CHARPOS* pCharPos, - CFX_Font* pFont, CFX_FontCache* pCache, - FX_FLOAT font_size, const CFX_AffineMatrix* pText2Device, - FX_DWORD fill_color, FX_DWORD text_flags, - int alpha_flag = 0, void* pIccTransform = NULL); - - FX_BOOL DrawTextPath(int nChars, const FXTEXT_CHARPOS* pCharPos, - CFX_Font* pFont, CFX_FontCache* pCache, - FX_FLOAT font_size, const CFX_AffineMatrix* pText2User, - const CFX_AffineMatrix* pUser2Device, const CFX_GraphStateData* pGraphState, - FX_DWORD fill_color, FX_DWORD stroke_color, CFX_PathData* pClippingPath, int nFlag = 0, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL); - virtual void Begin() {} - virtual void End() {} -private: - - CFX_DIBitmap* m_pBitmap; - - - - int m_Width; - - int m_Height; - - int m_bpp; - - int m_RenderCaps; - - int m_DeviceClass; - - FX_RECT m_ClipBox; - -protected: - - IFX_RenderDeviceDriver* m_pDeviceDriver; -private: - - void InitDeviceInfo(); - - void UpdateClipBox(); + const CFX_GraphStateData* pGraphState); + + FX_BOOL DrawPath(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState, + FX_DWORD fill_color, + FX_DWORD stroke_color, + int fill_mode, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL SetPixel(int x, + int y, + FX_DWORD color, + int alpha_flag = 0, + void* pIccTransform = NULL); + + FX_BOOL FillRect(const FX_RECT* pRect, + FX_DWORD color, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL DrawCosmeticLine(FX_FLOAT x1, + FX_FLOAT y1, + FX_FLOAT x2, + FX_FLOAT y2, + FX_DWORD color, + int fill_mode = 0, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, + int left, + int top, + void* pIccTransform = NULL); + + CFX_DIBitmap* GetBackDrop(); + + FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, + int left, + int top, + int blend_type = FXDIB_BLEND_NORMAL, + void* pIccTransform = NULL); + + FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, + int left, + int top, + int dest_width, + int dest_height, + FX_DWORD flags = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL SetBitMask(const CFX_DIBSource* pBitmap, + int left, + int top, + FX_DWORD color, + int alpha_flag = 0, + void* pIccTransform = NULL); + + FX_BOOL StretchBitMask(const CFX_DIBSource* pBitmap, + int left, + int top, + int dest_width, + int dest_height, + FX_DWORD color, + FX_DWORD flags = 0, + int alpha_flag = 0, + void* pIccTransform = NULL); + + FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, + int bitmap_alpha, + FX_DWORD color, + const CFX_AffineMatrix* pMatrix, + FX_DWORD flags, + void*& handle, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + + FX_BOOL ContinueDIBits(void* handle, IFX_Pause* pPause); + + void CancelDIBits(void* handle); + + FX_BOOL DrawNormalText(int nChars, + const FXTEXT_CHARPOS* pCharPos, + CFX_Font* pFont, + CFX_FontCache* pCache, + FX_FLOAT font_size, + const CFX_AffineMatrix* pText2Device, + FX_DWORD fill_color, + FX_DWORD text_flags, + int alpha_flag = 0, + void* pIccTransform = NULL); + + FX_BOOL DrawTextPath(int nChars, + const FXTEXT_CHARPOS* pCharPos, + CFX_Font* pFont, + CFX_FontCache* pCache, + FX_FLOAT font_size, + const CFX_AffineMatrix* pText2User, + const CFX_AffineMatrix* pUser2Device, + const CFX_GraphStateData* pGraphState, + FX_DWORD fill_color, + FX_DWORD stroke_color, + CFX_PathData* pClippingPath, + int nFlag = 0, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL); + virtual void Begin() {} + virtual void End() {} + + private: + CFX_DIBitmap* m_pBitmap; + + int m_Width; + + int m_Height; + + int m_bpp; + + int m_RenderCaps; + + int m_DeviceClass; + + FX_RECT m_ClipBox; + + protected: + IFX_RenderDeviceDriver* m_pDeviceDriver; + + private: + void InitDeviceInfo(); + + void UpdateClipBox(); }; -class CFX_FxgeDevice : public CFX_RenderDevice -{ -public: - - CFX_FxgeDevice(); - - ~CFX_FxgeDevice(); - - FX_BOOL Attach(CFX_DIBitmap* pBitmap, int dither_bits = 0, FX_BOOL bRgbByteOrder = FALSE, CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); - - FX_BOOL Create(int width, int height, FXDIB_Format format, int dither_bits = 0, CFX_DIBitmap* pOriDevice = NULL); -protected: - - FX_BOOL m_bOwnedBitmap; +class CFX_FxgeDevice : public CFX_RenderDevice { + public: + CFX_FxgeDevice(); + + ~CFX_FxgeDevice(); + + FX_BOOL Attach(CFX_DIBitmap* pBitmap, + int dither_bits = 0, + FX_BOOL bRgbByteOrder = FALSE, + CFX_DIBitmap* pOriDevice = NULL, + FX_BOOL bGroupKnockout = FALSE); + + FX_BOOL Create(int width, + int height, + FXDIB_Format format, + int dither_bits = 0, + CFX_DIBitmap* pOriDevice = NULL); + + protected: + FX_BOOL m_bOwnedBitmap; }; -class CFX_SkiaDevice : public CFX_RenderDevice -{ -public: - - CFX_SkiaDevice(); - - ~CFX_SkiaDevice(); - - FX_BOOL Attach(CFX_DIBitmap* pBitmap, int dither_bits = 0, FX_BOOL bRgbByteOrder = FALSE, CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); - - FX_BOOL Create(int width, int height, FXDIB_Format format, int dither_bits = 0, CFX_DIBitmap* pOriDevice = NULL); -protected: - - FX_BOOL m_bOwnedBitmap; +class CFX_SkiaDevice : public CFX_RenderDevice { + public: + CFX_SkiaDevice(); + + ~CFX_SkiaDevice(); + + FX_BOOL Attach(CFX_DIBitmap* pBitmap, + int dither_bits = 0, + FX_BOOL bRgbByteOrder = FALSE, + CFX_DIBitmap* pOriDevice = NULL, + FX_BOOL bGroupKnockout = FALSE); + + FX_BOOL Create(int width, + int height, + FXDIB_Format format, + int dither_bits = 0, + CFX_DIBitmap* pOriDevice = NULL); + + protected: + FX_BOOL m_bOwnedBitmap; }; -class IFX_RenderDeviceDriver -{ -public: - - static IFX_RenderDeviceDriver* CreateFxgeDriver(CFX_DIBitmap* pBitmap, FX_BOOL bRgbByteOrder = FALSE, - CFX_DIBitmap* pOriDevice = NULL, FX_BOOL bGroupKnockout = FALSE); +class IFX_RenderDeviceDriver { + public: + static IFX_RenderDeviceDriver* CreateFxgeDriver( + CFX_DIBitmap* pBitmap, + FX_BOOL bRgbByteOrder = FALSE, + CFX_DIBitmap* pOriDevice = NULL, + FX_BOOL bGroupKnockout = FALSE); - virtual ~IFX_RenderDeviceDriver() {} - virtual void Begin() { } - virtual void End() { } + virtual ~IFX_RenderDeviceDriver() {} + virtual void Begin() {} + virtual void End() {} - virtual int GetDeviceCaps(int caps_id) = 0; + virtual int GetDeviceCaps(int caps_id) = 0; - virtual CFX_Matrix GetCTM() const - { - return CFX_Matrix(); - } + virtual CFX_Matrix GetCTM() const { return CFX_Matrix(); } - virtual FX_BOOL IsPSPrintDriver() - { - return FALSE; - } + virtual FX_BOOL IsPSPrintDriver() { return FALSE; } - virtual FX_BOOL StartRendering() - { - return TRUE; - } + virtual FX_BOOL StartRendering() { return TRUE; } - virtual void EndRendering() {} + virtual void EndRendering() {} + virtual void SaveState() = 0; + virtual void RestoreState(FX_BOOL bKeepSaved = FALSE) = 0; + virtual FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + int fill_mode) = 0; - virtual void SaveState() = 0; - - virtual void RestoreState(FX_BOOL bKeepSaved = FALSE) = 0; - - - virtual FX_BOOL SetClip_PathFill(const CFX_PathData* pPathData, + virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device, - int fill_mode - ) = 0; - - virtual FX_BOOL SetClip_PathStroke(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState - ) - { - return FALSE; - } - - virtual FX_BOOL DrawPath(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState, - FX_DWORD fill_color, - FX_DWORD stroke_color, - int fill_mode, - int alpha_flag = 0, - void* pIccTransform = NULL, - int blend_type = FXDIB_BLEND_NORMAL - ) = 0; - - virtual FX_BOOL SetPixel(int x, int y, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL) - { - return FALSE; - } - - virtual FX_BOOL FillRect(const FX_RECT* pRect, FX_DWORD fill_color, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) - { - return FALSE; - } - - virtual FX_BOOL DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) - { - return FALSE; - } - - virtual FX_BOOL GetClipBox(FX_RECT* pRect) = 0; - - virtual FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform = NULL, FX_BOOL bDEdge = FALSE) - { - return FALSE; - } - virtual CFX_DIBitmap* GetBackDrop() - { - return NULL; - } - - virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, const FX_RECT* pSrcRect, - int dest_left, int dest_top, int blend_type, - int alpha_flag = 0, void* pIccTransform = NULL) = 0; - - virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, - int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) = 0; - - virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, FX_DWORD color, - const CFX_AffineMatrix* pMatrix, FX_DWORD flags, void*& handle, - int alpha_flag = 0, void* pIccTransform = NULL, int blend_type = FXDIB_BLEND_NORMAL) = 0; - - virtual FX_BOOL ContinueDIBits(void* handle, IFX_Pause* pPause) - { - return FALSE; - } - - virtual void CancelDIBits(void* handle) {} - - virtual FX_BOOL DrawDeviceText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, - CFX_FontCache* pCache, const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL) - { - return FALSE; - } - - virtual void* GetPlatformSurface() - { - return NULL; - } - - virtual int GetDriverType() - { - return 0; - } - - virtual void ClearDriver() {} + const CFX_GraphStateData* pGraphState) { + return FALSE; + } + + virtual FX_BOOL DrawPath(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState, + FX_DWORD fill_color, + FX_DWORD stroke_color, + int fill_mode, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL) = 0; + + virtual FX_BOOL SetPixel(int x, + int y, + FX_DWORD color, + int alpha_flag = 0, + void* pIccTransform = NULL) { + return FALSE; + } + + virtual FX_BOOL FillRect(const FX_RECT* pRect, + FX_DWORD fill_color, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL) { + return FALSE; + } + + virtual FX_BOOL DrawCosmeticLine(FX_FLOAT x1, + FX_FLOAT y1, + FX_FLOAT x2, + FX_FLOAT y2, + FX_DWORD color, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL) { + return FALSE; + } + + virtual FX_BOOL GetClipBox(FX_RECT* pRect) = 0; + + virtual FX_BOOL GetDIBits(CFX_DIBitmap* pBitmap, + int left, + int top, + void* pIccTransform = NULL, + FX_BOOL bDEdge = FALSE) { + return FALSE; + } + virtual CFX_DIBitmap* GetBackDrop() { return NULL; } + + virtual FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, + FX_DWORD color, + const FX_RECT* pSrcRect, + int dest_left, + int dest_top, + int blend_type, + int alpha_flag = 0, + void* pIccTransform = NULL) = 0; + + virtual FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, + FX_DWORD color, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + FX_DWORD flags, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL) = 0; + + virtual FX_BOOL StartDIBits(const CFX_DIBSource* pBitmap, + int bitmap_alpha, + FX_DWORD color, + const CFX_AffineMatrix* pMatrix, + FX_DWORD flags, + void*& handle, + int alpha_flag = 0, + void* pIccTransform = NULL, + int blend_type = FXDIB_BLEND_NORMAL) = 0; + + virtual FX_BOOL ContinueDIBits(void* handle, IFX_Pause* pPause) { + return FALSE; + } + + virtual void CancelDIBits(void* handle) {} + + virtual FX_BOOL DrawDeviceText(int nChars, + const FXTEXT_CHARPOS* pCharPos, + CFX_Font* pFont, + CFX_FontCache* pCache, + const CFX_AffineMatrix* pObject2Device, + FX_FLOAT font_size, + FX_DWORD color, + int alpha_flag = 0, + void* pIccTransform = NULL) { + return FALSE; + } + + virtual void* GetPlatformSurface() { return NULL; } + + virtual int GetDriverType() { return 0; } + + virtual void ClearDriver() {} }; -class IFX_PSOutput -{ -public: - virtual void Release() = 0; - virtual void OutputPS(const FX_CHAR* string, int len) = 0; - -protected: - ~IFX_PSOutput() { } +class IFX_PSOutput { + public: + virtual void Release() = 0; + virtual void OutputPS(const FX_CHAR* string, int len) = 0; + + protected: + ~IFX_PSOutput() {} }; class CPSFont; -class CFX_PSRenderer -{ -public: - - CFX_PSRenderer(); +class CFX_PSRenderer { + public: + CFX_PSRenderer(); - ~CFX_PSRenderer(); + ~CFX_PSRenderer(); - void Init(IFX_PSOutput* pOutput, int ps_level, int width, int height, FX_BOOL bCmykOutput); - FX_BOOL StartRendering(); - void EndRendering(); + void Init(IFX_PSOutput* pOutput, + int ps_level, + int width, + int height, + FX_BOOL bCmykOutput); + FX_BOOL StartRendering(); + void EndRendering(); - void SaveState(); + void SaveState(); - void RestoreState(FX_BOOL bKeepSaved = FALSE); + void RestoreState(FX_BOOL bKeepSaved = FALSE); - void SetClip_PathFill(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - int fill_mode - ); + void SetClip_PathFill(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + int fill_mode); - void SetClip_PathStroke(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState - ); + void SetClip_PathStroke(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState); - FX_RECT GetClipBox() - { - return m_ClipBox; - } + FX_RECT GetClipBox() { return m_ClipBox; } - FX_BOOL DrawPath(const CFX_PathData* pPathData, - const CFX_AffineMatrix* pObject2Device, - const CFX_GraphStateData* pGraphState, - FX_DWORD fill_color, - FX_DWORD stroke_color, - int fill_mode, - int alpha_flag = 0, - void* pIccTransform = NULL - ); + FX_BOOL DrawPath(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device, + const CFX_GraphStateData* pGraphState, + FX_DWORD fill_color, + FX_DWORD stroke_color, + int fill_mode, + int alpha_flag = 0, + void* pIccTransform = NULL); - FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, - int alpha_flag = 0, void* pIccTransform = NULL); + FX_BOOL SetDIBits(const CFX_DIBSource* pBitmap, + FX_DWORD color, + int dest_left, + int dest_top, + int alpha_flag = 0, + void* pIccTransform = NULL); - FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, int dest_left, int dest_top, - int dest_width, int dest_height, FX_DWORD flags, - int alpha_flag = 0, void* pIccTransform = NULL); + FX_BOOL StretchDIBits(const CFX_DIBSource* pBitmap, + FX_DWORD color, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + FX_DWORD flags, + int alpha_flag = 0, + void* pIccTransform = NULL); - FX_BOOL DrawDIBits(const CFX_DIBSource* pBitmap, FX_DWORD color, - const CFX_AffineMatrix* pMatrix, FX_DWORD flags, - int alpha_flag = 0, void* pIccTransform = NULL); + FX_BOOL DrawDIBits(const CFX_DIBSource* pBitmap, + FX_DWORD color, + const CFX_AffineMatrix* pMatrix, + FX_DWORD flags, + int alpha_flag = 0, + void* pIccTransform = NULL); - FX_BOOL DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, CFX_FontCache* pCache, - const CFX_AffineMatrix* pObject2Device, FX_FLOAT font_size, FX_DWORD color, - int alpha_flag = 0, void* pIccTransform = NULL); -private: + FX_BOOL DrawText(int nChars, + const FXTEXT_CHARPOS* pCharPos, + CFX_Font* pFont, + CFX_FontCache* pCache, + const CFX_AffineMatrix* pObject2Device, + FX_FLOAT font_size, + FX_DWORD color, + int alpha_flag = 0, + void* pIccTransform = NULL); - IFX_PSOutput* m_pOutput; + private: + IFX_PSOutput* m_pOutput; - int m_PSLevel; + int m_PSLevel; - CFX_GraphStateData m_CurGraphState; + CFX_GraphStateData m_CurGraphState; - FX_BOOL m_bGraphStateSet; + FX_BOOL m_bGraphStateSet; - FX_BOOL m_bCmykOutput; + FX_BOOL m_bCmykOutput; - FX_BOOL m_bColorSet; + FX_BOOL m_bColorSet; - FX_DWORD m_LastColor; + FX_DWORD m_LastColor; - FX_RECT m_ClipBox; + FX_RECT m_ClipBox; - CFX_ArrayTemplate<CPSFont*> m_PSFontList; + CFX_ArrayTemplate<CPSFont*> m_PSFontList; - CFX_ArrayTemplate<FX_RECT> m_ClipBoxStack; - FX_BOOL m_bInited; + CFX_ArrayTemplate<FX_RECT> m_ClipBoxStack; + FX_BOOL m_bInited; - void OutputPath(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device); + void OutputPath(const CFX_PathData* pPathData, + const CFX_AffineMatrix* pObject2Device); - void SetGraphState(const CFX_GraphStateData* pGraphState); + void SetGraphState(const CFX_GraphStateData* pGraphState); - void SetColor(FX_DWORD color, int alpha_flag, void* pIccTransform); + void SetColor(FX_DWORD color, int alpha_flag, void* pIccTransform); - void FindPSFontGlyph(CFX_FaceCache* pFaceCache, CFX_Font* pFont, const FXTEXT_CHARPOS& charpos, int& ps_fontnum, int &ps_glyphindex); + void FindPSFontGlyph(CFX_FaceCache* pFaceCache, + CFX_Font* pFont, + const FXTEXT_CHARPOS& charpos, + int& ps_fontnum, + int& ps_glyphindex); - void WritePSBinary(const uint8_t* data, int len); + void WritePSBinary(const uint8_t* data, int len); }; #endif // CORE_INCLUDE_FXGE_FX_GE_H_ diff --git a/core/include/fxge/fx_ge_apple.h b/core/include/fxge/fx_ge_apple.h index 0fb8bedcfc..16298581b3 100644 --- a/core/include/fxge/fx_ge_apple.h +++ b/core/include/fxge/fx_ge_apple.h @@ -7,21 +7,20 @@ #ifndef CORE_INCLUDE_FXGE_FX_GE_APPLE_H_ #define CORE_INCLUDE_FXGE_FX_GE_APPLE_H_ -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ -class CFX_QuartzDevice : public CFX_RenderDevice -{ -public: - CFX_QuartzDevice(); - ~CFX_QuartzDevice(); - FX_BOOL Attach(CGContextRef context, int32_t nDeviceClass = FXDC_DISPLAY); - FX_BOOL Attach(CFX_DIBitmap* pBitmap); - FX_BOOL Create(int32_t width, int32_t height, FXDIB_Format format); +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ +class CFX_QuartzDevice : public CFX_RenderDevice { + public: + CFX_QuartzDevice(); + ~CFX_QuartzDevice(); + FX_BOOL Attach(CGContextRef context, int32_t nDeviceClass = FXDC_DISPLAY); + FX_BOOL Attach(CFX_DIBitmap* pBitmap); + FX_BOOL Create(int32_t width, int32_t height, FXDIB_Format format); - CGContextRef GetContext(); + CGContextRef GetContext(); -protected: - CGContextRef m_pContext; - FX_BOOL m_bOwnedBitmap; + protected: + CGContextRef m_pContext; + FX_BOOL m_bOwnedBitmap; }; #endif diff --git a/core/include/fxge/fx_ge_win32.h b/core/include/fxge/fx_ge_win32.h index 5b16146b6a..149c46d40b 100644 --- a/core/include/fxge/fx_ge_win32.h +++ b/core/include/fxge/fx_ge_win32.h @@ -11,96 +11,87 @@ #ifndef _WINDOWS_ #include <windows.h> #endif -#define WINDIB_OPEN_MEMORY 0x1 -#define WINDIB_OPEN_PATHNAME 0x2 -typedef struct WINDIB_Open_Args_ { +#define WINDIB_OPEN_MEMORY 0x1 +#define WINDIB_OPEN_PATHNAME 0x2 +typedef struct WINDIB_Open_Args_ { + int flags; - int flags; + const uint8_t* memory_base; - const uint8_t* memory_base; + size_t memory_size; - size_t memory_size; - - const FX_WCHAR* path_name; + const FX_WCHAR* path_name; } WINDIB_Open_Args_; -class CFX_WindowsDIB : public CFX_DIBitmap -{ -public: - - static CFX_ByteString GetBitmapInfo(const CFX_DIBitmap* pBitmap); +class CFX_WindowsDIB : public CFX_DIBitmap { + public: + static CFX_ByteString GetBitmapInfo(const CFX_DIBitmap* pBitmap); - static CFX_DIBitmap* LoadFromBuf(BITMAPINFO* pbmi, void* pData); + static CFX_DIBitmap* LoadFromBuf(BITMAPINFO* pbmi, void* pData); - static HBITMAP GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC); + static HBITMAP GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC); - static CFX_DIBitmap* LoadFromDDB(HDC hDC, HBITMAP hBitmap, FX_DWORD* pPalette = NULL, FX_DWORD size = 256); + static CFX_DIBitmap* LoadFromDDB(HDC hDC, + HBITMAP hBitmap, + FX_DWORD* pPalette = NULL, + FX_DWORD size = 256); - static CFX_DIBitmap* LoadFromFile(const FX_WCHAR* filename); + static CFX_DIBitmap* LoadFromFile(const FX_WCHAR* filename); - static CFX_DIBitmap* LoadFromFile(const FX_CHAR* filename) - { - return LoadFromFile(CFX_WideString::FromLocal(filename).c_str()); - } + static CFX_DIBitmap* LoadFromFile(const FX_CHAR* filename) { + return LoadFromFile(CFX_WideString::FromLocal(filename).c_str()); + } - static CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args); + static CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args); - CFX_WindowsDIB(HDC hDC, int width, int height); + CFX_WindowsDIB(HDC hDC, int width, int height); - ~CFX_WindowsDIB(); + ~CFX_WindowsDIB(); - HDC GetDC() const - { - return m_hMemDC; - } + HDC GetDC() const { return m_hMemDC; } - HBITMAP GetWindowsBitmap() const - { - return m_hBitmap; - } + HBITMAP GetWindowsBitmap() const { return m_hBitmap; } - void LoadFromDevice(HDC hDC, int left, int top); + void LoadFromDevice(HDC hDC, int left, int top); - void SetToDevice(HDC hDC, int left, int top); -protected: + void SetToDevice(HDC hDC, int left, int top); - HDC m_hMemDC; + protected: + HDC m_hMemDC; - HBITMAP m_hBitmap; + HBITMAP m_hBitmap; - HBITMAP m_hOldBitmap; + HBITMAP m_hOldBitmap; }; -class CFX_WindowsDevice : public CFX_RenderDevice -{ -public: - static IFX_RenderDeviceDriver* CreateDriver(HDC hDC, FX_BOOL bCmykOutput = FALSE); +class CFX_WindowsDevice : public CFX_RenderDevice { + public: + static IFX_RenderDeviceDriver* CreateDriver(HDC hDC, + FX_BOOL bCmykOutput = FALSE); - CFX_WindowsDevice(HDC hDC, FX_BOOL bCmykOutput = FALSE, FX_BOOL bForcePSOutput = FALSE, int psLevel = 2); + CFX_WindowsDevice(HDC hDC, + FX_BOOL bCmykOutput = FALSE, + FX_BOOL bForcePSOutput = FALSE, + int psLevel = 2); - HDC GetDC() const; + HDC GetDC() const; - FX_BOOL m_bForcePSOutput; + FX_BOOL m_bForcePSOutput; - static int m_psLevel; + static int m_psLevel; }; -class CFX_WinBitmapDevice : public CFX_RenderDevice -{ -public: - - CFX_WinBitmapDevice(int width, int height, FXDIB_Format format); +class CFX_WinBitmapDevice : public CFX_RenderDevice { + public: + CFX_WinBitmapDevice(int width, int height, FXDIB_Format format); - ~CFX_WinBitmapDevice(); + ~CFX_WinBitmapDevice(); - HDC GetDC() - { - return m_hDC; - } -protected: + HDC GetDC() { return m_hDC; } - HBITMAP m_hBitmap; + protected: + HBITMAP m_hBitmap; - HBITMAP m_hOldBitmap; + HBITMAP m_hOldBitmap; - HDC m_hDC; + HDC m_hDC; }; #endif |