From 2d883813f969dcb88e240b6bd7bcd5af9e782331 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 14 Aug 2017 15:49:46 -0400 Subject: Merge CFDE_RenderContext into CFWL_Edit This CL removes CFDE_RenderContext and moves the ::Render method to be ::RenderText on the CFWL_Edit class which was the only caller. Change-Id: Ic940a3f0d10cfce169f5e491de90803fc8a7940d Reviewed-on: https://pdfium-review.googlesource.com/10950 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- BUILD.gn | 2 -- xfa/fde/cfde_rendercontext.cpp | 61 ------------------------------------------ xfa/fde/cfde_rendercontext.h | 27 ------------------- xfa/fwl/cfwl_edit.cpp | 52 ++++++++++++++++++++++++++++++----- xfa/fwl/cfwl_edit.h | 4 +++ xfa/fxfa/cxfa_ffpageview.cpp | 1 - 6 files changed, 50 insertions(+), 97 deletions(-) delete mode 100644 xfa/fde/cfde_rendercontext.cpp delete mode 100644 xfa/fde/cfde_rendercontext.h diff --git a/BUILD.gn b/BUILD.gn index 9c23428c3e..93196a491a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1457,8 +1457,6 @@ if (pdf_enable_xfa) { static_library("xfa") { sources = [ - "xfa/fde/cfde_rendercontext.cpp", - "xfa/fde/cfde_rendercontext.h", "xfa/fde/cfde_renderdevice.cpp", "xfa/fde/cfde_textout.cpp", "xfa/fde/cfde_textout.h", diff --git a/xfa/fde/cfde_rendercontext.cpp b/xfa/fde/cfde_rendercontext.cpp deleted file mode 100644 index 0b44cb4a27..0000000000 --- a/xfa/fde/cfde_rendercontext.cpp +++ /dev/null @@ -1,61 +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_rendercontext.h" - -#include - -#include "third_party/base/logging.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fde/cfde_renderdevice.h" -#include "xfa/fde/cfde_txtedtpage.h" -#include "xfa/fde/cfde_txtedttextset.h" - -CFDE_RenderContext::CFDE_RenderContext(CFDE_RenderDevice* pRenderDevice) - : m_pRenderDevice(pRenderDevice) {} - -CFDE_RenderContext::~CFDE_RenderContext() {} - -void CFDE_RenderContext::Render(CFDE_TxtEdtPage* pCanvasSet, - const CFX_Matrix& tmDoc2Device) { - if (!m_pRenderDevice || !pCanvasSet) - return; - - CFDE_TxtEdtTextSet* pVisualSet = pCanvasSet->GetTextSet(); - if (!pVisualSet) - return; - - CFX_RetainPtr pFont = pVisualSet->GetFont(); - if (!pFont) - return; - - CFX_RectF rtDocClip = m_pRenderDevice->GetClipRect(); - if (rtDocClip.IsEmpty()) { - rtDocClip.left = rtDocClip.top = 0; - rtDocClip.width = static_cast(m_pRenderDevice->GetWidth()); - rtDocClip.height = static_cast(m_pRenderDevice->GetHeight()); - } - tmDoc2Device.GetInverse().TransformRect(rtDocClip); - - std::vector char_pos; - - for (size_t i = 0; i < pCanvasSet->GetTextPieceCount(); ++i) { - const FDE_TEXTEDITPIECE& pText = pCanvasSet->GetTextPiece(i); - if (!rtDocClip.IntersectWith(pVisualSet->GetRect(pText))) - continue; - - int32_t iCount = pVisualSet->GetDisplayPos(pText, nullptr, false); - if (iCount < 1) - continue; - if (char_pos.size() < static_cast(iCount)) - char_pos.resize(iCount, FXTEXT_CHARPOS()); - - iCount = pVisualSet->GetDisplayPos(pText, char_pos.data(), false); - m_pRenderDevice->DrawString(pVisualSet->GetFontColor(), pFont, - char_pos.data(), iCount, - pVisualSet->GetFontSize(), &tmDoc2Device); - } -} diff --git a/xfa/fde/cfde_rendercontext.h b/xfa/fde/cfde_rendercontext.h deleted file mode 100644 index 6be77c6453..0000000000 --- a/xfa/fde/cfde_rendercontext.h +++ /dev/null @@ -1,27 +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_RENDERCONTEXT_H_ -#define XFA_FDE_CFDE_RENDERCONTEXT_H_ - -#include "core/fxcrt/fx_coordinates.h" - -class CFDE_RenderDevice; -class CFDE_TxtEdtPage; -class CFDE_TxtEdtTextSet; - -class CFDE_RenderContext { - public: - explicit CFDE_RenderContext(CFDE_RenderDevice* pRenderDevice); - ~CFDE_RenderContext(); - - void Render(CFDE_TxtEdtPage* pCanvasSet, const CFX_Matrix& tmDoc2Device); - - private: - CFDE_RenderDevice* m_pRenderDevice; -}; - -#endif // XFA_FDE_CFDE_RENDERCONTEXT_H_ diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp index fe4b9dad0c..042e076ab6 100644 --- a/xfa/fwl/cfwl_edit.cpp +++ b/xfa/fwl/cfwl_edit.cpp @@ -13,10 +13,10 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/cfde_rendercontext.h" #include "xfa/fde/cfde_renderdevice.h" #include "xfa/fde/cfde_txtedtengine.h" #include "xfa/fde/cfde_txtedtpage.h" +#include "xfa/fde/cfde_txtedttextset.h" #include "xfa/fgas/font/cfgas_gefont.h" #include "xfa/fwl/cfwl_app.h" #include "xfa/fwl/cfwl_caret.h" @@ -567,11 +567,7 @@ void CFWL_Edit::DrawContent(CXFA_Graphics* pGraphics, if (!pRenderDev) return; - CFDE_RenderDevice renderDevice(pRenderDev); - renderDevice.SetClipRect(rtClip); - - CFDE_RenderContext renderContext(&renderDevice); - renderContext.Render(pPage, mt); + RenderText(pRenderDev, rtClip, *pPage, mt); if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) { pGraphics->RestoreGraphState(); @@ -596,6 +592,50 @@ void CFWL_Edit::DrawContent(CXFA_Graphics* pGraphics, pGraphics->RestoreGraphState(); } +void CFWL_Edit::RenderText(CFX_RenderDevice* pRenderDev, + const CFX_RectF& clipRect, + const CFDE_TxtEdtPage& pPage, + const CFX_Matrix& mt) { + ASSERT(pRenderDev); + + CFDE_TxtEdtTextSet* pTextSet = pPage.GetTextSet(); + if (!pTextSet) + return; + + CFX_RetainPtr pFont = pTextSet->GetFont(); + if (!pFont) + return; + + CFDE_RenderDevice renderDevice(pRenderDev); + renderDevice.SetClipRect(clipRect); + + CFX_RectF rtDocClip = renderDevice.GetClipRect(); + if (rtDocClip.IsEmpty()) { + rtDocClip.left = rtDocClip.top = 0; + rtDocClip.width = static_cast(renderDevice.GetWidth()); + rtDocClip.height = static_cast(renderDevice.GetHeight()); + } + mt.GetInverse().TransformRect(rtDocClip); + + std::vector char_pos; + + for (size_t i = 0; i < pPage.GetTextPieceCount(); ++i) { + const FDE_TEXTEDITPIECE& pText = pPage.GetTextPiece(i); + if (!rtDocClip.IntersectWith(pTextSet->GetRect(pText))) + continue; + + int32_t iCount = pTextSet->GetDisplayPos(pText, nullptr, false); + if (iCount < 1) + continue; + if (char_pos.size() < static_cast(iCount)) + char_pos.resize(iCount, FXTEXT_CHARPOS()); + + iCount = pTextSet->GetDisplayPos(pText, char_pos.data(), false); + renderDevice.DrawString(pTextSet->GetFontColor(), pFont, char_pos.data(), + iCount, pTextSet->GetFontSize(), &mt); + } +} + void CFWL_Edit::UpdateEditEngine() { UpdateEditParams(); UpdateEditLayout(); diff --git a/xfa/fwl/cfwl_edit.h b/xfa/fwl/cfwl_edit.h index 15d20bf7cb..dd165032a3 100644 --- a/xfa/fwl/cfwl_edit.h +++ b/xfa/fwl/cfwl_edit.h @@ -109,6 +109,10 @@ class CFWL_Edit : public CFWL_Widget { CFDE_TxtEdtEngine* GetTxtEdtEngine() { return &m_EdtEngine; } private: + void RenderText(CFX_RenderDevice* pRenderDev, + const CFX_RectF& clipRect, + const CFDE_TxtEdtPage& pPage, + const CFX_Matrix& mt); void DrawTextBk(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix); diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp index 9ba4432352..594d71db0d 100644 --- a/xfa/fxfa/cxfa_ffpageview.cpp +++ b/xfa/fxfa/cxfa_ffpageview.cpp @@ -12,7 +12,6 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/cfde_rendercontext.h" #include "xfa/fxfa/cxfa_ffcheckbutton.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" -- cgit v1.2.3