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