| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fde/fde_render.h" | 7 #include "xfa/fde/fde_render.h" |
| 8 | 8 |
| 9 #include "xfa/fde/fde_object.h" | 9 #include "xfa/fde/fde_object.h" |
| 10 #include "xfa/fde/fde_renderdevice.h" | 10 #include "xfa/fde/fde_renderdevice.h" |
| 11 #include "xfa/fgas/crt/fgas_memory.h" | 11 #include "xfa/fgas/crt/fgas_memory.h" |
| 12 | 12 |
| 13 #define FDE_PATHRENDER_Stroke 1 | 13 #define FDE_PATHRENDER_Stroke 1 |
| 14 #define FDE_PATHRENDER_Fill 2 | 14 #define FDE_PATHRENDER_Fill 2 |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class CFDE_RenderContext : public IFDE_RenderContext, public CFX_Target { | 18 class CFDE_RenderContext : public IFDE_RenderContext, public CFX_Target { |
| 19 public: | 19 public: |
| 20 CFDE_RenderContext(); | 20 CFDE_RenderContext(); |
| 21 virtual ~CFDE_RenderContext(); | 21 virtual ~CFDE_RenderContext(); |
| 22 virtual void Release() { delete this; } | 22 virtual void Release() { delete this; } |
| 23 virtual FX_BOOL StartRender(IFDE_RenderDevice* pRenderDevice, | 23 virtual FX_BOOL StartRender(IFDE_RenderDevice* pRenderDevice, |
| 24 IFDE_CanvasSet* pCanvasSet, | 24 IFDE_CanvasSet* pCanvasSet, |
| 25 const CFX_Matrix& tmDoc2Device); | 25 const CFX_Matrix& tmDoc2Device); |
| 26 virtual FDE_RENDERSTATUS GetStatus() const { return m_eStatus; } | 26 virtual FDE_RENDERSTATUS GetStatus() const { return m_eStatus; } |
| 27 virtual FDE_RENDERSTATUS DoRender(IFX_Pause* pPause = nullptr); | 27 virtual FDE_RENDERSTATUS DoRender(IFX_Pause* pPause = nullptr); |
| 28 virtual void StopRender(); | 28 virtual void StopRender(); |
| 29 void RenderPath(IFDE_PathSet* pPathSet, FDE_HVISUALOBJ hPath); | |
| 30 void RenderText(IFDE_TextSet* pTextSet, FDE_HVISUALOBJ hText); | 29 void RenderText(IFDE_TextSet* pTextSet, FDE_HVISUALOBJ hText); |
| 31 FX_BOOL ApplyClip(IFDE_VisualSet* pVisualSet, | 30 FX_BOOL ApplyClip(IFDE_VisualSet* pVisualSet, |
| 32 FDE_HVISUALOBJ hObj, | 31 FDE_HVISUALOBJ hObj, |
| 33 FDE_HDEVICESTATE& hState); | 32 FDE_HDEVICESTATE& hState); |
| 34 void RestoreClip(FDE_HDEVICESTATE hState); | 33 void RestoreClip(FDE_HDEVICESTATE hState); |
| 35 | 34 |
| 36 protected: | 35 protected: |
| 37 FDE_RENDERSTATUS m_eStatus; | 36 FDE_RENDERSTATUS m_eStatus; |
| 38 IFDE_RenderDevice* m_pRenderDevice; | 37 IFDE_RenderDevice* m_pRenderDevice; |
| 39 CFDE_Brush* m_pBrush; | 38 CFDE_Brush* m_pBrush; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 rtObj.Empty(); | 161 rtObj.Empty(); |
| 163 pVisualSet->GetRect(hVisualObj, rtObj); | 162 pVisualSet->GetRect(hVisualObj, rtObj); |
| 164 if (!rtDocClip.IntersectWith(rtObj)) | 163 if (!rtDocClip.IntersectWith(rtObj)) |
| 165 continue; | 164 continue; |
| 166 | 165 |
| 167 switch (pVisualSet->GetType()) { | 166 switch (pVisualSet->GetType()) { |
| 168 case FDE_VISUALOBJ_Text: | 167 case FDE_VISUALOBJ_Text: |
| 169 RenderText((IFDE_TextSet*)pVisualSet, hVisualObj); | 168 RenderText((IFDE_TextSet*)pVisualSet, hVisualObj); |
| 170 iCount += 5; | 169 iCount += 5; |
| 171 break; | 170 break; |
| 172 case FDE_VISUALOBJ_Path: | |
| 173 RenderPath((IFDE_PathSet*)pVisualSet, hVisualObj); | |
| 174 iCount += 20; | |
| 175 break; | |
| 176 case FDE_VISUALOBJ_Widget: | |
| 177 iCount += 10; | |
| 178 break; | |
| 179 case FDE_VISUALOBJ_Canvas: | 171 case FDE_VISUALOBJ_Canvas: |
| 180 FXSYS_assert(FALSE); | 172 FXSYS_assert(FALSE); |
| 181 break; | 173 break; |
| 182 default: | 174 default: |
| 183 break; | 175 break; |
| 184 } | 176 } |
| 185 if (iCount >= 100 && pPause && pPause->NeedToPauseNow()) { | 177 if (iCount >= 100 && pPause && pPause->NeedToPauseNow()) { |
| 186 eStatus = FDE_RENDERSTATUS_Paused; | 178 eStatus = FDE_RENDERSTATUS_Paused; |
| 187 break; | 179 break; |
| 188 } | 180 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 FX_ARGB dwColor = pTextSet->GetFontColor(hText); | 228 FX_ARGB dwColor = pTextSet->GetFontColor(hText); |
| 237 m_pBrush->SetColor(dwColor); | 229 m_pBrush->SetColor(dwColor); |
| 238 FDE_HDEVICESTATE hState; | 230 FDE_HDEVICESTATE hState; |
| 239 FX_BOOL bClip = ApplyClip(pTextSet, hText, hState); | 231 FX_BOOL bClip = ApplyClip(pTextSet, hText, hState); |
| 240 m_pRenderDevice->DrawString(m_pBrush, pFont, m_pCharPos, iCount, fFontSize, | 232 m_pRenderDevice->DrawString(m_pBrush, pFont, m_pCharPos, iCount, fFontSize, |
| 241 &m_Transform); | 233 &m_Transform); |
| 242 if (bClip) | 234 if (bClip) |
| 243 RestoreClip(hState); | 235 RestoreClip(hState); |
| 244 } | 236 } |
| 245 | 237 |
| 246 void CFDE_RenderContext::RenderPath(IFDE_PathSet* pPathSet, | |
| 247 FDE_HVISUALOBJ hPath) { | |
| 248 FXSYS_assert(m_pRenderDevice); | |
| 249 FXSYS_assert(pPathSet && hPath); | |
| 250 | |
| 251 IFDE_Path* pPath = pPathSet->GetPath(hPath); | |
| 252 if (!pPath) | |
| 253 return; | |
| 254 | |
| 255 FDE_HDEVICESTATE hState; | |
| 256 FX_BOOL bClip = ApplyClip(pPathSet, hPath, hState); | |
| 257 int32_t iRenderMode = pPathSet->GetRenderMode(hPath); | |
| 258 if (iRenderMode & FDE_PATHRENDER_Stroke) { | |
| 259 CFDE_Pen* pPen = pPathSet->GetPen(hPath); | |
| 260 FX_FLOAT fWidth = pPathSet->GetPenWidth(hPath); | |
| 261 if (pPen && fWidth > 0) | |
| 262 m_pRenderDevice->DrawPath(pPen, fWidth, pPath, &m_Transform); | |
| 263 } | |
| 264 if (iRenderMode & FDE_PATHRENDER_Fill) { | |
| 265 CFDE_Brush* pBrush = pPathSet->GetBrush(hPath); | |
| 266 if (pBrush) | |
| 267 m_pRenderDevice->FillPath(pBrush, pPath, &m_Transform); | |
| 268 } | |
| 269 if (bClip) | |
| 270 RestoreClip(hState); | |
| 271 } | |
| 272 | |
| 273 FX_BOOL CFDE_RenderContext::ApplyClip(IFDE_VisualSet* pVisualSet, | 238 FX_BOOL CFDE_RenderContext::ApplyClip(IFDE_VisualSet* pVisualSet, |
| 274 FDE_HVISUALOBJ hObj, | 239 FDE_HVISUALOBJ hObj, |
| 275 FDE_HDEVICESTATE& hState) { | 240 FDE_HDEVICESTATE& hState) { |
| 276 CFX_RectF rtClip; | 241 CFX_RectF rtClip; |
| 277 if (!pVisualSet->GetClip(hObj, rtClip)) | 242 if (!pVisualSet->GetClip(hObj, rtClip)) |
| 278 return FALSE; | 243 return FALSE; |
| 279 | 244 |
| 280 CFX_RectF rtObj; | 245 CFX_RectF rtObj; |
| 281 pVisualSet->GetRect(hObj, rtObj); | 246 pVisualSet->GetRect(hObj, rtObj); |
| 282 rtClip.Offset(rtObj.left, rtObj.top); | 247 rtClip.Offset(rtObj.left, rtObj.top); |
| 283 m_Transform.TransformRect(rtClip); | 248 m_Transform.TransformRect(rtClip); |
| 284 const CFX_RectF& rtDevClip = m_pRenderDevice->GetClipRect(); | 249 const CFX_RectF& rtDevClip = m_pRenderDevice->GetClipRect(); |
| 285 rtClip.Intersect(rtDevClip); | 250 rtClip.Intersect(rtDevClip); |
| 286 hState = m_pRenderDevice->SaveState(); | 251 hState = m_pRenderDevice->SaveState(); |
| 287 return m_pRenderDevice->SetClipRect(rtClip); | 252 return m_pRenderDevice->SetClipRect(rtClip); |
| 288 } | 253 } |
| 289 | 254 |
| 290 void CFDE_RenderContext::RestoreClip(FDE_HDEVICESTATE hState) { | 255 void CFDE_RenderContext::RestoreClip(FDE_HDEVICESTATE hState) { |
| 291 m_pRenderDevice->RestoreState(hState); | 256 m_pRenderDevice->RestoreState(hState); |
| 292 } | 257 } |
| OLD | NEW |