diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-08-14 15:03:20 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-14 19:57:00 +0000 |
commit | 2d03e604b3979db45f6f2ea8c00c8d7fe0790790 (patch) | |
tree | ca8dd7b7115e66b5e72c1367cb5ddb6923b9dc7c /xfa/fde/cfde_rendercontext.cpp | |
parent | c068c8e1ac5d41ace2a89827601669e8b573ef48 (diff) | |
download | pdfium-2d03e604b3979db45f6f2ea8c00c8d7fe0790790.tar.xz |
Cleaning up the visual set iterator
This CL starts cleaning up the visual set iterator code.
Change-Id: I643dc9edeeb0c7ff06ccd34a1977f811675413d8
Reviewed-on: https://pdfium-review.googlesource.com/10615
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde/cfde_rendercontext.cpp')
-rw-r--r-- | xfa/fde/cfde_rendercontext.cpp | 86 |
1 files changed, 31 insertions, 55 deletions
diff --git a/xfa/fde/cfde_rendercontext.cpp b/xfa/fde/cfde_rendercontext.cpp index 284de5daa2..0b44cb4a27 100644 --- a/xfa/fde/cfde_rendercontext.cpp +++ b/xfa/fde/cfde_rendercontext.cpp @@ -6,80 +6,56 @@ #include "xfa/fde/cfde_rendercontext.h" +#include <vector> + #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() - : m_pRenderDevice(nullptr), m_Transform() { - m_Transform.SetIdentity(); -} +CFDE_RenderContext::CFDE_RenderContext(CFDE_RenderDevice* pRenderDevice) + : m_pRenderDevice(pRenderDevice) {} CFDE_RenderContext::~CFDE_RenderContext() {} -void CFDE_RenderContext::StartRender(CFDE_RenderDevice* pRenderDevice, - CFDE_TxtEdtPage* pCanvasSet, - const CFX_Matrix& tmDoc2Device) { - if (m_pRenderDevice || !pRenderDevice || !pCanvasSet) +void CFDE_RenderContext::Render(CFDE_TxtEdtPage* pCanvasSet, + const CFX_Matrix& tmDoc2Device) { + if (!m_pRenderDevice || !pCanvasSet) return; - m_pRenderDevice = pRenderDevice; - m_Transform = tmDoc2Device; - if (!m_pIterator) - m_pIterator = pdfium::MakeUnique<CFDE_VisualSetIterator>(); - if (m_pIterator->AttachCanvas(pCanvasSet)) - m_pIterator->FilterObjects(); -} + CFDE_TxtEdtTextSet* pVisualSet = pCanvasSet->GetTextSet(); + if (!pVisualSet) + return; -void CFDE_RenderContext::DoRender() { - if (!m_pRenderDevice || !m_pIterator) + CFX_RetainPtr<CFGAS_GEFont> pFont = pVisualSet->GetFont(); + if (!pFont) return; CFX_RectF rtDocClip = m_pRenderDevice->GetClipRect(); if (rtDocClip.IsEmpty()) { rtDocClip.left = rtDocClip.top = 0; - rtDocClip.width = (float)m_pRenderDevice->GetWidth(); - rtDocClip.height = (float)m_pRenderDevice->GetHeight(); + rtDocClip.width = static_cast<float>(m_pRenderDevice->GetWidth()); + rtDocClip.height = static_cast<float>(m_pRenderDevice->GetHeight()); } - m_Transform.GetInverse().TransformRect(rtDocClip); - IFDE_VisualSet* pVisualSet; - FDE_TEXTEDITPIECE* pPiece; - int32_t iCount = 0; - while (true) { - pPiece = m_pIterator->GetNext(pVisualSet); - if (!pPiece || !pVisualSet) - return; - if (!rtDocClip.IntersectWith(pVisualSet->GetRect(*pPiece))) - continue; + tmDoc2Device.GetInverse().TransformRect(rtDocClip); - switch (pVisualSet->GetType()) { - case FDE_VISUALOBJ_Text: - RenderText(static_cast<CFDE_TxtEdtTextSet*>(pVisualSet), pPiece); - iCount += 5; - break; - default: - break; - } - } -} + std::vector<FXTEXT_CHARPOS> char_pos; -void CFDE_RenderContext::RenderText(CFDE_TxtEdtTextSet* pTextSet, - FDE_TEXTEDITPIECE* pText) { - ASSERT(m_pRenderDevice); - ASSERT(pTextSet && pText); - - CFX_RetainPtr<CFGAS_GEFont> pFont = pTextSet->GetFont(); - if (!pFont) - return; + 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 = pTextSet->GetDisplayPos(*pText, nullptr, false); - if (iCount < 1) - return; - if (m_CharPos.size() < static_cast<size_t>(iCount)) - m_CharPos.resize(iCount, FXTEXT_CHARPOS()); + int32_t iCount = pVisualSet->GetDisplayPos(pText, nullptr, false); + if (iCount < 1) + continue; + if (char_pos.size() < static_cast<size_t>(iCount)) + char_pos.resize(iCount, FXTEXT_CHARPOS()); - iCount = pTextSet->GetDisplayPos(*pText, m_CharPos.data(), false); - m_pRenderDevice->DrawString(pTextSet->GetFontColor(), pFont, m_CharPos.data(), - iCount, pTextSet->GetFontSize(), &m_Transform); + iCount = pVisualSet->GetDisplayPos(pText, char_pos.data(), false); + m_pRenderDevice->DrawString(pVisualSet->GetFontColor(), pFont, + char_pos.data(), iCount, + pVisualSet->GetFontSize(), &tmDoc2Device); + } } |