OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef XFA_INCLUDE_FXGRAPHICS_FX_GRAPHICS_H_ | 7 #ifndef XFA_FXGRAPHICS_INCLUDE_CFX_GRAPHICS_H_ |
8 #define XFA_INCLUDE_FXGRAPHICS_FX_GRAPHICS_H_ | 8 #define XFA_FXGRAPHICS_INCLUDE_CFX_GRAPHICS_H_ |
9 | 9 |
10 #include "core/include/fpdfapi/fpdf_pageobj.h" | 10 #include "core/include/fxcrt/fx_system.h" |
11 #include "core/include/fxge/fx_dib.h" | |
12 #include "core/include/fxge/fx_ge.h" | |
11 | 13 |
12 typedef int FX_ERR; | 14 class CFX_Color; |
15 class CFX_Path; | |
16 class CAGG_Graphics; | |
17 | |
13 #define FX_ERR_Succeeded 0 | 18 #define FX_ERR_Succeeded 0 |
14 #define FX_ERR_Indefinite -1 | 19 #define FX_ERR_Indefinite -1 |
15 #define FX_ERR_Parameter_Invalid -100 | 20 #define FX_ERR_Parameter_Invalid -100 |
16 #define FX_ERR_Property_Invalid -200 | 21 #define FX_ERR_Property_Invalid -200 |
17 #define FX_ERR_Intermediate_Value_Invalid -300 | 22 #define FX_ERR_Intermediate_Value_Invalid -300 |
18 #define FX_ERR_Method_Not_Supported -400 | 23 #define FX_ERR_Method_Not_Supported -400 |
19 #define FX_ERR_Out_Of_Memory -500 | 24 #define FX_ERR_Out_Of_Memory -500 |
20 | 25 |
21 #define FX_SHADING_Steps 256 | 26 typedef int FX_ERR; |
Tom Sepez
2016/03/16 17:08:52
nit: use "using" while we're at it.
Can't some of
dsinclair
2016/03/16 19:21:08
Done.
| |
22 typedef int32_t FX_DashStyle; | 27 typedef int32_t FX_DashStyle; |
28 typedef int32_t FX_StrokeAlignment; | |
29 typedef int32_t FX_HatchStyle; | |
30 typedef int32_t FX_DeviceCap; | |
31 typedef int32_t FX_FillMode; | |
32 | |
23 enum { | 33 enum { |
Tom Sepez
2016/03/16 17:08:52
anon enum?
dsinclair
2016/03/16 19:21:08
Named as the types above.
| |
24 FX_DASHSTYLE_Solid = 0, | 34 FX_DASHSTYLE_Solid = 0, |
25 FX_DASHSTYLE_Dash = 1, | 35 FX_DASHSTYLE_Dash = 1, |
26 FX_DASHSTYLE_Dot = 2, | 36 FX_DASHSTYLE_Dot = 2, |
27 FX_DASHSTYLE_DashDot = 3, | 37 FX_DASHSTYLE_DashDot = 3, |
28 FX_DASHSTYLE_DashDotDot = 4 | 38 FX_DASHSTYLE_DashDotDot = 4 |
29 }; | 39 }; |
30 typedef int32_t FX_StrokeAlignment; | 40 |
31 enum { | 41 enum { |
32 FX_STROKEALIGNMENT_Center = 0, | 42 FX_STROKEALIGNMENT_Center = 0, |
33 FX_STROKEALIGNMENT_Inset = 1, | 43 FX_STROKEALIGNMENT_Inset = 1, |
34 FX_STROKEALIGNMENT_Outset = 2, | 44 FX_STROKEALIGNMENT_Outset = 2, |
35 FX_STROKEALIGNMENT_Left = 3, | 45 FX_STROKEALIGNMENT_Left = 3, |
36 FX_STROKEALIGNMENT_Right = 4 | 46 FX_STROKEALIGNMENT_Right = 4 |
37 }; | 47 }; |
38 typedef int32_t FX_HatchStyle; | 48 |
39 enum { | 49 enum { |
40 FX_HATCHSTYLE_Horizontal = 0, | 50 FX_HATCHSTYLE_Horizontal = 0, |
41 FX_HATCHSTYLE_Vertical = 1, | 51 FX_HATCHSTYLE_Vertical = 1, |
42 FX_HATCHSTYLE_ForwardDiagonal = 2, | 52 FX_HATCHSTYLE_ForwardDiagonal = 2, |
43 FX_HATCHSTYLE_BackwardDiagonal = 3, | 53 FX_HATCHSTYLE_BackwardDiagonal = 3, |
44 FX_HATCHSTYLE_Cross = 4, | 54 FX_HATCHSTYLE_Cross = 4, |
45 FX_HATCHSTYLE_DiagonalCross = 5, | 55 FX_HATCHSTYLE_DiagonalCross = 5, |
46 FX_HATCHSTYLE_05Percent = 6, | 56 FX_HATCHSTYLE_05Percent = 6, |
47 FX_HATCHSTYLE_10Percent = 7, | 57 FX_HATCHSTYLE_10Percent = 7, |
48 FX_HATCHSTYLE_20Percent = 8, | 58 FX_HATCHSTYLE_20Percent = 8, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 FX_HATCHSTYLE_DottedDiamond = 44, | 94 FX_HATCHSTYLE_DottedDiamond = 44, |
85 FX_HATCHSTYLE_Shingle = 45, | 95 FX_HATCHSTYLE_Shingle = 45, |
86 FX_HATCHSTYLE_Trellis = 46, | 96 FX_HATCHSTYLE_Trellis = 46, |
87 FX_HATCHSTYLE_Sphere = 47, | 97 FX_HATCHSTYLE_Sphere = 47, |
88 FX_HATCHSTYLE_SmallGrid = 48, | 98 FX_HATCHSTYLE_SmallGrid = 48, |
89 FX_HATCHSTYLE_SmallCheckerBoard = 49, | 99 FX_HATCHSTYLE_SmallCheckerBoard = 49, |
90 FX_HATCHSTYLE_LargeCheckerBoard = 50, | 100 FX_HATCHSTYLE_LargeCheckerBoard = 50, |
91 FX_HATCHSTYLE_OutlinedDiamond = 51, | 101 FX_HATCHSTYLE_OutlinedDiamond = 51, |
92 FX_HATCHSTYLE_SolidDiamond = 52 | 102 FX_HATCHSTYLE_SolidDiamond = 52 |
93 }; | 103 }; |
94 typedef int32_t FX_DeviceCap; | 104 |
95 typedef int32_t FX_FillMode; | |
96 class CFX_RenderDevice; | 105 class CFX_RenderDevice; |
97 class CFX_GraphStateData; | |
98 class CFX_Matrix; | |
99 class CFX_DIBSource; | |
100 class CFX_DIBitmap; | |
101 class CFX_Font; | |
102 class CFX_WideString; | |
103 class CFX_PathGenerator; | |
104 class CFX_Graphics; | |
105 class CFX_Color; | |
106 class CFX_Path; | |
107 class CFX_Pattern; | |
108 class CFX_Shading; | |
109 | |
110 class CAGG_Graphics { | |
111 public: | |
112 CAGG_Graphics(); | |
113 virtual ~CAGG_Graphics(); | |
114 | |
115 FX_ERR Create(CFX_Graphics* owner, | |
116 int32_t width, | |
117 int32_t height, | |
118 FXDIB_Format format); | |
119 | |
120 private: | |
121 CFX_Graphics* m_owner; | |
122 }; | |
123 | 106 |
124 class CFX_Graphics { | 107 class CFX_Graphics { |
125 public: | 108 public: |
126 CFX_Graphics(); | 109 CFX_Graphics(); |
127 virtual ~CFX_Graphics(); | 110 virtual ~CFX_Graphics(); |
128 | 111 |
129 FX_ERR Create(CFX_RenderDevice* renderDevice, FX_BOOL isAntialiasing = TRUE); | 112 FX_ERR Create(CFX_RenderDevice* renderDevice, FX_BOOL isAntialiasing = TRUE); |
130 FX_ERR Create(int32_t width, | 113 FX_ERR Create(int32_t width, |
131 int32_t height, | 114 int32_t height, |
132 FXDIB_Format format, | 115 FXDIB_Format format, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 FX_ERR Transfer(CFX_Graphics* graphics, | 178 FX_ERR Transfer(CFX_Graphics* graphics, |
196 FX_FLOAT srcLeft, | 179 FX_FLOAT srcLeft, |
197 FX_FLOAT srcTop, | 180 FX_FLOAT srcTop, |
198 const CFX_RectF& dstRect, | 181 const CFX_RectF& dstRect, |
199 const CFX_Matrix* matrix); | 182 const CFX_Matrix* matrix); |
200 | 183 |
201 FX_ERR InverseRect(const CFX_RectF& rect); | 184 FX_ERR InverseRect(const CFX_RectF& rect); |
202 FX_ERR XorDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); | 185 FX_ERR XorDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); |
203 FX_ERR EqvDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); | 186 FX_ERR EqvDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); |
204 | 187 |
188 protected: | |
189 int32_t m_type; | |
190 | |
205 private: | 191 private: |
192 struct TInfo { | |
193 TInfo() | |
194 : isAntialiasing(TRUE), | |
195 strokeAlignment(FX_STROKEALIGNMENT_Center), | |
196 isActOnDash(FALSE), | |
197 strokeColor(nullptr), | |
198 fillColor(nullptr), | |
199 font(nullptr), | |
200 fontSize(40.0), | |
201 fontHScale(1.0), | |
202 fontSpacing(0.0) {} | |
203 explicit TInfo(const TInfo& info); | |
204 TInfo& operator=(const TInfo& other); | |
205 | |
206 CFX_GraphStateData graphState; | |
207 FX_BOOL isAntialiasing; | |
208 FX_StrokeAlignment strokeAlignment; | |
209 CFX_Matrix CTM; | |
210 FX_BOOL isActOnDash; | |
211 CFX_Color* strokeColor; | |
212 CFX_Color* fillColor; | |
213 CFX_Font* font; | |
214 FX_FLOAT fontSize; | |
215 FX_FLOAT fontHScale; | |
216 FX_FLOAT fontSpacing; | |
217 } m_info; | |
218 | |
206 FX_ERR RenderDeviceSetLineDash(FX_DashStyle dashStyle); | 219 FX_ERR RenderDeviceSetLineDash(FX_DashStyle dashStyle); |
207 FX_ERR RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix); | 220 FX_ERR RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix); |
208 FX_ERR RenderDeviceFillPath(CFX_Path* path, | 221 FX_ERR RenderDeviceFillPath(CFX_Path* path, |
209 FX_FillMode fillMode, | 222 FX_FillMode fillMode, |
210 CFX_Matrix* matrix); | 223 CFX_Matrix* matrix); |
211 FX_ERR RenderDeviceDrawImage(CFX_DIBSource* source, | 224 FX_ERR RenderDeviceDrawImage(CFX_DIBSource* source, |
212 const CFX_PointF& point, | 225 const CFX_PointF& point, |
213 CFX_Matrix* matrix); | 226 CFX_Matrix* matrix); |
214 FX_ERR RenderDeviceStretchImage(CFX_DIBSource* source, | 227 FX_ERR RenderDeviceStretchImage(CFX_DIBSource* source, |
215 const CFX_RectF& rect, | 228 const CFX_RectF& rect, |
(...skipping 11 matching lines...) Expand all Loading... | |
227 FX_ERR FillPathWithShading(CFX_Path* path, | 240 FX_ERR FillPathWithShading(CFX_Path* path, |
228 FX_FillMode fillMode, | 241 FX_FillMode fillMode, |
229 CFX_Matrix* matrix); | 242 CFX_Matrix* matrix); |
230 | 243 |
231 FX_ERR SetDIBitsWithMatrix(CFX_DIBSource* source, CFX_Matrix* matrix); | 244 FX_ERR SetDIBitsWithMatrix(CFX_DIBSource* source, CFX_Matrix* matrix); |
232 FX_ERR CalcTextInfo(const CFX_WideString& text, | 245 FX_ERR CalcTextInfo(const CFX_WideString& text, |
233 FX_DWORD* charCodes, | 246 FX_DWORD* charCodes, |
234 FXTEXT_CHARPOS* charPos, | 247 FXTEXT_CHARPOS* charPos, |
235 CFX_RectF& rect); | 248 CFX_RectF& rect); |
236 | 249 |
237 protected: | |
238 int32_t m_type; | |
239 | |
240 private: | |
241 struct TInfo { | |
242 TInfo() | |
243 : isAntialiasing(TRUE), | |
244 strokeAlignment(FX_STROKEALIGNMENT_Center), | |
245 isActOnDash(FALSE), | |
246 strokeColor(nullptr), | |
247 fillColor(nullptr), | |
248 font(nullptr), | |
249 fontSize(40.0), | |
250 fontHScale(1.0), | |
251 fontSpacing(0.0) {} | |
252 explicit TInfo(const TInfo& info); | |
253 TInfo& operator=(const TInfo& other); | |
254 | |
255 CFX_GraphStateData graphState; | |
256 FX_BOOL isAntialiasing; | |
257 FX_StrokeAlignment strokeAlignment; | |
258 CFX_Matrix CTM; | |
259 FX_BOOL isActOnDash; | |
260 CFX_Color* strokeColor; | |
261 CFX_Color* fillColor; | |
262 CFX_Font* font; | |
263 FX_FLOAT fontSize; | |
264 FX_FLOAT fontHScale; | |
265 FX_FLOAT fontSpacing; | |
266 } m_info; | |
267 CFX_RenderDevice* m_renderDevice; | 250 CFX_RenderDevice* m_renderDevice; |
268 CFX_PtrArray m_infoStack; | 251 CFX_PtrArray m_infoStack; |
269 CAGG_Graphics* m_aggGraphics; | 252 CAGG_Graphics* m_aggGraphics; |
270 friend class CAGG_Graphics; | 253 friend class CAGG_Graphics; |
271 }; | 254 }; |
272 | 255 |
273 class CFX_Path { | 256 #endif // XFA_FXGRAPHICS_INCLUDE_CFX_GRAPHICS_H_ |
274 public: | |
275 CFX_Path(); | |
276 virtual ~CFX_Path(); | |
277 | |
278 FX_ERR Create(); | |
279 FX_ERR MoveTo(FX_FLOAT x, FX_FLOAT y); | |
280 FX_ERR LineTo(FX_FLOAT x, FX_FLOAT y); | |
281 FX_ERR BezierTo(FX_FLOAT ctrlX1, | |
282 FX_FLOAT ctrlY1, | |
283 FX_FLOAT ctrlX2, | |
284 FX_FLOAT ctrlY2, | |
285 FX_FLOAT toX, | |
286 FX_FLOAT toY); | |
287 FX_ERR ArcTo(FX_FLOAT left, | |
288 FX_FLOAT top, | |
289 FX_FLOAT width, | |
290 FX_FLOAT height, | |
291 FX_FLOAT startAngle, | |
292 FX_FLOAT sweepAngle); | |
293 FX_ERR Close(); | |
294 | |
295 FX_ERR AddLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2); | |
296 FX_ERR AddBezier(FX_FLOAT startX, | |
297 FX_FLOAT startY, | |
298 FX_FLOAT ctrlX1, | |
299 FX_FLOAT ctrlY1, | |
300 FX_FLOAT ctrlX2, | |
301 FX_FLOAT ctrlY2, | |
302 FX_FLOAT endX, | |
303 FX_FLOAT endY); | |
304 FX_ERR AddRectangle(FX_FLOAT left, | |
305 FX_FLOAT top, | |
306 FX_FLOAT width, | |
307 FX_FLOAT height); | |
308 FX_ERR AddEllipse(FX_FLOAT left, | |
309 FX_FLOAT top, | |
310 FX_FLOAT width, | |
311 FX_FLOAT height); | |
312 FX_ERR AddEllipse(const CFX_RectF& rect); | |
313 FX_ERR AddArc(FX_FLOAT left, | |
314 FX_FLOAT top, | |
315 FX_FLOAT width, | |
316 FX_FLOAT height, | |
317 FX_FLOAT startAngle, | |
318 FX_FLOAT sweepAngle); | |
319 FX_ERR AddPie(FX_FLOAT left, | |
320 FX_FLOAT top, | |
321 FX_FLOAT width, | |
322 FX_FLOAT height, | |
323 FX_FLOAT startAngle, | |
324 FX_FLOAT sweepAngle); | |
325 FX_ERR AddSubpath(CFX_Path* path); | |
326 FX_ERR Clear(); | |
327 | |
328 FX_BOOL IsEmpty(); | |
329 CFX_PathData* GetPathData(); | |
330 | |
331 private: | |
332 CFX_PathGenerator* m_generator; | |
333 }; | |
334 | |
335 class CFX_Color { | |
336 public: | |
337 CFX_Color(); | |
338 // TODO(weili): Remove implicit conversions. Make this explicit. | |
339 CFX_Color(const FX_ARGB argb); | |
340 explicit CFX_Color(CFX_Pattern* pattern, const FX_ARGB argb = 0x0); | |
341 explicit CFX_Color(CFX_Shading* shading); | |
342 virtual ~CFX_Color(); | |
343 | |
344 FX_ERR Set(const FX_ARGB argb); | |
345 FX_ERR Set(CFX_Pattern* pattern, const FX_ARGB argb = 0x0); | |
346 FX_ERR Set(CFX_Shading* shading); | |
347 | |
348 private: | |
349 int32_t m_type; | |
350 union { | |
351 struct { | |
352 FX_ARGB argb; | |
353 CFX_Pattern* pattern; | |
354 } m_info; | |
355 CFX_Shading* m_shading; | |
356 }; | |
357 | |
358 friend class CFX_Graphics; | |
359 }; | |
360 | |
361 class CFX_Pattern { | |
362 public: | |
363 CFX_Pattern(); | |
364 virtual ~CFX_Pattern(); | |
365 | |
366 FX_ERR Create(CFX_DIBitmap* bitmap, | |
367 const FX_FLOAT xStep, | |
368 const FX_FLOAT yStep, | |
369 CFX_Matrix* matrix = NULL); | |
370 FX_ERR Create(FX_HatchStyle hatchStyle, | |
371 const FX_ARGB foreArgb, | |
372 const FX_ARGB backArgb, | |
373 CFX_Matrix* matrix = NULL); | |
374 | |
375 private: | |
376 int32_t m_type; | |
377 CFX_Matrix m_matrix; | |
378 union { | |
379 struct { | |
380 CFX_RectF rect; | |
381 FX_FLOAT xStep; | |
382 FX_FLOAT yStep; | |
383 FX_BOOL isColored; | |
384 } m_rectInfo; | |
385 struct { | |
386 CFX_DIBitmap* bitmap; | |
387 FX_FLOAT x1Step; | |
388 FX_FLOAT y1Step; | |
389 } m_bitmapInfo; | |
390 struct { | |
391 FX_HatchStyle hatchStyle; | |
392 FX_ARGB foreArgb; | |
393 FX_ARGB backArgb; | |
394 } m_hatchInfo; | |
395 }; | |
396 friend class CFX_Graphics; | |
397 }; | |
398 | |
399 class CFX_Shading { | |
400 public: | |
401 CFX_Shading(); | |
402 virtual ~CFX_Shading(); | |
403 | |
404 FX_ERR CreateAxial(const CFX_PointF& beginPoint, | |
405 const CFX_PointF& endPoint, | |
406 FX_BOOL isExtendedBegin, | |
407 FX_BOOL isExtendedEnd, | |
408 const FX_ARGB beginArgb, | |
409 const FX_ARGB endArgb); | |
410 FX_ERR CreateRadial(const CFX_PointF& beginPoint, | |
411 const CFX_PointF& endPoint, | |
412 const FX_FLOAT beginRadius, | |
413 const FX_FLOAT endRadius, | |
414 FX_BOOL isExtendedBegin, | |
415 FX_BOOL isExtendedEnd, | |
416 const FX_ARGB beginArgb, | |
417 const FX_ARGB endArgb); | |
418 | |
419 private: | |
420 FX_ERR InitArgbArray(); | |
421 | |
422 int32_t m_type; | |
423 CFX_PointF m_beginPoint; | |
424 CFX_PointF m_endPoint; | |
425 FX_FLOAT m_beginRadius; | |
426 FX_FLOAT m_endRadius; | |
427 FX_BOOL m_isExtendedBegin; | |
428 FX_BOOL m_isExtendedEnd; | |
429 FX_ARGB m_beginArgb; | |
430 FX_ARGB m_endArgb; | |
431 FX_ARGB m_argbArray[FX_SHADING_Steps]; | |
432 friend class CFX_Graphics; | |
433 }; | |
434 | |
435 #endif // XFA_INCLUDE_FXGRAPHICS_FX_GRAPHICS_H_ | |
OLD | NEW |