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_gedevice.h" | 9 #include "xfa/fde/fde_gedevice.h" |
10 #include "xfa/fde/fde_object.h" | 10 #include "xfa/fde/fde_object.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 CFDE_RenderContext::CFDE_RenderContext() | 16 CFDE_RenderContext::CFDE_RenderContext() |
17 : m_eStatus(FDE_RENDERSTATUS_Reset), | 17 : m_eStatus(FDE_RENDERSTATUS_Reset), |
18 m_pRenderDevice(nullptr), | 18 m_pRenderDevice(nullptr), |
19 m_pBrush(nullptr), | |
20 m_Transform(), | 19 m_Transform(), |
21 m_pCharPos(nullptr), | 20 m_pCharPos(nullptr), |
22 m_iCharPosCount(0), | 21 m_iCharPosCount(0) { |
23 m_pIterator(nullptr) { | |
24 m_Transform.SetIdentity(); | 22 m_Transform.SetIdentity(); |
25 } | 23 } |
26 | 24 |
27 CFDE_RenderContext::~CFDE_RenderContext() { | 25 CFDE_RenderContext::~CFDE_RenderContext() { |
28 StopRender(); | 26 StopRender(); |
29 } | 27 } |
30 | 28 |
31 FX_BOOL CFDE_RenderContext::StartRender(CFDE_RenderDevice* pRenderDevice, | 29 FX_BOOL CFDE_RenderContext::StartRender(CFDE_RenderDevice* pRenderDevice, |
32 IFDE_CanvasSet* pCanvasSet, | 30 IFDE_CanvasSet* pCanvasSet, |
33 const CFX_Matrix& tmDoc2Device) { | 31 const CFX_Matrix& tmDoc2Device) { |
34 if (m_pRenderDevice) | 32 if (m_pRenderDevice) |
35 return FALSE; | 33 return FALSE; |
36 if (!pRenderDevice) | 34 if (!pRenderDevice) |
37 return FALSE; | 35 return FALSE; |
38 if (!pCanvasSet) | 36 if (!pCanvasSet) |
39 return FALSE; | 37 return FALSE; |
40 | 38 |
41 m_eStatus = FDE_RENDERSTATUS_Paused; | 39 m_eStatus = FDE_RENDERSTATUS_Paused; |
42 m_pRenderDevice = pRenderDevice; | 40 m_pRenderDevice = pRenderDevice; |
43 m_Transform = tmDoc2Device; | 41 m_Transform = tmDoc2Device; |
44 if (!m_pIterator) | 42 if (!m_pIterator) |
45 m_pIterator = new CFDE_VisualSetIterator; | 43 m_pIterator.reset(new CFDE_VisualSetIterator); |
46 | 44 |
47 return m_pIterator->AttachCanvas(pCanvasSet) && m_pIterator->FilterObjects(); | 45 return m_pIterator->AttachCanvas(pCanvasSet) && m_pIterator->FilterObjects(); |
48 } | 46 } |
49 | 47 |
50 FDE_RENDERSTATUS CFDE_RenderContext::DoRender(IFX_Pause* pPause) { | 48 FDE_RENDERSTATUS CFDE_RenderContext::DoRender(IFX_Pause* pPause) { |
51 if (!m_pRenderDevice) | 49 if (!m_pRenderDevice) |
52 return FDE_RENDERSTATUS_Failed; | 50 return FDE_RENDERSTATUS_Failed; |
53 if (!m_pIterator) | 51 if (!m_pIterator) |
54 return FDE_RENDERSTATUS_Failed; | 52 return FDE_RENDERSTATUS_Failed; |
55 | 53 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 break; | 92 break; |
95 } | 93 } |
96 } | 94 } |
97 return m_eStatus = eStatus; | 95 return m_eStatus = eStatus; |
98 } | 96 } |
99 | 97 |
100 void CFDE_RenderContext::StopRender() { | 98 void CFDE_RenderContext::StopRender() { |
101 m_eStatus = FDE_RENDERSTATUS_Reset; | 99 m_eStatus = FDE_RENDERSTATUS_Reset; |
102 m_pRenderDevice = nullptr; | 100 m_pRenderDevice = nullptr; |
103 m_Transform.SetIdentity(); | 101 m_Transform.SetIdentity(); |
104 if (m_pIterator) { | 102 m_pIterator.reset(); |
105 m_pIterator->Release(); | 103 m_pBrush.reset(); |
106 m_pIterator = nullptr; | |
107 } | |
108 delete m_pBrush; | |
109 m_pBrush = nullptr; | |
110 FX_Free(m_pCharPos); | 104 FX_Free(m_pCharPos); |
111 m_pCharPos = nullptr; | 105 m_pCharPos = nullptr; |
112 m_iCharPosCount = 0; | 106 m_iCharPosCount = 0; |
113 } | 107 } |
114 | 108 |
115 void CFDE_RenderContext::RenderText(IFDE_TextSet* pTextSet, | 109 void CFDE_RenderContext::RenderText(IFDE_TextSet* pTextSet, |
116 FDE_HVISUALOBJ hText) { | 110 FDE_HVISUALOBJ hText) { |
117 ASSERT(m_pRenderDevice); | 111 ASSERT(m_pRenderDevice); |
118 ASSERT(pTextSet && hText); | 112 ASSERT(pTextSet && hText); |
119 | 113 |
120 IFX_Font* pFont = pTextSet->GetFont(hText); | 114 IFX_Font* pFont = pTextSet->GetFont(hText); |
121 if (!pFont) | 115 if (!pFont) |
122 return; | 116 return; |
123 | 117 |
124 int32_t iCount = pTextSet->GetDisplayPos(hText, nullptr, FALSE); | 118 int32_t iCount = pTextSet->GetDisplayPos(hText, nullptr, FALSE); |
125 if (iCount < 1) | 119 if (iCount < 1) |
126 return; | 120 return; |
127 | 121 |
128 if (!m_pBrush) | 122 if (!m_pBrush) |
129 m_pBrush = new CFDE_Brush; | 123 m_pBrush.reset(new CFDE_Brush); |
130 | 124 |
131 if (!m_pCharPos) | 125 if (!m_pCharPos) |
132 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, iCount); | 126 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, iCount); |
133 else if (m_iCharPosCount < iCount) | 127 else if (m_iCharPosCount < iCount) |
134 m_pCharPos = FX_Realloc(FXTEXT_CHARPOS, m_pCharPos, iCount); | 128 m_pCharPos = FX_Realloc(FXTEXT_CHARPOS, m_pCharPos, iCount); |
135 | 129 |
136 if (m_iCharPosCount < iCount) | 130 if (m_iCharPosCount < iCount) |
137 m_iCharPosCount = iCount; | 131 m_iCharPosCount = iCount; |
138 | 132 |
139 iCount = pTextSet->GetDisplayPos(hText, m_pCharPos, FALSE); | 133 iCount = pTextSet->GetDisplayPos(hText, m_pCharPos, FALSE); |
140 FX_FLOAT fFontSize = pTextSet->GetFontSize(hText); | 134 FX_FLOAT fFontSize = pTextSet->GetFontSize(hText); |
141 FX_ARGB dwColor = pTextSet->GetFontColor(hText); | 135 FX_ARGB dwColor = pTextSet->GetFontColor(hText); |
142 m_pBrush->SetColor(dwColor); | 136 m_pBrush->SetColor(dwColor); |
143 FDE_HDEVICESTATE hState; | 137 FDE_HDEVICESTATE hState; |
144 FX_BOOL bClip = ApplyClip(pTextSet, hText, hState); | 138 FX_BOOL bClip = ApplyClip(pTextSet, hText, hState); |
145 m_pRenderDevice->DrawString(m_pBrush, pFont, m_pCharPos, iCount, fFontSize, | 139 m_pRenderDevice->DrawString(m_pBrush.get(), pFont, m_pCharPos, iCount, |
146 &m_Transform); | 140 fFontSize, &m_Transform); |
147 if (bClip) | 141 if (bClip) |
148 RestoreClip(hState); | 142 RestoreClip(hState); |
149 } | 143 } |
150 | 144 |
151 FX_BOOL CFDE_RenderContext::ApplyClip(IFDE_VisualSet* pVisualSet, | 145 FX_BOOL CFDE_RenderContext::ApplyClip(IFDE_VisualSet* pVisualSet, |
152 FDE_HVISUALOBJ hObj, | 146 FDE_HVISUALOBJ hObj, |
153 FDE_HDEVICESTATE& hState) { | 147 FDE_HDEVICESTATE& hState) { |
154 CFX_RectF rtClip; | 148 CFX_RectF rtClip; |
155 if (!pVisualSet->GetClip(hObj, rtClip)) | 149 if (!pVisualSet->GetClip(hObj, rtClip)) |
156 return FALSE; | 150 return FALSE; |
157 | 151 |
158 CFX_RectF rtObj; | 152 CFX_RectF rtObj; |
159 pVisualSet->GetRect(hObj, rtObj); | 153 pVisualSet->GetRect(hObj, rtObj); |
160 rtClip.Offset(rtObj.left, rtObj.top); | 154 rtClip.Offset(rtObj.left, rtObj.top); |
161 m_Transform.TransformRect(rtClip); | 155 m_Transform.TransformRect(rtClip); |
162 const CFX_RectF& rtDevClip = m_pRenderDevice->GetClipRect(); | 156 const CFX_RectF& rtDevClip = m_pRenderDevice->GetClipRect(); |
163 rtClip.Intersect(rtDevClip); | 157 rtClip.Intersect(rtDevClip); |
164 hState = m_pRenderDevice->SaveState(); | 158 hState = m_pRenderDevice->SaveState(); |
165 return m_pRenderDevice->SetClipRect(rtClip); | 159 return m_pRenderDevice->SetClipRect(rtClip); |
166 } | 160 } |
167 | 161 |
168 void CFDE_RenderContext::RestoreClip(FDE_HDEVICESTATE hState) { | 162 void CFDE_RenderContext::RestoreClip(FDE_HDEVICESTATE hState) { |
169 m_pRenderDevice->RestoreState(hState); | 163 m_pRenderDevice->RestoreState(hState); |
170 } | 164 } |
OLD | NEW |