OLD | NEW |
| (Empty) |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef XFA_FXGRAPHICS_INCLUDE_CFX_GRAPHICS_H_ | |
8 #define XFA_FXGRAPHICS_INCLUDE_CFX_GRAPHICS_H_ | |
9 | |
10 #include <memory> | |
11 | |
12 #include "core/fxcrt/fx_system.h" | |
13 #include "core/fxge/cfx_fxgedevice.h" | |
14 #include "core/fxge/cfx_graphstatedata.h" | |
15 #include "core/fxge/cfx_renderdevice.h" | |
16 #include "core/fxge/fx_dib.h" | |
17 #include "core/fxge/fx_font.h" | |
18 #include "xfa/fwl/core/fwl_error.h" | |
19 | |
20 class CFX_Color; | |
21 class CFX_Path; | |
22 class CAGG_Graphics; | |
23 | |
24 using FX_DeviceCap = int32_t; | |
25 using FX_FillMode = int32_t; | |
26 | |
27 enum FX_DashStyle { | |
28 FX_DASHSTYLE_Solid = 0, | |
29 FX_DASHSTYLE_Dash = 1, | |
30 FX_DASHSTYLE_Dot = 2, | |
31 FX_DASHSTYLE_DashDot = 3, | |
32 FX_DASHSTYLE_DashDotDot = 4 | |
33 }; | |
34 | |
35 enum FX_StrokeAlignment { | |
36 FX_STROKEALIGNMENT_Center = 0, | |
37 FX_STROKEALIGNMENT_Inset = 1, | |
38 FX_STROKEALIGNMENT_Outset = 2, | |
39 FX_STROKEALIGNMENT_Left = 3, | |
40 FX_STROKEALIGNMENT_Right = 4 | |
41 }; | |
42 | |
43 enum FX_HatchStyle { | |
44 FX_HATCHSTYLE_Horizontal = 0, | |
45 FX_HATCHSTYLE_Vertical = 1, | |
46 FX_HATCHSTYLE_ForwardDiagonal = 2, | |
47 FX_HATCHSTYLE_BackwardDiagonal = 3, | |
48 FX_HATCHSTYLE_Cross = 4, | |
49 FX_HATCHSTYLE_DiagonalCross = 5, | |
50 FX_HATCHSTYLE_05Percent = 6, | |
51 FX_HATCHSTYLE_10Percent = 7, | |
52 FX_HATCHSTYLE_20Percent = 8, | |
53 FX_HATCHSTYLE_25Percent = 9, | |
54 FX_HATCHSTYLE_30Percent = 10, | |
55 FX_HATCHSTYLE_40Percent = 11, | |
56 FX_HATCHSTYLE_50Percent = 12, | |
57 FX_HATCHSTYLE_60Percent = 13, | |
58 FX_HATCHSTYLE_70Percent = 14, | |
59 FX_HATCHSTYLE_75Percent = 15, | |
60 FX_HATCHSTYLE_80Percent = 16, | |
61 FX_HATCHSTYLE_90Percent = 17, | |
62 FX_HATCHSTYLE_LightDownwardDiagonal = 18, | |
63 FX_HATCHSTYLE_LightUpwardDiagonal = 19, | |
64 FX_HATCHSTYLE_DarkDownwardDiagonal = 20, | |
65 FX_HATCHSTYLE_DarkUpwardDiagonal = 21, | |
66 FX_HATCHSTYLE_WideDownwardDiagonal = 22, | |
67 FX_HATCHSTYLE_WideUpwardDiagonal = 23, | |
68 FX_HATCHSTYLE_LightVertical = 24, | |
69 FX_HATCHSTYLE_LightHorizontal = 25, | |
70 FX_HATCHSTYLE_NarrowVertical = 26, | |
71 FX_HATCHSTYLE_NarrowHorizontal = 27, | |
72 FX_HATCHSTYLE_DarkVertical = 28, | |
73 FX_HATCHSTYLE_DarkHorizontal = 29, | |
74 FX_HATCHSTYLE_DashedDownwardDiagonal = 30, | |
75 FX_HATCHSTYLE_DashedUpwardDiagonal = 31, | |
76 FX_HATCHSTYLE_DashedHorizontal = 32, | |
77 FX_HATCHSTYLE_DashedVertical = 33, | |
78 FX_HATCHSTYLE_SmallConfetti = 34, | |
79 FX_HATCHSTYLE_LargeConfetti = 35, | |
80 FX_HATCHSTYLE_ZigZag = 36, | |
81 FX_HATCHSTYLE_Wave = 37, | |
82 FX_HATCHSTYLE_DiagonalBrick = 38, | |
83 FX_HATCHSTYLE_HorizontalBrick = 39, | |
84 FX_HATCHSTYLE_Weave = 40, | |
85 FX_HATCHSTYLE_Plaid = 41, | |
86 FX_HATCHSTYLE_Divot = 42, | |
87 FX_HATCHSTYLE_DottedGrid = 43, | |
88 FX_HATCHSTYLE_DottedDiamond = 44, | |
89 FX_HATCHSTYLE_Shingle = 45, | |
90 FX_HATCHSTYLE_Trellis = 46, | |
91 FX_HATCHSTYLE_Sphere = 47, | |
92 FX_HATCHSTYLE_SmallGrid = 48, | |
93 FX_HATCHSTYLE_SmallCheckerBoard = 49, | |
94 FX_HATCHSTYLE_LargeCheckerBoard = 50, | |
95 FX_HATCHSTYLE_OutlinedDiamond = 51, | |
96 FX_HATCHSTYLE_SolidDiamond = 52 | |
97 }; | |
98 | |
99 class CFX_RenderDevice; | |
100 | |
101 class CFX_Graphics { | |
102 public: | |
103 CFX_Graphics(); | |
104 virtual ~CFX_Graphics(); | |
105 | |
106 FWL_Error Create(CFX_RenderDevice* renderDevice, | |
107 FX_BOOL isAntialiasing = TRUE); | |
108 FWL_Error Create(int32_t width, | |
109 int32_t height, | |
110 FXDIB_Format format, | |
111 FX_BOOL isNative = TRUE, | |
112 FX_BOOL isAntialiasing = TRUE); | |
113 | |
114 FWL_Error GetDeviceCap(const int32_t capID, FX_DeviceCap& capVal); | |
115 FWL_Error IsPrinterDevice(FX_BOOL& isPrinter); | |
116 FWL_Error EnableAntialiasing(FX_BOOL isAntialiasing); | |
117 | |
118 FWL_Error SaveGraphState(); | |
119 FWL_Error RestoreGraphState(); | |
120 | |
121 FWL_Error GetLineCap(CFX_GraphStateData::LineCap& lineCap) const; | |
122 FWL_Error GetDashCount(int32_t& dashCount) const; | |
123 FWL_Error GetLineDash(FX_FLOAT& dashPhase, FX_FLOAT* dashArray) const; | |
124 FWL_Error GetLineJoin(CFX_GraphStateData::LineJoin& lineJoin) const; | |
125 FWL_Error GetMiterLimit(FX_FLOAT& miterLimit) const; | |
126 FWL_Error GetLineWidth(FX_FLOAT& lineWidth) const; | |
127 FWL_Error GetStrokeAlignment(FX_StrokeAlignment& strokeAlignment) const; | |
128 FWL_Error GetClipRect(CFX_RectF& rect) const; | |
129 CFX_Matrix* GetMatrix(); | |
130 CFX_RenderDevice* GetRenderDevice(); | |
131 | |
132 FWL_Error SetLineCap(CFX_GraphStateData::LineCap lineCap); | |
133 FWL_Error SetLineDash(FX_FLOAT dashPhase, | |
134 FX_FLOAT* dashArray, | |
135 int32_t dashCount); | |
136 FWL_Error SetLineDash(FX_DashStyle dashStyle); | |
137 FWL_Error SetLineJoin(CFX_GraphStateData::LineJoin lineJoin); | |
138 FWL_Error SetMiterLimit(FX_FLOAT miterLimit); | |
139 FWL_Error SetLineWidth(FX_FLOAT lineWidth, FX_BOOL isActOnDash = FALSE); | |
140 FWL_Error SetStrokeAlignment(FX_StrokeAlignment strokeAlignment); | |
141 FWL_Error SetStrokeColor(CFX_Color* color); | |
142 FWL_Error SetFillColor(CFX_Color* color); | |
143 FWL_Error SetClipRect(const CFX_RectF& rect); | |
144 FWL_Error SetFont(CFX_Font* font); | |
145 FWL_Error SetFontSize(const FX_FLOAT size); | |
146 FWL_Error SetFontHScale(const FX_FLOAT scale); | |
147 FWL_Error SetCharSpacing(const FX_FLOAT spacing); | |
148 FWL_Error SetTextDrawingMode(const int32_t mode); | |
149 | |
150 FWL_Error StrokePath(CFX_Path* path, CFX_Matrix* matrix = nullptr); | |
151 FWL_Error FillPath(CFX_Path* path, | |
152 FX_FillMode fillMode = FXFILL_WINDING, | |
153 CFX_Matrix* matrix = nullptr); | |
154 FWL_Error ClipPath(CFX_Path* path, | |
155 FX_FillMode fillMode = FXFILL_WINDING, | |
156 CFX_Matrix* matrix = nullptr); | |
157 FWL_Error DrawImage(CFX_DIBSource* source, | |
158 const CFX_PointF& point, | |
159 CFX_Matrix* matrix = nullptr); | |
160 FWL_Error StretchImage(CFX_DIBSource* source, | |
161 const CFX_RectF& rect, | |
162 CFX_Matrix* matrix = nullptr); | |
163 FWL_Error ConcatMatrix(const CFX_Matrix* matrix); | |
164 FWL_Error ClearClip(); | |
165 FWL_Error ShowText(const CFX_PointF& point, | |
166 const CFX_WideString& text, | |
167 CFX_Matrix* matrix = nullptr); | |
168 FWL_Error CalcTextRect(CFX_RectF& rect, | |
169 const CFX_WideString& text, | |
170 FX_BOOL isMultiline = FALSE, | |
171 CFX_Matrix* matrix = nullptr); | |
172 FWL_Error Transfer(CFX_Graphics* graphics, const CFX_Matrix* matrix); | |
173 FWL_Error Transfer(CFX_Graphics* graphics, | |
174 FX_FLOAT srcLeft, | |
175 FX_FLOAT srcTop, | |
176 const CFX_RectF& dstRect, | |
177 const CFX_Matrix* matrix); | |
178 | |
179 FWL_Error InverseRect(const CFX_RectF& rect); | |
180 FWL_Error XorDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); | |
181 FWL_Error EqvDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); | |
182 | |
183 protected: | |
184 int32_t m_type; | |
185 | |
186 private: | |
187 struct TInfo { | |
188 TInfo(); | |
189 explicit TInfo(const TInfo& info); | |
190 TInfo& operator=(const TInfo& other); | |
191 | |
192 CFX_GraphStateData graphState; | |
193 FX_BOOL isAntialiasing; | |
194 FX_StrokeAlignment strokeAlignment; | |
195 CFX_Matrix CTM; | |
196 FX_BOOL isActOnDash; | |
197 CFX_Color* strokeColor; | |
198 CFX_Color* fillColor; | |
199 CFX_Font* font; | |
200 FX_FLOAT fontSize; | |
201 FX_FLOAT fontHScale; | |
202 FX_FLOAT fontSpacing; | |
203 } m_info; | |
204 | |
205 FWL_Error RenderDeviceSetLineDash(FX_DashStyle dashStyle); | |
206 FWL_Error RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix); | |
207 FWL_Error RenderDeviceFillPath(CFX_Path* path, | |
208 FX_FillMode fillMode, | |
209 CFX_Matrix* matrix); | |
210 FWL_Error RenderDeviceDrawImage(CFX_DIBSource* source, | |
211 const CFX_PointF& point, | |
212 CFX_Matrix* matrix); | |
213 FWL_Error RenderDeviceStretchImage(CFX_DIBSource* source, | |
214 const CFX_RectF& rect, | |
215 CFX_Matrix* matrix); | |
216 FWL_Error RenderDeviceShowText(const CFX_PointF& point, | |
217 const CFX_WideString& text, | |
218 CFX_Matrix* matrix); | |
219 | |
220 FWL_Error StrokePathWithPattern(CFX_Path* path, CFX_Matrix* matrix); | |
221 FWL_Error StrokePathWithShading(CFX_Path* path, CFX_Matrix* matrix); | |
222 | |
223 FWL_Error FillPathWithPattern(CFX_Path* path, | |
224 FX_FillMode fillMode, | |
225 CFX_Matrix* matrix); | |
226 FWL_Error FillPathWithShading(CFX_Path* path, | |
227 FX_FillMode fillMode, | |
228 CFX_Matrix* matrix); | |
229 | |
230 FWL_Error SetDIBitsWithMatrix(CFX_DIBSource* source, CFX_Matrix* matrix); | |
231 FWL_Error CalcTextInfo(const CFX_WideString& text, | |
232 uint32_t* charCodes, | |
233 FXTEXT_CHARPOS* charPos, | |
234 CFX_RectF& rect); | |
235 | |
236 CFX_RenderDevice* m_renderDevice; | |
237 CFX_ArrayTemplate<TInfo*> m_infoStack; | |
238 std::unique_ptr<CAGG_Graphics> m_aggGraphics; | |
239 friend class CAGG_Graphics; | |
240 }; | |
241 | |
242 #endif // XFA_FXGRAPHICS_INCLUDE_CFX_GRAPHICS_H_ | |
OLD | NEW |