Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scpainter.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /* This file is part of the KDE project
00008    Copyright (C) 2001, 2002, 2003 The Karbon Developers
00009 
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Library General Public
00012    License as published by the Free Software Foundation; either
00013    version 2 of the License, or (at your option) any later version.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Library General Public License for more details.
00019 
00020    You should have received a copy of the GNU Library General Public License
00021    along with this library; see the file COPYING.LIB.  If not, write to
00022    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023    Boston, MA 02111-1307, USA.
00024 */
00025 /* Adapted for Scribus 22.08.2003 by Franz Schmid */
00026 
00027 #ifndef __SCPAINTER_H__
00028 #define __SCPAINTER_H__
00029 
00030 // libart wrapper
00031 
00032 #include <qglobal.h>
00033 #include <qwmatrix.h>
00034 #include <qvaluelist.h>
00035 #include <qvaluestack.h>
00036 #include <qcolor.h>
00037 #include <qfont.h>
00038 #include <qpixmap.h>
00039 #include <qimage.h>
00040 #include "scribusapi.h"
00041 #include "scconfig.h"
00042 #include "fpoint.h"
00043 #include "fpointarray.h"
00044 #include "vgradient.h"
00045 #include "scpattern.h"
00046 
00047 // If defined, use gdk-pixbuf for ScPainter::end() on X11 (ignored on other
00048 // platforms). Otherwise use portable ScPainter::end() and omit X11-specific
00049 // code and pixbuf support.
00050 #ifndef SC_USE_PIXBUF
00051 #define SC_USE_PIXBUF
00052 #endif
00053 
00054 // If defined, use Win32 GDI functions for ScPainter::end() on Win32 (ignored
00055 // on other platforms). Otherwise use portable ScPainter::end()
00056 #ifndef SC_USE_GDI
00057 #define SC_USE_GDI
00058 #endif
00059 
00060 
00061 class QPainter;
00062 #ifdef HAVE_CAIRO
00063 typedef struct _cairo cairo_t;
00064 typedef struct _cairo_surface cairo_surface_t;
00065 typedef struct _cairo_pattern cairo_pattern_t;
00066 #else
00067 struct _ArtVpath;
00068 struct _ArtBpath;
00069 struct _ArtSVP;
00070 struct _ArtGradientStop;
00071 #endif
00072 
00073 class SCRIBUS_API ScPainter
00074 {
00075 public:
00076        ScPainter( QPaintDevice *target, unsigned int w = 0, unsigned int h = 0, unsigned int x = 0, unsigned int y = 0 );
00077        ScPainter( QImage *target, unsigned int w = 0, unsigned int h = 0, unsigned int x = 0, unsigned int y = 0 );
00078 #ifdef HAVE_CAIRO
00079        ScPainter( QImage *target, unsigned int w, unsigned int h, double transparency, int blendmode );
00080        ScPainter( QString target, unsigned int w, unsigned int h, double transparency, int blendmode );
00081 #endif
00082        virtual ~ScPainter();
00083        enum FillMode { None, Solid, Gradient, Pattern };
00084 #ifdef HAVE_CAIRO
00085        virtual void beginLayer(double transparency, int blendmode, FPointArray *clipArray = 0);
00086        virtual void endLayer();
00087        virtual void setAntialiasing(bool enable);
00088 #endif
00089        virtual void begin();
00090        virtual void end();
00091        void clear();
00092        virtual void clear( const QColor & );
00093 
00094        // matrix manipulation
00095        virtual void setWorldMatrix( const QWMatrix & );
00096        virtual const QWMatrix worldMatrix();
00097        virtual void setZoomFactor( double );
00098        virtual double zoomFactor() { return m_zoomFactor; }
00099        virtual void translate( double, double );
00100        virtual void rotate( double );
00101        virtual void scale( double, double );
00102 
00103        // drawing
00104        virtual void moveTo( const double &, const double & );
00105        virtual void lineTo( const double &, const double & );
00106        virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
00107        virtual void newPath();
00108        virtual void closePath();
00109        virtual void fillTextPath();
00110        virtual void strokeTextPath();
00111        virtual void fillPath();
00112        virtual void strokePath();
00113        virtual void setFillRule( bool fillRule );
00114        virtual bool fillRule() { return m_fillRule; }
00115        virtual void setFillMode( int fill );
00116        virtual void setGradient( VGradient::VGradientType mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
00117        virtual void setPattern(ScPattern *pattern, double scaleX, double scaleY, double offsetX, double offsetY, double rotation);
00118        virtual void setClipPath();
00119 #ifndef HAVE_CAIRO
00120        virtual void setClipPath2(FPointArray *points, bool closed);
00121 #endif
00122 
00123        virtual void drawImage( QImage *image );
00124        virtual void setupPolygon(FPointArray *points, bool closed = true);
00125        virtual void setupTextPolygon(FPointArray *points);
00126        virtual void drawPolygon();
00127        virtual void drawPolyLine();
00128        virtual void drawLine(FPoint start, FPoint end);
00129        virtual void drawRect(double, double, double, double);
00130 
00131        // pen + brush
00132        virtual QColor pen();
00133        virtual QColor brush();
00134        virtual void setPen( const QColor & );
00135        virtual void setPen( const QColor &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
00136        virtual void setPenOpacity( double op );
00137        virtual void setLineWidth( double w);
00138        virtual void setDash(const QValueList<double>& array, double ofs);
00139        virtual void setBrush( const QColor & );
00140        virtual void setBrushOpacity( double op );
00141        virtual void setOpacity( double op );
00142        virtual void setFont( const QFont &f );
00143        virtual QFont font();
00144 
00145 
00146        // stack management
00147        virtual void save();
00148        virtual void restore();
00149 
00150        //
00151        virtual void setRasterOp( int op );
00152 
00153        virtual QPaintDevice *device() { return m_target; }
00154        unsigned char *buffer() { return m_buffer; }
00155        VGradient fill_gradient;
00156        VGradient stroke_gradient;
00157        ScPattern *m_pattern;
00158 
00159 private:
00160 #ifdef HAVE_CAIRO
00161        void drawVPath( int mode );
00162 #else
00163        void drawVPath( struct _ArtVpath *vec, int mode, bool preCal = false );
00164        void applyGradient( _ArtSVP *svp, bool fill );
00165        void applyPattern( _ArtSVP *svp);
00166        virtual void resize( unsigned int w, unsigned int h );
00167        _ArtGradientStop *buildStopArray( VGradient &gradient, int & );
00168        void clampToViewport( const _ArtSVP &svp, int &x0, int &y0, int &x1, int &y1 );
00169        void clampToViewport( int &x0, int &y0, int &x1, int &y1 );
00170        void ensureSpace( unsigned int );
00171        struct _ArtBpath *m_path;
00172        struct _ArtBpath *m_path2;
00173        struct _ArtSVP *m_clipPath;
00174 #endif
00175        unsigned int m_index;
00176        unsigned int m_alloccount;
00177        unsigned char *m_buffer;
00178        QPaintDevice *m_target;
00179        QImage *m_image;
00180        QImage  tmp_image;
00181        double  m_layerTransparency;
00182        int  m_blendMode;
00183        QPixmap pixm;
00184        QImage m_img;
00185        unsigned int m_width;
00186        unsigned int m_height;
00187        unsigned int m_x;
00188        unsigned int m_y;
00189        QWMatrix m_matrix;
00190        QFont m_font;
00191        bool mf_underline;
00192        bool mf_strikeout;
00193        bool mf_shadow;
00194        bool mf_outlined;
00196        QColor m_fill;
00197        double fill_trans;
00198        bool m_fillRule;
00199        int fillMode;                      // 0 = none, 1 = solid, 2 = gradient 3 = pattern
00200        int gradientMode;           // 1 = linear, 2 = radial
00201        double patternScaleX;
00202        double patternScaleY;
00203        double patternOffsetX;
00204        double patternOffsetY;
00205        double patternRotation;
00207        QColor m_stroke;
00208        double stroke_trans;
00209        double LineWidth;
00210 
00212   Qt::PenCapStyle PLineEnd;
00214   Qt::PenJoinStyle PLineJoin;
00216        QValueList<double> m_array;
00217        double m_offset;
00219        QValueStack<QWMatrix> MStack;
00221        double m_zoomFactor;
00222        bool imageMode;
00223        bool layeredMode;
00224        bool svgMode;
00225 #ifdef HAVE_CAIRO
00226        cairo_t *m_cr;
00227        struct layerProp
00228        {
00229               cairo_surface_t *data;
00230               int blendmode;
00231               double tranparency;
00232               FPointArray groupClip;
00233               bool pushed;
00234        };
00235        QValueStack<layerProp> Layers;
00236 #elif defined(Q_WS_X11) && defined(SC_USE_PIXBUF)
00237        GC gc;
00238 #elif defined(_WIN32) && defined(SC_USE_GDI)
00239        HDC dc;
00240 #endif
00241 };
00242 
00243 #endif