Home | History | Annotate | Download | only in fde
      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:
     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 
     21   ~CFDE_Pen() {
     22     if (m_pBrush && m_bAutoRelease) {
     23       m_pBrush->Release();
     24     }
     25   }
     26   virtual void Release() { delete this; }
     27 
     28   virtual int32_t GetType() const {
     29     return m_pBrush ? m_pBrush->GetType() : FDE_PENTYPE_SolidColor;
     30   }
     31 
     32   virtual FX_ARGB GetColor() const { return m_Color; }
     33   virtual void SetColor(FX_ARGB color) { m_Color = color; }
     34   virtual IFDE_Brush* GetBrush() const { return m_pBrush; }
     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   }
     42   virtual int32_t GetLineCap() const { return m_iLineCap; }
     43   virtual void SetLineCap(int32_t iLineCap) { m_iLineCap = iLineCap; }
     44   virtual int32_t GetDashStyle() const { return m_iDashStyle; }
     45   virtual void SetDashStyle(int32_t iDashStyle) { m_iDashStyle = iDashStyle; }
     46   virtual FX_FLOAT GetDashPhase() const { return m_fDashPhase; }
     47   virtual void SetDashPhase(FX_FLOAT fPhase) { m_fDashPhase = fPhase; }
     48   virtual int32_t CountDashArray() const { return m_DashArray.GetSize(); }
     49   virtual int32_t GetDashArray(CFX_FloatArray& dashArray) const {
     50     dashArray.Copy(m_DashArray);
     51     return dashArray.GetSize();
     52   }
     53   virtual void SetDashArray(const CFX_FloatArray& dashArray) {
     54     m_DashArray.Copy(dashArray);
     55   }
     56   virtual int32_t GetLineJoin() const { return m_iLineJoin; }
     57   virtual void SetLineJoin(int32_t iLineJoin) { m_iLineJoin = iLineJoin; }
     58   virtual FX_FLOAT GetMiterLimit() const { return m_fMiterLimit; }
     59   virtual void SetMiterLimit(FX_FLOAT fMiterLimit) {
     60     m_fMiterLimit = fMiterLimit;
     61   }
     62   virtual int32_t CountCompoundPatterns() const {
     63     return m_CompoundPatterns.GetSize();
     64   }
     65   virtual FX_BOOL GetCompoundPatterns(
     66       CFDE_CompoundPatterns& compoundPatterns) const {
     67     return compoundPatterns.Copy(m_CompoundPatterns), TRUE;
     68   }
     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:
     87   CFDE_SolidBrush() : m_Color(0xFF000000) { m_Matrix.SetIdentity(); }
     88 
     89   virtual void Release() { delete this; }
     90   virtual int32_t GetType() const { return FDE_BRUSHTYPE_Solid; }
     91   virtual const CFX_Matrix& GetMatrix() const { return m_Matrix; }
     92   virtual void ResetMatrix() { m_Matrix.SetIdentity(); }
     93   virtual void TranslateMatrix(FX_FLOAT dx, FX_FLOAT dy) {
     94     m_Matrix.Translate(dx, dy);
     95   }
     96   virtual void RotateMatrix(FX_FLOAT fRadian) { m_Matrix.Rotate(fRadian); }
     97   virtual void ScaleMatrix(FX_FLOAT sx, FX_FLOAT sy) { m_Matrix.Scale(sx, sy); }
     98   virtual void ConcatMatrix(const CFX_Matrix& matrix) {
     99     m_Matrix.Concat(matrix);
    100   }
    101   virtual void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; }
    102   virtual FX_ARGB GetColor() const { return m_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:
    110   CFDE_HatchBrush() : m_iStyle(-1), m_BackColor(0), m_ForeColor(0) {
    111     m_Matrix.SetIdentity();
    112   }
    113 
    114   virtual void Release() { delete this; }
    115   virtual int32_t GetType() const { return FDE_BRUSHTYPE_Hatch; }
    116   virtual const CFX_Matrix& GetMatrix() const { return m_Matrix; }
    117   virtual void ResetMatrix() { m_Matrix.SetIdentity(); }
    118   virtual void TranslateMatrix(FX_FLOAT dx, FX_FLOAT dy) {
    119     m_Matrix.Translate(dx, dy);
    120   }
    121   virtual void RotateMatrix(FX_FLOAT fRadian) { m_Matrix.Rotate(fRadian); }
    122   virtual void ScaleMatrix(FX_FLOAT sx, FX_FLOAT sy) { m_Matrix.Scale(sx, sy); }
    123   virtual void ConcatMatrix(const CFX_Matrix& matrix) {
    124     m_Matrix.Concat(matrix);
    125   }
    126   virtual void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; }
    127   virtual FX_ARGB GetColor(FX_BOOL bForegroundColor) const {
    128     return bForegroundColor ? m_ForeColor : m_BackColor;
    129   }
    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 
    138   virtual int32_t GetHatchStyle() const { return m_iStyle; };
    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:
    150   CFDE_TextureBrush() : m_iWrap(0), m_pImage(NULL), m_bAutoRelease(FALSE) {
    151     m_Matrix.SetIdentity();
    152   }
    153 
    154   virtual void Release() { delete this; }
    155   virtual int32_t GetType() const { return FDE_BRUSHTYPE_Texture; }
    156   virtual const CFX_Matrix& GetMatrix() const { return m_Matrix; }
    157   virtual void ResetMatrix() { m_Matrix.SetIdentity(); }
    158   virtual void TranslateMatrix(FX_FLOAT dx, FX_FLOAT dy) {
    159     m_Matrix.Translate(dx, dy);
    160   }
    161   virtual void RotateMatrix(FX_FLOAT fRadian) { m_Matrix.Rotate(fRadian); }
    162   virtual void ScaleMatrix(FX_FLOAT sx, FX_FLOAT sy) { m_Matrix.Scale(sx, sy); }
    163   virtual void ConcatMatrix(const CFX_Matrix& matrix) {
    164     m_Matrix.Concat(matrix);
    165   }
    166   virtual void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; }
    167   virtual IFDE_Image* GetImage() const { return m_pImage; }
    168   virtual void SetImage(IFDE_Image* pImage, FX_BOOL bAutoRelease) {
    169     m_pImage = pImage;
    170     m_bAutoRelease = bAutoRelease;
    171   }
    172   virtual int32_t GetWrapMode() const { return m_iWrap; }
    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:
    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 
    186   virtual void Release() { delete this; }
    187   virtual int32_t GetType() const { return FDE_BRUSHTYPE_LinearGradient; }
    188   virtual const CFX_Matrix& GetMatrix() const { return m_Matrix; }
    189   virtual void ResetMatrix() { m_Matrix.SetIdentity(); }
    190   virtual void TranslateMatrix(FX_FLOAT dx, FX_FLOAT dy) {
    191     m_Matrix.Translate(dx, dy);
    192   }
    193   virtual void RotateMatrix(FX_FLOAT fRadian) { m_Matrix.Rotate(fRadian); }
    194   virtual void ScaleMatrix(FX_FLOAT sx, FX_FLOAT sy) { m_Matrix.Scale(sx, sy); }
    195   virtual void ConcatMatrix(const CFX_Matrix& matrix) {
    196     m_Matrix.Concat(matrix);
    197   }
    198   virtual void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; }
    199   virtual void GetLinearPoints(CFX_PointF& startingPoint,
    200                                CFX_PointF& endingPoint) const {
    201     startingPoint = m_StartPoint;
    202     endingPoint = m_EndPoint;
    203   }
    204   virtual void SetLinearPoints(const CFX_PointF& startingPoint,
    205                                const CFX_PointF& endingPoint) {
    206     m_StartPoint = startingPoint;
    207     m_EndPoint = endingPoint;
    208   }
    209   virtual void GetLinearColors(FX_ARGB& startingColor,
    210                                FX_ARGB& endingColor) const {
    211     startingColor = m_StartColor;
    212     endingColor = m_EndColor;
    213   }
    214   virtual void SetLinearColors(const FX_ARGB& startingColor,
    215                                const FX_ARGB& endingColor) {
    216     m_StartColor = startingColor;
    217     m_EndColor = endingColor;
    218   }
    219   virtual int32_t CountGradientColors() const { return m_GradColors.GetSize(); }
    220   virtual FX_BOOL GetGradientColors(CFDE_GradientColors& colors) const {
    221     return colors.Copy(m_GradColors), TRUE;
    222   }
    223   virtual FX_BOOL SetGradientColors(const CFDE_GradientColors& colors) {
    224     return m_GradColors.Copy(colors), TRUE;
    225   }
    226 
    227   virtual int32_t GetWrapMode() const { return m_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