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 = NULL); | 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); | 29 void RenderPath(IFDE_PathSet* pPathSet, FDE_HVISUALOBJ hPath); |
30 void RenderText(IFDE_TextSet* pTextSet, FDE_HVISUALOBJ hText); | 30 void RenderText(IFDE_TextSet* pTextSet, FDE_HVISUALOBJ hText); |
31 FX_BOOL ApplyClip(IFDE_VisualSet* pVisualSet, | 31 FX_BOOL ApplyClip(IFDE_VisualSet* pVisualSet, |
32 FDE_HVISUALOBJ hObj, | 32 FDE_HVISUALOBJ hObj, |
33 FDE_HDEVICESTATE& hState); | 33 FDE_HDEVICESTATE& hState); |
34 void RestoreClip(FDE_HDEVICESTATE hState); | 34 void RestoreClip(FDE_HDEVICESTATE hState); |
35 | 35 |
36 protected: | 36 protected: |
37 FDE_RENDERSTATUS m_eStatus; | 37 FDE_RENDERSTATUS m_eStatus; |
38 IFDE_RenderDevice* m_pRenderDevice; | 38 IFDE_RenderDevice* m_pRenderDevice; |
39 IFDE_SolidBrush* m_pSolidBrush; | 39 CFDE_Brush* m_pBrush; |
40 CFX_Matrix m_Transform; | 40 CFX_Matrix m_Transform; |
41 FXTEXT_CHARPOS* m_pCharPos; | 41 FXTEXT_CHARPOS* m_pCharPos; |
42 int32_t m_iCharPosCount; | 42 int32_t m_iCharPosCount; |
43 IFDE_VisualSetIterator* m_pIterator; | 43 IFDE_VisualSetIterator* m_pIterator; |
44 }; | 44 }; |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 void FDE_GetPageMatrix(CFX_Matrix& pageMatrix, | 48 void FDE_GetPageMatrix(CFX_Matrix& pageMatrix, |
49 const CFX_RectF& docPageRect, | 49 const CFX_RectF& docPageRect, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 m.e = bFlipY ? (FX_FLOAT)devicePageRect.right() | 86 m.e = bFlipY ? (FX_FLOAT)devicePageRect.right() |
87 : (FX_FLOAT)devicePageRect.left; | 87 : (FX_FLOAT)devicePageRect.left; |
88 m.f = bFlipX ? (FX_FLOAT)devicePageRect.top | 88 m.f = bFlipX ? (FX_FLOAT)devicePageRect.top |
89 : (FX_FLOAT)devicePageRect.bottom(); | 89 : (FX_FLOAT)devicePageRect.bottom(); |
90 break; | 90 break; |
91 default: | 91 default: |
92 break; | 92 break; |
93 } | 93 } |
94 pageMatrix = m; | 94 pageMatrix = m; |
95 } | 95 } |
| 96 |
96 IFDE_RenderContext* IFDE_RenderContext::Create() { | 97 IFDE_RenderContext* IFDE_RenderContext::Create() { |
97 return new CFDE_RenderContext; | 98 return new CFDE_RenderContext; |
98 } | 99 } |
| 100 |
99 CFDE_RenderContext::CFDE_RenderContext() | 101 CFDE_RenderContext::CFDE_RenderContext() |
100 : m_eStatus(FDE_RENDERSTATUS_Reset), | 102 : m_eStatus(FDE_RENDERSTATUS_Reset), |
101 m_pRenderDevice(NULL), | 103 m_pRenderDevice(nullptr), |
102 m_pSolidBrush(NULL), | 104 m_pBrush(nullptr), |
103 m_Transform(), | 105 m_Transform(), |
104 m_pCharPos(NULL), | 106 m_pCharPos(nullptr), |
105 m_iCharPosCount(0), | 107 m_iCharPosCount(0), |
106 m_pIterator(NULL) { | 108 m_pIterator(nullptr) { |
107 m_Transform.SetIdentity(); | 109 m_Transform.SetIdentity(); |
108 } | 110 } |
| 111 |
109 CFDE_RenderContext::~CFDE_RenderContext() { | 112 CFDE_RenderContext::~CFDE_RenderContext() { |
110 StopRender(); | 113 StopRender(); |
111 } | 114 } |
| 115 |
112 FX_BOOL CFDE_RenderContext::StartRender(IFDE_RenderDevice* pRenderDevice, | 116 FX_BOOL CFDE_RenderContext::StartRender(IFDE_RenderDevice* pRenderDevice, |
113 IFDE_CanvasSet* pCanvasSet, | 117 IFDE_CanvasSet* pCanvasSet, |
114 const CFX_Matrix& tmDoc2Device) { | 118 const CFX_Matrix& tmDoc2Device) { |
115 if (m_pRenderDevice != NULL) { | 119 if (m_pRenderDevice) |
116 return FALSE; | 120 return FALSE; |
117 } | 121 if (!pRenderDevice) |
118 if (pRenderDevice == NULL) { | |
119 return FALSE; | 122 return FALSE; |
120 } | 123 if (!pCanvasSet) |
121 if (pCanvasSet == NULL) { | |
122 return FALSE; | 124 return FALSE; |
123 } | |
124 | 125 |
125 m_eStatus = FDE_RENDERSTATUS_Paused; | 126 m_eStatus = FDE_RENDERSTATUS_Paused; |
126 m_pRenderDevice = pRenderDevice; | 127 m_pRenderDevice = pRenderDevice; |
127 m_Transform = tmDoc2Device; | 128 m_Transform = tmDoc2Device; |
128 if (m_pIterator == NULL) { | 129 if (!m_pIterator) { |
129 m_pIterator = IFDE_VisualSetIterator::Create(); | 130 m_pIterator = IFDE_VisualSetIterator::Create(); |
130 FXSYS_assert(m_pIterator != NULL); | 131 FXSYS_assert(m_pIterator); |
131 } | 132 } |
132 return m_pIterator->AttachCanvas(pCanvasSet) && m_pIterator->FilterObjects(); | 133 return m_pIterator->AttachCanvas(pCanvasSet) && m_pIterator->FilterObjects(); |
133 } | 134 } |
| 135 |
134 FDE_RENDERSTATUS CFDE_RenderContext::DoRender(IFX_Pause* pPause) { | 136 FDE_RENDERSTATUS CFDE_RenderContext::DoRender(IFX_Pause* pPause) { |
135 if (m_pRenderDevice == NULL) { | 137 if (!m_pRenderDevice) |
136 return FDE_RENDERSTATUS_Failed; | 138 return FDE_RENDERSTATUS_Failed; |
137 } | 139 if (!m_pIterator) |
138 if (m_pIterator == NULL) { | |
139 return FDE_RENDERSTATUS_Failed; | 140 return FDE_RENDERSTATUS_Failed; |
140 } | 141 |
141 FDE_RENDERSTATUS eStatus = FDE_RENDERSTATUS_Paused; | 142 FDE_RENDERSTATUS eStatus = FDE_RENDERSTATUS_Paused; |
142 CFX_Matrix rm; | 143 CFX_Matrix rm; |
143 rm.SetReverse(m_Transform); | 144 rm.SetReverse(m_Transform); |
144 CFX_RectF rtDocClip = m_pRenderDevice->GetClipRect(); | 145 CFX_RectF rtDocClip = m_pRenderDevice->GetClipRect(); |
145 if (rtDocClip.IsEmpty()) { | 146 if (rtDocClip.IsEmpty()) { |
146 rtDocClip.left = rtDocClip.top = 0; | 147 rtDocClip.left = rtDocClip.top = 0; |
147 rtDocClip.width = (FX_FLOAT)m_pRenderDevice->GetWidth(); | 148 rtDocClip.width = (FX_FLOAT)m_pRenderDevice->GetWidth(); |
148 rtDocClip.height = (FX_FLOAT)m_pRenderDevice->GetHeight(); | 149 rtDocClip.height = (FX_FLOAT)m_pRenderDevice->GetHeight(); |
149 } | 150 } |
150 rm.TransformRect(rtDocClip); | 151 rm.TransformRect(rtDocClip); |
151 IFDE_VisualSet* pVisualSet; | 152 IFDE_VisualSet* pVisualSet; |
152 FDE_HVISUALOBJ hVisualObj; | 153 FDE_HVISUALOBJ hVisualObj; |
153 CFX_RectF rtObj; | 154 CFX_RectF rtObj; |
154 int32_t iCount = 0; | 155 int32_t iCount = 0; |
155 while (TRUE) { | 156 while (TRUE) { |
156 hVisualObj = m_pIterator->GetNext(pVisualSet); | 157 hVisualObj = m_pIterator->GetNext(pVisualSet); |
157 if (hVisualObj == NULL || pVisualSet == NULL) { | 158 if (!hVisualObj || !pVisualSet) { |
158 eStatus = FDE_RENDERSTATUS_Done; | 159 eStatus = FDE_RENDERSTATUS_Done; |
159 break; | 160 break; |
160 } | 161 } |
161 rtObj.Empty(); | 162 rtObj.Empty(); |
162 pVisualSet->GetRect(hVisualObj, rtObj); | 163 pVisualSet->GetRect(hVisualObj, rtObj); |
163 if (!rtDocClip.IntersectWith(rtObj)) { | 164 if (!rtDocClip.IntersectWith(rtObj)) |
164 continue; | 165 continue; |
165 } | 166 |
166 switch (pVisualSet->GetType()) { | 167 switch (pVisualSet->GetType()) { |
167 case FDE_VISUALOBJ_Text: | 168 case FDE_VISUALOBJ_Text: |
168 RenderText((IFDE_TextSet*)pVisualSet, hVisualObj); | 169 RenderText((IFDE_TextSet*)pVisualSet, hVisualObj); |
169 iCount += 5; | 170 iCount += 5; |
170 break; | 171 break; |
171 case FDE_VISUALOBJ_Path: | 172 case FDE_VISUALOBJ_Path: |
172 RenderPath((IFDE_PathSet*)pVisualSet, hVisualObj); | 173 RenderPath((IFDE_PathSet*)pVisualSet, hVisualObj); |
173 iCount += 20; | 174 iCount += 20; |
174 break; | 175 break; |
175 case FDE_VISUALOBJ_Widget: | 176 case FDE_VISUALOBJ_Widget: |
176 iCount += 10; | 177 iCount += 10; |
177 break; | 178 break; |
178 case FDE_VISUALOBJ_Canvas: | 179 case FDE_VISUALOBJ_Canvas: |
179 FXSYS_assert(FALSE); | 180 FXSYS_assert(FALSE); |
180 break; | 181 break; |
181 default: | 182 default: |
182 break; | 183 break; |
183 } | 184 } |
184 if (iCount >= 100 && pPause != NULL && pPause->NeedToPauseNow()) { | 185 if (iCount >= 100 && pPause && pPause->NeedToPauseNow()) { |
185 eStatus = FDE_RENDERSTATUS_Paused; | 186 eStatus = FDE_RENDERSTATUS_Paused; |
186 break; | 187 break; |
187 } | 188 } |
188 } | 189 } |
189 return m_eStatus = eStatus; | 190 return m_eStatus = eStatus; |
190 } | 191 } |
| 192 |
191 void CFDE_RenderContext::StopRender() { | 193 void CFDE_RenderContext::StopRender() { |
192 m_eStatus = FDE_RENDERSTATUS_Reset; | 194 m_eStatus = FDE_RENDERSTATUS_Reset; |
193 m_pRenderDevice = nullptr; | 195 m_pRenderDevice = nullptr; |
194 m_Transform.SetIdentity(); | 196 m_Transform.SetIdentity(); |
195 if (m_pIterator) { | 197 if (m_pIterator) { |
196 m_pIterator->Release(); | 198 m_pIterator->Release(); |
197 m_pIterator = nullptr; | 199 m_pIterator = nullptr; |
198 } | 200 } |
199 if (m_pSolidBrush) { | 201 if (m_pBrush) { |
200 m_pSolidBrush->Release(); | 202 delete m_pBrush; |
201 m_pSolidBrush = nullptr; | 203 m_pBrush = nullptr; |
202 } | 204 } |
203 FX_Free(m_pCharPos); | 205 FX_Free(m_pCharPos); |
204 m_pCharPos = nullptr; | 206 m_pCharPos = nullptr; |
205 m_iCharPosCount = 0; | 207 m_iCharPosCount = 0; |
206 } | 208 } |
| 209 |
207 void CFDE_RenderContext::RenderText(IFDE_TextSet* pTextSet, | 210 void CFDE_RenderContext::RenderText(IFDE_TextSet* pTextSet, |
208 FDE_HVISUALOBJ hText) { | 211 FDE_HVISUALOBJ hText) { |
209 FXSYS_assert(m_pRenderDevice != NULL); | 212 FXSYS_assert(m_pRenderDevice); |
210 FXSYS_assert(pTextSet != NULL && hText != NULL); | 213 FXSYS_assert(pTextSet && hText); |
| 214 |
211 IFX_Font* pFont = pTextSet->GetFont(hText); | 215 IFX_Font* pFont = pTextSet->GetFont(hText); |
212 if (pFont == NULL) { | 216 if (!pFont) |
213 return; | 217 return; |
214 } | 218 |
215 int32_t iCount = pTextSet->GetDisplayPos(hText, NULL, FALSE); | 219 int32_t iCount = pTextSet->GetDisplayPos(hText, nullptr, FALSE); |
216 if (iCount < 1) { | 220 if (iCount < 1) |
217 return; | 221 return; |
218 } | 222 |
219 if (m_pSolidBrush == NULL) { | 223 if (!m_pBrush) |
220 m_pSolidBrush = new CFDE_SolidBrush; | 224 m_pBrush = new CFDE_Brush; |
221 if (m_pSolidBrush == NULL) { | 225 |
222 return; | 226 if (!m_pCharPos) |
223 } | |
224 } | |
225 if (m_pCharPos == NULL) { | |
226 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, iCount); | 227 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, iCount); |
227 } else if (m_iCharPosCount < iCount) { | 228 else if (m_iCharPosCount < iCount) |
228 m_pCharPos = FX_Realloc(FXTEXT_CHARPOS, m_pCharPos, iCount); | 229 m_pCharPos = FX_Realloc(FXTEXT_CHARPOS, m_pCharPos, iCount); |
229 } | 230 |
230 if (m_iCharPosCount < iCount) { | 231 if (m_iCharPosCount < iCount) |
231 m_iCharPosCount = iCount; | 232 m_iCharPosCount = iCount; |
232 } | 233 |
233 iCount = pTextSet->GetDisplayPos(hText, m_pCharPos, FALSE); | 234 iCount = pTextSet->GetDisplayPos(hText, m_pCharPos, FALSE); |
234 FX_FLOAT fFontSize = pTextSet->GetFontSize(hText); | 235 FX_FLOAT fFontSize = pTextSet->GetFontSize(hText); |
235 FX_ARGB dwColor = pTextSet->GetFontColor(hText); | 236 FX_ARGB dwColor = pTextSet->GetFontColor(hText); |
236 m_pSolidBrush->SetColor(dwColor); | 237 m_pBrush->SetColor(dwColor); |
237 FDE_HDEVICESTATE hState; | 238 FDE_HDEVICESTATE hState; |
238 FX_BOOL bClip = ApplyClip(pTextSet, hText, hState); | 239 FX_BOOL bClip = ApplyClip(pTextSet, hText, hState); |
239 m_pRenderDevice->DrawString(m_pSolidBrush, pFont, m_pCharPos, iCount, | 240 m_pRenderDevice->DrawString(m_pBrush, pFont, m_pCharPos, iCount, fFontSize, |
240 fFontSize, &m_Transform); | 241 &m_Transform); |
241 if (bClip) { | 242 if (bClip) |
242 RestoreClip(hState); | 243 RestoreClip(hState); |
243 } | |
244 } | 244 } |
| 245 |
245 void CFDE_RenderContext::RenderPath(IFDE_PathSet* pPathSet, | 246 void CFDE_RenderContext::RenderPath(IFDE_PathSet* pPathSet, |
246 FDE_HVISUALOBJ hPath) { | 247 FDE_HVISUALOBJ hPath) { |
247 FXSYS_assert(m_pRenderDevice != NULL); | 248 FXSYS_assert(m_pRenderDevice); |
248 FXSYS_assert(pPathSet != NULL && hPath != NULL); | 249 FXSYS_assert(pPathSet && hPath); |
| 250 |
249 IFDE_Path* pPath = pPathSet->GetPath(hPath); | 251 IFDE_Path* pPath = pPathSet->GetPath(hPath); |
250 if (pPath == NULL) { | 252 if (!pPath) |
251 return; | 253 return; |
252 } | 254 |
253 FDE_HDEVICESTATE hState; | 255 FDE_HDEVICESTATE hState; |
254 FX_BOOL bClip = ApplyClip(pPathSet, hPath, hState); | 256 FX_BOOL bClip = ApplyClip(pPathSet, hPath, hState); |
255 int32_t iRenderMode = pPathSet->GetRenderMode(hPath); | 257 int32_t iRenderMode = pPathSet->GetRenderMode(hPath); |
256 if (iRenderMode & FDE_PATHRENDER_Stroke) { | 258 if (iRenderMode & FDE_PATHRENDER_Stroke) { |
257 IFDE_Pen* pPen = pPathSet->GetPen(hPath); | 259 CFDE_Pen* pPen = pPathSet->GetPen(hPath); |
258 FX_FLOAT fWidth = pPathSet->GetPenWidth(hPath); | 260 FX_FLOAT fWidth = pPathSet->GetPenWidth(hPath); |
259 if (pPen != NULL && fWidth > 0) { | 261 if (pPen && fWidth > 0) |
260 m_pRenderDevice->DrawPath(pPen, fWidth, pPath, &m_Transform); | 262 m_pRenderDevice->DrawPath(pPen, fWidth, pPath, &m_Transform); |
261 } | |
262 } | 263 } |
263 if (iRenderMode & FDE_PATHRENDER_Fill) { | 264 if (iRenderMode & FDE_PATHRENDER_Fill) { |
264 IFDE_Brush* pBrush = pPathSet->GetBrush(hPath); | 265 CFDE_Brush* pBrush = pPathSet->GetBrush(hPath); |
265 if (pBrush != NULL) { | 266 if (pBrush) |
266 m_pRenderDevice->FillPath(pBrush, pPath, &m_Transform); | 267 m_pRenderDevice->FillPath(pBrush, pPath, &m_Transform); |
267 } | |
268 } | 268 } |
269 if (bClip) { | 269 if (bClip) |
270 RestoreClip(hState); | 270 RestoreClip(hState); |
271 } | |
272 } | 271 } |
| 272 |
273 FX_BOOL CFDE_RenderContext::ApplyClip(IFDE_VisualSet* pVisualSet, | 273 FX_BOOL CFDE_RenderContext::ApplyClip(IFDE_VisualSet* pVisualSet, |
274 FDE_HVISUALOBJ hObj, | 274 FDE_HVISUALOBJ hObj, |
275 FDE_HDEVICESTATE& hState) { | 275 FDE_HDEVICESTATE& hState) { |
276 CFX_RectF rtClip; | 276 CFX_RectF rtClip; |
277 if (!pVisualSet->GetClip(hObj, rtClip)) { | 277 if (!pVisualSet->GetClip(hObj, rtClip)) |
278 return FALSE; | 278 return FALSE; |
279 } | 279 |
280 CFX_RectF rtObj; | 280 CFX_RectF rtObj; |
281 pVisualSet->GetRect(hObj, rtObj); | 281 pVisualSet->GetRect(hObj, rtObj); |
282 rtClip.Offset(rtObj.left, rtObj.top); | 282 rtClip.Offset(rtObj.left, rtObj.top); |
283 m_Transform.TransformRect(rtClip); | 283 m_Transform.TransformRect(rtClip); |
284 const CFX_RectF& rtDevClip = m_pRenderDevice->GetClipRect(); | 284 const CFX_RectF& rtDevClip = m_pRenderDevice->GetClipRect(); |
285 rtClip.Intersect(rtDevClip); | 285 rtClip.Intersect(rtDevClip); |
286 hState = m_pRenderDevice->SaveState(); | 286 hState = m_pRenderDevice->SaveState(); |
287 return m_pRenderDevice->SetClipRect(rtClip); | 287 return m_pRenderDevice->SetClipRect(rtClip); |
288 } | 288 } |
| 289 |
289 void CFDE_RenderContext::RestoreClip(FDE_HDEVICESTATE hState) { | 290 void CFDE_RenderContext::RestoreClip(FDE_HDEVICESTATE hState) { |
290 m_pRenderDevice->RestoreState(hState); | 291 m_pRenderDevice->RestoreState(hState); |
291 } | 292 } |
OLD | NEW |