1 /* 2 For general Scribus (>=1.3.2) copyright and licensing information please refer 3 to the COPYING file provided with the program. Following this notice may exist 4 a copyright and/or license notice that predates the release of Scribus 1.3.2 5 for which a new license (GPL+exception) is in place. 6 */ 7 8 #ifndef SCPAINTEREX_CAIRO_H 9 #define SCPAINTEREX_CAIRO_H 10 11 #include <cairo.h> 12 #include "scpainterexbase.h" 13 14 #include "mesh.h" 15 16 class ScPainterEx_Cairo : public ScPainterExBase 17 { 18 public: 19 ScPainterEx_Cairo(cairo_t* context, QRect& rect, ScribusDoc* doc, bool gray ); 20 virtual ~ScPainterEx_Cairo(); 21 capabilities()22 virtual Capabilities capabilities() { return transparencies; } 23 supportedColorModes()24 virtual int supportedColorModes() { return (int) rgbMode; } preferredColorMode()25 virtual ColorMode preferredColorMode() { return rgbMode; } imageMode()26 virtual ImageMode imageMode() { return rgbImages; } 27 28 virtual void begin(); 29 virtual void end(); 30 virtual void clear(); 31 virtual void clear( ScColorShade & ); 32 33 // matrix manipulation 34 virtual void setWorldMatrix( const QTransform & ); 35 virtual const QTransform worldMatrix(); 36 virtual void translate( double, double ); 37 virtual void translate( const QPointF& offset ); 38 virtual void rotate( double ); 39 virtual void scale( double, double ); 40 41 // drawing 42 virtual void moveTo( const double &, const double & ); 43 virtual void lineTo( const double &, const double & ); 44 virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 ); 45 virtual void newPath(); 46 virtual void closePath(); 47 virtual void fillPath(); 48 virtual void strokePath(); 49 virtual void setFillRule( bool fillRule ); fillRule()50 virtual bool fillRule() { return m_fillRule; } 51 virtual void setFillMode( int fill ); fillMode()52 virtual int fillMode() { return m_fillMode; } 53 virtual void setStrokeMode( int fill ); strokeMode()54 virtual int strokeMode() { return m_strokeMode; } 55 virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc, double scale, double skew); 56 virtual void setPattern(ScPattern *pattern, double scaleX, double scaleY, double offsetX, double offsetY, double rotation, double skewX, double skewY, bool mirrorX, bool mirrorY); 57 58 virtual void setMaskMode( int mask ); 59 virtual void setGradientMask(VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc, double scale, double skew); 60 virtual void setPatternMask(ScPattern *pattern, double scaleX, double scaleY, double offsetX, double offsetY, double rotation, double skewX, double skewY, bool mirrorX, bool mirrorY); 61 62 virtual void set4ColorGeometry(FPoint p1, FPoint p2, FPoint p3, FPoint p4, FPoint c1, FPoint c2, FPoint c3, FPoint c4); 63 virtual void set4ColorColors(const ScColorShade& col1, const ScColorShade& col2, const ScColorShade& col3, const ScColorShade& col4); 64 virtual void setDiamondGeometry(FPoint p1, FPoint p2, FPoint p3, FPoint p4, FPoint c1, FPoint c2, FPoint c3, FPoint c4, FPoint c5); 65 virtual void setMeshGradient(FPoint p1, FPoint p2, FPoint p3, FPoint p4, QList<QList<MeshPoint> > meshArray); 66 virtual void setMeshGradient(FPoint p1, FPoint p2, FPoint p3, FPoint p4, QList<meshGradientPatch> meshPatches); 67 68 virtual void setClipPath(); 69 70 virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode ); 71 virtual void setupPolygon(const FPointArray *points, bool closed = true); 72 virtual void drawPolygon(); 73 virtual void drawPolyLine(); 74 virtual void drawLine(FPoint start, FPoint end); 75 virtual void drawLine(const QPointF& start, const QPointF& end); 76 virtual void drawRect(double, double, double, double); 77 78 // pen + brush 79 virtual ScColorShade pen(); 80 virtual ScColorShade brush(); 81 virtual void setPen( const ScColorShade & ); 82 virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo ); 83 virtual void setPenOpacity( double op ); 84 virtual void setLineWidth( double w); 85 virtual void setDash(const QVector<double>& array, double ofs); 86 virtual void setBrush( const ScColorShade & ); 87 virtual void setBrushOpacity( double op ); 88 virtual void setOpacity( double op ); 89 virtual void setFont( const QFont &f ); 90 virtual QFont font(); 91 92 // stack management 93 virtual void save(); 94 virtual void restore(); 95 96 virtual void setRasterOp( int op ); 97 virtual void setBlendModeFill( int blendMode ); 98 virtual void setBlendModeStroke( int blendMode ); 99 100 private: 101 void fillPathHelper(); 102 void strokePathHelper(); 103 104 void drawGradient( VGradientEx& gradient ); 105 void drawLinearGradient( VGradientEx& gradient, const QRect& rect ); 106 void drawCircularGradient( VGradientEx& gradient, const QRect& rect ); 107 void drawFourColorGradient( const QRect& rect ); 108 void drawDiamondGradient( VGradientEx& gradient, const QRect& rect ); 109 void drawMeshGradient( const QRect& rect ); 110 void drawFreeMeshGradient( const QRect& rect ); 111 112 void strokeGradient( VGradientEx& gradient ); 113 void strokeLinearGradient( VGradientEx& gradient ); 114 void strokeCircularGradient( VGradientEx& gradient ); 115 116 void getClipPathDimensions( QRect& r ); 117 118 ScribusDoc* m_doc; 119 120 unsigned int m_width; 121 unsigned int m_height; 122 QTransform m_matrix; 123 QFont m_font; 124 /* Layer blend mode*/ 125 int m_blendModeLayer; 126 int m_blendModeFill; 127 int m_blendModeStroke; 128 /* Filling */ 129 ScColorShade m_fillColor; 130 double m_fillTrans; 131 bool m_fillRule; 132 int m_fillMode; // 0 = none, 1 = solid, 2 = gradient 133 int m_gradientMode; // 1 = linear, 2 = radial 134 135 double m_patternScaleX; 136 double m_patternScaleY; 137 double m_patternOffsetX; 138 double m_patternOffsetY; 139 double m_patternRotation; 140 double m_patternSkewX; 141 double m_patternSkewY; 142 bool m_patternMirrorX; 143 bool m_patternMirrorY; 144 145 FPoint m_gradPatchP1; 146 FPoint m_gradPatchP2; 147 FPoint m_gradPatchP3; 148 FPoint m_gradPatchP4; 149 FPoint m_gradControlP1; 150 FPoint m_gradControlP2; 151 FPoint m_gradControlP3; 152 FPoint m_gradControlP4; 153 FPoint m_gradControlP5; 154 ScColorShade m_gradPatchColor1; 155 ScColorShade m_gradPatchColor2; 156 ScColorShade m_gradPatchColor3; 157 ScColorShade m_gradPatchColor4; 158 QList<QList<MeshPoint> > m_meshGradientArray; 159 QList<meshGradientPatch> m_meshGradientPatches; 160 161 double m_gradientScale; 162 double m_gradientSkew; 163 /* Stroking */ 164 ScColorShade m_strokeColor; 165 double m_strokeTrans; 166 double m_lineWidth; 167 int m_strokeMode; // 0 = none, 1 = solid, 2 = gradient 3 = pattern 168 /* Masking */ 169 int m_maskMode; // 0 = none, 1 = gradient 2 = pattern 170 double m_maskPatternScaleX; 171 double m_maskPatternScaleY; 172 double m_maskPatternOffsetX; 173 double m_maskPatternOffsetY; 174 double m_maskPatternRotation; 175 double m_maskPatternSkewX; 176 double m_maskPatternSkewY; 177 bool m_maskPatternMirrorX; 178 bool m_maskPatternMirrorY; 179 double m_maskGradientScale; 180 double m_maskGradientSkew; 181 182 /* Grayscale conversion option */ 183 bool m_convertToGray; 184 185 /* Line End Style */ 186 Qt::PenCapStyle m_lineEnd; 187 /* Line Join Style */ 188 Qt::PenJoinStyle m_lineJoin; 189 /* The Dash Array */ 190 QVector<double> m_array; 191 double m_offset; 192 /* Transformation Stack */ 193 QStack<QTransform> m_stack; 194 195 /* Cairo context */ 196 cairo_t* m_cr; 197 198 /* Color conversion function */ 199 QColor transformColor( ScColorShade& colorShade, double trans ); 200 void transformImage( QImage& image ); 201 202 QStack<int> m_gStates; 203 double m_positionX; 204 double m_positionY; 205 }; 206 207 #endif 208