diff options
author | dsinclair <dsinclair@chromium.org> | 2016-04-21 11:06:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-21 11:06:27 -0700 |
commit | acd0d59e3c09f04bffd178aecd3638d3e189faba (patch) | |
tree | 39e30a37353f74aeb775834967eb86779c0bbdcd /xfa/fde/tto/fde_textout.cpp | |
parent | 4f70b53efb39e9b9b868d99999582282be57fe50 (diff) | |
download | pdfium-acd0d59e3c09f04bffd178aecd3638d3e189faba.tar.xz |
Cleanup FDE interfaces.
This CL removes IFDE_TextOut, IFDE_Path, IFDE_RenderContext, IFDE_RenderDevice,
and IFDE_VisualSetIterator in favour of the concrete classes.
BUG=pdfium:468
Review URL: https://codereview.chromium.org/1896893003
Diffstat (limited to 'xfa/fde/tto/fde_textout.cpp')
-rw-r--r-- | xfa/fde/tto/fde_textout.cpp | 215 |
1 files changed, 27 insertions, 188 deletions
diff --git a/xfa/fde/tto/fde_textout.cpp b/xfa/fde/tto/fde_textout.cpp index 7895b785f3..a18fbbd0ae 100644 --- a/xfa/fde/tto/fde_textout.cpp +++ b/xfa/fde/tto/fde_textout.cpp @@ -10,180 +10,13 @@ #include "core/fxcrt/include/fx_coordinates.h" #include "core/fxcrt/include/fx_system.h" +#include "xfa/fde/cfde_path.h" +#include "xfa/fde/fde_gedevice.h" #include "xfa/fde/fde_object.h" -#include "xfa/fde/fde_renderdevice.h" #include "xfa/fgas/crt/fgas_memory.h" #include "xfa/fgas/crt/fgas_utils.h" #include "xfa/fgas/layout/fgas_textbreak.h" -namespace { - -struct FDE_TTOPIECE { - public: - int32_t iStartChar; - int32_t iChars; - uint32_t dwCharStyles; - CFX_RectF rtPiece; -}; -typedef FDE_TTOPIECE* FDE_LPTTOPIECE; -typedef CFX_MassArrayTemplate<FDE_TTOPIECE> CFDE_TTOPieceArray; - -class CFDE_TTOLine : public CFX_Target { - public: - CFDE_TTOLine(); - CFDE_TTOLine(const CFDE_TTOLine& ttoLine); - ~CFDE_TTOLine(); - int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece); - int32_t GetSize() const; - FDE_LPTTOPIECE GetPtrAt(int32_t index); - void RemoveLast(int32_t iCount); - void RemoveAll(FX_BOOL bLeaveMemory); - FX_BOOL m_bNewReload; - CFDE_TTOPieceArray m_pieces; - - protected: - int32_t m_iPieceCount; -}; -typedef CFX_ObjectMassArrayTemplate<CFDE_TTOLine> CFDE_TTOLineArray; - -class CFDE_TextOut : public IFDE_TextOut, public CFX_Target { - public: - CFDE_TextOut(); - ~CFDE_TextOut(); - virtual void Release() { delete this; } - virtual void SetFont(IFX_Font* pFont); - virtual void SetFontSize(FX_FLOAT fFontSize); - virtual void SetTextColor(FX_ARGB color); - virtual void SetStyles(uint32_t dwStyles); - virtual void SetTabWidth(FX_FLOAT fTabWidth); - virtual void SetEllipsisString(const CFX_WideString& wsEllipsis); - virtual void SetParagraphBreakChar(FX_WCHAR wch); - virtual void SetAlignment(int32_t iAlignment); - virtual void SetLineSpace(FX_FLOAT fLineSpace); - virtual void SetDIBitmap(CFX_DIBitmap* pDIB); - virtual void SetRenderDevice(CFX_RenderDevice* pDevice); - virtual void SetClipRect(const CFX_Rect& rtClip); - virtual void SetClipRect(const CFX_RectF& rtClip); - virtual void SetMatrix(const CFX_Matrix& matrix); - virtual void SetLineBreakTolerance(FX_FLOAT fTolerance); - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_Size& size); - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_SizeF& size); - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_Rect& rect); - virtual void CalcSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_RectF& rect); - - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - int32_t x, - int32_t y); - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - FX_FLOAT x, - FX_FLOAT y); - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_Rect& rect); - virtual void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_RectF& rect); - - virtual void SetLogicClipRect(const CFX_RectF& rtClip); - virtual void CalcLogicSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_SizeF& size); - virtual void CalcLogicSize(const FX_WCHAR* pwsStr, - int32_t iLength, - CFX_RectF& rect); - virtual void DrawLogicText(const FX_WCHAR* pwsStr, - int32_t iLength, - FX_FLOAT x, - FX_FLOAT y); - virtual void DrawLogicText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_RectF& rect); - virtual int32_t GetTotalLines(); - - protected: - void CalcTextSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect); - FX_BOOL RetrieveLineWidth(uint32_t dwBreakStatus, - FX_FLOAT& fStartPos, - FX_FLOAT& fWidth, - FX_FLOAT& fHeight); - void SetLineWidth(CFX_RectF& rect); - void DrawText(const FX_WCHAR* pwsStr, - int32_t iLength, - const CFX_RectF& rect, - const CFX_RectF& rtClip); - void LoadText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_RectF& rect); - void LoadEllipsis(); - void ExpandBuffer(int32_t iSize, int32_t iType); - void RetrieveEllPieces(int32_t*& pCharWidths); - - void Reload(const CFX_RectF& rect); - void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect); - FX_BOOL RetriecePieces(uint32_t dwBreakStatus, - int32_t& iStartChar, - int32_t& iPieceWidths, - FX_BOOL bReload, - const CFX_RectF& rect); - void AppendPiece(const FDE_TTOPIECE& ttoPiece, - FX_BOOL bNeedReload, - FX_BOOL bEnd); - void ReplaceWidthEllipsis(); - void DoAlignment(const CFX_RectF& rect); - void OnDraw(const CFX_RectF& rtClip); - int32_t GetDisplayPos(FDE_LPTTOPIECE pPiece); - int32_t GetCharRects(FDE_LPTTOPIECE pPiece); - - FX_TXTRUN ToTextRun(const FDE_LPTTOPIECE pPiece); - void DrawLine(const FDE_LPTTOPIECE pPiece, CFDE_Pen*& pPen); - - CFX_TxtBreak* m_pTxtBreak; - IFX_Font* m_pFont; - FX_FLOAT m_fFontSize; - FX_FLOAT m_fLineSpace; - FX_FLOAT m_fLinePos; - FX_FLOAT m_fTolerance; - int32_t m_iAlignment; - int32_t m_iTxtBkAlignment; - int32_t* m_pCharWidths; - int32_t m_iChars; - int32_t* m_pEllCharWidths; - int32_t m_iEllChars; - FX_WCHAR m_wParagraphBkChar; - FX_ARGB m_TxtColor; - uint32_t m_dwStyles; - uint32_t m_dwTxtBkStyles; - CFX_WideString m_wsEllipsis; - FX_BOOL m_bElliChanged; - int32_t m_iEllipsisWidth; - CFX_WideString m_wsText; - CFX_RectF m_rtClip; - CFX_RectF m_rtLogicClip; - CFX_Matrix m_Matrix; - CFDE_TTOLineArray m_ttoLines; - int32_t m_iCurLine; - int32_t m_iCurPiece; - int32_t m_iTotalLines; - FXTEXT_CHARPOS* m_pCharPos; - int32_t m_iCharPosSize; - IFDE_RenderDevice* m_pRenderDevice; - CFX_Int32Array m_hotKeys; - CFX_RectFArray m_rectArray; -}; - -} // namespace - -IFDE_TextOut* IFDE_TextOut::Create() { - return new CFDE_TextOut; -} CFDE_TextOut::CFDE_TextOut() : m_pFont(NULL), m_fFontSize(12.0f), @@ -299,19 +132,25 @@ void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) { m_fLineSpace = fLineSpace; } void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { - FXSYS_assert(pDIB != NULL); - if (m_pRenderDevice != NULL) { + FXSYS_assert(pDIB); + + if (m_pRenderDevice) m_pRenderDevice->Release(); - } - m_pRenderDevice = IFDE_RenderDevice::Create(pDIB); + + CFX_FxgeDevice* device = new CFX_FxgeDevice; + device->Attach(pDIB, 0, FALSE); + m_pRenderDevice = new CFDE_RenderDevice(device, FALSE); } + void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { - FXSYS_assert(pDevice != NULL); - if (m_pRenderDevice != NULL) { + FXSYS_assert(pDevice); + + if (m_pRenderDevice) m_pRenderDevice->Release(); - } - m_pRenderDevice = IFDE_RenderDevice::Create(pDevice); + + m_pRenderDevice = new CFDE_RenderDevice(pDevice, FALSE); } + void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); @@ -834,7 +673,7 @@ void CFDE_TextOut::ReplaceWidthEllipsis() { int32_t iCharCount = 0; int32_t iPiece = pLine->GetSize(); while (iPiece-- > 0) { - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(iPiece); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(iPiece); if (pPiece == NULL) { break; } @@ -876,7 +715,7 @@ void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { const FX_WCHAR* pwsStr = m_wsText.c_str(); FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); int32_t iPieceWidths = 0; - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(0); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); int32_t iStartChar = pPiece->iStartChar; m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; int32_t iPieceCount = pLine->GetSize(); @@ -911,7 +750,7 @@ void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { return; } CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(iLines - 1); - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(0); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); if (pPiece == NULL) { return; } @@ -931,7 +770,7 @@ void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); int32_t iPieces = pLine->GetSize(); for (int32_t j = 0; j < iPieces; j++) { - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(j); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); if (bVertical) { pPiece->rtPiece.left += fInc; } else { @@ -959,7 +798,7 @@ void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); int32_t iPieces = pLine->GetSize(); for (int32_t j = 0; j < iPieces; j++) { - FDE_LPTTOPIECE pPiece = pLine->GetPtrAt(j); + FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); if (pPiece == NULL) { continue; } @@ -976,19 +815,19 @@ void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { delete pPen; } -int32_t CFDE_TextOut::GetDisplayPos(FDE_LPTTOPIECE pPiece) { +int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { FX_TXTRUN tr = ToTextRun(pPiece); ExpandBuffer(tr.iLength, 2); return m_pTxtBreak->GetDisplayPos(&tr, m_pCharPos); } -int32_t CFDE_TextOut::GetCharRects(FDE_LPTTOPIECE pPiece) { +int32_t CFDE_TextOut::GetCharRects(const FDE_TTOPIECE* pPiece) { FX_TXTRUN tr = ToTextRun(pPiece); m_rectArray.RemoveAll(); return m_pTxtBreak->GetCharRects(&tr, m_rectArray); } -FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_LPTTOPIECE pPiece) { +FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { FX_TXTRUN tr; tr.wsStr = m_wsText + pPiece->iStartChar; tr.pWidths = m_pCharWidths + pPiece->iStartChar; @@ -1002,7 +841,7 @@ FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_LPTTOPIECE pPiece) { return tr; } -void CFDE_TextOut::DrawLine(const FDE_LPTTOPIECE pPiece, CFDE_Pen*& pPen) { +void CFDE_TextOut::DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen*& pPen) { FX_BOOL bUnderLine = !!(m_dwStyles & FDE_TTOSTYLE_Underline); FX_BOOL bStrikeOut = !!(m_dwStyles & FDE_TTOSTYLE_Strikeout); FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); @@ -1014,7 +853,7 @@ void CFDE_TextOut::DrawLine(const FDE_LPTTOPIECE pPiece, CFDE_Pen*& pPen) { pPen = new CFDE_Pen; pPen->SetColor(m_TxtColor); } - IFDE_Path* pPath = IFDE_Path::Create(); + CFDE_Path* pPath = new CFDE_Path; int32_t iLineCount = 0; CFX_RectF rtText = pPiece->rtPiece; CFX_PointF pt1, pt2; @@ -1100,7 +939,7 @@ int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { int32_t CFDE_TTOLine::GetSize() const { return m_iPieceCount; } -FDE_LPTTOPIECE CFDE_TTOLine::GetPtrAt(int32_t index) { +FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) { if (index >= m_iPieceCount) { return NULL; } |