From 8da79203b32d1a0df05a23da83044bdaf71c320d Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 13 Mar 2017 12:08:31 -0400 Subject: Simplify the CFX_TxtPiece class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl removes unused methods and makes GetString return a CFX_WideString instead of taking an out parameter. Change-Id: I3d2fcbdf51e7619f4fa42e46a0c83fbfa1132a84 Reviewed-on: https://pdfium-review.googlesource.com/2950 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña --- xfa/fde/cfde_txtedtpage.cpp | 4 ++-- xfa/fde/tto/fde_textout.cpp | 8 +++----- xfa/fgas/layout/fgas_textbreak.cpp | 15 +++++++-------- xfa/fgas/layout/fgas_textbreak.h | 29 ++++++++++------------------- 4 files changed, 22 insertions(+), 34 deletions(-) (limited to 'xfa') diff --git a/xfa/fde/cfde_txtedtpage.cpp b/xfa/fde/cfde_txtedtpage.cpp index 7a2cb1b18d..fd44b28ef2 100644 --- a/xfa/fde/cfde_txtedtpage.cpp +++ b/xfa/fde/cfde_txtedtpage.cpp @@ -344,8 +344,8 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, nPieceStart += TxtEdtPiece.nCount; m_Pieces.push_back(TxtEdtPiece); for (int32_t k = 0; k < TxtEdtPiece.nCount; k++) { - CFX_Char* ptc = pPiece->GetCharPtr(k); - m_CharWidths[TxtEdtPiece.nStart + k] = ptc->m_iCharWidth; + m_CharWidths[TxtEdtPiece.nStart + k] = + pPiece->GetChar(k).m_iCharWidth; } } fLinePos += fLineStep; diff --git a/xfa/fde/tto/fde_textout.cpp b/xfa/fde/tto/fde_textout.cpp index 55b1272e11..5c59b2c8d6 100644 --- a/xfa/fde/tto/fde_textout.cpp +++ b/xfa/fde/tto/fde_textout.cpp @@ -391,8 +391,7 @@ void CFDE_TextOut::RetrieveEllPieces(std::vector* pCharWidths) { const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); int32_t iPieceChars = pPiece->GetLength(); for (int32_t j = 0; j < iPieceChars; j++) { - CFX_Char* pTC = pPiece->GetCharPtr(j); - (*pCharWidths)[iCharIndex] = std::max(pTC->m_iCharWidth, 0); + (*pCharWidths)[iCharIndex] = std::max(pPiece->GetChar(j).m_iCharWidth, 0); m_iEllipsisWidth += (*pCharWidths)[iCharIndex]; iCharIndex++; } @@ -465,7 +464,6 @@ bool CFDE_TextOut::RetrievePieces(CFX_BreakType dwBreakStatus, bool bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); FX_FLOAT fLineStep = (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; - CFX_Char* pTC = nullptr; bool bNeedReload = false; FX_FLOAT fLineWidth = rect.Width(); int32_t iLineWidth = FXSYS_round(fLineWidth * 20000.0f); @@ -477,8 +475,8 @@ bool CFDE_TextOut::RetrievePieces(CFX_BreakType dwBreakStatus, int32_t iWidth = 0; int32_t j = 0; for (; j < iPieceChars; j++) { - pTC = pPiece->GetCharPtr(j); - int32_t iCurCharWidth = pTC->m_iCharWidth > 0 ? pTC->m_iCharWidth : 0; + const CFX_Char& pTC = pPiece->GetChar(j); + int32_t iCurCharWidth = pTC.m_iCharWidth > 0 ? pTC.m_iCharWidth : 0; if (bSingleLine || !bLineWrap) { if (iLineWidth - iPieceWidths - iWidth < iCurCharWidth) { bNeedReload = true; diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp index 68930db919..a6473842f0 100644 --- a/xfa/fgas/layout/fgas_textbreak.cpp +++ b/xfa/fgas/layout/fgas_textbreak.cpp @@ -563,7 +563,6 @@ void CFX_TxtBreak::EndBreak_Alignment(const std::deque& tpos, int32_t iCount = pCurPieces->GetSize(); bool bFind = false; FX_TPO tpo; - CFX_TxtChar* pTC; FX_CHARTYPE chartype; for (i = iCount - 1; i > -1; i--) { tpo = tpos[i]; @@ -574,14 +573,14 @@ void CFX_TxtBreak::EndBreak_Alignment(const std::deque& tpos, bool bArabic = FX_IsOdd(ttp.m_iBidiLevel); j = bArabic ? 0 : ttp.m_iChars - 1; while (j > -1 && j < ttp.m_iChars) { - pTC = ttp.GetCharPtr(j); - if (pTC->m_nBreakType == FX_LBT_DIRECT_BRK) + const CFX_TxtChar& pTC = ttp.GetChar(j); + if (pTC.m_nBreakType == FX_LBT_DIRECT_BRK) iGapChars++; if (!bFind || !bAllChars) { - chartype = pTC->GetCharType(); + chartype = pTC.GetCharType(); if (chartype == FX_CHARTYPE_Space || chartype == FX_CHARTYPE_Control) { if (!bFind) { - iCharWidth = pTC->m_iCharWidth; + iCharWidth = pTC.m_iCharWidth; if (bAllChars && iCharWidth > 0) iNetWidth -= iCharWidth; } @@ -610,12 +609,12 @@ void CFX_TxtBreak::EndBreak_Alignment(const std::deque& tpos, ttp.m_iStartPos = iStart; for (j = 0; j < ttp.m_iChars; j++) { - pTC = ttp.GetCharPtr(j); - if (pTC->m_nBreakType != FX_LBT_DIRECT_BRK || pTC->m_iCharWidth < 0) + CFX_TxtChar& pTC = ttp.GetChar(j); + if (pTC.m_nBreakType != FX_LBT_DIRECT_BRK || pTC.m_iCharWidth < 0) continue; int32_t k = iOffset / iGapChars; - pTC->m_iCharWidth += k; + pTC.m_iCharWidth += k; ttp.m_iWidth += k; iOffset -= k; iGapChars--; diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h index 1070a7bce4..513912d409 100644 --- a/xfa/fgas/layout/fgas_textbreak.h +++ b/xfa/fgas/layout/fgas_textbreak.h @@ -76,27 +76,18 @@ class CFX_TxtPiece { return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth; } int32_t GetLength() const { return m_iChars; } - int32_t GetEndChar() const { return m_iStartChar + m_iChars; } - CFX_TxtChar* GetCharPtr(int32_t index) const { + + CFX_TxtChar& GetChar(int32_t index) const { ASSERT(index > -1 && index < m_iChars && m_pChars); - return &(*m_pChars)[m_iStartChar + index]; - } - void GetString(FX_WCHAR* pText) const { - ASSERT(pText); - int32_t iEndChar = m_iStartChar + m_iChars; - for (int32_t i = m_iStartChar; i < iEndChar; i++) - *pText++ = static_cast((*m_pChars)[i].m_wCharCode); + return (*m_pChars)[m_iStartChar + index]; } - void GetString(CFX_WideString& wsText) const { - FX_WCHAR* pText = wsText.GetBuffer(m_iChars); - GetString(pText); - wsText.ReleaseBuffer(m_iChars); - } - void GetWidths(int32_t* pWidths) const { - ASSERT(pWidths); - int32_t iEndChar = m_iStartChar + m_iChars; - for (int32_t i = m_iStartChar; i < iEndChar; i++) - *pWidths++ = (*m_pChars)[i].m_iCharWidth; + + CFX_WideString GetString() const { + CFX_WideString ret; + ret.Reserve(m_iChars); + for (int32_t i = m_iStartChar; i < m_iStartChar + m_iChars; i++) + ret += static_cast((*m_pChars)[i].m_wCharCode); + return ret; } CFX_BreakType m_dwStatus; -- cgit v1.2.3