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