diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-08-14 17:23:25 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-15 13:42:32 +0000 |
commit | 73b492a5d775c05d8c186c8478d1003edfffd34c (patch) | |
tree | 0815bab5627ae27f5eb2f1a45b90bb9dc10b9e1c /xfa/fde | |
parent | 5f0e64435c97755a7d309e80ea0a4dad83e76e73 (diff) | |
download | pdfium-73b492a5d775c05d8c186c8478d1003edfffd34c.tar.xz |
Remove CFDE_RenderDevice
This CL removes CFDE_RenderDevice. For most of the proxy'd calls we call
the CFX_RenderDevice directly now. To set the clip rect an overload was
added to accept a CFX_RectF and handle the casting to FX_RECT. The one
needed method, DrawString, is move to a static on CFDE_TextOut.
Change-Id: I95ea7e1fa1fd4702074b797c06423c9c9cb51db9
Reviewed-on: https://pdfium-review.googlesource.com/10951
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde')
-rw-r--r-- | xfa/fde/cfde_renderdevice.cpp | 159 | ||||
-rw-r--r-- | xfa/fde/cfde_renderdevice.h | 48 | ||||
-rw-r--r-- | xfa/fde/cfde_textout.cpp | 105 | ||||
-rw-r--r-- | xfa/fde/cfde_textout.h | 13 |
4 files changed, 102 insertions, 223 deletions
diff --git a/xfa/fde/cfde_renderdevice.cpp b/xfa/fde/cfde_renderdevice.cpp deleted file mode 100644 index e9457f4c5e..0000000000 --- a/xfa/fde/cfde_renderdevice.cpp +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fde/cfde_renderdevice.h" - -#include <algorithm> -#include <memory> -#include <utility> - -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "core/fxge/cfx_substfont.h" -#include "core/fxge/dib/cfx_imagerenderer.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fgas/font/cfgas_fontmgr.h" -#include "xfa/fgas/font/cfgas_gefont.h" - -CFDE_RenderDevice::CFDE_RenderDevice(CFX_RenderDevice* pDevice) - : m_pDevice(pDevice) { - ASSERT(pDevice); - - FX_RECT rt = m_pDevice->GetClipBox(); - m_rtClip = CFX_RectF(static_cast<float>(rt.left), static_cast<float>(rt.top), - static_cast<float>(rt.Width()), - static_cast<float>(rt.Height())); -} - -CFDE_RenderDevice::~CFDE_RenderDevice() {} - -int32_t CFDE_RenderDevice::GetWidth() const { - return m_pDevice->GetWidth(); -} - -int32_t CFDE_RenderDevice::GetHeight() const { - return m_pDevice->GetHeight(); -} - -void CFDE_RenderDevice::SaveState() { - m_pDevice->SaveState(); -} - -void CFDE_RenderDevice::RestoreState() { - m_pDevice->RestoreState(false); - const FX_RECT& rt = m_pDevice->GetClipBox(); - m_rtClip = CFX_RectF(static_cast<float>(rt.left), static_cast<float>(rt.top), - static_cast<float>(rt.Width()), - static_cast<float>(rt.Height())); -} - -bool CFDE_RenderDevice::SetClipRect(const CFX_RectF& rtClip) { - m_rtClip = rtClip; - return m_pDevice->SetClip_Rect( - FX_RECT((int32_t)floor(rtClip.left), (int32_t)floor(rtClip.top), - (int32_t)ceil(rtClip.right()), (int32_t)ceil(rtClip.bottom()))); -} - -const CFX_RectF& CFDE_RenderDevice::GetClipRect() { - return m_rtClip; -} - -bool CFDE_RenderDevice::DrawString(FX_ARGB color, - const CFX_RetainPtr<CFGAS_GEFont>& pFont, - const FXTEXT_CHARPOS* pCharPos, - int32_t iCount, - float fFontSize, - const CFX_Matrix* pMatrix) { - ASSERT(pFont && pCharPos && iCount > 0); - CFX_Font* pFxFont = pFont->GetDevFont(); - if ((pFont->GetFontStyles() & FX_FONTSTYLE_Italic) != 0 && - !pFxFont->IsItalic()) { - FXTEXT_CHARPOS* pCP = (FXTEXT_CHARPOS*)pCharPos; - float* pAM; - for (int32_t i = 0; i < iCount; ++i) { - static const float mc = 0.267949f; - pAM = pCP->m_AdjustMatrix; - pAM[2] = mc * pAM[0] + pAM[2]; - pAM[3] = mc * pAM[1] + pAM[3]; - pCP++; - } - } - FXTEXT_CHARPOS* pCP = (FXTEXT_CHARPOS*)pCharPos; - CFX_RetainPtr<CFGAS_GEFont> pCurFont; - CFX_RetainPtr<CFGAS_GEFont> pSTFont; - FXTEXT_CHARPOS* pCurCP = nullptr; - int32_t iCurCount = 0; - -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - uint32_t dwFontStyle = pFont->GetFontStyles(); - CFX_Font FxFont; - auto SubstFxFont = pdfium::MakeUnique<CFX_SubstFont>(); - SubstFxFont->m_Weight = dwFontStyle & FX_FONTSTYLE_Bold ? 700 : 400; - SubstFxFont->m_ItalicAngle = dwFontStyle & FX_FONTSTYLE_Italic ? -12 : 0; - SubstFxFont->m_WeightCJK = SubstFxFont->m_Weight; - SubstFxFont->m_bItalicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); - FxFont.SetSubstFont(std::move(SubstFxFont)); -#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - - for (int32_t i = 0; i < iCount; ++i) { - pSTFont = pFont->GetSubstFont((int32_t)pCP->m_GlyphIndex); - pCP->m_GlyphIndex &= 0x00FFFFFF; - pCP->m_bFontStyle = false; - if (pCurFont != pSTFont) { - if (pCurFont) { - pFxFont = pCurFont->GetDevFont(); -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - FxFont.SetFace(pFxFont->GetFace()); - m_pDevice->DrawNormalText(iCurCount, pCurCP, &FxFont, -fFontSize, - pMatrix, color, FXTEXT_CLEARTYPE); -#else - m_pDevice->DrawNormalText(iCurCount, pCurCP, pFxFont, -fFontSize, - pMatrix, color, FXTEXT_CLEARTYPE); -#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - } - pCurFont = pSTFont; - pCurCP = pCP; - iCurCount = 1; - } else { - iCurCount++; - } - pCP++; - } - if (pCurFont && iCurCount) { - pFxFont = pCurFont->GetDevFont(); -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - FxFont.SetFace(pFxFont->GetFace()); - bool bRet = - m_pDevice->DrawNormalText(iCurCount, pCurCP, &FxFont, -fFontSize, - pMatrix, color, FXTEXT_CLEARTYPE); - FxFont.SetFace(nullptr); - return bRet; -#else - return m_pDevice->DrawNormalText(iCurCount, pCurCP, pFxFont, -fFontSize, - pMatrix, color, FXTEXT_CLEARTYPE); -#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - } - -#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - FxFont.SetFace(nullptr); -#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ - - return true; -} - -bool CFDE_RenderDevice::DrawPath(FX_ARGB color, - float fPenWidth, - const CFX_PathData& pPath, - const CFX_Matrix* pMatrix) { - CFX_GraphStateData graphState; - graphState.m_LineCap = CFX_GraphStateData::LineCapButt; - graphState.m_LineJoin = CFX_GraphStateData::LineJoinMiter; - graphState.m_LineWidth = fPenWidth; - graphState.m_MiterLimit = 10; - graphState.m_DashPhase = 0; - return m_pDevice->DrawPath(&pPath, pMatrix, &graphState, 0, color, 0); -} diff --git a/xfa/fde/cfde_renderdevice.h b/xfa/fde/cfde_renderdevice.h deleted file mode 100644 index ccc2ef281e..0000000000 --- a/xfa/fde/cfde_renderdevice.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FDE_CFDE_RENDERDEVICE_H_ -#define XFA_FDE_CFDE_RENDERDEVICE_H_ - -#include <vector> - -#include "core/fxge/cfx_renderdevice.h" -#include "xfa/fgas/font/cfgas_gefont.h" - -class CFX_PathData; -class CFX_GraphStateData; - -class CFDE_RenderDevice { - public: - explicit CFDE_RenderDevice(CFX_RenderDevice* pDevice); - ~CFDE_RenderDevice(); - - int32_t GetWidth() const; - int32_t GetHeight() const; - - void SaveState(); - void RestoreState(); - - bool SetClipRect(const CFX_RectF& rtClip); - const CFX_RectF& GetClipRect(); - - bool DrawString(FX_ARGB color, - const CFX_RetainPtr<CFGAS_GEFont>& pFont, - const FXTEXT_CHARPOS* pCharPos, - int32_t iCount, - float fFontSize, - const CFX_Matrix* pMatrix); - bool DrawPath(FX_ARGB color, - float fPenWidth, - const CFX_PathData& pPath, - const CFX_Matrix* pMatrix); - - private: - CFX_RenderDevice* const m_pDevice; - CFX_RectF m_rtClip; -}; - -#endif // XFA_FDE_CFDE_RENDERDEVICE_H_ diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp index 5f7fe078f1..7a246a8efe 100644 --- a/xfa/fde/cfde_textout.cpp +++ b/xfa/fde/cfde_textout.cpp @@ -14,7 +14,6 @@ #include "core/fxge/cfx_pathdata.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/cfde_renderdevice.h" #include "xfa/fgas/layout/cfx_txtbreak.h" namespace { @@ -31,6 +30,90 @@ bool IsTextAlignmentTop(const FDE_TextAlignment align) { } // namespace +// static +bool CFDE_TextOut::DrawString(CFX_RenderDevice* device, + FX_ARGB color, + const CFX_RetainPtr<CFGAS_GEFont>& pFont, + const FXTEXT_CHARPOS* pCharPos, + int32_t iCount, + float fFontSize, + const CFX_Matrix* pMatrix) { + ASSERT(pFont && pCharPos && iCount > 0); + CFX_Font* pFxFont = pFont->GetDevFont(); + if ((pFont->GetFontStyles() & FX_FONTSTYLE_Italic) != 0 && + !pFxFont->IsItalic()) { + FXTEXT_CHARPOS* pCP = (FXTEXT_CHARPOS*)pCharPos; + float* pAM; + for (int32_t i = 0; i < iCount; ++i) { + static const float mc = 0.267949f; + pAM = pCP->m_AdjustMatrix; + pAM[2] = mc * pAM[0] + pAM[2]; + pAM[3] = mc * pAM[1] + pAM[3]; + pCP++; + } + } + FXTEXT_CHARPOS* pCP = (FXTEXT_CHARPOS*)pCharPos; + CFX_RetainPtr<CFGAS_GEFont> pCurFont; + CFX_RetainPtr<CFGAS_GEFont> pSTFont; + FXTEXT_CHARPOS* pCurCP = nullptr; + int32_t iCurCount = 0; + +#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + uint32_t dwFontStyle = pFont->GetFontStyles(); + CFX_Font FxFont; + auto SubstFxFont = pdfium::MakeUnique<CFX_SubstFont>(); + SubstFxFont->m_Weight = dwFontStyle & FX_FONTSTYLE_Bold ? 700 : 400; + SubstFxFont->m_ItalicAngle = dwFontStyle & FX_FONTSTYLE_Italic ? -12 : 0; + SubstFxFont->m_WeightCJK = SubstFxFont->m_Weight; + SubstFxFont->m_bItalicCJK = !!(dwFontStyle & FX_FONTSTYLE_Italic); + FxFont.SetSubstFont(std::move(SubstFxFont)); +#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + + for (int32_t i = 0; i < iCount; ++i) { + pSTFont = pFont->GetSubstFont((int32_t)pCP->m_GlyphIndex); + pCP->m_GlyphIndex &= 0x00FFFFFF; + pCP->m_bFontStyle = false; + if (pCurFont != pSTFont) { + if (pCurFont) { + pFxFont = pCurFont->GetDevFont(); +#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + FxFont.SetFace(pFxFont->GetFace()); + device->DrawNormalText(iCurCount, pCurCP, &FxFont, -fFontSize, pMatrix, + color, FXTEXT_CLEARTYPE); +#else + device->DrawNormalText(iCurCount, pCurCP, pFxFont, -fFontSize, pMatrix, + color, FXTEXT_CLEARTYPE); +#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + } + pCurFont = pSTFont; + pCurCP = pCP; + iCurCount = 1; + } else { + iCurCount++; + } + pCP++; + } + if (pCurFont && iCurCount) { + pFxFont = pCurFont->GetDevFont(); +#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + FxFont.SetFace(pFxFont->GetFace()); + bool bRet = device->DrawNormalText(iCurCount, pCurCP, &FxFont, -fFontSize, + pMatrix, color, FXTEXT_CLEARTYPE); + FxFont.SetFace(nullptr); + return bRet; +#else + return device->DrawNormalText(iCurCount, pCurCP, pFxFont, -fFontSize, + pMatrix, color, FXTEXT_CLEARTYPE); +#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + } + +#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + FxFont.SetFace(nullptr); +#endif // _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ + + return true; +} + FDE_TTOPIECE::FDE_TTOPIECE() = default; FDE_TTOPIECE::FDE_TTOPIECE(const FDE_TTOPIECE& that) = default; @@ -102,11 +185,6 @@ void CFDE_TextOut::SetLineSpace(float fLineSpace) { m_fLineSpace = fLineSpace; } -void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { - ASSERT(pDevice); - m_pRenderDevice = pdfium::MakeUnique<CFDE_RenderDevice>(pDevice); -} - void CFDE_TextOut::SetLineBreakTolerance(float fTolerance) { m_fTolerance = fTolerance; m_pTxtBreak->SetLineBreakTolerance(m_fTolerance); @@ -208,7 +286,8 @@ bool CFDE_TextOut::RetrieveLineWidth(CFX_BreakType dwBreakStatus, return true; } -void CFDE_TextOut::DrawLogicText(const wchar_t* pwsStr, +void CFDE_TextOut::DrawLogicText(CFX_RenderDevice* device, + const wchar_t* pwsStr, int32_t iLength, const CFX_RectF& rect) { ASSERT(m_pFont && m_fFontSize >= 1.0f); @@ -226,15 +305,15 @@ void CFDE_TextOut::DrawLogicText(const wchar_t* pwsStr, Reload(rect); DoAlignment(rect); - if (!m_pRenderDevice || m_ttoLines.empty()) + if (!device || m_ttoLines.empty()) return; CFX_RectF rtClip; m_Matrix.TransformRect(rtClip); - m_pRenderDevice->SaveState(); + device->SaveState(); if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) - m_pRenderDevice->SetClipRect(rtClip); + device->SetClip_Rect(rtClip); for (auto& line : m_ttoLines) { int32_t iPieces = line.GetSize(); @@ -245,12 +324,12 @@ void CFDE_TextOut::DrawLogicText(const wchar_t* pwsStr, int32_t iCount = GetDisplayPos(pPiece); if (iCount > 0) { - m_pRenderDevice->DrawString(m_TxtColor, m_pFont, m_CharPos.data(), - iCount, m_fFontSize, &m_Matrix); + CFDE_TextOut::DrawString(device, m_TxtColor, m_pFont, m_CharPos.data(), + iCount, m_fFontSize, &m_Matrix); } } } - m_pRenderDevice->RestoreState(); + device->RestoreState(false); } void CFDE_TextOut::LoadText(const wchar_t* pwsStr, diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h index f2541bb11b..421987c3fd 100644 --- a/xfa/fde/cfde_textout.h +++ b/xfa/fde/cfde_textout.h @@ -76,6 +76,14 @@ class CFDE_TTOLine { class CFDE_TextOut { public: + static bool DrawString(CFX_RenderDevice* device, + FX_ARGB color, + const CFX_RetainPtr<CFGAS_GEFont>& pFont, + const FXTEXT_CHARPOS* pCharPos, + int32_t iCount, + float fFontSize, + const CFX_Matrix* pMatrix); + CFDE_TextOut(); ~CFDE_TextOut(); @@ -85,13 +93,13 @@ class CFDE_TextOut { void SetStyles(const FDE_TextStyle& dwStyles); void SetAlignment(FDE_TextAlignment iAlignment); void SetLineSpace(float fLineSpace); - void SetRenderDevice(CFX_RenderDevice* pDevice); void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } void SetLineBreakTolerance(float fTolerance); 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, + void DrawLogicText(CFX_RenderDevice* device, + const wchar_t* pwsStr, int32_t iLength, const CFX_RectF& rect); int32_t GetTotalLines() const { return m_iTotalLines; } @@ -134,7 +142,6 @@ class CFDE_TextOut { int32_t m_iCurPiece; int32_t m_iTotalLines; std::vector<FXTEXT_CHARPOS> m_CharPos; - std::unique_ptr<CFDE_RenderDevice> m_pRenderDevice; }; #endif // XFA_FDE_CFDE_TEXTOUT_H_ |