diff options
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/extension.h | 243 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_bstring.cpp | 12 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_util.cpp | 6 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_wstring.cpp | 12 | ||||
-rw-r--r-- | core/fxcrt/fx_bidi.cpp | 2 | ||||
-rw-r--r-- | core/fxcrt/fx_bidi.h | 2 | ||||
-rw-r--r-- | core/fxcrt/fx_extension.cpp | 260 | ||||
-rw-r--r-- | core/fxcrt/fx_xml_parser.cpp | 114 | ||||
-rw-r--r-- | core/fxcrt/include/fx_string.h | 18 | ||||
-rw-r--r-- | core/fxcrt/include/fx_ucd.h | 31 | ||||
-rw-r--r-- | core/fxcrt/include/fx_xml.h | 8 | ||||
-rw-r--r-- | core/fxcrt/xml_int.h | 95 |
12 files changed, 497 insertions, 306 deletions
diff --git a/core/fxcrt/extension.h b/core/fxcrt/extension.h index 877f1ca144..d4fd0931f4 100644 --- a/core/fxcrt/extension.h +++ b/core/fxcrt/extension.h @@ -37,30 +37,16 @@ class IFXCRT_FileAccess { #ifdef PDF_ENABLE_XFA class CFX_CRTFileAccess : public IFX_FileAccess { public: - CFX_CRTFileAccess() : m_RefCount(0) {} + CFX_CRTFileAccess(); + ~CFX_CRTFileAccess() override; // IFX_FileAccess - void Release() override { - if (--m_RefCount == 0) - delete this; - } - - IFX_FileAccess* Retain() override { - m_RefCount++; - return this; - } - - void GetPath(CFX_WideString& wsPath) override { wsPath = m_path; } - - IFX_FileStream* CreateFileStream(uint32_t dwModes) override { - return FX_CreateFileStream(m_path.c_str(), dwModes); - } + void Release() override; + IFX_FileAccess* Retain() override; + void GetPath(CFX_WideString& wsPath) override; + IFX_FileStream* CreateFileStream(uint32_t dwModes) override; - FX_BOOL Init(const CFX_WideStringC& wsPath) { - m_path = wsPath; - m_RefCount = 1; - return TRUE; - } + FX_BOOL Init(const CFX_WideStringC& wsPath); protected: CFX_WideString m_path; @@ -96,190 +82,29 @@ class CFX_CRTFileStream final : public IFX_FileStream { #define FX_MEMSTREAM_TakeOver 0x02 class CFX_MemoryStream final : public IFX_MemoryStream { public: - explicit CFX_MemoryStream(FX_BOOL bConsecutive) - : m_dwCount(1), - m_nTotalSize(0), - m_nCurSize(0), - m_nCurPos(0), - m_nGrowSize(FX_MEMSTREAM_BlockSize) { - m_dwFlags = - FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0); - } - CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, FX_BOOL bTakeOver) - : m_dwCount(1), - m_nTotalSize(nSize), - m_nCurSize(nSize), - m_nCurPos(0), - m_nGrowSize(FX_MEMSTREAM_BlockSize) { - m_Blocks.Add(pBuffer); - m_dwFlags = - FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); - } - ~CFX_MemoryStream() override { - if (m_dwFlags & FX_MEMSTREAM_TakeOver) { - for (int32_t i = 0; i < m_Blocks.GetSize(); i++) { - FX_Free(m_Blocks[i]); - } - } - m_Blocks.RemoveAll(); - } - - // IFX_MemoryStream: - IFX_FileStream* Retain() override { - m_dwCount++; - return this; - } - void Release() override { - uint32_t nCount = --m_dwCount; - if (nCount) { - return; - } - delete this; - } - FX_FILESIZE GetSize() override { return (FX_FILESIZE)m_nCurSize; } - FX_BOOL IsEOF() override { return m_nCurPos >= (size_t)GetSize(); } - FX_FILESIZE GetPosition() override { return (FX_FILESIZE)m_nCurPos; } - FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { - if (!buffer || !size) { - return FALSE; - } + explicit CFX_MemoryStream(FX_BOOL bConsecutive); + CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, FX_BOOL bTakeOver); + ~CFX_MemoryStream() override; - FX_SAFE_SIZE_T newPos = size; - newPos += offset; - if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || - newPos.ValueOrDie() > m_nCurSize) { - return FALSE; - } - - m_nCurPos = newPos.ValueOrDie(); - if (m_dwFlags & FX_MEMSTREAM_Consecutive) { - FXSYS_memcpy(buffer, m_Blocks[0] + (size_t)offset, size); - return TRUE; - } - size_t nStartBlock = (size_t)offset / m_nGrowSize; - offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize); - while (size) { - size_t nRead = m_nGrowSize - (size_t)offset; - if (nRead > size) { - nRead = size; - } - FXSYS_memcpy(buffer, m_Blocks[(int)nStartBlock] + (size_t)offset, nRead); - buffer = ((uint8_t*)buffer) + nRead; - size -= nRead; - nStartBlock++; - offset = 0; - } - return TRUE; - } - size_t ReadBlock(void* buffer, size_t size) override { - if (m_nCurPos >= m_nCurSize) { - return 0; - } - size_t nRead = std::min(size, m_nCurSize - m_nCurPos); - if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) { - return 0; - } - return nRead; - } + // IFX_MemoryStream + IFX_FileStream* Retain() override; + void Release() override; + FX_FILESIZE GetSize() override; + FX_BOOL IsEOF() override; + FX_FILESIZE GetPosition() override; + FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; + size_t ReadBlock(void* buffer, size_t size) override; FX_BOOL WriteBlock(const void* buffer, FX_FILESIZE offset, - size_t size) override { - if (!buffer || !size) { - return FALSE; - } - if (m_dwFlags & FX_MEMSTREAM_Consecutive) { - FX_SAFE_SIZE_T newPos = size; - newPos += offset; - if (!newPos.IsValid()) - return FALSE; - - m_nCurPos = newPos.ValueOrDie(); - if (m_nCurPos > m_nTotalSize) { - m_nTotalSize = - (m_nCurPos + m_nGrowSize - 1) / m_nGrowSize * m_nGrowSize; - if (m_Blocks.GetSize() < 1) { - uint8_t* block = FX_Alloc(uint8_t, m_nTotalSize); - m_Blocks.Add(block); - } else { - m_Blocks[0] = FX_Realloc(uint8_t, m_Blocks[0], m_nTotalSize); - } - if (!m_Blocks[0]) { - m_Blocks.RemoveAll(); - return FALSE; - } - } - FXSYS_memcpy(m_Blocks[0] + (size_t)offset, buffer, size); - if (m_nCurSize < m_nCurPos) { - m_nCurSize = m_nCurPos; - } - return TRUE; - } - - FX_SAFE_SIZE_T newPos = size; - newPos += offset; - if (!newPos.IsValid()) { - return FALSE; - } - - if (!ExpandBlocks(newPos.ValueOrDie())) { - return FALSE; - } - m_nCurPos = newPos.ValueOrDie(); - size_t nStartBlock = (size_t)offset / m_nGrowSize; - offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize); - while (size) { - size_t nWrite = m_nGrowSize - (size_t)offset; - if (nWrite > size) { - nWrite = size; - } - FXSYS_memcpy(m_Blocks[(int)nStartBlock] + (size_t)offset, buffer, nWrite); - buffer = ((uint8_t*)buffer) + nWrite; - size -= nWrite; - nStartBlock++; - offset = 0; - } - return TRUE; - } - FX_BOOL Flush() override { return TRUE; } - FX_BOOL IsConsecutive() const override { - return !!(m_dwFlags & FX_MEMSTREAM_Consecutive); - } - void EstimateSize(size_t nInitSize, size_t nGrowSize) override { - if (m_dwFlags & FX_MEMSTREAM_Consecutive) { - if (m_Blocks.GetSize() < 1) { - uint8_t* pBlock = - FX_Alloc(uint8_t, std::max(nInitSize, static_cast<size_t>(4096))); - m_Blocks.Add(pBlock); - } - m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096)); - } else if (m_Blocks.GetSize() < 1) { - m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096)); - } - } - uint8_t* GetBuffer() const override { - return m_Blocks.GetSize() ? m_Blocks[0] : nullptr; - } + size_t size) override; + FX_BOOL Flush() override; + FX_BOOL IsConsecutive() const override; + void EstimateSize(size_t nInitSize, size_t nGrowSize) override; + uint8_t* GetBuffer() const override; void AttachBuffer(uint8_t* pBuffer, size_t nSize, - FX_BOOL bTakeOver = FALSE) override { - if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { - return; - } - m_Blocks.RemoveAll(); - m_Blocks.Add(pBuffer); - m_nTotalSize = m_nCurSize = nSize; - m_nCurPos = 0; - m_dwFlags = - FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); - } - void DetachBuffer() override { - if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { - return; - } - m_Blocks.RemoveAll(); - m_nTotalSize = m_nCurSize = m_nCurPos = 0; - m_dwFlags = FX_MEMSTREAM_TakeOver; - } + FX_BOOL bTakeOver = FALSE) override; + void DetachBuffer() override; protected: CFX_ArrayTemplate<uint8_t*> m_Blocks; @@ -289,23 +114,7 @@ class CFX_MemoryStream final : public IFX_MemoryStream { size_t m_nCurPos; size_t m_nGrowSize; uint32_t m_dwFlags; - FX_BOOL ExpandBlocks(size_t size) { - if (m_nCurSize < size) { - m_nCurSize = size; - } - if (size <= m_nTotalSize) { - return TRUE; - } - int32_t iCount = m_Blocks.GetSize(); - size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize; - m_Blocks.SetSize(m_Blocks.GetSize() + (int32_t)size); - while (size--) { - uint8_t* pBlock = FX_Alloc(uint8_t, m_nGrowSize); - m_Blocks.SetAt(iCount++, pBlock); - m_nTotalSize += m_nGrowSize; - } - return TRUE; - } + FX_BOOL ExpandBlocks(size_t size); }; #ifdef __cplusplus diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp index 379f1ee882..d0ba1af5ba 100644 --- a/core/fxcrt/fx_basic_bstring.cpp +++ b/core/fxcrt/fx_basic_bstring.cpp @@ -94,11 +94,23 @@ CFX_ByteString::CFX_ByteString(const uint8_t* pStr, FX_STRSIZE nLen) { } } +CFX_ByteString::CFX_ByteString() {} + +CFX_ByteString::CFX_ByteString(const CFX_ByteString& other) + : m_pData(other.m_pData) {} + +CFX_ByteString::CFX_ByteString(CFX_ByteString&& other) { + m_pData.Swap(other.m_pData); +} + CFX_ByteString::CFX_ByteString(char ch) { m_pData.Reset(StringData::Create(1)); m_pData->m_String[0] = ch; } +CFX_ByteString::CFX_ByteString(const FX_CHAR* ptr) + : CFX_ByteString(ptr, ptr ? FXSYS_strlen(ptr) : 0) {} + CFX_ByteString::CFX_ByteString(const CFX_ByteStringC& stringSrc) { if (!stringSrc.IsEmpty()) m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength())); diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp index 8eba2cce0e..b9cf470d08 100644 --- a/core/fxcrt/fx_basic_util.cpp +++ b/core/fxcrt/fx_basic_util.cpp @@ -117,14 +117,16 @@ class CFindFileData { HANDLE m_Handle; FX_BOOL m_bEnd; }; + class CFindFileDataA : public CFindFileData { public: - virtual ~CFindFileDataA() {} + ~CFindFileDataA() override {} WIN32_FIND_DATAA m_FindData; }; + class CFindFileDataW : public CFindFileData { public: - virtual ~CFindFileDataW() {} + ~CFindFileDataW() override {} WIN32_FIND_DATAW m_FindData; }; #endif diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp index ba86823fe2..8837c6bb3b 100644 --- a/core/fxcrt/fx_basic_wstring.cpp +++ b/core/fxcrt/fx_basic_wstring.cpp @@ -63,6 +63,15 @@ const FX_WCHAR* FX_wcsstr(const FX_WCHAR* haystack, static_assert(sizeof(CFX_WideString) <= sizeof(FX_WCHAR*), "Strings must not require more space than pointers"); +CFX_WideString::CFX_WideString() {} + +CFX_WideString::CFX_WideString(const CFX_WideString& other) + : m_pData(other.m_pData) {} + +CFX_WideString::CFX_WideString(CFX_WideString&& other) { + m_pData.Swap(other.m_pData); +} + CFX_WideString::CFX_WideString(const FX_WCHAR* pStr, FX_STRSIZE nLen) { if (nLen < 0) nLen = pStr ? FXSYS_wcslen(pStr) : 0; @@ -76,6 +85,9 @@ CFX_WideString::CFX_WideString(FX_WCHAR ch) { m_pData->m_String[0] = ch; } +CFX_WideString::CFX_WideString(const FX_WCHAR* ptr) + : CFX_WideString(ptr, ptr ? FXSYS_wcslen(ptr) : 0) {} + CFX_WideString::CFX_WideString(const CFX_WideStringC& stringSrc) { if (!stringSrc.IsEmpty()) { m_pData.Reset(StringData::Create(stringSrc.c_str(), stringSrc.GetLength())); diff --git a/core/fxcrt/fx_bidi.cpp b/core/fxcrt/fx_bidi.cpp index d8a8f88a64..f1d162dee9 100644 --- a/core/fxcrt/fx_bidi.cpp +++ b/core/fxcrt/fx_bidi.cpp @@ -73,6 +73,8 @@ CFX_BidiString::CFX_BidiString(const CFX_WideString& str) SetOverallDirectionRight(); } +CFX_BidiString::~CFX_BidiString() {} + void CFX_BidiString::SetOverallDirectionRight() { if (m_eOverallDirection != CFX_BidiChar::RIGHT) { std::reverse(m_Order.begin(), m_Order.end()); diff --git a/core/fxcrt/fx_bidi.h b/core/fxcrt/fx_bidi.h index 309c6f518d..ad5fb27054 100644 --- a/core/fxcrt/fx_bidi.h +++ b/core/fxcrt/fx_bidi.h @@ -49,7 +49,9 @@ class CFX_BidiChar { class CFX_BidiString { public: using const_iterator = std::vector<CFX_BidiChar::Segment>::const_iterator; + explicit CFX_BidiString(const CFX_WideString& str); + ~CFX_BidiString(); // Overall direction is always LEFT or RIGHT, never NEUTRAL. CFX_BidiChar::Direction OverallDirection() const { diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index 1a95e8c318..4c77244b3d 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -16,11 +16,271 @@ #include <ctime> #endif +#ifdef PDF_ENABLE_XFA + +CFX_CRTFileAccess::CFX_CRTFileAccess() : m_RefCount(0) {} + +CFX_CRTFileAccess::~CFX_CRTFileAccess() {} + +void CFX_CRTFileAccess::Release() { + if (--m_RefCount == 0) + delete this; +} + +IFX_FileAccess* CFX_CRTFileAccess::Retain() { + m_RefCount++; + return (IFX_FileAccess*)this; +} + +void CFX_CRTFileAccess::GetPath(CFX_WideString& wsPath) { + wsPath = m_path; +} + +IFX_FileStream* CFX_CRTFileAccess::CreateFileStream(uint32_t dwModes) { + return FX_CreateFileStream(m_path.c_str(), dwModes); +} + +FX_BOOL CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) { + m_path = wsPath; + m_RefCount = 1; + return TRUE; +} + +#endif // PDF_ENABLE_XFA + CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA) : m_pFile(std::move(pFA)), m_dwCount(1) {} CFX_CRTFileStream::~CFX_CRTFileStream() {} +CFX_MemoryStream::CFX_MemoryStream(FX_BOOL bConsecutive) + : m_dwCount(1), + m_nTotalSize(0), + m_nCurSize(0), + m_nCurPos(0), + m_nGrowSize(FX_MEMSTREAM_BlockSize) { + m_dwFlags = + FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0); +} + +CFX_MemoryStream::CFX_MemoryStream(uint8_t* pBuffer, + size_t nSize, + FX_BOOL bTakeOver) + : m_dwCount(1), + m_nTotalSize(nSize), + m_nCurSize(nSize), + m_nCurPos(0), + m_nGrowSize(FX_MEMSTREAM_BlockSize) { + m_Blocks.Add(pBuffer); + m_dwFlags = + FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); +} + +CFX_MemoryStream::~CFX_MemoryStream() { + if (m_dwFlags & FX_MEMSTREAM_TakeOver) { + for (int32_t i = 0; i < m_Blocks.GetSize(); i++) { + FX_Free(m_Blocks[i]); + } + } + m_Blocks.RemoveAll(); +} + +IFX_FileStream* CFX_MemoryStream::Retain() { + m_dwCount++; + return this; +} + +void CFX_MemoryStream::Release() { + uint32_t nCount = --m_dwCount; + if (nCount) { + return; + } + delete this; +} + +FX_FILESIZE CFX_MemoryStream::GetSize() { + return (FX_FILESIZE)m_nCurSize; +} + +FX_BOOL CFX_MemoryStream::IsEOF() { + return m_nCurPos >= (size_t)GetSize(); +} + +FX_FILESIZE CFX_MemoryStream::GetPosition() { + return (FX_FILESIZE)m_nCurPos; +} + +FX_BOOL CFX_MemoryStream::ReadBlock(void* buffer, + FX_FILESIZE offset, + size_t size) { + if (!buffer || !size) { + return FALSE; + } + + FX_SAFE_SIZE_T newPos = size; + newPos += offset; + if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || + newPos.ValueOrDie() > m_nCurSize) { + return FALSE; + } + + m_nCurPos = newPos.ValueOrDie(); + if (m_dwFlags & FX_MEMSTREAM_Consecutive) { + FXSYS_memcpy(buffer, m_Blocks[0] + (size_t)offset, size); + return TRUE; + } + size_t nStartBlock = (size_t)offset / m_nGrowSize; + offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize); + while (size) { + size_t nRead = m_nGrowSize - (size_t)offset; + if (nRead > size) { + nRead = size; + } + FXSYS_memcpy(buffer, m_Blocks[(int)nStartBlock] + (size_t)offset, nRead); + buffer = ((uint8_t*)buffer) + nRead; + size -= nRead; + nStartBlock++; + offset = 0; + } + return TRUE; +} + +size_t CFX_MemoryStream::ReadBlock(void* buffer, size_t size) { + if (m_nCurPos >= m_nCurSize) { + return 0; + } + size_t nRead = std::min(size, m_nCurSize - m_nCurPos); + if (!ReadBlock(buffer, (int32_t)m_nCurPos, nRead)) { + return 0; + } + return nRead; +} + +FX_BOOL CFX_MemoryStream::WriteBlock(const void* buffer, + FX_FILESIZE offset, + size_t size) { + if (!buffer || !size) { + return FALSE; + } + if (m_dwFlags & FX_MEMSTREAM_Consecutive) { + FX_SAFE_SIZE_T newPos = size; + newPos += offset; + if (!newPos.IsValid()) + return FALSE; + + m_nCurPos = newPos.ValueOrDie(); + if (m_nCurPos > m_nTotalSize) { + m_nTotalSize = (m_nCurPos + m_nGrowSize - 1) / m_nGrowSize * m_nGrowSize; + if (m_Blocks.GetSize() < 1) { + uint8_t* block = FX_Alloc(uint8_t, m_nTotalSize); + m_Blocks.Add(block); + } else { + m_Blocks[0] = FX_Realloc(uint8_t, m_Blocks[0], m_nTotalSize); + } + if (!m_Blocks[0]) { + m_Blocks.RemoveAll(); + return FALSE; + } + } + FXSYS_memcpy(m_Blocks[0] + (size_t)offset, buffer, size); + if (m_nCurSize < m_nCurPos) { + m_nCurSize = m_nCurPos; + } + return TRUE; + } + + FX_SAFE_SIZE_T newPos = size; + newPos += offset; + if (!newPos.IsValid()) { + return FALSE; + } + + if (!ExpandBlocks(newPos.ValueOrDie())) { + return FALSE; + } + m_nCurPos = newPos.ValueOrDie(); + size_t nStartBlock = (size_t)offset / m_nGrowSize; + offset -= (FX_FILESIZE)(nStartBlock * m_nGrowSize); + while (size) { + size_t nWrite = m_nGrowSize - (size_t)offset; + if (nWrite > size) { + nWrite = size; + } + FXSYS_memcpy(m_Blocks[(int)nStartBlock] + (size_t)offset, buffer, nWrite); + buffer = ((uint8_t*)buffer) + nWrite; + size -= nWrite; + nStartBlock++; + offset = 0; + } + return TRUE; +} + +FX_BOOL CFX_MemoryStream::Flush() { + return TRUE; +} + +FX_BOOL CFX_MemoryStream::IsConsecutive() const { + return !!(m_dwFlags & FX_MEMSTREAM_Consecutive); +} + +void CFX_MemoryStream::EstimateSize(size_t nInitSize, size_t nGrowSize) { + if (m_dwFlags & FX_MEMSTREAM_Consecutive) { + if (m_Blocks.GetSize() < 1) { + uint8_t* pBlock = + FX_Alloc(uint8_t, std::max(nInitSize, static_cast<size_t>(4096))); + m_Blocks.Add(pBlock); + } + m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096)); + } else if (m_Blocks.GetSize() < 1) { + m_nGrowSize = std::max(nGrowSize, static_cast<size_t>(4096)); + } +} + +uint8_t* CFX_MemoryStream::GetBuffer() const { + return m_Blocks.GetSize() ? m_Blocks[0] : nullptr; +} + +void CFX_MemoryStream::AttachBuffer(uint8_t* pBuffer, + size_t nSize, + FX_BOOL bTakeOver) { + if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { + return; + } + m_Blocks.RemoveAll(); + m_Blocks.Add(pBuffer); + m_nTotalSize = m_nCurSize = nSize; + m_nCurPos = 0; + m_dwFlags = + FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); +} + +void CFX_MemoryStream::DetachBuffer() { + if (!(m_dwFlags & FX_MEMSTREAM_Consecutive)) { + return; + } + m_Blocks.RemoveAll(); + m_nTotalSize = m_nCurSize = m_nCurPos = 0; + m_dwFlags = FX_MEMSTREAM_TakeOver; +} + +FX_BOOL CFX_MemoryStream::ExpandBlocks(size_t size) { + if (m_nCurSize < size) { + m_nCurSize = size; + } + if (size <= m_nTotalSize) { + return TRUE; + } + int32_t iCount = m_Blocks.GetSize(); + size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize; + m_Blocks.SetSize(m_Blocks.GetSize() + (int32_t)size); + while (size--) { + uint8_t* pBlock = FX_Alloc(uint8_t, m_nGrowSize); + m_Blocks.SetAt(iCount++, pBlock); + m_nTotalSize += m_nGrowSize; + } + return TRUE; +} + IFX_FileStream* CFX_CRTFileStream::Retain() { m_dwCount++; return this; diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp index 6017bd8fda..9412cdde04 100644 --- a/core/fxcrt/fx_xml_parser.cpp +++ b/core/fxcrt/fx_xml_parser.cpp @@ -12,11 +12,121 @@ #include "core/fxcrt/include/fx_xml.h" #include "third_party/base/stl_util.h" +CXML_DataBufAcc::CXML_DataBufAcc(const uint8_t* pBuffer, size_t size) + : m_pBuffer(pBuffer), m_dwSize(size), m_dwCurPos(0) {} + +CXML_DataBufAcc::~CXML_DataBufAcc() {} + +void CXML_DataBufAcc::Release() { + delete this; +} + +FX_BOOL CXML_DataBufAcc::IsEOF() { + return m_dwCurPos >= m_dwSize; +} + +FX_FILESIZE CXML_DataBufAcc::GetPosition() { + return (FX_FILESIZE)m_dwCurPos; +} + +size_t CXML_DataBufAcc::ReadBlock(void* buffer, size_t size) { + return 0; +} + +FX_BOOL CXML_DataBufAcc::ReadNextBlock(FX_BOOL bRestart) { + if (bRestart) { + m_dwCurPos = 0; + } + if (m_dwCurPos < m_dwSize) { + m_dwCurPos = m_dwSize; + return TRUE; + } + return FALSE; +} + +const uint8_t* CXML_DataBufAcc::GetBlockBuffer() { + return m_pBuffer; +} + +size_t CXML_DataBufAcc::GetBlockSize() { + return m_dwSize; +} + +FX_FILESIZE CXML_DataBufAcc::GetBlockOffset() { + return 0; +} + +CXML_DataStmAcc::CXML_DataStmAcc(IFX_FileRead* pFileRead) + : m_pFileRead(pFileRead), m_pBuffer(nullptr), m_nStart(0), m_dwSize(0) { + ASSERT(m_pFileRead); +} + +CXML_DataStmAcc::~CXML_DataStmAcc() { + FX_Free(m_pBuffer); +} + +void CXML_DataStmAcc::Release() { + delete this; +} + +FX_BOOL CXML_DataStmAcc::IsEOF() { + return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize(); +} + +FX_FILESIZE CXML_DataStmAcc::GetPosition() { + return m_nStart + (FX_FILESIZE)m_dwSize; +} + +size_t CXML_DataStmAcc::ReadBlock(void* buffer, size_t size) { + return 0; +} + +FX_BOOL CXML_DataStmAcc::ReadNextBlock(FX_BOOL bRestart) { + if (bRestart) { + m_nStart = 0; + } + FX_FILESIZE nLength = m_pFileRead->GetSize(); + m_nStart += (FX_FILESIZE)m_dwSize; + if (m_nStart >= nLength) { + return FALSE; + } + static const FX_FILESIZE FX_XMLDATASTREAM_BufferSize = 32 * 1024; + m_dwSize = static_cast<size_t>( + std::min(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart)); + if (!m_pBuffer) { + m_pBuffer = FX_Alloc(uint8_t, m_dwSize); + } + return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize); +} + +const uint8_t* CXML_DataStmAcc::GetBlockBuffer() { + return (const uint8_t*)m_pBuffer; +} + +size_t CXML_DataStmAcc::GetBlockSize() { + return m_dwSize; +} + +FX_FILESIZE CXML_DataStmAcc::GetBlockOffset() { + return m_nStart; +} + +CXML_Parser::CXML_Parser() + : m_pDataAcc(nullptr), + m_bOwnedStream(FALSE), + m_nOffset(0), + m_bSaveSpaceChars(FALSE), + m_pBuffer(nullptr), + m_dwBufferSize(0), + m_nBufferOffset(0), + m_dwIndex(0) {} + CXML_Parser::~CXML_Parser() { if (m_bOwnedStream) { m_pDataAcc->Release(); } } + FX_BOOL CXML_Parser::Init(uint8_t* pBuffer, size_t size) { m_pDataAcc = new CXML_DataBufAcc(pBuffer, size); return Init(TRUE); @@ -764,6 +874,10 @@ bool CXML_AttrItem::Matches(const CFX_ByteString& space, return (space.IsEmpty() || m_QSpaceName == space) && m_AttrName == name; } +CXML_AttrMap::CXML_AttrMap() {} + +CXML_AttrMap::~CXML_AttrMap() {} + const CFX_WideString* CXML_AttrMap::Lookup(const CFX_ByteString& space, const CFX_ByteString& name) const { if (!m_pMap) diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h index 142f9372d0..b0a89fd06c 100644 --- a/core/fxcrt/include/fx_string.h +++ b/core/fxcrt/include/fx_string.h @@ -34,14 +34,13 @@ class CFX_ByteString { public: using CharType = FX_CHAR; - CFX_ByteString() {} - CFX_ByteString(const CFX_ByteString& other) : m_pData(other.m_pData) {} - CFX_ByteString(CFX_ByteString&& other) { m_pData.Swap(other.m_pData); } + CFX_ByteString(); + CFX_ByteString(const CFX_ByteString& other); + CFX_ByteString(CFX_ByteString&& other); // Deliberately implicit to avoid calling on every string literal. CFX_ByteString(char ch); - CFX_ByteString(const FX_CHAR* ptr) - : CFX_ByteString(ptr, ptr ? FXSYS_strlen(ptr) : 0) {} + CFX_ByteString(const FX_CHAR* ptr); CFX_ByteString(const FX_CHAR* ptr, FX_STRSIZE len); CFX_ByteString(const uint8_t* ptr, FX_STRSIZE len); @@ -238,14 +237,13 @@ class CFX_WideString { public: using CharType = FX_WCHAR; - CFX_WideString() {} - CFX_WideString(const CFX_WideString& other) : m_pData(other.m_pData) {} - CFX_WideString(CFX_WideString&& other) { m_pData.Swap(other.m_pData); } + CFX_WideString(); + CFX_WideString(const CFX_WideString& other); + CFX_WideString(CFX_WideString&& other); // Deliberately implicit to avoid calling on every string literal. CFX_WideString(FX_WCHAR ch); - CFX_WideString(const FX_WCHAR* ptr) - : CFX_WideString(ptr, ptr ? FXSYS_wcslen(ptr) : 0) {} + CFX_WideString(const FX_WCHAR* ptr); CFX_WideString(const FX_WCHAR* ptr, FX_STRSIZE len); diff --git a/core/fxcrt/include/fx_ucd.h b/core/fxcrt/include/fx_ucd.h index c2c4688628..eeecd39cbf 100644 --- a/core/fxcrt/include/fx_ucd.h +++ b/core/fxcrt/include/fx_ucd.h @@ -152,8 +152,7 @@ typedef CFX_ArrayTemplate<CFX_Char> CFX_CharArray; class CFX_TxtChar : public CFX_Char { public: CFX_TxtChar() - : CFX_Char(), - m_dwStatus(0), + : m_dwStatus(0), m_iBidiClass(0), m_iBidiLevel(0), m_iBidiPos(0), @@ -169,17 +168,9 @@ class CFX_TxtChar : public CFX_Char { 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(nullptr) {} + CFX_RTFChar(); + CFX_RTFChar(const CFX_RTFChar& other); + uint32_t m_dwStatus; int32_t m_iFontSize; int32_t m_iFontHeight; @@ -191,6 +182,20 @@ class CFX_RTFChar : public CFX_Char { uint32_t m_dwIdentity; IFX_Retainable* m_pUserData; }; + +inline CFX_RTFChar::CFX_RTFChar() + : 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(nullptr) {} + +inline CFX_RTFChar::CFX_RTFChar(const CFX_RTFChar& other) = default; + typedef CFX_ArrayTemplate<CFX_RTFChar> CFX_RTFCharArray; #endif // PDF_ENABLE_XFA diff --git a/core/fxcrt/include/fx_xml.h b/core/fxcrt/include/fx_xml.h index 0e8c82b103..4db4998c32 100644 --- a/core/fxcrt/include/fx_xml.h +++ b/core/fxcrt/include/fx_xml.h @@ -23,13 +23,17 @@ class CXML_AttrItem { class CXML_AttrMap { public: + CXML_AttrMap(); + ~CXML_AttrMap(); + const CFX_WideString* Lookup(const CFX_ByteString& space, const CFX_ByteString& name) const; + int GetSize() const; + CXML_AttrItem& GetAt(int index) const; + void SetAt(const CFX_ByteString& space, const CFX_ByteString& name, const CFX_WideString& value); - int GetSize() const; - CXML_AttrItem& GetAt(int index) const; std::unique_ptr<std::vector<CXML_AttrItem>> m_pMap; }; diff --git a/core/fxcrt/xml_int.h b/core/fxcrt/xml_int.h index 6d3db4f525..121441b0c4 100644 --- a/core/fxcrt/xml_int.h +++ b/core/fxcrt/xml_int.h @@ -16,28 +16,18 @@ class CXML_Element; class CXML_DataBufAcc : public IFX_BufferRead { public: - CXML_DataBufAcc(const uint8_t* pBuffer, size_t size) - : m_pBuffer(pBuffer), m_dwSize(size), m_dwCurPos(0) {} - ~CXML_DataBufAcc() override {} + CXML_DataBufAcc(const uint8_t* pBuffer, size_t size); + ~CXML_DataBufAcc() override; // IFX_BufferRead - void Release() override { delete this; } - FX_BOOL IsEOF() override { return m_dwCurPos >= m_dwSize; } - FX_FILESIZE GetPosition() override { return (FX_FILESIZE)m_dwCurPos; } - size_t ReadBlock(void* buffer, size_t size) override { return 0; } - FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) override { - if (bRestart) { - m_dwCurPos = 0; - } - if (m_dwCurPos < m_dwSize) { - m_dwCurPos = m_dwSize; - return TRUE; - } - return FALSE; - } - const uint8_t* GetBlockBuffer() override { return m_pBuffer; } - size_t GetBlockSize() override { return m_dwSize; } - FX_FILESIZE GetBlockOffset() override { return 0; } + void Release() override; + FX_BOOL IsEOF() override; + FX_FILESIZE GetPosition() override; + size_t ReadBlock(void* buffer, size_t size) override; + FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) override; + const uint8_t* GetBlockBuffer() override; + size_t GetBlockSize() override; + FX_FILESIZE GetBlockOffset() override; protected: const uint8_t* m_pBuffer; @@ -47,40 +37,18 @@ class CXML_DataBufAcc : public IFX_BufferRead { class CXML_DataStmAcc : public IFX_BufferRead { public: - explicit CXML_DataStmAcc(IFX_FileRead* pFileRead) - : m_pFileRead(pFileRead), m_pBuffer(nullptr), m_nStart(0), m_dwSize(0) { - ASSERT(m_pFileRead); - } - ~CXML_DataStmAcc() override { FX_Free(m_pBuffer); } - - void Release() override { delete this; } - FX_BOOL IsEOF() override { - return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize(); - } - FX_FILESIZE GetPosition() override { - return m_nStart + (FX_FILESIZE)m_dwSize; - } - size_t ReadBlock(void* buffer, size_t size) override { return 0; } - FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) override { - if (bRestart) { - m_nStart = 0; - } - FX_FILESIZE nLength = m_pFileRead->GetSize(); - m_nStart += (FX_FILESIZE)m_dwSize; - if (m_nStart >= nLength) { - return FALSE; - } - static const FX_FILESIZE FX_XMLDATASTREAM_BufferSize = 32 * 1024; - m_dwSize = static_cast<size_t>( - std::min(FX_XMLDATASTREAM_BufferSize, nLength - m_nStart)); - if (!m_pBuffer) { - m_pBuffer = FX_Alloc(uint8_t, m_dwSize); - } - return m_pFileRead->ReadBlock(m_pBuffer, m_nStart, m_dwSize); - } - const uint8_t* GetBlockBuffer() override { return (const uint8_t*)m_pBuffer; } - size_t GetBlockSize() override { return m_dwSize; } - FX_FILESIZE GetBlockOffset() override { return m_nStart; } + explicit CXML_DataStmAcc(IFX_FileRead* pFileRead); + ~CXML_DataStmAcc() override; + + // IFX_BufferRead + void Release() override; + FX_BOOL IsEOF() override; + FX_FILESIZE GetPosition() override; + size_t ReadBlock(void* buffer, size_t size) override; + FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) override; + const uint8_t* GetBlockBuffer() override; + size_t GetBlockSize() override; + FX_FILESIZE GetBlockOffset() override; protected: IFX_FileRead* m_pFileRead; @@ -91,15 +59,9 @@ class CXML_DataStmAcc : public IFX_BufferRead { class CXML_Parser { public: + CXML_Parser(); ~CXML_Parser(); - IFX_BufferRead* m_pDataAcc; - FX_BOOL m_bOwnedStream; - FX_FILESIZE m_nOffset; - FX_BOOL m_bSaveSpaceChars; - const uint8_t* m_pBuffer; - size_t m_dwBufferSize; - FX_FILESIZE m_nBufferOffset; - size_t m_dwIndex; + FX_BOOL Init(uint8_t* pBuffer, size_t size); FX_BOOL Init(IFX_FileRead* pFileRead); FX_BOOL Init(IFX_BufferRead* pBuffer); @@ -121,6 +83,15 @@ class CXML_Parser { const CFX_WideStringC& content, CXML_Element* pElement); void InsertCDATASegment(CFX_UTF8Decoder& decoder, CXML_Element* pElement); + + IFX_BufferRead* m_pDataAcc; + FX_BOOL m_bOwnedStream; + FX_FILESIZE m_nOffset; + FX_BOOL m_bSaveSpaceChars; + const uint8_t* m_pBuffer; + size_t m_dwBufferSize; + FX_FILESIZE m_nBufferOffset; + size_t m_dwIndex; }; void FX_XML_SplitQualifiedName(const CFX_ByteStringC& bsFullName, |