| 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 using FX_ERR = int; |
| 22 typedef int32_t FX_DashStyle; | 27 using FX_DeviceCap = int32_t; |
| 23 enum { | 28 using FX_FillMode = int32_t; |
| 29 |
| 30 enum FX_DashStyle { |
| 24 FX_DASHSTYLE_Solid = 0, | 31 FX_DASHSTYLE_Solid = 0, |
| 25 FX_DASHSTYLE_Dash = 1, | 32 FX_DASHSTYLE_Dash = 1, |
| 26 FX_DASHSTYLE_Dot = 2, | 33 FX_DASHSTYLE_Dot = 2, |
| 27 FX_DASHSTYLE_DashDot = 3, | 34 FX_DASHSTYLE_DashDot = 3, |
| 28 FX_DASHSTYLE_DashDotDot = 4 | 35 FX_DASHSTYLE_DashDotDot = 4 |
| 29 }; | 36 }; |
| 30 typedef int32_t FX_StrokeAlignment; | 37 |
| 31 enum { | 38 enum FX_StrokeAlignment { |
| 32 FX_STROKEALIGNMENT_Center = 0, | 39 FX_STROKEALIGNMENT_Center = 0, |
| 33 FX_STROKEALIGNMENT_Inset = 1, | 40 FX_STROKEALIGNMENT_Inset = 1, |
| 34 FX_STROKEALIGNMENT_Outset = 2, | 41 FX_STROKEALIGNMENT_Outset = 2, |
| 35 FX_STROKEALIGNMENT_Left = 3, | 42 FX_STROKEALIGNMENT_Left = 3, |
| 36 FX_STROKEALIGNMENT_Right = 4 | 43 FX_STROKEALIGNMENT_Right = 4 |
| 37 }; | 44 }; |
| 38 typedef int32_t FX_HatchStyle; | 45 |
| 39 enum { | 46 enum FX_HatchStyle { |
| 40 FX_HATCHSTYLE_Horizontal = 0, | 47 FX_HATCHSTYLE_Horizontal = 0, |
| 41 FX_HATCHSTYLE_Vertical = 1, | 48 FX_HATCHSTYLE_Vertical = 1, |
| 42 FX_HATCHSTYLE_ForwardDiagonal = 2, | 49 FX_HATCHSTYLE_ForwardDiagonal = 2, |
| 43 FX_HATCHSTYLE_BackwardDiagonal = 3, | 50 FX_HATCHSTYLE_BackwardDiagonal = 3, |
| 44 FX_HATCHSTYLE_Cross = 4, | 51 FX_HATCHSTYLE_Cross = 4, |
| 45 FX_HATCHSTYLE_DiagonalCross = 5, | 52 FX_HATCHSTYLE_DiagonalCross = 5, |
| 46 FX_HATCHSTYLE_05Percent = 6, | 53 FX_HATCHSTYLE_05Percent = 6, |
| 47 FX_HATCHSTYLE_10Percent = 7, | 54 FX_HATCHSTYLE_10Percent = 7, |
| 48 FX_HATCHSTYLE_20Percent = 8, | 55 FX_HATCHSTYLE_20Percent = 8, |
| 49 FX_HATCHSTYLE_25Percent = 9, | 56 FX_HATCHSTYLE_25Percent = 9, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 FX_HATCHSTYLE_DottedDiamond = 44, | 91 FX_HATCHSTYLE_DottedDiamond = 44, |
| 85 FX_HATCHSTYLE_Shingle = 45, | 92 FX_HATCHSTYLE_Shingle = 45, |
| 86 FX_HATCHSTYLE_Trellis = 46, | 93 FX_HATCHSTYLE_Trellis = 46, |
| 87 FX_HATCHSTYLE_Sphere = 47, | 94 FX_HATCHSTYLE_Sphere = 47, |
| 88 FX_HATCHSTYLE_SmallGrid = 48, | 95 FX_HATCHSTYLE_SmallGrid = 48, |
| 89 FX_HATCHSTYLE_SmallCheckerBoard = 49, | 96 FX_HATCHSTYLE_SmallCheckerBoard = 49, |
| 90 FX_HATCHSTYLE_LargeCheckerBoard = 50, | 97 FX_HATCHSTYLE_LargeCheckerBoard = 50, |
| 91 FX_HATCHSTYLE_OutlinedDiamond = 51, | 98 FX_HATCHSTYLE_OutlinedDiamond = 51, |
| 92 FX_HATCHSTYLE_SolidDiamond = 52 | 99 FX_HATCHSTYLE_SolidDiamond = 52 |
| 93 }; | 100 }; |
| 94 typedef int32_t FX_DeviceCap; | 101 |
| 95 typedef int32_t FX_FillMode; | |
| 96 class CFX_RenderDevice; | 102 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 | 103 |
| 124 class CFX_Graphics { | 104 class CFX_Graphics { |
| 125 public: | 105 public: |
| 126 CFX_Graphics(); | 106 CFX_Graphics(); |
| 127 virtual ~CFX_Graphics(); | 107 virtual ~CFX_Graphics(); |
| 128 | 108 |
| 129 FX_ERR Create(CFX_RenderDevice* renderDevice, FX_BOOL isAntialiasing = TRUE); | 109 FX_ERR Create(CFX_RenderDevice* renderDevice, FX_BOOL isAntialiasing = TRUE); |
| 130 FX_ERR Create(int32_t width, | 110 FX_ERR Create(int32_t width, |
| 131 int32_t height, | 111 int32_t height, |
| 132 FXDIB_Format format, | 112 FXDIB_Format format, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 FX_ERR Transfer(CFX_Graphics* graphics, | 175 FX_ERR Transfer(CFX_Graphics* graphics, |
| 196 FX_FLOAT srcLeft, | 176 FX_FLOAT srcLeft, |
| 197 FX_FLOAT srcTop, | 177 FX_FLOAT srcTop, |
| 198 const CFX_RectF& dstRect, | 178 const CFX_RectF& dstRect, |
| 199 const CFX_Matrix* matrix); | 179 const CFX_Matrix* matrix); |
| 200 | 180 |
| 201 FX_ERR InverseRect(const CFX_RectF& rect); | 181 FX_ERR InverseRect(const CFX_RectF& rect); |
| 202 FX_ERR XorDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); | 182 FX_ERR XorDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); |
| 203 FX_ERR EqvDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); | 183 FX_ERR EqvDIBitmap(const CFX_DIBitmap* srcBitmap, const CFX_RectF& rect); |
| 204 | 184 |
| 185 protected: |
| 186 int32_t m_type; |
| 187 |
| 205 private: | 188 private: |
| 189 struct TInfo { |
| 190 TInfo() |
| 191 : isAntialiasing(TRUE), |
| 192 strokeAlignment(FX_STROKEALIGNMENT_Center), |
| 193 isActOnDash(FALSE), |
| 194 strokeColor(nullptr), |
| 195 fillColor(nullptr), |
| 196 font(nullptr), |
| 197 fontSize(40.0), |
| 198 fontHScale(1.0), |
| 199 fontSpacing(0.0) {} |
| 200 explicit TInfo(const TInfo& info); |
| 201 TInfo& operator=(const TInfo& other); |
| 202 |
| 203 CFX_GraphStateData graphState; |
| 204 FX_BOOL isAntialiasing; |
| 205 FX_StrokeAlignment strokeAlignment; |
| 206 CFX_Matrix CTM; |
| 207 FX_BOOL isActOnDash; |
| 208 CFX_Color* strokeColor; |
| 209 CFX_Color* fillColor; |
| 210 CFX_Font* font; |
| 211 FX_FLOAT fontSize; |
| 212 FX_FLOAT fontHScale; |
| 213 FX_FLOAT fontSpacing; |
| 214 } m_info; |
| 215 |
| 206 FX_ERR RenderDeviceSetLineDash(FX_DashStyle dashStyle); | 216 FX_ERR RenderDeviceSetLineDash(FX_DashStyle dashStyle); |
| 207 FX_ERR RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix); | 217 FX_ERR RenderDeviceStrokePath(CFX_Path* path, CFX_Matrix* matrix); |
| 208 FX_ERR RenderDeviceFillPath(CFX_Path* path, | 218 FX_ERR RenderDeviceFillPath(CFX_Path* path, |
| 209 FX_FillMode fillMode, | 219 FX_FillMode fillMode, |
| 210 CFX_Matrix* matrix); | 220 CFX_Matrix* matrix); |
| 211 FX_ERR RenderDeviceDrawImage(CFX_DIBSource* source, | 221 FX_ERR RenderDeviceDrawImage(CFX_DIBSource* source, |
| 212 const CFX_PointF& point, | 222 const CFX_PointF& point, |
| 213 CFX_Matrix* matrix); | 223 CFX_Matrix* matrix); |
| 214 FX_ERR RenderDeviceStretchImage(CFX_DIBSource* source, | 224 FX_ERR RenderDeviceStretchImage(CFX_DIBSource* source, |
| 215 const CFX_RectF& rect, | 225 const CFX_RectF& rect, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 227 FX_ERR FillPathWithShading(CFX_Path* path, | 237 FX_ERR FillPathWithShading(CFX_Path* path, |
| 228 FX_FillMode fillMode, | 238 FX_FillMode fillMode, |
| 229 CFX_Matrix* matrix); | 239 CFX_Matrix* matrix); |
| 230 | 240 |
| 231 FX_ERR SetDIBitsWithMatrix(CFX_DIBSource* source, CFX_Matrix* matrix); | 241 FX_ERR SetDIBitsWithMatrix(CFX_DIBSource* source, CFX_Matrix* matrix); |
| 232 FX_ERR CalcTextInfo(const CFX_WideString& text, | 242 FX_ERR CalcTextInfo(const CFX_WideString& text, |
| 233 FX_DWORD* charCodes, | 243 FX_DWORD* charCodes, |
| 234 FXTEXT_CHARPOS* charPos, | 244 FXTEXT_CHARPOS* charPos, |
| 235 CFX_RectF& rect); | 245 CFX_RectF& rect); |
| 236 | 246 |
| 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; | 247 CFX_RenderDevice* m_renderDevice; |
| 268 CFX_PtrArray m_infoStack; | 248 CFX_PtrArray m_infoStack; |
| 269 CAGG_Graphics* m_aggGraphics; | 249 CAGG_Graphics* m_aggGraphics; |
| 270 friend class CAGG_Graphics; | 250 friend class CAGG_Graphics; |
| 271 }; | 251 }; |
| 272 | 252 |
| 273 class CFX_Path { | 253 #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 |