r17284 by jghali - more updates for win32 printing
scribus-commit
scribus-commit at lists.scribus.net
Tue Feb 7 23:02:12 UTC 2012
Author: jghali
Date: Tue Feb 7 23:02:12 2012
New Revision: 17284
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17284
Log:
more updates for win32 printing
Modified:
trunk/Scribus/scribus/scpainterex_cairo.cpp
trunk/Scribus/scribus/scpainterex_cairo.h
Modified: trunk/Scribus/scribus/scpainterex_cairo.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17284&path=/trunk/Scribus/scribus/scpainterex_cairo.cpp
==============================================================================
--- trunk/Scribus/scribus/scpainterex_cairo.cpp (original)
+++ trunk/Scribus/scribus/scpainterex_cairo.cpp Tue Feb 7 23:02:12 2012
@@ -496,20 +496,12 @@
}
else
{
- double r, g, b;
- QColor strokeColor = transformColor( m_strokeColor, 1.0 );
- strokeColor.getRgbF(&r, &g, &b);
- cairo_set_source_rgba( m_cr, r, g, b, m_strokeTrans );
-
cairo_set_line_width( m_cr, m_lineWidth );
if( m_array.count() > 0 )
cairo_set_dash( m_cr, m_array.data(), m_array.count(), static_cast<double>(m_offset));
else
cairo_set_dash( m_cr, NULL, 0, 0 );
- if (m_strokeTrans != 1.0)
- cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
- else
- cairo_set_operator(m_cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
if( m_lineEnd == Qt::RoundCap )
cairo_set_line_cap (m_cr, CAIRO_LINE_CAP_ROUND);
else if( m_lineEnd == Qt::SquareCap )
@@ -522,7 +514,24 @@
cairo_set_line_join( m_cr, CAIRO_LINE_JOIN_BEVEL );
else if( m_lineJoin == Qt::MiterJoin )
cairo_set_line_join( m_cr, CAIRO_LINE_JOIN_MITER );
- cairo_stroke_preserve( m_cr );
+ if (m_strokeMode == 3)
+ {
+
+ }
+ else if (m_strokeMode == 2)
+ {
+ strokeGradient(m_strokeGradient);
+ }
+ else
+ {
+ double r, g, b;
+ QColor strokeColor = transformColor( m_strokeColor, 1.0 );
+ strokeColor.getRgbF(&r, &g, &b);
+ cairo_set_source_rgba( m_cr, r, g, b, m_strokeTrans );
+ setRasterOp(m_blendModeStroke);
+ cairo_stroke_preserve( m_cr );
+ }
+
}
cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
cairo_restore( m_cr );
@@ -759,7 +768,7 @@
cairo_pattern_set_filter(pat, CAIRO_FILTER_GOOD);
cairo_set_source (m_cr, pat);
- cairo_clip_preserve (m_cr);
+ //cairo_clip_preserve (m_cr);
if (m_maskMode > 0)
{
@@ -973,7 +982,7 @@
cairo_pattern_set_filter(pat, CAIRO_FILTER_GOOD);
cairo_set_source (m_cr, pat);
- cairo_clip_preserve (m_cr);
+ //cairo_clip_preserve (m_cr);
if (m_maskMode > 0)
{
@@ -1051,7 +1060,7 @@
cairo_pattern_set_filter(pat, CAIRO_FILTER_BEST);
cairo_set_source (m_cr, pat);
- cairo_clip_preserve (m_cr);
+ //cairo_clip_preserve (m_cr);
if (m_maskMode > 0)
{
@@ -1127,7 +1136,7 @@
cairo_pattern_set_filter(pat, CAIRO_FILTER_BEST);
cairo_set_source (m_cr, pat);
- cairo_clip_preserve (m_cr);
+ //cairo_clip_preserve (m_cr);
if (m_maskMode > 0)
{
@@ -1150,6 +1159,124 @@
if (cr) cairo_destroy( cr );
}
+void ScPainterEx_Cairo::strokeGradient(VGradientEx& gradient)
+{
+ save();
+ if ( gradient.type() == VGradientEx::linear )
+ strokeLinearGradient(gradient);
+ else if ( gradient.type() == VGradientEx::radial )
+ strokeCircularGradient(gradient);
+ restore();
+}
+
+void ScPainterEx_Cairo::strokeLinearGradient(VGradientEx& gradient)
+{
+ cairo_pattern_t *pat = NULL;
+ double r, g, b, lastPoint = 0.0;
+ double x1 = gradient.origin().x();
+ double y1 = gradient.origin().y();
+ double x2 = gradient.vector().x();
+ double y2 = gradient.vector().y();
+ double fx = gradient.focalPoint().x();
+ double fy = gradient.focalPoint().y();
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx* stop = NULL;
+ QColor color;
+
+ cairo_push_group(m_cr);
+
+ pat = cairo_pattern_create_linear (x1, y1, x2, y2);
+ cairo_pattern_set_extend(pat, CAIRO_EXTEND_PAD);
+ cairo_pattern_set_filter(pat, CAIRO_FILTER_GOOD);
+
+ bool isFirst = true;
+ double lastStop = 0.0;
+ for( uint index = 0 ; index < gradient.Stops(); index++)
+ {
+ stop = colorStops.at(index);
+ if ((lastStop == stop->rampPoint) && (!isFirst))
+ continue;
+ isFirst = false;
+ color = transformColor( ScColorShade(stop->color, stop->shade), 1.0 );
+ color.getRgbF(&r, &g, &b);
+ cairo_pattern_add_color_stop_rgba (pat, stop->rampPoint, r, g, b, stop->opacity);
+ lastStop = stop->rampPoint;
+ }
+
+ cairo_matrix_t matrix;
+ QTransform qmatrix;
+ qmatrix.translate(x1, y1);
+ qmatrix.shear(-m_gradientSkew, 0);
+ qmatrix.translate(-x1, -y1);
+ cairo_matrix_init(&matrix, qmatrix.m11(), qmatrix.m12(), qmatrix.m21(), qmatrix.m22(), qmatrix.dx(), qmatrix.dy());
+ cairo_matrix_invert(&matrix);
+ cairo_pattern_set_matrix (pat, &matrix);
+ cairo_set_source (m_cr, pat);
+ cairo_stroke_preserve( m_cr );
+ cairo_pattern_destroy (pat);
+
+ cairo_pop_group_to_source (m_cr);
+
+ setRasterOp(m_blendModeStroke);
+ cairo_paint_with_alpha (m_cr, m_strokeTrans);
+}
+
+void ScPainterEx_Cairo::strokeCircularGradient(VGradientEx& gradient)
+{
+ cairo_pattern_t *pat = NULL;
+ double r, g, b, lastPoint = 0.0;
+ double x1 = gradient.origin().x();
+ double y1 = gradient.origin().y();
+ double x2 = gradient.vector().x();
+ double y2 = gradient.vector().y();
+ double fx = gradient.focalPoint().x();
+ double fy = gradient.focalPoint().y();
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx* stop = NULL;
+ QColor color;
+
+ cairo_push_group(m_cr);
+
+ pat = cairo_pattern_create_radial (fx, fy, 0, x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)));
+ cairo_pattern_set_extend(pat, CAIRO_EXTEND_PAD);
+ cairo_pattern_set_filter(pat, CAIRO_FILTER_GOOD);
+
+ bool isFirst = true;
+ double lastStop = 0.0;
+ for( uint index = 0 ; index < gradient.Stops(); index++)
+ {
+ stop = colorStops.at(index);
+ if ((lastStop == stop->rampPoint) && (!isFirst))
+ continue;
+ isFirst = false;
+ color = transformColor( ScColorShade(stop->color, stop->shade), 1.0 );
+ color.getRgbF(&r, &g, &b);
+ cairo_pattern_add_color_stop_rgba (pat, stop->rampPoint, r, g, b, stop->opacity);
+ lastStop = stop->rampPoint;
+ }
+
+ cairo_matrix_t matrix;
+ QTransform qmatrix;
+ double rotEnd = xy2Deg(x2 - x1, y2 - y1);
+ qmatrix.translate(x1, y1);
+ qmatrix.rotate(rotEnd);
+ qmatrix.shear(m_gradientSkew, 0);
+ qmatrix.translate(0, y1 * (1.0 - m_gradientScale));
+ qmatrix.translate(-x1, -y1);
+ qmatrix.scale(1, m_gradientScale);
+ cairo_matrix_init(&matrix, qmatrix.m11(), qmatrix.m12(), qmatrix.m21(), qmatrix.m22(), qmatrix.dx(), qmatrix.dy());
+ cairo_matrix_invert(&matrix);
+ cairo_pattern_set_matrix (pat, &matrix);
+ cairo_set_source (m_cr, pat);
+ cairo_stroke_preserve( m_cr );
+ cairo_pattern_destroy (pat);
+
+ cairo_pop_group_to_source (m_cr);
+
+ setRasterOp(m_blendModeStroke);
+ cairo_paint_with_alpha (m_cr, m_strokeTrans);
+}
+
void ScPainterEx_Cairo::getClipPathDimensions( QRect& r )
{
double left = 0.0, right = 0.0, bottom = 0.0, top = 0.0;
Modified: trunk/Scribus/scribus/scpainterex_cairo.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17284&path=/trunk/Scribus/scribus/scpainterex_cairo.h
==============================================================================
--- trunk/Scribus/scribus/scpainterex_cairo.h (original)
+++ trunk/Scribus/scribus/scpainterex_cairo.h Tue Feb 7 23:02:12 2012
@@ -1,131 +1,137 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#ifndef SCPAINTEREX_CAIRO_H
-#define SCPAINTEREX_CAIRO_H
-
-#include <cairo.h>
-#include "scpainterexbase.h"
-
-#include "mesh.h"
-
-class ScPainterEx_Cairo : public ScPainterExBase
-{
-public:
- ScPainterEx_Cairo(cairo_t* context, QRect& rect, ScribusDoc* doc, bool gray );
- virtual ~ScPainterEx_Cairo();
-
- virtual Capabilities capabilities() { return transparencies; }
-
- virtual int supportedColorModes() { return (int) rgbMode; }
- virtual ColorMode preferredColorMode() { return rgbMode; }
- virtual ImageMode imageMode() { return rgbImages; }
-
- virtual void begin();
- virtual void end();
- virtual void clear();
- virtual void clear( ScColorShade & );
-
- // matrix manipulation
- virtual void setWorldMatrix( const QTransform & );
- virtual const QTransform worldMatrix();
- virtual void translate( double, double );
- virtual void rotate( double );
- virtual void scale( double, double );
-
- // drawing
- virtual void moveTo( const double &, const double & );
- virtual void lineTo( const double &, const double & );
- virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
- virtual void newPath();
- virtual void closePath();
- virtual void fillTextPath();
- virtual void strokeTextPath();
- virtual void fillPath();
- virtual void strokePath();
- virtual void setFillRule( bool fillRule );
- virtual bool fillRule() { return m_fillRule; }
- virtual void setFillMode( int fill );
- virtual int fillMode() { return m_fillMode; }
- virtual void setStrokeMode( int fill );
- virtual int strokeMode() { return m_strokeMode; }
- virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc, double scale, double skew);
- virtual void setPattern(ScPattern *pattern, double scaleX, double scaleY, double offsetX, double offsetY, double rotation, double skewX, double skewY, bool mirrorX, bool mirrorY);
-
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#ifndef SCPAINTEREX_CAIRO_H
+#define SCPAINTEREX_CAIRO_H
+
+#include <cairo.h>
+#include "scpainterexbase.h"
+
+#include "mesh.h"
+
+class ScPainterEx_Cairo : public ScPainterExBase
+{
+public:
+ ScPainterEx_Cairo(cairo_t* context, QRect& rect, ScribusDoc* doc, bool gray );
+ virtual ~ScPainterEx_Cairo();
+
+ virtual Capabilities capabilities() { return transparencies; }
+
+ virtual int supportedColorModes() { return (int) rgbMode; }
+ virtual ColorMode preferredColorMode() { return rgbMode; }
+ virtual ImageMode imageMode() { return rgbImages; }
+
+ virtual void begin();
+ virtual void end();
+ virtual void clear();
+ virtual void clear( ScColorShade & );
+
+ // matrix manipulation
+ virtual void setWorldMatrix( const QTransform & );
+ virtual const QTransform worldMatrix();
+ virtual void translate( double, double );
+ virtual void rotate( double );
+ virtual void scale( double, double );
+
+ // drawing
+ virtual void moveTo( const double &, const double & );
+ virtual void lineTo( const double &, const double & );
+ virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
+ virtual void newPath();
+ virtual void closePath();
+ virtual void fillTextPath();
+ virtual void strokeTextPath();
+ virtual void fillPath();
+ virtual void strokePath();
+ virtual void setFillRule( bool fillRule );
+ virtual bool fillRule() { return m_fillRule; }
+ virtual void setFillMode( int fill );
+ virtual int fillMode() { return m_fillMode; }
+ virtual void setStrokeMode( int fill );
+ virtual int strokeMode() { return m_strokeMode; }
+ virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc, double scale, double skew);
+ virtual void setPattern(ScPattern *pattern, double scaleX, double scaleY, double offsetX, double offsetY, double rotation, double skewX, double skewY, bool mirrorX, bool mirrorY);
+
virtual void setMaskMode( int mask );
virtual void setGradientMask(VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc, double scale, double skew);
- virtual void setPatternMask(ScPattern *pattern, double scaleX, double scaleY, double offsetX, double offsetY, double rotation, double skewX, double skewY, bool mirrorX, bool mirrorY);
-
+ virtual void setPatternMask(ScPattern *pattern, double scaleX, double scaleY, double offsetX, double offsetY, double rotation, double skewX, double skewY, bool mirrorX, bool mirrorY);
+
virtual void set4ColorGeometry(FPoint p1, FPoint p2, FPoint p3, FPoint p4, FPoint c1, FPoint c2, FPoint c3, FPoint c4);
virtual void set4ColorColors(const ScColorShade& col1, const ScColorShade& col2, const ScColorShade& col3, const ScColorShade& col4);
virtual void setDiamondGeometry(FPoint p1, FPoint p2, FPoint p3, FPoint p4, FPoint c1, FPoint c2, FPoint c3, FPoint c4, FPoint c5);
virtual void setMeshGradient(FPoint p1, FPoint p2, FPoint p3, FPoint p4, QList<QList<meshPoint> > meshArray);
- virtual void setMeshGradient(FPoint p1, FPoint p2, FPoint p3, FPoint p4, QList<meshGradientPatch> meshPatches);
-
- virtual void setClipPath();
-
- virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
- virtual void setupPolygon(FPointArray *points, bool closed = true);
- virtual void drawPolygon();
- virtual void drawPolyLine();
- virtual void drawLine(FPoint start, FPoint end);
- virtual void drawRect(double, double, double, double);
-
- // pen + brush
- virtual ScColorShade pen();
- virtual ScColorShade brush();
- virtual void setPen( const ScColorShade & );
- virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
- virtual void setPenOpacity( double op );
- virtual void setLineWidth( double w);
- virtual void setDash(const QVector<double>& array, double ofs);
- virtual void setBrush( const ScColorShade & );
- virtual void setBrushOpacity( double op );
- virtual void setOpacity( double op );
- virtual void setFont( const QFont &f );
- virtual QFont font();
-
- // stack management
- virtual void save();
- virtual void restore();
-
- virtual void setRasterOp( int op );
+ virtual void setMeshGradient(FPoint p1, FPoint p2, FPoint p3, FPoint p4, QList<meshGradientPatch> meshPatches);
+
+ virtual void setClipPath();
+
+ virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
+ virtual void setupPolygon(FPointArray *points, bool closed = true);
+ virtual void drawPolygon();
+ virtual void drawPolyLine();
+ virtual void drawLine(FPoint start, FPoint end);
+ virtual void drawRect(double, double, double, double);
+
+ // pen + brush
+ virtual ScColorShade pen();
+ virtual ScColorShade brush();
+ virtual void setPen( const ScColorShade & );
+ virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
+ virtual void setPenOpacity( double op );
+ virtual void setLineWidth( double w);
+ virtual void setDash(const QVector<double>& array, double ofs);
+ virtual void setBrush( const ScColorShade & );
+ virtual void setBrushOpacity( double op );
+ virtual void setOpacity( double op );
+ virtual void setFont( const QFont &f );
+ virtual QFont font();
+
+ // stack management
+ virtual void save();
+ virtual void restore();
+
+ virtual void setRasterOp( int op );
virtual void setBlendModeFill( int blendMode );
- virtual void setBlendModeStroke( int blendMode );
-
-private:
-
- void drawVPath( int mode );
- void drawGradient( VGradientEx& gradient );
- void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
- void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
- void drawFourColorGradient( const QRect& rect );
- void drawDiamondGradient( VGradientEx& gradient, const QRect& rect );
- void drawMeshGradient( const QRect& rect );
- void drawFreeMeshGradient( const QRect& rect );
- void getClipPathDimensions( QRect& r );
-
- ScribusDoc* m_doc;
-
- unsigned int m_width;
- unsigned int m_height;
- QTransform m_matrix;
- QFont m_font;
-/* Layer blend mode*/
+ virtual void setBlendModeStroke( int blendMode );
+
+private:
+
+ void drawVPath( int mode );
+
+ void drawGradient( VGradientEx& gradient );
+ void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
+ void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
+ void drawFourColorGradient( const QRect& rect );
+ void drawDiamondGradient( VGradientEx& gradient, const QRect& rect );
+ void drawMeshGradient( const QRect& rect );
+ void drawFreeMeshGradient( const QRect& rect );
+
+ void strokeGradient( VGradientEx& gradient );
+ void strokeLinearGradient( VGradientEx& gradient );
+ void strokeCircularGradient( VGradientEx& gradient );
+
+ void getClipPathDimensions( QRect& r );
+
+ ScribusDoc* m_doc;
+
+ unsigned int m_width;
+ unsigned int m_height;
+ QTransform m_matrix;
+ QFont m_font;
+/* Layer blend mode*/
int m_blendModeLayer;
int m_blendModeFill;
- int m_blendModeStroke;
-/* Filling */
- ScColorShade m_fillColor;
- double m_fillTrans;
- bool m_fillRule;
- int m_fillMode; // 0 = none, 1 = solid, 2 = gradient
- int m_gradientMode; // 1 = linear, 2 = radial
-
+ int m_blendModeStroke;
+/* Filling */
+ ScColorShade m_fillColor;
+ double m_fillTrans;
+ bool m_fillRule;
+ int m_fillMode; // 0 = none, 1 = solid, 2 = gradient
+ int m_gradientMode; // 1 = linear, 2 = radial
+
double m_patternScaleX;
double m_patternScaleY;
double m_patternOffsetX;
@@ -134,8 +140,8 @@
double m_patternSkewX;
double m_patternSkewY;
bool m_patternMirrorX;
- bool m_patternMirrorY;
-
+ bool m_patternMirrorY;
+
FPoint m_gradPatchP1;
FPoint m_gradPatchP2;
FPoint m_gradPatchP3;
@@ -150,16 +156,16 @@
ScColorShade m_gradPatchColor3;
ScColorShade m_gradPatchColor4;
QList<QList<meshPoint> > m_meshGradientArray;
- QList<meshGradientPatch> m_meshGradientPatches;
-
+ QList<meshGradientPatch> m_meshGradientPatches;
+
double m_gradientScale;
- double m_gradientSkew;
-/* Stroking */
- ScColorShade m_strokeColor;
- double m_strokeTrans;
- double m_lineWidth;
- int m_strokeMode; // 0 = none, 1 = solid, 2 = gradient 3 = pattern
-/* Masking */
+ double m_gradientSkew;
+/* Stroking */
+ ScColorShade m_strokeColor;
+ double m_strokeTrans;
+ double m_lineWidth;
+ int m_strokeMode; // 0 = none, 1 = solid, 2 = gradient 3 = pattern
+/* Masking */
int m_maskMode; // 0 = none, 1 = gradient 2 = pattern
double m_maskPatternScaleX;
double m_maskPatternScaleY;
@@ -171,31 +177,31 @@
bool m_maskPatternMirrorX;
bool m_maskPatternMirrorY;
double m_maskGradientScale;
- double m_maskGradientSkew;
-
-/* Grayscale conversion option */
- bool m_convertToGray;
-
-/* Line End Style */
- Qt::PenCapStyle m_lineEnd;
-/* Line Join Style */
- Qt::PenJoinStyle m_lineJoin;
-/* The Dash Array */
- QVector<double> m_array;
- double m_offset;
-/* Transformation Stack */
- QStack<QTransform> m_stack;
-
-/* Cairo context */
- cairo_t* m_cr;
-
-/* Color conversion function */
- QColor transformColor( ScColorShade& colorShade, double trans );
- void transformImage( QImage& image );
-
- QStack<int> m_gStates;
- double m_positionX;
- double m_positionY;
-};
-
-#endif
+ double m_maskGradientSkew;
+
+/* Grayscale conversion option */
+ bool m_convertToGray;
+
+/* Line End Style */
+ Qt::PenCapStyle m_lineEnd;
+/* Line Join Style */
+ Qt::PenJoinStyle m_lineJoin;
+/* The Dash Array */
+ QVector<double> m_array;
+ double m_offset;
+/* Transformation Stack */
+ QStack<QTransform> m_stack;
+
+/* Cairo context */
+ cairo_t* m_cr;
+
+/* Color conversion function */
+ QColor transformColor( ScColorShade& colorShade, double trans );
+ void transformImage( QImage& image );
+
+ QStack<int> m_gStates;
+ double m_positionX;
+ double m_positionY;
+};
+
+#endif
More information about the scribus-commit
mailing list