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