From 893822aa5b6254591f8e80fbffcbb4fa6ad849aa Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 13 Mar 2017 15:32:07 -0400 Subject: Merge text breaking helper classes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl merges the CFX_TxtPiece and CFX_RTFPiece classes into CFX_BreakPiece. CFX_TxtLine and CFX_RTFLine into CFX_BreakLine and CFX_TxtChar and CFX_RTFChar into CFX_Char. Change-Id: I95421bdf4cafd5e394db9238dea3603ccb8349c3 Reviewed-on: https://pdfium-review.googlesource.com/2966 Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- core/fxcrt/cfx_char.cpp | 50 +++++++++++++++++++++++++++++++ core/fxcrt/cfx_char.h | 43 +++++++++++++++++++++++++++ core/fxcrt/fx_arabic.cpp | 39 ++++++++++--------------- core/fxcrt/fx_arabic.h | 7 ++--- core/fxcrt/fx_ucd.h | 76 ------------------------------------------------ 5 files changed, 111 insertions(+), 104 deletions(-) create mode 100644 core/fxcrt/cfx_char.cpp create mode 100644 core/fxcrt/cfx_char.h (limited to 'core') diff --git a/core/fxcrt/cfx_char.cpp b/core/fxcrt/cfx_char.cpp new file mode 100644 index 0000000000..ab7abd9884 --- /dev/null +++ b/core/fxcrt/cfx_char.cpp @@ -0,0 +1,50 @@ +// Copyright 2017 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 + +#include "core/fxcrt/cfx_char.h" + +CFX_Char::CFX_Char() + : m_dwStatus(CFX_BreakType::None), + m_nBreakType(0), + m_dwCharStyles(0), + m_dwCharProps(0), + m_iCharWidth(0), + m_iHorizontalScale(100), + m_iVerticalScale(100), + m_iBidiClass(0), + m_iBidiLevel(0), + m_iBidiPos(0), + m_iBidiOrder(0), + m_wCharCode(0), + m_iFontSize(0), + m_iFontHeight(0), + m_dwIdentity(0), + m_pUserData(nullptr) {} + +CFX_Char::CFX_Char(uint16_t wCharCode, uint32_t dwCharProps) + : m_nBreakType(0), + m_dwCharStyles(0), + m_dwCharProps(dwCharProps), + m_iCharWidth(0), + m_iHorizontalScale(100), + m_iVerticalScale(100), + m_iBidiClass(0), + m_iBidiLevel(0), + m_iBidiPos(0), + m_iBidiOrder(0), + m_wCharCode(wCharCode), + m_iFontSize(0), + m_iFontHeight(0), + m_dwIdentity(0), + m_pUserData(nullptr) {} + +CFX_Char::CFX_Char(const CFX_Char& other) = default; + +CFX_Char::~CFX_Char() = default; + +FX_CHARTYPE CFX_Char::GetCharType() const { + return GetCharTypeFromProp(m_dwCharProps); +} diff --git a/core/fxcrt/cfx_char.h b/core/fxcrt/cfx_char.h new file mode 100644 index 0000000000..bc91c91386 --- /dev/null +++ b/core/fxcrt/cfx_char.h @@ -0,0 +1,43 @@ +// Copyright 2017 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_CFX_CHAR_H_ +#define CORE_FXCRT_CFX_CHAR_H_ + +#include + +#include "core/fxcrt/fx_ucd.h" + +enum class CFX_BreakType { None = 0, Piece, Line, Paragraph, Page }; + +class CFX_Char { + public: + CFX_Char(); + CFX_Char(uint16_t wCharCode, uint32_t dwCharProps); + CFX_Char(const CFX_Char& other); + ~CFX_Char(); + + FX_CHARTYPE GetCharType() const; + + CFX_BreakType m_dwStatus; + uint8_t m_nBreakType; + uint32_t m_dwCharStyles; + uint32_t m_dwCharProps; + int32_t m_iCharWidth; + int32_t m_iHorizontalScale; + int32_t m_iVerticalScale; + int16_t m_iBidiClass; + int16_t m_iBidiLevel; + int16_t m_iBidiPos; + int16_t m_iBidiOrder; + uint16_t m_wCharCode; + int32_t m_iFontSize; + int32_t m_iFontHeight; + uint32_t m_dwIdentity; + CFX_RetainPtr m_pUserData; +}; + +#endif // CORE_FXCRT_CFX_CHAR_H_ diff --git a/core/fxcrt/fx_arabic.cpp b/core/fxcrt/fx_arabic.cpp index 29e6e437e8..11743e41ad 100644 --- a/core/fxcrt/fx_arabic.cpp +++ b/core/fxcrt/fx_arabic.cpp @@ -410,10 +410,9 @@ void FX_BidiReorder(int32_t iBaseLevel, } } -template class CFX_BidiLineTemplate { public: - void FX_BidiReverseString(std::vector& chars, + void FX_BidiReverseString(std::vector& chars, int32_t iStart, int32_t iCount) { ASSERT(iStart >= 0 && iStart < pdfium::CollectionSize(chars)); @@ -422,7 +421,7 @@ class CFX_BidiLineTemplate { std::reverse(chars.begin() + iStart, chars.begin() + iStart + iCount); } - void FX_BidiSetDeferredRun(std::vector& chars, + void FX_BidiSetDeferredRun(std::vector& chars, bool bClass, int32_t iStart, int32_t iCount, @@ -439,7 +438,7 @@ class CFX_BidiLineTemplate { } } - void FX_BidiClassify(std::vector& chars, int32_t iCount, bool bWS) { + void FX_BidiClassify(std::vector& chars, int32_t iCount, bool bWS) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); if (bWS) { for (int32_t i = 0; i < iCount; i++) { @@ -456,7 +455,7 @@ class CFX_BidiLineTemplate { } } - void FX_BidiResolveExplicit(std::vector& chars, + void FX_BidiResolveExplicit(std::vector& chars, int32_t iCount, int32_t iBaseLevel) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); @@ -465,7 +464,7 @@ class CFX_BidiLineTemplate { chars[i].m_iBidiLevel = static_cast(iBaseLevel); } - void FX_BidiResolveWeak(std::vector& chars, + void FX_BidiResolveWeak(std::vector& chars, int32_t iCount, int32_t iBaseLevel) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); @@ -473,7 +472,7 @@ class CFX_BidiLineTemplate { if (iCount < 1) { return; } - baseType *pTC, *pTCNext; + CFX_Char *pTC, *pTCNext; int32_t iLevelCur = iBaseLevel; int32_t iState = FX_IsOdd(iBaseLevel) ? FX_BWSxr : FX_BWSxl; int32_t i = 0, iNum = 0, iClsCur, iClsRun, iClsNew, iAction; @@ -537,7 +536,7 @@ class CFX_BidiLineTemplate { } } - void FX_BidiResolveNeutrals(std::vector& chars, + void FX_BidiResolveNeutrals(std::vector& chars, int32_t iCount, int32_t iBaseLevel) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); @@ -546,7 +545,7 @@ class CFX_BidiLineTemplate { if (iCount < 1) { return; } - baseType* pTC; + CFX_Char* pTC; int32_t iLevel = iBaseLevel; int32_t iState = FX_IsOdd(iBaseLevel) ? FX_BNSr : FX_BNSl; int32_t i = 0, iNum = 0, iClsCur, iClsRun, iClsNew, iAction; @@ -586,7 +585,7 @@ class CFX_BidiLineTemplate { } } - void FX_BidiResolveImplicit(std::vector& chars, int32_t iCount) { + void FX_BidiResolveImplicit(std::vector& chars, int32_t iCount) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); for (int32_t i = 0; i < iCount; i++) { int32_t iCls = chars[i].m_iBidiClass; @@ -600,7 +599,7 @@ class CFX_BidiLineTemplate { } } - void FX_BidiResolveWhitespace(std::vector& chars, + void FX_BidiResolveWhitespace(std::vector& chars, int32_t iCount, int32_t iBaseLevel) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); @@ -644,7 +643,7 @@ class CFX_BidiLineTemplate { } } - int32_t FX_BidiReorderLevel(std::vector& chars, + int32_t FX_BidiReorderLevel(std::vector& chars, int32_t iCount, int32_t iBaseLevel, int32_t iStart, @@ -672,7 +671,7 @@ class CFX_BidiLineTemplate { return iNum; } - void FX_BidiReorder(std::vector& chars, + void FX_BidiReorder(std::vector& chars, int32_t iCount, int32_t iBaseLevel) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); @@ -683,13 +682,13 @@ class CFX_BidiLineTemplate { } } - void FX_BidiPosition(std::vector& chars, int32_t iCount) { + void FX_BidiPosition(std::vector& chars, int32_t iCount) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); for (int32_t i = 0; i < iCount; ++i) chars[chars[i].m_iBidiPos].m_iBidiOrder = i; } - void FX_BidiLine(std::vector& chars, + void FX_BidiLine(std::vector& chars, int32_t iCount, int32_t iBaseLevel) { ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize(chars)); @@ -708,15 +707,9 @@ class CFX_BidiLineTemplate { } }; -void FX_BidiLine(std::vector& chars, +void FX_BidiLine(std::vector& chars, int32_t iCount, int32_t iBaseLevel) { - CFX_BidiLineTemplate blt; - blt.FX_BidiLine(chars, iCount, iBaseLevel); -} -void FX_BidiLine(std::vector& chars, - int32_t iCount, - int32_t iBaseLevel) { - CFX_BidiLineTemplate blt; + CFX_BidiLineTemplate blt; blt.FX_BidiLine(chars, iCount, iBaseLevel); } diff --git a/core/fxcrt/fx_arabic.h b/core/fxcrt/fx_arabic.h index 9f6ec50ef6..1856f106c2 100644 --- a/core/fxcrt/fx_arabic.h +++ b/core/fxcrt/fx_arabic.h @@ -9,8 +9,8 @@ #include +#include "core/fxcrt/cfx_char.h" #include "core/fxcrt/fx_system.h" -#include "core/fxcrt/fx_ucd.h" #define FX_BIDIMAXLEVEL 61 #define FX_BidiDirection(a) (FX_IsOdd(a) ? FX_BIDICLASS_R : FX_BIDICLASS_L) @@ -164,10 +164,7 @@ const FX_ARBFORMTABLE* FX_GetArabicFormTable(FX_WCHAR unicode); FX_WCHAR FX_GetArabicFromAlefTable(FX_WCHAR alef); FX_WCHAR FX_GetArabicFromShaddaTable(FX_WCHAR shadda); -void FX_BidiLine(std::vector& chars, - int32_t iCount, - int32_t iBaseLevel = 0); -void FX_BidiLine(std::vector& chars, +void FX_BidiLine(std::vector& chars, int32_t iCount, int32_t iBaseLevel = 0); diff --git a/core/fxcrt/fx_ucd.h b/core/fxcrt/fx_ucd.h index f8a92a18f2..488c275808 100644 --- a/core/fxcrt/fx_ucd.h +++ b/core/fxcrt/fx_ucd.h @@ -119,82 +119,6 @@ FX_WCHAR FX_GetMirrorChar(FX_WCHAR wch, bool bRTL, bool bVertical); -enum class CFX_BreakType { None = 0, Piece, Line, Paragraph, Page }; - -class CFX_Char { - public: - CFX_Char() - : m_dwStatus(CFX_BreakType::None), - m_wCharCode(0), - m_nBreakType(0), - m_dwCharProps(0), - m_iCharWidth(0), - m_iHorizontalScale(100), - m_iVerticalScale(100) {} - - CFX_Char(uint16_t wCharCode, uint32_t dwCharProps) - : m_wCharCode(wCharCode), - m_nBreakType(0), - m_dwCharProps(dwCharProps), - m_iCharWidth(0), - m_iHorizontalScale(100), - m_iVerticalScale(100) {} - - FX_CHARTYPE GetCharType() const { return GetCharTypeFromProp(m_dwCharProps); } - - CFX_BreakType m_dwStatus; - uint16_t m_wCharCode; - uint8_t m_nBreakType; - uint32_t m_dwCharProps; - int32_t m_iCharWidth; - int32_t m_iHorizontalScale; - int32_t m_iVerticalScale; -}; - -class CFX_TxtChar : public CFX_Char { - public: - CFX_TxtChar() - : m_dwCharStyles(0), - m_iBidiClass(0), - m_iBidiLevel(0), - m_iBidiPos(0), - m_iBidiOrder(0) {} - - uint32_t m_dwCharStyles; - int16_t m_iBidiClass; - int16_t m_iBidiLevel; - int16_t m_iBidiPos; - int16_t m_iBidiOrder; -}; - -class CFX_RTFChar : public CFX_Char { - public: - CFX_RTFChar(); - CFX_RTFChar(const CFX_RTFChar& other); - ~CFX_RTFChar(); - - 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_dwIdentity; - CFX_RetainPtr m_pUserData; -}; - -inline CFX_RTFChar::CFX_RTFChar() - : m_iFontSize(0), - m_iFontHeight(0), - m_iBidiClass(0), - m_iBidiLevel(0), - m_iBidiPos(0), - m_dwIdentity(0), - m_pUserData(nullptr) {} - -inline CFX_RTFChar::CFX_RTFChar(const CFX_RTFChar& other) = default; -inline CFX_RTFChar::~CFX_RTFChar() = default; - #endif // PDF_ENABLE_XFA #endif // CORE_FXCRT_FX_UCD_H_ -- cgit v1.2.3