From 33316fccc6a523077d15dc7944a492099a99f6e1 Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 24 Jan 2017 12:17:40 -0800 Subject: Use std::vector for fx_ucd.h arrays. Review-Url: https://codereview.chromium.org/2650773003 --- xfa/fgas/layout/fgas_textbreak.h | 47 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'xfa/fgas/layout/fgas_textbreak.h') diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h index ea86079ac3..19f1050039 100644 --- a/xfa/fgas/layout/fgas_textbreak.h +++ b/xfa/fgas/layout/fgas_textbreak.h @@ -12,6 +12,7 @@ #include "core/fxcrt/fx_ucd.h" #include "core/fxge/cfx_renderdevice.h" +#include "third_party/base/stl_util.h" #include "xfa/fgas/crt/fgas_utils.h" #include "xfa/fgas/layout/fgas_unicode.h" @@ -117,16 +118,13 @@ class CFX_TxtPiece { int32_t GetEndChar() const { return m_iStartChar + m_iChars; } CFX_TxtChar* GetCharPtr(int32_t index) const { ASSERT(index > -1 && index < m_iChars && m_pChars); - return m_pChars->GetDataPtr(m_iStartChar + index); + return &(*m_pChars)[m_iStartChar + index]; } void GetString(FX_WCHAR* pText) const { ASSERT(pText); int32_t iEndChar = m_iStartChar + m_iChars; - CFX_Char* pChar; - for (int32_t i = m_iStartChar; i < iEndChar; i++) { - pChar = m_pChars->GetDataPtr(i); - *pText++ = (FX_WCHAR)pChar->m_wCharCode; - } + for (int32_t i = m_iStartChar; i < iEndChar; i++) + *pText++ = static_cast((*m_pChars)[i].m_wCharCode); } void GetString(CFX_WideString& wsText) const { FX_WCHAR* pText = wsText.GetBuffer(m_iChars); @@ -136,11 +134,8 @@ class CFX_TxtPiece { void GetWidths(int32_t* pWidths) const { ASSERT(pWidths); int32_t iEndChar = m_iStartChar + m_iChars; - CFX_Char* pChar; - for (int32_t i = m_iStartChar; i < iEndChar; i++) { - pChar = m_pChars->GetDataPtr(i); - *pWidths++ = pChar->m_iCharWidth; - } + for (int32_t i = m_iStartChar; i < iEndChar; i++) + *pWidths++ = (*m_pChars)[i].m_iCharWidth; } uint32_t m_dwStatus; @@ -153,7 +148,7 @@ class CFX_TxtPiece { int32_t m_iHorizontalScale; int32_t m_iVerticalScale; uint32_t m_dwCharStyles; - CFX_TxtCharArray* m_pChars; + std::vector* m_pChars; void* m_pUserData; }; @@ -164,34 +159,38 @@ class CFX_TxtLine { explicit CFX_TxtLine(int32_t iBlockSize); ~CFX_TxtLine(); - int32_t CountChars() const { return m_pLineChars->GetSize(); } + int32_t CountChars() const { + return pdfium::CollectionSize(*m_pLineChars); + } + CFX_TxtChar* GetCharPtr(int32_t index) const { - ASSERT(index > -1 && index < m_pLineChars->GetSize()); - return m_pLineChars->GetDataPtr(index); + ASSERT(index >= 0 && + index < pdfium::CollectionSize(*m_pLineChars)); + return &(*m_pLineChars)[index]; } + int32_t CountPieces() const { return m_pLinePieces->GetSize(); } CFX_TxtPiece* GetPiecePtr(int32_t index) const { ASSERT(index > -1 && index < m_pLinePieces->GetSize()); return m_pLinePieces->GetPtrAt(index); } + void GetString(CFX_WideString& wsStr) const { - int32_t iCount = m_pLineChars->GetSize(); + int32_t iCount = pdfium::CollectionSize(*m_pLineChars); FX_WCHAR* pBuf = wsStr.GetBuffer(iCount); - CFX_Char* pChar; - for (int32_t i = 0; i < iCount; i++) { - pChar = m_pLineChars->GetDataPtr(i); - *pBuf++ = (FX_WCHAR)pChar->m_wCharCode; - } + for (int32_t i = 0; i < iCount; i++) + *pBuf++ = static_cast((*m_pLineChars)[i].m_wCharCode); wsStr.ReleaseBuffer(iCount); } + void RemoveAll(bool bLeaveMemory = false) { - m_pLineChars->RemoveAll(); + m_pLineChars->clear(); m_pLinePieces->RemoveAll(bLeaveMemory); m_iWidth = 0; m_iArabicChars = 0; } - std::unique_ptr m_pLineChars; + std::unique_ptr> m_pLineChars; std::unique_ptr m_pLinePieces; int32_t m_iStart; int32_t m_iWidth; @@ -261,7 +260,7 @@ class CFX_TxtBreak { void EndBreak_Alignment(CFX_TPOArray& tpos, bool bAllChars, uint32_t dwStatus); - int32_t GetBreakPos(CFX_TxtCharArray& ca, + int32_t GetBreakPos(std::vector& ca, int32_t& iEndPos, bool bAllChars = false, bool bOnlyBrk = false); -- cgit v1.2.3