OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 7 #ifndef CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
8 #define CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 8 #define CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer; | 80 std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer; |
81 }; | 81 }; |
82 | 82 |
83 class CFX_ByteTextBuf : public CFX_BinaryBuf { | 83 class CFX_ByteTextBuf : public CFX_BinaryBuf { |
84 public: | 84 public: |
85 void AppendChar(int ch) { AppendByte((uint8_t)ch); } | 85 void AppendChar(int ch) { AppendByte((uint8_t)ch); } |
86 FX_STRSIZE GetLength() const { return m_DataSize; } | 86 FX_STRSIZE GetLength() const { return m_DataSize; } |
87 CFX_ByteStringC GetByteString() const; | 87 CFX_ByteStringC GetByteString() const; |
88 | 88 |
89 CFX_ByteTextBuf& operator<<(int i); | 89 CFX_ByteTextBuf& operator<<(int i); |
90 CFX_ByteTextBuf& operator<<(FX_DWORD i); | 90 CFX_ByteTextBuf& operator<<(uint32_t i); |
91 CFX_ByteTextBuf& operator<<(double f); | 91 CFX_ByteTextBuf& operator<<(double f); |
92 CFX_ByteTextBuf& operator<<(const CFX_ByteStringC& lpsz); | 92 CFX_ByteTextBuf& operator<<(const CFX_ByteStringC& lpsz); |
93 CFX_ByteTextBuf& operator<<(const CFX_ByteTextBuf& buf); | 93 CFX_ByteTextBuf& operator<<(const CFX_ByteTextBuf& buf); |
94 }; | 94 }; |
95 | 95 |
96 class CFX_WideTextBuf : public CFX_BinaryBuf { | 96 class CFX_WideTextBuf : public CFX_BinaryBuf { |
97 public: | 97 public: |
98 void AppendChar(FX_WCHAR wch); | 98 void AppendChar(FX_WCHAR wch); |
99 FX_STRSIZE GetLength() const { return m_DataSize / sizeof(FX_WCHAR); } | 99 FX_STRSIZE GetLength() const { return m_DataSize / sizeof(FX_WCHAR); } |
100 FX_WCHAR* GetBuffer() const { | 100 FX_WCHAR* GetBuffer() const { |
(...skipping 16 matching lines...) Expand all Loading... |
117 | 117 |
118 #ifdef PDF_ENABLE_XFA | 118 #ifdef PDF_ENABLE_XFA |
119 class CFX_ArchiveSaver { | 119 class CFX_ArchiveSaver { |
120 public: | 120 public: |
121 CFX_ArchiveSaver() : m_pStream(NULL) {} | 121 CFX_ArchiveSaver() : m_pStream(NULL) {} |
122 | 122 |
123 CFX_ArchiveSaver& operator<<(uint8_t i); | 123 CFX_ArchiveSaver& operator<<(uint8_t i); |
124 | 124 |
125 CFX_ArchiveSaver& operator<<(int i); | 125 CFX_ArchiveSaver& operator<<(int i); |
126 | 126 |
127 CFX_ArchiveSaver& operator<<(FX_DWORD i); | 127 CFX_ArchiveSaver& operator<<(uint32_t i); |
128 | 128 |
129 CFX_ArchiveSaver& operator<<(FX_FLOAT i); | 129 CFX_ArchiveSaver& operator<<(FX_FLOAT i); |
130 | 130 |
131 CFX_ArchiveSaver& operator<<(double i); | 131 CFX_ArchiveSaver& operator<<(double i); |
132 | 132 |
133 CFX_ArchiveSaver& operator<<(const CFX_ByteStringC& bstr); | 133 CFX_ArchiveSaver& operator<<(const CFX_ByteStringC& bstr); |
134 | 134 |
135 CFX_ArchiveSaver& operator<<(const FX_WCHAR* bstr); | 135 CFX_ArchiveSaver& operator<<(const FX_WCHAR* bstr); |
136 | 136 |
137 CFX_ArchiveSaver& operator<<(const CFX_WideString& wstr); | 137 CFX_ArchiveSaver& operator<<(const CFX_WideString& wstr); |
138 | 138 |
139 void Write(const void* pData, FX_STRSIZE dwSize); | 139 void Write(const void* pData, FX_STRSIZE dwSize); |
140 | 140 |
141 intptr_t GetLength() { return m_SavingBuf.GetSize(); } | 141 intptr_t GetLength() { return m_SavingBuf.GetSize(); } |
142 | 142 |
143 const uint8_t* GetBuffer() { return m_SavingBuf.GetBuffer(); } | 143 const uint8_t* GetBuffer() { return m_SavingBuf.GetBuffer(); } |
144 | 144 |
145 void SetStream(IFX_FileStream* pStream) { m_pStream = pStream; } | 145 void SetStream(IFX_FileStream* pStream) { m_pStream = pStream; } |
146 | 146 |
147 protected: | 147 protected: |
148 CFX_BinaryBuf m_SavingBuf; | 148 CFX_BinaryBuf m_SavingBuf; |
149 | 149 |
150 IFX_FileStream* m_pStream; | 150 IFX_FileStream* m_pStream; |
151 }; | 151 }; |
152 class CFX_ArchiveLoader { | 152 class CFX_ArchiveLoader { |
153 public: | 153 public: |
154 CFX_ArchiveLoader(const uint8_t* pData, FX_DWORD dwSize); | 154 CFX_ArchiveLoader(const uint8_t* pData, uint32_t dwSize); |
155 | 155 |
156 CFX_ArchiveLoader& operator>>(uint8_t& i); | 156 CFX_ArchiveLoader& operator>>(uint8_t& i); |
157 | 157 |
158 CFX_ArchiveLoader& operator>>(int& i); | 158 CFX_ArchiveLoader& operator>>(int& i); |
159 | 159 |
160 CFX_ArchiveLoader& operator>>(FX_DWORD& i); | 160 CFX_ArchiveLoader& operator>>(uint32_t& i); |
161 | 161 |
162 CFX_ArchiveLoader& operator>>(FX_FLOAT& i); | 162 CFX_ArchiveLoader& operator>>(FX_FLOAT& i); |
163 | 163 |
164 CFX_ArchiveLoader& operator>>(double& i); | 164 CFX_ArchiveLoader& operator>>(double& i); |
165 | 165 |
166 CFX_ArchiveLoader& operator>>(CFX_ByteString& bstr); | 166 CFX_ArchiveLoader& operator>>(CFX_ByteString& bstr); |
167 | 167 |
168 CFX_ArchiveLoader& operator>>(CFX_WideString& wstr); | 168 CFX_ArchiveLoader& operator>>(CFX_WideString& wstr); |
169 | 169 |
170 FX_BOOL IsEOF(); | 170 FX_BOOL IsEOF(); |
171 | 171 |
172 FX_BOOL Read(void* pBuf, FX_DWORD dwSize); | 172 FX_BOOL Read(void* pBuf, uint32_t dwSize); |
173 | 173 |
174 protected: | 174 protected: |
175 FX_DWORD m_LoadingPos; | 175 uint32_t m_LoadingPos; |
176 | 176 |
177 const uint8_t* m_pLoadingBuf; | 177 const uint8_t* m_pLoadingBuf; |
178 | 178 |
179 FX_DWORD m_LoadingSize; | 179 uint32_t m_LoadingSize; |
180 }; | 180 }; |
181 #endif // PDF_ENABLE_XFA | 181 #endif // PDF_ENABLE_XFA |
182 | 182 |
183 class CFX_FileBufferArchive { | 183 class CFX_FileBufferArchive { |
184 public: | 184 public: |
185 CFX_FileBufferArchive(); | 185 CFX_FileBufferArchive(); |
186 ~CFX_FileBufferArchive(); | 186 ~CFX_FileBufferArchive(); |
187 | 187 |
188 void Clear(); | 188 void Clear(); |
189 bool Flush(); | 189 bool Flush(); |
190 int32_t AppendBlock(const void* pBuf, size_t size); | 190 int32_t AppendBlock(const void* pBuf, size_t size); |
191 int32_t AppendByte(uint8_t byte); | 191 int32_t AppendByte(uint8_t byte); |
192 int32_t AppendDWord(FX_DWORD i); | 192 int32_t AppendDWord(uint32_t i); |
193 int32_t AppendString(const CFX_ByteStringC& lpsz); | 193 int32_t AppendString(const CFX_ByteStringC& lpsz); |
194 | 194 |
195 // |pFile| must outlive the CFX_FileBufferArchive. | 195 // |pFile| must outlive the CFX_FileBufferArchive. |
196 void AttachFile(IFX_StreamWrite* pFile); | 196 void AttachFile(IFX_StreamWrite* pFile); |
197 | 197 |
198 private: | 198 private: |
199 static const size_t kBufSize = 32768; | 199 static const size_t kBufSize = 32768; |
200 | 200 |
201 size_t m_Length; | 201 size_t m_Length; |
202 std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer; | 202 std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer; |
(...skipping 12 matching lines...) Expand all Loading... |
215 }; | 215 }; |
216 | 216 |
217 class CFX_UTF8Decoder { | 217 class CFX_UTF8Decoder { |
218 public: | 218 public: |
219 CFX_UTF8Decoder() { m_PendingBytes = 0; } | 219 CFX_UTF8Decoder() { m_PendingBytes = 0; } |
220 | 220 |
221 void Clear(); | 221 void Clear(); |
222 | 222 |
223 void Input(uint8_t byte); | 223 void Input(uint8_t byte); |
224 | 224 |
225 void AppendChar(FX_DWORD ch); | 225 void AppendChar(uint32_t ch); |
226 | 226 |
227 void ClearStatus() { m_PendingBytes = 0; } | 227 void ClearStatus() { m_PendingBytes = 0; } |
228 | 228 |
229 CFX_WideStringC GetResult() const { return m_Buffer.GetWideString(); } | 229 CFX_WideStringC GetResult() const { return m_Buffer.GetWideString(); } |
230 | 230 |
231 protected: | 231 protected: |
232 int m_PendingBytes; | 232 int m_PendingBytes; |
233 | 233 |
234 FX_DWORD m_PendingChar; | 234 uint32_t m_PendingChar; |
235 | 235 |
236 CFX_WideTextBuf m_Buffer; | 236 CFX_WideTextBuf m_Buffer; |
237 }; | 237 }; |
238 | 238 |
239 class CFX_UTF8Encoder { | 239 class CFX_UTF8Encoder { |
240 public: | 240 public: |
241 CFX_UTF8Encoder() {} | 241 CFX_UTF8Encoder() {} |
242 | 242 |
243 void Input(FX_WCHAR unicode); | 243 void Input(FX_WCHAR unicode); |
244 void AppendStr(const CFX_ByteStringC& str) { m_Buffer << str; } | 244 void AppendStr(const CFX_ByteStringC& str) { m_Buffer << str; } |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 void RemoveAll(); | 624 void RemoveAll(); |
625 | 625 |
626 FX_POSITION GetStartPosition() const { | 626 FX_POSITION GetStartPosition() const { |
627 return (m_nCount == 0) ? NULL : (FX_POSITION)-1; | 627 return (m_nCount == 0) ? NULL : (FX_POSITION)-1; |
628 } | 628 } |
629 | 629 |
630 void GetNextAssoc(FX_POSITION& rNextPosition, | 630 void GetNextAssoc(FX_POSITION& rNextPosition, |
631 void*& rKey, | 631 void*& rKey, |
632 void*& rValue) const; | 632 void*& rValue) const; |
633 | 633 |
634 FX_DWORD GetHashTableSize() const { return m_nHashTableSize; } | 634 uint32_t GetHashTableSize() const { return m_nHashTableSize; } |
635 | 635 |
636 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); | 636 void InitHashTable(uint32_t hashSize, FX_BOOL bAllocNow = TRUE); |
637 | 637 |
638 protected: | 638 protected: |
639 CAssoc** m_pHashTable; | 639 CAssoc** m_pHashTable; |
640 | 640 |
641 FX_DWORD m_nHashTableSize; | 641 uint32_t m_nHashTableSize; |
642 | 642 |
643 int m_nCount; | 643 int m_nCount; |
644 | 644 |
645 CAssoc* m_pFreeList; | 645 CAssoc* m_pFreeList; |
646 | 646 |
647 struct CFX_Plex* m_pBlocks; | 647 struct CFX_Plex* m_pBlocks; |
648 | 648 |
649 int m_nBlockSize; | 649 int m_nBlockSize; |
650 | 650 |
651 FX_DWORD HashKey(void* key) const; | 651 uint32_t HashKey(void* key) const; |
652 | 652 |
653 CAssoc* NewAssoc(); | 653 CAssoc* NewAssoc(); |
654 | 654 |
655 void FreeAssoc(CAssoc* pAssoc); | 655 void FreeAssoc(CAssoc* pAssoc); |
656 | 656 |
657 CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const; | 657 CAssoc* GetAssocAt(void* key, uint32_t& hash) const; |
658 }; | 658 }; |
659 | 659 |
660 template <class KeyType, class ValueType> | 660 template <class KeyType, class ValueType> |
661 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr { | 661 class CFX_MapPtrTemplate : public CFX_MapPtrToPtr { |
662 public: | 662 public: |
663 CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {} | 663 CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {} |
664 | 664 |
665 FX_BOOL Lookup(KeyType key, ValueType& rValue) const { | 665 FX_BOOL Lookup(KeyType key, ValueType& rValue) const { |
666 void* pValue = NULL; | 666 void* pValue = NULL; |
667 if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) { | 667 if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 void SetPrivateData(void* module_id, | 785 void SetPrivateData(void* module_id, |
786 void* pData, | 786 void* pData, |
787 PD_CALLBACK_FREEDATA callback); | 787 PD_CALLBACK_FREEDATA callback); |
788 void SetPrivateObj(void* module_id, CFX_DestructObject* pObj); | 788 void SetPrivateObj(void* module_id, CFX_DestructObject* pObj); |
789 | 789 |
790 void* GetPrivateData(void* module_id); | 790 void* GetPrivateData(void* module_id); |
791 FX_BOOL LookupPrivateData(void* module_id, void*& pData) const { | 791 FX_BOOL LookupPrivateData(void* module_id, void*& pData) const { |
792 if (!module_id) { | 792 if (!module_id) { |
793 return FALSE; | 793 return FALSE; |
794 } | 794 } |
795 FX_DWORD nCount = m_DataList.GetSize(); | 795 uint32_t nCount = m_DataList.GetSize(); |
796 for (FX_DWORD n = 0; n < nCount; n++) { | 796 for (uint32_t n = 0; n < nCount; n++) { |
797 if (m_DataList[n].m_pModuleId == module_id) { | 797 if (m_DataList[n].m_pModuleId == module_id) { |
798 pData = m_DataList[n].m_pData; | 798 pData = m_DataList[n].m_pData; |
799 return TRUE; | 799 return TRUE; |
800 } | 800 } |
801 } | 801 } |
802 return FALSE; | 802 return FALSE; |
803 } | 803 } |
804 | 804 |
805 FX_BOOL RemovePrivateData(void* module_id); | 805 FX_BOOL RemovePrivateData(void* module_id); |
806 | 806 |
807 protected: | 807 protected: |
808 CFX_ArrayTemplate<FX_PRIVATEDATA> m_DataList; | 808 CFX_ArrayTemplate<FX_PRIVATEDATA> m_DataList; |
809 | 809 |
810 void AddData(void* module_id, | 810 void AddData(void* module_id, |
811 void* pData, | 811 void* pData, |
812 PD_CALLBACK_FREEDATA callback, | 812 PD_CALLBACK_FREEDATA callback, |
813 FX_BOOL bSelfDestruct); | 813 FX_BOOL bSelfDestruct); |
814 }; | 814 }; |
815 | 815 |
816 class CFX_BitStream { | 816 class CFX_BitStream { |
817 public: | 817 public: |
818 void Init(const uint8_t* pData, FX_DWORD dwSize); | 818 void Init(const uint8_t* pData, uint32_t dwSize); |
819 | 819 |
820 FX_DWORD GetBits(FX_DWORD nBits); | 820 uint32_t GetBits(uint32_t nBits); |
821 | 821 |
822 void ByteAlign(); | 822 void ByteAlign(); |
823 | 823 |
824 FX_BOOL IsEOF() { return m_BitPos >= m_BitSize; } | 824 FX_BOOL IsEOF() { return m_BitPos >= m_BitSize; } |
825 | 825 |
826 void SkipBits(FX_DWORD nBits) { m_BitPos += nBits; } | 826 void SkipBits(uint32_t nBits) { m_BitPos += nBits; } |
827 | 827 |
828 void Rewind() { m_BitPos = 0; } | 828 void Rewind() { m_BitPos = 0; } |
829 | 829 |
830 FX_DWORD GetPos() const { return m_BitPos; } | 830 uint32_t GetPos() const { return m_BitPos; } |
831 | 831 |
832 FX_DWORD BitsRemaining() const { | 832 uint32_t BitsRemaining() const { |
833 return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0; | 833 return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0; |
834 } | 834 } |
835 | 835 |
836 protected: | 836 protected: |
837 FX_DWORD m_BitPos; | 837 uint32_t m_BitPos; |
838 | 838 |
839 FX_DWORD m_BitSize; | 839 uint32_t m_BitSize; |
840 | 840 |
841 const uint8_t* m_pData; | 841 const uint8_t* m_pData; |
842 }; | 842 }; |
843 template <class ObjClass> | 843 template <class ObjClass> |
844 class CFX_CountRef { | 844 class CFX_CountRef { |
845 public: | 845 public: |
846 typedef CFX_CountRef<ObjClass> Ref; | 846 typedef CFX_CountRef<ObjClass> Ref; |
847 | 847 |
848 class CountedObj : public ObjClass { | 848 class CountedObj : public ObjClass { |
849 public: | 849 public: |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 protected: | 1084 protected: |
1085 T1 m_Data; | 1085 T1 m_Data; |
1086 }; | 1086 }; |
1087 typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_FILESIZE)>, | 1087 typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_FILESIZE)>, |
1088 FX_FILESIZE> CFX_FileSizeListArray; | 1088 FX_FILESIZE> CFX_FileSizeListArray; |
1089 | 1089 |
1090 #ifdef PDF_ENABLE_XFA | 1090 #ifdef PDF_ENABLE_XFA |
1091 class IFX_Unknown { | 1091 class IFX_Unknown { |
1092 public: | 1092 public: |
1093 virtual ~IFX_Unknown() {} | 1093 virtual ~IFX_Unknown() {} |
1094 virtual FX_DWORD Release() = 0; | 1094 virtual uint32_t Release() = 0; |
1095 virtual FX_DWORD AddRef() = 0; | 1095 virtual uint32_t AddRef() = 0; |
1096 }; | 1096 }; |
1097 #define FX_IsOdd(a) ((a)&1) | 1097 #define FX_IsOdd(a) ((a)&1) |
1098 #endif // PDF_ENABLE_XFA | 1098 #endif // PDF_ENABLE_XFA |
1099 | 1099 |
1100 class CFX_Vector_3by1 { | 1100 class CFX_Vector_3by1 { |
1101 public: | 1101 public: |
1102 CFX_Vector_3by1() : a(0.0f), b(0.0f), c(0.0f) {} | 1102 CFX_Vector_3by1() : a(0.0f), b(0.0f), c(0.0f) {} |
1103 | 1103 |
1104 CFX_Vector_3by1(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1) | 1104 CFX_Vector_3by1(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1) |
1105 : a(a1), b(b1), c(c1) {} | 1105 : a(a1), b(b1), c(c1) {} |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 FX_FLOAT c; | 1143 FX_FLOAT c; |
1144 FX_FLOAT d; | 1144 FX_FLOAT d; |
1145 FX_FLOAT e; | 1145 FX_FLOAT e; |
1146 FX_FLOAT f; | 1146 FX_FLOAT f; |
1147 FX_FLOAT g; | 1147 FX_FLOAT g; |
1148 FX_FLOAT h; | 1148 FX_FLOAT h; |
1149 FX_FLOAT i; | 1149 FX_FLOAT i; |
1150 }; | 1150 }; |
1151 | 1151 |
1152 #endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 1152 #endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
OLD | NEW |