diff options
Diffstat (limited to 'xfa/fde')
-rw-r--r-- | xfa/fde/cfde_txtedtpage.cpp | 20 | ||||
-rw-r--r-- | xfa/fde/cfde_txtedtparag.cpp | 51 | ||||
-rw-r--r-- | xfa/fde/tto/fde_textout.cpp | 77 | ||||
-rw-r--r-- | xfa/fde/tto/fde_textout.h | 5 |
4 files changed, 78 insertions, 75 deletions
diff --git a/xfa/fde/cfde_txtedtpage.cpp b/xfa/fde/cfde_txtedtpage.cpp index 8b58b2b443..12333c608d 100644 --- a/xfa/fde/cfde_txtedtpage.cpp +++ b/xfa/fde/cfde_txtedtpage.cpp @@ -246,7 +246,7 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, m_pIter.reset(new CFDE_TxtEdtBuf::Iterator(static_cast<CFDE_TxtEdtBuf*>(pBuf), wcAlias)); CFX_TxtBreak* pBreak = m_pEditEngine->GetTextBreak(); - pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + pBreak->EndBreak(CFX_BreakType::Paragraph); pBreak->ClearBreakPieces(); int32_t nPageLineCount = m_pEditEngine->GetPageLineCount(); int32_t nStartLine = nPageLineCount * m_nPageIndex; @@ -274,11 +274,11 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, m_pTextSet = pdfium::MakeUnique<CFDE_TxtEdtTextSet>(this); m_Pieces.clear(); - uint32_t dwBreakStatus = FX_TXTBREAK_None; + CFX_BreakType dwBreakStatus = CFX_BreakType::None; int32_t nPieceStart = 0; m_CharWidths.resize(nPageEnd - nPageStart + 1, 0); - pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + pBreak->EndBreak(CFX_BreakType::Paragraph); pBreak->ClearBreakPieces(); m_nPageStart = nPageStart; m_nCharCount = nPageEnd - nPageStart + 1; @@ -290,15 +290,15 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, bool bFirstPiece = true; do { if (bReload) { - dwBreakStatus = pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + dwBreakStatus = pBreak->EndBreak(CFX_BreakType::Paragraph); } else { FX_WCHAR wAppend = pIter->GetChar(); dwBreakStatus = pBreak->AppendChar(wAppend); } - if (pIter->GetAt() == nPageEnd && dwBreakStatus < FX_TXTBREAK_LineBreak) { - dwBreakStatus = pBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); - } - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { + if (pIter->GetAt() == nPageEnd && CFX_BreakTypeNoneOrPiece(dwBreakStatus)) + dwBreakStatus = pBreak->EndBreak(CFX_BreakType::Paragraph); + + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) { int32_t nPieceCount = pBreak->CountBreakPieces(); for (int32_t j = 0; j < nPieceCount; j++) { const CFX_TxtPiece* pPiece = pBreak->GetBreakPiece(j); @@ -312,7 +312,7 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, TxtEdtPiece.dwCharStyles |= FX_TXTCHARSTYLE_OddBidiLevel; } FX_FLOAT fParaBreakWidth = 0.0f; - if (pPiece->m_dwStatus > FX_TXTBREAK_PieceBreak) { + if (!CFX_BreakTypeNoneOrPiece(pPiece->m_dwStatus)) { FX_WCHAR wRtChar = pParams->wLineBreakChar; if (TxtEdtPiece.nCount >= 2) { FX_WCHAR wChar = pBuf->GetCharByIndex( @@ -356,7 +356,7 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox, fLinePos += fLineStep; pBreak->ClearBreakPieces(); } - if (pIter->GetAt() == nPageEnd && dwBreakStatus == FX_TXTBREAK_LineBreak) { + if (pIter->GetAt() == nPageEnd && dwBreakStatus == CFX_BreakType::Line) { bReload = true; pIter->Next(true); } diff --git a/xfa/fde/cfde_txtedtparag.cpp b/xfa/fde/cfde_txtedtparag.cpp index f9f88bfb5d..f7ba6d9631 100644 --- a/xfa/fde/cfde_txtedtparag.cpp +++ b/xfa/fde/cfde_txtedtparag.cpp @@ -8,6 +8,7 @@ #include <memory> +#include "third_party/base/ptr_util.h" #include "xfa/fde/cfde_txtedtbuf.h" #include "xfa/fde/cfde_txtedtengine.h" #include "xfa/fde/ifde_txtedtengine.h" @@ -37,28 +38,28 @@ void CFDE_TxtEdtParag::LoadParag() { CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); const FDE_TXTEDTPARAMS* pParam = m_pEngine->GetEditParams(); FX_WCHAR wcAlias = 0; - if (pParam->dwMode & FDE_TEXTEDITMODE_Password) { + if (pParam->dwMode & FDE_TEXTEDITMODE_Password) wcAlias = m_pEngine->GetAliasChar(); - } + std::unique_ptr<IFX_CharIter> pIter(new CFDE_TxtEdtBuf::Iterator( static_cast<CFDE_TxtEdtBuf*>(pTxtBuf), wcAlias)); pIter->SetAt(m_nCharStart); int32_t nEndIndex = m_nCharStart + m_nCharCount; CFX_ArrayTemplate<int32_t> LineBaseArr; bool bReload = false; - uint32_t dwBreakStatus = FX_TXTBREAK_None; + CFX_BreakType dwBreakStatus = CFX_BreakType::None; do { if (bReload) { - dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + dwBreakStatus = pTxtBreak->EndBreak(CFX_BreakType::Paragraph); } else { FX_WCHAR wAppend = pIter->GetChar(); dwBreakStatus = pTxtBreak->AppendChar(wAppend); } if (pIter->GetAt() + 1 == nEndIndex && - dwBreakStatus < FX_TXTBREAK_LineBreak) { - dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + CFX_BreakTypeNoneOrPiece(dwBreakStatus)) { + dwBreakStatus = pTxtBreak->EndBreak(CFX_BreakType::Paragraph); } - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) { int32_t nCount = pTxtBreak->CountBreakPieces(); int32_t nTotal = 0; for (int32_t j = 0; j < nCount; j++) { @@ -68,28 +69,28 @@ void CFDE_TxtEdtParag::LoadParag() { LineBaseArr.Add(nTotal); pTxtBreak->ClearBreakPieces(); } - if ((pIter->GetAt() + 1 == nEndIndex) && - (dwBreakStatus == FX_TXTBREAK_LineBreak)) { + if (pIter->GetAt() + 1 == nEndIndex && + dwBreakStatus == CFX_BreakType::Line) { bReload = true; pIter->Next(true); } } while (pIter->Next(false) && (pIter->GetAt() < nEndIndex)); - pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + pTxtBreak->EndBreak(CFX_BreakType::Paragraph); pTxtBreak->ClearBreakPieces(); int32_t nLineCount = LineBaseArr.GetSize(); m_nLineCount = nLineCount; - if (m_lpData) { + if (m_lpData) m_lpData = FX_Realloc(int32_t, m_lpData, nLineCount + 1); - } else { + else m_lpData = FX_Alloc(int32_t, nLineCount + 1); - } + int32_t* pIntArr = m_lpData; pIntArr[0] = 1; m_nLineCount = nLineCount; pIntArr++; - for (int32_t j = 0; j < nLineCount; j++, pIntArr++) { + for (int32_t j = 0; j < nLineCount; j++, pIntArr++) *pIntArr = LineBaseArr[j]; - } + LineBaseArr.RemoveAll(); } @@ -106,34 +107,34 @@ void CFDE_TxtEdtParag::CalcLines() { CFX_TxtBreak* pTxtBreak = m_pEngine->GetTextBreak(); CFDE_TxtEdtBuf* pTxtBuf = m_pEngine->GetTextBuf(); int32_t nCount = 0; - uint32_t dwBreakStatus = FX_TXTBREAK_None; + CFX_BreakType dwBreakStatus = CFX_BreakType::None; int32_t nEndIndex = m_nCharStart + m_nCharCount; - std::unique_ptr<IFX_CharIter> pIter( - new CFDE_TxtEdtBuf::Iterator(static_cast<CFDE_TxtEdtBuf*>(pTxtBuf))); + auto pIter = pdfium::MakeUnique<CFDE_TxtEdtBuf::Iterator>( + static_cast<CFDE_TxtEdtBuf*>(pTxtBuf)); pIter->SetAt(m_nCharStart); bool bReload = false; do { if (bReload) { - dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + dwBreakStatus = pTxtBreak->EndBreak(CFX_BreakType::Paragraph); } else { FX_WCHAR wAppend = pIter->GetChar(); dwBreakStatus = pTxtBreak->AppendChar(wAppend); } if (pIter->GetAt() + 1 == nEndIndex && - dwBreakStatus < FX_TXTBREAK_LineBreak) { - dwBreakStatus = pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + CFX_BreakTypeNoneOrPiece(dwBreakStatus)) { + dwBreakStatus = pTxtBreak->EndBreak(CFX_BreakType::Paragraph); } - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) { nCount++; pTxtBreak->ClearBreakPieces(); } - if ((pIter->GetAt() + 1 == nEndIndex) && - (dwBreakStatus == FX_TXTBREAK_LineBreak)) { + if (pIter->GetAt() + 1 == nEndIndex && + dwBreakStatus == CFX_BreakType::Line) { bReload = true; pIter->Next(true); } } while (pIter->Next(false) && (pIter->GetAt() < nEndIndex)); - pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); + pTxtBreak->EndBreak(CFX_BreakType::Paragraph); pTxtBreak->ClearBreakPieces(); m_nLineCount = nCount; } diff --git a/xfa/fde/tto/fde_textout.cpp b/xfa/fde/tto/fde_textout.cpp index b4bbe67238..93be50d34a 100644 --- a/xfa/fde/tto/fde_textout.cpp +++ b/xfa/fde/tto/fde_textout.cpp @@ -196,7 +196,7 @@ void CFDE_TextOut::CalcTextSize(const FX_WCHAR* pwsStr, FX_FLOAT fWidth = 0.0f; FX_FLOAT fHeight = 0.0f; FX_FLOAT fStartPos = bVertical ? rect.bottom() : rect.right(); - uint32_t dwBreakStatus = 0; + CFX_BreakType dwBreakStatus = CFX_BreakType::None; FX_WCHAR wPreChar = 0; FX_WCHAR wch; FX_WCHAR wBreak = 0; @@ -211,15 +211,15 @@ void CFDE_TextOut::CalcTextSize(const FX_WCHAR* pwsStr, continue; } dwBreakStatus = m_pTxtBreak->AppendChar(wch); - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) RetrieveLineWidth(dwBreakStatus, fStartPos, fWidth, fHeight); - } + wPreChar = 0; } - dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { + dwBreakStatus = m_pTxtBreak->EndBreak(CFX_BreakType::Paragraph); + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) RetrieveLineWidth(dwBreakStatus, fStartPos, fWidth, fHeight); - } + m_pTxtBreak->Reset(); FX_FLOAT fInc = rect.Height() - fHeight; if (bVertical) { @@ -265,13 +265,13 @@ void CFDE_TextOut::SetLineWidth(CFX_RectF& rect) { } } -bool CFDE_TextOut::RetrieveLineWidth(uint32_t dwBreakStatus, +bool CFDE_TextOut::RetrieveLineWidth(CFX_BreakType dwBreakStatus, FX_FLOAT& fStartPos, FX_FLOAT& fWidth, FX_FLOAT& fHeight) { - if (dwBreakStatus <= FX_TXTBREAK_PieceBreak) { + if (CFX_BreakTypeNoneOrPiece(dwBreakStatus)) return false; - } + FX_FLOAT fLineStep = (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; bool bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); @@ -279,14 +279,15 @@ bool CFDE_TextOut::RetrieveLineWidth(uint32_t dwBreakStatus, int32_t iCount = m_pTxtBreak->CountBreakPieces(); for (int32_t i = 0; i < iCount; i++) { const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); - fLineWidth += (FX_FLOAT)pPiece->m_iWidth / 20000.0f; - fStartPos = std::min(fStartPos, (FX_FLOAT)pPiece->m_iStartPos / 20000.0f); + fLineWidth += static_cast<FX_FLOAT>(pPiece->m_iWidth) / 20000.0f; + fStartPos = std::min(fStartPos, + static_cast<FX_FLOAT>(pPiece->m_iStartPos) / 20000.0f); } m_pTxtBreak->ClearBreakPieces(); - if (dwBreakStatus == FX_TXTBREAK_ParagraphBreak) { + if (dwBreakStatus == CFX_BreakType::Paragraph) { m_pTxtBreak->Reset(); } - if (!bLineWrap && dwBreakStatus == FX_TXTBREAK_LineBreak) { + if (!bLineWrap && dwBreakStatus == CFX_BreakType::Line) { fWidth += fLineWidth; } else { fWidth = std::max(fWidth, fLineWidth); @@ -404,17 +405,18 @@ void CFDE_TextOut::LoadEllipsis() { } ExpandBuffer(iLength, 1); const FX_WCHAR* pStr = m_wsEllipsis.c_str(); - uint32_t dwBreakStatus; + CFX_BreakType dwBreakStatus; FX_WCHAR wch; while (iLength-- > 0) { wch = *pStr++; dwBreakStatus = m_pTxtBreak->AppendChar(wch); - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) RetrieveEllPieces(&m_EllCharWidths); } - dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) + dwBreakStatus = m_pTxtBreak->EndBreak(CFX_BreakType::Paragraph); + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) RetrieveEllPieces(&m_EllCharWidths); + m_pTxtBreak->Reset(); } @@ -454,7 +456,7 @@ void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, int32_t iStartChar = 0; int32_t iChars = 0; int32_t iPieceWidths = 0; - uint32_t dwBreakStatus; + CFX_BreakType dwBreakStatus; FX_WCHAR wch; bool bRet = false; while (iTxtLength-- > 0) { @@ -467,11 +469,12 @@ void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, *pStr++ = wch; iChars++; dwBreakStatus = m_pTxtBreak->AppendChar(wch); - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) { bool bEndofLine = - RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, false, rect); - if (bEndofLine && (bLineWrap || (dwBreakStatus > FX_TXTBREAK_LineBreak && - !bLineWrap))) { + RetrievePieces(dwBreakStatus, iStartChar, iPieceWidths, false, rect); + if (bEndofLine && + (bLineWrap || dwBreakStatus == CFX_BreakType::Paragraph || + dwBreakStatus == CFX_BreakType::Page)) { iPieceWidths = 0; m_iCurLine++; m_fLinePos += fLineStep; @@ -485,16 +488,16 @@ void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, } } } - dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); - if (dwBreakStatus > FX_TXTBREAK_PieceBreak && !bRet) { - RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, false, rect); - } + dwBreakStatus = m_pTxtBreak->EndBreak(CFX_BreakType::Paragraph); + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus) && !bRet) + RetrievePieces(dwBreakStatus, iStartChar, iPieceWidths, false, rect); + m_pTxtBreak->ClearBreakPieces(); m_pTxtBreak->Reset(); m_wsText.ReleaseBuffer(iLength); } -bool CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, +bool CFDE_TextOut::RetrievePieces(CFX_BreakType dwBreakStatus, int32_t& iStartChar, int32_t& iPieceWidths, bool bReload, @@ -559,9 +562,8 @@ bool CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, iPieceWidths += iWidth; } m_pTxtBreak->ClearBreakPieces(); - bool bRet = bSingleLine || bLineWrap || (!bLineWrap && bNeedReload) || - dwBreakStatus == FX_TXTBREAK_ParagraphBreak; - return bRet; + return bSingleLine || bLineWrap || bNeedReload || + dwBreakStatus == CFX_BreakType::Paragraph; } void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, @@ -650,7 +652,7 @@ void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; int32_t iPieceCount = pLine->GetSize(); int32_t iPieceIndex = 0; - uint32_t dwBreakStatus = 0; + CFX_BreakType dwBreakStatus = CFX_BreakType::None; FX_WCHAR wch; while (iPieceIndex < iPieceCount) { int32_t iStar = iStartChar; @@ -658,18 +660,17 @@ void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { while (iStar < iEnd) { wch = *(pwsStr + iStar); dwBreakStatus = m_pTxtBreak->AppendChar(wch); - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { - RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, true, rect); - } + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) + RetrievePieces(dwBreakStatus, iStartChar, iPieceWidths, true, rect); iStar++; } iPieceIndex++; pPiece = pLine->GetPtrAt(iPieceIndex); } - dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); - if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { - RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, true, rect); - } + dwBreakStatus = m_pTxtBreak->EndBreak(CFX_BreakType::Paragraph); + if (!CFX_BreakTypeNoneOrPiece(dwBreakStatus)) + RetrievePieces(dwBreakStatus, iStartChar, iPieceWidths, true, rect); + m_pTxtBreak->Reset(); } diff --git a/xfa/fde/tto/fde_textout.h b/xfa/fde/tto/fde_textout.h index 04d656776e..fd9f6027f4 100644 --- a/xfa/fde/tto/fde_textout.h +++ b/xfa/fde/tto/fde_textout.h @@ -11,6 +11,7 @@ #include <memory> #include <vector> +#include "core/fxcrt/fx_ucd.h" #include "core/fxge/cfx_fxgedevice.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/fx_dib.h" @@ -120,7 +121,7 @@ class CFDE_TextOut { protected: void CalcTextSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect); - bool RetrieveLineWidth(uint32_t dwBreakStatus, + bool RetrieveLineWidth(CFX_BreakType dwBreakStatus, FX_FLOAT& fStartPos, FX_FLOAT& fWidth, FX_FLOAT& fHeight); @@ -136,7 +137,7 @@ class CFDE_TextOut { void Reload(const CFX_RectF& rect); void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect); - bool RetriecePieces(uint32_t dwBreakStatus, + bool RetrievePieces(CFX_BreakType dwBreakStatus, int32_t& iStartChar, int32_t& iPieceWidths, bool bReload, |