summaryrefslogtreecommitdiff
path: root/xfa/fgas
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2017-03-13 13:06:05 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-03-13 17:26:01 +0000
commit6fcea1f851880b452bbaaeeeefefa48b49cab331 (patch)
tree88d4ad675466c98b5086efc8be69d981a02c5136 /xfa/fgas
parent8f03b422ed85180ac24fc76ba0fcf7de3556679f (diff)
downloadpdfium-6fcea1f851880b452bbaaeeeefefa48b49cab331.tar.xz
Convert TxtBreak line pieces to a vector.
This Cl converts the m_LinePieces array to a vector. This is the last usage of the CFX_BaseArrayTemplate so remove it and supporting code. Change-Id: I3f81e4fd1210f8d0347364a2e4e5bb42cd83cb30 Reviewed-on: https://pdfium-review.googlesource.com/2952 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fgas')
-rw-r--r--xfa/fgas/crt/fgas_utils.cpp292
-rw-r--r--xfa/fgas/crt/fgas_utils.h95
-rw-r--r--xfa/fgas/layout/fgas_textbreak.cpp128
-rw-r--r--xfa/fgas/layout/fgas_textbreak.h21
4 files changed, 65 insertions, 471 deletions
diff --git a/xfa/fgas/crt/fgas_utils.cpp b/xfa/fgas/crt/fgas_utils.cpp
index 4f13d4872c..5b7c72f6a4 100644
--- a/xfa/fgas/crt/fgas_utils.cpp
+++ b/xfa/fgas/crt/fgas_utils.cpp
@@ -10,298 +10,6 @@
#include "core/fxcrt/fx_basic.h"
-class FX_BASEARRAYDATA {
- public:
- FX_BASEARRAYDATA(int32_t growsize, int32_t blocksize);
- ~FX_BASEARRAYDATA();
-
- int32_t iGrowSize;
- int32_t iBlockSize;
- int32_t iTotalCount;
- int32_t iBlockCount;
- uint8_t* pBuffer;
-};
-
-FX_BASEARRAYDATA::FX_BASEARRAYDATA(int32_t growsize, int32_t blocksize)
- : iGrowSize(growsize),
- iBlockSize(blocksize),
- iTotalCount(0),
- iBlockCount(0),
- pBuffer(nullptr) {}
-
-FX_BASEARRAYDATA::~FX_BASEARRAYDATA() {
- FX_Free(pBuffer);
-}
-
-CFX_BaseArray::CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize) {
- ASSERT(iGrowSize > 0 && iBlockSize > 0);
- m_pData = new FX_BASEARRAYDATA(iGrowSize, iBlockSize);
-}
-CFX_BaseArray::~CFX_BaseArray() {
- RemoveAll(false);
- delete m_pData;
-}
-int32_t CFX_BaseArray::GetSize() const {
- return m_pData->iBlockCount;
-}
-int32_t CFX_BaseArray::GetBlockSize() const {
- return m_pData->iBlockSize;
-}
-uint8_t* CFX_BaseArray::AddSpaceTo(int32_t index) {
- ASSERT(index > -1);
- uint8_t*& pBuffer = m_pData->pBuffer;
- int32_t& iTotalCount = m_pData->iTotalCount;
- int32_t iBlockSize = m_pData->iBlockSize;
- if (index >= iTotalCount) {
- int32_t iGrowSize = m_pData->iGrowSize;
- iTotalCount = (index / iGrowSize + 1) * iGrowSize;
- int32_t iNewSize = iTotalCount * iBlockSize;
- if (!pBuffer) {
- pBuffer = FX_Alloc(uint8_t, iNewSize);
- } else {
- pBuffer = FX_Realloc(uint8_t, pBuffer, iNewSize);
- }
- }
- int32_t& iBlockCount = m_pData->iBlockCount;
- if (index >= iBlockCount) {
- iBlockCount = index + 1;
- }
- return pBuffer + index * iBlockSize;
-}
-uint8_t* CFX_BaseArray::GetAt(int32_t index) const {
- ASSERT(index > -1 && index < m_pData->iBlockCount);
- return m_pData->pBuffer + index * m_pData->iBlockSize;
-}
-uint8_t* CFX_BaseArray::GetBuffer() const {
- return m_pData->pBuffer;
-}
-int32_t CFX_BaseArray::Append(const CFX_BaseArray& src,
- int32_t iStart,
- int32_t iCount) {
- int32_t iBlockSize = m_pData->iBlockSize;
- ASSERT(iBlockSize == src.m_pData->iBlockSize);
- int32_t& iBlockCount = m_pData->iBlockCount;
- int32_t iAdded = src.GetSize();
- ASSERT(iStart > -1 && iStart < iAdded);
- if (iCount < 0) {
- iCount = iAdded;
- }
- if (iStart + iCount > iAdded) {
- iCount = iAdded - iStart;
- }
- if (iCount < 1) {
- return 0;
- }
- uint8_t* pDst = m_pData->pBuffer + iBlockCount * iBlockSize;
- AddSpaceTo(iBlockCount + iCount - 1);
- FXSYS_memcpy(pDst, src.m_pData->pBuffer + iStart * iBlockSize,
- iCount * iBlockSize);
- return iCount;
-}
-int32_t CFX_BaseArray::Copy(const CFX_BaseArray& src,
- int32_t iStart,
- int32_t iCount) {
- int32_t iBlockSize = m_pData->iBlockSize;
- ASSERT(iBlockSize == src.m_pData->iBlockSize);
- int32_t iCopied = src.GetSize();
- ASSERT(iStart > -1 && iStart < iCopied);
- if (iCount < 0) {
- iCount = iCopied;
- }
- if (iStart + iCount > iCopied) {
- iCount = iCopied - iStart;
- }
- if (iCount < 1) {
- return 0;
- }
- RemoveAll(true);
- AddSpaceTo(iCount - 1);
- FXSYS_memcpy(m_pData->pBuffer, src.m_pData->pBuffer + iStart * iBlockSize,
- iCount * iBlockSize);
- return iCount;
-}
-int32_t CFX_BaseArray::RemoveLast(int32_t iCount) {
- int32_t& iBlockCount = m_pData->iBlockCount;
- if (iCount < 0 || iCount > iBlockCount) {
- iCount = iBlockCount;
- iBlockCount = 0;
- } else {
- iBlockCount -= iCount;
- }
- return iCount;
-}
-void CFX_BaseArray::RemoveAll(bool bLeaveMemory) {
- if (!bLeaveMemory) {
- uint8_t*& pBuffer = m_pData->pBuffer;
- if (pBuffer) {
- FX_Free(pBuffer);
- pBuffer = nullptr;
- }
- m_pData->iTotalCount = 0;
- }
- m_pData->iBlockCount = 0;
-}
-
-CFX_BaseMassArrayImp::CFX_BaseMassArrayImp(int32_t iChunkSize,
- int32_t iBlockSize)
- : m_iChunkSize(iChunkSize),
- m_iBlockSize(iBlockSize),
- m_iChunkCount(0),
- m_iBlockCount(0),
- m_pData(new CFX_ArrayTemplate<void*>()) {
- ASSERT(m_iChunkSize > 0 && m_iBlockSize > 0);
- m_pData->SetSize(16);
-}
-CFX_BaseMassArrayImp::~CFX_BaseMassArrayImp() {
- RemoveAll(false);
- delete m_pData;
-}
-uint8_t* CFX_BaseMassArrayImp::AddSpaceTo(int32_t index) {
- ASSERT(index > -1);
- uint8_t* pChunk;
- if (index < m_iBlockCount) {
- pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize);
- } else {
- int32_t iMemSize = m_iChunkSize * m_iBlockSize;
- while (true) {
- if (index < m_iChunkCount * m_iChunkSize) {
- pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize);
- break;
- } else {
- pChunk = FX_Alloc(uint8_t, iMemSize);
- if (m_iChunkCount < m_pData->GetSize()) {
- m_pData->SetAt(m_iChunkCount, pChunk);
- } else {
- m_pData->Add(pChunk);
- }
- m_iChunkCount++;
- }
- }
- }
- ASSERT(pChunk);
- m_iBlockCount = index + 1;
- return pChunk + (index % m_iChunkSize) * m_iBlockSize;
-}
-uint8_t* CFX_BaseMassArrayImp::GetAt(int32_t index) const {
- ASSERT(index > -1 && index < m_iBlockCount);
- uint8_t* pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize);
- ASSERT(pChunk);
- return pChunk + (index % m_iChunkSize) * m_iBlockSize;
-}
-int32_t CFX_BaseMassArrayImp::Append(const CFX_BaseMassArrayImp& src,
- int32_t iStart,
- int32_t iCount) {
- ASSERT(m_iBlockSize == src.m_iBlockSize);
- int32_t iAdded = src.m_iBlockCount;
- ASSERT(iStart > -1 && iStart < iAdded);
- if (iCount < 0) {
- iCount = iAdded;
- }
- if (iStart + iCount > iAdded) {
- iCount = iAdded - iStart;
- }
- if (iCount < 1) {
- return m_iBlockCount;
- }
- int32_t iBlockCount = m_iBlockCount;
- int32_t iTotal = m_iBlockCount + iCount;
- AddSpaceTo(iTotal - 1);
- Append(iBlockCount, src, iStart, iCount);
- return m_iBlockCount;
-}
-int32_t CFX_BaseMassArrayImp::Copy(const CFX_BaseMassArrayImp& src,
- int32_t iStart,
- int32_t iCount) {
- ASSERT(m_iBlockSize == src.m_iBlockSize);
- int32_t iCopied = src.m_iBlockCount;
- ASSERT(iStart > -1);
- if (iStart >= iCopied) {
- return 0;
- }
- RemoveAll(true);
- if (iCount < 0) {
- iCount = iCopied;
- }
- if (iStart + iCount > iCopied) {
- iCount = iCopied - iStart;
- }
- if (iCount < 1) {
- return 0;
- }
- if (m_iBlockCount < iCount) {
- AddSpaceTo(iCount - 1);
- }
- Append(0, src, iStart, iCount);
- return m_iBlockCount;
-}
-
-void CFX_BaseMassArrayImp::Append(int32_t iDstStart,
- const CFX_BaseMassArrayImp& src,
- int32_t iSrcStart,
- int32_t iSrcCount) {
- ASSERT(iDstStart > -1);
- ASSERT(m_iBlockSize == src.m_iBlockSize);
- ASSERT(src.m_iBlockCount > 0);
- ASSERT(m_iBlockCount >= iDstStart + iSrcCount);
- ASSERT(iSrcStart > -1);
- ASSERT(iSrcStart < src.m_iBlockCount);
- ASSERT(iSrcCount > 0);
- ASSERT(iSrcStart + iSrcCount <= src.m_iBlockCount);
-
- int32_t iDstChunkIndex = iDstStart / m_iChunkSize;
- int32_t iSrcChunkIndex = iSrcStart / src.m_iChunkSize;
- uint8_t* pDstChunk = (uint8_t*)GetAt(iDstStart);
- uint8_t* pSrcChunk = (uint8_t*)src.GetAt(iSrcStart);
- int32_t iDstChunkSize = m_iChunkSize - (iDstStart % m_iChunkSize);
- int32_t iSrcChunkSize = src.m_iChunkSize - (iSrcStart % src.m_iChunkSize);
- int32_t iCopySize =
- std::min(iSrcCount, std::min(iSrcChunkSize, iDstChunkSize));
- int32_t iCopyBytes = iCopySize * m_iBlockSize;
- while (iSrcCount > 0) {
- ASSERT(pDstChunk && pSrcChunk);
- FXSYS_memcpy(pDstChunk, pSrcChunk, iCopyBytes);
- iSrcCount -= iCopySize;
- iSrcChunkSize -= iCopySize;
- if (iSrcChunkSize < 1) {
- iSrcChunkSize = src.m_iChunkSize;
- iSrcChunkIndex++;
- pSrcChunk = (uint8_t*)src.m_pData->GetAt(iSrcChunkIndex);
- } else {
- pSrcChunk += iCopyBytes;
- }
- iDstChunkSize -= iCopySize;
- if (iDstChunkSize < 1) {
- iDstChunkSize = m_iChunkSize;
- iDstChunkIndex++;
- pDstChunk = (uint8_t*)m_pData->GetAt(iDstChunkIndex);
- } else {
- pDstChunk += iCopyBytes;
- }
- iCopySize = std::min(iSrcCount, std::min(iSrcChunkSize, iDstChunkSize));
- iCopyBytes = iCopySize * m_iBlockSize;
- }
-}
-int32_t CFX_BaseMassArrayImp::RemoveLast(int32_t iCount) {
- if (iCount < 0 || iCount >= m_iBlockCount) {
- m_iBlockCount = 0;
- } else {
- m_iBlockCount -= iCount;
- }
- return m_iBlockCount;
-}
-void CFX_BaseMassArrayImp::RemoveAll(bool bLeaveMemory) {
- if (bLeaveMemory) {
- m_iBlockCount = 0;
- return;
- }
- for (int32_t i = 0; i < m_iChunkCount; i++)
- FX_Free(m_pData->GetAt(i));
-
- m_pData->RemoveAll();
- m_iChunkCount = 0;
- m_iBlockCount = 0;
-}
-
struct FX_BASEDISCRETEARRAYDATA {
int32_t iBlockSize;
int32_t iChunkSize;
diff --git a/xfa/fgas/crt/fgas_utils.h b/xfa/fgas/crt/fgas_utils.h
index 037528bd07..85f5e47310 100644
--- a/xfa/fgas/crt/fgas_utils.h
+++ b/xfa/fgas/crt/fgas_utils.h
@@ -9,101 +9,6 @@
#include "core/fxcrt/fx_coordinates.h"
-class FX_BASEARRAYDATA;
-
-class CFX_BaseArray {
- protected:
- CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize);
- ~CFX_BaseArray();
-
- int32_t GetSize() const;
- int32_t GetBlockSize() const;
- uint8_t* AddSpaceTo(int32_t index);
- uint8_t* GetAt(int32_t index) const;
- uint8_t* GetBuffer() const;
- int32_t Append(const CFX_BaseArray& src, int32_t iStart, int32_t iCount);
- int32_t Copy(const CFX_BaseArray& src, int32_t iStart, int32_t iCount);
- int32_t RemoveLast(int32_t iCount);
- void RemoveAll(bool bLeaveMemory);
-
- FX_BASEARRAYDATA* m_pData;
-};
-
-template <class baseType>
-class CFX_BaseArrayTemplate : public CFX_BaseArray {
- public:
- explicit CFX_BaseArrayTemplate(int32_t iGrowSize)
- : CFX_BaseArray(iGrowSize, sizeof(baseType)) {}
- CFX_BaseArrayTemplate(int32_t iGrowSize, int32_t iBlockSize)
- : CFX_BaseArray(iGrowSize, iBlockSize) {}
-
- int32_t GetSize() const { return CFX_BaseArray::GetSize(); }
- int32_t GetBlockSize() const { return CFX_BaseArray::GetBlockSize(); }
- baseType* AddSpace() {
- return (baseType*)CFX_BaseArray::AddSpaceTo(CFX_BaseArray::GetSize());
- }
- int32_t Add(const baseType& element) {
- int32_t index = CFX_BaseArray::GetSize();
- *(baseType*)CFX_BaseArray::AddSpaceTo(index) = element;
- return index;
- }
- baseType* GetBuffer() const { return (baseType*)CFX_BaseArray::GetBuffer(); }
- baseType& GetAt(int32_t index) const {
- return *(baseType*)CFX_BaseArray::GetAt(index);
- }
- baseType* GetPtrAt(int32_t index) const {
- return (baseType*)CFX_BaseArray::GetAt(index);
- }
- void SetAt(int32_t index, const baseType& element) {
- *(baseType*)CFX_BaseArray::GetAt(index) = element;
- }
- void SetAtGrow(int32_t index, const baseType& element) {
- *(baseType*)CFX_BaseArray::AddSpaceTo(index) = element;
- }
- int32_t Append(const CFX_BaseArrayTemplate& src,
- int32_t iStart,
- int32_t iCount) {
- return CFX_BaseArray::Append(src, iStart, iCount);
- }
- int32_t Copy(const CFX_BaseArrayTemplate& src,
- int32_t iStart,
- int32_t iCount) {
- return CFX_BaseArray::Copy(src, iStart, iCount);
- }
- int32_t RemoveLast(int32_t iCount) {
- return CFX_BaseArray::RemoveLast(iCount);
- }
- void RemoveAll(bool bLeaveMemory) { CFX_BaseArray::RemoveAll(bLeaveMemory); }
-};
-
-class CFX_BaseMassArrayImp {
- public:
- CFX_BaseMassArrayImp(int32_t iChunkSize, int32_t iBlockSize);
- ~CFX_BaseMassArrayImp();
-
- uint8_t* AddSpace() { return AddSpaceTo(m_iBlockCount); }
- uint8_t* AddSpaceTo(int32_t index);
- uint8_t* GetAt(int32_t index) const;
- int32_t Append(const CFX_BaseMassArrayImp& src,
- int32_t iStart,
- int32_t iCount);
- int32_t Copy(const CFX_BaseMassArrayImp& src, int32_t iStart, int32_t iCount);
- int32_t RemoveLast(int32_t iCount);
- void RemoveAll(bool bLeaveMemory);
-
- int32_t m_iChunkSize;
- int32_t m_iBlockSize;
- int32_t m_iChunkCount;
- int32_t m_iBlockCount;
- CFX_ArrayTemplate<void*>* m_pData;
-
- protected:
- void Append(int32_t iDstStart,
- const CFX_BaseMassArrayImp& src,
- int32_t iSrcStart,
- int32_t iSrcCount);
-};
-
class CFX_BaseDiscreteArray {
protected:
CFX_BaseDiscreteArray(int32_t iChunkSize, int32_t iBlockSize);
diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp
index 2d3b8b9f48..e168613882 100644
--- a/xfa/fgas/layout/fgas_textbreak.cpp
+++ b/xfa/fgas/layout/fgas_textbreak.cpp
@@ -65,9 +65,7 @@ CFX_TxtBreak::CFX_TxtBreak()
ResetArabicContext();
}
-CFX_TxtBreak::~CFX_TxtBreak() {
- Reset();
-}
+CFX_TxtBreak::~CFX_TxtBreak() {}
void CFX_TxtBreak::SetLineWidth(FX_FLOAT fLineWidth) {
m_iLineWidth = FXSYS_round(fLineWidth * 20000.0f);
@@ -453,7 +451,6 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos,
FX_BidiLine(chars, iBidiNum + 1, 0);
}
- CFX_TxtPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
if (bDone) {
tp.m_dwStatus = CFX_BreakType::Piece;
tp.m_iStartPos = m_pCurLine->m_iStart;
@@ -485,7 +482,7 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos,
i++;
}
tp.m_iChars = i - tp.m_iStartChar;
- pCurPieces->Add(tp);
+ m_pCurLine->m_LinePieces.push_back(tp);
tp.m_iStartPos += tp.m_iWidth;
tp.m_iStartChar = i;
tpo.index = ++j;
@@ -503,7 +500,7 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos,
if (i > tp.m_iStartChar) {
tp.m_dwStatus = dwStatus;
tp.m_iChars = i - tp.m_iStartChar;
- pCurPieces->Add(tp);
+ m_pCurLine->m_LinePieces.push_back(tp);
tpo.index = ++j;
tpo.pos = tp.m_iBidiPos;
tpos->push_back(tpo);
@@ -514,13 +511,12 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos,
int32_t iStartPos = 0;
for (i = 0; i <= j; i++) {
tpo = (*tpos)[i];
- CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index);
+ CFX_TxtPiece& ttp = m_pCurLine->m_LinePieces[tpo.index];
ttp.m_iStartPos = iStartPos;
iStartPos += ttp.m_iWidth;
}
}
- CFX_TxtPiece& ttp = pCurPieces->GetAt(j);
- ttp.m_dwStatus = dwStatus;
+ m_pCurLine->m_LinePieces[j].m_dwStatus = dwStatus;
}
} else {
tp.m_dwStatus = dwStatus;
@@ -533,7 +529,7 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos,
tp.m_dwCharStyles = pTC->m_dwCharStyles;
tp.m_iHorizontalScale = pTC->m_iHorizontalScale;
tp.m_iVerticalScale = pTC->m_iVerticalScale;
- pCurPieces->Add(tp);
+ m_pCurLine->m_LinePieces.push_back(tp);
tpos->push_back({0, 0});
}
}
@@ -543,34 +539,23 @@ void CFX_TxtBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
CFX_BreakType dwStatus) {
int32_t iNetWidth = m_pCurLine->m_iWidth;
int32_t iGapChars = 0;
- int32_t iCharWidth;
- CFX_TxtPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
- int32_t i;
- int32_t j;
- int32_t iCount = pCurPieces->GetSize();
bool bFind = false;
- FX_TPO tpo;
- FX_CHARTYPE chartype;
- for (i = iCount - 1; i > -1; i--) {
- tpo = tpos[i];
- CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index);
+ for (auto it = tpos.rbegin(); it != tpos.rend(); ++it) {
+ CFX_TxtPiece& ttp = m_pCurLine->m_LinePieces[it->index];
if (!bFind)
iNetWidth = ttp.GetEndPos();
bool bArabic = FX_IsOdd(ttp.m_iBidiLevel);
- j = bArabic ? 0 : ttp.m_iChars - 1;
+ int32_t j = bArabic ? 0 : ttp.m_iChars - 1;
while (j > -1 && j < ttp.m_iChars) {
const CFX_TxtChar& pTC = ttp.GetChar(j);
if (pTC.m_nBreakType == FX_LBT_DIRECT_BRK)
iGapChars++;
if (!bFind || !bAllChars) {
- chartype = pTC.GetCharType();
+ FX_CHARTYPE chartype = pTC.GetCharType();
if (chartype == FX_CHARTYPE_Space || chartype == FX_CHARTYPE_Control) {
- if (!bFind) {
- iCharWidth = pTC.m_iCharWidth;
- if (bAllChars && iCharWidth > 0)
- iNetWidth -= iCharWidth;
- }
+ if (!bFind && bAllChars && pTC.m_iCharWidth > 0)
+ iNetWidth -= pTC.m_iCharWidth;
} else {
bFind = true;
if (!bAllChars)
@@ -587,15 +572,14 @@ void CFX_TxtBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
if (iGapChars > 0 && m_iCurAlignment & CFX_TxtLineAlignment_Justified &&
dwStatus != CFX_BreakType::Paragraph) {
int32_t iStart = -1;
- for (i = 0; i < iCount; i++) {
- tpo = tpos[i];
- CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index);
+ for (auto& tpo : tpos) {
+ CFX_TxtPiece& ttp = m_pCurLine->m_LinePieces[tpo.index];
if (iStart < -1)
iStart = ttp.m_iStartPos;
else
ttp.m_iStartPos = iStart;
- for (j = 0; j < ttp.m_iChars; j++) {
+ for (int32_t j = 0; j < ttp.m_iChars; j++) {
CFX_TxtChar& pTC = ttp.GetChar(j);
if (pTC.m_nBreakType != FX_LBT_DIRECT_BRK || pTC.m_iCharWidth < 0)
continue;
@@ -617,49 +601,37 @@ void CFX_TxtBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
iOffset /= 2;
}
if (iOffset > 0) {
- for (i = 0; i < iCount; i++) {
- CFX_TxtPiece& ttp = pCurPieces->GetAt(i);
+ for (auto& ttp : m_pCurLine->m_LinePieces)
ttp.m_iStartPos += iOffset;
- }
}
}
}
CFX_BreakType CFX_TxtBreak::EndBreak(CFX_BreakType dwStatus) {
ASSERT(dwStatus != CFX_BreakType::None);
- const CFX_TxtPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
- int32_t iCount = pCurPieces->GetSize();
- if (iCount > 0) {
- CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount);
+
+ if (!m_pCurLine->m_LinePieces.empty()) {
if (dwStatus != CFX_BreakType::Piece)
- pLastPiece->m_dwStatus = dwStatus;
- else
- dwStatus = pLastPiece->m_dwStatus;
- return dwStatus;
- } else {
- if (HasTxtLine()) {
- pCurPieces = &m_TxtLine[m_iReadyLineIndex].m_LinePieces;
- iCount = pCurPieces->GetSize();
- if (iCount-- > 0) {
- CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(iCount);
- if (dwStatus != CFX_BreakType::Piece)
- pLastPiece->m_dwStatus = dwStatus;
- else
- dwStatus = pLastPiece->m_dwStatus;
- return dwStatus;
- }
- return CFX_BreakType::None;
+ m_pCurLine->m_LinePieces.back().m_dwStatus = dwStatus;
+ return m_pCurLine->m_LinePieces.back().m_dwStatus;
+ }
+
+ if (HasTxtLine()) {
+ if (!m_TxtLine[m_iReadyLineIndex].m_LinePieces.empty()) {
+ if (dwStatus != CFX_BreakType::Piece)
+ m_TxtLine[m_iReadyLineIndex].m_LinePieces.back().m_dwStatus = dwStatus;
+ return m_TxtLine[m_iReadyLineIndex].m_LinePieces.back().m_dwStatus;
}
+ return CFX_BreakType::None;
+ }
- iCount = m_pCurLine->CountChars();
- if (iCount < 1)
- return CFX_BreakType::None;
+ int32_t iCount = m_pCurLine->CountChars();
+ if (iCount < 1)
+ return CFX_BreakType::None;
- CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1);
- pTC->m_dwStatus = dwStatus;
- if (dwStatus == CFX_BreakType::Piece)
- return dwStatus;
- }
+ m_pCurLine->GetCharPtr(iCount - 1)->m_dwStatus = dwStatus;
+ if (dwStatus == CFX_BreakType::Piece)
+ return dwStatus;
m_iReadyLineIndex = m_pCurLine == &m_TxtLine[0] ? 0 : 1;
CFX_TxtLine* pNextLine = &m_TxtLine[1 - m_iReadyLineIndex];
@@ -790,7 +762,7 @@ void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine,
iCharPos++;
if (iCharPos >= iCount) {
- pNextLine->RemoveAll(true);
+ pNextLine->Clear();
CFX_Char* pTC = &curChars[iCharPos - 1];
pTC->m_nBreakType = FX_LBT_UNKNOWN;
return;
@@ -816,20 +788,25 @@ void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine,
}
int32_t CFX_TxtBreak::CountBreakPieces() const {
- return HasTxtLine() ? m_TxtLine[m_iReadyLineIndex].m_LinePieces.GetSize() : 0;
+ return HasTxtLine() ? pdfium::CollectionSize<int32_t>(
+ m_TxtLine[m_iReadyLineIndex].m_LinePieces)
+ : 0;
}
const CFX_TxtPiece* CFX_TxtBreak::GetBreakPiece(int32_t index) const {
if (!HasTxtLine())
return nullptr;
- if (index < 0 || index >= m_TxtLine[m_iReadyLineIndex].m_LinePieces.GetSize())
+ if (index < 0 ||
+ index >= pdfium::CollectionSize<int32_t>(
+ m_TxtLine[m_iReadyLineIndex].m_LinePieces)) {
return nullptr;
- return m_TxtLine[m_iReadyLineIndex].m_LinePieces.GetPtrAt(index);
+ }
+ return &m_TxtLine[m_iReadyLineIndex].m_LinePieces[index];
}
void CFX_TxtBreak::ClearBreakPieces() {
if (HasTxtLine())
- m_TxtLine[m_iReadyLineIndex].RemoveAll(true);
+ m_TxtLine[m_iReadyLineIndex].Clear();
m_iReadyLineIndex = -1;
}
@@ -838,8 +815,8 @@ void CFX_TxtBreak::Reset() {
m_iArabicContext = 1;
m_iCurArabicContext = 1;
ResetArabicContext();
- m_TxtLine[0].RemoveAll(true);
- m_TxtLine[1].RemoveAll(true);
+ m_TxtLine[0].Clear();
+ m_TxtLine[1].Clear();
}
struct FX_FORMCHAR {
@@ -1231,9 +1208,10 @@ CFX_TxtPiece::CFX_TxtPiece()
m_dwCharStyles(0),
m_pChars(nullptr) {}
-CFX_TxtLine::CFX_TxtLine()
- : m_LinePieces(16), m_iStart(0), m_iWidth(0), m_iArabicChars(0) {}
+CFX_TxtPiece::CFX_TxtPiece(const CFX_TxtPiece& other) = default;
-CFX_TxtLine::~CFX_TxtLine() {
- RemoveAll();
-}
+CFX_TxtPiece::~CFX_TxtPiece() = default;
+
+CFX_TxtLine::CFX_TxtLine() : m_iStart(0), m_iWidth(0), m_iArabicChars(0) {}
+
+CFX_TxtLine::~CFX_TxtLine() {}
diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h
index 6d2582f4e1..aebb25ffa6 100644
--- a/xfa/fgas/layout/fgas_textbreak.h
+++ b/xfa/fgas/layout/fgas_textbreak.h
@@ -71,6 +71,8 @@ struct FX_TXTRUN {
class CFX_TxtPiece {
public:
CFX_TxtPiece();
+ CFX_TxtPiece(const CFX_TxtPiece& other);
+ ~CFX_TxtPiece();
int32_t GetEndPos() const {
return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth;
@@ -103,8 +105,6 @@ class CFX_TxtPiece {
std::vector<CFX_TxtChar>* m_pChars;
};
-typedef CFX_BaseArrayTemplate<CFX_TxtPiece> CFX_TxtPieceArray;
-
class CFX_TxtLine {
public:
CFX_TxtLine();
@@ -124,10 +124,13 @@ class CFX_TxtLine {
return &m_LineChars[index];
}
- int32_t CountPieces() const { return m_LinePieces.GetSize(); }
- CFX_TxtPiece* GetPiecePtr(int32_t index) const {
- ASSERT(index > -1 && index < m_LinePieces.GetSize());
- return m_LinePieces.GetPtrAt(index);
+ int32_t CountPieces() const {
+ return pdfium::CollectionSize<int32_t>(m_LinePieces);
+ }
+
+ const CFX_TxtPiece* GetPiecePtr(int32_t index) const {
+ ASSERT(index >= 0 && index < CountPieces());
+ return &m_LinePieces[index];
}
void GetString(CFX_WideString& wsStr) const {
@@ -138,15 +141,15 @@ class CFX_TxtLine {
wsStr.ReleaseBuffer(iCount);
}
- void RemoveAll(bool bLeaveMemory = false) {
+ void Clear() {
m_LineChars.clear();
- m_LinePieces.RemoveAll(bLeaveMemory);
+ m_LinePieces.clear();
m_iWidth = 0;
m_iArabicChars = 0;
}
std::vector<CFX_TxtChar> m_LineChars;
- CFX_TxtPieceArray m_LinePieces;
+ std::vector<CFX_TxtPiece> m_LinePieces;
int32_t m_iStart;
int32_t m_iWidth;
int32_t m_iArabicChars;