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_EXTENSION_H_ | 7 #ifndef CORE_FXCRT_EXTENSION_H_ |
8 #define CORE_FXCRT_EXTENSION_H_ | 8 #define CORE_FXCRT_EXTENSION_H_ |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "core/fxcrt/include/fx_basic.h" | 12 #include "core/fxcrt/include/fx_basic.h" |
13 #include "core/fxcrt/include/fx_safe_types.h" | 13 #include "core/fxcrt/include/fx_safe_types.h" |
14 | 14 |
15 class IFXCRT_FileAccess { | 15 class IFXCRT_FileAccess { |
16 public: | 16 public: |
17 virtual ~IFXCRT_FileAccess() {} | 17 virtual ~IFXCRT_FileAccess() {} |
18 virtual FX_BOOL Open(const CFX_ByteStringC& fileName, FX_DWORD dwMode) = 0; | 18 virtual FX_BOOL Open(const CFX_ByteStringC& fileName, uint32_t dwMode) = 0; |
19 virtual FX_BOOL Open(const CFX_WideStringC& fileName, FX_DWORD dwMode) = 0; | 19 virtual FX_BOOL Open(const CFX_WideStringC& fileName, uint32_t dwMode) = 0; |
20 virtual void Close() = 0; | 20 virtual void Close() = 0; |
21 virtual void Release() = 0; | 21 virtual void Release() = 0; |
22 virtual FX_FILESIZE GetSize() const = 0; | 22 virtual FX_FILESIZE GetSize() const = 0; |
23 virtual FX_FILESIZE GetPosition() const = 0; | 23 virtual FX_FILESIZE GetPosition() const = 0; |
24 virtual FX_FILESIZE SetPosition(FX_FILESIZE pos) = 0; | 24 virtual FX_FILESIZE SetPosition(FX_FILESIZE pos) = 0; |
25 virtual size_t Read(void* pBuffer, size_t szBuffer) = 0; | 25 virtual size_t Read(void* pBuffer, size_t szBuffer) = 0; |
26 virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0; | 26 virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0; |
27 virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0; | 27 virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0; |
28 virtual size_t WritePos(const void* pBuffer, | 28 virtual size_t WritePos(const void* pBuffer, |
29 size_t szBuffer, | 29 size_t szBuffer, |
(...skipping 14 matching lines...) Expand all Loading... |
44 delete this; | 44 delete this; |
45 } | 45 } |
46 | 46 |
47 IFX_FileAccess* Retain() override { | 47 IFX_FileAccess* Retain() override { |
48 m_RefCount++; | 48 m_RefCount++; |
49 return (IFX_FileAccess*)this; | 49 return (IFX_FileAccess*)this; |
50 } | 50 } |
51 | 51 |
52 void GetPath(CFX_WideString& wsPath) override { wsPath = m_path; } | 52 void GetPath(CFX_WideString& wsPath) override { wsPath = m_path; } |
53 | 53 |
54 IFX_FileStream* CreateFileStream(FX_DWORD dwModes) override { | 54 IFX_FileStream* CreateFileStream(uint32_t dwModes) override { |
55 return FX_CreateFileStream(m_path, dwModes); | 55 return FX_CreateFileStream(m_path, dwModes); |
56 } | 56 } |
57 | 57 |
58 FX_BOOL Init(const CFX_WideStringC& wsPath) { | 58 FX_BOOL Init(const CFX_WideStringC& wsPath) { |
59 m_path = wsPath; | 59 m_path = wsPath; |
60 m_RefCount = 1; | 60 m_RefCount = 1; |
61 return TRUE; | 61 return TRUE; |
62 } | 62 } |
63 | 63 |
64 protected: | 64 protected: |
65 CFX_WideString m_path; | 65 CFX_WideString m_path; |
66 FX_DWORD m_RefCount; | 66 uint32_t m_RefCount; |
67 }; | 67 }; |
68 #endif // PDF_ENABLE_XFA | 68 #endif // PDF_ENABLE_XFA |
69 | 69 |
70 class CFX_CRTFileStream final : public IFX_FileStream { | 70 class CFX_CRTFileStream final : public IFX_FileStream { |
71 public: | 71 public: |
72 explicit CFX_CRTFileStream(IFXCRT_FileAccess* pFA); | 72 explicit CFX_CRTFileStream(IFXCRT_FileAccess* pFA); |
73 ~CFX_CRTFileStream() override; | 73 ~CFX_CRTFileStream() override; |
74 | 74 |
75 // IFX_FileStream: | 75 // IFX_FileStream: |
76 IFX_FileStream* Retain() override; | 76 IFX_FileStream* Retain() override; |
77 void Release() override; | 77 void Release() override; |
78 FX_FILESIZE GetSize() override; | 78 FX_FILESIZE GetSize() override; |
79 FX_BOOL IsEOF() override; | 79 FX_BOOL IsEOF() override; |
80 FX_FILESIZE GetPosition() override; | 80 FX_FILESIZE GetPosition() override; |
81 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | 81 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
82 size_t ReadBlock(void* buffer, size_t size) override; | 82 size_t ReadBlock(void* buffer, size_t size) override; |
83 FX_BOOL WriteBlock(const void* buffer, | 83 FX_BOOL WriteBlock(const void* buffer, |
84 FX_FILESIZE offset, | 84 FX_FILESIZE offset, |
85 size_t size) override; | 85 size_t size) override; |
86 FX_BOOL Flush() override; | 86 FX_BOOL Flush() override; |
87 | 87 |
88 protected: | 88 protected: |
89 IFXCRT_FileAccess* m_pFile; | 89 IFXCRT_FileAccess* m_pFile; |
90 FX_DWORD m_dwCount; | 90 uint32_t m_dwCount; |
91 }; | 91 }; |
92 | 92 |
93 #define FX_MEMSTREAM_BlockSize (64 * 1024) | 93 #define FX_MEMSTREAM_BlockSize (64 * 1024) |
94 #define FX_MEMSTREAM_Consecutive 0x01 | 94 #define FX_MEMSTREAM_Consecutive 0x01 |
95 #define FX_MEMSTREAM_TakeOver 0x02 | 95 #define FX_MEMSTREAM_TakeOver 0x02 |
96 class CFX_MemoryStream final : public IFX_MemoryStream { | 96 class CFX_MemoryStream final : public IFX_MemoryStream { |
97 public: | 97 public: |
98 explicit CFX_MemoryStream(FX_BOOL bConsecutive) | 98 explicit CFX_MemoryStream(FX_BOOL bConsecutive) |
99 : m_dwCount(1), | 99 : m_dwCount(1), |
100 m_nTotalSize(0), | 100 m_nTotalSize(0), |
(...skipping 21 matching lines...) Expand all Loading... |
122 } | 122 } |
123 m_Blocks.RemoveAll(); | 123 m_Blocks.RemoveAll(); |
124 } | 124 } |
125 | 125 |
126 // IFX_MemoryStream: | 126 // IFX_MemoryStream: |
127 IFX_FileStream* Retain() override { | 127 IFX_FileStream* Retain() override { |
128 m_dwCount++; | 128 m_dwCount++; |
129 return this; | 129 return this; |
130 } | 130 } |
131 void Release() override { | 131 void Release() override { |
132 FX_DWORD nCount = --m_dwCount; | 132 uint32_t nCount = --m_dwCount; |
133 if (nCount) { | 133 if (nCount) { |
134 return; | 134 return; |
135 } | 135 } |
136 delete this; | 136 delete this; |
137 } | 137 } |
138 FX_FILESIZE GetSize() override { return (FX_FILESIZE)m_nCurSize; } | 138 FX_FILESIZE GetSize() override { return (FX_FILESIZE)m_nCurSize; } |
139 FX_BOOL IsEOF() override { return m_nCurPos >= (size_t)GetSize(); } | 139 FX_BOOL IsEOF() override { return m_nCurPos >= (size_t)GetSize(); } |
140 FX_FILESIZE GetPosition() override { return (FX_FILESIZE)m_nCurPos; } | 140 FX_FILESIZE GetPosition() override { return (FX_FILESIZE)m_nCurPos; } |
141 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 141 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
142 if (!buffer || !size) { | 142 if (!buffer || !size) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { | 275 if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { |
276 return; | 276 return; |
277 } | 277 } |
278 m_Blocks.RemoveAll(); | 278 m_Blocks.RemoveAll(); |
279 m_nTotalSize = m_nCurSize = m_nCurPos = 0; | 279 m_nTotalSize = m_nCurSize = m_nCurPos = 0; |
280 m_dwFlags = FX_MEMSTREAM_TakeOver; | 280 m_dwFlags = FX_MEMSTREAM_TakeOver; |
281 } | 281 } |
282 | 282 |
283 protected: | 283 protected: |
284 CFX_ArrayTemplate<uint8_t*> m_Blocks; | 284 CFX_ArrayTemplate<uint8_t*> m_Blocks; |
285 FX_DWORD m_dwCount; | 285 uint32_t m_dwCount; |
286 size_t m_nTotalSize; | 286 size_t m_nTotalSize; |
287 size_t m_nCurSize; | 287 size_t m_nCurSize; |
288 size_t m_nCurPos; | 288 size_t m_nCurPos; |
289 size_t m_nGrowSize; | 289 size_t m_nGrowSize; |
290 FX_DWORD m_dwFlags; | 290 uint32_t m_dwFlags; |
291 FX_BOOL ExpandBlocks(size_t size) { | 291 FX_BOOL ExpandBlocks(size_t size) { |
292 if (m_nCurSize < size) { | 292 if (m_nCurSize < size) { |
293 m_nCurSize = size; | 293 m_nCurSize = size; |
294 } | 294 } |
295 if (size <= m_nTotalSize) { | 295 if (size <= m_nTotalSize) { |
296 return TRUE; | 296 return TRUE; |
297 } | 297 } |
298 int32_t iCount = m_Blocks.GetSize(); | 298 int32_t iCount = m_Blocks.GetSize(); |
299 size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize; | 299 size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize; |
300 m_Blocks.SetSize(m_Blocks.GetSize() + (int32_t)size); | 300 m_Blocks.SetSize(m_Blocks.GetSize() + (int32_t)size); |
(...skipping 12 matching lines...) Expand all Loading... |
313 #define MT_N 848 | 313 #define MT_N 848 |
314 #define MT_M 456 | 314 #define MT_M 456 |
315 #define MT_Matrix_A 0x9908b0df | 315 #define MT_Matrix_A 0x9908b0df |
316 #define MT_Upper_Mask 0x80000000 | 316 #define MT_Upper_Mask 0x80000000 |
317 #define MT_Lower_Mask 0x7fffffff | 317 #define MT_Lower_Mask 0x7fffffff |
318 struct FX_MTRANDOMCONTEXT { | 318 struct FX_MTRANDOMCONTEXT { |
319 FX_MTRANDOMCONTEXT() { | 319 FX_MTRANDOMCONTEXT() { |
320 mti = MT_N + 1; | 320 mti = MT_N + 1; |
321 bHaveSeed = FALSE; | 321 bHaveSeed = FALSE; |
322 } | 322 } |
323 FX_DWORD mti; | 323 uint32_t mti; |
324 FX_BOOL bHaveSeed; | 324 FX_BOOL bHaveSeed; |
325 FX_DWORD mt[MT_N]; | 325 uint32_t mt[MT_N]; |
326 }; | 326 }; |
327 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 327 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
328 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); | 328 FX_BOOL FX_GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount); |
329 #endif | 329 #endif |
330 #ifdef __cplusplus | 330 #ifdef __cplusplus |
331 } | 331 } |
332 #endif | 332 #endif |
333 | 333 |
334 #endif // CORE_FXCRT_EXTENSION_H_ | 334 #endif // CORE_FXCRT_EXTENSION_H_ |
OLD | NEW |