summaryrefslogtreecommitdiff
path: root/core/include/fxcrt
diff options
context:
space:
mode:
Diffstat (limited to 'core/include/fxcrt')
-rw-r--r--core/include/fxcrt/fx_basic.h3284
-rw-r--r--core/include/fxcrt/fx_coordinates.h1800
-rw-r--r--core/include/fxcrt/fx_ext.h206
-rw-r--r--core/include/fxcrt/fx_memory.h600
-rw-r--r--core/include/fxcrt/fx_stream.h400
-rw-r--r--core/include/fxcrt/fx_string.h1740
-rw-r--r--core/include/fxcrt/fx_system.h558
-rw-r--r--core/include/fxcrt/fx_xml.h418
8 files changed, 4503 insertions, 4503 deletions
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 29bc221e5b..378d6c30a8 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -1,1642 +1,1642 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FX_BASIC_H_
-#define _FX_BASIC_H_
-#ifndef _FX_SYSTEM_H_
-#include "fx_system.h"
-#endif
-#ifndef _FX_MEMORY_H_
-#include "fx_memory.h"
-#endif
-#ifndef _FX_STRING_H_
-#include "fx_string.h"
-#endif
-#ifndef _FX_STREAM_H_
-#include "fx_stream.h"
-#endif
-class CFX_BinaryBuf : public CFX_Object
-{
-public:
-
- CFX_BinaryBuf(IFX_Allocator* pAllocator = NULL);
-
- CFX_BinaryBuf(FX_STRSIZE size, IFX_Allocator* pAllocator = NULL);
-
- ~CFX_BinaryBuf();
-
- void Clear();
-
- void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0);
-
- void AppendBlock(const void* pBuf, FX_STRSIZE size);
-
- void AppendFill(FX_BYTE byte, FX_STRSIZE count);
-
- void AppendString(FX_BSTR str)
- {
- AppendBlock(str.GetPtr(), str.GetLength());
- }
-
- inline void AppendByte(FX_BYTE 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 AttachData(void* pBuf, FX_STRSIZE size);
-
- void CopyData(const void* pBuf, FX_STRSIZE size);
-
- void TakeOver(CFX_BinaryBuf& other);
-
- void Delete(int start_index, int count);
-
- FX_LPBYTE GetBuffer() const
- {
- return m_pBuffer;
- }
-
- FX_STRSIZE GetSize() const
- {
- return m_DataSize;
- }
-
- CFX_ByteStringC GetByteString() const;
- void GetByteStringL(CFX_ByteStringL &str) const;
-
- void DetachBuffer();
-
- IFX_Allocator* m_pAllocator;
-protected:
-
- FX_STRSIZE m_AllocStep;
-
- FX_LPBYTE m_pBuffer;
-
- FX_STRSIZE m_DataSize;
-
- FX_STRSIZE m_AllocSize;
-
- void ExpandBuf(FX_STRSIZE size);
-};
-class CFX_ByteTextBuf : public CFX_BinaryBuf
-{
-public:
-
- CFX_ByteTextBuf(IFX_Allocator* pAllocator = NULL) : CFX_BinaryBuf(pAllocator) {}
-
- void operator = (FX_BSTR str);
-
- void AppendChar(int ch)
- {
- AppendByte((FX_BYTE)ch);
- }
-
- CFX_ByteTextBuf& operator << (int i);
-
- CFX_ByteTextBuf& operator << (FX_DWORD i);
-
- CFX_ByteTextBuf& operator << (double f);
-
- CFX_ByteTextBuf& operator << (FX_BSTR lpsz);
-
- CFX_ByteTextBuf& operator << (const CFX_ByteTextBuf& buf);
-
- FX_STRSIZE GetLength() const
- {
- return m_DataSize;
- }
-};
-class CFX_WideTextBuf : public CFX_BinaryBuf
-{
-public:
-
- CFX_WideTextBuf(IFX_Allocator* pAllocator = NULL) : CFX_BinaryBuf(pAllocator) {}
-
- void operator = (FX_LPCWSTR lpsz);
-
- void operator = (FX_WSTR str);
-
- void AppendChar(FX_WCHAR wch);
-
- CFX_WideTextBuf& operator << (int i);
-
- CFX_WideTextBuf& operator << (double f);
-
- CFX_WideTextBuf& operator << (FX_LPCWSTR lpsz);
-
- CFX_WideTextBuf& operator << (FX_WSTR str);
- CFX_WideTextBuf& operator << (const CFX_WideString &str);
-
- CFX_WideTextBuf& operator << (const CFX_WideTextBuf& buf);
-
- FX_STRSIZE GetLength() const
- {
- return m_DataSize / sizeof(FX_WCHAR);
- }
-
- FX_LPWSTR GetBuffer() const
- {
- return (FX_LPWSTR)m_pBuffer;
- }
-
- void Delete(int start_index, int count)
- {
- CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), count * sizeof(FX_WCHAR));
- }
-
- CFX_WideStringC GetWideString() const;
- void GetWideStringL(CFX_WideStringL& wideText) const;
-};
-class CFX_ArchiveSaver : public CFX_Object
-{
-public:
-
- CFX_ArchiveSaver(IFX_Allocator* pAllocator = NULL) : m_SavingBuf(pAllocator), m_pStream(NULL) {}
-
- CFX_ArchiveSaver& operator << (FX_BYTE i);
-
- CFX_ArchiveSaver& operator << (int i);
-
- CFX_ArchiveSaver& operator << (FX_DWORD i);
-
- CFX_ArchiveSaver& operator << (FX_FLOAT i);
-
- CFX_ArchiveSaver& operator << (double i);
-
- CFX_ArchiveSaver& operator << (FX_BSTR bstr);
-
- CFX_ArchiveSaver& operator << (FX_LPCWSTR bstr);
-
- CFX_ArchiveSaver& operator << (const CFX_WideString& wstr);
-
- void Write(const void* pData, FX_STRSIZE dwSize);
-
- FX_INTPTR GetLength()
- {
- return m_SavingBuf.GetSize();
- }
-
- FX_LPCBYTE GetBuffer()
- {
- return m_SavingBuf.GetBuffer();
- }
-
- void SetStream(IFX_FileStream* pStream)
- {
- m_pStream = pStream;
- }
-protected:
-
- CFX_BinaryBuf m_SavingBuf;
-
- IFX_FileStream* m_pStream;
-};
-class CFX_ArchiveLoader : public CFX_Object
-{
-public:
-
- CFX_ArchiveLoader(FX_LPCBYTE pData, FX_DWORD dwSize);
-
- CFX_ArchiveLoader& operator >> (FX_BYTE& i);
-
- CFX_ArchiveLoader& operator >> (int& i);
-
- CFX_ArchiveLoader& operator >> (FX_DWORD& i);
-
- CFX_ArchiveLoader& operator >> (FX_FLOAT& i);
-
- CFX_ArchiveLoader& operator >> (double& i);
-
- CFX_ArchiveLoader& operator >> (CFX_ByteString& bstr);
-
- CFX_ArchiveLoader& operator >> (CFX_WideString& wstr);
-
- FX_BOOL IsEOF();
-
- FX_BOOL Read(void* pBuf, FX_DWORD dwSize);
-protected:
-
- FX_DWORD m_LoadingPos;
-
- FX_LPCBYTE m_pLoadingBuf;
-
- FX_DWORD m_LoadingSize;
-};
-class IFX_BufferArchive
-{
-public:
-
- IFX_BufferArchive(FX_STRSIZE size, IFX_Allocator* pAllocator = NULL);
-
-
- virtual void Clear();
-
-
- FX_BOOL Flush();
-
-
- FX_INT32 AppendBlock(const void* pBuf, size_t size);
-
- FX_INT32 AppendByte(FX_BYTE byte);
-
- FX_INT32 AppendDWord(FX_DWORD i);
-
-
- FX_INT32 AppendString(FX_BSTR lpsz);
-
-protected:
-
- virtual FX_BOOL DoWork(const void* pBuf, size_t size) = 0;
-
-
- IFX_Allocator* m_pAllocator;
-
- FX_STRSIZE m_BufSize;
-
- FX_LPBYTE m_pBuffer;
-
- FX_STRSIZE m_Length;
-};
-class CFX_FileBufferArchive : public IFX_BufferArchive, public CFX_Object
-{
-public:
- CFX_FileBufferArchive(FX_STRSIZE size = 32768, IFX_Allocator* pAllocator = NULL);
- ~CFX_FileBufferArchive();
- virtual void Clear();
-
- FX_BOOL AttachFile(IFX_StreamWrite *pFile, FX_BOOL bTakeover = FALSE);
-
- FX_BOOL AttachFile(FX_LPCWSTR filename);
-
- FX_BOOL AttachFile(FX_LPCSTR filename);
-private:
-
- virtual FX_BOOL DoWork(const void* pBuf, size_t size);
-
- IFX_StreamWrite *m_pFile;
-
- FX_BOOL m_bTakeover;
-};
-struct CFX_CharMap {
-
- static CFX_CharMap* GetDefaultMapper(FX_INT32 codepage = 0);
-
-
- CFX_WideString (*m_GetWideString)(CFX_CharMap* pMap, const CFX_ByteString& bstr);
-
- CFX_ByteString (*m_GetByteString)(CFX_CharMap* pMap, const CFX_WideString& wstr);
-
- FX_INT32 (*m_GetCodePage)();
-};
-class CFX_UTF8Decoder
-{
-public:
-
- CFX_UTF8Decoder(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator)
- {
- m_PendingBytes = 0;
- }
-
- void Clear();
-
- void Input(FX_BYTE byte);
-
- void AppendChar(FX_DWORD ch);
-
- void ClearStatus()
- {
- m_PendingBytes = 0;
- }
-
- CFX_WideStringC GetResult() const
- {
- return m_Buffer.GetWideString();
- }
- void GetResult(CFX_WideStringL &result) const
- {
- m_Buffer.GetWideStringL(result);
- }
-protected:
-
- int m_PendingBytes;
-
- FX_DWORD m_PendingChar;
-
- CFX_WideTextBuf m_Buffer;
-};
-class CFX_UTF8Encoder
-{
-public:
-
- CFX_UTF8Encoder(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator)
- {
- m_UTF16First = 0;
- }
-
- void Input(FX_WCHAR unicode);
-
- void AppendStr(FX_BSTR str)
- {
- m_UTF16First = 0;
- m_Buffer << str;
- }
-
- CFX_ByteStringC GetResult() const
- {
- return m_Buffer.GetByteString();
- }
- void GetResult(CFX_ByteStringL &result) const
- {
- m_Buffer.GetByteStringL(result);
- }
-protected:
-
- CFX_ByteTextBuf m_Buffer;
-
- 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 : public CFX_Object
-{
-public:
-
- IFX_Allocator* m_pAllocator;
-protected:
-
- CFX_BasicArray(int unit_size, IFX_Allocator* pAllocator = NULL);
-
- ~CFX_BasicArray();
-
- FX_BOOL SetSize(int nNewSize, int nGrowBy);
-
- FX_BOOL Append(const CFX_BasicArray& src);
-
- FX_BOOL Copy(const CFX_BasicArray& src);
-
- FX_LPBYTE InsertSpaceAt(int nIndex, int nCount);
-
- FX_BOOL RemoveAt(int nIndex, int nCount);
-
- FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray);
-
- const void* GetDataPtr(int index) const;
-protected:
-
- FX_LPBYTE m_pData;
-
- int m_nSize;
-
- int m_nMaxSize;
-
- int m_nGrowBy;
-
- int m_nUnitSize;
-};
-template<class TYPE>
-class CFX_ArrayTemplate : public CFX_BasicArray
-{
-public:
-
- CFX_ArrayTemplate(IFX_Allocator* pAllocator = NULL) : CFX_BasicArray(sizeof(TYPE), pAllocator) {}
-
- int GetSize() const
- {
- return m_nSize;
- }
-
- int GetUpperBound() const
- {
- return m_nSize - 1;
- }
-
- FX_BOOL SetSize(int nNewSize, int nGrowBy = -1)
- {
- return CFX_BasicArray::SetSize(nNewSize, nGrowBy);
- }
-
- void RemoveAll()
- {
- SetSize(0, -1);
- }
-
- 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];
- }
-
- FX_BOOL SetAt(int nIndex, TYPE newElement)
- {
- if (nIndex < 0 || nIndex >= m_nSize) {
- return FALSE;
- }
- ((TYPE*)m_pData)[nIndex] = newElement;
- return TRUE;
- }
-
- TYPE& ElementAt(int nIndex)
- {
- if (nIndex < 0 || nIndex >= m_nSize) {
- return *(TYPE*)NULL;
- }
- return ((TYPE*)m_pData)[nIndex];
- }
-
- const TYPE* GetData() const
- {
- return (const TYPE*)m_pData;
- }
-
- TYPE* GetData()
- {
- return (TYPE*)m_pData;
- }
-
- FX_BOOL SetAtGrow(int nIndex, TYPE newElement)
- {
- if (nIndex < 0) {
- return FALSE;
- }
- if (nIndex >= m_nSize)
- if (!SetSize(nIndex + 1, -1)) {
- return FALSE;
- }
- ((TYPE*)m_pData)[nIndex] = newElement;
- return TRUE;
- }
-
- FX_BOOL Add(TYPE newElement)
- {
- if (m_nSize < m_nMaxSize) {
- m_nSize ++;
- } else if (!SetSize(m_nSize + 1, -1)) {
- return FALSE;
- }
- ((TYPE*)m_pData)[m_nSize - 1] = newElement;
- return TRUE;
- }
-
- FX_BOOL Append(const CFX_ArrayTemplate& src)
- {
- return CFX_BasicArray::Append(src);
- }
-
- FX_BOOL Copy(const CFX_ArrayTemplate& src)
- {
- return CFX_BasicArray::Copy(src);
- }
-
- TYPE* GetDataPtr(int index)
- {
- return (TYPE*)CFX_BasicArray::GetDataPtr(index);
- }
-
- TYPE* AddSpace()
- {
- return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1);
- }
-
- TYPE* InsertSpaceAt(int nIndex, int nCount)
- {
- return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount);
- }
-
- const TYPE operator[](int nIndex) const
- {
- if (nIndex < 0 || nIndex >= m_nSize) {
- *(volatile char*)0 = '\0';
- }
- return ((const TYPE*)m_pData)[nIndex];
- }
-
- TYPE& operator[](int nIndex)
- {
- if (nIndex < 0 || nIndex >= m_nSize) {
- *(volatile char*)0 = '\0';
- }
- return ((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;
- }
-
- 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<FX_BYTE> 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<FX_INT32> CFX_Int32Array;
-template <class ObjectClass>
-class CFX_ObjectArray : public CFX_BasicArray
-{
-public:
-
- CFX_ObjectArray(IFX_Allocator* pAllocator = NULL) : CFX_BasicArray(sizeof(ObjectClass), pAllocator) {}
-
- ~CFX_ObjectArray()
- {
- RemoveAll();
- }
-
- void Add(const ObjectClass& data)
- {
- new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data);
- }
-
- ObjectClass& Add()
- {
- return *(ObjectClass*) new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass();
- }
-
- void* AddSpace()
- {
- return InsertSpaceAt(m_nSize, 1);
- }
-
- FX_INT32 Append(const CFX_ObjectArray& src, FX_INT32 nStart = 0, FX_INT32 nCount = -1)
- {
- if (nCount == 0) {
- return 0;
- }
- FX_INT32 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 (FX_INT32 i = nStart; i < nSize; i ++, pStartObj++) {
- new ((void*)pStartObj) ObjectClass(src[i]);
- }
- return nCount;
- }
-
- FX_INT32 Copy(const CFX_ObjectArray& src, FX_INT32 nStart = 0, FX_INT32 nCount = -1)
- {
- if (nCount == 0) {
- return 0;
- }
- FX_INT32 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, -1);
- ObjectClass* pStartObj = (ObjectClass*)m_pData;
- nSize = nStart + nCount;
- for (FX_INT32 i = nStart; i < nSize; i ++, pStartObj++) {
- new ((void*)pStartObj) ObjectClass(src[i]);
- }
- return nCount;
- }
-
- 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, -1);
- }
-};
-typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray;
-typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray;
-class CFX_BaseSegmentedArray : public CFX_Object
-{
-public:
-
- CFX_BaseSegmentedArray(int unit_size = 1, int segment_units = 512, int index_size = 8, IFX_Allocator* pAllocator = NULL);
-
- ~CFX_BaseSegmentedArray();
-
- void SetUnitSize(int unit_size, int segment_units, int index_size = 8);
-
- void* Add();
-
- void* GetAt(int index) const;
-
- void RemoveAll();
-
- void Delete(int index, int count = 1);
-
- int GetSize() const
- {
- return m_DataSize;
- }
-
- int GetSegmentSize() const
- {
- return m_SegmentSize;
- }
-
- int GetUnitSize() const
- {
- return m_UnitSize;
- }
-
- void* Iterate(FX_BOOL (*callback)(void* param, void* pData), void* param) const;
-
- IFX_Allocator* m_pAllocator;
-private:
-
- int m_UnitSize;
-
- short m_SegmentSize;
-
- FX_BYTE m_IndexSize;
-
- FX_BYTE m_IndexDepth;
-
- 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(FX_LPCBYTE 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, IFX_Allocator* pAllocator = NULL)
- : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size, pAllocator)
- {}
-
- 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_Object
-{
-public:
- CFX_FixedBufGrow(IFX_Allocator* pAllocator = NULL)
- : m_pAllocator(pAllocator)
- , m_pData(NULL)
- {}
- CFX_FixedBufGrow(int data_size, IFX_Allocator* pAllocator = NULL)
- : m_pAllocator(pAllocator)
- , m_pData(NULL)
- {
- if (data_size > FixedSize) {
- m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, data_size);
- } else {
- FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize);
- }
- }
- void SetDataSize(int data_size)
- {
- if (m_pData) {
- FX_Allocator_Free(m_pAllocator, m_pData);
- }
- m_pData = NULL;
- if (data_size > FixedSize) {
- m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, data_size);
- } else {
- FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize);
- }
- }
- ~CFX_FixedBufGrow()
- {
- if (m_pData) {
- FX_Allocator_Free(m_pAllocator, m_pData);
- }
- }
- operator DataType*()
- {
- return m_pData ? m_pData : m_Data;
- }
-private:
- IFX_Allocator* m_pAllocator;
- DataType m_Data[FixedSize];
- DataType* m_pData;
-};
-template <class DataType>
-class CFX_TempBuf
-{
-public:
- CFX_TempBuf(int size, IFX_Allocator* pAllocator = NULL) : m_pAllocator(pAllocator)
- {
- m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, size);
- }
- ~CFX_TempBuf()
- {
- if (m_pData) {
- FX_Allocator_Free(m_pAllocator, m_pData);
- }
- }
- DataType& operator[](int i)
- {
- FXSYS_assert(m_pData != NULL);
- return m_pData[i];
- }
- operator DataType*()
- {
- return m_pData;
- }
-private:
- IFX_Allocator* m_pAllocator;
- DataType* m_pData;
-};
-class CFX_MapPtrToPtr : public CFX_Object
-{
-protected:
-
- struct CAssoc {
-
- CAssoc* pNext;
-
- void* key;
-
- void* value;
- };
-public:
-
- CFX_MapPtrToPtr(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
-
- ~CFX_MapPtrToPtr();
-
- int GetCount() const
- {
- return m_nCount;
- }
-
- FX_BOOL IsEmpty() const
- {
- return m_nCount == 0;
- }
-
- FX_BOOL Lookup(void* key, void*& rValue) const;
-
- void* GetValueAt(void* key) const;
-
- void*& operator[](void* key);
-
- void SetAt(void* key, void* newValue)
- {
- (*this)[key] = newValue;
- }
-
- FX_BOOL RemoveKey(void* key);
-
- void RemoveAll();
-
- FX_POSITION GetStartPosition() const
- {
- return (m_nCount == 0) ? NULL : (FX_POSITION) - 1;
- }
-
- void GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void*& rValue) const;
-
- FX_DWORD GetHashTableSize() const
- {
- return m_nHashTableSize;
- }
-
- void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
-protected:
-
- IFX_Allocator* m_pAllocator;
-
- CAssoc** m_pHashTable;
-
- FX_DWORD m_nHashTableSize;
-
- int m_nCount;
-
- CAssoc* m_pFreeList;
-
- struct CFX_Plex* m_pBlocks;
-
- int m_nBlockSize;
-
- FX_DWORD HashKey(void* key) const;
-
- CAssoc* NewAssoc();
-
- void FreeAssoc(CAssoc* pAssoc);
-
- CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const;
-};
-template <class KeyType, class ValueType>
-class CFX_MapPtrTemplate : public CFX_MapPtrToPtr
-{
-public:
-
- CFX_MapPtrTemplate(IFX_Allocator* pAllocator = NULL) : CFX_MapPtrToPtr(10, pAllocator) {}
-
- FX_BOOL Lookup(KeyType key, ValueType& rValue) const
- {
- FX_LPVOID pValue = NULL;
- if (!CFX_MapPtrToPtr::Lookup((void*)(FX_UINTPTR)key, pValue)) {
- return FALSE;
- }
- rValue = (ValueType)(FX_UINTPTR)pValue;
- return TRUE;
- }
-
- ValueType& operator[](KeyType key)
- {
- return (ValueType&)CFX_MapPtrToPtr::operator []((void*)(FX_UINTPTR)key);
- }
-
- void SetAt(KeyType key, ValueType newValue)
- {
- CFX_MapPtrToPtr::SetAt((void*)(FX_UINTPTR)key, (void*)(FX_UINTPTR)newValue);
- }
-
- FX_BOOL RemoveKey(KeyType key)
- {
- return CFX_MapPtrToPtr::RemoveKey((void*)(FX_UINTPTR)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)(FX_UINTPTR)pKey;
- rValue = (ValueType)(FX_UINTPTR)pValue;
- }
-};
-class CFX_CMapDWordToDWord : public CFX_Object
-{
-public:
-
- CFX_CMapDWordToDWord(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator) {}
-
- FX_BOOL Lookup(FX_DWORD key, FX_DWORD& value) const;
-
- void SetAt(FX_DWORD key, FX_DWORD value);
-
- void EstimateSize(FX_DWORD size, FX_DWORD grow_by);
-
- FX_POSITION GetStartPosition() const;
-
- void GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX_DWORD& value) const;
-protected:
-
- CFX_BinaryBuf m_Buffer;
-};
-class CFX_MapByteStringToPtr : public CFX_Object
-{
-protected:
-
- struct CAssoc {
-
- CAssoc* pNext;
-
- FX_DWORD nHashValue;
-
- CFX_ByteString key;
-
- void* value;
- };
-public:
-
- CFX_MapByteStringToPtr(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
-
- int GetCount() const
- {
- return m_nCount;
- }
-
- FX_BOOL IsEmpty() const
- {
- return m_nCount == 0;
- }
-
- FX_BOOL Lookup(FX_BSTR key, void*& rValue) const;
-
- void*& operator[](FX_BSTR key);
-
- void SetAt(FX_BSTR key, void* newValue)
- {
- (*this)[key] = newValue;
- }
-
- FX_BOOL RemoveKey(FX_BSTR key);
-
- void RemoveAll();
-
- FX_POSITION GetStartPosition() const
- {
- return (m_nCount == 0) ? NULL : (FX_POSITION) - 1;
- }
-
- void GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const;
-
- FX_LPVOID GetNextValue(FX_POSITION& rNextPosition) const;
-
- FX_DWORD GetHashTableSize() const
- {
- return m_nHashTableSize;
- }
-
- void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
-
- FX_DWORD HashKey(FX_BSTR key) const;
-protected:
-
- IFX_Allocator* m_pAllocator;
-
- CAssoc** m_pHashTable;
-
- FX_DWORD m_nHashTableSize;
-
- int m_nCount;
-
- CAssoc* m_pFreeList;
-
- struct CFX_Plex* m_pBlocks;
-
- int m_nBlockSize;
-
- CAssoc* NewAssoc();
-
- void FreeAssoc(CAssoc* pAssoc);
-
- CAssoc* GetAssocAt(FX_BSTR key, FX_DWORD& hash) const;
-public:
-
- ~CFX_MapByteStringToPtr();
-};
-class CFX_CMapByteStringToPtr : public CFX_Object
-{
-public:
-
- CFX_CMapByteStringToPtr(IFX_Allocator* pAllocator = NULL);
-
- ~CFX_CMapByteStringToPtr();
-
- void RemoveAll();
-
- FX_POSITION GetStartPosition() const;
-
- void GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const;
-
- FX_LPVOID GetNextValue(FX_POSITION& rNextPosition) const;
-
- FX_BOOL Lookup(FX_BSTR key, void*& rValue) const;
-
- void SetAt(FX_BSTR key, void* value);
-
- void RemoveKey(FX_BSTR key);
-
- int GetCount() const;
-
- void AddValue(FX_BSTR key, void* pValue);
-private:
-
- CFX_BaseSegmentedArray m_Buffer;
-};
-class CFX_PtrList : public CFX_Object
-{
-protected:
-
- struct CNode {
-
- CNode* pNext;
-
- CNode* pPrev;
-
- void* data;
- };
-public:
-
- CFX_PtrList(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
-
- FX_POSITION GetHeadPosition() const
- {
- return (FX_POSITION)m_pNodeHead;
- }
-
- 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* 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 GetPrevPosition(FX_POSITION pos) const
- {
- return ((CNode*)pos)->pPrev;
- }
-
- void* GetAt(FX_POSITION rPosition) const
- {
- CNode* pNode = (CNode*) rPosition;
- return pNode->data;
- }
-
- int GetCount() const
- {
- return m_nCount;
- }
-
- FX_POSITION AddTail(void* newElement);
-
- FX_POSITION AddHead(void* 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 Find(void* searchValue, FX_POSITION startAfter = NULL ) const;
-
- FX_POSITION FindIndex(int index) const;
-
- void RemoveAt(FX_POSITION pos);
-
- void RemoveAll();
-protected:
-
- IFX_Allocator* m_pAllocator;
-
- CNode* m_pNodeHead;
-
- CNode* m_pNodeTail;
-
- int m_nCount;
-
- CNode* m_pNodeFree;
-
- struct CFX_Plex* m_pBlocks;
-
- int m_nBlockSize;
-
- CNode* NewNode(CNode* pPrev, CNode* pNext);
-
- void FreeNode(CNode* pNode);
-public:
-
- ~CFX_PtrList();
-};
-typedef void (*PD_CALLBACK_FREEDATA)(FX_LPVOID pData);
-struct FX_PRIVATEDATA {
-
- void FreeData();
-
- FX_LPVOID m_pModuleId;
-
- FX_LPVOID m_pData;
-
- PD_CALLBACK_FREEDATA m_pCallback;
-
- FX_BOOL m_bSelfDestruct;
-};
-class CFX_PrivateData
-{
-public:
-
- CFX_PrivateData(IFX_Allocator* pAllocator = NULL) : m_DataList(pAllocator) {}
-
- ~CFX_PrivateData();
-
- void ClearAll();
-
- void SetPrivateData(FX_LPVOID module_id, FX_LPVOID pData, PD_CALLBACK_FREEDATA callback);
-
- void SetPrivateObj(FX_LPVOID module_id, CFX_DestructObject* pObj);
-
- FX_LPVOID GetPrivateData(FX_LPVOID module_id);
-
- FX_BOOL LookupPrivateData(FX_LPVOID module_id, FX_LPVOID &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(FX_LPVOID module_id);
-protected:
-
- CFX_ArrayTemplate<FX_PRIVATEDATA> m_DataList;
-
- void AddData(FX_LPVOID module_id, FX_LPVOID pData, PD_CALLBACK_FREEDATA callback, FX_BOOL bSelfDestruct);
-};
-class CFX_BitStream : public CFX_Object
-{
-public:
-
- void Init(FX_LPCBYTE pData, FX_DWORD dwSize);
-
-
- FX_DWORD GetBits(FX_DWORD nBits);
-
- void ByteAlign();
-
- FX_BOOL IsEOF()
- {
- return m_BitPos >= m_BitSize;
- }
-
- void SkipBits(FX_DWORD nBits)
- {
- m_BitPos += nBits;
- }
-
- void Rewind()
- {
- m_BitPos = 0;
- }
-protected:
-
- FX_DWORD m_BitPos;
-
- FX_DWORD m_BitSize;
-
- FX_LPCBYTE m_pData;
-};
-template <class ObjClass> class CFX_CountRef : public CFX_Object
-{
-public:
-
- typedef CFX_CountRef<ObjClass> Ref;
-
- class CountedObj : public ObjClass
- {
- public:
-
- CountedObj() {}
-
- CountedObj(const CountedObj& src) : ObjClass(src) {}
-
- int m_RefCount;
- };
-
- CFX_CountRef()
- {
- m_pObject = NULL;
- }
-
- CFX_CountRef(const Ref& ref)
- {
- m_pObject = ref.m_pObject;
- if (m_pObject) {
- m_pObject->m_RefCount ++;
- }
- }
-
- ~CFX_CountRef()
- {
- if (!m_pObject) {
- return;
- }
- 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;
- }
-
- 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;
- }
-
- 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;
- }
-
- const ObjClass* GetObject() const
- {
- return m_pObject;
- }
-
- operator const ObjClass*() const
- {
- return m_pObject;
- }
-
- 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;
- }
-
- 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 operator == (const Ref& ref) const
- {
- return m_pObject == ref.m_pObject;
- }
-protected:
-
- CountedObj* m_pObject;
-};
-class IFX_Pause
-{
-public:
-
- virtual FX_BOOL NeedToPauseNow() = 0;
-};
-class CFX_DataFilter : public CFX_Object
-{
-public:
-
- virtual ~CFX_DataFilter();
-
- void SetDestFilter(CFX_DataFilter* pFilter);
-
- FX_BOOL IsEOF() const
- {
- return m_bEOF;
- }
-
- FX_DWORD GetSrcPos()
- {
- return m_SrcPos;
- }
-
- void FilterIn(FX_LPCBYTE src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf);
-
- void FilterFinish(CFX_BinaryBuf& dest_buf);
-protected:
-
- CFX_DataFilter();
- virtual void v_FilterIn(FX_LPCBYTE 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_DWORD m_SrcPos;
-
- CFX_DataFilter* m_pDestFilter;
-};
-template <class T>
-class CFX_SmartPointer
-{
-public:
- CFX_SmartPointer(T *pObj) : m_pObj(pObj) {}
- ~CFX_SmartPointer()
- {
- m_pObj->Release();
- }
- operator T*(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 : public CFX_Object
-{
-protected:
-
- struct DataList {
-
- FX_INT32 start;
-
- FX_INT32 count;
- FX_LPBYTE data;
- };
-public:
-
- CFX_SortListArray(IFX_Allocator* pAllocator = NULL) : m_CurList(0), m_DataLists(pAllocator) {}
-
- ~CFX_SortListArray()
- {
- Clear();
- }
-
-
- void Clear()
- {
- IFX_Allocator* pAllocator = m_DataLists.m_pAllocator;
- for (FX_INT32 i = m_DataLists.GetUpperBound(); i >= 0; i--) {
- DataList list = m_DataLists.ElementAt(i);
- if (list.data) {
- FX_Allocator_Free(pAllocator, list.data);
- }
- }
- m_DataLists.RemoveAll();
- m_CurList = 0;
- }
-
- void Append(FX_INT32 nStart, FX_INT32 nCount)
- {
- if (nStart < 0) {
- return;
- }
- IFX_Allocator* pAllocator = m_DataLists.m_pAllocator;
- while (nCount > 0) {
- FX_INT32 temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH);
- DataList list;
- list.data = FX_Allocator_Alloc(pAllocator, FX_BYTE, temp_count * unit);
- if (!list.data) {
- break;
- }
- FXSYS_memset32(list.data, 0, temp_count * unit);
- list.start = nStart;
- list.count = temp_count;
- Append(list);
- nCount -= temp_count;
- nStart += temp_count;
- }
- }
-
- FX_LPBYTE GetAt(FX_INT32 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;
- FX_INT32 iStart = 0;
- FX_INT32 iEnd = m_DataLists.GetUpperBound();
- FX_INT32 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)
- {
- FX_INT32 iStart = 0;
- FX_INT32 iEnd = m_DataLists.GetUpperBound();
- FX_INT32 iFind = 0;
- while (iStart <= iEnd) {
- FX_INT32 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;
- }
- }
- }
- m_DataLists.InsertAt(iFind, list);
- }
- FX_INT32 m_CurList;
- CFX_ArrayTemplate<DataList> m_DataLists;
-};
-template<typename T1, typename T2>
-class CFX_ListArrayTemplate : public CFX_Object
-{
-public:
-
- void Clear()
- {
- m_Data.Clear();
- }
-
- void Add(FX_INT32 nStart, FX_INT32 nCount)
- {
- m_Data.Append(nStart, nCount);
- }
-
- T2& operator [] (FX_INT32 nIndex)
- {
- FX_LPBYTE data = m_Data.GetAt(nIndex);
- FXSYS_assert(data != NULL);
- return (T2&)(*(volatile T2*)data);
- }
-
- T2* GetPtrAt(FX_INT32 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 enum {
- Ready,
- ToBeContinued,
- Found,
- NotFound,
- Failed,
- Done
-} FX_ProgressiveStatus;
-#define ProgressiveStatus FX_ProgressiveStatus
-#define FX_NAMESPACE_DECLARE(namespace, type) namespace::type
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FX_BASIC_H_
+#define _FX_BASIC_H_
+#ifndef _FX_SYSTEM_H_
+#include "fx_system.h"
+#endif
+#ifndef _FX_MEMORY_H_
+#include "fx_memory.h"
+#endif
+#ifndef _FX_STRING_H_
+#include "fx_string.h"
+#endif
+#ifndef _FX_STREAM_H_
+#include "fx_stream.h"
+#endif
+class CFX_BinaryBuf : public CFX_Object
+{
+public:
+
+ CFX_BinaryBuf(IFX_Allocator* pAllocator = NULL);
+
+ CFX_BinaryBuf(FX_STRSIZE size, IFX_Allocator* pAllocator = NULL);
+
+ ~CFX_BinaryBuf();
+
+ void Clear();
+
+ void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0);
+
+ void AppendBlock(const void* pBuf, FX_STRSIZE size);
+
+ void AppendFill(FX_BYTE byte, FX_STRSIZE count);
+
+ void AppendString(FX_BSTR str)
+ {
+ AppendBlock(str.GetPtr(), str.GetLength());
+ }
+
+ inline void AppendByte(FX_BYTE 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 AttachData(void* pBuf, FX_STRSIZE size);
+
+ void CopyData(const void* pBuf, FX_STRSIZE size);
+
+ void TakeOver(CFX_BinaryBuf& other);
+
+ void Delete(int start_index, int count);
+
+ FX_LPBYTE GetBuffer() const
+ {
+ return m_pBuffer;
+ }
+
+ FX_STRSIZE GetSize() const
+ {
+ return m_DataSize;
+ }
+
+ CFX_ByteStringC GetByteString() const;
+ void GetByteStringL(CFX_ByteStringL &str) const;
+
+ void DetachBuffer();
+
+ IFX_Allocator* m_pAllocator;
+protected:
+
+ FX_STRSIZE m_AllocStep;
+
+ FX_LPBYTE m_pBuffer;
+
+ FX_STRSIZE m_DataSize;
+
+ FX_STRSIZE m_AllocSize;
+
+ void ExpandBuf(FX_STRSIZE size);
+};
+class CFX_ByteTextBuf : public CFX_BinaryBuf
+{
+public:
+
+ CFX_ByteTextBuf(IFX_Allocator* pAllocator = NULL) : CFX_BinaryBuf(pAllocator) {}
+
+ void operator = (FX_BSTR str);
+
+ void AppendChar(int ch)
+ {
+ AppendByte((FX_BYTE)ch);
+ }
+
+ CFX_ByteTextBuf& operator << (int i);
+
+ CFX_ByteTextBuf& operator << (FX_DWORD i);
+
+ CFX_ByteTextBuf& operator << (double f);
+
+ CFX_ByteTextBuf& operator << (FX_BSTR lpsz);
+
+ CFX_ByteTextBuf& operator << (const CFX_ByteTextBuf& buf);
+
+ FX_STRSIZE GetLength() const
+ {
+ return m_DataSize;
+ }
+};
+class CFX_WideTextBuf : public CFX_BinaryBuf
+{
+public:
+
+ CFX_WideTextBuf(IFX_Allocator* pAllocator = NULL) : CFX_BinaryBuf(pAllocator) {}
+
+ void operator = (FX_LPCWSTR lpsz);
+
+ void operator = (FX_WSTR str);
+
+ void AppendChar(FX_WCHAR wch);
+
+ CFX_WideTextBuf& operator << (int i);
+
+ CFX_WideTextBuf& operator << (double f);
+
+ CFX_WideTextBuf& operator << (FX_LPCWSTR lpsz);
+
+ CFX_WideTextBuf& operator << (FX_WSTR str);
+ CFX_WideTextBuf& operator << (const CFX_WideString &str);
+
+ CFX_WideTextBuf& operator << (const CFX_WideTextBuf& buf);
+
+ FX_STRSIZE GetLength() const
+ {
+ return m_DataSize / sizeof(FX_WCHAR);
+ }
+
+ FX_LPWSTR GetBuffer() const
+ {
+ return (FX_LPWSTR)m_pBuffer;
+ }
+
+ void Delete(int start_index, int count)
+ {
+ CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), count * sizeof(FX_WCHAR));
+ }
+
+ CFX_WideStringC GetWideString() const;
+ void GetWideStringL(CFX_WideStringL& wideText) const;
+};
+class CFX_ArchiveSaver : public CFX_Object
+{
+public:
+
+ CFX_ArchiveSaver(IFX_Allocator* pAllocator = NULL) : m_SavingBuf(pAllocator), m_pStream(NULL) {}
+
+ CFX_ArchiveSaver& operator << (FX_BYTE i);
+
+ CFX_ArchiveSaver& operator << (int i);
+
+ CFX_ArchiveSaver& operator << (FX_DWORD i);
+
+ CFX_ArchiveSaver& operator << (FX_FLOAT i);
+
+ CFX_ArchiveSaver& operator << (double i);
+
+ CFX_ArchiveSaver& operator << (FX_BSTR bstr);
+
+ CFX_ArchiveSaver& operator << (FX_LPCWSTR bstr);
+
+ CFX_ArchiveSaver& operator << (const CFX_WideString& wstr);
+
+ void Write(const void* pData, FX_STRSIZE dwSize);
+
+ FX_INTPTR GetLength()
+ {
+ return m_SavingBuf.GetSize();
+ }
+
+ FX_LPCBYTE GetBuffer()
+ {
+ return m_SavingBuf.GetBuffer();
+ }
+
+ void SetStream(IFX_FileStream* pStream)
+ {
+ m_pStream = pStream;
+ }
+protected:
+
+ CFX_BinaryBuf m_SavingBuf;
+
+ IFX_FileStream* m_pStream;
+};
+class CFX_ArchiveLoader : public CFX_Object
+{
+public:
+
+ CFX_ArchiveLoader(FX_LPCBYTE pData, FX_DWORD dwSize);
+
+ CFX_ArchiveLoader& operator >> (FX_BYTE& i);
+
+ CFX_ArchiveLoader& operator >> (int& i);
+
+ CFX_ArchiveLoader& operator >> (FX_DWORD& i);
+
+ CFX_ArchiveLoader& operator >> (FX_FLOAT& i);
+
+ CFX_ArchiveLoader& operator >> (double& i);
+
+ CFX_ArchiveLoader& operator >> (CFX_ByteString& bstr);
+
+ CFX_ArchiveLoader& operator >> (CFX_WideString& wstr);
+
+ FX_BOOL IsEOF();
+
+ FX_BOOL Read(void* pBuf, FX_DWORD dwSize);
+protected:
+
+ FX_DWORD m_LoadingPos;
+
+ FX_LPCBYTE m_pLoadingBuf;
+
+ FX_DWORD m_LoadingSize;
+};
+class IFX_BufferArchive
+{
+public:
+
+ IFX_BufferArchive(FX_STRSIZE size, IFX_Allocator* pAllocator = NULL);
+
+
+ virtual void Clear();
+
+
+ FX_BOOL Flush();
+
+
+ FX_INT32 AppendBlock(const void* pBuf, size_t size);
+
+ FX_INT32 AppendByte(FX_BYTE byte);
+
+ FX_INT32 AppendDWord(FX_DWORD i);
+
+
+ FX_INT32 AppendString(FX_BSTR lpsz);
+
+protected:
+
+ virtual FX_BOOL DoWork(const void* pBuf, size_t size) = 0;
+
+
+ IFX_Allocator* m_pAllocator;
+
+ FX_STRSIZE m_BufSize;
+
+ FX_LPBYTE m_pBuffer;
+
+ FX_STRSIZE m_Length;
+};
+class CFX_FileBufferArchive : public IFX_BufferArchive, public CFX_Object
+{
+public:
+ CFX_FileBufferArchive(FX_STRSIZE size = 32768, IFX_Allocator* pAllocator = NULL);
+ ~CFX_FileBufferArchive();
+ virtual void Clear();
+
+ FX_BOOL AttachFile(IFX_StreamWrite *pFile, FX_BOOL bTakeover = FALSE);
+
+ FX_BOOL AttachFile(FX_LPCWSTR filename);
+
+ FX_BOOL AttachFile(FX_LPCSTR filename);
+private:
+
+ virtual FX_BOOL DoWork(const void* pBuf, size_t size);
+
+ IFX_StreamWrite *m_pFile;
+
+ FX_BOOL m_bTakeover;
+};
+struct CFX_CharMap {
+
+ static CFX_CharMap* GetDefaultMapper(FX_INT32 codepage = 0);
+
+
+ CFX_WideString (*m_GetWideString)(CFX_CharMap* pMap, const CFX_ByteString& bstr);
+
+ CFX_ByteString (*m_GetByteString)(CFX_CharMap* pMap, const CFX_WideString& wstr);
+
+ FX_INT32 (*m_GetCodePage)();
+};
+class CFX_UTF8Decoder
+{
+public:
+
+ CFX_UTF8Decoder(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator)
+ {
+ m_PendingBytes = 0;
+ }
+
+ void Clear();
+
+ void Input(FX_BYTE byte);
+
+ void AppendChar(FX_DWORD ch);
+
+ void ClearStatus()
+ {
+ m_PendingBytes = 0;
+ }
+
+ CFX_WideStringC GetResult() const
+ {
+ return m_Buffer.GetWideString();
+ }
+ void GetResult(CFX_WideStringL &result) const
+ {
+ m_Buffer.GetWideStringL(result);
+ }
+protected:
+
+ int m_PendingBytes;
+
+ FX_DWORD m_PendingChar;
+
+ CFX_WideTextBuf m_Buffer;
+};
+class CFX_UTF8Encoder
+{
+public:
+
+ CFX_UTF8Encoder(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator)
+ {
+ m_UTF16First = 0;
+ }
+
+ void Input(FX_WCHAR unicode);
+
+ void AppendStr(FX_BSTR str)
+ {
+ m_UTF16First = 0;
+ m_Buffer << str;
+ }
+
+ CFX_ByteStringC GetResult() const
+ {
+ return m_Buffer.GetByteString();
+ }
+ void GetResult(CFX_ByteStringL &result) const
+ {
+ m_Buffer.GetByteStringL(result);
+ }
+protected:
+
+ CFX_ByteTextBuf m_Buffer;
+
+ 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 : public CFX_Object
+{
+public:
+
+ IFX_Allocator* m_pAllocator;
+protected:
+
+ CFX_BasicArray(int unit_size, IFX_Allocator* pAllocator = NULL);
+
+ ~CFX_BasicArray();
+
+ FX_BOOL SetSize(int nNewSize, int nGrowBy);
+
+ FX_BOOL Append(const CFX_BasicArray& src);
+
+ FX_BOOL Copy(const CFX_BasicArray& src);
+
+ FX_LPBYTE InsertSpaceAt(int nIndex, int nCount);
+
+ FX_BOOL RemoveAt(int nIndex, int nCount);
+
+ FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray);
+
+ const void* GetDataPtr(int index) const;
+protected:
+
+ FX_LPBYTE m_pData;
+
+ int m_nSize;
+
+ int m_nMaxSize;
+
+ int m_nGrowBy;
+
+ int m_nUnitSize;
+};
+template<class TYPE>
+class CFX_ArrayTemplate : public CFX_BasicArray
+{
+public:
+
+ CFX_ArrayTemplate(IFX_Allocator* pAllocator = NULL) : CFX_BasicArray(sizeof(TYPE), pAllocator) {}
+
+ int GetSize() const
+ {
+ return m_nSize;
+ }
+
+ int GetUpperBound() const
+ {
+ return m_nSize - 1;
+ }
+
+ FX_BOOL SetSize(int nNewSize, int nGrowBy = -1)
+ {
+ return CFX_BasicArray::SetSize(nNewSize, nGrowBy);
+ }
+
+ void RemoveAll()
+ {
+ SetSize(0, -1);
+ }
+
+ 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];
+ }
+
+ FX_BOOL SetAt(int nIndex, TYPE newElement)
+ {
+ if (nIndex < 0 || nIndex >= m_nSize) {
+ return FALSE;
+ }
+ ((TYPE*)m_pData)[nIndex] = newElement;
+ return TRUE;
+ }
+
+ TYPE& ElementAt(int nIndex)
+ {
+ if (nIndex < 0 || nIndex >= m_nSize) {
+ return *(TYPE*)NULL;
+ }
+ return ((TYPE*)m_pData)[nIndex];
+ }
+
+ const TYPE* GetData() const
+ {
+ return (const TYPE*)m_pData;
+ }
+
+ TYPE* GetData()
+ {
+ return (TYPE*)m_pData;
+ }
+
+ FX_BOOL SetAtGrow(int nIndex, TYPE newElement)
+ {
+ if (nIndex < 0) {
+ return FALSE;
+ }
+ if (nIndex >= m_nSize)
+ if (!SetSize(nIndex + 1, -1)) {
+ return FALSE;
+ }
+ ((TYPE*)m_pData)[nIndex] = newElement;
+ return TRUE;
+ }
+
+ FX_BOOL Add(TYPE newElement)
+ {
+ if (m_nSize < m_nMaxSize) {
+ m_nSize ++;
+ } else if (!SetSize(m_nSize + 1, -1)) {
+ return FALSE;
+ }
+ ((TYPE*)m_pData)[m_nSize - 1] = newElement;
+ return TRUE;
+ }
+
+ FX_BOOL Append(const CFX_ArrayTemplate& src)
+ {
+ return CFX_BasicArray::Append(src);
+ }
+
+ FX_BOOL Copy(const CFX_ArrayTemplate& src)
+ {
+ return CFX_BasicArray::Copy(src);
+ }
+
+ TYPE* GetDataPtr(int index)
+ {
+ return (TYPE*)CFX_BasicArray::GetDataPtr(index);
+ }
+
+ TYPE* AddSpace()
+ {
+ return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1);
+ }
+
+ TYPE* InsertSpaceAt(int nIndex, int nCount)
+ {
+ return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount);
+ }
+
+ const TYPE operator[](int nIndex) const
+ {
+ if (nIndex < 0 || nIndex >= m_nSize) {
+ *(volatile char*)0 = '\0';
+ }
+ return ((const TYPE*)m_pData)[nIndex];
+ }
+
+ TYPE& operator[](int nIndex)
+ {
+ if (nIndex < 0 || nIndex >= m_nSize) {
+ *(volatile char*)0 = '\0';
+ }
+ return ((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;
+ }
+
+ 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<FX_BYTE> 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<FX_INT32> CFX_Int32Array;
+template <class ObjectClass>
+class CFX_ObjectArray : public CFX_BasicArray
+{
+public:
+
+ CFX_ObjectArray(IFX_Allocator* pAllocator = NULL) : CFX_BasicArray(sizeof(ObjectClass), pAllocator) {}
+
+ ~CFX_ObjectArray()
+ {
+ RemoveAll();
+ }
+
+ void Add(const ObjectClass& data)
+ {
+ new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data);
+ }
+
+ ObjectClass& Add()
+ {
+ return *(ObjectClass*) new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass();
+ }
+
+ void* AddSpace()
+ {
+ return InsertSpaceAt(m_nSize, 1);
+ }
+
+ FX_INT32 Append(const CFX_ObjectArray& src, FX_INT32 nStart = 0, FX_INT32 nCount = -1)
+ {
+ if (nCount == 0) {
+ return 0;
+ }
+ FX_INT32 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 (FX_INT32 i = nStart; i < nSize; i ++, pStartObj++) {
+ new ((void*)pStartObj) ObjectClass(src[i]);
+ }
+ return nCount;
+ }
+
+ FX_INT32 Copy(const CFX_ObjectArray& src, FX_INT32 nStart = 0, FX_INT32 nCount = -1)
+ {
+ if (nCount == 0) {
+ return 0;
+ }
+ FX_INT32 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, -1);
+ ObjectClass* pStartObj = (ObjectClass*)m_pData;
+ nSize = nStart + nCount;
+ for (FX_INT32 i = nStart; i < nSize; i ++, pStartObj++) {
+ new ((void*)pStartObj) ObjectClass(src[i]);
+ }
+ return nCount;
+ }
+
+ 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, -1);
+ }
+};
+typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray;
+typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray;
+class CFX_BaseSegmentedArray : public CFX_Object
+{
+public:
+
+ CFX_BaseSegmentedArray(int unit_size = 1, int segment_units = 512, int index_size = 8, IFX_Allocator* pAllocator = NULL);
+
+ ~CFX_BaseSegmentedArray();
+
+ void SetUnitSize(int unit_size, int segment_units, int index_size = 8);
+
+ void* Add();
+
+ void* GetAt(int index) const;
+
+ void RemoveAll();
+
+ void Delete(int index, int count = 1);
+
+ int GetSize() const
+ {
+ return m_DataSize;
+ }
+
+ int GetSegmentSize() const
+ {
+ return m_SegmentSize;
+ }
+
+ int GetUnitSize() const
+ {
+ return m_UnitSize;
+ }
+
+ void* Iterate(FX_BOOL (*callback)(void* param, void* pData), void* param) const;
+
+ IFX_Allocator* m_pAllocator;
+private:
+
+ int m_UnitSize;
+
+ short m_SegmentSize;
+
+ FX_BYTE m_IndexSize;
+
+ FX_BYTE m_IndexDepth;
+
+ 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(FX_LPCBYTE 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, IFX_Allocator* pAllocator = NULL)
+ : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size, pAllocator)
+ {}
+
+ 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_Object
+{
+public:
+ CFX_FixedBufGrow(IFX_Allocator* pAllocator = NULL)
+ : m_pAllocator(pAllocator)
+ , m_pData(NULL)
+ {}
+ CFX_FixedBufGrow(int data_size, IFX_Allocator* pAllocator = NULL)
+ : m_pAllocator(pAllocator)
+ , m_pData(NULL)
+ {
+ if (data_size > FixedSize) {
+ m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, data_size);
+ } else {
+ FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize);
+ }
+ }
+ void SetDataSize(int data_size)
+ {
+ if (m_pData) {
+ FX_Allocator_Free(m_pAllocator, m_pData);
+ }
+ m_pData = NULL;
+ if (data_size > FixedSize) {
+ m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, data_size);
+ } else {
+ FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize);
+ }
+ }
+ ~CFX_FixedBufGrow()
+ {
+ if (m_pData) {
+ FX_Allocator_Free(m_pAllocator, m_pData);
+ }
+ }
+ operator DataType*()
+ {
+ return m_pData ? m_pData : m_Data;
+ }
+private:
+ IFX_Allocator* m_pAllocator;
+ DataType m_Data[FixedSize];
+ DataType* m_pData;
+};
+template <class DataType>
+class CFX_TempBuf
+{
+public:
+ CFX_TempBuf(int size, IFX_Allocator* pAllocator = NULL) : m_pAllocator(pAllocator)
+ {
+ m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, size);
+ }
+ ~CFX_TempBuf()
+ {
+ if (m_pData) {
+ FX_Allocator_Free(m_pAllocator, m_pData);
+ }
+ }
+ DataType& operator[](int i)
+ {
+ FXSYS_assert(m_pData != NULL);
+ return m_pData[i];
+ }
+ operator DataType*()
+ {
+ return m_pData;
+ }
+private:
+ IFX_Allocator* m_pAllocator;
+ DataType* m_pData;
+};
+class CFX_MapPtrToPtr : public CFX_Object
+{
+protected:
+
+ struct CAssoc {
+
+ CAssoc* pNext;
+
+ void* key;
+
+ void* value;
+ };
+public:
+
+ CFX_MapPtrToPtr(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
+
+ ~CFX_MapPtrToPtr();
+
+ int GetCount() const
+ {
+ return m_nCount;
+ }
+
+ FX_BOOL IsEmpty() const
+ {
+ return m_nCount == 0;
+ }
+
+ FX_BOOL Lookup(void* key, void*& rValue) const;
+
+ void* GetValueAt(void* key) const;
+
+ void*& operator[](void* key);
+
+ void SetAt(void* key, void* newValue)
+ {
+ (*this)[key] = newValue;
+ }
+
+ FX_BOOL RemoveKey(void* key);
+
+ void RemoveAll();
+
+ FX_POSITION GetStartPosition() const
+ {
+ return (m_nCount == 0) ? NULL : (FX_POSITION) - 1;
+ }
+
+ void GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void*& rValue) const;
+
+ FX_DWORD GetHashTableSize() const
+ {
+ return m_nHashTableSize;
+ }
+
+ void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
+protected:
+
+ IFX_Allocator* m_pAllocator;
+
+ CAssoc** m_pHashTable;
+
+ FX_DWORD m_nHashTableSize;
+
+ int m_nCount;
+
+ CAssoc* m_pFreeList;
+
+ struct CFX_Plex* m_pBlocks;
+
+ int m_nBlockSize;
+
+ FX_DWORD HashKey(void* key) const;
+
+ CAssoc* NewAssoc();
+
+ void FreeAssoc(CAssoc* pAssoc);
+
+ CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const;
+};
+template <class KeyType, class ValueType>
+class CFX_MapPtrTemplate : public CFX_MapPtrToPtr
+{
+public:
+
+ CFX_MapPtrTemplate(IFX_Allocator* pAllocator = NULL) : CFX_MapPtrToPtr(10, pAllocator) {}
+
+ FX_BOOL Lookup(KeyType key, ValueType& rValue) const
+ {
+ FX_LPVOID pValue = NULL;
+ if (!CFX_MapPtrToPtr::Lookup((void*)(FX_UINTPTR)key, pValue)) {
+ return FALSE;
+ }
+ rValue = (ValueType)(FX_UINTPTR)pValue;
+ return TRUE;
+ }
+
+ ValueType& operator[](KeyType key)
+ {
+ return (ValueType&)CFX_MapPtrToPtr::operator []((void*)(FX_UINTPTR)key);
+ }
+
+ void SetAt(KeyType key, ValueType newValue)
+ {
+ CFX_MapPtrToPtr::SetAt((void*)(FX_UINTPTR)key, (void*)(FX_UINTPTR)newValue);
+ }
+
+ FX_BOOL RemoveKey(KeyType key)
+ {
+ return CFX_MapPtrToPtr::RemoveKey((void*)(FX_UINTPTR)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)(FX_UINTPTR)pKey;
+ rValue = (ValueType)(FX_UINTPTR)pValue;
+ }
+};
+class CFX_CMapDWordToDWord : public CFX_Object
+{
+public:
+
+ CFX_CMapDWordToDWord(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator) {}
+
+ FX_BOOL Lookup(FX_DWORD key, FX_DWORD& value) const;
+
+ void SetAt(FX_DWORD key, FX_DWORD value);
+
+ void EstimateSize(FX_DWORD size, FX_DWORD grow_by);
+
+ FX_POSITION GetStartPosition() const;
+
+ void GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX_DWORD& value) const;
+protected:
+
+ CFX_BinaryBuf m_Buffer;
+};
+class CFX_MapByteStringToPtr : public CFX_Object
+{
+protected:
+
+ struct CAssoc {
+
+ CAssoc* pNext;
+
+ FX_DWORD nHashValue;
+
+ CFX_ByteString key;
+
+ void* value;
+ };
+public:
+
+ CFX_MapByteStringToPtr(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
+
+ int GetCount() const
+ {
+ return m_nCount;
+ }
+
+ FX_BOOL IsEmpty() const
+ {
+ return m_nCount == 0;
+ }
+
+ FX_BOOL Lookup(FX_BSTR key, void*& rValue) const;
+
+ void*& operator[](FX_BSTR key);
+
+ void SetAt(FX_BSTR key, void* newValue)
+ {
+ (*this)[key] = newValue;
+ }
+
+ FX_BOOL RemoveKey(FX_BSTR key);
+
+ void RemoveAll();
+
+ FX_POSITION GetStartPosition() const
+ {
+ return (m_nCount == 0) ? NULL : (FX_POSITION) - 1;
+ }
+
+ void GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const;
+
+ FX_LPVOID GetNextValue(FX_POSITION& rNextPosition) const;
+
+ FX_DWORD GetHashTableSize() const
+ {
+ return m_nHashTableSize;
+ }
+
+ void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
+
+ FX_DWORD HashKey(FX_BSTR key) const;
+protected:
+
+ IFX_Allocator* m_pAllocator;
+
+ CAssoc** m_pHashTable;
+
+ FX_DWORD m_nHashTableSize;
+
+ int m_nCount;
+
+ CAssoc* m_pFreeList;
+
+ struct CFX_Plex* m_pBlocks;
+
+ int m_nBlockSize;
+
+ CAssoc* NewAssoc();
+
+ void FreeAssoc(CAssoc* pAssoc);
+
+ CAssoc* GetAssocAt(FX_BSTR key, FX_DWORD& hash) const;
+public:
+
+ ~CFX_MapByteStringToPtr();
+};
+class CFX_CMapByteStringToPtr : public CFX_Object
+{
+public:
+
+ CFX_CMapByteStringToPtr(IFX_Allocator* pAllocator = NULL);
+
+ ~CFX_CMapByteStringToPtr();
+
+ void RemoveAll();
+
+ FX_POSITION GetStartPosition() const;
+
+ void GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const;
+
+ FX_LPVOID GetNextValue(FX_POSITION& rNextPosition) const;
+
+ FX_BOOL Lookup(FX_BSTR key, void*& rValue) const;
+
+ void SetAt(FX_BSTR key, void* value);
+
+ void RemoveKey(FX_BSTR key);
+
+ int GetCount() const;
+
+ void AddValue(FX_BSTR key, void* pValue);
+private:
+
+ CFX_BaseSegmentedArray m_Buffer;
+};
+class CFX_PtrList : public CFX_Object
+{
+protected:
+
+ struct CNode {
+
+ CNode* pNext;
+
+ CNode* pPrev;
+
+ void* data;
+ };
+public:
+
+ CFX_PtrList(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
+
+ FX_POSITION GetHeadPosition() const
+ {
+ return (FX_POSITION)m_pNodeHead;
+ }
+
+ 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* 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 GetPrevPosition(FX_POSITION pos) const
+ {
+ return ((CNode*)pos)->pPrev;
+ }
+
+ void* GetAt(FX_POSITION rPosition) const
+ {
+ CNode* pNode = (CNode*) rPosition;
+ return pNode->data;
+ }
+
+ int GetCount() const
+ {
+ return m_nCount;
+ }
+
+ FX_POSITION AddTail(void* newElement);
+
+ FX_POSITION AddHead(void* 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 Find(void* searchValue, FX_POSITION startAfter = NULL ) const;
+
+ FX_POSITION FindIndex(int index) const;
+
+ void RemoveAt(FX_POSITION pos);
+
+ void RemoveAll();
+protected:
+
+ IFX_Allocator* m_pAllocator;
+
+ CNode* m_pNodeHead;
+
+ CNode* m_pNodeTail;
+
+ int m_nCount;
+
+ CNode* m_pNodeFree;
+
+ struct CFX_Plex* m_pBlocks;
+
+ int m_nBlockSize;
+
+ CNode* NewNode(CNode* pPrev, CNode* pNext);
+
+ void FreeNode(CNode* pNode);
+public:
+
+ ~CFX_PtrList();
+};
+typedef void (*PD_CALLBACK_FREEDATA)(FX_LPVOID pData);
+struct FX_PRIVATEDATA {
+
+ void FreeData();
+
+ FX_LPVOID m_pModuleId;
+
+ FX_LPVOID m_pData;
+
+ PD_CALLBACK_FREEDATA m_pCallback;
+
+ FX_BOOL m_bSelfDestruct;
+};
+class CFX_PrivateData
+{
+public:
+
+ CFX_PrivateData(IFX_Allocator* pAllocator = NULL) : m_DataList(pAllocator) {}
+
+ ~CFX_PrivateData();
+
+ void ClearAll();
+
+ void SetPrivateData(FX_LPVOID module_id, FX_LPVOID pData, PD_CALLBACK_FREEDATA callback);
+
+ void SetPrivateObj(FX_LPVOID module_id, CFX_DestructObject* pObj);
+
+ FX_LPVOID GetPrivateData(FX_LPVOID module_id);
+
+ FX_BOOL LookupPrivateData(FX_LPVOID module_id, FX_LPVOID &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(FX_LPVOID module_id);
+protected:
+
+ CFX_ArrayTemplate<FX_PRIVATEDATA> m_DataList;
+
+ void AddData(FX_LPVOID module_id, FX_LPVOID pData, PD_CALLBACK_FREEDATA callback, FX_BOOL bSelfDestruct);
+};
+class CFX_BitStream : public CFX_Object
+{
+public:
+
+ void Init(FX_LPCBYTE pData, FX_DWORD dwSize);
+
+
+ FX_DWORD GetBits(FX_DWORD nBits);
+
+ void ByteAlign();
+
+ FX_BOOL IsEOF()
+ {
+ return m_BitPos >= m_BitSize;
+ }
+
+ void SkipBits(FX_DWORD nBits)
+ {
+ m_BitPos += nBits;
+ }
+
+ void Rewind()
+ {
+ m_BitPos = 0;
+ }
+protected:
+
+ FX_DWORD m_BitPos;
+
+ FX_DWORD m_BitSize;
+
+ FX_LPCBYTE m_pData;
+};
+template <class ObjClass> class CFX_CountRef : public CFX_Object
+{
+public:
+
+ typedef CFX_CountRef<ObjClass> Ref;
+
+ class CountedObj : public ObjClass
+ {
+ public:
+
+ CountedObj() {}
+
+ CountedObj(const CountedObj& src) : ObjClass(src) {}
+
+ int m_RefCount;
+ };
+
+ CFX_CountRef()
+ {
+ m_pObject = NULL;
+ }
+
+ CFX_CountRef(const Ref& ref)
+ {
+ m_pObject = ref.m_pObject;
+ if (m_pObject) {
+ m_pObject->m_RefCount ++;
+ }
+ }
+
+ ~CFX_CountRef()
+ {
+ if (!m_pObject) {
+ return;
+ }
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ const ObjClass* GetObject() const
+ {
+ return m_pObject;
+ }
+
+ operator const ObjClass*() const
+ {
+ return m_pObject;
+ }
+
+ 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;
+ }
+
+ 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 operator == (const Ref& ref) const
+ {
+ return m_pObject == ref.m_pObject;
+ }
+protected:
+
+ CountedObj* m_pObject;
+};
+class IFX_Pause
+{
+public:
+
+ virtual FX_BOOL NeedToPauseNow() = 0;
+};
+class CFX_DataFilter : public CFX_Object
+{
+public:
+
+ virtual ~CFX_DataFilter();
+
+ void SetDestFilter(CFX_DataFilter* pFilter);
+
+ FX_BOOL IsEOF() const
+ {
+ return m_bEOF;
+ }
+
+ FX_DWORD GetSrcPos()
+ {
+ return m_SrcPos;
+ }
+
+ void FilterIn(FX_LPCBYTE src_buf, FX_DWORD src_size, CFX_BinaryBuf& dest_buf);
+
+ void FilterFinish(CFX_BinaryBuf& dest_buf);
+protected:
+
+ CFX_DataFilter();
+ virtual void v_FilterIn(FX_LPCBYTE 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_DWORD m_SrcPos;
+
+ CFX_DataFilter* m_pDestFilter;
+};
+template <class T>
+class CFX_SmartPointer
+{
+public:
+ CFX_SmartPointer(T *pObj) : m_pObj(pObj) {}
+ ~CFX_SmartPointer()
+ {
+ m_pObj->Release();
+ }
+ operator T*(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 : public CFX_Object
+{
+protected:
+
+ struct DataList {
+
+ FX_INT32 start;
+
+ FX_INT32 count;
+ FX_LPBYTE data;
+ };
+public:
+
+ CFX_SortListArray(IFX_Allocator* pAllocator = NULL) : m_CurList(0), m_DataLists(pAllocator) {}
+
+ ~CFX_SortListArray()
+ {
+ Clear();
+ }
+
+
+ void Clear()
+ {
+ IFX_Allocator* pAllocator = m_DataLists.m_pAllocator;
+ for (FX_INT32 i = m_DataLists.GetUpperBound(); i >= 0; i--) {
+ DataList list = m_DataLists.ElementAt(i);
+ if (list.data) {
+ FX_Allocator_Free(pAllocator, list.data);
+ }
+ }
+ m_DataLists.RemoveAll();
+ m_CurList = 0;
+ }
+
+ void Append(FX_INT32 nStart, FX_INT32 nCount)
+ {
+ if (nStart < 0) {
+ return;
+ }
+ IFX_Allocator* pAllocator = m_DataLists.m_pAllocator;
+ while (nCount > 0) {
+ FX_INT32 temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH);
+ DataList list;
+ list.data = FX_Allocator_Alloc(pAllocator, FX_BYTE, temp_count * unit);
+ if (!list.data) {
+ break;
+ }
+ FXSYS_memset32(list.data, 0, temp_count * unit);
+ list.start = nStart;
+ list.count = temp_count;
+ Append(list);
+ nCount -= temp_count;
+ nStart += temp_count;
+ }
+ }
+
+ FX_LPBYTE GetAt(FX_INT32 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;
+ FX_INT32 iStart = 0;
+ FX_INT32 iEnd = m_DataLists.GetUpperBound();
+ FX_INT32 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)
+ {
+ FX_INT32 iStart = 0;
+ FX_INT32 iEnd = m_DataLists.GetUpperBound();
+ FX_INT32 iFind = 0;
+ while (iStart <= iEnd) {
+ FX_INT32 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;
+ }
+ }
+ }
+ m_DataLists.InsertAt(iFind, list);
+ }
+ FX_INT32 m_CurList;
+ CFX_ArrayTemplate<DataList> m_DataLists;
+};
+template<typename T1, typename T2>
+class CFX_ListArrayTemplate : public CFX_Object
+{
+public:
+
+ void Clear()
+ {
+ m_Data.Clear();
+ }
+
+ void Add(FX_INT32 nStart, FX_INT32 nCount)
+ {
+ m_Data.Append(nStart, nCount);
+ }
+
+ T2& operator [] (FX_INT32 nIndex)
+ {
+ FX_LPBYTE data = m_Data.GetAt(nIndex);
+ FXSYS_assert(data != NULL);
+ return (T2&)(*(volatile T2*)data);
+ }
+
+ T2* GetPtrAt(FX_INT32 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 enum {
+ Ready,
+ ToBeContinued,
+ Found,
+ NotFound,
+ Failed,
+ Done
+} FX_ProgressiveStatus;
+#define ProgressiveStatus FX_ProgressiveStatus
+#define FX_NAMESPACE_DECLARE(namespace, type) namespace::type
+#endif
diff --git a/core/include/fxcrt/fx_coordinates.h b/core/include/fxcrt/fx_coordinates.h
index eee0dfb260..9a63e2a4ad 100644
--- a/core/include/fxcrt/fx_coordinates.h
+++ b/core/include/fxcrt/fx_coordinates.h
@@ -1,900 +1,900 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FXCRT_COORDINATES_
-#define _FXCRT_COORDINATES_
-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 CFX_Object
-{
-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<FX_INT32> CFX_Point;
-typedef CFX_PSVTemplate<FX_FLOAT> CFX_PointF;
-typedef CFX_PSVTemplate<FX_INT32> 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<FX_INT32> * FX_LPPOINT;
-typedef CFX_PSVTemplate<FX_FLOAT> * FX_LPPOINTF;
-typedef CFX_PSVTemplate<FX_INT32> 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 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 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);
- FXSYS_assert(fLen >= 0.0001f);
- FXT_PSV::x = ((baseType)FXT_PSV::x) / fLen;
- FXT_PSV::y = ((baseType)FXT_PSV::y) / fLen;
- }
- baseType DotProduct(baseType x, baseType y) const
- {
- return FXT_PSV::x * x + FXT_PSV::y * y;
- }
- baseType DotProduct(const FXT_VECTOR &v) const
- {
- return FXT_PSV::x * v.x + FXT_PSV::y * v.y;
- }
- FX_BOOL IsParallel(baseType x, baseType y) const
- {
- baseType t = FXT_PSV::x * y - FXT_PSV::y * x;
- return FXSYS_fabs(t) < 0x0001f;
- }
- FX_BOOL IsParallel(const FXT_VECTOR &v) const
- {
- return IsParallel(v.x, v.y);
- }
- FX_BOOL IsPerpendicular(baseType x, baseType y) const
- {
- baseType t = DotProduct(x, y);
- 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<FX_INT32> CFX_Vector;
-typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF;
-template<class baseType>
-class CFX_RTemplate: public CFX_Object
-{
-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<FX_INT32> CFX_Rect;
-typedef CFX_RTemplate<FX_FLOAT> CFX_RectF;
-typedef CFX_RTemplate<FX_INT32> * FX_LPRECT;
-typedef CFX_RTemplate<FX_FLOAT> * FX_LPRECTF;
-typedef CFX_RTemplate<FX_INT32> const * FX_LPCRECT;
-typedef CFX_RTemplate<FX_FLOAT> const * FX_LPCRECTF;
-typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray;
-struct FX_RECT {
-
- int left;
-
- int top;
-
- int right;
-
- int bottom;
-
- FX_RECT() {}
-
- 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 Height() const
- {
- return bottom - top;
- }
-
- FX_BOOL IsEmpty() const
- {
- return right <= left || bottom <= top;
- }
-
- void Normalize();
-
- void Intersect(const FX_RECT& src);
-
- void Intersect(int left1, int top1, int right1, int bottom1)
- {
- Intersect(FX_RECT(left1, top1, right1, bottom1));
- }
-
- 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;
- }
-
- 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(int x, int y) const
- {
- return x >= left && x < right && y >= top && y < bottom;
- }
-};
-struct FX_SMALL_RECT {
-
- FX_SHORT Left;
-
- FX_SHORT Top;
-
- FX_SHORT Right;
-
- FX_SHORT Bottom;
-};
-class CFX_FloatRect : public CFX_Object
-{
-public:
-
- 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(const FX_FLOAT* pArray)
- {
- left = pArray[0];
- bottom = pArray[1];
- right = pArray[2];
- top = pArray[3];
- }
-
- CFX_FloatRect(const FX_RECT& rect);
-
- FX_BOOL IsEmpty() const
- {
- return left >= right || bottom >= top;
- }
-
- void Normalize();
-
- void Reset()
- {
- left = right = bottom = top = 0;
- }
-
- FX_BOOL Contains(const CFX_FloatRect& other_rect) const;
-
- FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const;
-
- void Transform(const CFX_Matrix* pMatrix);
-
- void Intersect(const CFX_FloatRect& other_rect);
-
- void Union(const CFX_FloatRect& other_rect);
-
- FX_RECT GetInnerRect() const;
-
- FX_RECT GetOutterRect() const;
-
- FX_RECT GetClosestRect() const;
-
- int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects);
-
- void InitRect(FX_FLOAT x, FX_FLOAT y)
- {
- left = right = x;
- bottom = top = y;
- }
-
- void UpdateRect(FX_FLOAT x, FX_FLOAT y);
-
- FX_FLOAT Width() const
- {
- return right - left;
- }
-
- 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 left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top)
- {
- Normalize();
- this->left -= left;
- this->bottom -= bottom;
- this->right += right;
- this->top += 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 left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top)
- {
- Normalize();
- this->left += left;
- this->bottom += bottom;
- this->right -= right;
- this->top -= 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;
- }
-
- static CFX_FloatRect GetBBox(const CFX_FloatPoint* pPoints, int nPoints);
-
- FX_FLOAT left;
-
- FX_FLOAT right;
-
- FX_FLOAT bottom;
-
- FX_FLOAT top;
-};
-class CFX_Matrix : public CFX_Object
-{
-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;
- }
-
- 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(FX_INT32 x, FX_INT32 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;
- FX_INT32 TransformXDistance(FX_INT32 dx) const;
- FX_FLOAT TransformYDistance(FX_FLOAT dy) const;
- FX_INT32 TransformYDistance(FX_INT32 dy) const;
- FX_FLOAT TransformDistance(FX_FLOAT dx, FX_FLOAT dy) const;
- FX_INT32 TransformDistance(FX_INT32 dx, FX_INT32 dy) const;
-
- FX_FLOAT TransformDistance(FX_FLOAT distance) const;
- void TransformPoint(FX_FLOAT &x, FX_FLOAT &y) const;
- void TransformPoint(FX_INT32 &x, FX_INT32 &y) const;
- void TransformPoints(CFX_PointF *points, FX_INT32 iCount) const;
- void TransformPoints(CFX_Point *points, FX_INT32 iCount) const;
-
- 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;
-};
-#define CFX_AffineMatrix CFX_Matrix
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FXCRT_COORDINATES_
+#define _FXCRT_COORDINATES_
+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 CFX_Object
+{
+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<FX_INT32> CFX_Point;
+typedef CFX_PSVTemplate<FX_FLOAT> CFX_PointF;
+typedef CFX_PSVTemplate<FX_INT32> 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<FX_INT32> * FX_LPPOINT;
+typedef CFX_PSVTemplate<FX_FLOAT> * FX_LPPOINTF;
+typedef CFX_PSVTemplate<FX_INT32> 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 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 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);
+ FXSYS_assert(fLen >= 0.0001f);
+ FXT_PSV::x = ((baseType)FXT_PSV::x) / fLen;
+ FXT_PSV::y = ((baseType)FXT_PSV::y) / fLen;
+ }
+ baseType DotProduct(baseType x, baseType y) const
+ {
+ return FXT_PSV::x * x + FXT_PSV::y * y;
+ }
+ baseType DotProduct(const FXT_VECTOR &v) const
+ {
+ return FXT_PSV::x * v.x + FXT_PSV::y * v.y;
+ }
+ FX_BOOL IsParallel(baseType x, baseType y) const
+ {
+ baseType t = FXT_PSV::x * y - FXT_PSV::y * x;
+ return FXSYS_fabs(t) < 0x0001f;
+ }
+ FX_BOOL IsParallel(const FXT_VECTOR &v) const
+ {
+ return IsParallel(v.x, v.y);
+ }
+ FX_BOOL IsPerpendicular(baseType x, baseType y) const
+ {
+ baseType t = DotProduct(x, y);
+ 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<FX_INT32> CFX_Vector;
+typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF;
+template<class baseType>
+class CFX_RTemplate: public CFX_Object
+{
+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<FX_INT32> CFX_Rect;
+typedef CFX_RTemplate<FX_FLOAT> CFX_RectF;
+typedef CFX_RTemplate<FX_INT32> * FX_LPRECT;
+typedef CFX_RTemplate<FX_FLOAT> * FX_LPRECTF;
+typedef CFX_RTemplate<FX_INT32> const * FX_LPCRECT;
+typedef CFX_RTemplate<FX_FLOAT> const * FX_LPCRECTF;
+typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray;
+struct FX_RECT {
+
+ int left;
+
+ int top;
+
+ int right;
+
+ int bottom;
+
+ FX_RECT() {}
+
+ 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 Height() const
+ {
+ return bottom - top;
+ }
+
+ FX_BOOL IsEmpty() const
+ {
+ return right <= left || bottom <= top;
+ }
+
+ void Normalize();
+
+ void Intersect(const FX_RECT& src);
+
+ void Intersect(int left1, int top1, int right1, int bottom1)
+ {
+ Intersect(FX_RECT(left1, top1, right1, bottom1));
+ }
+
+ 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;
+ }
+
+ 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(int x, int y) const
+ {
+ return x >= left && x < right && y >= top && y < bottom;
+ }
+};
+struct FX_SMALL_RECT {
+
+ FX_SHORT Left;
+
+ FX_SHORT Top;
+
+ FX_SHORT Right;
+
+ FX_SHORT Bottom;
+};
+class CFX_FloatRect : public CFX_Object
+{
+public:
+
+ 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(const FX_FLOAT* pArray)
+ {
+ left = pArray[0];
+ bottom = pArray[1];
+ right = pArray[2];
+ top = pArray[3];
+ }
+
+ CFX_FloatRect(const FX_RECT& rect);
+
+ FX_BOOL IsEmpty() const
+ {
+ return left >= right || bottom >= top;
+ }
+
+ void Normalize();
+
+ void Reset()
+ {
+ left = right = bottom = top = 0;
+ }
+
+ FX_BOOL Contains(const CFX_FloatRect& other_rect) const;
+
+ FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const;
+
+ void Transform(const CFX_Matrix* pMatrix);
+
+ void Intersect(const CFX_FloatRect& other_rect);
+
+ void Union(const CFX_FloatRect& other_rect);
+
+ FX_RECT GetInnerRect() const;
+
+ FX_RECT GetOutterRect() const;
+
+ FX_RECT GetClosestRect() const;
+
+ int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects);
+
+ void InitRect(FX_FLOAT x, FX_FLOAT y)
+ {
+ left = right = x;
+ bottom = top = y;
+ }
+
+ void UpdateRect(FX_FLOAT x, FX_FLOAT y);
+
+ FX_FLOAT Width() const
+ {
+ return right - left;
+ }
+
+ 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 left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top)
+ {
+ Normalize();
+ this->left -= left;
+ this->bottom -= bottom;
+ this->right += right;
+ this->top += 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 left, FX_FLOAT bottom, FX_FLOAT right, FX_FLOAT top)
+ {
+ Normalize();
+ this->left += left;
+ this->bottom += bottom;
+ this->right -= right;
+ this->top -= 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;
+ }
+
+ static CFX_FloatRect GetBBox(const CFX_FloatPoint* pPoints, int nPoints);
+
+ FX_FLOAT left;
+
+ FX_FLOAT right;
+
+ FX_FLOAT bottom;
+
+ FX_FLOAT top;
+};
+class CFX_Matrix : public CFX_Object
+{
+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;
+ }
+
+ 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(FX_INT32 x, FX_INT32 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;
+ FX_INT32 TransformXDistance(FX_INT32 dx) const;
+ FX_FLOAT TransformYDistance(FX_FLOAT dy) const;
+ FX_INT32 TransformYDistance(FX_INT32 dy) const;
+ FX_FLOAT TransformDistance(FX_FLOAT dx, FX_FLOAT dy) const;
+ FX_INT32 TransformDistance(FX_INT32 dx, FX_INT32 dy) const;
+
+ FX_FLOAT TransformDistance(FX_FLOAT distance) const;
+ void TransformPoint(FX_FLOAT &x, FX_FLOAT &y) const;
+ void TransformPoint(FX_INT32 &x, FX_INT32 &y) const;
+ void TransformPoints(CFX_PointF *points, FX_INT32 iCount) const;
+ void TransformPoints(CFX_Point *points, FX_INT32 iCount) const;
+
+ 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;
+};
+#define CFX_AffineMatrix CFX_Matrix
+#endif
diff --git a/core/include/fxcrt/fx_ext.h b/core/include/fxcrt/fx_ext.h
index 7fdbfcd0af..03ec488135 100644
--- a/core/include/fxcrt/fx_ext.h
+++ b/core/include/fxcrt/fx_ext.h
@@ -1,103 +1,103 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FXCRT_EXTENSION_
-#define _FXCRT_EXTENSION_
-#ifndef _FX_BASIC_H_
-#include "fx_basic.h"
-#endif
-#ifndef _FXCRT_COORDINATES_
-#include "fx_coordinates.h"
-#endif
-#ifndef _FX_XML_H_
-#include "fx_xml.h"
-#endif
-#ifndef _FX_UNICODE_
-#include "fx_ucd.h"
-#endif
-#ifndef _FX_ARABIC_
-#include "fx_arb.h"
-#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-FX_FLOAT FXSYS_tan(FX_FLOAT a);
-FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x);
-FX_FLOAT FXSYS_strtof(FX_LPCSTR pcsStr, FX_INT32 iLength = -1, FX_INT32 *pUsedLen = NULL);
-FX_FLOAT FXSYS_wcstof(FX_LPCWSTR pwsStr, FX_INT32 iLength = -1, FX_INT32 *pUsedLen = NULL);
-FX_LPWSTR FXSYS_wcsncpy(FX_LPWSTR dstStr, FX_LPCWSTR srcStr, size_t count);
-FX_INT32 FXSYS_wcsnicmp(FX_LPCWSTR s1, FX_LPCWSTR s2, size_t count);
-FX_INT32 FXSYS_strnicmp(FX_LPCSTR s1, FX_LPCSTR s2, size_t count);
-inline FX_BOOL FXSYS_islower(FX_INT32 ch)
-{
- return ch >= 'a' && ch <= 'z';
-}
-inline FX_BOOL FXSYS_isupper(FX_INT32 ch)
-{
- return ch >= 'A' && ch <= 'Z';
-}
-inline FX_INT32 FXSYS_tolower(FX_INT32 ch)
-{
- return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20);
-}
-inline FX_INT32 FXSYS_toupper(FX_INT32 ch)
-{
- return ch < 'a' || ch > 'z' ? ch : (ch - 0x20);
-}
-
-
-
-FX_DWORD FX_HashCode_String_GetA(FX_LPCSTR pStr, FX_INT32 iLength, FX_BOOL bIgnoreCase = FALSE);
-FX_DWORD FX_HashCode_String_GetW(FX_LPCWSTR pStr, FX_INT32 iLength, FX_BOOL bIgnoreCase = FALSE);
-
-#ifdef __cplusplus
-}
-#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-FX_LPVOID FX_Random_MT_Start(FX_DWORD dwSeed);
-
-FX_DWORD FX_Random_MT_Generate(FX_LPVOID pContext);
-
-void FX_Random_MT_Close(FX_LPVOID pContext);
-
-void FX_Random_GenerateBase(FX_LPDWORD pBuffer, FX_INT32 iCount);
-
-void FX_Random_GenerateMT(FX_LPDWORD pBuffer, FX_INT32 iCount);
-
-void FX_Random_GenerateCrypto(FX_LPDWORD pBuffer, FX_INT32 iCount);
-#ifdef __cplusplus
-}
-#endif
-template<class baseType>
-class CFX_SSortTemplate
-{
-public:
- void ShellSort(baseType *pArray, FX_INT32 iCount)
- {
- FXSYS_assert(pArray != NULL && iCount > 0);
- FX_INT32 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
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FXCRT_EXTENSION_
+#define _FXCRT_EXTENSION_
+#ifndef _FX_BASIC_H_
+#include "fx_basic.h"
+#endif
+#ifndef _FXCRT_COORDINATES_
+#include "fx_coordinates.h"
+#endif
+#ifndef _FX_XML_H_
+#include "fx_xml.h"
+#endif
+#ifndef _FX_UNICODE_
+#include "fx_ucd.h"
+#endif
+#ifndef _FX_ARABIC_
+#include "fx_arb.h"
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+FX_FLOAT FXSYS_tan(FX_FLOAT a);
+FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x);
+FX_FLOAT FXSYS_strtof(FX_LPCSTR pcsStr, FX_INT32 iLength = -1, FX_INT32 *pUsedLen = NULL);
+FX_FLOAT FXSYS_wcstof(FX_LPCWSTR pwsStr, FX_INT32 iLength = -1, FX_INT32 *pUsedLen = NULL);
+FX_LPWSTR FXSYS_wcsncpy(FX_LPWSTR dstStr, FX_LPCWSTR srcStr, size_t count);
+FX_INT32 FXSYS_wcsnicmp(FX_LPCWSTR s1, FX_LPCWSTR s2, size_t count);
+FX_INT32 FXSYS_strnicmp(FX_LPCSTR s1, FX_LPCSTR s2, size_t count);
+inline FX_BOOL FXSYS_islower(FX_INT32 ch)
+{
+ return ch >= 'a' && ch <= 'z';
+}
+inline FX_BOOL FXSYS_isupper(FX_INT32 ch)
+{
+ return ch >= 'A' && ch <= 'Z';
+}
+inline FX_INT32 FXSYS_tolower(FX_INT32 ch)
+{
+ return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20);
+}
+inline FX_INT32 FXSYS_toupper(FX_INT32 ch)
+{
+ return ch < 'a' || ch > 'z' ? ch : (ch - 0x20);
+}
+
+
+
+FX_DWORD FX_HashCode_String_GetA(FX_LPCSTR pStr, FX_INT32 iLength, FX_BOOL bIgnoreCase = FALSE);
+FX_DWORD FX_HashCode_String_GetW(FX_LPCWSTR pStr, FX_INT32 iLength, FX_BOOL bIgnoreCase = FALSE);
+
+#ifdef __cplusplus
+}
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+FX_LPVOID FX_Random_MT_Start(FX_DWORD dwSeed);
+
+FX_DWORD FX_Random_MT_Generate(FX_LPVOID pContext);
+
+void FX_Random_MT_Close(FX_LPVOID pContext);
+
+void FX_Random_GenerateBase(FX_LPDWORD pBuffer, FX_INT32 iCount);
+
+void FX_Random_GenerateMT(FX_LPDWORD pBuffer, FX_INT32 iCount);
+
+void FX_Random_GenerateCrypto(FX_LPDWORD pBuffer, FX_INT32 iCount);
+#ifdef __cplusplus
+}
+#endif
+template<class baseType>
+class CFX_SSortTemplate
+{
+public:
+ void ShellSort(baseType *pArray, FX_INT32 iCount)
+ {
+ FXSYS_assert(pArray != NULL && iCount > 0);
+ FX_INT32 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
diff --git a/core/include/fxcrt/fx_memory.h b/core/include/fxcrt/fx_memory.h
index b0c94c4c73..cf795fa869 100644
--- a/core/include/fxcrt/fx_memory.h
+++ b/core/include/fxcrt/fx_memory.h
@@ -1,300 +1,300 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FX_MEMORY_H_
-#define _FX_MEMORY_H_
-#ifndef _FX_SYSTEM_H_
-#include "fx_system.h"
-#endif
-#define FXMEM_NONLEAVE 1
-#define FXMEM_MOVABLE 2
-#define FXMEM_DISCARDABLE 4
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef struct _FXMEM_SystemMgr {
-
- void* (*Alloc)(struct _FXMEM_SystemMgr* pMgr, size_t size, int flags);
-
- void* (*AllocDebug)(struct _FXMEM_SystemMgr* pMgr, size_t size, int flags, FX_LPCSTR file, int line);
-
- void* (*Realloc)(struct _FXMEM_SystemMgr* pMgr, void* pointer, size_t size, int flags);
-
- void* (*ReallocDebug)(struct _FXMEM_SystemMgr* pMgr, void* pointer, size_t size, int flags, FX_LPCSTR file, int line);
-
- void* (*Lock)(struct _FXMEM_SystemMgr* pMgr, void* handle);
-
- void (*Unlock)(struct _FXMEM_SystemMgr* pMgr, void* handle);
-
- void (*Free)(struct _FXMEM_SystemMgr* pMgr, void* pointer, int flags);
-
- void (*Purge)(struct _FXMEM_SystemMgr* pMgr);
-
- void (*CollectAll)(struct _FXMEM_SystemMgr* pMgr);
-
-
- void* user;
-} FXMEM_SystemMgr;
-FX_DEFINEHANDLE(FXMEM_FoxitMgr)
-typedef struct _FXMEM_SystemMgr2 {
-
- FX_BOOL (*More)(struct _FXMEM_SystemMgr2* pMgr, size_t alloc_size, void** new_memory, size_t* new_size);
-
- void (*Free)(struct _FXMEM_SystemMgr2* pMgr, void* memory);
-} FXMEM_SystemMgr2;
-FXMEM_FoxitMgr* FXMEM_CreateMemoryMgr(size_t size, FX_BOOL extensible);
-void FXMEM_DestroyFoxitMgr(FXMEM_FoxitMgr* pFoxitMgr);
-void* FXMEM_DefaultAlloc(size_t byte_size, int flags);
-void* FXMEM_DefaultAlloc2(size_t units, size_t unit_size, int flags);
-void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags);
-void* FXMEM_DefaultRealloc2(void* pointer, size_t units, size_t unit_size, int flags);
-void FXMEM_DefaultFree(void* pointer, int flags);
-#define FX_Alloc(type, size) (type*)FXMEM_DefaultAlloc2(size, sizeof(type), 0)
-#define FX_Realloc(type, ptr, size) (type*)FXMEM_DefaultRealloc2(ptr, size, sizeof(type), 0)
-#define FX_AllocNL(type, size) (type*)FXMEM_DefaultAlloc2(size, sizeof(type), FXMEM_NONLEAVE)
-#define FX_ReallocNL(type, ptr, size) (type*)FXMEM_DefaultRealloc2(ptr, size, sizeof(type), FXMEM_NONLEAVE)
-#define FX_Free(pointer) FXMEM_DefaultFree(pointer, 0)
-#ifdef __cplusplus
-}
-#endif
-#ifdef __cplusplus
-#if defined(_DEBUG)
-#define FX_NEW new(__FILE__, __LINE__)
-#else
-
-#define FX_NEW new
-#endif
-class CFX_Object
-{
-public:
-
- void* operator new (size_t size, FX_LPCSTR file, int line);
-
- void operator delete (void* p, FX_LPCSTR file, int line);
-
- void* operator new (size_t size);
-
- void operator delete (void* p);
-
- void* operator new[] (size_t size, FX_LPCSTR file, int line);
-
- void operator delete[] (void* p, FX_LPCSTR file, int line);
-
- void* operator new[] (size_t size);
-
- void operator delete[] (void* p);
-
- void* operator new (size_t, void* buf)
- {
- return buf;
- }
-
- void operator delete (void*, void*) {}
-};
-#define FX_NEW_VECTOR(Pointer, Class, Count) \
- { \
- Pointer = FX_Alloc(Class, Count); \
- if (Pointer) { \
- for (int i = 0; i < (Count); i ++) new (Pointer + i) Class; \
- } \
- }
-#define FX_DELETE_VECTOR(Pointer, Class, Count) \
- { \
- for (int i = 0; i < (Count); i ++) Pointer[i].~Class(); \
- FX_Free(Pointer); \
- }
-class CFX_DestructObject : public CFX_Object
-{
-public:
-
- virtual ~CFX_DestructObject() {}
-};
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef struct _IFX_Allocator {
-
- void* (*m_AllocDebug)(struct _IFX_Allocator* pAllocator, size_t size, FX_LPCSTR file, int line);
-
- void* (*m_Alloc)(struct _IFX_Allocator* pAllocator, size_t size);
-
- void* (*m_ReallocDebug)(struct _IFX_Allocator* pAllocator, void* p, size_t size, FX_LPCSTR file, int line);
-
- void* (*m_Realloc)(struct _IFX_Allocator* pAllocator, void* p, size_t size);
-
- void (*m_Free)(struct _IFX_Allocator* pAllocator, void* p);
-} IFX_Allocator;
-IFX_Allocator* FXMEM_GetDefAllocator();
-#ifdef __cplusplus
-}
-#endif
-#ifdef _DEBUG
-
-#define FX_Allocator_Alloc(fxAllocator, type, size) \
- ((fxAllocator) ? (type*)(fxAllocator)->m_AllocDebug((fxAllocator), (size) * sizeof(type), __FILE__, __LINE__) : (FX_Alloc(type, size)))
-
-#define FX_Allocator_Realloc(fxAllocator, type, ptr, new_size) \
- ((fxAllocator) ? (type*)(fxAllocator)->m_ReallocDebug((fxAllocator), (ptr), (new_size) * sizeof(type), __FILE__, __LINE__) : (FX_Realloc(type, ptr, new_size)))
-#else
-
-#define FX_Allocator_Alloc(fxAllocator, type, size) \
- ((fxAllocator) ? (type*)(fxAllocator)->m_Alloc((fxAllocator), (size) * sizeof(type)) : (FX_Alloc(type, size)))
-
-#define FX_Allocator_Realloc(fxAllocator, type, ptr, new_size) \
- ((fxAllocator) ? (type*)(fxAllocator)->m_Realloc((fxAllocator), (ptr), (new_size) * sizeof(type)) : (FX_Realloc(type, ptr, new_size)))
-#endif
-#define FX_Allocator_Free(fxAllocator, ptr) \
- ((fxAllocator) ? (fxAllocator)->m_Free((fxAllocator), (ptr)) : (FX_Free(ptr)))
-inline void* operator new(size_t size, IFX_Allocator* fxAllocator)
-{
- return (void*)FX_Allocator_Alloc(fxAllocator, FX_BYTE, size);
-}
-inline void operator delete(void* ptr, IFX_Allocator* fxAllocator)
-{
-}
-#define FX_NewAtAllocator(fxAllocator) \
- ::new(fxAllocator)
-#define FX_DeleteAtAllocator(pointer, fxAllocator, __class__) \
- (pointer)->~__class__(); \
- FX_Allocator_Free(fxAllocator, pointer)
-class CFX_AllocObject
-{
-public:
-
- void* operator new (size_t size, IFX_Allocator* pAllocator, FX_LPCSTR file, int line);
-#ifndef _FX_NO_EXCEPTION_
-
- void operator delete (void* p, IFX_Allocator* pAllocator, FX_LPCSTR file, int line);
-#endif
-
- void* operator new (size_t size, IFX_Allocator* pAllocator);
-
- void operator delete (void* p);
-#ifndef _FX_NO_EXCEPTION_
-
- void operator delete (void* p, IFX_Allocator* pAllocator);
-#endif
-
- void* operator new (size_t, void* buf)
- {
- return buf;
- }
-#ifndef _FX_NO_EXCEPTION_
-
- void operator delete (void*, void*) {}
-#endif
-
- IFX_Allocator* GetAllocator() const
- {
- return m_pAllocator;
- }
-private:
-
- void* operator new[] (size_t size, IFX_Allocator* pAllocator, FX_LPCSTR file, int line)
- {
- return operator new(size, pAllocator, file, line);
- }
-#ifndef _FX_NO_EXCEPTION_
-
- void operator delete[] (void* p, IFX_Allocator* pAllocator, FX_LPCSTR file, int line) {}
-#endif
-
- void* operator new[] (size_t size, IFX_Allocator* pAllocator)
- {
- return operator new(size, pAllocator);
- }
-
- void operator delete[] (void* p) {}
-#ifndef _FX_NO_EXCEPTION_
-
- void operator delete[] (void* p, IFX_Allocator* pAllocator) {}
-#endif
-protected:
-
- IFX_Allocator* m_pAllocator;
-};
-#if defined(_DEBUG)
-#define FX_NEWAT(pAllocator) new(pAllocator, __FILE__, __LINE__)
-#else
-
-#define FX_NEWAT(pAllocator) new(pAllocator)
-#endif
-class CFX_GrowOnlyPool : public IFX_Allocator, public CFX_Object
-{
-public:
-
- CFX_GrowOnlyPool(IFX_Allocator* pAllocator = NULL, size_t trunk_size = 16384);
-
- ~CFX_GrowOnlyPool();
-
- void SetAllocator(IFX_Allocator* pAllocator);
-
- void SetTrunkSize(size_t trunk_size)
- {
- m_TrunkSize = trunk_size;
- }
-
- void* AllocDebug(size_t size, FX_LPCSTR file, int line)
- {
- return Alloc(size);
- }
-
- void* Alloc(size_t size);
-
- void* ReallocDebug(void* p, size_t new_size, FX_LPCSTR file, int line)
- {
- return NULL;
- }
-
- void* Realloc(void* p, size_t new_size)
- {
- return NULL;
- }
-
- void Free(void*) {}
-
- void FreeAll();
-private:
-
- size_t m_TrunkSize;
-
- void* m_pFirstTrunk;
-
- IFX_Allocator* m_pAllocator;
-};
-#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
-#define FX_FIXEDMEM_PAGESIZE (4096 * 16)
-#define FX_FIXEDMEM_MIDBLOCKSIZE (4096)
-typedef struct _FX_MEMCONFIG {
-
- size_t nPageNum_Init8;
-
- size_t nPageNum_Init16;
-
- size_t nPageNum_Init32;
-
- size_t nPageNum_More16;
-
- size_t nPageNum_More32;
-
- size_t nPageSize_Mid;
-
- size_t nPageNum_InitMid;
-
- size_t nPageNum_MoreMid;
-
- size_t nPageSize_Large;
-
- size_t nPageSize_Alone;
-} FX_MEMCONFIG;
-void FXMEM_SetConfig(const FX_MEMCONFIG* memConfig);
-#ifdef __cplusplus
-}
-#endif
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FX_MEMORY_H_
+#define _FX_MEMORY_H_
+#ifndef _FX_SYSTEM_H_
+#include "fx_system.h"
+#endif
+#define FXMEM_NONLEAVE 1
+#define FXMEM_MOVABLE 2
+#define FXMEM_DISCARDABLE 4
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef struct _FXMEM_SystemMgr {
+
+ void* (*Alloc)(struct _FXMEM_SystemMgr* pMgr, size_t size, int flags);
+
+ void* (*AllocDebug)(struct _FXMEM_SystemMgr* pMgr, size_t size, int flags, FX_LPCSTR file, int line);
+
+ void* (*Realloc)(struct _FXMEM_SystemMgr* pMgr, void* pointer, size_t size, int flags);
+
+ void* (*ReallocDebug)(struct _FXMEM_SystemMgr* pMgr, void* pointer, size_t size, int flags, FX_LPCSTR file, int line);
+
+ void* (*Lock)(struct _FXMEM_SystemMgr* pMgr, void* handle);
+
+ void (*Unlock)(struct _FXMEM_SystemMgr* pMgr, void* handle);
+
+ void (*Free)(struct _FXMEM_SystemMgr* pMgr, void* pointer, int flags);
+
+ void (*Purge)(struct _FXMEM_SystemMgr* pMgr);
+
+ void (*CollectAll)(struct _FXMEM_SystemMgr* pMgr);
+
+
+ void* user;
+} FXMEM_SystemMgr;
+FX_DEFINEHANDLE(FXMEM_FoxitMgr)
+typedef struct _FXMEM_SystemMgr2 {
+
+ FX_BOOL (*More)(struct _FXMEM_SystemMgr2* pMgr, size_t alloc_size, void** new_memory, size_t* new_size);
+
+ void (*Free)(struct _FXMEM_SystemMgr2* pMgr, void* memory);
+} FXMEM_SystemMgr2;
+FXMEM_FoxitMgr* FXMEM_CreateMemoryMgr(size_t size, FX_BOOL extensible);
+void FXMEM_DestroyFoxitMgr(FXMEM_FoxitMgr* pFoxitMgr);
+void* FXMEM_DefaultAlloc(size_t byte_size, int flags);
+void* FXMEM_DefaultAlloc2(size_t units, size_t unit_size, int flags);
+void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags);
+void* FXMEM_DefaultRealloc2(void* pointer, size_t units, size_t unit_size, int flags);
+void FXMEM_DefaultFree(void* pointer, int flags);
+#define FX_Alloc(type, size) (type*)FXMEM_DefaultAlloc2(size, sizeof(type), 0)
+#define FX_Realloc(type, ptr, size) (type*)FXMEM_DefaultRealloc2(ptr, size, sizeof(type), 0)
+#define FX_AllocNL(type, size) (type*)FXMEM_DefaultAlloc2(size, sizeof(type), FXMEM_NONLEAVE)
+#define FX_ReallocNL(type, ptr, size) (type*)FXMEM_DefaultRealloc2(ptr, size, sizeof(type), FXMEM_NONLEAVE)
+#define FX_Free(pointer) FXMEM_DefaultFree(pointer, 0)
+#ifdef __cplusplus
+}
+#endif
+#ifdef __cplusplus
+#if defined(_DEBUG)
+#define FX_NEW new(__FILE__, __LINE__)
+#else
+
+#define FX_NEW new
+#endif
+class CFX_Object
+{
+public:
+
+ void* operator new (size_t size, FX_LPCSTR file, int line);
+
+ void operator delete (void* p, FX_LPCSTR file, int line);
+
+ void* operator new (size_t size);
+
+ void operator delete (void* p);
+
+ void* operator new[] (size_t size, FX_LPCSTR file, int line);
+
+ void operator delete[] (void* p, FX_LPCSTR file, int line);
+
+ void* operator new[] (size_t size);
+
+ void operator delete[] (void* p);
+
+ void* operator new (size_t, void* buf)
+ {
+ return buf;
+ }
+
+ void operator delete (void*, void*) {}
+};
+#define FX_NEW_VECTOR(Pointer, Class, Count) \
+ { \
+ Pointer = FX_Alloc(Class, Count); \
+ if (Pointer) { \
+ for (int i = 0; i < (Count); i ++) new (Pointer + i) Class; \
+ } \
+ }
+#define FX_DELETE_VECTOR(Pointer, Class, Count) \
+ { \
+ for (int i = 0; i < (Count); i ++) Pointer[i].~Class(); \
+ FX_Free(Pointer); \
+ }
+class CFX_DestructObject : public CFX_Object
+{
+public:
+
+ virtual ~CFX_DestructObject() {}
+};
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef struct _IFX_Allocator {
+
+ void* (*m_AllocDebug)(struct _IFX_Allocator* pAllocator, size_t size, FX_LPCSTR file, int line);
+
+ void* (*m_Alloc)(struct _IFX_Allocator* pAllocator, size_t size);
+
+ void* (*m_ReallocDebug)(struct _IFX_Allocator* pAllocator, void* p, size_t size, FX_LPCSTR file, int line);
+
+ void* (*m_Realloc)(struct _IFX_Allocator* pAllocator, void* p, size_t size);
+
+ void (*m_Free)(struct _IFX_Allocator* pAllocator, void* p);
+} IFX_Allocator;
+IFX_Allocator* FXMEM_GetDefAllocator();
+#ifdef __cplusplus
+}
+#endif
+#ifdef _DEBUG
+
+#define FX_Allocator_Alloc(fxAllocator, type, size) \
+ ((fxAllocator) ? (type*)(fxAllocator)->m_AllocDebug((fxAllocator), (size) * sizeof(type), __FILE__, __LINE__) : (FX_Alloc(type, size)))
+
+#define FX_Allocator_Realloc(fxAllocator, type, ptr, new_size) \
+ ((fxAllocator) ? (type*)(fxAllocator)->m_ReallocDebug((fxAllocator), (ptr), (new_size) * sizeof(type), __FILE__, __LINE__) : (FX_Realloc(type, ptr, new_size)))
+#else
+
+#define FX_Allocator_Alloc(fxAllocator, type, size) \
+ ((fxAllocator) ? (type*)(fxAllocator)->m_Alloc((fxAllocator), (size) * sizeof(type)) : (FX_Alloc(type, size)))
+
+#define FX_Allocator_Realloc(fxAllocator, type, ptr, new_size) \
+ ((fxAllocator) ? (type*)(fxAllocator)->m_Realloc((fxAllocator), (ptr), (new_size) * sizeof(type)) : (FX_Realloc(type, ptr, new_size)))
+#endif
+#define FX_Allocator_Free(fxAllocator, ptr) \
+ ((fxAllocator) ? (fxAllocator)->m_Free((fxAllocator), (ptr)) : (FX_Free(ptr)))
+inline void* operator new(size_t size, IFX_Allocator* fxAllocator)
+{
+ return (void*)FX_Allocator_Alloc(fxAllocator, FX_BYTE, size);
+}
+inline void operator delete(void* ptr, IFX_Allocator* fxAllocator)
+{
+}
+#define FX_NewAtAllocator(fxAllocator) \
+ ::new(fxAllocator)
+#define FX_DeleteAtAllocator(pointer, fxAllocator, __class__) \
+ (pointer)->~__class__(); \
+ FX_Allocator_Free(fxAllocator, pointer)
+class CFX_AllocObject
+{
+public:
+
+ void* operator new (size_t size, IFX_Allocator* pAllocator, FX_LPCSTR file, int line);
+#ifndef _FX_NO_EXCEPTION_
+
+ void operator delete (void* p, IFX_Allocator* pAllocator, FX_LPCSTR file, int line);
+#endif
+
+ void* operator new (size_t size, IFX_Allocator* pAllocator);
+
+ void operator delete (void* p);
+#ifndef _FX_NO_EXCEPTION_
+
+ void operator delete (void* p, IFX_Allocator* pAllocator);
+#endif
+
+ void* operator new (size_t, void* buf)
+ {
+ return buf;
+ }
+#ifndef _FX_NO_EXCEPTION_
+
+ void operator delete (void*, void*) {}
+#endif
+
+ IFX_Allocator* GetAllocator() const
+ {
+ return m_pAllocator;
+ }
+private:
+
+ void* operator new[] (size_t size, IFX_Allocator* pAllocator, FX_LPCSTR file, int line)
+ {
+ return operator new(size, pAllocator, file, line);
+ }
+#ifndef _FX_NO_EXCEPTION_
+
+ void operator delete[] (void* p, IFX_Allocator* pAllocator, FX_LPCSTR file, int line) {}
+#endif
+
+ void* operator new[] (size_t size, IFX_Allocator* pAllocator)
+ {
+ return operator new(size, pAllocator);
+ }
+
+ void operator delete[] (void* p) {}
+#ifndef _FX_NO_EXCEPTION_
+
+ void operator delete[] (void* p, IFX_Allocator* pAllocator) {}
+#endif
+protected:
+
+ IFX_Allocator* m_pAllocator;
+};
+#if defined(_DEBUG)
+#define FX_NEWAT(pAllocator) new(pAllocator, __FILE__, __LINE__)
+#else
+
+#define FX_NEWAT(pAllocator) new(pAllocator)
+#endif
+class CFX_GrowOnlyPool : public IFX_Allocator, public CFX_Object
+{
+public:
+
+ CFX_GrowOnlyPool(IFX_Allocator* pAllocator = NULL, size_t trunk_size = 16384);
+
+ ~CFX_GrowOnlyPool();
+
+ void SetAllocator(IFX_Allocator* pAllocator);
+
+ void SetTrunkSize(size_t trunk_size)
+ {
+ m_TrunkSize = trunk_size;
+ }
+
+ void* AllocDebug(size_t size, FX_LPCSTR file, int line)
+ {
+ return Alloc(size);
+ }
+
+ void* Alloc(size_t size);
+
+ void* ReallocDebug(void* p, size_t new_size, FX_LPCSTR file, int line)
+ {
+ return NULL;
+ }
+
+ void* Realloc(void* p, size_t new_size)
+ {
+ return NULL;
+ }
+
+ void Free(void*) {}
+
+ void FreeAll();
+private:
+
+ size_t m_TrunkSize;
+
+ void* m_pFirstTrunk;
+
+ IFX_Allocator* m_pAllocator;
+};
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define FX_FIXEDMEM_PAGESIZE (4096 * 16)
+#define FX_FIXEDMEM_MIDBLOCKSIZE (4096)
+typedef struct _FX_MEMCONFIG {
+
+ size_t nPageNum_Init8;
+
+ size_t nPageNum_Init16;
+
+ size_t nPageNum_Init32;
+
+ size_t nPageNum_More16;
+
+ size_t nPageNum_More32;
+
+ size_t nPageSize_Mid;
+
+ size_t nPageNum_InitMid;
+
+ size_t nPageNum_MoreMid;
+
+ size_t nPageSize_Large;
+
+ size_t nPageSize_Alone;
+} FX_MEMCONFIG;
+void FXMEM_SetConfig(const FX_MEMCONFIG* memConfig);
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/core/include/fxcrt/fx_stream.h b/core/include/fxcrt/fx_stream.h
index cda5253365..869797f7e9 100644
--- a/core/include/fxcrt/fx_stream.h
+++ b/core/include/fxcrt/fx_stream.h
@@ -1,200 +1,200 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FX_STREAM_H_
-#define _FX_STREAM_H_
-#ifndef _FX_MEMORY_H_
-#include "fx_memory.h"
-#endif
-void* FX_OpenFolder(FX_LPCSTR path);
-void* FX_OpenFolder(FX_LPCWSTR 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);
-void FX_CloseFolder(void* handle);
-FX_WCHAR FX_GetFolderSeparator();
-FX_DEFINEHANDLE(FX_HFILE)
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
-#define FX_FILESIZE FX_INT32
-#else
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-#ifndef O_LARGEFILE
-#define O_LARGEFILE 0
-#endif
-#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) ((FX_BYTE)(a>>24))
-#define FX_GETBYTEOFFSET16(a) ((FX_BYTE)(a>>16))
-#define FX_GETBYTEOFFSET8(a) ((FX_BYTE)(a>>8))
-#define FX_GETBYTEOFFSET0(a) ((FX_BYTE)(a))
-#define FX_FILEMODE_Write 0
-#define FX_FILEMODE_ReadOnly 1
-#define FX_FILEMODE_Truncate 2
-FX_HFILE FX_File_Open(FX_BSTR fileName, FX_DWORD dwMode, IFX_Allocator* pAllocator = NULL);
-FX_HFILE FX_File_Open(FX_WSTR fileName, FX_DWORD dwMode, IFX_Allocator* pAllocator = NULL);
-void FX_File_Close(FX_HFILE hFile, IFX_Allocator* pAllocator = NULL);
-FX_FILESIZE FX_File_GetSize(FX_HFILE hFile);
-FX_FILESIZE FX_File_GetPosition(FX_HFILE hFile);
-FX_FILESIZE FX_File_SetPosition(FX_HFILE hFile, FX_FILESIZE pos);
-size_t FX_File_Read(FX_HFILE hFile, void* pBuffer, size_t szBuffer);
-size_t FX_File_ReadPos(FX_HFILE hFile, void* pBuffer, size_t szBuffer, FX_FILESIZE pos);
-size_t FX_File_Write(FX_HFILE hFile, const void* pBuffer, size_t szBuffer);
-size_t FX_File_WritePos(FX_HFILE hFile, const void* pBuffer, size_t szBuffer, FX_FILESIZE pos);
-FX_BOOL FX_File_Flush(FX_HFILE hFile);
-FX_BOOL FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile);
-FX_BOOL FX_File_Exist(FX_BSTR fileName);
-FX_BOOL FX_File_Exist(FX_WSTR fileName);
-FX_BOOL FX_File_Delete(FX_BSTR fileName);
-FX_BOOL FX_File_Delete(FX_WSTR fileName);
-FX_BOOL FX_File_Copy(FX_BSTR fileNameSrc, FX_BSTR fileNameDst);
-FX_BOOL FX_File_Copy(FX_WSTR fileNameSrc, FX_WSTR fileNameDst);
-FX_BOOL FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst);
-FX_BOOL FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst);
-class IFX_StreamWrite
-{
-public:
-
- virtual void Release() = 0;
-
- virtual FX_BOOL WriteBlock(const void* pData, size_t size) = 0;
-};
-class IFX_FileWrite : public IFX_StreamWrite
-{
-public:
-
- virtual void Release() = 0;
-
- virtual FX_FILESIZE GetSize() = 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);
- }
-};
-IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename, IFX_Allocator* pAllocator = NULL);
-IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename, IFX_Allocator* pAllocator = NULL);
-class IFX_StreamRead
-{
-public:
-
- virtual void Release() = 0;
-
- virtual FX_BOOL IsEOF() = 0;
-
- virtual FX_FILESIZE GetPosition() = 0;
-
- virtual size_t ReadBlock(void* buffer, size_t size) = 0;
-};
-class IFX_FileRead : IFX_StreamRead
-{
-public:
-
- virtual void Release() = 0;
-
- virtual FX_FILESIZE GetSize() = 0;
-
- virtual FX_BOOL IsEOF()
- {
- return FALSE;
- }
-
- virtual FX_FILESIZE GetPosition()
- {
- return 0;
- }
-
- virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_FILESIZE size)
- {
- return FALSE;
- }
-
- virtual void ClearRange() {}
-
- virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0;
-
- virtual size_t ReadBlock(void* buffer, size_t size)
- {
- return 0;
- }
-};
-IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename, IFX_Allocator* pAllocator = NULL);
-IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename, IFX_Allocator* pAllocator = NULL);
-class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite
-{
-public:
-
- virtual IFX_FileStream* Retain() = 0;
-
- virtual void Release() = 0;
-
- virtual FX_FILESIZE GetSize() = 0;
-
- virtual FX_BOOL IsEOF() = 0;
-
- virtual FX_FILESIZE GetPosition() = 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 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;
-};
-IFX_FileStream* FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes, IFX_Allocator* pAllocator = NULL);
-IFX_FileStream* FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes, IFX_Allocator* pAllocator = NULL);
-class IFX_MemoryStream : public IFX_FileStream
-{
-public:
-
- virtual FX_BOOL IsConsecutive() const = 0;
-
- virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0;
-
- virtual FX_LPBYTE GetBuffer() const = 0;
-
- virtual void AttachBuffer(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) = 0;
-
- virtual void DetachBuffer() = 0;
-};
-IFX_MemoryStream* FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE, IFX_Allocator* pAllocator = NULL);
-IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE, IFX_Allocator* pAllocator = NULL);
-class IFX_BufferRead : public IFX_StreamRead
-{
-public:
-
- virtual void Release() = 0;
-
- virtual FX_BOOL IsEOF() = 0;
-
- virtual FX_FILESIZE GetPosition() = 0;
-
- virtual size_t ReadBlock(void* buffer, size_t size) = 0;
-
- virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) = 0;
-
- virtual FX_LPCBYTE GetBlockBuffer() = 0;
-
- virtual size_t GetBlockSize() = 0;
-
- virtual FX_FILESIZE GetBlockOffset() = 0;
-};
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FX_STREAM_H_
+#define _FX_STREAM_H_
+#ifndef _FX_MEMORY_H_
+#include "fx_memory.h"
+#endif
+void* FX_OpenFolder(FX_LPCSTR path);
+void* FX_OpenFolder(FX_LPCWSTR 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);
+void FX_CloseFolder(void* handle);
+FX_WCHAR FX_GetFolderSeparator();
+FX_DEFINEHANDLE(FX_HFILE)
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+#define FX_FILESIZE FX_INT32
+#else
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
+#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) ((FX_BYTE)(a>>24))
+#define FX_GETBYTEOFFSET16(a) ((FX_BYTE)(a>>16))
+#define FX_GETBYTEOFFSET8(a) ((FX_BYTE)(a>>8))
+#define FX_GETBYTEOFFSET0(a) ((FX_BYTE)(a))
+#define FX_FILEMODE_Write 0
+#define FX_FILEMODE_ReadOnly 1
+#define FX_FILEMODE_Truncate 2
+FX_HFILE FX_File_Open(FX_BSTR fileName, FX_DWORD dwMode, IFX_Allocator* pAllocator = NULL);
+FX_HFILE FX_File_Open(FX_WSTR fileName, FX_DWORD dwMode, IFX_Allocator* pAllocator = NULL);
+void FX_File_Close(FX_HFILE hFile, IFX_Allocator* pAllocator = NULL);
+FX_FILESIZE FX_File_GetSize(FX_HFILE hFile);
+FX_FILESIZE FX_File_GetPosition(FX_HFILE hFile);
+FX_FILESIZE FX_File_SetPosition(FX_HFILE hFile, FX_FILESIZE pos);
+size_t FX_File_Read(FX_HFILE hFile, void* pBuffer, size_t szBuffer);
+size_t FX_File_ReadPos(FX_HFILE hFile, void* pBuffer, size_t szBuffer, FX_FILESIZE pos);
+size_t FX_File_Write(FX_HFILE hFile, const void* pBuffer, size_t szBuffer);
+size_t FX_File_WritePos(FX_HFILE hFile, const void* pBuffer, size_t szBuffer, FX_FILESIZE pos);
+FX_BOOL FX_File_Flush(FX_HFILE hFile);
+FX_BOOL FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile);
+FX_BOOL FX_File_Exist(FX_BSTR fileName);
+FX_BOOL FX_File_Exist(FX_WSTR fileName);
+FX_BOOL FX_File_Delete(FX_BSTR fileName);
+FX_BOOL FX_File_Delete(FX_WSTR fileName);
+FX_BOOL FX_File_Copy(FX_BSTR fileNameSrc, FX_BSTR fileNameDst);
+FX_BOOL FX_File_Copy(FX_WSTR fileNameSrc, FX_WSTR fileNameDst);
+FX_BOOL FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst);
+FX_BOOL FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst);
+class IFX_StreamWrite
+{
+public:
+
+ virtual void Release() = 0;
+
+ virtual FX_BOOL WriteBlock(const void* pData, size_t size) = 0;
+};
+class IFX_FileWrite : public IFX_StreamWrite
+{
+public:
+
+ virtual void Release() = 0;
+
+ virtual FX_FILESIZE GetSize() = 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);
+ }
+};
+IFX_FileWrite* FX_CreateFileWrite(FX_LPCSTR filename, IFX_Allocator* pAllocator = NULL);
+IFX_FileWrite* FX_CreateFileWrite(FX_LPCWSTR filename, IFX_Allocator* pAllocator = NULL);
+class IFX_StreamRead
+{
+public:
+
+ virtual void Release() = 0;
+
+ virtual FX_BOOL IsEOF() = 0;
+
+ virtual FX_FILESIZE GetPosition() = 0;
+
+ virtual size_t ReadBlock(void* buffer, size_t size) = 0;
+};
+class IFX_FileRead : IFX_StreamRead
+{
+public:
+
+ virtual void Release() = 0;
+
+ virtual FX_FILESIZE GetSize() = 0;
+
+ virtual FX_BOOL IsEOF()
+ {
+ return FALSE;
+ }
+
+ virtual FX_FILESIZE GetPosition()
+ {
+ return 0;
+ }
+
+ virtual FX_BOOL SetRange(FX_FILESIZE offset, FX_FILESIZE size)
+ {
+ return FALSE;
+ }
+
+ virtual void ClearRange() {}
+
+ virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0;
+
+ virtual size_t ReadBlock(void* buffer, size_t size)
+ {
+ return 0;
+ }
+};
+IFX_FileRead* FX_CreateFileRead(FX_LPCSTR filename, IFX_Allocator* pAllocator = NULL);
+IFX_FileRead* FX_CreateFileRead(FX_LPCWSTR filename, IFX_Allocator* pAllocator = NULL);
+class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite
+{
+public:
+
+ virtual IFX_FileStream* Retain() = 0;
+
+ virtual void Release() = 0;
+
+ virtual FX_FILESIZE GetSize() = 0;
+
+ virtual FX_BOOL IsEOF() = 0;
+
+ virtual FX_FILESIZE GetPosition() = 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 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;
+};
+IFX_FileStream* FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes, IFX_Allocator* pAllocator = NULL);
+IFX_FileStream* FX_CreateFileStream(FX_LPCWSTR filename, FX_DWORD dwModes, IFX_Allocator* pAllocator = NULL);
+class IFX_MemoryStream : public IFX_FileStream
+{
+public:
+
+ virtual FX_BOOL IsConsecutive() const = 0;
+
+ virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0;
+
+ virtual FX_LPBYTE GetBuffer() const = 0;
+
+ virtual void AttachBuffer(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE) = 0;
+
+ virtual void DetachBuffer() = 0;
+};
+IFX_MemoryStream* FX_CreateMemoryStream(FX_LPBYTE pBuffer, size_t nSize, FX_BOOL bTakeOver = FALSE, IFX_Allocator* pAllocator = NULL);
+IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE, IFX_Allocator* pAllocator = NULL);
+class IFX_BufferRead : public IFX_StreamRead
+{
+public:
+
+ virtual void Release() = 0;
+
+ virtual FX_BOOL IsEOF() = 0;
+
+ virtual FX_FILESIZE GetPosition() = 0;
+
+ virtual size_t ReadBlock(void* buffer, size_t size) = 0;
+
+ virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) = 0;
+
+ virtual FX_LPCBYTE GetBlockBuffer() = 0;
+
+ virtual size_t GetBlockSize() = 0;
+
+ virtual FX_FILESIZE GetBlockOffset() = 0;
+};
+#endif
diff --git a/core/include/fxcrt/fx_string.h b/core/include/fxcrt/fx_string.h
index 563964cdf7..08fb83cfd7 100644
--- a/core/include/fxcrt/fx_string.h
+++ b/core/include/fxcrt/fx_string.h
@@ -1,870 +1,870 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FX_STRING_H_
-#define _FX_STRING_H_
-class CFX_ByteStringC;
-class CFX_ByteString;
-class CFX_WideStringC;
-class CFX_WideString;
-struct CFX_CharMap;
-class CFX_BinaryBuf;
-typedef int FX_STRSIZE;
-class CFX_ByteStringL;
-class CFX_WideStringL;
-class CFX_ByteStringC : public CFX_Object
-{
-public:
-
- CFX_ByteStringC()
- {
- m_Ptr = NULL;
- m_Length = 0;
- }
-
- CFX_ByteStringC(FX_LPCBYTE ptr, FX_STRSIZE size)
- {
- m_Ptr = ptr;
- m_Length = size;
- }
-
- CFX_ByteStringC(FX_LPCSTR ptr)
- {
- m_Ptr = (FX_LPCBYTE)ptr;
- m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0;
- }
-
- CFX_ByteStringC(FX_CHAR& ch)
- {
- m_Ptr = (FX_LPCBYTE)&ch;
- m_Length = 1;
- }
-
- CFX_ByteStringC(FX_LPCSTR ptr, FX_STRSIZE len)
- {
- m_Ptr = (FX_LPCBYTE)ptr;
- if (len == -1) {
- m_Length = (FX_STRSIZE)FXSYS_strlen(ptr);
- } else {
- m_Length = 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 = (FX_LPCSTR src)
- {
- m_Ptr = (FX_LPCBYTE)src;
- m_Length = (FX_STRSIZE)FXSYS_strlen(src);
- return *this;
- }
-
- CFX_ByteStringC& operator = (const CFX_ByteStringC& src)
- {
- m_Ptr = src.m_Ptr;
- m_Length = src.m_Length;
- return *this;
- }
-
- CFX_ByteStringC& operator = (const CFX_ByteString& src);
-
- bool operator == (const CFX_ByteStringC& str) const
- {
- return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length) == 0;
- }
-
- bool operator != (const CFX_ByteStringC& str) const
- {
- return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length) != 0;
- }
-#define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4))
-
- FX_DWORD GetID(FX_STRSIZE start_pos = 0) const;
-
- FX_LPCBYTE GetPtr() const
- {
- return m_Ptr;
- }
-
- FX_LPCSTR GetCStr() const
- {
- return (FX_LPCSTR)m_Ptr;
- }
-
- FX_STRSIZE GetLength() const
- {
- return m_Length;
- }
-
- bool IsEmpty() const
- {
- return m_Length == 0;
- }
-
- operator FX_LPCBYTE() const
- {
- return m_Ptr;
- }
-
- FX_BYTE GetAt(FX_STRSIZE index) const
- {
- return m_Ptr[index];
- }
-
- 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);
- }
-protected:
-
- FX_LPCBYTE m_Ptr;
-
- FX_STRSIZE m_Length;
-private:
-
- void* operator new (size_t) throw()
- {
- return NULL;
- }
-};
-typedef const CFX_ByteStringC& FX_BSTR;
-#define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1)
-struct CFX_StringData {
-
- long m_nRefs;
-
- FX_STRSIZE m_nDataLength;
-
- FX_STRSIZE m_nAllocLength;
-
- FX_CHAR m_String[1];
-};
-class CFX_ByteString : public CFX_Object
-{
-public:
-
- CFX_ByteString()
- {
- m_pData = NULL;
- }
-
- CFX_ByteString(const CFX_ByteString& str);
-
- CFX_ByteString(char ch);
-
- CFX_ByteString(FX_LPCSTR ptr, FX_STRSIZE len = -1);
-
- CFX_ByteString(FX_LPCBYTE ptr, FX_STRSIZE len);
-
- CFX_ByteString(FX_BSTR bstrc);
-
- CFX_ByteString(FX_BSTR bstrc1, FX_BSTR bstrc2);
-
- ~CFX_ByteString();
-
- static CFX_ByteString FromUnicode(FX_LPCWSTR ptr, FX_STRSIZE len = -1);
-
- static CFX_ByteString FromUnicode(const CFX_WideString& str);
-
- operator FX_LPCSTR() const
- {
- return m_pData ? m_pData->m_String : "";
- }
-
- operator FX_LPCBYTE() const
- {
- return m_pData ? (FX_LPCBYTE)m_pData->m_String : NULL;
- }
-
- FX_STRSIZE GetLength() const
- {
- return m_pData ? m_pData->m_nDataLength : 0;
- }
-
- bool IsEmpty() const
- {
- return !GetLength();
- }
-
- int Compare(FX_BSTR str) const;
-
-
- bool Equal(FX_BSTR str) const;
-
-
- bool EqualNoCase(FX_BSTR str) const;
-
- bool operator == (FX_LPCSTR str) const
- {
- return Equal(str);
- }
-
- bool operator == (FX_BSTR str) const
- {
- return Equal(str);
- }
-
- bool operator == (const CFX_ByteString& str) const;
-
- bool operator != (FX_LPCSTR str) const
- {
- return !Equal(str);
- }
-
- bool operator != (FX_BSTR str) const
- {
- return !Equal(str);
- }
-
- bool operator != (const CFX_ByteString& str) const
- {
- return !operator==(str);
- }
-
- void Empty();
-
- const CFX_ByteString& operator = (FX_LPCSTR str);
-
- const CFX_ByteString& operator = (FX_BSTR bstrc);
-
- const CFX_ByteString& operator = (const CFX_ByteString& stringSrc);
-
- const CFX_ByteString& operator = (const CFX_BinaryBuf& buf);
-
- void Load(FX_LPCBYTE str, FX_STRSIZE len);
-
- const CFX_ByteString& operator += (FX_CHAR ch);
-
- const CFX_ByteString& operator += (FX_LPCSTR str);
-
- const CFX_ByteString& operator += (const CFX_ByteString& str);
-
- const CFX_ByteString& operator += (FX_BSTR bstrc);
-
- FX_BYTE GetAt(FX_STRSIZE nIndex) const
- {
- return m_pData ? m_pData->m_String[nIndex] : 0;
- }
-
- FX_BYTE operator[](FX_STRSIZE nIndex) const
- {
- return m_pData ? m_pData->m_String[nIndex] : 0;
- }
-
- void SetAt(FX_STRSIZE nIndex, FX_CHAR ch);
-
- FX_STRSIZE Insert(FX_STRSIZE index, FX_CHAR ch);
-
- FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1);
-
-
- void Format(FX_LPCSTR lpszFormat, ... );
-
- void FormatV(FX_LPCSTR lpszFormat, va_list argList);
-
-
- void Reserve(FX_STRSIZE len);
-
- FX_LPSTR GetBuffer(FX_STRSIZE len);
-
- FX_LPSTR LockBuffer();
-
- void ReleaseBuffer(FX_STRSIZE len = -1);
-
- CFX_ByteString Mid(FX_STRSIZE first) const;
-
- CFX_ByteString Mid(FX_STRSIZE first, FX_STRSIZE count) const;
-
- CFX_ByteString Left(FX_STRSIZE count) const;
-
- CFX_ByteString Right(FX_STRSIZE count) const;
-
- FX_STRSIZE Find(FX_BSTR lpszSub, FX_STRSIZE start = 0) const;
-
- FX_STRSIZE Find(FX_CHAR ch, FX_STRSIZE start = 0) const;
-
- FX_STRSIZE ReverseFind(FX_CHAR ch) const;
-
- void MakeLower();
-
- void MakeUpper();
-
- void TrimRight();
-
- void TrimRight(FX_CHAR chTarget);
-
- void TrimRight(FX_BSTR lpszTargets);
-
- void TrimLeft();
-
- void TrimLeft(FX_CHAR chTarget);
-
- void TrimLeft(FX_BSTR lpszTargets);
-
- FX_STRSIZE Replace(FX_BSTR lpszOld, FX_BSTR lpszNew);
-
- FX_STRSIZE Remove(FX_CHAR ch);
-
- CFX_WideString UTF8Decode() const;
-
- void ConvertFrom(const CFX_WideString& str, CFX_CharMap* pCharMap = NULL);
-
- FX_DWORD GetID(FX_STRSIZE start_pos = 0) const;
-
- static CFX_ByteString LoadFromFile(FX_BSTR file_path);
-#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);
-protected:
-
- struct CFX_StringData* m_pData;
- void AllocCopy(CFX_ByteString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex, FX_STRSIZE nExtraLen) const;
- void AssignCopy(FX_STRSIZE nSrcLen, FX_LPCSTR lpszSrcData);
- void ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCSTR lpszSrc1Data, FX_STRSIZE nSrc2Len, FX_LPCSTR lpszSrc2Data);
- void ConcatInPlace(FX_STRSIZE nSrcLen, FX_LPCSTR lpszSrcData);
- void CopyBeforeWrite();
- void AllocBeforeWrite(FX_STRSIZE nLen);
-};
-inline CFX_ByteStringC::CFX_ByteStringC(const CFX_ByteString& src)
-{
- m_Ptr = (FX_LPCBYTE)src;
- m_Length = src.GetLength();
-}
-inline CFX_ByteStringC& CFX_ByteStringC::operator = (const CFX_ByteString& src)
-{
- m_Ptr = (FX_LPCBYTE)src;
- m_Length = src.GetLength();
- return *this;
-}
-
-inline CFX_ByteString operator + (FX_BSTR str1, FX_BSTR str2)
-{
- return CFX_ByteString(str1, str2);
-}
-inline CFX_ByteString operator + (FX_BSTR str1, FX_LPCSTR str2)
-{
- return CFX_ByteString(str1, str2);
-}
-inline CFX_ByteString operator + (FX_LPCSTR str1, FX_BSTR str2)
-{
- return CFX_ByteString(str1, str2);
-}
-inline CFX_ByteString operator + (FX_BSTR str1, FX_CHAR ch)
-{
- return CFX_ByteString(str1, CFX_ByteStringC(ch));
-}
-inline CFX_ByteString operator + (FX_CHAR ch, FX_BSTR 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, 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 + (const CFX_ByteString& str1, FX_LPCSTR str2)
-{
- return CFX_ByteString(str1, str2);
-}
-inline CFX_ByteString operator + (FX_LPCSTR str1, const CFX_ByteString& str2)
-{
- return CFX_ByteString(str1, str2);
-}
-inline CFX_ByteString operator + (const CFX_ByteString& str1, FX_BSTR str2)
-{
- return CFX_ByteString(str1, str2);
-}
-inline CFX_ByteString operator + (FX_BSTR str1, const CFX_ByteString& str2)
-{
- return CFX_ByteString(str1, str2);
-}
-class CFX_StringBufBase : public CFX_Object
-{
-public:
-
- CFX_StringBufBase(FX_STRSIZE limit)
- {
- m_Size = 0;
- m_Limit = limit;
- }
-
- FX_CHAR* GetPtr() const
- {
- return (FX_CHAR*)(this + 1);
- }
-
- FX_STRSIZE GetSize() const
- {
- return m_Size;
- }
-
- void Empty()
- {
- m_Size = 0;
- }
-
- void Copy(FX_BSTR str);
-
- void Append(FX_BSTR str);
-
- void Append(int i, FX_DWORD flags = 0);
-
- CFX_ByteStringC GetStringC() const
- {
- return CFX_ByteStringC((FX_CHAR*)(this + 1), m_Size);
- }
-
- CFX_ByteString GetString() const
- {
- return CFX_ByteString((FX_CHAR*)(this + 1), m_Size);
- }
-protected:
-
- FX_STRSIZE m_Limit;
-
- FX_STRSIZE m_Size;
-};
-template<FX_STRSIZE limit>
-class CFX_StringBufTemplate : public CFX_StringBufBase
-{
-public:
-
- CFX_StringBufTemplate() : CFX_StringBufBase(limit) {}
-
- FX_CHAR m_Buffer[limit];
-};
-typedef CFX_StringBufTemplate<256> CFX_StringBuf256;
-class CFX_WideStringC : public CFX_Object
-{
-public:
-
- CFX_WideStringC()
- {
- m_Ptr = NULL;
- m_Length = 0;
- }
-
- CFX_WideStringC(FX_LPCWSTR ptr)
- {
- m_Ptr = ptr;
- m_Length = ptr ? (FX_STRSIZE)FXSYS_wcslen(ptr) : 0;
- }
-
- CFX_WideStringC(FX_WCHAR& ch)
- {
- m_Ptr = &ch;
- m_Length = 1;
- }
-
- CFX_WideStringC(FX_LPCWSTR ptr, FX_STRSIZE len)
- {
- m_Ptr = ptr;
- if (len == -1) {
- m_Length = (FX_STRSIZE)FXSYS_wcslen(ptr);
- } else {
- m_Length = len;
- }
- }
-
- CFX_WideStringC(const CFX_WideStringC& src)
- {
- m_Ptr = src.m_Ptr;
- m_Length = src.m_Length;
- }
-
- CFX_WideStringC(const CFX_WideString& src);
-
- CFX_WideStringC& operator = (FX_LPCWSTR src)
- {
- m_Ptr = src;
- m_Length = (FX_STRSIZE)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_WideString& src);
-
- bool operator == (const CFX_WideStringC& str) const
- {
- return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length * sizeof(FX_WCHAR)) == 0;
- }
-
- bool operator != (const CFX_WideStringC& str) const
- {
- return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length * sizeof(FX_WCHAR)) != 0;
- }
-
- FX_LPCWSTR GetPtr() const
- {
- return m_Ptr;
- }
-
- FX_STRSIZE GetLength() const
- {
- return m_Length;
- }
-
- bool IsEmpty() const
- {
- return m_Length == 0;
- }
-
- 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 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);
- }
-
- 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);
- }
-protected:
-
- FX_LPCWSTR m_Ptr;
-
- FX_STRSIZE m_Length;
-private:
-
- void* operator new (size_t) throw()
- {
- return NULL;
- }
-};
-typedef const CFX_WideStringC& FX_WSTR;
-#define FX_WSTRC(wstr) CFX_WideStringC((FX_LPCWSTR)wstr, sizeof(wstr) / sizeof(FX_WCHAR) - 1)
-struct CFX_StringDataW {
-
- long m_nRefs;
-
- FX_STRSIZE m_nDataLength;
-
- FX_STRSIZE m_nAllocLength;
-
- FX_WCHAR m_String[1];
-};
-class CFX_WideString : public CFX_Object
-{
-public:
-
- CFX_WideString()
- {
- m_pData = NULL;
- }
-
- CFX_WideString(const CFX_WideString& str);
-
- CFX_WideString(FX_LPCWSTR ptr, FX_STRSIZE len = -1)
- {
- InitStr(ptr, len);
- }
-
- CFX_WideString(FX_WCHAR ch);
-
- CFX_WideString(const CFX_WideStringC& str);
-
- CFX_WideString(const CFX_WideStringC& str1, const CFX_WideStringC& str2);
-
- ~CFX_WideString();
-
- static CFX_WideString FromLocal(const char* str, FX_STRSIZE len = -1);
-
- static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len = -1);
-
- static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len = -1);
-
- operator FX_LPCWSTR() const
- {
- return m_pData ? m_pData->m_String : (FX_WCHAR*)L"";
- }
-
- void Empty();
-
-
- FX_BOOL IsEmpty() const
- {
- return !GetLength();
- }
-
- FX_STRSIZE GetLength() const
- {
- return m_pData ? m_pData->m_nDataLength : 0;
- }
-
- const CFX_WideString& operator = (FX_LPCWSTR str);
-
- const CFX_WideString& operator =(const CFX_WideString& stringSrc);
-
- const CFX_WideString& operator =(const CFX_WideStringC& stringSrc);
-
- const CFX_WideString& operator += (FX_LPCWSTR str);
-
- const CFX_WideString& operator += (FX_WCHAR ch);
-
- const CFX_WideString& operator += (const CFX_WideString& str);
-
- const CFX_WideString& operator += (const CFX_WideStringC& str);
-
- 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;
- }
-
- void SetAt(FX_STRSIZE nIndex, FX_WCHAR ch);
-
- int Compare(FX_LPCWSTR str) const;
-
- int Compare(const CFX_WideString& str) const;
-
- int CompareNoCase(FX_LPCWSTR str) const;
-
- bool Equal(const CFX_WideStringC& str) const;
-
- CFX_WideString Mid(FX_STRSIZE first) const;
-
- CFX_WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const;
-
- CFX_WideString Left(FX_STRSIZE count) const;
-
- CFX_WideString Right(FX_STRSIZE count) const;
-
- FX_STRSIZE Insert(FX_STRSIZE index, FX_WCHAR ch);
-
- FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1);
-
- void Format(FX_LPCWSTR lpszFormat, ... );
-
- void FormatV(FX_LPCWSTR lpszFormat, va_list argList);
-
- void MakeLower();
-
- void MakeUpper();
-
- void TrimRight();
-
- void TrimRight(FX_WCHAR chTarget);
-
- void TrimRight(FX_LPCWSTR lpszTargets);
-
- void TrimLeft();
-
- void TrimLeft(FX_WCHAR chTarget);
-
- void TrimLeft(FX_LPCWSTR lpszTargets);
-
- void Reserve(FX_STRSIZE len);
-
- FX_LPWSTR GetBuffer(FX_STRSIZE len);
-
- FX_LPWSTR LockBuffer();
-
- void ReleaseBuffer(FX_STRSIZE len = -1);
-
- int GetInteger() const;
-
- FX_FLOAT GetFloat() const;
-
- FX_STRSIZE Find(FX_LPCWSTR lpszSub, FX_STRSIZE start = 0) const;
-
- FX_STRSIZE Find(FX_WCHAR ch, FX_STRSIZE start = 0) const;
-
- FX_STRSIZE Replace(FX_LPCWSTR lpszOld, FX_LPCWSTR lpszNew);
-
- FX_STRSIZE Remove(FX_WCHAR ch);
-
- CFX_ByteString UTF8Encode() const;
-
- CFX_ByteString UTF16LE_Encode(FX_BOOL bTerminate = TRUE) const;
-
- void ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMap = NULL);
-protected:
- void InitStr(FX_LPCWSTR ptr, int len);
-
- CFX_StringDataW* m_pData;
- void CopyBeforeWrite();
- void AllocBeforeWrite(FX_STRSIZE nLen);
- void ConcatInPlace(FX_STRSIZE nSrcLen, FX_LPCWSTR lpszSrcData);
- void ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCWSTR lpszSrc1Data, FX_STRSIZE nSrc2Len, FX_LPCWSTR lpszSrc2Data);
- void AssignCopy(FX_STRSIZE nSrcLen, FX_LPCWSTR lpszSrcData);
- void AllocCopy(CFX_WideString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex, FX_STRSIZE nExtraLen) const;
-};
-inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src)
-{
- m_Ptr = (FX_LPCWSTR)src;
- m_Length = src.GetLength();
-}
-inline CFX_WideStringC& CFX_WideStringC::operator = (const CFX_WideString& src)
-{
- m_Ptr = (FX_LPCWSTR)src;
- 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, FX_LPCWSTR str2)
-{
- return CFX_WideString(str1, str2);
-}
-inline CFX_WideString operator + (FX_LPCWSTR 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 + (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, 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 + (const CFX_WideString& str1, FX_LPCWSTR str2)
-{
- return CFX_WideString(str1, str2);
-}
-inline CFX_WideString operator + (FX_LPCWSTR 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_WideStringC& str1, const CFX_WideString& str2)
-{
- return CFX_WideString(str1, str2);
-}
-
-bool operator==(const CFX_WideString& s1, const CFX_WideString& s2);
-bool operator==(const CFX_WideString& s1, const CFX_WideStringC& s2);
-bool operator==(const CFX_WideStringC& s1, const CFX_WideString& s2);
-bool operator== (const CFX_WideString& s1, FX_LPCWSTR s2);
-bool operator==(FX_LPCWSTR s1, const CFX_WideString& s2);
-bool operator!=(const CFX_WideString& s1, const CFX_WideString& s2);
-bool operator!=(const CFX_WideString& s1, const CFX_WideStringC& s2);
-bool operator!=(const CFX_WideStringC& s1, const CFX_WideString& s2);
-bool operator!= (const CFX_WideString& s1, FX_LPCWSTR s2);
-bool operator!=(FX_LPCWSTR s1, const CFX_WideString& s2);
-FX_FLOAT FX_atof(FX_BSTR str);
-void FX_atonum(FX_BSTR str, FX_BOOL& bInteger, void* pData);
-FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf);
-CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len);
-inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr)
-{
- return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength());
-}
-inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr)
-{
- return FX_UTF8Encode((FX_LPCWSTR)wsStr, wsStr.GetLength());
-}
-class CFX_ByteStringL : public CFX_ByteStringC
-{
-public:
- CFX_ByteStringL() : CFX_ByteStringC() {}
- ~CFX_ByteStringL() {}
-
- void Empty(IFX_Allocator* pAllocator);
- FX_LPSTR AllocBuffer(FX_STRSIZE length, IFX_Allocator* pAllocator);
-
- void Set(FX_BSTR src, IFX_Allocator* pAllocator);
-};
-class CFX_WideStringL : public CFX_WideStringC
-{
-public:
- CFX_WideStringL() : CFX_WideStringC() {}
- ~CFX_WideStringL() {}
-
- void Empty(IFX_Allocator* pAllocator);
- void Set(FX_WSTR src, IFX_Allocator* pAllocator);
-
- int GetInteger() const;
- FX_FLOAT GetFloat() const;
-
- void TrimRight(FX_LPCWSTR lpszTargets);
-};
-void FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len, CFX_ByteStringL &utf8Str, IFX_Allocator* pAllocator = NULL);
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FX_STRING_H_
+#define _FX_STRING_H_
+class CFX_ByteStringC;
+class CFX_ByteString;
+class CFX_WideStringC;
+class CFX_WideString;
+struct CFX_CharMap;
+class CFX_BinaryBuf;
+typedef int FX_STRSIZE;
+class CFX_ByteStringL;
+class CFX_WideStringL;
+class CFX_ByteStringC : public CFX_Object
+{
+public:
+
+ CFX_ByteStringC()
+ {
+ m_Ptr = NULL;
+ m_Length = 0;
+ }
+
+ CFX_ByteStringC(FX_LPCBYTE ptr, FX_STRSIZE size)
+ {
+ m_Ptr = ptr;
+ m_Length = size;
+ }
+
+ CFX_ByteStringC(FX_LPCSTR ptr)
+ {
+ m_Ptr = (FX_LPCBYTE)ptr;
+ m_Length = ptr ? (FX_STRSIZE)FXSYS_strlen(ptr) : 0;
+ }
+
+ CFX_ByteStringC(FX_CHAR& ch)
+ {
+ m_Ptr = (FX_LPCBYTE)&ch;
+ m_Length = 1;
+ }
+
+ CFX_ByteStringC(FX_LPCSTR ptr, FX_STRSIZE len)
+ {
+ m_Ptr = (FX_LPCBYTE)ptr;
+ if (len == -1) {
+ m_Length = (FX_STRSIZE)FXSYS_strlen(ptr);
+ } else {
+ m_Length = 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 = (FX_LPCSTR src)
+ {
+ m_Ptr = (FX_LPCBYTE)src;
+ m_Length = (FX_STRSIZE)FXSYS_strlen(src);
+ return *this;
+ }
+
+ CFX_ByteStringC& operator = (const CFX_ByteStringC& src)
+ {
+ m_Ptr = src.m_Ptr;
+ m_Length = src.m_Length;
+ return *this;
+ }
+
+ CFX_ByteStringC& operator = (const CFX_ByteString& src);
+
+ bool operator == (const CFX_ByteStringC& str) const
+ {
+ return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length) == 0;
+ }
+
+ bool operator != (const CFX_ByteStringC& str) const
+ {
+ return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length) != 0;
+ }
+#define FXBSTR_ID(c1, c2, c3, c4) ((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4))
+
+ FX_DWORD GetID(FX_STRSIZE start_pos = 0) const;
+
+ FX_LPCBYTE GetPtr() const
+ {
+ return m_Ptr;
+ }
+
+ FX_LPCSTR GetCStr() const
+ {
+ return (FX_LPCSTR)m_Ptr;
+ }
+
+ FX_STRSIZE GetLength() const
+ {
+ return m_Length;
+ }
+
+ bool IsEmpty() const
+ {
+ return m_Length == 0;
+ }
+
+ operator FX_LPCBYTE() const
+ {
+ return m_Ptr;
+ }
+
+ FX_BYTE GetAt(FX_STRSIZE index) const
+ {
+ return m_Ptr[index];
+ }
+
+ 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);
+ }
+protected:
+
+ FX_LPCBYTE m_Ptr;
+
+ FX_STRSIZE m_Length;
+private:
+
+ void* operator new (size_t) throw()
+ {
+ return NULL;
+ }
+};
+typedef const CFX_ByteStringC& FX_BSTR;
+#define FX_BSTRC(str) CFX_ByteStringC(str, sizeof str-1)
+struct CFX_StringData {
+
+ long m_nRefs;
+
+ FX_STRSIZE m_nDataLength;
+
+ FX_STRSIZE m_nAllocLength;
+
+ FX_CHAR m_String[1];
+};
+class CFX_ByteString : public CFX_Object
+{
+public:
+
+ CFX_ByteString()
+ {
+ m_pData = NULL;
+ }
+
+ CFX_ByteString(const CFX_ByteString& str);
+
+ CFX_ByteString(char ch);
+
+ CFX_ByteString(FX_LPCSTR ptr, FX_STRSIZE len = -1);
+
+ CFX_ByteString(FX_LPCBYTE ptr, FX_STRSIZE len);
+
+ CFX_ByteString(FX_BSTR bstrc);
+
+ CFX_ByteString(FX_BSTR bstrc1, FX_BSTR bstrc2);
+
+ ~CFX_ByteString();
+
+ static CFX_ByteString FromUnicode(FX_LPCWSTR ptr, FX_STRSIZE len = -1);
+
+ static CFX_ByteString FromUnicode(const CFX_WideString& str);
+
+ operator FX_LPCSTR() const
+ {
+ return m_pData ? m_pData->m_String : "";
+ }
+
+ operator FX_LPCBYTE() const
+ {
+ return m_pData ? (FX_LPCBYTE)m_pData->m_String : NULL;
+ }
+
+ FX_STRSIZE GetLength() const
+ {
+ return m_pData ? m_pData->m_nDataLength : 0;
+ }
+
+ bool IsEmpty() const
+ {
+ return !GetLength();
+ }
+
+ int Compare(FX_BSTR str) const;
+
+
+ bool Equal(FX_BSTR str) const;
+
+
+ bool EqualNoCase(FX_BSTR str) const;
+
+ bool operator == (FX_LPCSTR str) const
+ {
+ return Equal(str);
+ }
+
+ bool operator == (FX_BSTR str) const
+ {
+ return Equal(str);
+ }
+
+ bool operator == (const CFX_ByteString& str) const;
+
+ bool operator != (FX_LPCSTR str) const
+ {
+ return !Equal(str);
+ }
+
+ bool operator != (FX_BSTR str) const
+ {
+ return !Equal(str);
+ }
+
+ bool operator != (const CFX_ByteString& str) const
+ {
+ return !operator==(str);
+ }
+
+ void Empty();
+
+ const CFX_ByteString& operator = (FX_LPCSTR str);
+
+ const CFX_ByteString& operator = (FX_BSTR bstrc);
+
+ const CFX_ByteString& operator = (const CFX_ByteString& stringSrc);
+
+ const CFX_ByteString& operator = (const CFX_BinaryBuf& buf);
+
+ void Load(FX_LPCBYTE str, FX_STRSIZE len);
+
+ const CFX_ByteString& operator += (FX_CHAR ch);
+
+ const CFX_ByteString& operator += (FX_LPCSTR str);
+
+ const CFX_ByteString& operator += (const CFX_ByteString& str);
+
+ const CFX_ByteString& operator += (FX_BSTR bstrc);
+
+ FX_BYTE GetAt(FX_STRSIZE nIndex) const
+ {
+ return m_pData ? m_pData->m_String[nIndex] : 0;
+ }
+
+ FX_BYTE operator[](FX_STRSIZE nIndex) const
+ {
+ return m_pData ? m_pData->m_String[nIndex] : 0;
+ }
+
+ void SetAt(FX_STRSIZE nIndex, FX_CHAR ch);
+
+ FX_STRSIZE Insert(FX_STRSIZE index, FX_CHAR ch);
+
+ FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1);
+
+
+ void Format(FX_LPCSTR lpszFormat, ... );
+
+ void FormatV(FX_LPCSTR lpszFormat, va_list argList);
+
+
+ void Reserve(FX_STRSIZE len);
+
+ FX_LPSTR GetBuffer(FX_STRSIZE len);
+
+ FX_LPSTR LockBuffer();
+
+ void ReleaseBuffer(FX_STRSIZE len = -1);
+
+ CFX_ByteString Mid(FX_STRSIZE first) const;
+
+ CFX_ByteString Mid(FX_STRSIZE first, FX_STRSIZE count) const;
+
+ CFX_ByteString Left(FX_STRSIZE count) const;
+
+ CFX_ByteString Right(FX_STRSIZE count) const;
+
+ FX_STRSIZE Find(FX_BSTR lpszSub, FX_STRSIZE start = 0) const;
+
+ FX_STRSIZE Find(FX_CHAR ch, FX_STRSIZE start = 0) const;
+
+ FX_STRSIZE ReverseFind(FX_CHAR ch) const;
+
+ void MakeLower();
+
+ void MakeUpper();
+
+ void TrimRight();
+
+ void TrimRight(FX_CHAR chTarget);
+
+ void TrimRight(FX_BSTR lpszTargets);
+
+ void TrimLeft();
+
+ void TrimLeft(FX_CHAR chTarget);
+
+ void TrimLeft(FX_BSTR lpszTargets);
+
+ FX_STRSIZE Replace(FX_BSTR lpszOld, FX_BSTR lpszNew);
+
+ FX_STRSIZE Remove(FX_CHAR ch);
+
+ CFX_WideString UTF8Decode() const;
+
+ void ConvertFrom(const CFX_WideString& str, CFX_CharMap* pCharMap = NULL);
+
+ FX_DWORD GetID(FX_STRSIZE start_pos = 0) const;
+
+ static CFX_ByteString LoadFromFile(FX_BSTR file_path);
+#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);
+protected:
+
+ struct CFX_StringData* m_pData;
+ void AllocCopy(CFX_ByteString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex, FX_STRSIZE nExtraLen) const;
+ void AssignCopy(FX_STRSIZE nSrcLen, FX_LPCSTR lpszSrcData);
+ void ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCSTR lpszSrc1Data, FX_STRSIZE nSrc2Len, FX_LPCSTR lpszSrc2Data);
+ void ConcatInPlace(FX_STRSIZE nSrcLen, FX_LPCSTR lpszSrcData);
+ void CopyBeforeWrite();
+ void AllocBeforeWrite(FX_STRSIZE nLen);
+};
+inline CFX_ByteStringC::CFX_ByteStringC(const CFX_ByteString& src)
+{
+ m_Ptr = (FX_LPCBYTE)src;
+ m_Length = src.GetLength();
+}
+inline CFX_ByteStringC& CFX_ByteStringC::operator = (const CFX_ByteString& src)
+{
+ m_Ptr = (FX_LPCBYTE)src;
+ m_Length = src.GetLength();
+ return *this;
+}
+
+inline CFX_ByteString operator + (FX_BSTR str1, FX_BSTR str2)
+{
+ return CFX_ByteString(str1, str2);
+}
+inline CFX_ByteString operator + (FX_BSTR str1, FX_LPCSTR str2)
+{
+ return CFX_ByteString(str1, str2);
+}
+inline CFX_ByteString operator + (FX_LPCSTR str1, FX_BSTR str2)
+{
+ return CFX_ByteString(str1, str2);
+}
+inline CFX_ByteString operator + (FX_BSTR str1, FX_CHAR ch)
+{
+ return CFX_ByteString(str1, CFX_ByteStringC(ch));
+}
+inline CFX_ByteString operator + (FX_CHAR ch, FX_BSTR 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, 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 + (const CFX_ByteString& str1, FX_LPCSTR str2)
+{
+ return CFX_ByteString(str1, str2);
+}
+inline CFX_ByteString operator + (FX_LPCSTR str1, const CFX_ByteString& str2)
+{
+ return CFX_ByteString(str1, str2);
+}
+inline CFX_ByteString operator + (const CFX_ByteString& str1, FX_BSTR str2)
+{
+ return CFX_ByteString(str1, str2);
+}
+inline CFX_ByteString operator + (FX_BSTR str1, const CFX_ByteString& str2)
+{
+ return CFX_ByteString(str1, str2);
+}
+class CFX_StringBufBase : public CFX_Object
+{
+public:
+
+ CFX_StringBufBase(FX_STRSIZE limit)
+ {
+ m_Size = 0;
+ m_Limit = limit;
+ }
+
+ FX_CHAR* GetPtr() const
+ {
+ return (FX_CHAR*)(this + 1);
+ }
+
+ FX_STRSIZE GetSize() const
+ {
+ return m_Size;
+ }
+
+ void Empty()
+ {
+ m_Size = 0;
+ }
+
+ void Copy(FX_BSTR str);
+
+ void Append(FX_BSTR str);
+
+ void Append(int i, FX_DWORD flags = 0);
+
+ CFX_ByteStringC GetStringC() const
+ {
+ return CFX_ByteStringC((FX_CHAR*)(this + 1), m_Size);
+ }
+
+ CFX_ByteString GetString() const
+ {
+ return CFX_ByteString((FX_CHAR*)(this + 1), m_Size);
+ }
+protected:
+
+ FX_STRSIZE m_Limit;
+
+ FX_STRSIZE m_Size;
+};
+template<FX_STRSIZE limit>
+class CFX_StringBufTemplate : public CFX_StringBufBase
+{
+public:
+
+ CFX_StringBufTemplate() : CFX_StringBufBase(limit) {}
+
+ FX_CHAR m_Buffer[limit];
+};
+typedef CFX_StringBufTemplate<256> CFX_StringBuf256;
+class CFX_WideStringC : public CFX_Object
+{
+public:
+
+ CFX_WideStringC()
+ {
+ m_Ptr = NULL;
+ m_Length = 0;
+ }
+
+ CFX_WideStringC(FX_LPCWSTR ptr)
+ {
+ m_Ptr = ptr;
+ m_Length = ptr ? (FX_STRSIZE)FXSYS_wcslen(ptr) : 0;
+ }
+
+ CFX_WideStringC(FX_WCHAR& ch)
+ {
+ m_Ptr = &ch;
+ m_Length = 1;
+ }
+
+ CFX_WideStringC(FX_LPCWSTR ptr, FX_STRSIZE len)
+ {
+ m_Ptr = ptr;
+ if (len == -1) {
+ m_Length = (FX_STRSIZE)FXSYS_wcslen(ptr);
+ } else {
+ m_Length = len;
+ }
+ }
+
+ CFX_WideStringC(const CFX_WideStringC& src)
+ {
+ m_Ptr = src.m_Ptr;
+ m_Length = src.m_Length;
+ }
+
+ CFX_WideStringC(const CFX_WideString& src);
+
+ CFX_WideStringC& operator = (FX_LPCWSTR src)
+ {
+ m_Ptr = src;
+ m_Length = (FX_STRSIZE)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_WideString& src);
+
+ bool operator == (const CFX_WideStringC& str) const
+ {
+ return str.m_Length == m_Length && FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length * sizeof(FX_WCHAR)) == 0;
+ }
+
+ bool operator != (const CFX_WideStringC& str) const
+ {
+ return str.m_Length != m_Length || FXSYS_memcmp32(str.m_Ptr, m_Ptr, m_Length * sizeof(FX_WCHAR)) != 0;
+ }
+
+ FX_LPCWSTR GetPtr() const
+ {
+ return m_Ptr;
+ }
+
+ FX_STRSIZE GetLength() const
+ {
+ return m_Length;
+ }
+
+ bool IsEmpty() const
+ {
+ return m_Length == 0;
+ }
+
+ 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 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);
+ }
+
+ 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);
+ }
+protected:
+
+ FX_LPCWSTR m_Ptr;
+
+ FX_STRSIZE m_Length;
+private:
+
+ void* operator new (size_t) throw()
+ {
+ return NULL;
+ }
+};
+typedef const CFX_WideStringC& FX_WSTR;
+#define FX_WSTRC(wstr) CFX_WideStringC((FX_LPCWSTR)wstr, sizeof(wstr) / sizeof(FX_WCHAR) - 1)
+struct CFX_StringDataW {
+
+ long m_nRefs;
+
+ FX_STRSIZE m_nDataLength;
+
+ FX_STRSIZE m_nAllocLength;
+
+ FX_WCHAR m_String[1];
+};
+class CFX_WideString : public CFX_Object
+{
+public:
+
+ CFX_WideString()
+ {
+ m_pData = NULL;
+ }
+
+ CFX_WideString(const CFX_WideString& str);
+
+ CFX_WideString(FX_LPCWSTR ptr, FX_STRSIZE len = -1)
+ {
+ InitStr(ptr, len);
+ }
+
+ CFX_WideString(FX_WCHAR ch);
+
+ CFX_WideString(const CFX_WideStringC& str);
+
+ CFX_WideString(const CFX_WideStringC& str1, const CFX_WideStringC& str2);
+
+ ~CFX_WideString();
+
+ static CFX_WideString FromLocal(const char* str, FX_STRSIZE len = -1);
+
+ static CFX_WideString FromUTF8(const char* str, FX_STRSIZE len = -1);
+
+ static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len = -1);
+
+ operator FX_LPCWSTR() const
+ {
+ return m_pData ? m_pData->m_String : (FX_WCHAR*)L"";
+ }
+
+ void Empty();
+
+
+ FX_BOOL IsEmpty() const
+ {
+ return !GetLength();
+ }
+
+ FX_STRSIZE GetLength() const
+ {
+ return m_pData ? m_pData->m_nDataLength : 0;
+ }
+
+ const CFX_WideString& operator = (FX_LPCWSTR str);
+
+ const CFX_WideString& operator =(const CFX_WideString& stringSrc);
+
+ const CFX_WideString& operator =(const CFX_WideStringC& stringSrc);
+
+ const CFX_WideString& operator += (FX_LPCWSTR str);
+
+ const CFX_WideString& operator += (FX_WCHAR ch);
+
+ const CFX_WideString& operator += (const CFX_WideString& str);
+
+ const CFX_WideString& operator += (const CFX_WideStringC& str);
+
+ 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;
+ }
+
+ void SetAt(FX_STRSIZE nIndex, FX_WCHAR ch);
+
+ int Compare(FX_LPCWSTR str) const;
+
+ int Compare(const CFX_WideString& str) const;
+
+ int CompareNoCase(FX_LPCWSTR str) const;
+
+ bool Equal(const CFX_WideStringC& str) const;
+
+ CFX_WideString Mid(FX_STRSIZE first) const;
+
+ CFX_WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const;
+
+ CFX_WideString Left(FX_STRSIZE count) const;
+
+ CFX_WideString Right(FX_STRSIZE count) const;
+
+ FX_STRSIZE Insert(FX_STRSIZE index, FX_WCHAR ch);
+
+ FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1);
+
+ void Format(FX_LPCWSTR lpszFormat, ... );
+
+ void FormatV(FX_LPCWSTR lpszFormat, va_list argList);
+
+ void MakeLower();
+
+ void MakeUpper();
+
+ void TrimRight();
+
+ void TrimRight(FX_WCHAR chTarget);
+
+ void TrimRight(FX_LPCWSTR lpszTargets);
+
+ void TrimLeft();
+
+ void TrimLeft(FX_WCHAR chTarget);
+
+ void TrimLeft(FX_LPCWSTR lpszTargets);
+
+ void Reserve(FX_STRSIZE len);
+
+ FX_LPWSTR GetBuffer(FX_STRSIZE len);
+
+ FX_LPWSTR LockBuffer();
+
+ void ReleaseBuffer(FX_STRSIZE len = -1);
+
+ int GetInteger() const;
+
+ FX_FLOAT GetFloat() const;
+
+ FX_STRSIZE Find(FX_LPCWSTR lpszSub, FX_STRSIZE start = 0) const;
+
+ FX_STRSIZE Find(FX_WCHAR ch, FX_STRSIZE start = 0) const;
+
+ FX_STRSIZE Replace(FX_LPCWSTR lpszOld, FX_LPCWSTR lpszNew);
+
+ FX_STRSIZE Remove(FX_WCHAR ch);
+
+ CFX_ByteString UTF8Encode() const;
+
+ CFX_ByteString UTF16LE_Encode(FX_BOOL bTerminate = TRUE) const;
+
+ void ConvertFrom(const CFX_ByteString& str, CFX_CharMap* pCharMap = NULL);
+protected:
+ void InitStr(FX_LPCWSTR ptr, int len);
+
+ CFX_StringDataW* m_pData;
+ void CopyBeforeWrite();
+ void AllocBeforeWrite(FX_STRSIZE nLen);
+ void ConcatInPlace(FX_STRSIZE nSrcLen, FX_LPCWSTR lpszSrcData);
+ void ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCWSTR lpszSrc1Data, FX_STRSIZE nSrc2Len, FX_LPCWSTR lpszSrc2Data);
+ void AssignCopy(FX_STRSIZE nSrcLen, FX_LPCWSTR lpszSrcData);
+ void AllocCopy(CFX_WideString& dest, FX_STRSIZE nCopyLen, FX_STRSIZE nCopyIndex, FX_STRSIZE nExtraLen) const;
+};
+inline CFX_WideStringC::CFX_WideStringC(const CFX_WideString& src)
+{
+ m_Ptr = (FX_LPCWSTR)src;
+ m_Length = src.GetLength();
+}
+inline CFX_WideStringC& CFX_WideStringC::operator = (const CFX_WideString& src)
+{
+ m_Ptr = (FX_LPCWSTR)src;
+ 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, FX_LPCWSTR str2)
+{
+ return CFX_WideString(str1, str2);
+}
+inline CFX_WideString operator + (FX_LPCWSTR 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 + (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, 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 + (const CFX_WideString& str1, FX_LPCWSTR str2)
+{
+ return CFX_WideString(str1, str2);
+}
+inline CFX_WideString operator + (FX_LPCWSTR 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_WideStringC& str1, const CFX_WideString& str2)
+{
+ return CFX_WideString(str1, str2);
+}
+
+bool operator==(const CFX_WideString& s1, const CFX_WideString& s2);
+bool operator==(const CFX_WideString& s1, const CFX_WideStringC& s2);
+bool operator==(const CFX_WideStringC& s1, const CFX_WideString& s2);
+bool operator== (const CFX_WideString& s1, FX_LPCWSTR s2);
+bool operator==(FX_LPCWSTR s1, const CFX_WideString& s2);
+bool operator!=(const CFX_WideString& s1, const CFX_WideString& s2);
+bool operator!=(const CFX_WideString& s1, const CFX_WideStringC& s2);
+bool operator!=(const CFX_WideStringC& s1, const CFX_WideString& s2);
+bool operator!= (const CFX_WideString& s1, FX_LPCWSTR s2);
+bool operator!=(FX_LPCWSTR s1, const CFX_WideString& s2);
+FX_FLOAT FX_atof(FX_BSTR str);
+void FX_atonum(FX_BSTR str, FX_BOOL& bInteger, void* pData);
+FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf);
+CFX_ByteString FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len);
+inline CFX_ByteString FX_UTF8Encode(FX_WSTR wsStr)
+{
+ return FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength());
+}
+inline CFX_ByteString FX_UTF8Encode(const CFX_WideString &wsStr)
+{
+ return FX_UTF8Encode((FX_LPCWSTR)wsStr, wsStr.GetLength());
+}
+class CFX_ByteStringL : public CFX_ByteStringC
+{
+public:
+ CFX_ByteStringL() : CFX_ByteStringC() {}
+ ~CFX_ByteStringL() {}
+
+ void Empty(IFX_Allocator* pAllocator);
+ FX_LPSTR AllocBuffer(FX_STRSIZE length, IFX_Allocator* pAllocator);
+
+ void Set(FX_BSTR src, IFX_Allocator* pAllocator);
+};
+class CFX_WideStringL : public CFX_WideStringC
+{
+public:
+ CFX_WideStringL() : CFX_WideStringC() {}
+ ~CFX_WideStringL() {}
+
+ void Empty(IFX_Allocator* pAllocator);
+ void Set(FX_WSTR src, IFX_Allocator* pAllocator);
+
+ int GetInteger() const;
+ FX_FLOAT GetFloat() const;
+
+ void TrimRight(FX_LPCWSTR lpszTargets);
+};
+void FX_UTF8Encode(FX_LPCWSTR pwsStr, FX_STRSIZE len, CFX_ByteStringL &utf8Str, IFX_Allocator* pAllocator = NULL);
+#endif
diff --git a/core/include/fxcrt/fx_system.h b/core/include/fxcrt/fx_system.h
index f72be0ffcb..0021c1437d 100644
--- a/core/include/fxcrt/fx_system.h
+++ b/core/include/fxcrt/fx_system.h
@@ -1,279 +1,279 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FX_SYSTEM_H_
-#define _FX_SYSTEM_H_
-#define _FX_WIN32_DESKTOP_ 1
-#define _FX_LINUX_DESKTOP_ 4
-#define _FX_MACOSX_ 7
-#define _FX_ANDROID_ 12
-#define _FXM_PLATFORM_WINDOWS_ 1
-#define _FXM_PLATFORM_LINUX_ 2
-#define _FXM_PLATFORM_APPLE_ 3
-#define _FXM_PLATFORM_ANDROID_ 4
-#ifndef _FX_OS_
-#if defined(__ANDROID__)
-#define _FX_OS_ _FX_ANDROID_
-#define _FXM_PLATFORM_ _FXM_PLATFORM_ANDROID_
-#elif defined(_WIN32) || defined(_WIN64)
-#define _FX_OS_ _FX_WIN32_DESKTOP_
-#define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_
-#elif defined(__linux__)
-#define _FX_OS_ _FX_LINUX_DESKTOP_
-#define _FXM_PLATFORM_ _FXM_PLATFORM_LINUX_
-#elif defined(__APPLE__)
-#define _FX_OS_ _FX_MACOSX_
-#define _FXM_PLATFORM_ _FXM_PLATFORM_APPLE_
-#endif
-#endif
-#if !defined(_FX_OS_) || _FX_OS_ == 0
-#error Sorry, can not figure out what OS you are targeting to. Please specify _FX_OS_ macro.
-#endif
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
-#define _CRT_SECURE_NO_WARNINGS
-#include <windows.h>
-#endif
-#define _FX_W32_ 1
-#define _FX_W64_ 2
-#ifndef _FX_WORDSIZE_
-#if defined(_WIN64) || defined(__arm64) || defined(__arm64__) || defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || defined(__powerpc64__) || defined(__x86_64__) || __WORDSIZE == 64
-#define _FX_WORDSIZE_ _FX_W64_
-#else
-#define _FX_WORDSIZE_ _FX_W32_
-#endif
-#endif
-#include <stddef.h>
-#include <stdarg.h>
-#include <setjmp.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <wchar.h>
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
-#include <libkern/OSAtomic.h>
-#if _FX_OS_ == _FX_MACOSX_
-#include <Carbon/Carbon.h>
-#elif _FX_OS_ == _FX_IOS_
-#include <CoreText/CoreText.h>
-#include <CoreGraphics/CoreGraphics.h>
-#endif
-#endif
-#ifdef __cplusplus
-extern "C" {
-#endif
-typedef void* FX_LPVOID;
-typedef void const* FX_LPCVOID;
-typedef void* FX_POSITION;
-typedef signed char FX_INT8;
-typedef unsigned char FX_UINT8;
-typedef unsigned char FX_BYTE;
-typedef unsigned char* FX_LPBYTE;
-typedef unsigned char const* FX_LPCBYTE;
-typedef short FX_INT16;
-typedef unsigned short FX_UINT16;
-typedef short FX_SHORT;
-typedef unsigned short FX_WORD;
-typedef unsigned short* FX_LPWORD;
-typedef unsigned short const* FX_LPCWORD;
-typedef int FX_INT32;
-typedef float FX_FLOAT;
-typedef int FX_BOOL;
-typedef int FX_ERR;
-#define FX_SUCCEEDED(Status) ((FX_ERR)(Status) >= 0)
-#define FX_FAILED(Status) ((FX_ERR)(Status) < 0)
-typedef char FX_CHAR;
-typedef char* FX_LPSTR;
-typedef char const* FX_LPCSTR;
-typedef unsigned int FX_DWORD;
-typedef unsigned int* FX_LPDWORD;
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
-typedef __int64 FX_INT64;
-typedef unsigned __int64 FX_UINT64;
-#else
-typedef long long int FX_INT64;
-typedef unsigned long long FX_UINT64;
-#endif
-#if _FX_WORDSIZE_ == _FX_W64_
-typedef FX_INT64 FX_INTPTR;
-typedef FX_UINT64 FX_UINTPTR;
-#else
-typedef int FX_INTPTR;
-typedef unsigned int FX_UINTPTR;
-#endif
-typedef wchar_t FX_WCHAR;
-typedef wchar_t* FX_LPWSTR;
-typedef wchar_t const* FX_LPCWSTR;
-typedef FX_DWORD FX_UINT32;
-typedef FX_UINT64 FX_QWORD;
-#define FX_DEFINEHANDLE(name) typedef struct _##name {FX_LPVOID pData;} * name;
-#if defined(DEBUG) && !defined(_DEBUG)
-#define _DEBUG
-#endif
-#ifndef TRUE
-
-#define TRUE 1
-#endif
-#ifndef FALSE
-
-#define FALSE 0
-#endif
-#ifndef NULL
-
-#define NULL 0
-#endif
-#define FXSYS_assert assert
-#ifndef ASSERT
-#ifdef _DEBUG
-#define ASSERT FXSYS_assert
-#else
-
-#define ASSERT(a)
-#endif
-#endif
-#define FX_MAX(a, b) (((a) > (b)) ? (a) : (b))
-#define FX_MIN(a, b) (((a) < (b)) ? (a) : (b))
-#define FX_PI 3.1415926535897932384626433832795f
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
-#define FXSYS_snprintf _snprintf
-#else
-#define FXSYS_snprintf snprintf
-#endif
-#define FXSYS_sprintf sprintf
-#define FXSYS_vsprintf vsprintf
-#define FXSYS_strchr strchr
-#define FXSYS_strlen strlen
-#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
-#define FXSYS_wfopen(f, m) _wfopen((const wchar_t*)(f), (const wchar_t*)(m))
-#else
-#define FXSYS_wfopen _wfopen
-#endif
-#else
-FXSYS_FILE* FXSYS_wfopen(FX_LPCWSTR filename, FX_LPCWSTR mode);
-#endif
-
-#define FXSYS_wcslen wcslen
-#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
-#define FXSYS_itoa _itoa
-#define FXSYS_strlwr _strlwr
-#define FXSYS_strupr _strupr
-#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_wcslwr(str) _wcslwr((wchar_t*)(str))
-#define FXSYS_wcsupr(str) _wcsupr((wchar_t*)(str))
-#else
-#define FXSYS_wcsicmp _wcsicmp
-#define FXSYS_WideCharToMultiByte WideCharToMultiByte
-#define FXSYS_MultiByteToWideChar MultiByteToWideChar
-#define FXSYS_wcslwr _wcslwr
-#define FXSYS_wcsupr _wcsupr
-#endif
-#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);
-#endif
-#define FXSYS_memcpy32 FXSYS_memcpy
-#define FXSYS_memcmp32 FXSYS_memcmp
-#define FXSYS_memset32 FXSYS_memset
-#define FXSYS_memset8 FXSYS_memset
-#define FXSYS_memmove32 FXSYS_memmove
-#ifdef __cplusplus
-}
-#endif
-#include <math.h>
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
-#define FXSYS_pow(a, b) (FX_FLOAT)powf(a, b)
-#else
-#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
-#ifdef __cplusplus
-extern "C" {
-#endif
-#define _FX_LSB_FIRST_
-#define FXDWORD_FROM_LSBFIRST(i) (i)
-#define FXDWORD_FROM_MSBFIRST(i) (((FX_BYTE)(i) << 24) | ((FX_BYTE)((i) >> 8) << 16) | ((FX_BYTE)((i) >> 16) << 8) | (FX_BYTE)((i) >> 24))
-#define FXDWORD_GET_LSBFIRST(p) ((((FX_LPBYTE)(p))[3] << 24) | (((FX_LPBYTE)(p))[2] << 16) | (((FX_LPBYTE)(p))[1] << 8) | (((FX_LPBYTE)(p))[0]))
-#define FXDWORD_GET_MSBFIRST(p) ((((FX_LPBYTE)(p))[0] << 24) | (((FX_LPBYTE)(p))[1] << 16) | (((FX_LPBYTE)(p))[2] << 8) | (((FX_LPBYTE)(p))[3]))
-#define FXSYS_HIBYTE(word) ((FX_BYTE)((word) >> 8))
-#define FXSYS_LOBYTE(word) ((FX_BYTE)(word))
-#define FXSYS_HIWORD(dword) ((FX_WORD)((dword) >> 16))
-#define FXSYS_LOWORD(dword) ((FX_WORD)(dword))
-FX_INT32 FXSYS_atoi(FX_LPCSTR str);
-FX_INT32 FXSYS_wtoi(FX_LPCWSTR str);
-FX_INT64 FXSYS_atoi64(FX_LPCSTR str);
-FX_INT64 FXSYS_wtoi64(FX_LPCWSTR str);
-FX_LPCSTR FXSYS_i64toa(FX_INT64 value, FX_LPSTR str, int radix);
-FX_LPCWSTR FXSYS_i64tow(FX_INT64 value, FX_LPWSTR 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
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FX_SYSTEM_H_
+#define _FX_SYSTEM_H_
+#define _FX_WIN32_DESKTOP_ 1
+#define _FX_LINUX_DESKTOP_ 4
+#define _FX_MACOSX_ 7
+#define _FX_ANDROID_ 12
+#define _FXM_PLATFORM_WINDOWS_ 1
+#define _FXM_PLATFORM_LINUX_ 2
+#define _FXM_PLATFORM_APPLE_ 3
+#define _FXM_PLATFORM_ANDROID_ 4
+#ifndef _FX_OS_
+#if defined(__ANDROID__)
+#define _FX_OS_ _FX_ANDROID_
+#define _FXM_PLATFORM_ _FXM_PLATFORM_ANDROID_
+#elif defined(_WIN32) || defined(_WIN64)
+#define _FX_OS_ _FX_WIN32_DESKTOP_
+#define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_
+#elif defined(__linux__)
+#define _FX_OS_ _FX_LINUX_DESKTOP_
+#define _FXM_PLATFORM_ _FXM_PLATFORM_LINUX_
+#elif defined(__APPLE__)
+#define _FX_OS_ _FX_MACOSX_
+#define _FXM_PLATFORM_ _FXM_PLATFORM_APPLE_
+#endif
+#endif
+#if !defined(_FX_OS_) || _FX_OS_ == 0
+#error Sorry, can not figure out what OS you are targeting to. Please specify _FX_OS_ macro.
+#endif
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+#define _CRT_SECURE_NO_WARNINGS
+#include <windows.h>
+#endif
+#define _FX_W32_ 1
+#define _FX_W64_ 2
+#ifndef _FX_WORDSIZE_
+#if defined(_WIN64) || defined(__arm64) || defined(__arm64__) || defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || defined(__powerpc64__) || defined(__x86_64__) || __WORDSIZE == 64
+#define _FX_WORDSIZE_ _FX_W64_
+#else
+#define _FX_WORDSIZE_ _FX_W32_
+#endif
+#endif
+#include <stddef.h>
+#include <stdarg.h>
+#include <setjmp.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <wchar.h>
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+#include <libkern/OSAtomic.h>
+#if _FX_OS_ == _FX_MACOSX_
+#include <Carbon/Carbon.h>
+#elif _FX_OS_ == _FX_IOS_
+#include <CoreText/CoreText.h>
+#include <CoreGraphics/CoreGraphics.h>
+#endif
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef void* FX_LPVOID;
+typedef void const* FX_LPCVOID;
+typedef void* FX_POSITION;
+typedef signed char FX_INT8;
+typedef unsigned char FX_UINT8;
+typedef unsigned char FX_BYTE;
+typedef unsigned char* FX_LPBYTE;
+typedef unsigned char const* FX_LPCBYTE;
+typedef short FX_INT16;
+typedef unsigned short FX_UINT16;
+typedef short FX_SHORT;
+typedef unsigned short FX_WORD;
+typedef unsigned short* FX_LPWORD;
+typedef unsigned short const* FX_LPCWORD;
+typedef int FX_INT32;
+typedef float FX_FLOAT;
+typedef int FX_BOOL;
+typedef int FX_ERR;
+#define FX_SUCCEEDED(Status) ((FX_ERR)(Status) >= 0)
+#define FX_FAILED(Status) ((FX_ERR)(Status) < 0)
+typedef char FX_CHAR;
+typedef char* FX_LPSTR;
+typedef char const* FX_LPCSTR;
+typedef unsigned int FX_DWORD;
+typedef unsigned int* FX_LPDWORD;
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+typedef __int64 FX_INT64;
+typedef unsigned __int64 FX_UINT64;
+#else
+typedef long long int FX_INT64;
+typedef unsigned long long FX_UINT64;
+#endif
+#if _FX_WORDSIZE_ == _FX_W64_
+typedef FX_INT64 FX_INTPTR;
+typedef FX_UINT64 FX_UINTPTR;
+#else
+typedef int FX_INTPTR;
+typedef unsigned int FX_UINTPTR;
+#endif
+typedef wchar_t FX_WCHAR;
+typedef wchar_t* FX_LPWSTR;
+typedef wchar_t const* FX_LPCWSTR;
+typedef FX_DWORD FX_UINT32;
+typedef FX_UINT64 FX_QWORD;
+#define FX_DEFINEHANDLE(name) typedef struct _##name {FX_LPVOID pData;} * name;
+#if defined(DEBUG) && !defined(_DEBUG)
+#define _DEBUG
+#endif
+#ifndef TRUE
+
+#define TRUE 1
+#endif
+#ifndef FALSE
+
+#define FALSE 0
+#endif
+#ifndef NULL
+
+#define NULL 0
+#endif
+#define FXSYS_assert assert
+#ifndef ASSERT
+#ifdef _DEBUG
+#define ASSERT FXSYS_assert
+#else
+
+#define ASSERT(a)
+#endif
+#endif
+#define FX_MAX(a, b) (((a) > (b)) ? (a) : (b))
+#define FX_MIN(a, b) (((a) < (b)) ? (a) : (b))
+#define FX_PI 3.1415926535897932384626433832795f
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+#define FXSYS_snprintf _snprintf
+#else
+#define FXSYS_snprintf snprintf
+#endif
+#define FXSYS_sprintf sprintf
+#define FXSYS_vsprintf vsprintf
+#define FXSYS_strchr strchr
+#define FXSYS_strlen strlen
+#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
+#define FXSYS_wfopen(f, m) _wfopen((const wchar_t*)(f), (const wchar_t*)(m))
+#else
+#define FXSYS_wfopen _wfopen
+#endif
+#else
+FXSYS_FILE* FXSYS_wfopen(FX_LPCWSTR filename, FX_LPCWSTR mode);
+#endif
+
+#define FXSYS_wcslen wcslen
+#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
+#define FXSYS_itoa _itoa
+#define FXSYS_strlwr _strlwr
+#define FXSYS_strupr _strupr
+#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_wcslwr(str) _wcslwr((wchar_t*)(str))
+#define FXSYS_wcsupr(str) _wcsupr((wchar_t*)(str))
+#else
+#define FXSYS_wcsicmp _wcsicmp
+#define FXSYS_WideCharToMultiByte WideCharToMultiByte
+#define FXSYS_MultiByteToWideChar MultiByteToWideChar
+#define FXSYS_wcslwr _wcslwr
+#define FXSYS_wcsupr _wcsupr
+#endif
+#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);
+#endif
+#define FXSYS_memcpy32 FXSYS_memcpy
+#define FXSYS_memcmp32 FXSYS_memcmp
+#define FXSYS_memset32 FXSYS_memset
+#define FXSYS_memset8 FXSYS_memset
+#define FXSYS_memmove32 FXSYS_memmove
+#ifdef __cplusplus
+}
+#endif
+#include <math.h>
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
+#define FXSYS_pow(a, b) (FX_FLOAT)powf(a, b)
+#else
+#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
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define _FX_LSB_FIRST_
+#define FXDWORD_FROM_LSBFIRST(i) (i)
+#define FXDWORD_FROM_MSBFIRST(i) (((FX_BYTE)(i) << 24) | ((FX_BYTE)((i) >> 8) << 16) | ((FX_BYTE)((i) >> 16) << 8) | (FX_BYTE)((i) >> 24))
+#define FXDWORD_GET_LSBFIRST(p) ((((FX_LPBYTE)(p))[3] << 24) | (((FX_LPBYTE)(p))[2] << 16) | (((FX_LPBYTE)(p))[1] << 8) | (((FX_LPBYTE)(p))[0]))
+#define FXDWORD_GET_MSBFIRST(p) ((((FX_LPBYTE)(p))[0] << 24) | (((FX_LPBYTE)(p))[1] << 16) | (((FX_LPBYTE)(p))[2] << 8) | (((FX_LPBYTE)(p))[3]))
+#define FXSYS_HIBYTE(word) ((FX_BYTE)((word) >> 8))
+#define FXSYS_LOBYTE(word) ((FX_BYTE)(word))
+#define FXSYS_HIWORD(dword) ((FX_WORD)((dword) >> 16))
+#define FXSYS_LOWORD(dword) ((FX_WORD)(dword))
+FX_INT32 FXSYS_atoi(FX_LPCSTR str);
+FX_INT32 FXSYS_wtoi(FX_LPCWSTR str);
+FX_INT64 FXSYS_atoi64(FX_LPCSTR str);
+FX_INT64 FXSYS_wtoi64(FX_LPCWSTR str);
+FX_LPCSTR FXSYS_i64toa(FX_INT64 value, FX_LPSTR str, int radix);
+FX_LPCWSTR FXSYS_i64tow(FX_INT64 value, FX_LPWSTR 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
+#endif
diff --git a/core/include/fxcrt/fx_xml.h b/core/include/fxcrt/fx_xml.h
index 1217677740..19a49cde12 100644
--- a/core/include/fxcrt/fx_xml.h
+++ b/core/include/fxcrt/fx_xml.h
@@ -1,209 +1,209 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef _FX_XML_H_
-#define _FX_XML_H_
-#ifndef _FX_BASIC_H_
-#include "fx_basic.h"
-#endif
-class CXML_AttrItem : public CFX_Object
-{
-public:
- CFX_ByteStringL m_QSpaceName;
- CFX_ByteStringL m_AttrName;
- CFX_WideStringL m_Value;
-
- void Empty(IFX_Allocator* pAllocator = NULL)
- {
- m_QSpaceName.Empty(pAllocator);
- m_AttrName.Empty(pAllocator);
- m_Value.Empty(pAllocator);
- }
-};
-class CXML_AttrMap : public CFX_Object
-{
-public:
- CXML_AttrMap()
- {
- m_pMap = NULL;
- }
- ~CXML_AttrMap()
- {
- RemoveAll(NULL);
- }
- const CFX_WideStringL* Lookup(FX_BSTR space, FX_BSTR name) const;
- void SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value, IFX_Allocator* pAllocator = NULL);
- void RemoveAt(FX_BSTR space, FX_BSTR name, IFX_Allocator* pAllocator = NULL);
- void RemoveAll(IFX_Allocator* pAllocator = NULL);
- int GetSize() const;
- CXML_AttrItem& GetAt(int index) const;
- CFX_ObjectArray<CXML_AttrItem>* m_pMap;
-};
-class CXML_Content : public CFX_Object
-{
-public:
- CXML_Content() : m_bCDATA(FALSE), m_Content() {}
- ~CXML_Content()
- {
- Empty(NULL);
- }
- void Empty(IFX_Allocator* pAllocator = NULL)
- {
- m_Content.Empty(pAllocator);
- }
- void Set(FX_BOOL bCDATA, FX_WSTR content, IFX_Allocator* pAllocator = NULL)
- {
- m_bCDATA = bCDATA;
- m_Content.Set(content, pAllocator);
- }
- FX_BOOL m_bCDATA;
- CFX_WideStringL m_Content;
-};
-class CXML_Element : public CFX_Object
-{
-public:
-
- static CXML_Element* Parse(const void* pBuffer, size_t size, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
-
- static CXML_Element* Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
-
- static CXML_Element* Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
-
- CXML_Element(FX_BSTR qSpace, FX_BSTR tagName, IFX_Allocator* pAllocator = NULL);
-
- CXML_Element(FX_BSTR qTagName, IFX_Allocator* pAllocator = NULL);
-
- CXML_Element(IFX_Allocator* pAllocator = NULL);
-
- ~CXML_Element();
-
- void Empty();
-
-
-
- CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const;
- void GetTagName(CFX_ByteStringL &tagName, FX_BOOL bQualified = FALSE) const;
-
- CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const;
- void GetNamespace(CFX_ByteStringL &nameSpace, FX_BOOL bQualified = FALSE) const;
-
- CFX_ByteString GetNamespaceURI(FX_BSTR qName) const;
- void GetNamespaceURI(FX_BSTR qName, CFX_ByteStringL &uri) 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;
- void GetAttrByIndex(int index, CFX_ByteStringL &space, CFX_ByteStringL &name, CFX_WideStringL &value) const;
-
- FX_BOOL HasAttr(FX_BSTR qName) const;
-
- FX_BOOL GetAttrValue(FX_BSTR name, CFX_WideString& attribute) const;
- CFX_WideString GetAttrValue(FX_BSTR name) const
- {
- CFX_WideString attr;
- GetAttrValue(name, attr);
- return attr;
- }
- const CFX_WideStringL* GetAttrValuePtr(FX_BSTR name) const;
-
- FX_BOOL GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const;
- CFX_WideString GetAttrValue(FX_BSTR space, FX_BSTR name) const
- {
- CFX_WideString attr;
- GetAttrValue(space, name, attr);
- return attr;
- }
- const CFX_WideStringL* GetAttrValuePtr(FX_BSTR space, FX_BSTR name) const;
-
- FX_BOOL GetAttrInteger(FX_BSTR name, int& attribute) const;
- int GetAttrInteger(FX_BSTR name) const
- {
- int attr = 0;
- GetAttrInteger(name, attr);
- return attr;
- }
-
- FX_BOOL GetAttrInteger(FX_BSTR space, FX_BSTR name, int& attribute) const;
- int GetAttrInteger(FX_BSTR space, FX_BSTR name) const
- {
- int attr = 0;
- GetAttrInteger(space, name, attr);
- return attr;
- }
-
- FX_BOOL GetAttrFloat(FX_BSTR name, FX_FLOAT& attribute) const;
- FX_FLOAT GetAttrFloat(FX_BSTR name) const
- {
- FX_FLOAT attr = 0;
- GetAttrFloat(name, attr);
- return attr;
- }
-
- FX_BOOL GetAttrFloat(FX_BSTR space, FX_BSTR name, FX_FLOAT& attribute) const;
- FX_FLOAT GetAttrFloat(FX_BSTR space, FX_BSTR 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;
- const CFX_WideStringL* GetContentPtr(FX_DWORD index) const;
-
- CXML_Element* GetElement(FX_DWORD index) const;
-
- CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag) const
- {
- return GetElement(space, tag, 0);
- }
-
- FX_DWORD CountElements(FX_BSTR space, FX_BSTR tag) const;
-
- CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag, int index) const;
-
- FX_DWORD FindElement(CXML_Element *pChild) const;
-
-
-
-
- void SetTag(FX_BSTR qSpace, FX_BSTR tagname);
-
- void SetTag(FX_BSTR qTagName);
-
- void RemoveChildren();
-
- void RemoveChild(FX_DWORD index);
-
-
-protected:
-
- CXML_Element* m_pParent;
-
- CFX_ByteStringL m_QSpaceName;
-
- CFX_ByteStringL m_TagName;
-
- CXML_AttrMap m_AttrMap;
-
- CFX_PtrArray m_Children;
- friend class CXML_Parser;
- friend class CXML_Composer;
-};
-#endif
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _FX_XML_H_
+#define _FX_XML_H_
+#ifndef _FX_BASIC_H_
+#include "fx_basic.h"
+#endif
+class CXML_AttrItem : public CFX_Object
+{
+public:
+ CFX_ByteStringL m_QSpaceName;
+ CFX_ByteStringL m_AttrName;
+ CFX_WideStringL m_Value;
+
+ void Empty(IFX_Allocator* pAllocator = NULL)
+ {
+ m_QSpaceName.Empty(pAllocator);
+ m_AttrName.Empty(pAllocator);
+ m_Value.Empty(pAllocator);
+ }
+};
+class CXML_AttrMap : public CFX_Object
+{
+public:
+ CXML_AttrMap()
+ {
+ m_pMap = NULL;
+ }
+ ~CXML_AttrMap()
+ {
+ RemoveAll(NULL);
+ }
+ const CFX_WideStringL* Lookup(FX_BSTR space, FX_BSTR name) const;
+ void SetAt(FX_BSTR space, FX_BSTR name, FX_WSTR value, IFX_Allocator* pAllocator = NULL);
+ void RemoveAt(FX_BSTR space, FX_BSTR name, IFX_Allocator* pAllocator = NULL);
+ void RemoveAll(IFX_Allocator* pAllocator = NULL);
+ int GetSize() const;
+ CXML_AttrItem& GetAt(int index) const;
+ CFX_ObjectArray<CXML_AttrItem>* m_pMap;
+};
+class CXML_Content : public CFX_Object
+{
+public:
+ CXML_Content() : m_bCDATA(FALSE), m_Content() {}
+ ~CXML_Content()
+ {
+ Empty(NULL);
+ }
+ void Empty(IFX_Allocator* pAllocator = NULL)
+ {
+ m_Content.Empty(pAllocator);
+ }
+ void Set(FX_BOOL bCDATA, FX_WSTR content, IFX_Allocator* pAllocator = NULL)
+ {
+ m_bCDATA = bCDATA;
+ m_Content.Set(content, pAllocator);
+ }
+ FX_BOOL m_bCDATA;
+ CFX_WideStringL m_Content;
+};
+class CXML_Element : public CFX_Object
+{
+public:
+
+ static CXML_Element* Parse(const void* pBuffer, size_t size, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
+
+ static CXML_Element* Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
+
+ static CXML_Element* Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL);
+
+ CXML_Element(FX_BSTR qSpace, FX_BSTR tagName, IFX_Allocator* pAllocator = NULL);
+
+ CXML_Element(FX_BSTR qTagName, IFX_Allocator* pAllocator = NULL);
+
+ CXML_Element(IFX_Allocator* pAllocator = NULL);
+
+ ~CXML_Element();
+
+ void Empty();
+
+
+
+ CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const;
+ void GetTagName(CFX_ByteStringL &tagName, FX_BOOL bQualified = FALSE) const;
+
+ CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const;
+ void GetNamespace(CFX_ByteStringL &nameSpace, FX_BOOL bQualified = FALSE) const;
+
+ CFX_ByteString GetNamespaceURI(FX_BSTR qName) const;
+ void GetNamespaceURI(FX_BSTR qName, CFX_ByteStringL &uri) 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;
+ void GetAttrByIndex(int index, CFX_ByteStringL &space, CFX_ByteStringL &name, CFX_WideStringL &value) const;
+
+ FX_BOOL HasAttr(FX_BSTR qName) const;
+
+ FX_BOOL GetAttrValue(FX_BSTR name, CFX_WideString& attribute) const;
+ CFX_WideString GetAttrValue(FX_BSTR name) const
+ {
+ CFX_WideString attr;
+ GetAttrValue(name, attr);
+ return attr;
+ }
+ const CFX_WideStringL* GetAttrValuePtr(FX_BSTR name) const;
+
+ FX_BOOL GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& attribute) const;
+ CFX_WideString GetAttrValue(FX_BSTR space, FX_BSTR name) const
+ {
+ CFX_WideString attr;
+ GetAttrValue(space, name, attr);
+ return attr;
+ }
+ const CFX_WideStringL* GetAttrValuePtr(FX_BSTR space, FX_BSTR name) const;
+
+ FX_BOOL GetAttrInteger(FX_BSTR name, int& attribute) const;
+ int GetAttrInteger(FX_BSTR name) const
+ {
+ int attr = 0;
+ GetAttrInteger(name, attr);
+ return attr;
+ }
+
+ FX_BOOL GetAttrInteger(FX_BSTR space, FX_BSTR name, int& attribute) const;
+ int GetAttrInteger(FX_BSTR space, FX_BSTR name) const
+ {
+ int attr = 0;
+ GetAttrInteger(space, name, attr);
+ return attr;
+ }
+
+ FX_BOOL GetAttrFloat(FX_BSTR name, FX_FLOAT& attribute) const;
+ FX_FLOAT GetAttrFloat(FX_BSTR name) const
+ {
+ FX_FLOAT attr = 0;
+ GetAttrFloat(name, attr);
+ return attr;
+ }
+
+ FX_BOOL GetAttrFloat(FX_BSTR space, FX_BSTR name, FX_FLOAT& attribute) const;
+ FX_FLOAT GetAttrFloat(FX_BSTR space, FX_BSTR 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;
+ const CFX_WideStringL* GetContentPtr(FX_DWORD index) const;
+
+ CXML_Element* GetElement(FX_DWORD index) const;
+
+ CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag) const
+ {
+ return GetElement(space, tag, 0);
+ }
+
+ FX_DWORD CountElements(FX_BSTR space, FX_BSTR tag) const;
+
+ CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag, int index) const;
+
+ FX_DWORD FindElement(CXML_Element *pChild) const;
+
+
+
+
+ void SetTag(FX_BSTR qSpace, FX_BSTR tagname);
+
+ void SetTag(FX_BSTR qTagName);
+
+ void RemoveChildren();
+
+ void RemoveChild(FX_DWORD index);
+
+
+protected:
+
+ CXML_Element* m_pParent;
+
+ CFX_ByteStringL m_QSpaceName;
+
+ CFX_ByteStringL m_TagName;
+
+ CXML_AttrMap m_AttrMap;
+
+ CFX_PtrArray m_Children;
+ friend class CXML_Parser;
+ friend class CXML_Composer;
+};
+#endif