From 9342b33ec0e2b43c0ee0b94bb70f2e981c263877 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 16 Aug 2017 17:26:23 -0400 Subject: Remove redundant members in CFDE_TxtEdtEngine This CL removes a bunch of redundant members from the text edit engine. The change information tracking was removed as most of it was unused or was used inconsistently. Change-Id: I92460594e46accff0b78e1183c8574fc83ce728a Reviewed-on: https://pdfium-review.googlesource.com/11275 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- xfa/fde/cfde_textout.cpp | 1 - xfa/fde/cfde_txtedtengine.cpp | 91 ++++++++++++++++-------------------------- xfa/fde/cfde_txtedtengine.h | 42 +++---------------- xfa/fde/cfde_txtedtpage.cpp | 7 ++-- xfa/fde/cfde_txtedttextset.cpp | 2 - 5 files changed, 44 insertions(+), 99 deletions(-) (limited to 'xfa/fde') diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp index 7a246a8efe..9bbeadee58 100644 --- a/xfa/fde/cfde_textout.cpp +++ b/xfa/fde/cfde_textout.cpp @@ -549,7 +549,6 @@ FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { tr.fFontSize = m_fFontSize; tr.dwStyles = m_dwTxtBkStyles; tr.dwCharStyles = pPiece->dwCharStyles; - tr.wLineBreakChar = L'\n'; tr.pRect = &pPiece->rtPiece; return tr; } diff --git a/xfa/fde/cfde_txtedtengine.cpp b/xfa/fde/cfde_txtedtengine.cpp index 31cbfc0773..9877d87fb4 100644 --- a/xfa/fde/cfde_txtedtengine.cpp +++ b/xfa/fde/cfde_txtedtengine.cpp @@ -21,7 +21,6 @@ namespace { const uint32_t kPageWidthMax = 0xffff; -const uint32_t kUnicodeParagraphSeparator = 0x2029; enum FDE_TXTEDT_MODIFY_RET { FDE_TXTEDT_MODIFY_RET_F_Locked = -5, @@ -49,24 +48,21 @@ class InsertOperation : public IFDE_TxtEdtDoRecord { ~InsertOperation() override {} void Undo() const override { + CFX_WideString prev = m_pEngine->GetText(0, -1); + if (m_pEngine->IsSelect()) m_pEngine->ClearSelection(); m_pEngine->Inner_DeleteRange(m_nCaret, m_wsInsert.GetLength()); - m_pEngine->UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Delete, - m_wsInsert); - m_pEngine->GetParams()->pEventSink->OnTextChanged( - *m_pEngine->GetChangeInfo()); + m_pEngine->GetParams()->pEventSink->OnTextChanged(prev); m_pEngine->SetCaretPos(m_nCaret, true); } void Redo() const override { + CFX_WideString prev = m_pEngine->GetText(0, -1); m_pEngine->Inner_Insert(m_nCaret, m_wsInsert.c_str(), m_wsInsert.GetLength()); - m_pEngine->UpdateChangeInfoInsert(FDE_TXTEDT_TEXTCHANGE_TYPE_Insert, - m_wsInsert); - m_pEngine->GetParams()->pEventSink->OnTextChanged( - *m_pEngine->GetChangeInfo()); + m_pEngine->GetParams()->pEventSink->OnTextChanged(prev); m_pEngine->SetCaretPos(m_nCaret, false); } @@ -94,6 +90,7 @@ class DeleteOperation : public IFDE_TxtEdtDoRecord { ~DeleteOperation() override {} void Undo() const override { + CFX_WideString prev = m_pEngine->GetText(0, -1); if (m_pEngine->IsSelect()) m_pEngine->ClearSelection(); @@ -101,22 +98,17 @@ class DeleteOperation : public IFDE_TxtEdtDoRecord { if (m_bSel) m_pEngine->AddSelRange(m_nIndex, m_wsRange.GetLength()); - m_pEngine->UpdateChangeInfoInsert(FDE_TXTEDT_TEXTCHANGE_TYPE_Insert, - m_wsRange); - m_pEngine->GetParams()->pEventSink->OnTextChanged( - *m_pEngine->GetChangeInfo()); + m_pEngine->GetParams()->pEventSink->OnTextChanged(prev); m_pEngine->SetCaretPos(m_nCaret, true); } void Redo() const override { + CFX_WideString prev = m_pEngine->GetText(0, -1); m_pEngine->Inner_DeleteRange(m_nIndex, m_wsRange.GetLength()); if (m_bSel) m_pEngine->RemoveSelRange(m_nIndex, m_wsRange.GetLength()); - m_pEngine->UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Delete, - m_wsRange); - m_pEngine->GetParams()->pEventSink->OnTextChanged( - *m_pEngine->GetChangeInfo()); + m_pEngine->GetParams()->pEventSink->OnTextChanged(prev); m_pEngine->SetCaretPos(m_nIndex, true); } @@ -141,19 +133,10 @@ FDE_TXTEDTPARAMS::FDE_TXTEDTPARAMS() dwFontColor(0xff000000), fLineSpace(10.0f), fTabWidth(36), - wDefChar(0xFEFF), - wLineBreakChar('\n'), - nLineEnd(0), - nHorzScale(100), - fCharSpace(0), pEventSink(nullptr) {} FDE_TXTEDTPARAMS::~FDE_TXTEDTPARAMS() {} -FDE_TXTEDT_TEXTCHANGE_INFO::FDE_TXTEDT_TEXTCHANGE_INFO() {} - -FDE_TXTEDT_TEXTCHANGE_INFO::~FDE_TXTEDT_TEXTCHANGE_INFO() {} - CFDE_TxtEdtEngine::CFDE_TxtEdtEngine() : m_pTxtBuf(pdfium::MakeUnique()), m_nPageLineCount(20), @@ -161,16 +144,13 @@ CFDE_TxtEdtEngine::CFDE_TxtEdtEngine() m_nAnchorPos(-1), m_fCaretPosReserve(0.0), m_nCaret(0), - m_bBefore(true), m_nCaretPage(0), - m_bLock(false), m_nLimit(0), m_wcAliasChar(L'*'), m_nFirstLineEnd(FDE_TXTEDIT_LINEEND_Auto), - m_bAutoLineEnd(true), - m_wLineEnd(kUnicodeParagraphSeparator) { - m_bAutoLineEnd = (m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto); -} + m_bBefore(true), + m_bLock(false), + m_bAutoLineEnd(true) {} CFDE_TxtEdtEngine::~CFDE_TxtEdtEngine() { RemoveAllParags(); @@ -184,8 +164,7 @@ void CFDE_TxtEdtEngine::SetEditParams(const FDE_TXTEDTPARAMS& params) { m_pTextBreak = pdfium::MakeUnique(); m_Param = params; - m_wLineEnd = params.wLineBreakChar; - m_bAutoLineEnd = m_Param.nLineEnd == FDE_TXTEDIT_LINEEND_Auto; + m_bAutoLineEnd = true; UpdateTxtBreak(); } @@ -210,7 +189,7 @@ void CFDE_TxtEdtEngine::SetText(const CFX_WideString& wsText) { } m_pTxtBuf->SetText(wsTemp); } - m_pTxtBuf->Insert(nLength, &m_wLineEnd, 1); + m_pTxtBuf->Insert(nLength, L"\n", 1); RebuildParagraphs(); } @@ -238,8 +217,10 @@ void CFDE_TxtEdtEngine::ClearText() { return; } + CFX_WideString prev = GetText(0, -1); + DeleteRange_DoRecord(0, len, false); - m_Param.pEventSink->OnTextChanged(m_ChangeInfo); + m_Param.pEventSink->OnTextChanged(prev); SetCaretPos(0, true); } @@ -393,10 +374,9 @@ int32_t CFDE_TxtEdtEngine::Insert(const CFX_WideString& str) { m_Param.pEventSink->OnAddDoRecord(pdfium::MakeUnique( this, m_nCaret, CFX_WideString(lpBuffer, nLength))); - m_ChangeInfo.wsPrevText = GetText(0, -1); + CFX_WideString prev = GetText(0, -1); Inner_Insert(m_nCaret, lpBuffer, nLength); - m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert; - m_ChangeInfo.wsInsert = CFX_WideString(lpBuffer, nLength); + int32_t nStart = m_nCaret; nStart += nLength; wchar_t wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); @@ -406,7 +386,7 @@ int32_t CFDE_TxtEdtEngine::Insert(const CFX_WideString& str) { bBefore = false; } SetCaretPos(nStart, bBefore); - m_Param.pEventSink->OnTextChanged(m_ChangeInfo); + m_Param.pEventSink->OnTextChanged(prev); return FDE_TXTEDT_MODIFY_RET_S_Normal; } @@ -450,12 +430,11 @@ void CFDE_TxtEdtEngine::Delete(bool bBackspace) { m_Param.pEventSink->OnAddDoRecord(pdfium::MakeUnique( this, nStart, m_nCaret, wsRange, false)); - UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Delete, - GetText(nStart, nCount)); + CFX_WideString prev = GetText(0, -1); Inner_DeleteRange(nStart, nCount); SetCaretPos(nStart + ((!bBackspace && nStart > 0) ? -1 : 0), (bBackspace || nStart == 0)); - m_Param.pEventSink->OnTextChanged(m_ChangeInfo); + m_Param.pEventSink->OnTextChanged(prev); } void CFDE_TxtEdtEngine::RemoveSelRange(int32_t nStart, int32_t nCount) { @@ -670,7 +649,7 @@ void CFDE_TxtEdtEngine::Inner_Insert(int32_t nStart, int32_t nParagIndex = ParagPos.nParagIndex; for (int32_t i = 0; i < nLength; i++, lpPos++) { wCurChar = *lpPos; - if (wCurChar == m_wLineEnd) { + if (wCurChar == L'\n') { if (bFirst) { pParag->SetTextLength(nLeavePart + (i - nTextStart + 1)); pParag->SetLineCount(-1); @@ -780,8 +759,6 @@ void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart, m_Param.pEventSink->OnAddDoRecord(pdfium::MakeUnique( this, nStart, m_nCaret, wsRange, bSel)); - UpdateChangeInfoDelete(FDE_TXTEDT_TEXTCHANGE_TYPE_Delete, - GetText(nStart, nCount)); Inner_DeleteRange(nStart, nCount); } @@ -804,7 +781,7 @@ void CFDE_TxtEdtEngine::RebuildParagraphs() { do { wChar = pIter->GetChar(); nIndex = pIter->GetAt(); - if (wChar == m_wLineEnd) { + if (wChar == L'\n') { auto pParag = pdfium::MakeUnique(this); pParag->SetStartIndex(nParagStart); pParag->SetTextLength(nIndex - nParagStart + 1); @@ -885,11 +862,11 @@ void CFDE_TxtEdtEngine::UpdateTxtBreak() { m_pTextBreak->SetFont(m_Param.pFont); m_pTextBreak->SetFontSize(m_Param.fFontSize); m_pTextBreak->SetTabWidth(m_Param.fTabWidth); - m_pTextBreak->SetDefaultChar(m_Param.wDefChar); - m_pTextBreak->SetParagraphBreakChar(m_Param.wLineBreakChar); + m_pTextBreak->SetDefaultChar(0xFEFF); + m_pTextBreak->SetParagraphBreakChar(L'\n'); m_pTextBreak->SetLineBreakTolerance(m_Param.fFontSize * 0.2f); - m_pTextBreak->SetHorizontalScale(m_Param.nHorzScale); - m_pTextBreak->SetCharSpace(m_Param.fCharSpace); + m_pTextBreak->SetHorizontalScale(100); + m_pTextBreak->SetCharSpace(0); } bool CFDE_TxtEdtEngine::ReplaceParagEnd(wchar_t*& lpText, @@ -899,7 +876,7 @@ bool CFDE_TxtEdtEngine::ReplaceParagEnd(wchar_t*& lpText, wchar_t wc = lpText[i]; switch (wc) { case L'\r': { - lpText[i] = m_wLineEnd; + lpText[i] = L'\n'; bPreIsCR = true; } break; case L'\n': { @@ -917,7 +894,7 @@ bool CFDE_TxtEdtEngine::ReplaceParagEnd(wchar_t*& lpText, m_bAutoLineEnd = false; } } else { - lpText[i] = m_wLineEnd; + lpText[i] = L'\n'; if (m_bAutoLineEnd) { m_nFirstLineEnd = FDE_TXTEDIT_LINEEND_LF; m_bAutoLineEnd = false; @@ -943,7 +920,7 @@ void CFDE_TxtEdtEngine::RecoverParagEnd(CFX_WideString& wsText) const { int32_t nLength = wsText.GetLength(); wchar_t* lpPos = const_cast(wsText.c_str()); for (int32_t i = 0; i < nLength; i++, lpPos++) { - if (*lpPos == m_wLineEnd) { + if (*lpPos == L'\n') { *lpPos = wc; PosArr.push_back(i); } @@ -974,7 +951,7 @@ void CFDE_TxtEdtEngine::RecoverParagEnd(CFX_WideString& wsText) const { int32_t nLength = wsText.GetLength(); wchar_t* lpBuf = const_cast(wsText.c_str()); for (int32_t i = 0; i < nLength; i++, lpBuf++) { - if (*lpBuf == m_wLineEnd) + if (*lpBuf == L'\n') *lpBuf = wc; } } @@ -1269,6 +1246,8 @@ void CFDE_TxtEdtEngine::DeleteSelect() { if (nCountRange <= 0) return; + CFX_WideString prev = GetText(0, -1); + int32_t nSelStart = 0; while (nCountRange > 0) { int32_t nSelCount = GetSelRange(--nCountRange, &nSelStart); @@ -1276,7 +1255,7 @@ void CFDE_TxtEdtEngine::DeleteSelect() { DeleteRange_DoRecord(nSelStart, nSelCount, true); } ClearSelection(); - m_Param.pEventSink->OnTextChanged(m_ChangeInfo); + m_Param.pEventSink->OnTextChanged(prev); m_Param.pEventSink->OnSelChanged(); SetCaretPos(nSelStart, true); } diff --git a/xfa/fde/cfde_txtedtengine.h b/xfa/fde/cfde_txtedtengine.h index 9d472ce65a..b22c36f5ec 100644 --- a/xfa/fde/cfde_txtedtengine.h +++ b/xfa/fde/cfde_txtedtengine.h @@ -55,37 +55,20 @@ struct FDE_TXTEDTPARAMS { float fPlateWidth; float fPlateHeight; + int32_t nLineCount; uint32_t dwLayoutStyles; uint32_t dwAlignment; uint32_t dwMode; + CFX_RetainPtr pFont; float fFontSize; FX_ARGB dwFontColor; + float fLineSpace; float fTabWidth; - wchar_t wDefChar; - wchar_t wLineBreakChar; - int32_t nLineEnd; - int32_t nHorzScale; - float fCharSpace; - CFWL_Edit* pEventSink; -}; -enum FDE_TXTEDT_TEXTCHANGE_TYPE { - FDE_TXTEDT_TEXTCHANGE_TYPE_Insert = 0, - FDE_TXTEDT_TEXTCHANGE_TYPE_Delete, - FDE_TXTEDT_TEXTCHANGE_TYPE_Replace, -}; - -struct FDE_TXTEDT_TEXTCHANGE_INFO { - FDE_TXTEDT_TEXTCHANGE_INFO(); - ~FDE_TXTEDT_TEXTCHANGE_INFO(); - - int32_t nChangeType; - CFX_WideString wsInsert; - CFX_WideString wsDelete; - CFX_WideString wsPrevText; + CFWL_Edit* pEventSink; }; class CFDE_TxtEdtEngine { @@ -149,17 +132,6 @@ class CFDE_TxtEdtEngine { void Inner_DeleteRange(int32_t nStart, int32_t nCount); void Inner_Insert(int32_t nStart, const wchar_t* lpText, int32_t nLength); const FDE_TXTEDTPARAMS* GetParams() const { return &m_Param; } - FDE_TXTEDT_TEXTCHANGE_INFO* GetChangeInfo() { return &m_ChangeInfo; } - - void UpdateChangeInfoInsert(int32_t type, const CFX_WideString& insertValue) { - m_ChangeInfo.nChangeType = type; - m_ChangeInfo.wsInsert = insertValue; - } - - void UpdateChangeInfoDelete(int32_t type, const CFX_WideString& deleteValue) { - m_ChangeInfo.nChangeType = type; - m_ChangeInfo.wsDelete = deleteValue; - } private: struct FDE_TXTEDTSELRANGE { @@ -229,16 +201,14 @@ class CFDE_TxtEdtEngine { int32_t m_nAnchorPos; float m_fCaretPosReserve; int32_t m_nCaret; - bool m_bBefore; int32_t m_nCaretPage; CFX_RectF m_rtCaret; - bool m_bLock; int32_t m_nLimit; wchar_t m_wcAliasChar; int32_t m_nFirstLineEnd; + bool m_bBefore; + bool m_bLock; bool m_bAutoLineEnd; - wchar_t m_wLineEnd; - FDE_TXTEDT_TEXTCHANGE_INFO m_ChangeInfo; }; #endif // XFA_FDE_CFDE_TXTEDTENGINE_H_ diff --git a/xfa/fde/cfde_txtedtpage.cpp b/xfa/fde/cfde_txtedtpage.cpp index cbc652da76..3020882c7e 100644 --- a/xfa/fde/cfde_txtedtpage.cpp +++ b/xfa/fde/cfde_txtedtpage.cpp @@ -260,22 +260,21 @@ int32_t CFDE_TxtEdtPage::LoadPage() { float fParaBreakWidth = 0.0f; if (!CFX_BreakTypeNoneOrPiece(pPiece->m_dwStatus)) { - wchar_t wRtChar = pParams->wLineBreakChar; if (TxtEdtPiece.nCount >= 2) { wchar_t wChar = pBuf->GetCharByIndex( m_nPageStart + TxtEdtPiece.nStart + TxtEdtPiece.nCount - 1); wchar_t wCharPre = pBuf->GetCharByIndex( m_nPageStart + TxtEdtPiece.nStart + TxtEdtPiece.nCount - 2); - if (wChar == wRtChar) { + if (wChar == L'\n') { fParaBreakWidth += fDefCharWidth; } - if (wCharPre == wRtChar) { + if (wCharPre == L'\n') { fParaBreakWidth += fDefCharWidth; } } else if (TxtEdtPiece.nCount >= 1) { wchar_t wChar = pBuf->GetCharByIndex( m_nPageStart + TxtEdtPiece.nStart + TxtEdtPiece.nCount - 1); - if (wChar == wRtChar) { + if (wChar == L'\n') { fParaBreakWidth += fDefCharWidth; } } diff --git a/xfa/fde/cfde_txtedttextset.cpp b/xfa/fde/cfde_txtedttextset.cpp index fce52d3278..0b6cf8214e 100644 --- a/xfa/fde/cfde_txtedttextset.cpp +++ b/xfa/fde/cfde_txtedttextset.cpp @@ -35,7 +35,6 @@ int32_t CFDE_TxtEdtTextSet::GetDisplayPos(const FDE_TEXTEDITPIECE& piece, tr.dwStyles = dwLayoutStyle; tr.dwCharStyles = piece.dwCharStyles; tr.pRect = &piece.rtPiece; - tr.wLineBreakChar = pTextParams->wLineBreakChar; return pBreak->GetDisplayPos(&tr, pCharPos); } @@ -57,6 +56,5 @@ std::vector CFDE_TxtEdtTextSet::GetCharRects( tr.dwStyles = dwLayoutStyle; tr.dwCharStyles = pPiece->dwCharStyles; tr.pRect = &pPiece->rtPiece; - tr.wLineBreakChar = pTextParams->wLineBreakChar; return pEngine->GetTextBreak()->GetCharRects(&tr, bBBox); } -- cgit v1.2.3