Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / include / fxgraphics / fx_graphics.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef __H_FX_GRAPHICS__\r
8 #define __H_FX_GRAPHICS__\r
9 #define FX_ERR_Succeeded                                        0\r
10 #define FX_ERR_Indefinite                                       -1\r
11 #define FX_ERR_Parameter_Invalid                        -100\r
12 #define FX_ERR_Property_Invalid                         -200\r
13 #define FX_ERR_Intermediate_Value_Invalid       -300\r
14 #define FX_ERR_Method_Not_Supported                     -400\r
15 #define FX_ERR_Out_Of_Memory                            -500\r
16 #define _FX_RETURN_IF_FAIL(arg) {if (!(arg)) return;}\r
17 #define _FX_RETURN_VALUE_IF_FAIL(arg, val) {if (!(arg)) return val;}\r
18 #define _FX_GOTO_POSITION_IF_FAIL(arg, pos) {if (!(arg)) goto pos;}\r
19 #define _FX_ERR_CHECK_RETURN_IF_FAIL(arg) {if ((arg) != FX_ERR_Succeeded) return;}\r
20 #define _FX_ERR_CHECK_RETURN_VALUE_IF_FAIL(arg, val) {if ((arg) != FX_ERR_Succeeded) return val;}\r
21 #define _FX_ERR_CHECK_GOTO_POSITION_IF_FAIL(arg, pos) {if ((arg) != FX_ERR_Succeeded) goto pos;}\r
22 #define FX_SHADING_Steps        256\r
23 typedef FX_INT32 FX_DashStyle;\r
24 enum {\r
25     FX_DASHSTYLE_Solid                                          = 0,\r
26     FX_DASHSTYLE_Dash                                           = 1,\r
27     FX_DASHSTYLE_Dot                                            = 2,\r
28     FX_DASHSTYLE_DashDot                                        = 3,\r
29     FX_DASHSTYLE_DashDotDot                                     = 4\r
30 };\r
31 typedef FX_INT32 FX_StrokeAlignment;\r
32 enum {\r
33     FX_STROKEALIGNMENT_Center                           = 0,\r
34     FX_STROKEALIGNMENT_Inset                            = 1,\r
35     FX_STROKEALIGNMENT_Outset                           = 2,\r
36     FX_STROKEALIGNMENT_Left                                     = 3,\r
37     FX_STROKEALIGNMENT_Right                            = 4\r
38 };\r
39 typedef FX_INT32 FX_HatchStyle;\r
40 enum {\r
41     FX_HATCHSTYLE_Horizontal                            = 0,\r
42     FX_HATCHSTYLE_Vertical                                      = 1,\r
43     FX_HATCHSTYLE_ForwardDiagonal                       = 2,\r
44     FX_HATCHSTYLE_BackwardDiagonal                      = 3,\r
45     FX_HATCHSTYLE_Cross                                         = 4,\r
46     FX_HATCHSTYLE_DiagonalCross                         = 5,\r
47     FX_HATCHSTYLE_05Percent                                     = 6,\r
48     FX_HATCHSTYLE_10Percent                                     = 7,\r
49     FX_HATCHSTYLE_20Percent                                     = 8,\r
50     FX_HATCHSTYLE_25Percent                                     = 9,\r
51     FX_HATCHSTYLE_30Percent                                     = 10,\r
52     FX_HATCHSTYLE_40Percent                                     = 11,\r
53     FX_HATCHSTYLE_50Percent                                     = 12,\r
54     FX_HATCHSTYLE_60Percent                                     = 13,\r
55     FX_HATCHSTYLE_70Percent                                     = 14,\r
56     FX_HATCHSTYLE_75Percent                                     = 15,\r
57     FX_HATCHSTYLE_80Percent                                     = 16,\r
58     FX_HATCHSTYLE_90Percent                                     = 17,\r
59     FX_HATCHSTYLE_LightDownwardDiagonal         = 18,\r
60     FX_HATCHSTYLE_LightUpwardDiagonal           = 19,\r
61     FX_HATCHSTYLE_DarkDownwardDiagonal          = 20,\r
62     FX_HATCHSTYLE_DarkUpwardDiagonal            = 21,\r
63     FX_HATCHSTYLE_WideDownwardDiagonal          = 22,\r
64     FX_HATCHSTYLE_WideUpwardDiagonal            = 23,\r
65     FX_HATCHSTYLE_LightVertical                         = 24,\r
66     FX_HATCHSTYLE_LightHorizontal                       = 25,\r
67     FX_HATCHSTYLE_NarrowVertical                        = 26,\r
68     FX_HATCHSTYLE_NarrowHorizontal                      = 27,\r
69     FX_HATCHSTYLE_DarkVertical                          = 28,\r
70     FX_HATCHSTYLE_DarkHorizontal                        = 29,\r
71     FX_HATCHSTYLE_DashedDownwardDiagonal        = 30,\r
72     FX_HATCHSTYLE_DashedUpwardDiagonal          = 31,\r
73     FX_HATCHSTYLE_DashedHorizontal                      = 32,\r
74     FX_HATCHSTYLE_DashedVertical                        = 33,\r
75     FX_HATCHSTYLE_SmallConfetti                         = 34,\r
76     FX_HATCHSTYLE_LargeConfetti                         = 35,\r
77     FX_HATCHSTYLE_ZigZag                                        = 36,\r
78     FX_HATCHSTYLE_Wave                                          = 37,\r
79     FX_HATCHSTYLE_DiagonalBrick                         = 38,\r
80     FX_HATCHSTYLE_HorizontalBrick                       = 39,\r
81     FX_HATCHSTYLE_Weave                                         = 40,\r
82     FX_HATCHSTYLE_Plaid                                         = 41,\r
83     FX_HATCHSTYLE_Divot                                         = 42,\r
84     FX_HATCHSTYLE_DottedGrid                            = 43,\r
85     FX_HATCHSTYLE_DottedDiamond                         = 44,\r
86     FX_HATCHSTYLE_Shingle                                       = 45,\r
87     FX_HATCHSTYLE_Trellis                                       = 46,\r
88     FX_HATCHSTYLE_Sphere                                        = 47,\r
89     FX_HATCHSTYLE_SmallGrid                                     = 48,\r
90     FX_HATCHSTYLE_SmallCheckerBoard                     = 49,\r
91     FX_HATCHSTYLE_LargeCheckerBoard                     = 50,\r
92     FX_HATCHSTYLE_OutlinedDiamond                       = 51,\r
93     FX_HATCHSTYLE_SolidDiamond                          = 52\r
94 };\r
95 typedef FX_INT32 FX_DeviceCap;\r
96 typedef FX_INT32 FX_FillMode;\r
97 class CFX_Object;\r
98 class CFX_RenderDevice;\r
99 class CFX_GraphStateData;\r
100 class CFX_Matrix;\r
101 class CFX_DIBSource;\r
102 class CFX_DIBitmap;\r
103 class CFX_Font;\r
104 class CFX_WideString;\r
105 class IFX_FileRead;\r
106 class CFX_PathGenerator;\r
107 class CAGG_Graphics;\r
108 class CFX_Graphics;\r
109 class CFX_Color;\r
110 class CFX_Path;\r
111 class CFX_Pattern;\r
112 class CFX_Shading;\r
113 class CFX_Graphics : public CFX_Object\r
114 {\r
115 public:\r
116 \r
117 \r
118     CFX_Graphics();\r
119 \r
120     FX_ERR Create(CFX_RenderDevice * renderDevice, FX_BOOL isAntialiasing = TRUE);\r
121 \r
122     FX_ERR Create(FX_INT32         width,\r
123                   FX_INT32         height,\r
124                   FXDIB_Format format,\r
125                   FX_BOOL      isNative       = TRUE,\r
126                   FX_BOOL          isAntialiasing = TRUE);\r
127 \r
128 \r
129     virtual ~CFX_Graphics();\r
130 \r
131 \r
132 \r
133     FX_ERR GetDeviceCap(const FX_INT32 capID, FX_DeviceCap & capVal);\r
134     FX_ERR IsPrinterDevice(FX_BOOL & isPrinter);\r
135     FX_ERR EnableAntialiasing(FX_BOOL isAntialiasing);\r
136 \r
137 \r
138 \r
139     FX_ERR SaveGraphState();\r
140 \r
141     FX_ERR RestoreGraphState();\r
142 \r
143 \r
144 \r
145     FX_ERR GetLineCap(CFX_GraphStateData::LineCap & lineCap);\r
146 \r
147     FX_ERR SetLineCap(CFX_GraphStateData::LineCap lineCap);\r
148 \r
149     FX_ERR GetDashCount(FX_INT32 & dashCount);\r
150 \r
151     FX_ERR GetLineDash(FX_FLOAT & dashPhase, FX_FLOAT * dashArray);\r
152 \r
153     FX_ERR SetLineDash(FX_FLOAT dashPhase, FX_FLOAT * dashArray, FX_INT32 dashCount);\r
154 \r
155     FX_ERR SetLineDash(FX_DashStyle dashStyle);\r
156 \r
157     FX_ERR GetLineJoin(CFX_GraphStateData::LineJoin & lineJoin);\r
158 \r
159     FX_ERR SetLineJoin(CFX_GraphStateData::LineJoin lineJoin);\r
160 \r
161     FX_ERR GetMiterLimit(FX_FLOAT & miterLimit);\r
162 \r
163     FX_ERR SetMiterLimit(FX_FLOAT miterLimit);\r
164 \r
165     FX_ERR GetLineWidth(FX_FLOAT & lineWidth);\r
166 \r
167     FX_ERR SetLineWidth(FX_FLOAT lineWidth, FX_BOOL isActOnDash = FALSE);\r
168 \r
169     FX_ERR GetStrokeAlignment(FX_StrokeAlignment & strokeAlignment);\r
170 \r
171     FX_ERR SetStrokeAlignment(FX_StrokeAlignment strokeAlignment);\r
172 \r
173 \r
174 \r
175     FX_ERR SetStrokeColor(CFX_Color * color);\r
176 \r
177     FX_ERR SetFillColor(CFX_Color * color);\r
178 \r
179 \r
180 \r
181     FX_ERR StrokePath(CFX_Path * path, CFX_Matrix * matrix = NULL);\r
182 \r
183     FX_ERR FillPath(CFX_Path *   path,\r
184                     FX_FillMode  fillMode = FXFILL_WINDING,\r
185                     CFX_Matrix * matrix   = NULL);\r
186 \r
187     FX_ERR ClipPath(CFX_Path *   path,\r
188                     FX_FillMode  fillMode = FXFILL_WINDING,\r
189                     CFX_Matrix * matrix   = NULL);\r
190 \r
191 \r
192 \r
193     FX_ERR DrawImage(CFX_DIBSource *    source,\r
194                      const CFX_PointF & point,\r
195                      CFX_Matrix *               matrix = NULL);\r
196 \r
197     FX_ERR StretchImage(CFX_DIBSource *   source,\r
198                         const CFX_RectF & rect,\r
199                         CFX_Matrix *      matrix = NULL);\r
200 \r
201 \r
202 \r
203     FX_ERR ConcatMatrix(CFX_Matrix * matrix);\r
204 \r
205     CFX_Matrix * GetMatrix();\r
206 \r
207 \r
208 \r
209     FX_ERR GetClipRect(CFX_RectF & rect);\r
210 \r
211     FX_ERR SetClipRect(const CFX_RectF & rect);\r
212 \r
213     FX_ERR ClearClip();\r
214 \r
215 \r
216 \r
217     FX_ERR SetFont(CFX_Font * font);\r
218 \r
219     FX_ERR SetFontSize(const FX_FLOAT size);\r
220 \r
221     FX_ERR SetFontHScale(const FX_FLOAT scale);\r
222 \r
223     FX_ERR SetCharSpacing(const FX_FLOAT spacing);\r
224 \r
225     FX_ERR SetTextDrawingMode(const FX_INT32 mode);\r
226 \r
227 \r
228     FX_ERR ShowText(const CFX_PointF &     point,\r
229                     const CFX_WideString & text,\r
230                     CFX_Matrix *                   matrix = NULL);\r
231 \r
232 \r
233     FX_ERR CalcTextRect(CFX_RectF &                        rect,\r
234                         const CFX_WideString & text,\r
235                         FX_BOOL                            isMultiline = FALSE,\r
236                         CFX_Matrix *               matrix          = NULL);\r
237 \r
238 \r
239 \r
240     FX_ERR Transfer(CFX_Graphics * graphics, CFX_Matrix * matrix = NULL);\r
241 \r
242 \r
243     FX_ERR Transfer(CFX_Graphics *        graphics,\r
244                     FX_FLOAT              srcLeft,\r
245                     FX_FLOAT              srcTop,\r
246                     const CFX_RectF & dstRect,\r
247                     CFX_Matrix *          matrix  = NULL);\r
248 \r
249 \r
250 \r
251 \r
252     CFX_RenderDevice * GetRenderDevice();\r
253 \r
254     FX_ERR      InverseRect(const CFX_RectF & rect);\r
255     FX_ERR      XorDIBitmap(const CFX_DIBitmap * srcBitmap, const CFX_RectF & rect);\r
256     FX_ERR      EqvDIBitmap(const CFX_DIBitmap * srcBitmap, const CFX_RectF & rect);\r
257 private:\r
258 \r
259     FX_ERR RenderDeviceSetLineDash(FX_DashStyle dashStyle);\r
260 \r
261     FX_ERR RenderDeviceStrokePath(CFX_Path * path, CFX_Matrix * matrix);\r
262 \r
263     FX_ERR RenderDeviceFillPath(CFX_Path *       path,\r
264                                 FX_FillMode      fillMode,\r
265                                 CFX_Matrix * matrix);\r
266 \r
267 \r
268     FX_ERR RenderDeviceDrawImage(CFX_DIBSource *        source,\r
269                                  const CFX_PointF &     point,\r
270                                  CFX_Matrix *           matrix);\r
271 \r
272     FX_ERR RenderDeviceStretchImage(CFX_DIBSource *       source,\r
273                                     const CFX_RectF & rect,\r
274                                     CFX_Matrix *          matrix);\r
275 \r
276     FX_ERR RenderDeviceShowText(const CFX_PointF &         point,\r
277                                 const CFX_WideString & text,\r
278                                 CFX_Matrix *               matrix);\r
279 \r
280     FX_ERR StrokePathWithPattern(CFX_Path * path, CFX_Matrix * matrix);\r
281 \r
282     FX_ERR StrokePathWithShading(CFX_Path * path, CFX_Matrix * matrix);\r
283 \r
284     FX_ERR FillPathWithPattern(CFX_Path *       path,\r
285                                FX_FillMode      fillMode,\r
286                                CFX_Matrix *     matrix);\r
287 \r
288     FX_ERR FillPathWithShading(CFX_Path *       path,\r
289                                FX_FillMode      fillMode,\r
290                                CFX_Matrix *     matrix);\r
291     FX_ERR SetDIBitsWithMatrix(CFX_DIBSource * source, CFX_Matrix * matrix);\r
292     FX_ERR CalcTextInfo(const CFX_WideString & text, FX_DWORD * charCodes, FXTEXT_CHARPOS * charPos, CFX_RectF & rect);\r
293 \r
294 \r
295 protected:\r
296     FX_INT32            _type;\r
297 private:\r
298     struct TInfo : public CFX_Object {\r
299         CFX_GraphStateData      _graphState;\r
300         FX_BOOL                         _isAntialiasing;\r
301         FX_StrokeAlignment      _strokeAlignment;\r
302         CFX_Matrix                      _CTM;\r
303         FX_BOOL                         _isActOnDash;\r
304         CFX_Color *                     _strokeColor;\r
305         CFX_Color *                     _fillColor;\r
306         CFX_Font *                      _font;\r
307         FX_FLOAT                        _fontSize;\r
308         FX_FLOAT                        _fontHScale;\r
309         FX_FLOAT                        _fontSpacing;\r
310     } _info;\r
311     CFX_RenderDevice *  _renderDevice;\r
312     CFX_PtrArray                _infoStack;\r
313     CAGG_Graphics *     _aggGraphics;\r
314     friend class CAGG_Graphics;\r
315 \r
316 };\r
317 class CFX_Path : public CFX_Object\r
318 {\r
319 public:\r
320 \r
321 \r
322     CFX_Path();\r
323 \r
324     FX_ERR Create();\r
325 \r
326     virtual ~CFX_Path();\r
327 \r
328 \r
329     FX_ERR MoveTo(FX_FLOAT x, FX_FLOAT y);\r
330 \r
331     FX_ERR LineTo(FX_FLOAT x, FX_FLOAT y);\r
332 \r
333     FX_ERR BezierTo(FX_FLOAT ctrlX1,\r
334                     FX_FLOAT ctrlY1,\r
335                     FX_FLOAT ctrlX2,\r
336                     FX_FLOAT ctrlY2,\r
337                     FX_FLOAT toX,\r
338                     FX_FLOAT toY);\r
339 \r
340     FX_ERR ArcTo(FX_FLOAT left,\r
341                  FX_FLOAT top,\r
342                  FX_FLOAT width,\r
343                  FX_FLOAT height,\r
344                  FX_FLOAT startAngle,\r
345                  FX_FLOAT sweepAngle);\r
346 \r
347     FX_ERR Close();\r
348 \r
349 \r
350     FX_ERR AddLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2);\r
351 \r
352     FX_ERR AddBezier(FX_FLOAT startX,\r
353                      FX_FLOAT startY,\r
354                      FX_FLOAT ctrlX1,\r
355                      FX_FLOAT ctrlY1,\r
356                      FX_FLOAT ctrlX2,\r
357                      FX_FLOAT ctrlY2,\r
358                      FX_FLOAT endX,\r
359                      FX_FLOAT endY);\r
360 \r
361     FX_ERR AddRectangle(FX_FLOAT left, FX_FLOAT top, FX_FLOAT width, FX_FLOAT height);\r
362 \r
363     FX_ERR AddEllipse(FX_FLOAT left, FX_FLOAT top, FX_FLOAT width, FX_FLOAT height);\r
364 \r
365     FX_ERR AddEllipse(const CFX_RectF & rect);\r
366 \r
367     FX_ERR AddArc(FX_FLOAT left,\r
368                   FX_FLOAT top,\r
369                   FX_FLOAT width,\r
370                   FX_FLOAT height,\r
371                   FX_FLOAT startAngle,\r
372                   FX_FLOAT sweepAngle);\r
373 \r
374     FX_ERR AddPie(FX_FLOAT left,\r
375                   FX_FLOAT top,\r
376                   FX_FLOAT width,\r
377                   FX_FLOAT height,\r
378                   FX_FLOAT startAngle,\r
379                   FX_FLOAT sweepAngle);\r
380 \r
381     FX_ERR AddSubpath(CFX_Path * path);\r
382 \r
383     FX_ERR Clear();\r
384 \r
385     FX_BOOL IsEmpty();\r
386 \r
387     CFX_PathData * GetPathData();\r
388 private:\r
389     CFX_PathGenerator * _generator;\r
390 };\r
391 class CFX_Color : public CFX_Object\r
392 {\r
393 public:\r
394 \r
395     CFX_Color();\r
396 \r
397     CFX_Color(const FX_ARGB argb);\r
398 \r
399 \r
400     CFX_Color(CFX_Pattern * pattern, const FX_ARGB argb = 0x0);\r
401 \r
402 \r
403     CFX_Color(CFX_Shading * shading);\r
404 \r
405 \r
406     virtual ~CFX_Color();\r
407 \r
408 \r
409     FX_ERR Set(const FX_ARGB argb);\r
410 \r
411 \r
412     FX_ERR Set(CFX_Pattern * pattern, const FX_ARGB argb = 0x0);\r
413 \r
414 \r
415     FX_ERR Set(CFX_Shading * shading);\r
416 \r
417 private:\r
418     FX_INT32                            _type;\r
419     union {\r
420         struct {\r
421             FX_ARGB                     _argb;\r
422             CFX_Pattern *       _pattern;\r
423         };\r
424         CFX_Shading *           _shading;\r
425     };\r
426 \r
427     friend class CFX_Graphics;\r
428 };\r
429 class CFX_Pattern : public CFX_Object\r
430 {\r
431 public:\r
432 \r
433 \r
434     CFX_Pattern();\r
435 \r
436     FX_ERR Create(CFX_DIBitmap * bitmap,\r
437                   const FX_FLOAT xStep,\r
438                   const FX_FLOAT yStep,\r
439                   CFX_Matrix *   matrix = NULL);\r
440 \r
441     FX_ERR Create(FX_HatchStyle hatchStyle,\r
442                   const FX_ARGB foreArgb,\r
443                   const FX_ARGB backArgb,\r
444                   CFX_Matrix *  matrix = NULL);\r
445 \r
446     virtual ~CFX_Pattern();\r
447 \r
448 private:\r
449     FX_INT32                            _type;\r
450     CFX_Matrix                          _matrix;\r
451     union {\r
452         struct {\r
453             CFX_RectF           _rect;\r
454             FX_FLOAT            _xStep;\r
455             FX_FLOAT            _yStep;\r
456             FX_BOOL                     _isColored;\r
457         };\r
458         struct {\r
459             CFX_DIBitmap *      _bitmap;\r
460             FX_FLOAT            _x1Step;\r
461             FX_FLOAT            _y1Step;\r
462         };\r
463         struct {\r
464             FX_HatchStyle       _hatchStyle;\r
465             FX_ARGB                     _foreArgb;\r
466             FX_ARGB                     _backArgb;\r
467         };\r
468     };\r
469     friend class CFX_Graphics;\r
470 };\r
471 class CFX_Shading : public CFX_Object\r
472 {\r
473 public:\r
474 \r
475 \r
476     CFX_Shading();\r
477 \r
478     FX_ERR CreateAxial(const CFX_PointF & beginPoint,\r
479                        const CFX_PointF & endPoint,\r
480                        FX_BOOL                    isExtendedBegin,\r
481                        FX_BOOL                    isExtendedEnd,\r
482                        const FX_ARGB      beginArgb,\r
483                        const FX_ARGB      endArgb);\r
484 \r
485     FX_ERR CreateRadial(const CFX_PointF & beginPoint,\r
486                         const CFX_PointF & endPoint,\r
487                         const FX_FLOAT     beginRadius,\r
488                         const FX_FLOAT     endRadius,\r
489                         FX_BOOL                    isExtendedBegin,\r
490                         FX_BOOL                    isExtendedEnd,\r
491                         const FX_ARGB      beginArgb,\r
492                         const FX_ARGB      endArgb);\r
493 \r
494     virtual ~CFX_Shading();\r
495 \r
496 private:\r
497     FX_ERR InitArgbArray();\r
498 private:\r
499     FX_INT32    _type;\r
500     CFX_PointF  _beginPoint;\r
501     CFX_PointF  _endPoint;\r
502     FX_FLOAT    _beginRadius;\r
503     FX_FLOAT    _endRadius;\r
504     FX_BOOL             _isExtendedBegin;\r
505     FX_BOOL             _isExtendedEnd;\r
506     FX_ARGB             _beginArgb;\r
507     FX_ARGB             _endArgb;\r
508     FX_ARGB             _argbArray[FX_SHADING_Steps];\r
509     friend class CFX_Graphics;\r
510 };\r
511 #endif\r