summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fxcrt/fx_arabic.cpp167
-rw-r--r--core/fxcrt/fx_arb.h6
-rw-r--r--core/fxcrt/fx_ucd.h5
3 files changed, 81 insertions, 97 deletions
diff --git a/core/fxcrt/fx_arabic.cpp b/core/fxcrt/fx_arabic.cpp
index a649e49759..108c6c19ac 100644
--- a/core/fxcrt/fx_arabic.cpp
+++ b/core/fxcrt/fx_arabic.cpp
@@ -5,7 +5,12 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "core/fxcrt/fx_arabic.h"
+
+#include <algorithm>
+#include <vector>
+
#include "core/fxcrt/fx_ucd.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -419,81 +424,62 @@ void FX_BidiReorder(int32_t iBaseLevel,
template <class baseType>
class CFX_BidiLineTemplate {
public:
- void FX_BidiReverseString(CFX_ArrayTemplate<baseType>& chars,
+ void FX_BidiReverseString(std::vector<baseType>& chars,
int32_t iStart,
int32_t iCount) {
- ASSERT(iStart > -1 && iStart < chars.GetSize());
- ASSERT(iCount >= 0 && iStart + iCount <= chars.GetSize());
- baseType *pStart, *pEnd;
- int32_t iEnd = iStart + iCount - 1, iTemp;
- while (iStart < iEnd) {
- pStart = chars.GetDataPtr(iStart++);
- pEnd = chars.GetDataPtr(iEnd--);
- iTemp = pStart->m_iBidiPos;
- pStart->m_iBidiPos = pEnd->m_iBidiPos;
- pEnd->m_iBidiPos = iTemp;
- }
+ ASSERT(iStart >= 0 && iStart < pdfium::CollectionSize<int32_t>(chars));
+ ASSERT(iCount >= 0 &&
+ iStart + iCount <= pdfium::CollectionSize<int32_t>(chars));
+ std::reverse(chars.begin() + iStart, chars.begin() + iStart + iCount);
}
- void FX_BidiSetDeferredRun(CFX_ArrayTemplate<baseType>& chars,
+
+ void FX_BidiSetDeferredRun(std::vector<baseType>& chars,
bool bClass,
int32_t iStart,
int32_t iCount,
int32_t iValue) {
- ASSERT(iStart > -1 && iStart <= chars.GetSize());
+ ASSERT(iStart >= 0 && iStart <= pdfium::CollectionSize<int32_t>(chars));
ASSERT(iStart - iCount > -1);
- baseType* pTC;
int32_t iLast = iStart - iCount;
if (bClass) {
- for (int32_t i = iStart - 1; i >= iLast; i--) {
- pTC = chars.GetDataPtr(i);
- pTC->m_iBidiClass = (int16_t)iValue;
- }
+ for (int32_t i = iStart - 1; i >= iLast; i--)
+ chars[i].m_iBidiClass = (int16_t)iValue;
} else {
- for (int32_t i = iStart - 1; i >= iLast; i--) {
- pTC = chars.GetDataPtr(i);
- pTC->m_iBidiLevel = (int16_t)iValue;
- }
+ for (int32_t i = iStart - 1; i >= iLast; i--)
+ chars[i].m_iBidiLevel = (int16_t)iValue;
}
}
- void FX_BidiClassify(CFX_ArrayTemplate<baseType>& chars,
- int32_t iCount,
- bool bWS) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
- baseType* pTC;
+
+ void FX_BidiClassify(std::vector<baseType>& chars, int32_t iCount, bool bWS) {
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
if (bWS) {
for (int32_t i = 0; i < iCount; i++) {
- pTC = chars.GetDataPtr(i);
- pTC->m_iBidiClass =
- (int16_t)(pTC->m_dwCharProps & FX_BIDICLASSBITSMASK) >>
+ chars[i].m_iBidiClass =
+ (int16_t)(chars[i].m_dwCharProps & FX_BIDICLASSBITSMASK) >>
FX_BIDICLASSBITS;
}
} else {
for (int32_t i = 0; i < iCount; i++) {
- pTC = chars.GetDataPtr(i);
- pTC->m_iBidiClass = (int16_t)
- gc_FX_BidiNTypes[(pTC->m_dwCharProps & FX_BIDICLASSBITSMASK) >>
+ chars[i].m_iBidiClass = (int16_t)
+ gc_FX_BidiNTypes[(chars[i].m_dwCharProps & FX_BIDICLASSBITSMASK) >>
FX_BIDICLASSBITS];
}
}
}
- void FX_BidiResolveExplicit(CFX_ArrayTemplate<baseType>& chars,
+
+ void FX_BidiResolveExplicit(std::vector<baseType>& chars,
int32_t iCount,
int32_t iBaseLevel) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
ASSERT(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL);
- if (iCount < 1) {
- return;
- }
- baseType* pTC;
- for (int32_t i = 0; i < iCount; i++) {
- pTC = chars.GetDataPtr(i);
- pTC->m_iBidiLevel = (int16_t)iBaseLevel;
- }
+ for (int32_t i = 0; i < iCount; i++)
+ chars[i].m_iBidiLevel = static_cast<int16_t>(iBaseLevel);
}
- void FX_BidiResolveWeak(CFX_ArrayTemplate<baseType>& chars,
+
+ void FX_BidiResolveWeak(std::vector<baseType>& chars,
int32_t iCount,
int32_t iBaseLevel) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
iCount--;
if (iCount < 1) {
return;
@@ -503,7 +489,7 @@ class CFX_BidiLineTemplate {
int32_t iState = FX_IsOdd(iBaseLevel) ? FX_BWSxr : FX_BWSxl;
int32_t i = 0, iNum = 0, iClsCur, iClsRun, iClsNew, iAction;
for (; i <= iCount; i++) {
- pTC = chars.GetDataPtr(i);
+ pTC = &chars[i];
iClsCur = pTC->m_iBidiClass;
if (iClsCur == FX_BIDICLASS_BN) {
pTC->m_iBidiLevel = (int16_t)iLevelCur;
@@ -511,7 +497,7 @@ class CFX_BidiLineTemplate {
iClsCur = FX_BidiDirection(iLevelCur);
pTC->m_iBidiClass = (int16_t)iClsCur;
} else if (i < iCount) {
- pTCNext = chars.GetDataPtr(i + 1);
+ pTCNext = &chars[i + 1];
int32_t iLevelNext, iLevelNew;
iClsNew = pTCNext->m_iBidiClass;
iLevelNext = pTCNext->m_iBidiLevel;
@@ -561,10 +547,11 @@ class CFX_BidiLineTemplate {
}
}
}
- void FX_BidiResolveNeutrals(CFX_ArrayTemplate<baseType>& chars,
+
+ void FX_BidiResolveNeutrals(std::vector<baseType>& chars,
int32_t iCount,
int32_t iBaseLevel) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
ASSERT(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL);
iCount--;
if (iCount < 1) {
@@ -575,7 +562,7 @@ class CFX_BidiLineTemplate {
int32_t iState = FX_IsOdd(iBaseLevel) ? FX_BNSr : FX_BNSl;
int32_t i = 0, iNum = 0, iClsCur, iClsRun, iClsNew, iAction;
for (; i <= iCount; i++) {
- pTC = chars.GetDataPtr(i);
+ pTC = &chars[i];
iClsCur = pTC->m_iBidiClass;
if (iClsCur == FX_BIDICLASS_BN) {
if (iNum) {
@@ -609,27 +596,25 @@ class CFX_BidiLineTemplate {
}
}
}
- void FX_BidiResolveImplicit(CFX_ArrayTemplate<baseType>& chars,
- int32_t iCount) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
- baseType* pTC;
- int32_t iCls, iLevel;
+
+ void FX_BidiResolveImplicit(std::vector<baseType>& chars, int32_t iCount) {
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
for (int32_t i = 0; i < iCount; i++) {
- pTC = chars.GetDataPtr(i);
- iCls = pTC->m_iBidiClass;
+ int32_t iCls = chars[i].m_iBidiClass;
if (iCls == FX_BIDICLASS_BN) {
continue;
}
ASSERT(iCls > FX_BIDICLASS_ON && iCls < FX_BIDICLASS_AL);
- iLevel = pTC->m_iBidiLevel;
+ int32_t iLevel = chars[i].m_iBidiLevel;
iLevel += gc_FX_BidiAddLevel[FX_IsOdd(iLevel)][iCls - 1];
- pTC->m_iBidiLevel = (int16_t)iLevel;
+ chars[i].m_iBidiLevel = (int16_t)iLevel;
}
}
- void FX_BidiResolveWhitespace(CFX_ArrayTemplate<baseType>& chars,
+
+ void FX_BidiResolveWhitespace(std::vector<baseType>& chars,
int32_t iCount,
int32_t iBaseLevel) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
ASSERT(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL);
if (iCount < 1) {
return;
@@ -637,10 +622,8 @@ class CFX_BidiLineTemplate {
iCount--;
int32_t iLevel = iBaseLevel;
int32_t i = 0, iNum = 0;
- baseType* pTC;
for (; i <= iCount; i++) {
- pTC = chars.GetDataPtr(i);
- switch (pTC->m_iBidiClass) {
+ switch (chars[i].m_iBidiClass) {
case FX_BIDICLASS_WS:
iNum++;
break;
@@ -650,7 +633,7 @@ class CFX_BidiLineTemplate {
case FX_BIDICLASS_RLO:
case FX_BIDICLASS_PDF:
case FX_BIDICLASS_BN:
- pTC->m_iBidiLevel = (int16_t)iLevel;
+ chars[i].m_iBidiLevel = (int16_t)iLevel;
iNum++;
break;
case FX_BIDICLASS_S:
@@ -658,41 +641,39 @@ class CFX_BidiLineTemplate {
if (iNum > 0) {
FX_BidiSetDeferredRun(chars, false, i, iNum, iBaseLevel);
}
- pTC->m_iBidiLevel = (int16_t)iBaseLevel;
+ chars[i].m_iBidiLevel = (int16_t)iBaseLevel;
iNum = 0;
break;
default:
iNum = 0;
break;
}
- iLevel = pTC->m_iBidiLevel;
+ iLevel = chars[i].m_iBidiLevel;
}
if (iNum > 0) {
FX_BidiSetDeferredRun(chars, false, i, iNum, iBaseLevel);
}
}
- int32_t FX_BidiReorderLevel(CFX_ArrayTemplate<baseType>& chars,
+
+ int32_t FX_BidiReorderLevel(std::vector<baseType>& chars,
int32_t iCount,
int32_t iBaseLevel,
int32_t iStart,
bool bReverse) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
ASSERT(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL);
ASSERT(iStart >= 0 && iStart < iCount);
if (iCount < 1) {
return 0;
}
- baseType* pTC;
bReverse = bReverse || FX_IsOdd(iBaseLevel);
- int32_t i = iStart, iLevel;
+ int32_t i = iStart;
for (; i < iCount; i++) {
- pTC = chars.GetDataPtr(i);
- if ((iLevel = pTC->m_iBidiLevel) == iBaseLevel) {
+ int32_t iLevel = chars[i].m_iBidiLevel;
+ if (iLevel == iBaseLevel)
continue;
- }
- if (iLevel < iBaseLevel) {
+ if (iLevel < iBaseLevel)
break;
- }
i += FX_BidiReorderLevel(chars, iCount, iBaseLevel + 1, i, bReverse) - 1;
}
int32_t iNum = i - iStart;
@@ -701,31 +682,28 @@ class CFX_BidiLineTemplate {
}
return iNum;
}
- void FX_BidiReorder(CFX_ArrayTemplate<baseType>& chars,
+
+ void FX_BidiReorder(std::vector<baseType>& chars,
int32_t iCount,
int32_t iBaseLevel) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
ASSERT(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL);
int32_t i = 0;
while (i < iCount) {
i += FX_BidiReorderLevel(chars, iCount, iBaseLevel, i, false);
}
}
- void FX_BidiPosition(CFX_ArrayTemplate<baseType>& chars, int32_t iCount) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
- baseType* pTC;
- int32_t i = 0;
- while (i < iCount) {
- pTC = chars.GetDataPtr(i);
- pTC = chars.GetDataPtr(pTC->m_iBidiPos);
- pTC->m_iBidiOrder = i++;
- }
+
+ void FX_BidiPosition(std::vector<baseType>& chars, int32_t iCount) {
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
+ for (int32_t i = 0; i < iCount; ++i)
+ chars[chars[i].m_iBidiPos].m_iBidiOrder = i;
}
- void FX_BidiLine(CFX_ArrayTemplate<baseType>& chars,
+ void FX_BidiLine(std::vector<baseType>& chars,
int32_t iCount,
int32_t iBaseLevel) {
- ASSERT(iCount > -1 && iCount <= chars.GetSize());
+ ASSERT(iCount >= 0 && iCount <= pdfium::CollectionSize<int32_t>(chars));
if (iCount < 2) {
return;
}
@@ -740,11 +718,16 @@ class CFX_BidiLineTemplate {
FX_BidiPosition(chars, iCount);
}
};
-void FX_BidiLine(CFX_TxtCharArray& chars, int32_t iCount, int32_t iBaseLevel) {
+
+void FX_BidiLine(std::vector<CFX_TxtChar>& chars,
+ int32_t iCount,
+ int32_t iBaseLevel) {
CFX_BidiLineTemplate<CFX_TxtChar> blt;
blt.FX_BidiLine(chars, iCount, iBaseLevel);
}
-void FX_BidiLine(CFX_RTFCharArray& chars, int32_t iCount, int32_t iBaseLevel) {
+void FX_BidiLine(std::vector<CFX_RTFChar>& chars,
+ int32_t iCount,
+ int32_t iBaseLevel) {
CFX_BidiLineTemplate<CFX_RTFChar> blt;
blt.FX_BidiLine(chars, iCount, iBaseLevel);
}
diff --git a/core/fxcrt/fx_arb.h b/core/fxcrt/fx_arb.h
index 6d556fe9f9..d24197c7e5 100644
--- a/core/fxcrt/fx_arb.h
+++ b/core/fxcrt/fx_arb.h
@@ -7,6 +7,8 @@
#ifndef CORE_FXCRT_FX_ARB_H_
#define CORE_FXCRT_FX_ARB_H_
+#include <vector>
+
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/fx_ucd.h"
@@ -39,10 +41,10 @@ enum FX_ARBPOSITION {
};
void FX_BidiLine(CFX_WideString& wsText, int32_t iBaseLevel = 0);
-void FX_BidiLine(CFX_TxtCharArray& chars,
+void FX_BidiLine(std::vector<CFX_TxtChar>& chars,
int32_t iCount,
int32_t iBaseLevel = 0);
-void FX_BidiLine(CFX_RTFCharArray& chars,
+void FX_BidiLine(std::vector<CFX_RTFChar>& chars,
int32_t iCount,
int32_t iBaseLevel = 0);
diff --git a/core/fxcrt/fx_ucd.h b/core/fxcrt/fx_ucd.h
index d79693b9fd..798658f59f 100644
--- a/core/fxcrt/fx_ucd.h
+++ b/core/fxcrt/fx_ucd.h
@@ -148,7 +148,7 @@ class CFX_Char {
int32_t m_iHorizontalScale;
int32_t m_iVertialScale;
};
-typedef CFX_ArrayTemplate<CFX_Char> CFX_CharArray;
+
class CFX_TxtChar : public CFX_Char {
public:
CFX_TxtChar()
@@ -165,7 +165,7 @@ class CFX_TxtChar : public CFX_Char {
int16_t m_iBidiOrder;
void* m_pUserData;
};
-typedef CFX_ArrayTemplate<CFX_TxtChar> CFX_TxtCharArray;
+
class CFX_RTFChar : public CFX_Char {
public:
CFX_RTFChar();
@@ -196,7 +196,6 @@ inline CFX_RTFChar::CFX_RTFChar()
inline CFX_RTFChar::CFX_RTFChar(const CFX_RTFChar& other) = default;
-typedef CFX_ArrayTemplate<CFX_RTFChar> CFX_RTFCharArray;
#endif // PDF_ENABLE_XFA
#endif // CORE_FXCRT_FX_UCD_H_