From 8f03b422ed85180ac24fc76ba0fcf7de3556679f Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 13 Mar 2017 12:30:42 -0400 Subject: Simplify TxtBreak line handling. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl moves the two lines into an array and uses m_iReady to index the array. Change-Id: Ibecfb35fb72603433a6ed1efa6ec8ae609caebf7 Reviewed-on: https://pdfium-review.googlesource.com/2951 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña --- xfa/fgas/layout/fgas_textbreak.cpp | 52 +++++++++++++------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) (limited to 'xfa/fgas/layout/fgas_textbreak.cpp') diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp index a6473842f0..2d3b8b9f48 100644 --- a/xfa/fgas/layout/fgas_textbreak.cpp +++ b/xfa/fgas/layout/fgas_textbreak.cpp @@ -43,11 +43,11 @@ CFX_TxtBreak::CFX_TxtBreak() m_dwLayoutStyles(0), m_bSingleLine(false), m_bCombText(false), + m_bEquidistant(true), m_iArabicContext(1), m_iCurArabicContext(1), m_pFont(nullptr), m_iFontSize(240), - m_bEquidistant(true), m_iTabWidth(720000), m_wDefChar(0xFEFF), m_wParagBreakChar(L'\n'), @@ -57,11 +57,11 @@ CFX_TxtBreak::CFX_TxtBreak() m_iCombWidth(360000), m_eCharType(FX_CHARTYPE_Unknown), m_pCurLine(nullptr), - m_iReady(0), m_iTolerance(0), m_iHorScale(100), - m_iCharSpace(0) { - m_pCurLine = &m_TxtLine1; + m_iCharSpace(0), + m_iReadyLineIndex(-1) { + m_pCurLine = &m_TxtLine[0]; ResetArabicContext(); } @@ -194,19 +194,6 @@ CFX_TxtChar* CFX_TxtBreak::GetLastChar(int32_t index, bool bOmitChar) const { return nullptr; } -const CFX_TxtLine* CFX_TxtBreak::GetTxtLine() const { - if (m_iReady == 1) - return &m_TxtLine1; - if (m_iReady == 2) - return &m_TxtLine2; - return nullptr; -} - -const CFX_TxtPieceArray* CFX_TxtBreak::GetTxtPieces() const { - const CFX_TxtLine* pTxtLine = GetTxtLine(); - return pTxtLine ? &pTxtLine->m_LinePieces : nullptr; -} - inline FX_CHARTYPE CFX_TxtBreak::GetUnifiedCharType( FX_CHARTYPE chartype) const { return chartype >= FX_CHARTYPE_ArabicAlef ? FX_CHARTYPE_Arabic : chartype; @@ -650,9 +637,8 @@ CFX_BreakType CFX_TxtBreak::EndBreak(CFX_BreakType dwStatus) { dwStatus = pLastPiece->m_dwStatus; return dwStatus; } else { - const CFX_TxtLine* pLastLine = GetTxtLine(); - if (pLastLine) { - pCurPieces = &pLastLine->m_LinePieces; + if (HasTxtLine()) { + pCurPieces = &m_TxtLine[m_iReadyLineIndex].m_LinePieces; iCount = pCurPieces->GetSize(); if (iCount-- > 0) { CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(iCount); @@ -675,9 +661,8 @@ CFX_BreakType CFX_TxtBreak::EndBreak(CFX_BreakType dwStatus) { return dwStatus; } - m_iReady = m_pCurLine == &m_TxtLine1 ? 1 : 2; - CFX_TxtLine* pNextLine = - m_pCurLine == &m_TxtLine1 ? &m_TxtLine2 : &m_TxtLine1; + m_iReadyLineIndex = m_pCurLine == &m_TxtLine[0] ? 0 : 1; + CFX_TxtLine* pNextLine = &m_TxtLine[1 - m_iReadyLineIndex]; bool bAllChars = m_iCurAlignment > CFX_TxtLineAlignment_Right; if (!EndBreak_SplitLine(pNextLine, bAllChars)) { std::deque tpos; @@ -831,24 +816,21 @@ void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine, } int32_t CFX_TxtBreak::CountBreakPieces() const { - const CFX_TxtPieceArray* pTxtPieces = GetTxtPieces(); - return pTxtPieces ? pTxtPieces->GetSize() : 0; + return HasTxtLine() ? m_TxtLine[m_iReadyLineIndex].m_LinePieces.GetSize() : 0; } const CFX_TxtPiece* CFX_TxtBreak::GetBreakPiece(int32_t index) const { - const CFX_TxtPieceArray* pTxtPieces = GetTxtPieces(); - if (!pTxtPieces) + if (!HasTxtLine()) return nullptr; - if (index < 0 || index >= pTxtPieces->GetSize()) + if (index < 0 || index >= m_TxtLine[m_iReadyLineIndex].m_LinePieces.GetSize()) return nullptr; - return pTxtPieces->GetPtrAt(index); + return m_TxtLine[m_iReadyLineIndex].m_LinePieces.GetPtrAt(index); } void CFX_TxtBreak::ClearBreakPieces() { - const CFX_TxtLine* pTxtLine = GetTxtLine(); - if (pTxtLine) - const_cast(pTxtLine)->RemoveAll(true); - m_iReady = 0; + if (HasTxtLine()) + m_TxtLine[m_iReadyLineIndex].RemoveAll(true); + m_iReadyLineIndex = -1; } void CFX_TxtBreak::Reset() { @@ -856,8 +838,8 @@ void CFX_TxtBreak::Reset() { m_iArabicContext = 1; m_iCurArabicContext = 1; ResetArabicContext(); - m_TxtLine1.RemoveAll(true); - m_TxtLine2.RemoveAll(true); + m_TxtLine[0].RemoveAll(true); + m_TxtLine[1].RemoveAll(true); } struct FX_FORMCHAR { -- cgit v1.2.3