diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-02 11:32:19 -0800 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-02 20:06:11 +0000 |
commit | c3f74e91b2f019c3035395f5605cb98409502385 (patch) | |
tree | 86a1a772af54c525caa9df0e76e4cedcfff17607 /xfa/fde | |
parent | cb5eb3bdb0ed36571d313b38dad59e5bde65f4a7 (diff) | |
download | pdfium-c3f74e91b2f019c3035395f5605cb98409502385.tar.xz |
Use std::deque for CFX_MassArrayTemplate<FDE_TTOPIECE>
Change-Id: Ib6ad46c0d79f51579a99869c5ff87cc9baf75c6e
Reviewed-on: https://pdfium-review.googlesource.com/2897
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde')
-rw-r--r-- | xfa/fde/tto/fde_textout.cpp | 163 | ||||
-rw-r--r-- | xfa/fde/tto/fde_textout.h | 20 |
2 files changed, 82 insertions, 101 deletions
diff --git a/xfa/fde/tto/fde_textout.cpp b/xfa/fde/tto/fde_textout.cpp index 9011b8950f..7e9ff08ffd 100644 --- a/xfa/fde/tto/fde_textout.cpp +++ b/xfa/fde/tto/fde_textout.cpp @@ -11,12 +11,17 @@ #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_system.h" #include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" #include "xfa/fde/cfde_path.h" #include "xfa/fde/fde_gedevice.h" #include "xfa/fde/fde_object.h" #include "xfa/fgas/crt/fgas_utils.h" #include "xfa/fgas/layout/fgas_textbreak.h" +FDE_TTOPIECE::FDE_TTOPIECE() = default; +FDE_TTOPIECE::FDE_TTOPIECE(const FDE_TTOPIECE& that) = default; +FDE_TTOPIECE::~FDE_TTOPIECE() = default; + CFDE_TextOut::CFDE_TextOut() : m_pTxtBreak(new CFX_TxtBreak(FX_TXTBREAKPOLICY_None)), m_pFont(nullptr), @@ -41,9 +46,7 @@ CFDE_TextOut::CFDE_TextOut() m_rtLogicClip.Reset(); } -CFDE_TextOut::~CFDE_TextOut() { - m_ttoLines.RemoveAll(false); -} +CFDE_TextOut::~CFDE_TextOut() {} void CFDE_TextOut::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont) { ASSERT(pFont); @@ -359,7 +362,7 @@ void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, fLineWidth = rect.height; } m_pTxtBreak->SetLineWidth(fLineWidth); - m_ttoLines.RemoveAll(true); + m_ttoLines.clear(); m_wsText.clear(); LoadText(pwsStr, iLength, rect); if (m_dwStyles & FDE_TTOSTYLE_Ellipsis) { @@ -475,12 +478,8 @@ void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, } if ((bVertical && m_fLinePos + fLineStep < fLineStop) || (!bVertical && m_fLinePos + fLineStep > fLineStop)) { - int32_t iCurLine = m_iCurLine; - if (bEndofLine) { - iCurLine--; - } - CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(iCurLine); - pLine->m_bNewReload = true; + int32_t iCurLine = bEndofLine ? m_iCurLine - 1 : m_iCurLine; + m_ttoLines[iCurLine].SetNewReload(true); bRet = true; break; } @@ -532,8 +531,7 @@ bool CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, m_CharWidths[iChar++] = iCurCharWidth; } if (j == 0 && !bReload) { - CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); - pLine->m_bNewReload = true; + m_ttoLines[m_iCurLine].SetNewReload(true); } else if (j > 0) { CFX_RectF rtPiece; if (bVertical) { @@ -569,14 +567,15 @@ bool CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, bool bNeedReload, bool bEnd) { - if (m_iCurLine >= m_ttoLines.GetSize()) { + if (m_iCurLine >= pdfium::CollectionSize<int32_t>(m_ttoLines)) { CFDE_TTOLine ttoLine; - ttoLine.m_bNewReload = bNeedReload; + ttoLine.SetNewReload(bNeedReload); m_iCurPiece = ttoLine.AddPiece(m_iCurPiece, ttoPiece); - m_iCurLine = m_ttoLines.Add(ttoLine); + m_ttoLines.push_back(ttoLine); + m_iCurLine = pdfium::CollectionSize<int32_t>(m_ttoLines) - 1; } else { - CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); - pLine->m_bNewReload = bNeedReload; + CFDE_TTOLine* pLine = &m_ttoLines[m_iCurLine]; + pLine->SetNewReload(bNeedReload); m_iCurPiece = pLine->AddPiece(m_iCurPiece, ttoPiece); if (bEnd) { int32_t iPieces = pLine->GetSize(); @@ -585,36 +584,33 @@ void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, } } } - if (!bEnd && bNeedReload) { + if (!bEnd && bNeedReload) m_iCurPiece = 0; - } } void CFDE_TextOut::ReplaceWidthEllipsis() { LoadEllipsis(); int32_t iLength = m_wsEllipsis.GetLength(); - if (iLength < 1) { + if (iLength < 1) return; - } - int32_t iLines = m_ttoLines.GetSize(); - for (int32_t i = 0; i < iLines; i++) { - CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); - if (!pLine->m_bNewReload) { + + for (auto& line : m_ttoLines) { + if (!line.GetNewReload()) continue; - } + int32_t iEllipsisCharIndex = iLength - 1; int32_t iCharWidth = 0; int32_t iCharCount = 0; - int32_t iPiece = pLine->GetSize(); + int32_t iPiece = line.GetSize(); while (iPiece-- > 0) { - FDE_TTOPIECE* pPiece = pLine->GetPtrAt(iPiece); + FDE_TTOPIECE* pPiece = line.GetPtrAt(iPiece); if (!pPiece) break; for (int32_t j = pPiece->iChars - 1; j >= 0; j--) { - if (iEllipsisCharIndex < 0) { + if (iEllipsisCharIndex < 0) break; - } + int32_t index = pPiece->iStartChar + j; iCharWidth += m_CharWidths[index]; iCharCount++; @@ -627,23 +623,21 @@ void CFDE_TextOut::ReplaceWidthEllipsis() { } iEllipsisCharIndex--; } - if (iEllipsisCharIndex < 0) { + if (iEllipsisCharIndex < 0) break; - } } } } void CFDE_TextOut::Reload(const CFX_RectF& rect) { - int32_t iCount = m_ttoLines.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); - if (!pLine || !pLine->m_bNewReload) - continue; - - m_iCurLine = i; - m_iCurPiece = 0; - ReloadLinePiece(pLine, rect); + int i = 0; + for (auto& line : m_ttoLines) { + if (line.GetNewReload()) { + m_iCurLine = i; + m_iCurPiece = 0; + ReloadLinePiece(&line, rect); + } + ++i; } } @@ -680,12 +674,12 @@ void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { } void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { + if (m_ttoLines.empty()) + return; + bool bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); FX_FLOAT fLineStopS = bVertical ? rect.right() : rect.bottom(); - int32_t iLines = m_ttoLines.GetSize(); - if (iLines < 1) - return; - FDE_TTOPIECE* pFirstPiece = m_ttoLines.GetPtrAt(iLines - 1)->GetPtrAt(0); + FDE_TTOPIECE* pFirstPiece = m_ttoLines.back().GetPtrAt(0); if (!pFirstPiece) return; @@ -700,11 +694,10 @@ void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { } if (fInc < 1.0f) return; - for (int32_t i = 0; i < iLines; i++) { - CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); - int32_t iPieces = pLine->GetSize(); + for (auto& line : m_ttoLines) { + int32_t iPieces = line.GetSize(); for (int32_t j = 0; j < iPieces; j++) { - FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); + FDE_TTOPIECE* pPiece = line.GetPtrAt(j); if (bVertical) pPiece->rtPiece.left += fInc; else @@ -714,39 +707,34 @@ void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { } void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { - if (!m_pRenderDevice) - return; - - int32_t iLines = m_ttoLines.GetSize(); - if (iLines < 1) + if (!m_pRenderDevice || m_ttoLines.empty()) return; - CFDE_Brush* pBrush = new CFDE_Brush; + auto pBrush = pdfium::MakeUnique<CFDE_Brush>(); pBrush->SetColor(m_TxtColor); - CFDE_Pen* pPen = nullptr; m_pRenderDevice->SaveState(); - if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) { + if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) m_pRenderDevice->SetClipRect(rtClip); - } - for (int32_t i = 0; i < iLines; i++) { - CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); - int32_t iPieces = pLine->GetSize(); + + auto pPen = pdfium::MakeUnique<CFDE_Pen>(); + pPen->SetColor(m_TxtColor); + + for (auto& line : m_ttoLines) { + int32_t iPieces = line.GetSize(); for (int32_t j = 0; j < iPieces; j++) { - FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); + FDE_TTOPIECE* pPiece = line.GetPtrAt(j); if (!pPiece) continue; int32_t iCount = GetDisplayPos(pPiece); if (iCount > 0) { - m_pRenderDevice->DrawString(pBrush, m_pFont, m_CharPos.data(), iCount, - m_fFontSize, &m_Matrix); + m_pRenderDevice->DrawString(pBrush.get(), m_pFont, m_CharPos.data(), + iCount, m_fFontSize, &m_Matrix); } - DrawLine(pPiece, pPen); + DrawLine(pPiece, pPen.get()); } } m_pRenderDevice->RestoreState(); - delete pBrush; - delete pPen; } int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { @@ -775,7 +763,7 @@ FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { return tr; } -void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) { +void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen* pPen) { bool bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline); bool bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout); bool bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); @@ -783,10 +771,6 @@ void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) { if (!bUnderLine && !bStrikeOut && !bHotKey) return; - if (!pPen) { - pPen = new CFDE_Pen; - pPen->SetColor(m_TxtColor); - } std::unique_ptr<CFDE_Path> pPath(new CFDE_Path); int32_t iLineCount = 0; CFX_RectF rtText = pPiece->rtPiece; @@ -851,43 +835,42 @@ void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) { m_pRenderDevice->DrawPath(pPen, 1, pPath.get(), &m_Matrix); } -CFDE_TTOLine::CFDE_TTOLine() - : m_bNewReload(false), m_pieces(5), m_iPieceCount(0) {} +CFDE_TTOLine::CFDE_TTOLine() : m_bNewReload(false) {} CFDE_TTOLine::CFDE_TTOLine(const CFDE_TTOLine& ttoLine) : m_pieces(5) { m_bNewReload = ttoLine.m_bNewReload; - m_iPieceCount = ttoLine.m_iPieceCount; - m_pieces.Copy(ttoLine.m_pieces, 0, -1); + m_pieces = ttoLine.m_pieces; } CFDE_TTOLine::~CFDE_TTOLine() {} int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { - if (index >= m_iPieceCount) { - index = m_pieces.Add(ttoPiece) + 1; - m_iPieceCount++; - } else { - FDE_TTOPIECE& piece = m_pieces.GetAt(index); - piece = ttoPiece; + if (index >= pdfium::CollectionSize<int32_t>(m_pieces)) { + m_pieces.push_back(ttoPiece); + return pdfium::CollectionSize<int32_t>(m_pieces); } + m_pieces[index] = ttoPiece; return index; } int32_t CFDE_TTOLine::GetSize() const { - return m_iPieceCount; + return pdfium::CollectionSize<int32_t>(m_pieces); } FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) { - if (index >= m_iPieceCount) { + if (index < 0 || index >= pdfium::CollectionSize<int32_t>(m_pieces)) return nullptr; - } - return m_pieces.GetPtrAt(index); + + return &m_pieces[index]; } -void CFDE_TTOLine::RemoveLast(int32_t iCount) { - m_pieces.RemoveLast(iCount); +void CFDE_TTOLine::RemoveLast(int32_t icount) { + if (icount < 0) + return; + icount = std::min(icount, pdfium::CollectionSize<int32_t>(m_pieces)); + m_pieces.erase(m_pieces.end() - icount, m_pieces.end()); } -void CFDE_TTOLine::RemoveAll(bool bLeaveMemory) { - m_pieces.RemoveAll(bLeaveMemory); +void CFDE_TTOLine::RemoveAll() { + m_pieces.clear(); } diff --git a/xfa/fde/tto/fde_textout.h b/xfa/fde/tto/fde_textout.h index 2cd1bcdb70..04d656776e 100644 --- a/xfa/fde/tto/fde_textout.h +++ b/xfa/fde/tto/fde_textout.h @@ -7,6 +7,7 @@ #ifndef XFA_FDE_TTO_FDE_TEXTOUT_H_ #define XFA_FDE_TTO_FDE_TEXTOUT_H_ +#include <deque> #include <memory> #include <vector> @@ -48,6 +49,7 @@ struct FX_TXTRUN; struct FDE_TTOPIECE { FDE_TTOPIECE(); + FDE_TTOPIECE(const FDE_TTOPIECE& that); ~FDE_TTOPIECE(); int32_t iStartChar; @@ -55,9 +57,6 @@ struct FDE_TTOPIECE { uint32_t dwCharStyles; CFX_RectF rtPiece; }; -inline FDE_TTOPIECE::FDE_TTOPIECE() = default; -inline FDE_TTOPIECE::~FDE_TTOPIECE() = default; -typedef CFX_MassArrayTemplate<FDE_TTOPIECE> CFDE_TTOPieceArray; class CFDE_TTOLine { public: @@ -65,19 +64,18 @@ class CFDE_TTOLine { CFDE_TTOLine(const CFDE_TTOLine& ttoLine); ~CFDE_TTOLine(); + bool GetNewReload() const { return m_bNewReload; } + void SetNewReload(bool reload) { m_bNewReload = reload; } int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece); int32_t GetSize() const; FDE_TTOPIECE* GetPtrAt(int32_t index); void RemoveLast(int32_t iCount); - void RemoveAll(bool bLeaveMemory); + void RemoveAll(); + private: bool m_bNewReload; - CFDE_TTOPieceArray m_pieces; - - protected: - int32_t m_iPieceCount; + std::deque<FDE_TTOPIECE> m_pieces; }; -typedef CFX_ObjectMassArrayTemplate<CFDE_TTOLine> CFDE_TTOLineArray; class CFDE_TextOut { public: @@ -151,7 +149,7 @@ class CFDE_TextOut { int32_t GetCharRects(const FDE_TTOPIECE* pPiece); FX_TXTRUN ToTextRun(const FDE_TTOPIECE* pPiece); - void DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen); + void DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen* pPen); std::unique_ptr<CFX_TxtBreak> m_pTxtBreak; CFX_RetainPtr<CFGAS_GEFont> m_pFont; @@ -174,7 +172,7 @@ class CFDE_TextOut { CFX_RectF m_rtClip; CFX_RectF m_rtLogicClip; CFX_Matrix m_Matrix; - CFDE_TTOLineArray m_ttoLines; + std::deque<CFDE_TTOLine> m_ttoLines; int32_t m_iCurLine; int32_t m_iCurPiece; int32_t m_iTotalLines; |