diff options
author | dsinclair <dsinclair@chromium.org> | 2016-09-29 13:59:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-29 13:59:29 -0700 |
commit | a52ab741019342fbca0468e43a01deb44fa5f1bd (patch) | |
tree | 9b1deef3b8deb23d65bf56348b220fe59dcd3169 /core/fxcrt/include | |
parent | 8a4e286e686c3027f382afb07d3ddcec4610fdd9 (diff) | |
download | pdfium-a52ab741019342fbca0468e43a01deb44fa5f1bd.tar.xz |
Move core/fxcrt/include to core/fxcrt
BUG=pdfium:611
Review-Url: https://codereview.chromium.org/2382723003
Diffstat (limited to 'core/fxcrt/include')
-rw-r--r-- | core/fxcrt/include/cfx_count_ref.h | 81 | ||||
-rw-r--r-- | core/fxcrt/include/cfx_observable.h | 78 | ||||
-rw-r--r-- | core/fxcrt/include/cfx_retain_ptr.h | 57 | ||||
-rw-r--r-- | core/fxcrt/include/cfx_string_pool_template.h | 30 | ||||
-rw-r--r-- | core/fxcrt/include/cfx_weak_ptr.h | 80 | ||||
-rw-r--r-- | core/fxcrt/include/fx_arabic.h | 188 | ||||
-rw-r--r-- | core/fxcrt/include/fx_arb.h | 49 | ||||
-rw-r--r-- | core/fxcrt/include/fx_basic.h | 859 | ||||
-rw-r--r-- | core/fxcrt/include/fx_coordinates.h | 671 | ||||
-rw-r--r-- | core/fxcrt/include/fx_ext.h | 130 | ||||
-rw-r--r-- | core/fxcrt/include/fx_memory.h | 112 | ||||
-rw-r--r-- | core/fxcrt/include/fx_safe_types.h | 20 | ||||
-rw-r--r-- | core/fxcrt/include/fx_stream.h | 162 | ||||
-rw-r--r-- | core/fxcrt/include/fx_string.h | 465 | ||||
-rw-r--r-- | core/fxcrt/include/fx_system.h | 342 | ||||
-rw-r--r-- | core/fxcrt/include/fx_ucd.h | 202 | ||||
-rw-r--r-- | core/fxcrt/include/fx_xml.h | 173 |
17 files changed, 0 insertions, 3699 deletions
diff --git a/core/fxcrt/include/cfx_count_ref.h b/core/fxcrt/include/cfx_count_ref.h deleted file mode 100644 index a879967b28..0000000000 --- a/core/fxcrt/include/cfx_count_ref.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2016 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 CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ -#define CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ - -#include "core/fxcrt/include/cfx_retain_ptr.h" -#include "core/fxcrt/include/fx_system.h" - -// A shared object with Copy on Write semantics that makes it appear as -// if each one were independent. -template <class ObjClass> -class CFX_CountRef { - public: - CFX_CountRef() {} - CFX_CountRef(const CFX_CountRef& other) : m_pObject(other.m_pObject) {} - ~CFX_CountRef() {} - - template <typename... Args> - ObjClass* Emplace(Args... params) { - m_pObject.Reset(new CountedObj(params...)); - return m_pObject.Get(); - } - - CFX_CountRef& operator=(const CFX_CountRef& that) { - if (*this != that) - m_pObject = that.m_pObject; - return *this; - } - - void SetNull() { m_pObject.Reset(); } - const ObjClass* GetObject() const { return m_pObject.Get(); } - - template <typename... Args> - ObjClass* GetPrivateCopy(Args... params) { - if (!m_pObject) - return Emplace(params...); - if (!m_pObject->HasOneRef()) - m_pObject.Reset(new CountedObj(*m_pObject)); - return m_pObject.Get(); - } - - bool operator==(const CFX_CountRef& that) const { - return m_pObject == that.m_pObject; - } - bool operator!=(const CFX_CountRef& that) const { return !(*this == that); } - explicit operator bool() const { return !!m_pObject; } - - private: - class CountedObj : public ObjClass { - public: - template <typename... Args> - CountedObj(Args... params) : ObjClass(params...), m_RefCount(0) {} - - CountedObj(const CountedObj& src) : ObjClass(src), m_RefCount(0) {} - ~CountedObj() { m_RefCount = 0; } - - bool HasOneRef() const { return m_RefCount == 1; } - void Retain() { m_RefCount++; } - void Release() { - ASSERT(m_RefCount); - if (--m_RefCount == 0) - delete this; - } - - private: - // To ensure ref counts do not overflow, consider the worst possible case: - // the entire address space contains nothing but pointers to this object. - // Since the count increments with each new pointer, the largest value is - // the number of pointers that can fit into the address space. The size of - // the address space itself is a good upper bound on it. - intptr_t m_RefCount; - }; - - CFX_RetainPtr<CountedObj> m_pObject; -}; - -#endif // CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ diff --git a/core/fxcrt/include/cfx_observable.h b/core/fxcrt/include/cfx_observable.h deleted file mode 100644 index a5053f3952..0000000000 --- a/core/fxcrt/include/cfx_observable.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2016 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. - -#ifndef CORE_FXCRT_INCLUDE_CFX_OBSERVABLE_H_ -#define CORE_FXCRT_INCLUDE_CFX_OBSERVABLE_H_ - -#include <set> - -#include "core/fxcrt/include/fx_system.h" -#include "third_party/base/stl_util.h" - -template <class T> -class CFX_Observable { - public: - class ObservedPtr { - public: - ObservedPtr() : m_pObservedPtr(nullptr) {} - explicit ObservedPtr(T* pObservedPtr) : m_pObservedPtr(pObservedPtr) { - if (m_pObservedPtr) - m_pObservedPtr->AddObservedPtr(this); - } - ObservedPtr(const ObservedPtr& that) = delete; - ~ObservedPtr() { - if (m_pObservedPtr) - m_pObservedPtr->RemoveObservedPtr(this); - } - void Reset(T* pObservedPtr = nullptr) { - if (m_pObservedPtr) - m_pObservedPtr->RemoveObservedPtr(this); - m_pObservedPtr = pObservedPtr; - if (m_pObservedPtr) - m_pObservedPtr->AddObservedPtr(this); - } - void OnDestroy() { - ASSERT(m_pObservedPtr); - m_pObservedPtr = nullptr; - } - ObservedPtr& operator=(const ObservedPtr& that) = delete; - bool operator==(const ObservedPtr& that) const { - return m_pObservedPtr == that.m_pObservedPtr; - } - bool operator!=(const ObservedPtr& that) const { return !(*this == that); } - explicit operator bool() const { return !!m_pObservedPtr; } - T* Get() const { return m_pObservedPtr; } - T& operator*() const { return *m_pObservedPtr; } - T* operator->() const { return m_pObservedPtr; } - - private: - T* m_pObservedPtr; - }; - - CFX_Observable() {} - CFX_Observable(const CFX_Observable& that) = delete; - ~CFX_Observable() { NotifyObservedPtrs(); } - void AddObservedPtr(ObservedPtr* pObservedPtr) { - ASSERT(!pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr)); - m_ObservedPtrs.insert(pObservedPtr); - } - void RemoveObservedPtr(ObservedPtr* pObservedPtr) { - ASSERT(pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr)); - m_ObservedPtrs.erase(pObservedPtr); - } - void NotifyObservedPtrs() { - for (auto* pObservedPtr : m_ObservedPtrs) - pObservedPtr->OnDestroy(); - m_ObservedPtrs.clear(); - } - CFX_Observable& operator=(const CFX_Observable& that) = delete; - - protected: - size_t ActiveObservedPtrsForTesting() const { return m_ObservedPtrs.size(); } - - private: - std::set<ObservedPtr*> m_ObservedPtrs; -}; - -#endif // CORE_FXCRT_INCLUDE_CFX_OBSERVABLE_H_ diff --git a/core/fxcrt/include/cfx_retain_ptr.h b/core/fxcrt/include/cfx_retain_ptr.h deleted file mode 100644 index e40feb6b31..0000000000 --- a/core/fxcrt/include/cfx_retain_ptr.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2016 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. - -#ifndef CORE_FXCRT_INCLUDE_CFX_RETAIN_PTR_H_ -#define CORE_FXCRT_INCLUDE_CFX_RETAIN_PTR_H_ - -#include <memory> - -#include "core/fxcrt/include/fx_memory.h" - -template <class T> -class CFX_RetainPtr { - public: - explicit CFX_RetainPtr(T* pObj) : m_pObj(pObj) { - if (m_pObj) - m_pObj->Retain(); - } - - CFX_RetainPtr() : CFX_RetainPtr(nullptr) {} - CFX_RetainPtr(const CFX_RetainPtr& that) : CFX_RetainPtr(that.Get()) {} - CFX_RetainPtr(CFX_RetainPtr&& that) { Swap(that); } - - template <class U> - CFX_RetainPtr(const CFX_RetainPtr<U>& that) - : CFX_RetainPtr(that.Get()) {} - - void Reset(T* obj = nullptr) { - if (obj) - obj->Retain(); - m_pObj.reset(obj); - } - - T* Get() const { return m_pObj.get(); } - void Swap(CFX_RetainPtr& that) { m_pObj.swap(that.m_pObj); } - - CFX_RetainPtr& operator=(const CFX_RetainPtr& that) { - if (*this != that) - Reset(that.Get()); - return *this; - } - - bool operator==(const CFX_RetainPtr& that) const { - return Get() == that.Get(); - } - - bool operator!=(const CFX_RetainPtr& that) const { return !(*this == that); } - - explicit operator bool() const { return !!m_pObj; } - T& operator*() const { return *m_pObj.get(); } - T* operator->() const { return m_pObj.get(); } - - private: - std::unique_ptr<T, ReleaseDeleter<T>> m_pObj; -}; - -#endif // CORE_FXCRT_INCLUDE_CFX_RETAIN_PTR_H_ diff --git a/core/fxcrt/include/cfx_string_pool_template.h b/core/fxcrt/include/cfx_string_pool_template.h deleted file mode 100644 index a59d13a61d..0000000000 --- a/core/fxcrt/include/cfx_string_pool_template.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 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 CORE_FXCRT_INCLUDE_CFX_STRING_POOL_TEMPLATE_H_ -#define CORE_FXCRT_INCLUDE_CFX_STRING_POOL_TEMPLATE_H_ - -#include <unordered_set> - -#include "core/fxcrt/include/fx_string.h" - -template <typename StringType> -class CFX_StringPoolTemplate { - public: - StringType Intern(const StringType& str) { return *m_Pool.insert(str).first; } - void Clear() { m_Pool.clear(); } - - private: - std::unordered_set<StringType> m_Pool; -}; - -using CFX_ByteStringPool = CFX_StringPoolTemplate<CFX_ByteString>; -using CFX_WideStringPool = CFX_StringPoolTemplate<CFX_WideString>; - -extern template class CFX_StringPoolTemplate<CFX_ByteString>; -extern template class CFX_StringPoolTemplate<CFX_WideString>; - -#endif // CORE_FXCRT_INCLUDE_CFX_STRING_POOL_TEMPLATE_H_ diff --git a/core/fxcrt/include/cfx_weak_ptr.h b/core/fxcrt/include/cfx_weak_ptr.h deleted file mode 100644 index 64218cd679..0000000000 --- a/core/fxcrt/include/cfx_weak_ptr.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2016 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 CORE_FXCRT_INCLUDE_CFX_WEAK_PTR_H_ -#define CORE_FXCRT_INCLUDE_CFX_WEAK_PTR_H_ - -#include <memory> - -#include "core/fxcrt/include/cfx_retain_ptr.h" -#include "core/fxcrt/include/fx_system.h" - -template <class T, class D = std::default_delete<T>> -class CFX_WeakPtr { - public: - CFX_WeakPtr() {} - CFX_WeakPtr(const CFX_WeakPtr& that) : m_pHandle(that.m_pHandle) {} - CFX_WeakPtr(CFX_WeakPtr&& that) { Swap(that); } - CFX_WeakPtr(std::unique_ptr<T, D> pObj) - : m_pHandle(new Handle(std::move(pObj))) {} - - explicit operator bool() const { return m_pHandle && !!m_pHandle->Get(); } - bool HasOneRef() const { return m_pHandle && m_pHandle->HasOneRef(); } - T* operator->() { return m_pHandle->Get(); } - const T* operator->() const { return m_pHandle->Get(); } - CFX_WeakPtr& operator=(const CFX_WeakPtr& that) { - m_pHandle = that.m_pHandle; - return *this; - } - bool operator==(const CFX_WeakPtr& that) const { - return m_pHandle == that.m_pHandle; - } - bool operator!=(const CFX_WeakPtr& that) const { return !(*this == that); } - - T* Get() const { return m_pHandle ? m_pHandle->Get() : nullptr; } - void Clear() { - if (m_pHandle) { - m_pHandle->Clear(); - m_pHandle.Reset(); - } - } - void Reset() { m_pHandle.Reset(); } - void Reset(std::unique_ptr<T, D> pObj) { - m_pHandle.Reset(new Handle(std::move(pObj))); - } - void Swap(CFX_WeakPtr& that) { m_pHandle.Swap(that.m_pHandle); } - - private: - class Handle { - public: - explicit Handle(std::unique_ptr<T, D> ptr) - : m_nCount(0), m_pObj(std::move(ptr)) {} - void Reset(std::unique_ptr<T, D> ptr) { m_pObj = std::move(ptr); } - void Clear() { // Now you're all weak ptrs ... - m_pObj.reset(); // unique_ptr nulls first before invoking delete. - } - T* Get() const { return m_pObj.get(); } - T* Retain() { - ++m_nCount; - return m_pObj.get(); - } - void Release() { - if (--m_nCount == 0) - delete this; - } - bool HasOneRef() const { return m_nCount == 1; } - - private: - ~Handle() {} - - intptr_t m_nCount; - std::unique_ptr<T, D> m_pObj; - }; - - CFX_RetainPtr<Handle> m_pHandle; -}; - -#endif // CORE_FXCRT_INCLUDE_CFX_WEAK_PTR_H_ diff --git a/core/fxcrt/include/fx_arabic.h b/core/fxcrt/include/fx_arabic.h deleted file mode 100644 index 2617d1897f..0000000000 --- a/core/fxcrt/include/fx_arabic.h +++ /dev/null @@ -1,188 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_ARABIC_H_ -#define CORE_FXCRT_INCLUDE_FX_ARABIC_H_ - -#include "core/fxcrt/include/fx_arb.h" - -#define FX_BIDIMAXLEVEL 61 -#define FX_BidiDirection(a) (FX_IsOdd(a) ? FX_BIDICLASS_R : FX_BIDICLASS_L) -#define FX_BidiGetDeferredType(a) (((a) >> 4) & 0x0F) -#define FX_BidiGetResolvedType(a) ((a)&0x0F) - -namespace pdfium { -namespace arabic { - -bool IsArabicChar(FX_WCHAR wch); -bool IsArabicFormChar(FX_WCHAR wch); -FX_WCHAR GetFormChar(FX_WCHAR wch, FX_WCHAR prev = 0, FX_WCHAR next = 0); -FX_WCHAR GetFormChar(const CFX_Char* cur, - const CFX_Char* prev, - const CFX_Char* next); - -} // namespace arabic -} // namespace pdfium - -void FX_BidiReverseString(CFX_WideString& wsText, - int32_t iStart, - int32_t iCount); -void FX_BidiSetDeferredRun(CFX_Int32Array& values, - int32_t iStart, - int32_t iCount, - int32_t iValue); -void FX_BidiClassify(const CFX_WideString& wsText, - CFX_Int32Array& classes, - FX_BOOL bWS = FALSE); -int32_t FX_BidiResolveExplicit(int32_t iBaseLevel, - int32_t iDirection, - CFX_Int32Array& classes, - CFX_Int32Array& levels, - int32_t iStart, - int32_t iCount, - int32_t iNest = 0); - -enum FX_BIDIWEAKSTATE { - FX_BIDIWEAKSTATE_xa = 0, - FX_BIDIWEAKSTATE_xr, - FX_BIDIWEAKSTATE_xl, - FX_BIDIWEAKSTATE_ao, - FX_BIDIWEAKSTATE_ro, - FX_BIDIWEAKSTATE_lo, - FX_BIDIWEAKSTATE_rt, - FX_BIDIWEAKSTATE_lt, - FX_BIDIWEAKSTATE_cn, - FX_BIDIWEAKSTATE_ra, - FX_BIDIWEAKSTATE_re, - FX_BIDIWEAKSTATE_la, - FX_BIDIWEAKSTATE_le, - FX_BIDIWEAKSTATE_ac, - FX_BIDIWEAKSTATE_rc, - FX_BIDIWEAKSTATE_rs, - FX_BIDIWEAKSTATE_lc, - FX_BIDIWEAKSTATE_ls, - FX_BIDIWEAKSTATE_ret, - FX_BIDIWEAKSTATE_let, -}; -#define FX_BWSxa FX_BIDIWEAKSTATE_xa -#define FX_BWSxr FX_BIDIWEAKSTATE_xr -#define FX_BWSxl FX_BIDIWEAKSTATE_xl -#define FX_BWSao FX_BIDIWEAKSTATE_ao -#define FX_BWSro FX_BIDIWEAKSTATE_ro -#define FX_BWSlo FX_BIDIWEAKSTATE_lo -#define FX_BWSrt FX_BIDIWEAKSTATE_rt -#define FX_BWSlt FX_BIDIWEAKSTATE_lt -#define FX_BWScn FX_BIDIWEAKSTATE_cn -#define FX_BWSra FX_BIDIWEAKSTATE_ra -#define FX_BWSre FX_BIDIWEAKSTATE_re -#define FX_BWSla FX_BIDIWEAKSTATE_la -#define FX_BWSle FX_BIDIWEAKSTATE_le -#define FX_BWSac FX_BIDIWEAKSTATE_ac -#define FX_BWSrc FX_BIDIWEAKSTATE_rc -#define FX_BWSrs FX_BIDIWEAKSTATE_rs -#define FX_BWSlc FX_BIDIWEAKSTATE_lc -#define FX_BWSls FX_BIDIWEAKSTATE_ls -#define FX_BWSret FX_BIDIWEAKSTATE_ret -#define FX_BWSlet FX_BIDIWEAKSTATE_let - -enum FX_BIDIWEAKACTION { - FX_BIDIWEAKACTION_IX = 0x100, - FX_BIDIWEAKACTION_XX = 0x0F, - FX_BIDIWEAKACTION_xxx = (0x0F << 4) + 0x0F, - FX_BIDIWEAKACTION_xIx = 0x100 + FX_BIDIWEAKACTION_xxx, - FX_BIDIWEAKACTION_xxN = (0x0F << 4) + FX_BIDICLASS_ON, - FX_BIDIWEAKACTION_xxE = (0x0F << 4) + FX_BIDICLASS_EN, - FX_BIDIWEAKACTION_xxA = (0x0F << 4) + FX_BIDICLASS_AN, - FX_BIDIWEAKACTION_xxR = (0x0F << 4) + FX_BIDICLASS_R, - FX_BIDIWEAKACTION_xxL = (0x0F << 4) + FX_BIDICLASS_L, - FX_BIDIWEAKACTION_Nxx = (FX_BIDICLASS_ON << 4) + 0x0F, - FX_BIDIWEAKACTION_Axx = (FX_BIDICLASS_AN << 4) + 0x0F, - FX_BIDIWEAKACTION_ExE = (FX_BIDICLASS_EN << 4) + FX_BIDICLASS_EN, - FX_BIDIWEAKACTION_NIx = (FX_BIDICLASS_ON << 4) + 0x0F + 0x100, - FX_BIDIWEAKACTION_NxN = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_ON, - FX_BIDIWEAKACTION_NxR = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_R, - FX_BIDIWEAKACTION_NxE = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_EN, - FX_BIDIWEAKACTION_AxA = (FX_BIDICLASS_AN << 4) + FX_BIDICLASS_AN, - FX_BIDIWEAKACTION_NxL = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_L, - FX_BIDIWEAKACTION_LxL = (FX_BIDICLASS_L << 4) + FX_BIDICLASS_L, - FX_BIDIWEAKACTION_xIL = (0x0F << 4) + FX_BIDICLASS_L + 0x100, - FX_BIDIWEAKACTION_AxR = (FX_BIDICLASS_AN << 4) + FX_BIDICLASS_R, - FX_BIDIWEAKACTION_Lxx = (FX_BIDICLASS_L << 4) + 0x0F, -}; -#define FX_BWAIX FX_BIDIWEAKACTION_IX -#define FX_BWAXX FX_BIDIWEAKACTION_XX -#define FX_BWAxxx FX_BIDIWEAKACTION_xxx -#define FX_BWAxIx FX_BIDIWEAKACTION_xIx -#define FX_BWAxxN FX_BIDIWEAKACTION_xxN -#define FX_BWAxxE FX_BIDIWEAKACTION_xxE -#define FX_BWAxxA FX_BIDIWEAKACTION_xxA -#define FX_BWAxxR FX_BIDIWEAKACTION_xxR -#define FX_BWAxxL FX_BIDIWEAKACTION_xxL -#define FX_BWANxx FX_BIDIWEAKACTION_Nxx -#define FX_BWAAxx FX_BIDIWEAKACTION_Axx -#define FX_BWAExE FX_BIDIWEAKACTION_ExE -#define FX_BWANIx FX_BIDIWEAKACTION_NIx -#define FX_BWANxN FX_BIDIWEAKACTION_NxN -#define FX_BWANxR FX_BIDIWEAKACTION_NxR -#define FX_BWANxE FX_BIDIWEAKACTION_NxE -#define FX_BWAAxA FX_BIDIWEAKACTION_AxA -#define FX_BWANxL FX_BIDIWEAKACTION_NxL -#define FX_BWALxL FX_BIDIWEAKACTION_LxL -#define FX_BWAxIL FX_BIDIWEAKACTION_xIL -#define FX_BWAAxR FX_BIDIWEAKACTION_AxR -#define FX_BWALxx FX_BIDIWEAKACTION_Lxx - -void FX_BidiResolveWeak(int32_t iBaseLevel, - CFX_Int32Array& classes, - CFX_Int32Array& levels); -enum FX_BIDINEUTRALSTATE { - FX_BIDINEUTRALSTATE_r = 0, - FX_BIDINEUTRALSTATE_l, - FX_BIDINEUTRALSTATE_rn, - FX_BIDINEUTRALSTATE_ln, - FX_BIDINEUTRALSTATE_a, - FX_BIDINEUTRALSTATE_na, -}; -#define FX_BNSr FX_BIDINEUTRALSTATE_r -#define FX_BNSl FX_BIDINEUTRALSTATE_l -#define FX_BNSrn FX_BIDINEUTRALSTATE_rn -#define FX_BNSln FX_BIDINEUTRALSTATE_ln -#define FX_BNSa FX_BIDINEUTRALSTATE_a -#define FX_BNSna FX_BIDINEUTRALSTATE_na -enum FX_BIDINEUTRALACTION { - FX_BIDINEUTRALACTION_nL = FX_BIDICLASS_L, - FX_BIDINEUTRALACTION_En = (FX_BIDICLASS_AN << 4), - FX_BIDINEUTRALACTION_Rn = (FX_BIDICLASS_R << 4), - FX_BIDINEUTRALACTION_Ln = (FX_BIDICLASS_L << 4), - FX_BIDINEUTRALACTION_In = FX_BIDIWEAKACTION_IX, - FX_BIDINEUTRALACTION_LnL = (FX_BIDICLASS_L << 4) + FX_BIDICLASS_L, -}; -#define FX_BNAnL FX_BIDINEUTRALACTION_nL -#define FX_BNAEn FX_BIDINEUTRALACTION_En -#define FX_BNARn FX_BIDINEUTRALACTION_Rn -#define FX_BNALn FX_BIDINEUTRALACTION_Ln -#define FX_BNAIn FX_BIDINEUTRALACTION_In -#define FX_BNALnL FX_BIDINEUTRALACTION_LnL -int32_t FX_BidiGetDeferredNeutrals(int32_t iAction, int32_t iLevel); -int32_t FX_BidiGetResolvedNeutrals(int32_t iAction); -void FX_BidiResolveNeutrals(int32_t iBaseLevel, - CFX_Int32Array& classes, - const CFX_Int32Array& levels); -void FX_BidiResolveImplicit(const CFX_Int32Array& classes, - CFX_Int32Array& levels); -void FX_BidiResolveWhitespace(int32_t iBaseLevel, - const CFX_Int32Array& classes, - CFX_Int32Array& levels); -int32_t FX_BidiReorderLevel(int32_t iBaseLevel, - CFX_WideString& wsText, - const CFX_Int32Array& levels, - int32_t iStart, - FX_BOOL bReverse = FALSE); -void FX_BidiReorder(int32_t iBaseLevel, - CFX_WideString& wsText, - const CFX_Int32Array& levels); - -#endif // CORE_FXCRT_INCLUDE_FX_ARABIC_H_ diff --git a/core/fxcrt/include/fx_arb.h b/core/fxcrt/include/fx_arb.h deleted file mode 100644 index 6928519a80..0000000000 --- a/core/fxcrt/include/fx_arb.h +++ /dev/null @@ -1,49 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_ARB_H_ -#define CORE_FXCRT_INCLUDE_FX_ARB_H_ - -#include "core/fxcrt/include/fx_system.h" -#include "core/fxcrt/include/fx_ucd.h" - -struct FX_ARBFORMTABLE { - uint16_t wIsolated; - uint16_t wFinal; - uint16_t wInitial; - uint16_t wMedial; -}; - -struct FX_ARAALEF { - uint16_t wAlef; - uint16_t wIsolated; -}; - -struct FX_ARASHADDA { - uint16_t wShadda; - uint16_t wIsolated; -}; - -const FX_ARBFORMTABLE* FX_GetArabicFormTable(FX_WCHAR unicode); -FX_WCHAR FX_GetArabicFromAlefTable(FX_WCHAR alef); -FX_WCHAR FX_GetArabicFromShaddaTable(FX_WCHAR shadda); - -enum FX_ARBPOSITION { - FX_ARBPOSITION_Isolated = 0, - FX_ARBPOSITION_Final, - FX_ARBPOSITION_Initial, - FX_ARBPOSITION_Medial, -}; - -void FX_BidiLine(CFX_WideString& wsText, int32_t iBaseLevel = 0); -void FX_BidiLine(CFX_TxtCharArray& chars, - int32_t iCount, - int32_t iBaseLevel = 0); -void FX_BidiLine(CFX_RTFCharArray& chars, - int32_t iCount, - int32_t iBaseLevel = 0); - -#endif // CORE_FXCRT_INCLUDE_FX_ARB_H_ diff --git a/core/fxcrt/include/fx_basic.h b/core/fxcrt/include/fx_basic.h deleted file mode 100644 index 6a8988d5dc..0000000000 --- a/core/fxcrt/include/fx_basic.h +++ /dev/null @@ -1,859 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_BASIC_H_ -#define CORE_FXCRT_INCLUDE_FX_BASIC_H_ - -#include <algorithm> -#include <memory> - -#include "core/fxcrt/include/fx_memory.h" -#include "core/fxcrt/include/fx_stream.h" -#include "core/fxcrt/include/fx_string.h" -#include "core/fxcrt/include/fx_system.h" - -class CFX_BinaryBuf { - public: - CFX_BinaryBuf(); - explicit CFX_BinaryBuf(FX_STRSIZE size); - ~CFX_BinaryBuf(); - - uint8_t* GetBuffer() const { return m_pBuffer.get(); } - FX_STRSIZE GetSize() const { return m_DataSize; } - - void Clear(); - void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0); - void AppendBlock(const void* pBuf, FX_STRSIZE size); - void AppendString(const CFX_ByteString& str) { - AppendBlock(str.c_str(), str.GetLength()); - } - - void AppendByte(uint8_t byte) { - ExpandBuf(1); - m_pBuffer.get()[m_DataSize++] = byte; - } - - void InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size); - void Delete(int start_index, int count); - - // Takes ownership of |pBuf|. - void AttachData(uint8_t* pBuf, FX_STRSIZE size); - - // Releases ownership of |m_pBuffer| and returns it. - uint8_t* DetachBuffer(); - - protected: - void ExpandBuf(FX_STRSIZE size); - - FX_STRSIZE m_AllocStep; - FX_STRSIZE m_AllocSize; - FX_STRSIZE m_DataSize; - std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer; -}; - -class CFX_ByteTextBuf : public CFX_BinaryBuf { - public: - FX_STRSIZE GetLength() const { return m_DataSize; } - CFX_ByteString MakeString() const { - return CFX_ByteString(m_pBuffer.get(), m_DataSize); - } - CFX_ByteStringC AsStringC() const { - return CFX_ByteStringC(m_pBuffer.get(), m_DataSize); - } - - void AppendChar(int ch) { AppendByte(static_cast<uint8_t>(ch)); } - CFX_ByteTextBuf& operator<<(int i); - CFX_ByteTextBuf& operator<<(uint32_t i); - CFX_ByteTextBuf& operator<<(double f); - CFX_ByteTextBuf& operator<<(const FX_CHAR* pStr) { - return *this << CFX_ByteStringC(pStr); - } - CFX_ByteTextBuf& operator<<(const CFX_ByteString& str) { - return *this << str.AsStringC(); - } - CFX_ByteTextBuf& operator<<(const CFX_ByteStringC& lpsz); - CFX_ByteTextBuf& operator<<(const CFX_ByteTextBuf& buf); -}; - -class CFX_WideTextBuf : public CFX_BinaryBuf { - public: - void AppendChar(FX_WCHAR wch); - FX_STRSIZE GetLength() const { return m_DataSize / sizeof(FX_WCHAR); } - FX_WCHAR* GetBuffer() const { - return reinterpret_cast<FX_WCHAR*>(m_pBuffer.get()); - } - - CFX_WideStringC AsStringC() const { - return CFX_WideStringC(reinterpret_cast<const FX_WCHAR*>(m_pBuffer.get()), - m_DataSize / sizeof(FX_WCHAR)); - } - CFX_WideString MakeString() const { - return CFX_WideString(reinterpret_cast<const FX_WCHAR*>(m_pBuffer.get()), - m_DataSize / sizeof(FX_WCHAR)); - } - - void Delete(int start_index, int count) { - CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), - count * sizeof(FX_WCHAR)); - } - - CFX_WideTextBuf& operator<<(int i); - CFX_WideTextBuf& operator<<(double f); - CFX_WideTextBuf& operator<<(const FX_WCHAR* lpsz); - CFX_WideTextBuf& operator<<(const CFX_WideStringC& str); - CFX_WideTextBuf& operator<<(const CFX_WideString& str); - CFX_WideTextBuf& operator<<(const CFX_WideTextBuf& buf); -}; - -class CFX_FileBufferArchive { - public: - CFX_FileBufferArchive(); - ~CFX_FileBufferArchive(); - - void Clear(); - bool Flush(); - int32_t AppendBlock(const void* pBuf, size_t size); - int32_t AppendByte(uint8_t byte); - int32_t AppendDWord(uint32_t i); - int32_t AppendString(const CFX_ByteStringC& lpsz); - - // |pFile| must outlive the CFX_FileBufferArchive. - void AttachFile(IFX_StreamWrite* pFile); - - private: - static const size_t kBufSize = 32768; - - size_t m_Length; - std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer; - IFX_StreamWrite* m_pFile; -}; - -class CFX_CharMap { - public: - static CFX_ByteString GetByteString(uint16_t codepage, - const CFX_WideStringC& wstr); - - static CFX_WideString GetWideString(uint16_t codepage, - const CFX_ByteStringC& bstr); - - CFX_CharMap() = delete; -}; - -class CFX_UTF8Decoder { - public: - CFX_UTF8Decoder() { m_PendingBytes = 0; } - - void Clear(); - - void Input(uint8_t byte); - - void AppendChar(uint32_t ch); - - void ClearStatus() { m_PendingBytes = 0; } - - CFX_WideStringC GetResult() const { return m_Buffer.AsStringC(); } - - protected: - int m_PendingBytes; - - uint32_t m_PendingChar; - - CFX_WideTextBuf m_Buffer; -}; - -class CFX_UTF8Encoder { - public: - CFX_UTF8Encoder() {} - - void Input(FX_WCHAR unicode); - void AppendStr(const CFX_ByteStringC& str) { m_Buffer << str; } - CFX_ByteStringC GetResult() const { return m_Buffer.AsStringC(); } - - protected: - CFX_ByteTextBuf m_Buffer; -}; - -class CFX_BasicArray { - protected: - explicit CFX_BasicArray(int unit_size); - CFX_BasicArray(const CFX_BasicArray&) = delete; - ~CFX_BasicArray(); - - FX_BOOL SetSize(int nNewSize); - FX_BOOL Append(const CFX_BasicArray& src); - FX_BOOL Copy(const CFX_BasicArray& src); - uint8_t* 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: - uint8_t* m_pData; - int m_nSize; - int m_nMaxSize; - int m_nUnitSize; -}; - -template <class TYPE> -class CFX_ArrayTemplate : public CFX_BasicArray { - public: - CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {} - - int GetSize() const { return m_nSize; } - - int GetUpperBound() const { return m_nSize - 1; } - - FX_BOOL SetSize(int nNewSize) { return CFX_BasicArray::SetSize(nNewSize); } - - void RemoveAll() { SetSize(0); } - - const TYPE GetAt(int nIndex) const { - if (nIndex < 0 || nIndex >= m_nSize) { - PDFIUM_IMMEDIATE_CRASH(); - } - 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) { - PDFIUM_IMMEDIATE_CRASH(); - } - 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 && !SetSize(nIndex + 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)) { - 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; - } -}; - -#ifdef PDF_ENABLE_XFA -typedef CFX_ArrayTemplate<CFX_WideStringC> CFX_WideStringCArray; -typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray; -typedef CFX_ArrayTemplate<uint8_t> CFX_ByteArray; -typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array; - -template <class ObjectClass> -class CFX_ObjectArray : public CFX_BasicArray { - public: - CFX_ObjectArray() : CFX_BasicArray(sizeof(ObjectClass)) {} - - ~CFX_ObjectArray() { RemoveAll(); } - - 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); } - - int32_t Append(const CFX_ObjectArray& src, - int32_t nStart = 0, - int32_t nCount = -1) { - if (nCount == 0) { - return 0; - } - int32_t nSize = src.GetSize(); - if (!nSize) { - return 0; - } - ASSERT(nStart > -1 && nStart < nSize); - if (nCount < 0) { - nCount = nSize; - } - if (nStart + nCount > nSize) { - nCount = nSize - nStart; - } - if (nCount < 1) { - return 0; - } - nSize = m_nSize; - InsertSpaceAt(m_nSize, nCount); - ObjectClass* pStartObj = (ObjectClass*)GetDataPtr(nSize); - nSize = nStart + nCount; - for (int32_t i = nStart; i < nSize; i++, pStartObj++) { - new ((void*)pStartObj) ObjectClass(src[i]); - } - return nCount; - } - - int32_t Copy(const CFX_ObjectArray& src, - int32_t nStart = 0, - int32_t nCount = -1) { - if (nCount == 0) { - return 0; - } - int32_t nSize = src.GetSize(); - if (!nSize) { - return 0; - } - ASSERT(nStart > -1 && nStart < nSize); - if (nCount < 0) { - nCount = nSize; - } - if (nStart + nCount > nSize) { - nCount = nSize - nStart; - } - if (nCount < 1) { - return 0; - } - RemoveAll(); - SetSize(nCount); - ObjectClass* pStartObj = (ObjectClass*)m_pData; - nSize = nStart + nCount; - for (int32_t i = nStart; i < nSize; i++, pStartObj++) { - new ((void*)pStartObj) ObjectClass(src[i]); - } - return nCount; - } - - int GetSize() const { return m_nSize; } - - ObjectClass& operator[](int index) const { - ASSERT(index < m_nSize); - return *(ObjectClass*)CFX_BasicArray::GetDataPtr(index); - } - - ObjectClass* GetDataPtr(int index) { - return (ObjectClass*)CFX_BasicArray::GetDataPtr(index); - } - - void RemoveAt(int index) { - ASSERT(index < m_nSize); - ((ObjectClass*)GetDataPtr(index))->~ObjectClass(); - CFX_BasicArray::RemoveAt(index, 1); - } - - void RemoveAll() { - for (int i = 0; i < m_nSize; i++) { - ((ObjectClass*)GetDataPtr(i))->~ObjectClass(); - } - CFX_BasicArray::SetSize(0); - } -}; -typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray; -typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray; -#endif // PDF_ENABLE_XFA - -template <class DataType, int FixedSize> -class CFX_FixedBufGrow { - public: - explicit CFX_FixedBufGrow(int data_size) { - if (data_size > FixedSize) { - m_pGrowData.reset(FX_Alloc(DataType, data_size)); - return; - } - FXSYS_memset(m_FixedData, 0, sizeof(DataType) * FixedSize); - } - operator DataType*() { return m_pGrowData ? m_pGrowData.get() : m_FixedData; } - - private: - DataType m_FixedData[FixedSize]; - std::unique_ptr<DataType, FxFreeDeleter> m_pGrowData; -}; - -#ifdef PDF_ENABLE_XFA -class CFX_MapPtrToPtr { - protected: - struct CAssoc { - CAssoc* pNext; - void* key; - void* value; - }; - - public: - CFX_MapPtrToPtr(int nBlockSize = 10); - ~CFX_MapPtrToPtr(); - - int GetCount() const { return m_nCount; } - 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 ? nullptr : (FX_POSITION)-1; - } - - void GetNextAssoc(FX_POSITION& rNextPosition, - void*& rKey, - void*& rValue) const; - - uint32_t GetHashTableSize() const { return m_nHashTableSize; } - - void InitHashTable(uint32_t hashSize, FX_BOOL bAllocNow = TRUE); - - protected: - CAssoc** m_pHashTable; - - uint32_t m_nHashTableSize; - - int m_nCount; - - CAssoc* m_pFreeList; - - struct CFX_Plex* m_pBlocks; - - int m_nBlockSize; - - uint32_t HashKey(void* key) const; - - CAssoc* NewAssoc(); - - void FreeAssoc(CAssoc* pAssoc); - - CAssoc* GetAssocAt(void* key, uint32_t& hash) const; -}; - -template <class KeyType, class ValueType> -class CFX_MapPtrTemplate : public CFX_MapPtrToPtr { - public: - CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {} - - FX_BOOL Lookup(KeyType key, ValueType& rValue) const { - void* pValue = nullptr; - if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) { - return FALSE; - } - rValue = (ValueType)(uintptr_t)pValue; - return TRUE; - } - - ValueType& operator[](KeyType key) { - return (ValueType&)CFX_MapPtrToPtr::operator[]((void*)(uintptr_t)key); - } - - void SetAt(KeyType key, ValueType newValue) { - CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue); - } - - FX_BOOL RemoveKey(KeyType key) { - return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key); - } - - void GetNextAssoc(FX_POSITION& rNextPosition, - KeyType& rKey, - ValueType& rValue) const { - void* pKey = nullptr; - void* pValue = nullptr; - CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue); - rKey = (KeyType)(uintptr_t)pKey; - rValue = (ValueType)(uintptr_t)pValue; - } -}; -#endif // PDF_ENABLE_XFA - -class CFX_PtrList { - protected: - struct CNode { - CNode* pNext; - CNode* pPrev; - void* data; - }; - - public: - CFX_PtrList(int nBlockSize = 10); - - 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 = nullptr) const; - FX_POSITION FindIndex(int index) const; - - void RemoveAt(FX_POSITION pos); - void RemoveAll(); - - protected: - 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(); -}; - -#ifdef PDF_ENABLE_XFA -typedef void (*PD_CALLBACK_FREEDATA)(void* pData); -#endif // PDF_ENABLE_XFA - -class CFX_BitStream { - public: - void Init(const uint8_t* pData, uint32_t dwSize); - - uint32_t GetBits(uint32_t nBits); - - void ByteAlign(); - - FX_BOOL IsEOF() { return m_BitPos >= m_BitSize; } - - void SkipBits(uint32_t nBits) { m_BitPos += nBits; } - - void Rewind() { m_BitPos = 0; } - - uint32_t GetPos() const { return m_BitPos; } - - uint32_t BitsRemaining() const { - return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0; - } - - protected: - uint32_t m_BitPos; - - uint32_t m_BitSize; - - const uint8_t* m_pData; -}; - -class IFX_Pause { - public: - virtual ~IFX_Pause() {} - virtual FX_BOOL NeedToPauseNow() = 0; -}; - -template <typename T> -class CFX_AutoRestorer { - public: - explicit CFX_AutoRestorer(T* location) - : m_Location(location), m_OldValue(*location) {} - ~CFX_AutoRestorer() { *m_Location = m_OldValue; } - - private: - T* const m_Location; - const T m_OldValue; -}; - -#define FX_DATALIST_LENGTH 1024 -template <size_t unit> -class CFX_SortListArray { - protected: - struct DataList { - int32_t start; - - int32_t count; - uint8_t* data; - }; - - public: - CFX_SortListArray() : m_CurList(0) {} - - ~CFX_SortListArray() { Clear(); } - - void Clear() { - for (int32_t i = m_DataLists.GetUpperBound(); i >= 0; i--) { - DataList list = m_DataLists.ElementAt(i); - FX_Free(list.data); - } - m_DataLists.RemoveAll(); - m_CurList = 0; - } - - void Append(int32_t nStart, int32_t nCount) { - if (nStart < 0) { - return; - } - while (nCount > 0) { - int32_t temp_count = std::min(nCount, FX_DATALIST_LENGTH); - DataList list; - list.data = FX_Alloc2D(uint8_t, temp_count, unit); - list.start = nStart; - list.count = temp_count; - Append(list); - nCount -= temp_count; - nStart += temp_count; - } - } - - uint8_t* GetAt(int32_t nIndex) { - if (nIndex < 0) { - return nullptr; - } - if (m_CurList < 0 || m_CurList >= m_DataLists.GetSize()) { - return nullptr; - } - DataList* pCurList = m_DataLists.GetDataPtr(m_CurList); - if (!pCurList || nIndex < pCurList->start || - nIndex >= pCurList->start + pCurList->count) { - pCurList = nullptr; - int32_t iStart = 0; - int32_t iEnd = m_DataLists.GetUpperBound(); - int32_t iMid = 0; - while (iStart <= iEnd) { - iMid = (iStart + iEnd) / 2; - DataList* list = m_DataLists.GetDataPtr(iMid); - if (nIndex < list->start) { - iEnd = iMid - 1; - } else if (nIndex >= list->start + list->count) { - iStart = iMid + 1; - } else { - pCurList = list; - m_CurList = iMid; - break; - } - } - } - return pCurList ? pCurList->data + (nIndex - pCurList->start) * unit - : nullptr; - } - - protected: - void Append(const DataList& list) { - int32_t iStart = 0; - int32_t iEnd = m_DataLists.GetUpperBound(); - int32_t iFind = 0; - while (iStart <= iEnd) { - int32_t iMid = (iStart + iEnd) / 2; - DataList* cur_list = m_DataLists.GetDataPtr(iMid); - if (list.start < cur_list->start + cur_list->count) { - iEnd = iMid - 1; - } else { - if (iMid == iEnd) { - iFind = iMid + 1; - break; - } - DataList* next_list = m_DataLists.GetDataPtr(iMid + 1); - if (list.start < next_list->start) { - iFind = iMid + 1; - break; - } else { - iStart = iMid + 1; - } - } - } - m_DataLists.InsertAt(iFind, list); - } - int32_t m_CurList; - CFX_ArrayTemplate<DataList> m_DataLists; -}; -template <typename T1, typename T2> -class CFX_ListArrayTemplate { - public: - void Clear() { m_Data.Clear(); } - - void Add(int32_t nStart, int32_t nCount) { m_Data.Append(nStart, nCount); } - - T2& operator[](int32_t nIndex) { - uint8_t* data = m_Data.GetAt(nIndex); - ASSERT(data); - return (T2&)(*(volatile T2*)data); - } - - T2* GetPtrAt(int32_t nIndex) { return (T2*)m_Data.GetAt(nIndex); } - - protected: - T1 m_Data; -}; -typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_FILESIZE)>, - FX_FILESIZE> CFX_FileSizeListArray; - -#ifdef PDF_ENABLE_XFA -class IFX_Retainable { - public: - virtual uint32_t Retain() = 0; - virtual uint32_t Release() = 0; - - protected: - virtual ~IFX_Retainable() {} -}; -#define FX_IsOdd(a) ((a)&1) -#endif // PDF_ENABLE_XFA - -class CFX_Vector_3by1 { - public: - CFX_Vector_3by1() : a(0.0f), b(0.0f), c(0.0f) {} - - CFX_Vector_3by1(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1) - : a(a1), b(b1), c(c1) {} - - FX_FLOAT a; - FX_FLOAT b; - FX_FLOAT c; -}; -class CFX_Matrix_3by3 { - public: - CFX_Matrix_3by3() - : a(0.0f), - b(0.0f), - c(0.0f), - d(0.0f), - e(0.0f), - f(0.0f), - g(0.0f), - h(0.0f), - i(0.0f) {} - - CFX_Matrix_3by3(FX_FLOAT a1, - FX_FLOAT b1, - FX_FLOAT c1, - FX_FLOAT d1, - FX_FLOAT e1, - FX_FLOAT f1, - FX_FLOAT g1, - FX_FLOAT h1, - FX_FLOAT i1) - : a(a1), b(b1), c(c1), d(d1), e(e1), f(f1), g(g1), h(h1), i(i1) {} - - CFX_Matrix_3by3 Inverse(); - - CFX_Matrix_3by3 Multiply(const CFX_Matrix_3by3& m); - - CFX_Vector_3by1 TransformVector(const CFX_Vector_3by1& v); - - FX_FLOAT a; - FX_FLOAT b; - FX_FLOAT c; - FX_FLOAT d; - FX_FLOAT e; - FX_FLOAT f; - FX_FLOAT g; - FX_FLOAT h; - FX_FLOAT i; -}; - -uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); - -#endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_ diff --git a/core/fxcrt/include/fx_coordinates.h b/core/fxcrt/include/fx_coordinates.h deleted file mode 100644 index a7c01cadb7..0000000000 --- a/core/fxcrt/include/fx_coordinates.h +++ /dev/null @@ -1,671 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ -#define CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ - -#include "core/fxcrt/include/fx_basic.h" - -class CFX_Matrix; - -template <class BaseType> -class CFX_PSTemplate { - public: - CFX_PSTemplate() : x(0), y(0) {} - CFX_PSTemplate(BaseType new_x, BaseType new_y) : x(new_x), y(new_y) {} - CFX_PSTemplate(const CFX_PSTemplate& other) : x(other.x), y(other.y) {} - void clear() { - x = 0; - y = 0; - } - CFX_PSTemplate operator=(const CFX_PSTemplate& other) { - if (this != &other) { - x = other.x; - y = other.y; - } - return *this; - } - bool operator==(const CFX_PSTemplate& other) const { - return x == other.x && y == other.y; - } - bool operator!=(const CFX_PSTemplate& other) const { - return !(*this == other); - } - CFX_PSTemplate& operator+=(const CFX_PSTemplate<BaseType>& obj) { - x += obj.x; - y += obj.y; - return *this; - } - CFX_PSTemplate& operator-=(const CFX_PSTemplate<BaseType>& obj) { - x -= obj.x; - y -= obj.y; - return *this; - } - CFX_PSTemplate& operator*=(BaseType factor) { - x *= factor; - y *= factor; - return *this; - } - CFX_PSTemplate& operator/=(BaseType divisor) { - x /= divisor; - y /= divisor; - return *this; - } - CFX_PSTemplate operator+(const CFX_PSTemplate& other) { - return CFX_PSTemplate(x + other.x, y + other.y); - } - CFX_PSTemplate operator-(const CFX_PSTemplate& other) { - return CFX_PSTemplate(x - other.x, y - other.y); - } - CFX_PSTemplate operator*(BaseType factor) { - return CFX_PSTemplate(x * factor, y * factor); - } - CFX_PSTemplate operator/(BaseType divisor) { - return CFX_PSTemplate(x / divisor, y / divisor); - } - - BaseType x; - BaseType y; -}; -typedef CFX_PSTemplate<int32_t> CFX_Point; -typedef CFX_PSTemplate<FX_FLOAT> CFX_PointF; -typedef CFX_PSTemplate<int32_t> CFX_Size; -typedef CFX_PSTemplate<FX_FLOAT> CFX_SizeF; -typedef CFX_ArrayTemplate<CFX_Point> CFX_Points; -typedef CFX_ArrayTemplate<CFX_PointF> CFX_PointsF; - -template <class BaseType> -class CFX_VTemplate : public CFX_PSTemplate<BaseType> { - public: - using CFX_PSTemplate<BaseType>::x; - using CFX_PSTemplate<BaseType>::y; - - CFX_VTemplate() : CFX_PSTemplate<BaseType>() {} - CFX_VTemplate(BaseType new_x, BaseType new_y) - : CFX_PSTemplate<BaseType>(new_x, new_y) {} - - CFX_VTemplate(const CFX_VTemplate& other) : CFX_PSTemplate<BaseType>(other) {} - - CFX_VTemplate(const CFX_PSTemplate<BaseType>& point1, - const CFX_PSTemplate<BaseType>& point2) - : CFX_PSTemplate<BaseType>(point2.x - point1.x, point2.y - point1.y) {} - - FX_FLOAT Length() const { return FXSYS_sqrt(x * x + y * y); } - void Normalize() { - FX_FLOAT fLen = Length(); - if (fLen < 0.0001f) - return; - - x /= fLen; - y /= fLen; - } - void Translate(BaseType dx, BaseType dy) { - x += dx; - y += dy; - } - void Scale(BaseType sx, BaseType sy) { - x *= sx; - y *= sy; - } - void Rotate(FX_FLOAT fRadian) { - FX_FLOAT cosValue = FXSYS_cos(fRadian); - FX_FLOAT sinValue = FXSYS_sin(fRadian); - x = x * cosValue - y * sinValue; - y = x * sinValue + y * cosValue; - } -}; -typedef CFX_VTemplate<int32_t> CFX_Vector; -typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; - -// Rectangles. -// TODO(tsepez): Consolidate all these different rectangle classes. - -// LTRB rectangles (y-axis runs downwards). -struct FX_RECT { - FX_RECT() : left(0), top(0), right(0), bottom(0) {} - - FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {} - - int Width() const { return right - left; } - int Height() const { return bottom - top; } - bool IsEmpty() const { return right <= left || bottom <= top; } - - bool Valid() const { - pdfium::base::CheckedNumeric<int> w = right; - pdfium::base::CheckedNumeric<int> h = bottom; - w -= left; - h -= top; - return w.IsValid() && h.IsValid(); - } - - void Normalize(); - - void Intersect(const FX_RECT& src); - void Intersect(int l, int t, int r, int b) { Intersect(FX_RECT(l, t, r, b)); } - - void Union(const FX_RECT& other_rect); - void Union(int l, int t, int r, int b) { Union(FX_RECT(l, t, r, b)); } - - void Offset(int dx, int dy) { - left += dx; - right += dx; - top += dy; - bottom += dy; - } - - bool operator==(const FX_RECT& src) const { - return left == src.left && right == src.right && top == src.top && - bottom == src.bottom; - } - - 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; - } - - bool Contains(int x, int y) const { - return x >= left && x < right && y >= top && y < bottom; - } - - int32_t left; - int32_t top; - int32_t right; - int32_t bottom; -}; - -// LBRT rectangles (y-axis runs upwards). -class CFX_FloatPoint { - public: - CFX_FloatPoint() : x(0.0f), y(0.0f) {} - CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {} - - bool operator==(const CFX_FloatPoint& that) const { - return x == that.x && y == that.y; - } - bool operator!=(const CFX_FloatPoint& that) const { return !(*this == that); } - - FX_FLOAT x; - FX_FLOAT y; -}; - -// LTWH rectangles (y-axis runs downwards). -template <class baseType> -class CFX_RTemplate { - public: - typedef CFX_PSTemplate<baseType> FXT_POINT; - typedef CFX_PSTemplate<baseType> FXT_SIZE; - typedef CFX_VTemplate<baseType> FXT_VECTOR; - typedef CFX_RTemplate<baseType> FXT_RECT; - void Set(baseType dst_left, - baseType dst_top, - baseType dst_width, - baseType dst_height) { - left = dst_left; - top = dst_top; - width = dst_width; - height = dst_height; - } - void Set(baseType dst_left, baseType dst_top, const FXT_SIZE& dst_size) { - left = dst_left; - top = dst_top; - Size(dst_size); - } - void Set(const FXT_POINT& p, baseType dst_width, baseType dst_height) { - TopLeft(p); - width = dst_width; - height = dst_height; - } - void Set(const FXT_POINT& p1, const FXT_POINT& p2) { - TopLeft(p1); - width = p2.x - p1.x; - height = p2.y - p1.y; - Normalize(); - } - void Set(const FXT_POINT& p, const FXT_VECTOR& v) { - TopLeft(p); - width = v.x; - height = v.y; - Normalize(); - } - void Reset() { - left = 0; - top = 0; - width = 0; - 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 off_left, - baseType off_top, - baseType off_right, - baseType off_bottom) { - left -= off_left; - top -= off_top; - width += off_left + off_right; - height += off_top + off_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 off_left, - baseType off_top, - baseType off_right, - baseType off_bottom) { - left += off_left; - top += off_top; - width -= off_left + off_right; - height -= off_top + off_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; } - bool Contains(baseType x, baseType y) const { - return x >= left && x < left + width && y >= top && y < top + height; - } - bool Contains(const FXT_POINT& p) const { return Contains(p.x, p.y); } - 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 Union(baseType x, baseType y) { - baseType r = right(); - baseType 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(); - baseType 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(); - baseType 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 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 bool operator!=(const FXT_RECT& rc1, const FXT_RECT& rc2) { - return !(rc1 == rc2); - } - baseType left, top; - baseType width, height; -}; -typedef CFX_RTemplate<int32_t> CFX_Rect; -typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; -typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray; - -class CFX_FloatRect { - public: - CFX_FloatRect() : CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f) {} - CFX_FloatRect(FX_FLOAT l, FX_FLOAT b, FX_FLOAT r, FX_FLOAT t) - : left(l), bottom(b), right(r), top(t) {} - - explicit CFX_FloatRect(const FX_FLOAT* pArray) - : CFX_FloatRect(pArray[0], pArray[1], pArray[2], pArray[3]) {} - - explicit CFX_FloatRect(const FX_RECT& rect); - - void Normalize(); - - void Reset() { - left = 0.0f; - right = 0.0f; - bottom = 0.0f; - top = 0.0f; - } - - bool IsEmpty() const { return left >= right || bottom >= top; } - bool Contains(const CFX_FloatRect& other_rect) const; - 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 GetOuterRect() const; - FX_RECT GetClosestRect() const; - - int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); - - void InitRect(FX_FLOAT x, FX_FLOAT y) { - left = x; - right = x; - bottom = y; - 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 other_left, - FX_FLOAT other_bottom, - FX_FLOAT other_right, - FX_FLOAT other_top) { - Normalize(); - left -= other_left; - bottom -= other_bottom; - right += other_right; - top += other_top; - } - - void Inflate(const CFX_FloatRect& rt) { - Inflate(rt.left, rt.bottom, rt.right, rt.top); - } - - void Deflate(FX_FLOAT x, FX_FLOAT y) { - Normalize(); - left += x; - right -= x; - bottom += y; - top -= y; - } - - void Deflate(FX_FLOAT other_left, - FX_FLOAT other_bottom, - FX_FLOAT other_right, - FX_FLOAT other_top) { - Normalize(); - left += other_left; - bottom += other_bottom; - right -= other_right; - top -= other_top; - } - - void Deflate(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_PointF* pPoints, int nPoints); - - FX_RECT ToFxRect() const { - return FX_RECT(static_cast<int32_t>(left), static_cast<int32_t>(top), - static_cast<int32_t>(right), static_cast<int32_t>(bottom)); - } - - static CFX_FloatRect FromCFXRectF(const CFX_RectF& rect) { - return CFX_FloatRect(rect.left, rect.top, rect.right(), rect.bottom()); - } - - FX_FLOAT left; - FX_FLOAT bottom; - FX_FLOAT right; - FX_FLOAT top; -}; - -class CFX_Matrix { - public: - CFX_Matrix() { SetIdentity(); } - - 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); - - FX_BOOL IsIdentity() const { - return a == 1 && b == 0 && c == 0 && d == 1 && e == 0 && f == 0; - } - - FX_BOOL IsInvertible() const; - FX_BOOL Is90Rotated() const; - FX_BOOL IsScaled() const; - - void Translate(FX_FLOAT x, FX_FLOAT y, FX_BOOL bPrepended = FALSE); - void TranslateI(int32_t x, int32_t y, FX_BOOL bPrepended = FALSE) { - Translate((FX_FLOAT)x, (FX_FLOAT)y, bPrepended); - } - - void Scale(FX_FLOAT sx, FX_FLOAT sy, FX_BOOL bPrepended = FALSE); - void Rotate(FX_FLOAT fRadian, FX_BOOL bPrepended = FALSE); - void RotateAt(FX_FLOAT fRadian, - FX_FLOAT x, - FX_FLOAT y, - FX_BOOL bPrepended = FALSE); - - void Shear(FX_FLOAT fAlphaRadian, - FX_FLOAT fBetaRadian, - FX_BOOL bPrepended = FALSE); - - void MatchRect(const CFX_FloatRect& dest, const CFX_FloatRect& src); - FX_FLOAT GetXUnit() const; - FX_FLOAT GetYUnit() const; - void GetUnitRect(CFX_RectF& rect) const; - CFX_FloatRect GetUnitRect() const; - - FX_FLOAT GetUnitArea() const; - FX_FLOAT TransformXDistance(FX_FLOAT dx) const; - int32_t TransformXDistance(int32_t dx) const; - FX_FLOAT TransformYDistance(FX_FLOAT dy) const; - int32_t TransformYDistance(int32_t dy) const; - FX_FLOAT TransformDistance(FX_FLOAT dx, FX_FLOAT dy) const; - int32_t TransformDistance(int32_t dx, int32_t dy) const; - FX_FLOAT TransformDistance(FX_FLOAT distance) const; - - void TransformPoint(FX_FLOAT& x, FX_FLOAT& y) const; - void TransformPoint(int32_t& x, int32_t& y) const; - - void 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; -}; - -#endif // CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ diff --git a/core/fxcrt/include/fx_ext.h b/core/fxcrt/include/fx_ext.h deleted file mode 100644 index e33d57bdb7..0000000000 --- a/core/fxcrt/include/fx_ext.h +++ /dev/null @@ -1,130 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_EXT_H_ -#define CORE_FXCRT_INCLUDE_FX_EXT_H_ - -#include <cctype> -#include <cwctype> - -#include "core/fxcrt/include/fx_basic.h" - -#define FX_INVALID_OFFSET static_cast<uint32_t>(-1) - -// TODO(thestig) Using unique_ptr with ReleaseDeleter is still not ideal. -// Come up or wait for something better. This appears in this file rather -// than fx_stream.h due to include ordering restrictions. -using ScopedFileStream = - std::unique_ptr<IFX_FileStream, ReleaseDeleter<IFX_FileStream>>; - -FX_FLOAT FXSYS_tan(FX_FLOAT a); -FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); -FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, - int32_t iLength = -1, - int32_t* pUsedLen = nullptr); -FX_FLOAT FXSYS_wcstof(const FX_WCHAR* pwsStr, - int32_t iLength = -1, - int32_t* pUsedLen = nullptr); -FX_WCHAR* FXSYS_wcsncpy(FX_WCHAR* dstStr, const FX_WCHAR* srcStr, size_t count); -int32_t FXSYS_wcsnicmp(const FX_WCHAR* s1, const FX_WCHAR* s2, size_t count); -int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count); - -inline bool FXSYS_islower(int32_t ch) { - return ch >= 'a' && ch <= 'z'; -} -inline bool FXSYS_isupper(int32_t ch) { - return ch >= 'A' && ch <= 'Z'; -} -inline int32_t FXSYS_tolower(int32_t ch) { - return ch < 'A' || ch > 'Z' ? ch : (ch + 0x20); -} -inline int32_t FXSYS_toupper(int32_t ch) { - return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); -} -inline bool FXSYS_iswalpha(wchar_t wch) { - return (wch >= L'A' && wch <= L'Z') || (wch >= L'a' && wch <= L'z'); -} -inline bool FXSYS_iswdigit(wchar_t wch) { - return wch >= L'0' && wch <= L'9'; -} -inline bool FXSYS_iswalnum(wchar_t wch) { - return FXSYS_iswalpha(wch) || FXSYS_iswdigit(wch); -} -inline bool FXSYS_iswspace(FX_WCHAR c) { - return (c == 0x20) || (c == 0x0d) || (c == 0x0a) || (c == 0x09); -} - -inline int FXSYS_toHexDigit(const FX_CHAR c) { - if (!std::isxdigit(c)) - return 0; - char upchar = std::toupper(c); - return upchar > '9' ? upchar - 'A' + 10 : upchar - '0'; -} - -inline bool FXSYS_isDecimalDigit(const FX_CHAR c) { - return !!std::isdigit(c); -} - -inline bool FXSYS_isDecimalDigit(const FX_WCHAR c) { - return !!std::iswdigit(c); -} - -inline int FXSYS_toDecimalDigit(const FX_CHAR c) { - return std::isdigit(c) ? c - '0' : 0; -} - -inline int FXSYS_toDecimalDigit(const FX_WCHAR c) { - return std::iswdigit(c) ? c - L'0' : 0; -} - -FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value); -int FXSYS_FractionalScaleCount(); - -void* FX_Random_MT_Start(uint32_t dwSeed); -void FX_Random_MT_Close(void* pContext); -uint32_t FX_Random_MT_Generate(void* pContext); -void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount); -void FX_Random_GenerateMT(uint32_t* pBuffer, int32_t iCount); -void FX_Random_GenerateCrypto(uint32_t* pBuffer, int32_t iCount); - -#ifdef PDF_ENABLE_XFA -typedef struct FX_GUID { - uint32_t data1; - uint16_t data2; - uint16_t data3; - uint8_t data4[8]; -} FX_GUID, *FX_LPGUID; -typedef FX_GUID const* FX_LPCGUID; -void FX_GUID_CreateV4(FX_LPGUID pGUID); -void FX_GUID_ToString(FX_LPCGUID pGUID, - CFX_ByteString& bsStr, - FX_BOOL bSeparator = TRUE); -#endif // PDF_ENABLE_XFA - -template <class baseType> -class CFX_SSortTemplate { - public: - void ShellSort(baseType* pArray, int32_t iCount) { - ASSERT(pArray && iCount > 0); - int32_t i, j, gap; - baseType v1, v2; - gap = iCount >> 1; - while (gap > 0) { - for (i = gap; i < iCount; i++) { - j = i - gap; - v1 = pArray[i]; - while (j > -1 && (v2 = pArray[j]) > v1) { - pArray[j + gap] = v2; - j -= gap; - } - pArray[j + gap] = v1; - } - gap >>= 1; - } - } -}; - -#endif // CORE_FXCRT_INCLUDE_FX_EXT_H_ diff --git a/core/fxcrt/include/fx_memory.h b/core/fxcrt/include/fx_memory.h deleted file mode 100644 index a3eba2fd79..0000000000 --- a/core/fxcrt/include/fx_memory.h +++ /dev/null @@ -1,112 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_MEMORY_H_ -#define CORE_FXCRT_INCLUDE_FX_MEMORY_H_ - -#include "core/fxcrt/include/fx_system.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// For external C libraries to malloc through PDFium. These may return nullptr. -void* FXMEM_DefaultAlloc(size_t byte_size, int flags); -void* FXMEM_DefaultRealloc(void* pointer, size_t new_size, int flags); -void FXMEM_DefaultFree(void* pointer, int flags); - -#ifdef __cplusplus -} // extern "C" - -#include <stdlib.h> -#include <limits> -#include <memory> -#include <new> - -NEVER_INLINE void FX_OutOfMemoryTerminate(); - -inline void* FX_SafeRealloc(void* ptr, size_t num_members, size_t member_size) { - if (num_members < std::numeric_limits<size_t>::max() / member_size) { - return realloc(ptr, num_members * member_size); - } - return nullptr; -} - -inline void* FX_AllocOrDie(size_t num_members, size_t member_size) { - // TODO(tsepez): See if we can avoid the implicit memset(0). - if (void* result = calloc(num_members, member_size)) { - return result; - } - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. -} - -inline void* FX_AllocOrDie2D(size_t w, size_t h, size_t member_size) { - if (w < std::numeric_limits<size_t>::max() / h) { - return FX_AllocOrDie(w * h, member_size); - } - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. -} - -inline void* FX_ReallocOrDie(void* ptr, - size_t num_members, - size_t member_size) { - if (void* result = FX_SafeRealloc(ptr, num_members, member_size)) { - return result; - } - FX_OutOfMemoryTerminate(); // Never returns. - return nullptr; // Suppress compiler warning. -} - -// Never returns nullptr. -#define FX_Alloc(type, size) (type*) FX_AllocOrDie(size, sizeof(type)) -#define FX_Alloc2D(type, w, h) (type*) FX_AllocOrDie2D(w, h, sizeof(type)) -#define FX_Realloc(type, ptr, size) \ - (type*) FX_ReallocOrDie(ptr, size, sizeof(type)) - -// May return nullptr. -#define FX_TryAlloc(type, size) (type*) calloc(size, sizeof(type)) -#define FX_TryRealloc(type, ptr, size) \ - (type*) FX_SafeRealloc(ptr, size, sizeof(type)) - -#define FX_Free(ptr) free(ptr) - -// The FX_ArraySize(arr) macro returns the # of elements in an array arr. -// The expression is a compile-time constant, and therefore can be -// used in defining new arrays, for example. If you use FX_ArraySize on -// a pointer by mistake, you will get a compile-time error. -// -// One caveat is that FX_ArraySize() doesn't accept any array of an -// anonymous type or a type defined inside a function. -#define FX_ArraySize(array) (sizeof(ArraySizeHelper(array))) - -// This template function declaration is used in defining FX_ArraySize. -// Note that the function doesn't need an implementation, as we only -// use its type. -template <typename T, size_t N> -char(&ArraySizeHelper(T(&array)[N]))[N]; - -// Used with std::unique_ptr to FX_Free raw memory. -struct FxFreeDeleter { - inline void operator()(void* ptr) const { FX_Free(ptr); } -}; - -// Used with std::unique_ptr to Release() objects that can't be deleted. -template <class T> -struct ReleaseDeleter { - inline void operator()(T* ptr) const { ptr->Release(); } -}; - -// Used to help transfer ownership of a raw pointer to std::unique_ptr. -template <typename T> -std::unique_ptr<T> WrapUnique(T* ptr) { - return std::unique_ptr<T>(ptr); -} - -#endif // __cplusplus - -#endif // CORE_FXCRT_INCLUDE_FX_MEMORY_H_ diff --git a/core/fxcrt/include/fx_safe_types.h b/core/fxcrt/include/fx_safe_types.h deleted file mode 100644 index f12e74906b..0000000000 --- a/core/fxcrt/include/fx_safe_types.h +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -#ifndef CORE_FXCRT_INCLUDE_FX_SAFE_TYPES_H_ -#define CORE_FXCRT_INCLUDE_FX_SAFE_TYPES_H_ - -#include <stdlib.h> // For size_t. - -#include "core/fxcrt/include/fx_stream.h" // for FX_FILESIZE. -#include "core/fxcrt/include/fx_system.h" -#include "third_party/base/numerics/safe_math.h" - -typedef pdfium::base::CheckedNumeric<uint32_t> FX_SAFE_UINT32; -typedef pdfium::base::CheckedNumeric<int32_t> FX_SAFE_INT32; -typedef pdfium::base::CheckedNumeric<size_t> FX_SAFE_SIZE_T; -typedef pdfium::base::CheckedNumeric<FX_FILESIZE> FX_SAFE_FILESIZE; -typedef pdfium::base::CheckedNumeric<FX_STRSIZE> FX_SAFE_STRSIZE; - -#endif // CORE_FXCRT_INCLUDE_FX_SAFE_TYPES_H_ diff --git a/core/fxcrt/include/fx_stream.h b/core/fxcrt/include/fx_stream.h deleted file mode 100644 index a91b59f285..0000000000 --- a/core/fxcrt/include/fx_stream.h +++ /dev/null @@ -1,162 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_STREAM_H_ -#define CORE_FXCRT_INCLUDE_FX_STREAM_H_ - -#include "core/fxcrt/include/fx_string.h" -#include "core/fxcrt/include/fx_system.h" - -void* FX_OpenFolder(const FX_CHAR* path); -void* FX_OpenFolder(const FX_WCHAR* path); -FX_BOOL FX_GetNextFile(void* handle, - CFX_ByteString& filename, - FX_BOOL& bFolder); -FX_BOOL FX_GetNextFile(void* handle, - CFX_WideString& filename, - FX_BOOL& bFolder); -void FX_CloseFolder(void* handle); -FX_WCHAR FX_GetFolderSeparator(); - -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -#define FX_FILESIZE int32_t -#else -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> - -#ifndef O_BINARY -#define O_BINARY 0 -#endif // O_BINARY - -#ifndef O_LARGEFILE -#define O_LARGEFILE 0 -#endif // O_LARGEFILE - -#define FX_FILESIZE off_t -#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - -#define FX_GETBYTEOFFSET32(a) 0 -#define FX_GETBYTEOFFSET40(a) 0 -#define FX_GETBYTEOFFSET48(a) 0 -#define FX_GETBYTEOFFSET56(a) 0 -#define FX_GETBYTEOFFSET24(a) ((uint8_t)(a >> 24)) -#define FX_GETBYTEOFFSET16(a) ((uint8_t)(a >> 16)) -#define FX_GETBYTEOFFSET8(a) ((uint8_t)(a >> 8)) -#define FX_GETBYTEOFFSET0(a) ((uint8_t)(a)) -#define FX_FILEMODE_Write 0 -#define FX_FILEMODE_ReadOnly 1 -#define FX_FILEMODE_Truncate 2 - -class IFX_StreamWrite { - public: - virtual ~IFX_StreamWrite() {} - virtual void Release() = 0; - virtual FX_BOOL WriteBlock(const void* pData, size_t size) = 0; -}; - -class IFX_FileWrite : public IFX_StreamWrite { - public: - // IFX_StreamWrite: - FX_BOOL WriteBlock(const void* pData, size_t size) override; - virtual FX_FILESIZE GetSize() = 0; - virtual FX_BOOL Flush() = 0; - virtual FX_BOOL WriteBlock(const void* pData, - FX_FILESIZE offset, - size_t size) = 0; -}; - -class IFX_StreamRead { - public: - virtual ~IFX_StreamRead() {} - - 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 : public IFX_StreamRead { - public: - // IFX_StreamRead: - void Release() override = 0; - FX_BOOL IsEOF() override; - FX_FILESIZE GetPosition() override; - size_t ReadBlock(void* buffer, size_t size) override; - - virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) = 0; - virtual FX_FILESIZE GetSize() = 0; -}; - -IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename); -IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename); - -class IFX_FileStream : public IFX_FileRead, public IFX_FileWrite { - public: - virtual IFX_FileStream* Retain() = 0; - - // IFX_FileRead: - void Release() override = 0; - FX_BOOL IsEOF() override = 0; - FX_FILESIZE GetPosition() override = 0; - size_t ReadBlock(void* buffer, size_t size) override = 0; - FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override = 0; - FX_FILESIZE GetSize() override = 0; - - // IFX_FileWrite: - FX_BOOL WriteBlock(const void* buffer, - FX_FILESIZE offset, - size_t size) override = 0; - FX_BOOL WriteBlock(const void* buffer, size_t size) override; - FX_BOOL Flush() override = 0; -}; - -IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes); -IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, uint32_t dwModes); - -#ifdef PDF_ENABLE_XFA -class IFX_FileAccess { - public: - virtual ~IFX_FileAccess() {} - virtual void Release() = 0; - virtual IFX_FileAccess* Retain() = 0; - virtual void GetPath(CFX_WideString& wsPath) = 0; - virtual IFX_FileStream* CreateFileStream(uint32_t dwModes) = 0; -}; -IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath); -#endif // PDF_ENABLE_XFA - -class IFX_MemoryStream : public IFX_FileStream { - public: - virtual FX_BOOL IsConsecutive() const = 0; - virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0; - virtual uint8_t* GetBuffer() const = 0; - virtual void AttachBuffer(uint8_t* pBuffer, - size_t nSize, - FX_BOOL bTakeOver = FALSE) = 0; - virtual void DetachBuffer() = 0; -}; - -IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, - size_t nSize, - FX_BOOL bTakeOver = FALSE); -IFX_MemoryStream* FX_CreateMemoryStream(FX_BOOL bConsecutive = FALSE); - -class IFX_BufferRead : public IFX_StreamRead { - public: - // IFX_StreamRead: - void Release() override = 0; - FX_BOOL IsEOF() override = 0; - FX_FILESIZE GetPosition() override = 0; - size_t ReadBlock(void* buffer, size_t size) override = 0; - - virtual FX_BOOL ReadNextBlock(FX_BOOL bRestart = FALSE) = 0; - virtual const uint8_t* GetBlockBuffer() = 0; - virtual size_t GetBlockSize() = 0; - virtual FX_FILESIZE GetBlockOffset() = 0; -}; - -#endif // CORE_FXCRT_INCLUDE_FX_STREAM_H_ diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h deleted file mode 100644 index 6e9af221ca..0000000000 --- a/core/fxcrt/include/fx_string.h +++ /dev/null @@ -1,465 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_STRING_H_ -#define CORE_FXCRT_INCLUDE_FX_STRING_H_ - -#include <stdint.h> // For intptr_t. - -#include <algorithm> -#include <functional> - -#include "core/fxcrt/cfx_string_c_template.h" -#include "core/fxcrt/cfx_string_data_template.h" -#include "core/fxcrt/include/cfx_retain_ptr.h" -#include "core/fxcrt/include/fx_memory.h" -#include "core/fxcrt/include/fx_system.h" - -class CFX_ByteString; -class CFX_WideString; - -using CFX_ByteStringC = CFX_StringCTemplate<FX_CHAR>; -using CFX_WideStringC = CFX_StringCTemplate<FX_WCHAR>; - -#define FXBSTR_ID(c1, c2, c3, c4) \ - (((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | \ - ((uint32_t)c4)) - -#define FX_WSTRC(wstr) CFX_WideStringC(wstr, FX_ArraySize(wstr) - 1) - -// A mutable string with shared buffers using copy-on-write semantics that -// avoids the cost of std::string's iterator stability guarantees. -class CFX_ByteString { - public: - using CharType = FX_CHAR; - - CFX_ByteString(); - CFX_ByteString(const CFX_ByteString& other); - CFX_ByteString(CFX_ByteString&& other); - - // Deliberately implicit to avoid calling on every string literal. - CFX_ByteString(char ch); - CFX_ByteString(const FX_CHAR* ptr); - - CFX_ByteString(const FX_CHAR* ptr, FX_STRSIZE len); - CFX_ByteString(const uint8_t* ptr, FX_STRSIZE len); - - explicit CFX_ByteString(const CFX_ByteStringC& bstrc); - CFX_ByteString(const CFX_ByteStringC& bstrc1, const CFX_ByteStringC& bstrc2); - - ~CFX_ByteString(); - - void clear() { m_pData.Reset(); } - - static CFX_ByteString FromUnicode(const FX_WCHAR* ptr, FX_STRSIZE len = -1); - static CFX_ByteString FromUnicode(const CFX_WideString& str); - - // Explicit conversion to C-style string. - // Note: Any subsequent modification of |this| will invalidate the result. - const FX_CHAR* c_str() const { return m_pData ? m_pData->m_String : ""; } - - // Explicit conversion to uint8_t*. - // Note: Any subsequent modification of |this| will invalidate the result. - const uint8_t* raw_str() const { - return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String) - : nullptr; - } - - // Explicit conversion to CFX_ByteStringC. - // Note: Any subsequent modification of |this| will invalidate the result. - CFX_ByteStringC AsStringC() const { - return CFX_ByteStringC(raw_str(), GetLength()); - } - - FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } - bool IsEmpty() const { return !GetLength(); } - - int Compare(const CFX_ByteStringC& str) const; - bool EqualNoCase(const CFX_ByteStringC& str) const; - - bool operator==(const char* ptr) const; - bool operator==(const CFX_ByteStringC& str) const; - bool operator==(const CFX_ByteString& other) const; - - bool operator!=(const char* ptr) const { return !(*this == ptr); } - bool operator!=(const CFX_ByteStringC& str) const { return !(*this == str); } - bool operator!=(const CFX_ByteString& other) const { - return !(*this == other); - } - - bool operator<(const CFX_ByteString& str) const; - - const CFX_ByteString& operator=(const FX_CHAR* str); - const CFX_ByteString& operator=(const CFX_ByteStringC& bstrc); - const CFX_ByteString& operator=(const CFX_ByteString& stringSrc); - - const CFX_ByteString& operator+=(FX_CHAR ch); - const CFX_ByteString& operator+=(const FX_CHAR* str); - const CFX_ByteString& operator+=(const CFX_ByteString& str); - const CFX_ByteString& operator+=(const CFX_ByteStringC& bstrc); - - uint8_t GetAt(FX_STRSIZE nIndex) const { - return m_pData ? m_pData->m_String[nIndex] : 0; - } - - uint8_t 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(const FX_CHAR* lpszFormat, ...); - void FormatV(const FX_CHAR* lpszFormat, va_list argList); - - void Reserve(FX_STRSIZE len); - FX_CHAR* GetBuffer(FX_STRSIZE len); - 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(const CFX_ByteStringC& 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(const CFX_ByteStringC& lpszTargets); - - void TrimLeft(); - void TrimLeft(FX_CHAR chTarget); - void TrimLeft(const CFX_ByteStringC& lpszTargets); - - FX_STRSIZE Replace(const CFX_ByteStringC& lpszOld, - const CFX_ByteStringC& lpszNew); - - FX_STRSIZE Remove(FX_CHAR ch); - - CFX_WideString UTF8Decode() const; - - uint32_t GetID(FX_STRSIZE start_pos = 0) const; - -#define FXFORMAT_SIGNED 1 -#define FXFORMAT_HEX 2 -#define FXFORMAT_CAPITAL 4 - - static CFX_ByteString FormatInteger(int i, uint32_t flags = 0); - static CFX_ByteString FormatFloat(FX_FLOAT f, int precision = 0); - - protected: - using StringData = CFX_StringDataTemplate<FX_CHAR>; - - void ReallocBeforeWrite(FX_STRSIZE nNewLen); - void AllocBeforeWrite(FX_STRSIZE nNewLen); - void AllocCopy(CFX_ByteString& dest, - FX_STRSIZE nCopyLen, - FX_STRSIZE nCopyIndex) const; - void AssignCopy(const FX_CHAR* pSrcData, FX_STRSIZE nSrcLen); - void Concat(const FX_CHAR* lpszSrcData, FX_STRSIZE nSrcLen); - - CFX_RetainPtr<StringData> m_pData; - - friend class fxcrt_ByteStringConcat_Test; - friend class fxcrt_ByteStringPool_Test; -}; - -inline bool operator==(const char* lhs, const CFX_ByteString& rhs) { - return rhs == lhs; -} -inline bool operator==(const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { - return rhs == lhs; -} -inline bool operator!=(const char* lhs, const CFX_ByteString& rhs) { - return rhs != lhs; -} -inline bool operator!=(const CFX_ByteStringC& lhs, const CFX_ByteString& rhs) { - return rhs != lhs; -} - -inline CFX_ByteString operator+(const CFX_ByteStringC& str1, - const CFX_ByteStringC& str2) { - return CFX_ByteString(str1, str2); -} -inline CFX_ByteString operator+(const CFX_ByteStringC& str1, - const FX_CHAR* str2) { - return CFX_ByteString(str1, str2); -} -inline CFX_ByteString operator+(const FX_CHAR* str1, - const CFX_ByteStringC& str2) { - return CFX_ByteString(str1, str2); -} -inline CFX_ByteString operator+(const CFX_ByteStringC& str1, FX_CHAR ch) { - return CFX_ByteString(str1, CFX_ByteStringC(ch)); -} -inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteStringC& str2) { - return CFX_ByteString(ch, str2); -} -inline CFX_ByteString operator+(const CFX_ByteString& str1, - const CFX_ByteString& str2) { - return CFX_ByteString(str1.AsStringC(), str2.AsStringC()); -} -inline CFX_ByteString operator+(const CFX_ByteString& str1, FX_CHAR ch) { - return CFX_ByteString(str1.AsStringC(), CFX_ByteStringC(ch)); -} -inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteString& str2) { - return CFX_ByteString(ch, str2.AsStringC()); -} -inline CFX_ByteString operator+(const CFX_ByteString& str1, - const FX_CHAR* str2) { - return CFX_ByteString(str1.AsStringC(), str2); -} -inline CFX_ByteString operator+(const FX_CHAR* str1, - const CFX_ByteString& str2) { - return CFX_ByteString(str1, str2.AsStringC()); -} -inline CFX_ByteString operator+(const CFX_ByteString& str1, - const CFX_ByteStringC& str2) { - return CFX_ByteString(str1.AsStringC(), str2); -} -inline CFX_ByteString operator+(const CFX_ByteStringC& str1, - const CFX_ByteString& str2) { - return CFX_ByteString(str1, str2.AsStringC()); -} - -// A mutable string with shared buffers using copy-on-write semantics that -// avoids the cost of std::string's iterator stability guarantees. -class CFX_WideString { - public: - using CharType = FX_WCHAR; - - CFX_WideString(); - CFX_WideString(const CFX_WideString& other); - CFX_WideString(CFX_WideString&& other); - - // Deliberately implicit to avoid calling on every string literal. - CFX_WideString(FX_WCHAR ch); - CFX_WideString(const FX_WCHAR* ptr); - - CFX_WideString(const FX_WCHAR* ptr, FX_STRSIZE len); - - explicit CFX_WideString(const CFX_WideStringC& str); - CFX_WideString(const CFX_WideStringC& str1, const CFX_WideStringC& str2); - - ~CFX_WideString(); - - static CFX_WideString FromLocal(const CFX_ByteStringC& str); - static CFX_WideString FromCodePage(const CFX_ByteStringC& str, - uint16_t codepage); - - static CFX_WideString FromUTF8(const CFX_ByteStringC& str); - static CFX_WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len); - - static FX_STRSIZE WStringLength(const unsigned short* str); - - // Explicit conversion to C-style wide string. - // Note: Any subsequent modification of |this| will invalidate the result. - const FX_WCHAR* c_str() const { return m_pData ? m_pData->m_String : L""; } - - // Explicit conversion to CFX_WideStringC. - // Note: Any subsequent modification of |this| will invalidate the result. - CFX_WideStringC AsStringC() const { - return CFX_WideStringC(c_str(), GetLength()); - } - - void clear() { m_pData.Reset(); } - - FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; } - bool IsEmpty() const { return !GetLength(); } - - const CFX_WideString& operator=(const FX_WCHAR* str); - const CFX_WideString& operator=(const CFX_WideString& stringSrc); - const CFX_WideString& operator=(const CFX_WideStringC& stringSrc); - - const CFX_WideString& operator+=(const FX_WCHAR* str); - const CFX_WideString& operator+=(FX_WCHAR ch); - const CFX_WideString& operator+=(const CFX_WideString& str); - const CFX_WideString& operator+=(const CFX_WideStringC& str); - - bool operator==(const wchar_t* ptr) const; - bool operator==(const CFX_WideStringC& str) const; - bool operator==(const CFX_WideString& other) const; - - bool operator!=(const wchar_t* ptr) const { return !(*this == ptr); } - bool operator!=(const CFX_WideStringC& str) const { return !(*this == str); } - bool operator!=(const CFX_WideString& other) const { - return !(*this == other); - } - - bool operator<(const CFX_WideString& str) const; - - 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(const FX_WCHAR* str) const; - int Compare(const CFX_WideString& str) const; - int CompareNoCase(const FX_WCHAR* 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(const FX_WCHAR* lpszFormat, ...); - void FormatV(const FX_WCHAR* lpszFormat, va_list argList); - - void MakeLower(); - void MakeUpper(); - - void TrimRight(); - void TrimRight(FX_WCHAR chTarget); - void TrimRight(const CFX_WideStringC& pTargets); - - void TrimLeft(); - void TrimLeft(FX_WCHAR chTarget); - void TrimLeft(const CFX_WideStringC& pTargets); - - void Reserve(FX_STRSIZE len); - FX_WCHAR* GetBuffer(FX_STRSIZE len); - void ReleaseBuffer(FX_STRSIZE len = -1); - - int GetInteger() const; - FX_FLOAT GetFloat() const; - - FX_STRSIZE Find(const CFX_WideStringC& pSub, FX_STRSIZE start = 0) const; - FX_STRSIZE Find(FX_WCHAR ch, FX_STRSIZE start = 0) const; - FX_STRSIZE Replace(const CFX_WideStringC& pOld, const CFX_WideStringC& pNew); - FX_STRSIZE Remove(FX_WCHAR ch); - - CFX_ByteString UTF8Encode() const; - CFX_ByteString UTF16LE_Encode() const; - - protected: - using StringData = CFX_StringDataTemplate<FX_WCHAR>; - - void ReallocBeforeWrite(FX_STRSIZE nLen); - void AllocBeforeWrite(FX_STRSIZE nLen); - void AllocCopy(CFX_WideString& dest, - FX_STRSIZE nCopyLen, - FX_STRSIZE nCopyIndex) const; - void AssignCopy(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen); - void Concat(const FX_WCHAR* lpszSrcData, FX_STRSIZE nSrcLen); - - CFX_RetainPtr<StringData> m_pData; - - friend class fxcrt_WideStringConcatInPlace_Test; - friend class fxcrt_WideStringPool_Test; -}; - -inline CFX_WideString operator+(const CFX_WideStringC& str1, - const CFX_WideStringC& str2) { - return CFX_WideString(str1, str2); -} -inline CFX_WideString operator+(const CFX_WideStringC& str1, - const FX_WCHAR* str2) { - return CFX_WideString(str1, str2); -} -inline CFX_WideString operator+(const FX_WCHAR* str1, - const CFX_WideStringC& str2) { - return CFX_WideString(str1, str2); -} -inline CFX_WideString operator+(const CFX_WideStringC& str1, FX_WCHAR ch) { - return CFX_WideString(str1, CFX_WideStringC(ch)); -} -inline CFX_WideString operator+(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.AsStringC(), str2.AsStringC()); -} -inline CFX_WideString operator+(const CFX_WideString& str1, FX_WCHAR ch) { - return CFX_WideString(str1.AsStringC(), CFX_WideStringC(ch)); -} -inline CFX_WideString operator+(FX_WCHAR ch, const CFX_WideString& str2) { - return CFX_WideString(ch, str2.AsStringC()); -} -inline CFX_WideString operator+(const CFX_WideString& str1, - const FX_WCHAR* str2) { - return CFX_WideString(str1.AsStringC(), str2); -} -inline CFX_WideString operator+(const FX_WCHAR* str1, - const CFX_WideString& str2) { - return CFX_WideString(str1, str2.AsStringC()); -} -inline CFX_WideString operator+(const CFX_WideString& str1, - const CFX_WideStringC& str2) { - return CFX_WideString(str1.AsStringC(), str2); -} -inline CFX_WideString operator+(const CFX_WideStringC& str1, - const CFX_WideString& str2) { - return CFX_WideString(str1, str2.AsStringC()); -} -inline bool operator==(const wchar_t* lhs, const CFX_WideString& rhs) { - return rhs == lhs; -} -inline bool operator==(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { - return rhs == lhs; -} -inline bool operator!=(const wchar_t* lhs, const CFX_WideString& rhs) { - return rhs != lhs; -} -inline bool operator!=(const CFX_WideStringC& lhs, const CFX_WideString& rhs) { - return rhs != lhs; -} - -CFX_ByteString FX_UTF8Encode(const FX_WCHAR* pwsStr, FX_STRSIZE len); -inline CFX_ByteString FX_UTF8Encode(const CFX_WideStringC& wsStr) { - return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); -} -inline CFX_ByteString FX_UTF8Encode(const CFX_WideString& wsStr) { - return FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()); -} - -FX_FLOAT FX_atof(const CFX_ByteStringC& str); -inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { - return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); -} -bool FX_atonum(const CFX_ByteStringC& str, void* pData); -FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); - -uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase); -uint32_t FX_HashCode_GetW(const CFX_WideStringC& str, bool bIgnoreCase); - -namespace std { - -template <> -struct hash<CFX_ByteString> { - std::size_t operator()(const CFX_ByteString& str) const { - return FX_HashCode_GetA(str.AsStringC(), false); - } -}; - -template <> -struct hash<CFX_WideString> { - std::size_t operator()(const CFX_WideString& str) const { - return FX_HashCode_GetW(str.AsStringC(), false); - } -}; - -} // namespace std - -extern template struct std::hash<CFX_ByteString>; -extern template struct std::hash<CFX_WideString>; - -#endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ diff --git a/core/fxcrt/include/fx_system.h b/core/fxcrt/include/fx_system.h deleted file mode 100644 index 0542f33047..0000000000 --- a/core/fxcrt/include/fx_system.h +++ /dev/null @@ -1,342 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_SYSTEM_H_ -#define CORE_FXCRT_INCLUDE_FX_SYSTEM_H_ - -#include <assert.h> -#include <math.h> -#include <stdarg.h> -#include <stddef.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <wchar.h> - -// _FX_OS_ values: -#define _FX_WIN32_DESKTOP_ 1 -#define _FX_WIN64_DESKTOP_ 2 -#define _FX_LINUX_DESKTOP_ 4 -#define _FX_MACOSX_ 7 -#define _FX_ANDROID_ 12 - -// _FXM_PLATFORM_ values; -#define _FXM_PLATFORM_WINDOWS_ 1 // _FX_WIN32_DESKTOP_ or _FX_WIN64_DESKTOP_. -#define _FXM_PLATFORM_LINUX_ 2 // _FX_LINUX_DESKTOP_ always. -#define _FXM_PLATFORM_APPLE_ 3 // _FX_MACOSX_ always. -#define _FXM_PLATFORM_ANDROID_ 4 // _FX_ANDROID_ always. - -#ifndef _FX_OS_ -#if defined(__ANDROID__) -#define _FX_OS_ _FX_ANDROID_ -#define _FXM_PLATFORM_ _FXM_PLATFORM_ANDROID_ -#elif defined(_WIN32) -#define _FX_OS_ _FX_WIN32_DESKTOP_ -#define _FXM_PLATFORM_ _FXM_PLATFORM_WINDOWS_ -#elif defined(_WIN64) -#define _FX_OS_ _FX_WIN64_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 // _FX_OS_ - -#if !defined(_FX_OS_) || _FX_OS_ == 0 -#error Sorry, can not figure out target OS. Please specify _FX_OS_ macro. -#endif - -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -#include <windows.h> -#include <sal.h> -#endif - -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ -#include <Carbon/Carbon.h> -#include <libkern/OSAtomic.h> -#endif - -#ifdef __cplusplus -extern "C" { -#endif -typedef void* FX_POSITION; // Keep until fxcrt containers gone -typedef float FX_FLOAT; // Keep, allow upgrade to doubles. -typedef double FX_DOUBLE; // Keep, allow downgrade to floats. -typedef int FX_BOOL; // Keep, sadly not always 0 or 1. -typedef char FX_CHAR; // Keep, questionable signedness. -typedef wchar_t FX_WCHAR; // Keep, maybe bad platform wchars. - -#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) -#define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) -#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) -#define IsFloatEqual(fa, fb) IsFloatZero(fa - fb) - -// PDFium string sizes are limited to 2^31-1, and the value is signed to -// allow -1 as a placeholder for "unknown". -// TODO(palmer): it should be a |size_t|, or at least unsigned. -typedef int FX_STRSIZE; - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifdef __cplusplus -static_assert(TRUE == true, "true_needs_to_be_true"); -static_assert(FALSE == false, "false_needs_to_be_false"); -#endif - -#ifndef ASSERT -#ifndef NDEBUG -#define ASSERT assert -#else -#define ASSERT(a) -#endif -#endif - -#if defined(__clang__) || defined(__GNUC__) -#define PDFIUM_IMMEDIATE_CRASH() __builtin_trap() -#else -#define PDFIUM_IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0)) -#endif - -// M_PI not universally present on all platforms. -#define FX_PI 3.1415926535897932384626433832795f -#define FX_BEZIER 0.5522847498308f - -// NOTE: prevent use of the return value from snprintf() since some platforms -// have different return values (e.g. windows _vsnprintf()), and provide -// versions that always NUL-terminate. -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 -void FXSYS_snprintf(char* str, - size_t size, - _Printf_format_string_ const char* fmt, - ...); -void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap); -#else -#define FXSYS_snprintf (void) snprintf -#define FXSYS_vsnprintf (void) vsnprintf -#endif - -#define FXSYS_sprintf DO_NOT_USE_SPRINTF_DIE_DIE_DIE -#define FXSYS_vsprintf DO_NOT_USE_VSPRINTF_DIE_DIE_DIE -#define FXSYS_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(const FX_WCHAR* filename, const FX_WCHAR* mode); -#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - -#ifdef __cplusplus -} // extern "C" - -#include "third_party/base/numerics/safe_conversions.h" - -#define FXSYS_strlen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(strlen(ptr)) -#define FXSYS_wcslen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(wcslen(ptr)) - -// Overloaded functions for C++ templates -inline FX_STRSIZE FXSYS_len(const FX_CHAR* ptr) { - return FXSYS_strlen(ptr); -} - -inline FX_STRSIZE FXSYS_len(const FX_WCHAR* ptr) { - return FXSYS_wcslen(ptr); -} - -inline int FXSYS_cmp(const FX_CHAR* ptr1, const FX_CHAR* ptr2, size_t len) { - return memcmp(ptr1, ptr2, len); -} - -inline int FXSYS_cmp(const FX_WCHAR* ptr1, const FX_WCHAR* ptr2, size_t len) { - return wmemcmp(ptr1, ptr2, len); -} - -inline const FX_CHAR* FXSYS_chr(const FX_CHAR* ptr, FX_CHAR ch, size_t len) { - return reinterpret_cast<const FX_CHAR*>(memchr(ptr, ch, len)); -} - -inline const FX_WCHAR* FXSYS_chr(const FX_WCHAR* ptr, FX_WCHAR ch, size_t len) { - return wmemchr(ptr, ch, len); -} - -extern "C" { -#else -#define FXSYS_strlen(ptr) ((FX_STRSIZE)strlen(ptr)) -#define FXSYS_wcslen(ptr) ((FX_STRSIZE)wcslen(ptr)) -#endif - -#define FXSYS_wcscmp wcscmp -#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_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(); -char* FXSYS_itoa(int value, char* str, int radix); -int FXSYS_WideCharToMultiByte(uint32_t codepage, - uint32_t dwFlags, - const wchar_t* wstr, - int wlen, - char* buf, - int buflen, - const char* default_str, - int* pUseDefault); -int FXSYS_MultiByteToWideChar(uint32_t codepage, - uint32_t dwFlags, - const char* bstr, - int blen, - wchar_t* buf, - int buflen); -uint32_t FXSYS_GetFullPathName(const char* filename, - uint32_t buflen, - char* buf, - char** filepart); -uint32_t FXSYS_GetModuleFileName(void* hModule, char* buf, uint32_t bufsize); -char* FXSYS_strlwr(char* str); -char* FXSYS_strupr(char* str); -int FXSYS_stricmp(const char*, const char*); -int FXSYS_wcsicmp(const wchar_t* str1, const wchar_t* str2); -wchar_t* FXSYS_wcslwr(wchar_t* str); -wchar_t* FXSYS_wcsupr(wchar_t* str); -#endif // _FXM_PLATFORM == _FXM_PLATFORM_WINDOWS_ - -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -#define FXSYS_pow(a, b) (FX_FLOAT) powf(a, b) -#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 -#define FXDWORD_GET_LSBFIRST(p) \ - ((static_cast<uint32_t>(p[3]) << 24) | (static_cast<uint32_t>(p[2]) << 16) | \ - (static_cast<uint32_t>(p[1]) << 8) | (static_cast<uint32_t>(p[0]))) -#define FXDWORD_GET_MSBFIRST(p) \ - ((static_cast<uint32_t>(p[0]) << 24) | (static_cast<uint32_t>(p[1]) << 16) | \ - (static_cast<uint32_t>(p[2]) << 8) | (static_cast<uint32_t>(p[3]))) -#define FXSYS_HIBYTE(word) ((uint8_t)((word) >> 8)) -#define FXSYS_LOBYTE(word) ((uint8_t)(word)) -#define FXSYS_HIWORD(dword) ((uint16_t)((dword) >> 16)) -#define FXSYS_LOWORD(dword) ((uint16_t)(dword)) -int32_t FXSYS_atoi(const FX_CHAR* str); -uint32_t FXSYS_atoui(const FX_CHAR* str); -int32_t FXSYS_wtoi(const FX_WCHAR* str); -int64_t FXSYS_atoi64(const FX_CHAR* str); -int64_t FXSYS_wtoi64(const FX_WCHAR* str); -const FX_CHAR* FXSYS_i64toa(int64_t value, FX_CHAR* str, int radix); -int FXSYS_round(FX_FLOAT f); -#define FXSYS_sqrt2(a, b) (FX_FLOAT) FXSYS_sqrt((a) * (a) + (b) * (b)) -#ifdef __cplusplus -}; -#endif - -// To print a size_t value in a portable way: -// size_t size; -// printf("xyz: %" PRIuS, size); -// The "u" in the macro corresponds to %u, and S is for "size". - -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - -#if (defined(_INTTYPES_H) || defined(_INTTYPES_H_)) && !defined(PRId64) -#error "inttypes.h has already been included before this header file, but " -#error "without __STDC_FORMAT_MACROS defined." -#endif - -#if !defined(__STDC_FORMAT_MACROS) -#define __STDC_FORMAT_MACROS -#endif - -#include <inttypes.h> - -#if !defined(PRIuS) -#define PRIuS "zu" -#endif - -#else // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - -#if !defined(PRIuS) -#define PRIuS "Iu" -#endif - -#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - -// Prevent a function from ever being inlined, typically because we'd -// like it to appear in stack traces. -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -#define NEVER_INLINE __declspec(noinline) -#else // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -#define NEVER_INLINE __attribute__((__noinline__)) -#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - -#endif // CORE_FXCRT_INCLUDE_FX_SYSTEM_H_ diff --git a/core/fxcrt/include/fx_ucd.h b/core/fxcrt/include/fx_ucd.h deleted file mode 100644 index eeecd39cbf..0000000000 --- a/core/fxcrt/include/fx_ucd.h +++ /dev/null @@ -1,202 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_UCD_H_ -#define CORE_FXCRT_INCLUDE_FX_UCD_H_ - -#include "core/fxcrt/include/fx_basic.h" - -#define FX_BIDICLASSBITS 6 -#define FX_BIDICLASSBITSMASK (31 << FX_BIDICLASSBITS) - -enum FX_BIDICLASS { - FX_BIDICLASS_ON = 0, // Other Neutral - FX_BIDICLASS_L = 1, // Left Letter - FX_BIDICLASS_R = 2, // Right Letter - FX_BIDICLASS_AN = 3, // Arabic Number - FX_BIDICLASS_EN = 4, // European Number - FX_BIDICLASS_AL = 5, // Arabic Letter - FX_BIDICLASS_NSM = 6, // Non-spacing Mark - FX_BIDICLASS_CS = 7, // Common Number Separator - FX_BIDICLASS_ES = 8, // European Separator - FX_BIDICLASS_ET = 9, // European Number Terminator - FX_BIDICLASS_BN = 10, // Boundary Neutral - FX_BIDICLASS_S = 11, // Segment Separator - FX_BIDICLASS_WS = 12, // Whitespace - FX_BIDICLASS_B = 13, // Paragraph Separator - FX_BIDICLASS_RLO = 14, // Right-to-Left Override - FX_BIDICLASS_RLE = 15, // Right-to-Left Embedding - FX_BIDICLASS_LRO = 16, // Left-to-Right Override - FX_BIDICLASS_LRE = 17, // Left-to-Right Embedding - FX_BIDICLASS_PDF = 18, // Pop Directional Format - FX_BIDICLASS_N = FX_BIDICLASS_ON, -}; - -extern const uint32_t kTextLayoutCodeProperties[]; -extern const size_t kTextLayoutCodePropertiesSize; - -extern const uint16_t kFXTextLayoutVerticalMirror[]; -extern const size_t kFXTextLayoutVerticalMirrorSize; - -extern const uint16_t kFXTextLayoutBidiMirror[]; -extern const size_t kFXTextLayoutBidiMirrorSize; - -uint32_t FX_GetUnicodeProperties(FX_WCHAR wch); -FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, FX_BOOL bRTL, FX_BOOL bVertical); - -#ifdef PDF_ENABLE_XFA -enum FX_CHARBREAKPROP { - FX_CBP_OP = 0, - FX_CBP_CL = 1, - FX_CBP_QU = 2, - FX_CBP_GL = 3, - FX_CBP_NS = 4, - FX_CBP_EX = 5, - FX_CBP_SY = 6, - FX_CBP_IS = 7, - FX_CBP_PR = 8, - FX_CBP_PO = 9, - FX_CBP_NU = 10, - FX_CBP_AL = 11, - FX_CBP_ID = 12, - FX_CBP_IN = 13, - FX_CBP_HY = 14, - FX_CBP_BA = 15, - FX_CBP_BB = 16, - FX_CBP_B2 = 17, - FX_CBP_ZW = 18, - FX_CBP_CM = 19, - FX_CBP_WJ = 20, - FX_CBP_H2 = 21, - FX_CBP_H3 = 22, - FX_CBP_JL = 23, - FX_CBP_JV = 24, - FX_CBP_JT = 25, - - FX_CBP_BK = 26, - FX_CBP_CR = 27, - FX_CBP_LF = 28, - FX_CBP_NL = 29, - FX_CBP_SA = 30, - FX_CBP_SG = 31, - FX_CBP_CB = 32, - FX_CBP_XX = 33, - FX_CBP_AI = 34, - FX_CBP_SP = 35, - FX_CBP_TB = 37, - FX_CBP_NONE = 36, -}; - -#define FX_CHARTYPEBITS 11 -#define FX_CHARTYPEBITSMASK (15 << FX_CHARTYPEBITS) -enum FX_CHARTYPE { - FX_CHARTYPE_Unknown = 0, - FX_CHARTYPE_Tab = (1 << FX_CHARTYPEBITS), - FX_CHARTYPE_Space = (2 << FX_CHARTYPEBITS), - FX_CHARTYPE_Control = (3 << FX_CHARTYPEBITS), - FX_CHARTYPE_Combination = (4 << FX_CHARTYPEBITS), - FX_CHARTYPE_Numeric = (5 << FX_CHARTYPEBITS), - FX_CHARTYPE_Normal = (6 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicAlef = (7 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicSpecial = (8 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicDistortion = (9 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicNormal = (10 << FX_CHARTYPEBITS), - FX_CHARTYPE_ArabicForm = (11 << FX_CHARTYPEBITS), - FX_CHARTYPE_Arabic = (12 << FX_CHARTYPEBITS), -}; -inline FX_CHARTYPE GetCharTypeFromProp(uint32_t prop) { - return static_cast<FX_CHARTYPE>(prop & FX_CHARTYPEBITSMASK); -} - -FX_BOOL FX_IsCtrlCode(FX_WCHAR ch); -FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, - uint32_t dwProps, - FX_BOOL bRTL, - FX_BOOL bVertical); -class CFX_Char { - public: - CFX_Char() - : m_wCharCode(0), - m_nBreakType(0), - m_nRotation(0), - m_dwCharProps(0), - m_dwCharStyles(0), - m_iCharWidth(0), - m_iHorizontalScale(100), - m_iVertialScale(100) {} - CFX_Char(uint16_t wCharCode, uint32_t dwCharProps) - : m_wCharCode(wCharCode), - m_nBreakType(0), - m_nRotation(0), - m_dwCharProps(dwCharProps), - m_dwCharStyles(0), - m_iCharWidth(0), - m_iHorizontalScale(100), - m_iVertialScale(100) {} - - FX_CHARTYPE GetCharType() const { return GetCharTypeFromProp(m_dwCharProps); } - - uint16_t m_wCharCode; - uint8_t m_nBreakType; - int8_t m_nRotation; - uint32_t m_dwCharProps; - uint32_t m_dwCharStyles; - int32_t m_iCharWidth; - int32_t m_iHorizontalScale; - int32_t m_iVertialScale; -}; -typedef CFX_ArrayTemplate<CFX_Char> CFX_CharArray; -class CFX_TxtChar : public CFX_Char { - public: - CFX_TxtChar() - : m_dwStatus(0), - m_iBidiClass(0), - m_iBidiLevel(0), - m_iBidiPos(0), - m_iBidiOrder(0), - m_pUserData(nullptr) {} - uint32_t m_dwStatus; - int16_t m_iBidiClass; - int16_t m_iBidiLevel; - int16_t m_iBidiPos; - int16_t m_iBidiOrder; - void* m_pUserData; -}; -typedef CFX_ArrayTemplate<CFX_TxtChar> CFX_TxtCharArray; -class CFX_RTFChar : public CFX_Char { - public: - CFX_RTFChar(); - CFX_RTFChar(const CFX_RTFChar& other); - - uint32_t m_dwStatus; - int32_t m_iFontSize; - int32_t m_iFontHeight; - int16_t m_iBidiClass; - int16_t m_iBidiLevel; - int16_t m_iBidiPos; - int16_t m_iBidiOrder; - uint32_t m_dwLayoutStyles; - uint32_t m_dwIdentity; - IFX_Retainable* m_pUserData; -}; - -inline CFX_RTFChar::CFX_RTFChar() - : m_dwStatus(0), - m_iFontSize(0), - m_iFontHeight(0), - m_iBidiClass(0), - m_iBidiLevel(0), - m_iBidiPos(0), - m_dwLayoutStyles(0), - m_dwIdentity(0), - m_pUserData(nullptr) {} - -inline CFX_RTFChar::CFX_RTFChar(const CFX_RTFChar& other) = default; - -typedef CFX_ArrayTemplate<CFX_RTFChar> CFX_RTFCharArray; -#endif // PDF_ENABLE_XFA - -#endif // CORE_FXCRT_INCLUDE_FX_UCD_H_ diff --git a/core/fxcrt/include/fx_xml.h b/core/fxcrt/include/fx_xml.h deleted file mode 100644 index 4db4998c32..0000000000 --- a/core/fxcrt/include/fx_xml.h +++ /dev/null @@ -1,173 +0,0 @@ -// 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 CORE_FXCRT_INCLUDE_FX_XML_H_ -#define CORE_FXCRT_INCLUDE_FX_XML_H_ - -#include <memory> -#include <vector> - -#include "core/fxcrt/include/fx_basic.h" - -class CXML_AttrItem { - public: - bool Matches(const CFX_ByteString& space, const CFX_ByteString& name) const; - - CFX_ByteString m_QSpaceName; - CFX_ByteString m_AttrName; - CFX_WideString m_Value; -}; - -class CXML_AttrMap { - public: - CXML_AttrMap(); - ~CXML_AttrMap(); - - const CFX_WideString* Lookup(const CFX_ByteString& space, - const CFX_ByteString& name) const; - int GetSize() const; - CXML_AttrItem& GetAt(int index) const; - - void SetAt(const CFX_ByteString& space, - const CFX_ByteString& name, - const CFX_WideString& value); - - std::unique_ptr<std::vector<CXML_AttrItem>> m_pMap; -}; - -class CXML_Content { - public: - CXML_Content() : m_bCDATA(FALSE), m_Content() {} - void Set(FX_BOOL bCDATA, const CFX_WideStringC& content) { - m_bCDATA = bCDATA; - m_Content = content; - } - - FX_BOOL m_bCDATA; - CFX_WideString m_Content; -}; - -class CXML_Element { - public: - enum ChildType { Invalid, Element, Content }; - - static CXML_Element* Parse(const void* pBuffer, - size_t size, - FX_BOOL bSaveSpaceChars = FALSE, - FX_FILESIZE* pParsedSize = nullptr); - static CXML_Element* Parse(IFX_FileRead* pFile, - FX_BOOL bSaveSpaceChars = FALSE, - FX_FILESIZE* pParsedSize = nullptr); - static CXML_Element* Parse(IFX_BufferRead* pBuffer, - FX_BOOL bSaveSpaceChars = FALSE, - FX_FILESIZE* pParsedSize = nullptr); - - CXML_Element(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagName); - CXML_Element(const CFX_ByteStringC& qTagName); - CXML_Element(); - ~CXML_Element(); - - void Empty(); - CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const; - CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const; - CFX_ByteString GetNamespaceURI(const CFX_ByteString& qName) const; - CXML_Element* GetParent() const { return m_pParent; } - uint32_t CountAttrs() const { return m_AttrMap.GetSize(); } - void GetAttrByIndex(int index, - CFX_ByteString& space, - CFX_ByteString& name, - CFX_WideString& value) const; - FX_BOOL HasAttr(const CFX_ByteStringC& qName) const; - FX_BOOL GetAttrValue(const CFX_ByteStringC& name, - CFX_WideString& attribute) const; - CFX_WideString GetAttrValue(const CFX_ByteStringC& name) const { - CFX_WideString attr; - GetAttrValue(name, attr); - return attr; - } - - FX_BOOL GetAttrValue(const CFX_ByteStringC& space, - const CFX_ByteStringC& name, - CFX_WideString& attribute) const; - CFX_WideString GetAttrValue(const CFX_ByteStringC& space, - const CFX_ByteStringC& name) const { - CFX_WideString attr; - GetAttrValue(space, name, attr); - return attr; - } - - FX_BOOL GetAttrInteger(const CFX_ByteStringC& name, int& attribute) const; - int GetAttrInteger(const CFX_ByteStringC& name) const { - int attr = 0; - GetAttrInteger(name, attr); - return attr; - } - - FX_BOOL GetAttrInteger(const CFX_ByteStringC& space, - const CFX_ByteStringC& name, - int& attribute) const; - int GetAttrInteger(const CFX_ByteStringC& space, - const CFX_ByteStringC& name) const { - int attr = 0; - GetAttrInteger(space, name, attr); - return attr; - } - - FX_BOOL GetAttrFloat(const CFX_ByteStringC& name, FX_FLOAT& attribute) const; - FX_FLOAT GetAttrFloat(const CFX_ByteStringC& name) const { - FX_FLOAT attr = 0; - GetAttrFloat(name, attr); - return attr; - } - - FX_BOOL GetAttrFloat(const CFX_ByteStringC& space, - const CFX_ByteStringC& name, - FX_FLOAT& attribute) const; - FX_FLOAT GetAttrFloat(const CFX_ByteStringC& space, - const CFX_ByteStringC& name) const { - FX_FLOAT attr = 0; - GetAttrFloat(space, name, attr); - return attr; - } - - uint32_t CountChildren() const { return m_Children.size(); } - ChildType GetChildType(uint32_t index) const; - CFX_WideString GetContent(uint32_t index) const; - CXML_Element* GetElement(uint32_t index) const; - CXML_Element* GetElement(const CFX_ByteStringC& space, - const CFX_ByteStringC& tag) const { - return GetElement(space, tag, 0); - } - - uint32_t CountElements(const CFX_ByteStringC& space, - const CFX_ByteStringC& tag) const; - CXML_Element* GetElement(const CFX_ByteStringC& space, - const CFX_ByteStringC& tag, - int index) const; - - uint32_t FindElement(CXML_Element* pChild) const; - void SetTag(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagname); - void SetTag(const CFX_ByteStringC& qTagName); - void RemoveChildren(); - void RemoveChild(uint32_t index); - - protected: - struct ChildRecord { - ChildType type; - void* child; // CXML_Element and CXML_Content lack a common ancestor. - }; - - CXML_Element* m_pParent; - CFX_ByteString m_QSpaceName; - CFX_ByteString m_TagName; - CXML_AttrMap m_AttrMap; - std::vector<ChildRecord> m_Children; - - friend class CXML_Parser; - friend class CXML_Composer; -}; - -#endif // CORE_FXCRT_INCLUDE_FX_XML_H_ |