From 54a8390782c734f6c919f126ea5b93d5a3dcdc00 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 14 Aug 2017 11:08:39 -0400 Subject: Cleanup CFDE_TextOut methods This CL removes unused CFDE_TextOut methods and merges some single use methods. Change-Id: Ie625ad737aeb1dc163b03f15f4774744062a9491 Reviewed-on: https://pdfium-review.googlesource.com/10570 Commit-Queue: dsinclair Reviewed-by: Tom Sepez Reviewed-by: Henrique Nakashima --- xfa/fde/cfde_textout.cpp | 196 +++++++++++------------------------------------ xfa/fde/cfde_textout.h | 34 +------- 2 files changed, 46 insertions(+), 184 deletions(-) (limited to 'xfa/fde') diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp index 3278a88ebb..5f7fe078f1 100644 --- a/xfa/fde/cfde_textout.cpp +++ b/xfa/fde/cfde_textout.cpp @@ -45,8 +45,6 @@ CFDE_TextOut::CFDE_TextOut() m_fLinePos(0.0f), m_fTolerance(0.0f), m_iAlignment(FDE_TextAlignment::kTopLeft), - m_iTxtBkAlignment(0), - m_wParagraphBkChar(L'\n'), m_TxtColor(0xFF000000), m_dwTxtBkStyles(0), m_ttoLines(5), @@ -54,8 +52,6 @@ CFDE_TextOut::CFDE_TextOut() m_iCurPiece(0), m_iTotalLines(0) { m_Matrix.SetIdentity(); - m_rtClip.Reset(); - m_rtLogicClip.Reset(); } CFDE_TextOut::~CFDE_TextOut() {} @@ -72,10 +68,6 @@ void CFDE_TextOut::SetFontSize(float fFontSize) { m_pTxtBreak->SetFontSize(fFontSize); } -void CFDE_TextOut::SetTextColor(FX_ARGB color) { - m_TxtColor = color; -} - void CFDE_TextOut::SetStyles(const FDE_TextStyle& dwStyles) { m_Styles = dwStyles; @@ -86,31 +78,23 @@ void CFDE_TextOut::SetStyles(const FDE_TextStyle& dwStyles) { m_pTxtBreak->SetLayoutStyles(m_dwTxtBkStyles); } -void CFDE_TextOut::SetTabWidth(float fTabWidth) { - ASSERT(fTabWidth > 1.0f); - m_pTxtBreak->SetTabWidth(fTabWidth); -} - -void CFDE_TextOut::SetParagraphBreakChar(wchar_t wch) { - m_wParagraphBkChar = wch; - m_pTxtBreak->SetParagraphBreakChar(wch); -} - void CFDE_TextOut::SetAlignment(FDE_TextAlignment iAlignment) { m_iAlignment = iAlignment; + + int32_t txtBreakAlignment = 0; switch (m_iAlignment) { case FDE_TextAlignment::kCenter: - m_iTxtBkAlignment = CFX_TxtLineAlignment_Center; + txtBreakAlignment = CFX_TxtLineAlignment_Center; break; case FDE_TextAlignment::kCenterRight: - m_iTxtBkAlignment = CFX_TxtLineAlignment_Right; + txtBreakAlignment = CFX_TxtLineAlignment_Right; break; case FDE_TextAlignment::kCenterLeft: case FDE_TextAlignment::kTopLeft: - m_iTxtBkAlignment = CFX_TxtLineAlignment_Left; + txtBreakAlignment = CFX_TxtLineAlignment_Left; break; } - m_pTxtBreak->SetAlignment(m_iTxtBkAlignment); + m_pTxtBreak->SetAlignment(txtBreakAlignment); } void CFDE_TextOut::SetLineSpace(float fLineSpace) { @@ -118,45 +102,16 @@ void CFDE_TextOut::SetLineSpace(float fLineSpace) { m_fLineSpace = fLineSpace; } -void CFDE_TextOut::SetDIBitmap(const CFX_RetainPtr& pDIB) { - ASSERT(pDIB); - m_pRenderDevice.reset(); - m_pDefaultRenderDevice = pdfium::MakeUnique(); - m_pDefaultRenderDevice->Attach(pDIB, false, nullptr, false); - m_pRenderDevice = - pdfium::MakeUnique(m_pDefaultRenderDevice.get()); -} - void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { ASSERT(pDevice); m_pRenderDevice = pdfium::MakeUnique(pDevice); } -void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { - m_rtClip = rtClip.As(); -} - -void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) { - m_rtClip = rtClip; -} - -void CFDE_TextOut::SetLogicClipRect(const CFX_RectF& rtClip) { - m_rtLogicClip = rtClip; -} - -void CFDE_TextOut::SetMatrix(const CFX_Matrix& matrix) { - m_Matrix = matrix; -} - void CFDE_TextOut::SetLineBreakTolerance(float fTolerance) { m_fTolerance = fTolerance; m_pTxtBreak->SetLineBreakTolerance(m_fTolerance); } -int32_t CFDE_TextOut::GetTotalLines() { - return m_iTotalLines; -} - void CFDE_TextOut::CalcLogicSize(const wchar_t* pwsStr, int32_t iLength, CFX_SizeF& size) { @@ -171,16 +126,18 @@ void CFDE_TextOut::CalcLogicSize(const wchar_t* pwsStr, if (!pwsStr || iLength < 1) { rect.width = 0.0f; rect.height = 0.0f; - } else { - CalcTextSize(pwsStr, iLength, rect); + return; } -} -void CFDE_TextOut::CalcTextSize(const wchar_t* pwsStr, - int32_t iLength, - CFX_RectF& rect) { ASSERT(m_pFont && m_fFontSize >= 1.0f); - SetLineWidth(rect); + + if (!m_Styles.single_line_) { + if (rect.Width() < 1.0f) + rect.width = m_fFontSize * 1000.0f; + + m_pTxtBreak->SetLineWidth(rect.Width()); + } + m_iTotalLines = 0; const wchar_t* pStr = pwsStr; float fWidth = 0.0f; @@ -221,15 +178,6 @@ void CFDE_TextOut::CalcTextSize(const wchar_t* pwsStr, rect.height -= m_fLineSpace - m_fFontSize; } -void CFDE_TextOut::SetLineWidth(CFX_RectF& rect) { - if (m_Styles.single_line_) - return; - if (rect.Width() < 1.0f) - rect.width = m_fFontSize * 1000.0f; - - m_pTxtBreak->SetLineWidth(rect.Width()); -} - bool CFDE_TextOut::RetrieveLineWidth(CFX_BreakType dwBreakStatus, float& fStartPos, float& fWidth, @@ -260,58 +208,9 @@ bool CFDE_TextOut::RetrieveLineWidth(CFX_BreakType dwBreakStatus, return true; } -void CFDE_TextOut::DrawText(const wchar_t* pwsStr, - int32_t iLength, - int32_t x, - int32_t y) { - CFX_RectF rtText(static_cast(x), static_cast(y), - m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); - DrawText(pwsStr, iLength, rtText); -} - -void CFDE_TextOut::DrawText(const wchar_t* pwsStr, - int32_t iLength, - float x, - float y) { - DrawText(pwsStr, iLength, - CFX_RectF(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f)); -} - -void CFDE_TextOut::DrawText(const wchar_t* pwsStr, - int32_t iLength, - const CFX_Rect& rect) { - DrawText(pwsStr, iLength, rect.As()); -} - -void CFDE_TextOut::DrawText(const wchar_t* pwsStr, - int32_t iLength, - const CFX_RectF& rect) { - CFX_RectF rtText(rect.left, rect.top, rect.width, rect.height); - m_Matrix.GetInverse().TransformRect(rtText); - DrawText(pwsStr, iLength, rtText, m_rtClip); -} - -void CFDE_TextOut::DrawLogicText(const wchar_t* pwsStr, - int32_t iLength, - float x, - float y) { - CFX_RectF rtText(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); - DrawLogicText(pwsStr, iLength, rtText); -} - void CFDE_TextOut::DrawLogicText(const wchar_t* pwsStr, int32_t iLength, const CFX_RectF& rect) { - CFX_RectF rtClip(m_rtLogicClip.left, m_rtLogicClip.top, m_rtLogicClip.width, - m_rtLogicClip.height); - m_Matrix.TransformRect(rtClip); - DrawText(pwsStr, iLength, rect, rtClip); -} - -void CFDE_TextOut::DrawText(const wchar_t* pwsStr, - int32_t iLength, - const CFX_RectF& rect, - const CFX_RectF& rtClip) { ASSERT(m_pFont && m_fFontSize >= 1.0f); if (!pwsStr || iLength < 1) return; @@ -322,10 +221,36 @@ void CFDE_TextOut::DrawText(const wchar_t* pwsStr, m_pTxtBreak->SetLineWidth(fLineWidth); m_ttoLines.clear(); m_wsText.clear(); + LoadText(pwsStr, iLength, rect); Reload(rect); DoAlignment(rect); - OnDraw(rtClip); + + if (!m_pRenderDevice || m_ttoLines.empty()) + return; + + CFX_RectF rtClip; + m_Matrix.TransformRect(rtClip); + + m_pRenderDevice->SaveState(); + if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) + m_pRenderDevice->SetClipRect(rtClip); + + for (auto& line : m_ttoLines) { + int32_t iPieces = line.GetSize(); + for (int32_t j = 0; j < iPieces; j++) { + FDE_TTOPIECE* pPiece = line.GetPtrAt(j); + if (!pPiece) + continue; + + int32_t iCount = GetDisplayPos(pPiece); + if (iCount > 0) { + m_pRenderDevice->DrawString(m_TxtColor, m_pFont, m_CharPos.data(), + iCount, m_fFontSize, &m_Matrix); + } + } + } + m_pRenderDevice->RestoreState(); } void CFDE_TextOut::LoadText(const wchar_t* pwsStr, @@ -528,31 +453,6 @@ void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { } } -void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { - if (!m_pRenderDevice || m_ttoLines.empty()) - return; - - m_pRenderDevice->SaveState(); - if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) - m_pRenderDevice->SetClipRect(rtClip); - - for (auto& line : m_ttoLines) { - int32_t iPieces = line.GetSize(); - for (int32_t j = 0; j < iPieces; j++) { - FDE_TTOPIECE* pPiece = line.GetPtrAt(j); - if (!pPiece) - continue; - - int32_t iCount = GetDisplayPos(pPiece); - if (iCount > 0) { - m_pRenderDevice->DrawString(m_TxtColor, m_pFont, m_CharPos.data(), - iCount, m_fFontSize, &m_Matrix); - } - } - } - m_pRenderDevice->RestoreState(); -} - int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { FX_TXTRUN tr = ToTextRun(pPiece); ASSERT(tr.iLength >= 0); @@ -561,12 +461,6 @@ int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { return m_pTxtBreak->GetDisplayPos(&tr, m_CharPos.data()); } -int32_t CFDE_TextOut::GetCharRects(const FDE_TTOPIECE* pPiece) { - FX_TXTRUN tr = ToTextRun(pPiece); - m_rectArray = m_pTxtBreak->GetCharRects(&tr); - return pdfium::CollectionSize(m_rectArray); -} - FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { FX_TXTRUN tr; tr.wsStr = m_wsText + pPiece->iStartChar; @@ -576,7 +470,7 @@ FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { tr.fFontSize = m_fFontSize; tr.dwStyles = m_dwTxtBkStyles; tr.dwCharStyles = pPiece->dwCharStyles; - tr.wLineBreakChar = m_wParagraphBkChar; + tr.wLineBreakChar = L'\n'; tr.pRect = &pPiece->rtPiece; return tr; } @@ -613,7 +507,3 @@ void CFDE_TTOLine::RemoveLast(int32_t icount) { icount = std::min(icount, pdfium::CollectionSize(m_pieces)); m_pieces.erase(m_pieces.end() - icount, m_pieces.end()); } - -void CFDE_TTOLine::RemoveAll() { - m_pieces.clear(); -} diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h index 8d99900566..f2541bb11b 100644 --- a/xfa/fde/cfde_textout.h +++ b/xfa/fde/cfde_textout.h @@ -68,7 +68,6 @@ class CFDE_TTOLine { int32_t GetSize() const; FDE_TTOPIECE* GetPtrAt(int32_t index); void RemoveLast(int32_t iCount); - void RemoveAll(); private: bool m_bNewReload; @@ -82,44 +81,26 @@ class CFDE_TextOut { void SetFont(const CFX_RetainPtr& pFont); void SetFontSize(float fFontSize); - void SetTextColor(FX_ARGB color); + void SetTextColor(FX_ARGB color) { m_TxtColor = color; } void SetStyles(const FDE_TextStyle& dwStyles); - void SetTabWidth(float fTabWidth); - void SetParagraphBreakChar(wchar_t wch); void SetAlignment(FDE_TextAlignment iAlignment); void SetLineSpace(float fLineSpace); - void SetDIBitmap(const CFX_RetainPtr& pDIB); void SetRenderDevice(CFX_RenderDevice* pDevice); - void SetClipRect(const CFX_Rect& rtClip); - void SetClipRect(const CFX_RectF& rtClip); - void SetMatrix(const CFX_Matrix& matrix); + void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } void SetLineBreakTolerance(float fTolerance); - void DrawText(const wchar_t* pwsStr, int32_t iLength, int32_t x, int32_t y); - void DrawText(const wchar_t* pwsStr, int32_t iLength, float x, float y); - void DrawText(const wchar_t* pwsStr, int32_t iLength, const CFX_Rect& rect); - void DrawText(const wchar_t* pwsStr, int32_t iLength, const CFX_RectF& rect); - - void SetLogicClipRect(const CFX_RectF& rtClip); void CalcLogicSize(const wchar_t* pwsStr, int32_t iLength, CFX_SizeF& size); void CalcLogicSize(const wchar_t* pwsStr, int32_t iLength, CFX_RectF& rect); - void DrawLogicText(const wchar_t* pwsStr, int32_t iLength, float x, float y); void DrawLogicText(const wchar_t* pwsStr, int32_t iLength, const CFX_RectF& rect); - int32_t GetTotalLines(); + int32_t GetTotalLines() const { return m_iTotalLines; } private: - void CalcTextSize(const wchar_t* pwsStr, int32_t iLength, CFX_RectF& rect); bool RetrieveLineWidth(CFX_BreakType dwBreakStatus, float& fStartPos, float& fWidth, float& fHeight); - void SetLineWidth(CFX_RectF& rect); - void DrawText(const wchar_t* pwsStr, - int32_t iLength, - const CFX_RectF& rect, - const CFX_RectF& rtClip); void LoadText(const wchar_t* pwsStr, int32_t iLength, const CFX_RectF& rect); void Reload(const CFX_RectF& rect); @@ -131,9 +112,7 @@ class CFDE_TextOut { const CFX_RectF& rect); void AppendPiece(const FDE_TTOPIECE& ttoPiece, bool bNeedReload, bool bEnd); void DoAlignment(const CFX_RectF& rect); - void OnDraw(const CFX_RectF& rtClip); int32_t GetDisplayPos(FDE_TTOPIECE* pPiece); - int32_t GetCharRects(const FDE_TTOPIECE* pPiece); FX_TXTRUN ToTextRun(const FDE_TTOPIECE* pPiece); @@ -145,24 +124,17 @@ class CFDE_TextOut { float m_fTolerance; FDE_TextAlignment m_iAlignment; FDE_TextStyle m_Styles; - int32_t m_iTxtBkAlignment; std::vector m_CharWidths; - wchar_t m_wParagraphBkChar; FX_ARGB m_TxtColor; uint32_t m_dwTxtBkStyles; CFX_WideString m_wsText; - CFX_RectF m_rtClip; - CFX_RectF m_rtLogicClip; CFX_Matrix m_Matrix; std::deque m_ttoLines; int32_t m_iCurLine; int32_t m_iCurPiece; int32_t m_iTotalLines; std::vector m_CharPos; - // NOTE: m_pDefaultRenderDevice must outlive m_pRenderDevice. - std::unique_ptr m_pDefaultRenderDevice; std::unique_ptr m_pRenderDevice; - std::vector m_rectArray; }; #endif // XFA_FDE_CFDE_TEXTOUT_H_ -- cgit v1.2.3