summaryrefslogtreecommitdiff
path: root/xfa/fgas/layout
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-03-07 16:03:17 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-03-08 13:44:54 +0000
commitf7fccbd0da7ac700e1342e18b2bd1fa82438f3fc (patch)
treeddb1da15fd6935ead6a825048bacd6f647c31657 /xfa/fgas/layout
parent7b8e8c0cdd1bdc67a61e167883c72ad672529b84 (diff)
downloadpdfium-f7fccbd0da7ac700e1342e18b2bd1fa82438f3fc.tar.xz
Remove CFX_RTFPieceArray and use std::vector
This CL removes the CFX_RTFPieceArray typedef and updates the code to use a std::vector. Change-Id: I885038d432e700830958e37b8c03c5beceff012f Reviewed-on: https://pdfium-review.googlesource.com/2936 Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fgas/layout')
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.cpp85
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.h25
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak_unittest.cpp6
3 files changed, 44 insertions, 72 deletions
diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp
index 774d78f79e..50fda35bdd 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.cpp
+++ b/xfa/fgas/layout/fgas_rtfbreak.cpp
@@ -41,9 +41,7 @@ CFX_RTFBreak::CFX_RTFBreak(uint32_t dwLayoutStyles)
m_bPagination = !!(m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_Pagination);
}
-CFX_RTFBreak::~CFX_RTFBreak() {
- Reset();
-}
+CFX_RTFBreak::~CFX_RTFBreak() {}
void CFX_RTFBreak::SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) {
if (fLineStart > fLineEnd)
@@ -381,32 +379,22 @@ CFX_RTFBreakType CFX_RTFBreak::EndBreak(CFX_RTFBreakType dwStatus) {
ASSERT(dwStatus != CFX_RTFBreakType::None);
++m_dwIdentity;
- const CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
- int32_t iCount = pCurPieces->GetSize();
- if (iCount > 0) {
- CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount);
+ if (!m_pCurLine->m_LinePieces.empty()) {
if (dwStatus != CFX_RTFBreakType::Piece)
- pLastPiece->m_dwStatus = dwStatus;
- else
- dwStatus = pLastPiece->m_dwStatus;
- return dwStatus;
+ m_pCurLine->m_LinePieces.back().m_dwStatus = dwStatus;
+ return m_pCurLine->m_LinePieces.back().m_dwStatus;
}
if (HasRTFLine()) {
- pCurPieces = &m_RTFLine[m_iReady].m_LinePieces;
- iCount = pCurPieces->GetSize();
- if (iCount-- > 0) {
- CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(iCount);
+ if (!m_RTFLine[m_iReady].m_LinePieces.empty()) {
if (dwStatus != CFX_RTFBreakType::Piece)
- pLastPiece->m_dwStatus = dwStatus;
- else
- dwStatus = pLastPiece->m_dwStatus;
- return dwStatus;
+ m_RTFLine[m_iReady].m_LinePieces.back().m_dwStatus = dwStatus;
+ return m_RTFLine[m_iReady].m_LinePieces.back().m_dwStatus;
}
return CFX_RTFBreakType::None;
}
- iCount = m_pCurLine->CountChars();
+ int32_t iCount = m_pCurLine->CountChars();
if (iCount < 1)
return CFX_RTFBreakType::None;
@@ -494,7 +482,7 @@ bool CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine,
tp.m_iChars += 1;
++i;
}
- m_pCurLine->m_LinePieces.Add(tp);
+ m_pCurLine->m_LinePieces.push_back(tp);
bNew = true;
} else {
tp.m_iWidth += pTC->m_iCharWidth;
@@ -560,7 +548,8 @@ void CFX_RTFBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos,
} else if (iBidiLevel != pTC->m_iBidiLevel ||
pTC->m_dwIdentity != dwIdentity) {
tp.m_iChars = i - tp.m_iStartChar;
- m_pCurLine->m_LinePieces.Add(tp);
+ m_pCurLine->m_LinePieces.push_back(tp);
+
tp.m_iStartPos += tp.m_iWidth;
tp.m_iStartChar = i;
tpo.index = j++;
@@ -578,7 +567,8 @@ void CFX_RTFBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos,
if (i > tp.m_iStartChar) {
tp.m_dwStatus = dwStatus;
tp.m_iChars = i - tp.m_iStartChar;
- m_pCurLine->m_LinePieces.Add(tp);
+ m_pCurLine->m_LinePieces.push_back(tp);
+
tpo.index = j;
tpo.pos = tp.m_iBidiPos;
tpos->push_back(tpo);
@@ -587,7 +577,7 @@ void CFX_RTFBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos,
std::sort(tpos->begin(), tpos->end());
int32_t iStartPos = m_pCurLine->m_iStart;
for (const auto& it : *tpos) {
- CFX_RTFPiece& ttp = m_pCurLine->m_LinePieces.GetAt(it.index);
+ CFX_RTFPiece& ttp = m_pCurLine->m_LinePieces[it.index];
ttp.m_iStartPos = iStartPos;
iStartPos += ttp.m_iWidth;
}
@@ -598,10 +588,9 @@ void CFX_RTFBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
CFX_RTFBreakType dwStatus) {
int32_t iNetWidth = m_pCurLine->m_iWidth;
int32_t iGapChars = 0;
- int32_t iCount = m_pCurLine->m_LinePieces.GetSize();
bool bFind = false;
- for (int32_t i = iCount - 1; i > -1; --i) {
- CFX_RTFPiece& ttp = m_pCurLine->m_LinePieces.GetAt(tpos[i].index);
+ for (auto it = tpos.rbegin(); it != tpos.rend(); it++) {
+ CFX_RTFPiece& ttp = m_pCurLine->m_LinePieces[it->index];
if (!bFind)
iNetWidth = ttp.GetEndPos();
@@ -638,8 +627,8 @@ void CFX_RTFBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
(m_iAlignment == CFX_RTFLineAlignment::Justified &&
dwStatus != CFX_RTFBreakType::Paragraph))) {
int32_t iStart = -1;
- for (int32_t i = 0; i < iCount; ++i) {
- CFX_RTFPiece& ttp = m_pCurLine->m_LinePieces.GetAt(tpos[i].index);
+ for (const auto& tpo : tpos) {
+ CFX_RTFPiece& ttp = m_pCurLine->m_LinePieces[tpo.index];
if (iStart < 0)
iStart = ttp.m_iStartPos;
else
@@ -665,10 +654,8 @@ void CFX_RTFBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
if (m_iAlignment == CFX_RTFLineAlignment::Center)
iOffset /= 2;
if (iOffset > 0) {
- for (int32_t i = 0; i < iCount; ++i) {
- CFX_RTFPiece& ttp = m_pCurLine->m_LinePieces.GetAt(i);
+ for (auto& ttp : m_pCurLine->m_LinePieces)
ttp.m_iStartPos += iOffset;
- }
}
}
}
@@ -784,7 +771,7 @@ void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine,
++iCharPos;
if (iCharPos >= iCount) {
- pNextLine->RemoveAll(true);
+ pNextLine->Clear();
curChars[iCharPos - 1].m_nBreakType = FX_LBT_UNKNOWN;
return;
}
@@ -807,30 +794,33 @@ void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine,
}
int32_t CFX_RTFBreak::CountBreakPieces() const {
- return HasRTFLine() ? m_RTFLine[m_iReady].m_LinePieces.GetSize() : 0;
+ return HasRTFLine()
+ ? pdfium::CollectionSize<int32_t>(m_RTFLine[m_iReady].m_LinePieces)
+ : 0;
}
-const CFX_RTFPiece* CFX_RTFBreak::GetBreakPiece(int32_t index) const {
+const CFX_RTFPiece* CFX_RTFBreak::GetBreakPieceUnstable(int32_t index) const {
if (!HasRTFLine())
return nullptr;
- const CFX_RTFPieceArray* pRTFPieces = &m_RTFLine[m_iReady].m_LinePieces;
- if (index < 0 || index >= pRTFPieces->GetSize())
+ const std::vector<CFX_RTFPiece>& pRTFPieces =
+ m_RTFLine[m_iReady].m_LinePieces;
+ if (index < 0 || index >= pdfium::CollectionSize<int32_t>(pRTFPieces))
return nullptr;
- return pRTFPieces->GetPtrAt(index);
+ return &pRTFPieces[index];
}
void CFX_RTFBreak::ClearBreakPieces() {
if (HasRTFLine())
- m_RTFLine[m_iReady].RemoveAll(true);
+ m_RTFLine[m_iReady].Clear();
m_iReady = -1;
}
void CFX_RTFBreak::Reset() {
m_eCharType = FX_CHARTYPE_Unknown;
- m_RTFLine[0].RemoveAll(true);
- m_RTFLine[1].RemoveAll(true);
+ m_RTFLine[0].Clear();
+ m_RTFLine[1].Clear();
}
int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
@@ -963,16 +953,13 @@ CFX_RTFPiece::CFX_RTFPiece()
m_pChars(nullptr),
m_pUserData(nullptr) {}
-CFX_RTFPiece::~CFX_RTFPiece() {
- Reset();
-}
+CFX_RTFPiece::CFX_RTFPiece(const CFX_RTFPiece& other) = default;
-CFX_RTFLine::CFX_RTFLine()
- : m_LinePieces(16), m_iStart(0), m_iWidth(0), m_iArabicChars(0) {}
+CFX_RTFPiece::~CFX_RTFPiece() {}
-CFX_RTFLine::~CFX_RTFLine() {
- RemoveAll(false);
-}
+CFX_RTFLine::CFX_RTFLine() : m_iStart(0), m_iWidth(0), m_iArabicChars(0) {}
+
+CFX_RTFLine::~CFX_RTFLine() {}
FX_RTFTEXTOBJ::FX_RTFTEXTOBJ()
: pFont(nullptr),
diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h
index 835430e919..125b06fe95 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.h
+++ b/xfa/fgas/layout/fgas_rtfbreak.h
@@ -48,6 +48,7 @@ struct FX_RTFTEXTOBJ {
class CFX_RTFPiece {
public:
CFX_RTFPiece();
+ CFX_RTFPiece(const CFX_RTFPiece& other);
~CFX_RTFPiece();
int32_t GetEndPos() const {
@@ -75,20 +76,6 @@ class CFX_RTFPiece {
return ret;
}
- void Reset() {
- m_dwStatus = CFX_RTFBreakType::Piece;
- if (m_iWidth > -1)
- m_iStartPos += m_iWidth;
-
- m_iWidth = -1;
- m_iStartChar += m_iChars;
- m_iChars = 0;
- m_iBidiLevel = 0;
- m_iBidiPos = 0;
- m_iHorizontalScale = 100;
- m_iVerticalScale = 100;
- }
-
CFX_RTFBreakType m_dwStatus;
int32_t m_iStartPos;
int32_t m_iWidth;
@@ -105,8 +92,6 @@ class CFX_RTFPiece {
CFX_RetainPtr<CFX_Retainable> m_pUserData;
};
-typedef CFX_BaseArrayTemplate<CFX_RTFPiece> CFX_RTFPieceArray;
-
class CFX_RTFLine {
public:
CFX_RTFLine();
@@ -122,15 +107,15 @@ class CFX_RTFLine {
}
int32_t GetLineEnd() const { return m_iStart + m_iWidth; }
- void RemoveAll(bool bLeaveMemory) {
+ void Clear() {
m_LineChars.clear();
- m_LinePieces.RemoveAll(bLeaveMemory);
+ m_LinePieces.clear();
m_iWidth = 0;
m_iArabicChars = 0;
}
std::vector<CFX_RTFChar> m_LineChars;
- CFX_RTFPieceArray m_LinePieces;
+ std::vector<CFX_RTFPiece> m_LinePieces;
int32_t m_iStart;
int32_t m_iWidth;
int32_t m_iArabicChars;
@@ -157,7 +142,7 @@ class CFX_RTFBreak {
CFX_RTFBreakType EndBreak(CFX_RTFBreakType dwStatus);
int32_t CountBreakPieces() const;
- const CFX_RTFPiece* GetBreakPiece(int32_t index) const;
+ const CFX_RTFPiece* GetBreakPieceUnstable(int32_t index) const;
void ClearBreakPieces();
void Reset();
diff --git a/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp b/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp
index aba440aac7..bbac9d5806 100644
--- a/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp
+++ b/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp
@@ -58,7 +58,7 @@ TEST_F(RTFBreakTest, AddChars) {
EXPECT_EQ(CFX_RTFBreakType::Paragraph, b->AppendChar(L'\n'));
ASSERT_EQ(1, b->CountBreakPieces());
- EXPECT_EQ(str + L"\n", b->GetBreakPiece(0)->GetString());
+ EXPECT_EQ(str + L"\n", b->GetBreakPieceUnstable(0)->GetString());
b->ClearBreakPieces();
b->Reset();
@@ -71,7 +71,7 @@ TEST_F(RTFBreakTest, AddChars) {
// Force the end of the break at the end of the string.
b->EndBreak(CFX_RTFBreakType::Paragraph);
ASSERT_EQ(1, b->CountBreakPieces());
- EXPECT_EQ(str, b->GetBreakPiece(0)->GetString());
+ EXPECT_EQ(str, b->GetBreakPieceUnstable(0)->GetString());
}
TEST_F(RTFBreakTest, ControlCharacters) {
@@ -83,5 +83,5 @@ TEST_F(RTFBreakTest, ControlCharacters) {
EXPECT_EQ(CFX_RTFBreakType::Paragraph, b->AppendChar(L'\n'));
ASSERT_EQ(1, b->CountBreakPieces());
- EXPECT_EQ(L"\v", b->GetBreakPiece(0)->GetString());
+ EXPECT_EQ(L"\v", b->GetBreakPieceUnstable(0)->GetString());
}