1 // Copyright 2014 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 _FDE_BASEOBJECT_IMP 8 #define _FDE_BASEOBJECT_IMP 9 class CFDE_Pen : public IFDE_Pen, public CFX_Target { 10 public: CFDE_Pen()11 CFDE_Pen() 12 : m_Color(0), 13 m_iLineCap(0), 14 m_iLineJoin(0), 15 m_iDashStyle(0), 16 m_fDashPhase(0), 17 m_fMiterLimit(10), 18 m_bAutoRelease(FALSE), 19 m_pBrush(NULL) {} 20 ~CFDE_Pen()21 ~CFDE_Pen() { 22 if (m_pBrush && m_bAutoRelease) { 23 m_pBrush->Release(); 24 } 25 } Release()26 virtual void Release() { delete this; } 27 GetType()28 virtual int32_t GetType() const { 29 return m_pBrush ? m_pBrush->GetType() : FDE_PENTYPE_SolidColor; 30 } 31 GetColor()32 virtual FX_ARGB GetColor() const { return m_Color; } SetColor(FX_ARGB color)33 virtual void SetColor(FX_ARGB color) { m_Color = color; } GetBrush()34 virtual IFDE_Brush* GetBrush() const { return m_pBrush; } SetBrush(IFDE_Brush * pBrush,FX_BOOL bAutoRelease)35 virtual void SetBrush(IFDE_Brush* pBrush, FX_BOOL bAutoRelease) { 36 m_bAutoRelease = bAutoRelease; 37 m_pBrush = pBrush; 38 if (m_pBrush && m_pBrush->GetType() == FDE_BRUSHTYPE_Solid) { 39 m_Color = ((IFDE_SolidBrush*)m_pBrush)->GetColor(); 40 } 41 } GetLineCap()42 virtual int32_t GetLineCap() const { return m_iLineCap; } SetLineCap(int32_t iLineCap)43 virtual void SetLineCap(int32_t iLineCap) { m_iLineCap = iLineCap; } GetDashStyle()44 virtual int32_t GetDashStyle() const { return m_iDashStyle; } SetDashStyle(int32_t iDashStyle)45 virtual void SetDashStyle(int32_t iDashStyle) { m_iDashStyle = iDashStyle; } GetDashPhase()46 virtual FX_FLOAT GetDashPhase() const { return m_fDashPhase; } SetDashPhase(FX_FLOAT fPhase)47 virtual void SetDashPhase(FX_FLOAT fPhase) { m_fDashPhase = fPhase; } CountDashArray()48 virtual int32_t CountDashArray() const { return m_DashArray.GetSize(); } GetDashArray(CFX_FloatArray & dashArray)49 virtual int32_t GetDashArray(CFX_FloatArray& dashArray) const { 50 dashArray.Copy(m_DashArray); 51 return dashArray.GetSize(); 52 } SetDashArray(const CFX_FloatArray & dashArray)53 virtual void SetDashArray(const CFX_FloatArray& dashArray) { 54 m_DashArray.Copy(dashArray); 55 } GetLineJoin()56 virtual int32_t GetLineJoin() const { return m_iLineJoin; } SetLineJoin(int32_t iLineJoin)57 virtual void SetLineJoin(int32_t iLineJoin) { m_iLineJoin = iLineJoin; } GetMiterLimit()58 virtual FX_FLOAT GetMiterLimit() const { return m_fMiterLimit; } SetMiterLimit(FX_FLOAT fMiterLimit)59 virtual void SetMiterLimit(FX_FLOAT fMiterLimit) { 60 m_fMiterLimit = fMiterLimit; 61 } CountCompoundPatterns()62 virtual int32_t CountCompoundPatterns() const { 63 return m_CompoundPatterns.GetSize(); 64 } GetCompoundPatterns(CFDE_CompoundPatterns & compoundPatterns)65 virtual FX_BOOL GetCompoundPatterns( 66 CFDE_CompoundPatterns& compoundPatterns) const { 67 return compoundPatterns.Copy(m_CompoundPatterns), TRUE; 68 } SetCompoundPatterns(const CFDE_CompoundPatterns & compoundPatterns)69 virtual FX_BOOL SetCompoundPatterns( 70 const CFDE_CompoundPatterns& compoundPatterns) { 71 return m_CompoundPatterns.Copy(compoundPatterns), TRUE; 72 } 73 74 FX_ARGB m_Color; 75 int32_t m_iLineCap; 76 int32_t m_iLineJoin; 77 int32_t m_iDashStyle; 78 FX_FLOAT m_fDashPhase; 79 FX_FLOAT m_fMiterLimit; 80 FX_BOOL m_bAutoRelease; 81 IFDE_Brush* m_pBrush; 82 CFX_FloatArray m_DashArray; 83 CFDE_CompoundPatterns m_CompoundPatterns; 84 }; 85 class CFDE_SolidBrush : public IFDE_SolidBrush, public CFX_Target { 86 public: CFDE_SolidBrush()87 CFDE_SolidBrush() : m_Color(0xFF000000) { m_Matrix.SetIdentity(); } 88 Release()89 virtual void Release() { delete this; } GetType()90 virtual int32_t GetType() const { return FDE_BRUSHTYPE_Solid; } GetMatrix()91 virtual const CFX_Matrix& GetMatrix() const { return m_Matrix; } ResetMatrix()92 virtual void ResetMatrix() { m_Matrix.SetIdentity(); } TranslateMatrix(FX_FLOAT dx,FX_FLOAT dy)93 virtual void TranslateMatrix(FX_FLOAT dx, FX_FLOAT dy) { 94 m_Matrix.Translate(dx, dy); 95 } RotateMatrix(FX_FLOAT fRadian)96 virtual void RotateMatrix(FX_FLOAT fRadian) { m_Matrix.Rotate(fRadian); } ScaleMatrix(FX_FLOAT sx,FX_FLOAT sy)97 virtual void ScaleMatrix(FX_FLOAT sx, FX_FLOAT sy) { m_Matrix.Scale(sx, sy); } ConcatMatrix(const CFX_Matrix & matrix)98 virtual void ConcatMatrix(const CFX_Matrix& matrix) { 99 m_Matrix.Concat(matrix); 100 } SetMatrix(const CFX_Matrix & matrix)101 virtual void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } GetColor()102 virtual FX_ARGB GetColor() const { return m_Color; } SetColor(FX_ARGB color)103 virtual void SetColor(FX_ARGB color) { m_Color = color; } 104 105 FX_ARGB m_Color; 106 CFX_Matrix m_Matrix; 107 }; 108 class CFDE_HatchBrush : public IFDE_HatchBrush, public CFX_Target { 109 public: CFDE_HatchBrush()110 CFDE_HatchBrush() : m_iStyle(-1), m_BackColor(0), m_ForeColor(0) { 111 m_Matrix.SetIdentity(); 112 } 113 Release()114 virtual void Release() { delete this; } GetType()115 virtual int32_t GetType() const { return FDE_BRUSHTYPE_Hatch; } GetMatrix()116 virtual const CFX_Matrix& GetMatrix() const { return m_Matrix; } ResetMatrix()117 virtual void ResetMatrix() { m_Matrix.SetIdentity(); } TranslateMatrix(FX_FLOAT dx,FX_FLOAT dy)118 virtual void TranslateMatrix(FX_FLOAT dx, FX_FLOAT dy) { 119 m_Matrix.Translate(dx, dy); 120 } RotateMatrix(FX_FLOAT fRadian)121 virtual void RotateMatrix(FX_FLOAT fRadian) { m_Matrix.Rotate(fRadian); } ScaleMatrix(FX_FLOAT sx,FX_FLOAT sy)122 virtual void ScaleMatrix(FX_FLOAT sx, FX_FLOAT sy) { m_Matrix.Scale(sx, sy); } ConcatMatrix(const CFX_Matrix & matrix)123 virtual void ConcatMatrix(const CFX_Matrix& matrix) { 124 m_Matrix.Concat(matrix); 125 } SetMatrix(const CFX_Matrix & matrix)126 virtual void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } GetColor(FX_BOOL bForegroundColor)127 virtual FX_ARGB GetColor(FX_BOOL bForegroundColor) const { 128 return bForegroundColor ? m_ForeColor : m_BackColor; 129 } SetColor(FX_ARGB color,FX_BOOL bForegroundColor)130 virtual void SetColor(FX_ARGB color, FX_BOOL bForegroundColor) { 131 if (bForegroundColor) { 132 m_ForeColor = color; 133 } else { 134 m_BackColor = color; 135 } 136 } 137 GetHatchStyle()138 virtual int32_t GetHatchStyle() const { return m_iStyle; }; SetHatchStyle(int32_t iHatchStyle)139 virtual FX_BOOL SetHatchStyle(int32_t iHatchStyle) { 140 m_iStyle = iHatchStyle; 141 return m_iStyle >= FDE_HATCHSTYLE_Min && m_iStyle <= FDE_HATCHSTYLE_Max; 142 } 143 int32_t m_iStyle; 144 FX_ARGB m_BackColor; 145 FX_ARGB m_ForeColor; 146 CFX_Matrix m_Matrix; 147 }; 148 class CFDE_TextureBrush : public IFDE_TextureBrush, public CFX_Target { 149 public: CFDE_TextureBrush()150 CFDE_TextureBrush() : m_iWrap(0), m_pImage(NULL), m_bAutoRelease(FALSE) { 151 m_Matrix.SetIdentity(); 152 } 153 Release()154 virtual void Release() { delete this; } GetType()155 virtual int32_t GetType() const { return FDE_BRUSHTYPE_Texture; } GetMatrix()156 virtual const CFX_Matrix& GetMatrix() const { return m_Matrix; } ResetMatrix()157 virtual void ResetMatrix() { m_Matrix.SetIdentity(); } TranslateMatrix(FX_FLOAT dx,FX_FLOAT dy)158 virtual void TranslateMatrix(FX_FLOAT dx, FX_FLOAT dy) { 159 m_Matrix.Translate(dx, dy); 160 } RotateMatrix(FX_FLOAT fRadian)161 virtual void RotateMatrix(FX_FLOAT fRadian) { m_Matrix.Rotate(fRadian); } ScaleMatrix(FX_FLOAT sx,FX_FLOAT sy)162 virtual void ScaleMatrix(FX_FLOAT sx, FX_FLOAT sy) { m_Matrix.Scale(sx, sy); } ConcatMatrix(const CFX_Matrix & matrix)163 virtual void ConcatMatrix(const CFX_Matrix& matrix) { 164 m_Matrix.Concat(matrix); 165 } SetMatrix(const CFX_Matrix & matrix)166 virtual void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } GetImage()167 virtual IFDE_Image* GetImage() const { return m_pImage; } SetImage(IFDE_Image * pImage,FX_BOOL bAutoRelease)168 virtual void SetImage(IFDE_Image* pImage, FX_BOOL bAutoRelease) { 169 m_pImage = pImage; 170 m_bAutoRelease = bAutoRelease; 171 } GetWrapMode()172 virtual int32_t GetWrapMode() const { return m_iWrap; } SetWrapMode(int32_t iWrapMode)173 virtual void SetWrapMode(int32_t iWrapMode) { m_iWrap = iWrapMode; } 174 int32_t m_iWrap; 175 IFDE_Image* m_pImage; 176 FX_BOOL m_bAutoRelease; 177 CFX_Matrix m_Matrix; 178 }; 179 class CFDE_LinearBrush : public IFDE_LinearGradientBrush, public CFX_Target { 180 public: CFDE_LinearBrush()181 CFDE_LinearBrush() : m_EndColor(0), m_StartColor(0), m_iWrapMode(0) { 182 m_StartPoint.x = m_StartPoint.y = m_EndPoint.x = m_EndPoint.y = 0; 183 m_Matrix.SetIdentity(); 184 } 185 Release()186 virtual void Release() { delete this; } GetType()187 virtual int32_t GetType() const { return FDE_BRUSHTYPE_LinearGradient; } GetMatrix()188 virtual const CFX_Matrix& GetMatrix() const { return m_Matrix; } ResetMatrix()189 virtual void ResetMatrix() { m_Matrix.SetIdentity(); } TranslateMatrix(FX_FLOAT dx,FX_FLOAT dy)190 virtual void TranslateMatrix(FX_FLOAT dx, FX_FLOAT dy) { 191 m_Matrix.Translate(dx, dy); 192 } RotateMatrix(FX_FLOAT fRadian)193 virtual void RotateMatrix(FX_FLOAT fRadian) { m_Matrix.Rotate(fRadian); } ScaleMatrix(FX_FLOAT sx,FX_FLOAT sy)194 virtual void ScaleMatrix(FX_FLOAT sx, FX_FLOAT sy) { m_Matrix.Scale(sx, sy); } ConcatMatrix(const CFX_Matrix & matrix)195 virtual void ConcatMatrix(const CFX_Matrix& matrix) { 196 m_Matrix.Concat(matrix); 197 } SetMatrix(const CFX_Matrix & matrix)198 virtual void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } GetLinearPoints(CFX_PointF & startingPoint,CFX_PointF & endingPoint)199 virtual void GetLinearPoints(CFX_PointF& startingPoint, 200 CFX_PointF& endingPoint) const { 201 startingPoint = m_StartPoint; 202 endingPoint = m_EndPoint; 203 } SetLinearPoints(const CFX_PointF & startingPoint,const CFX_PointF & endingPoint)204 virtual void SetLinearPoints(const CFX_PointF& startingPoint, 205 const CFX_PointF& endingPoint) { 206 m_StartPoint = startingPoint; 207 m_EndPoint = endingPoint; 208 } GetLinearColors(FX_ARGB & startingColor,FX_ARGB & endingColor)209 virtual void GetLinearColors(FX_ARGB& startingColor, 210 FX_ARGB& endingColor) const { 211 startingColor = m_StartColor; 212 endingColor = m_EndColor; 213 } SetLinearColors(const FX_ARGB & startingColor,const FX_ARGB & endingColor)214 virtual void SetLinearColors(const FX_ARGB& startingColor, 215 const FX_ARGB& endingColor) { 216 m_StartColor = startingColor; 217 m_EndColor = endingColor; 218 } CountGradientColors()219 virtual int32_t CountGradientColors() const { return m_GradColors.GetSize(); } GetGradientColors(CFDE_GradientColors & colors)220 virtual FX_BOOL GetGradientColors(CFDE_GradientColors& colors) const { 221 return colors.Copy(m_GradColors), TRUE; 222 } SetGradientColors(const CFDE_GradientColors & colors)223 virtual FX_BOOL SetGradientColors(const CFDE_GradientColors& colors) { 224 return m_GradColors.Copy(colors), TRUE; 225 } 226 GetWrapMode()227 virtual int32_t GetWrapMode() const { return m_iWrapMode; } SetWrapMode(int32_t iWrapMode)228 virtual void SetWrapMode(int32_t iWrapMode) { m_iWrapMode = iWrapMode; } 229 CFX_PointF m_EndPoint; 230 CFX_PointF m_StartPoint; 231 FX_ARGB m_EndColor; 232 FX_ARGB m_StartColor; 233 CFDE_GradientColors m_GradColors; 234 int32_t m_iWrapMode; 235 CFX_Matrix m_Matrix; 236 }; 237 #endif 238