Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scpainterex_gdi.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 /* Adapted for Scribus 15.01.2006 by Jean Ghali */
00027 
00028 #ifndef __SCGDIPAINTER_H__
00029 #define __SCGDIPAINTER_H__
00030 
00031 // libart wrapper
00032 
00033 #include <qglobal.h>
00034 #include <qwmatrix.h>
00035 #include <qvaluelist.h>
00036 #include <qvaluestack.h>
00037 #include <qcolor.h>
00038 #include <qfont.h>
00039 #include <qpixmap.h>
00040 #include "scribusapi.h"
00041 #include "scconfig.h"
00042 #include "fpoint.h"
00043 #include "fpointarray.h"
00044 #include "vgradient.h"
00045 
00046 #include "scpainterexbase.h"
00047 
00048 #include <valarray>
00049 #include <windows.h>
00050 
00051 class QPainter;
00052 class ScribusDoc;
00053 
00054 #ifdef SC_USE_GDIPLUS
00055 namespace Gdiplus
00056 {
00057        class Graphics;
00058        class GraphicsPath;
00059 };
00060 #endif
00061 
00062 // Typedef to use the GDI gradientFill function
00063 typedef bool (STDAPICALLTYPE *gradientFillFunc) (HDC, PTRIVERTEX, ULONG, PVOID, ULONG, ULONG);  
00064 
00065 class SCRIBUS_API ScPainterEx_GDI : public ScPainterExBase
00066 {
00067 public:
00068 
00069        ScPainterEx_GDI(HDC hDC, QRect& rect, ScribusDoc* doc, bool gray );
00070        virtual ~ScPainterEx_GDI();
00071 
00072        virtual Capabilities capabilities() { return transparencies; }
00073 
00074        virtual int supportedColorModes() { return (int) rgbMode; }
00075        virtual ColorMode preferredColorMode() { return rgbMode; }
00076        virtual ImageMode imageMode() { return rgbImages; }
00077 
00078        virtual void begin();
00079        virtual void end();
00080        virtual void clear();
00081        virtual void clear( ScColorShade & );
00082 
00083        // matrix manipulation
00084        virtual void setWorldMatrix( const QWMatrix & );
00085        virtual const QWMatrix worldMatrix();
00086        virtual void translate( double, double );
00087        virtual void rotate( double );
00088        virtual void scale( double, double );
00089 
00090        // drawing
00091        virtual void moveTo( const double &, const double & );
00092        virtual void lineTo( const double &, const double & );
00093        virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
00094        virtual void newPath();
00095        virtual void fillTextPath();
00096        virtual void strokeTextPath();
00097        virtual void fillPath();
00098        virtual void strokePath();
00099        virtual void setFillRule( bool fillRule );
00100        virtual bool fillRule() { return m_fillRule; }
00101        virtual void setFillMode( int fill );
00102        virtual int  fillMode() { return m_fillMode; }
00103        virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
00104        virtual void setPattern ( ScPattern* pattern, QWMatrix& patternTransform );
00105        virtual void setClipPath();
00106 
00107        virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
00108        virtual void setupPolygon(FPointArray *points, bool closed = true);
00109        virtual void setupTextPolygon(FPointArray *points);
00110        virtual void drawPolygon();
00111        virtual void drawPolyLine();
00112        virtual void drawLine(FPoint start, FPoint end);
00113        virtual void drawRect(double, double, double, double);
00114 
00115        // pen + brush
00116        virtual ScColorShade pen();
00117        virtual ScColorShade brush();
00118        virtual void setPen( const ScColorShade & );
00119        virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
00120        virtual void setPenOpacity( double op );
00121        virtual void setLineWidth( double w);
00122        virtual void setDash(const QValueList<double>& array, double ofs);
00123        virtual void setBrush( const ScColorShade & );
00124        virtual void setBrushOpacity( double op );
00125        virtual void setOpacity( double op );
00126        virtual void setFont( const QFont &f );
00127        virtual QFont font();
00128 
00129        // stack management
00130        virtual void save();
00131        virtual void restore();
00132 
00133        virtual void setRasterOp( int op );
00134 
00135 private:
00136 
00137        void drawVPath( int mode );
00138        void drawGradient( VGradientEx& gradient );
00139        void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
00140        void drawLinearGradient_GradientFill( VGradientEx& gradient, const QRect& rect );
00141        void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
00142        void drawCircleStrip( int x, int y, int w, int h, int r, int g, int b, int a );
00143        void drawRectangleStrip( int x, int y, int w, int h, int r, int g, int b, int a );
00144        void getClipPathDimensions( QRect& r );
00145        void transformPoint( const FPoint& in, FPoint& out );
00146        void transformPoints( const FPoint* in, FPoint* out, uint length );
00147        void loadMsImg32( void );
00148 
00149        ScribusDoc* m_doc;
00150 
00151        unsigned int m_width;
00152        unsigned int m_height;
00153        QWMatrix m_matrix;
00154        QFont m_font;
00155 /* Filling */
00156        ScColorShade m_fillColor;
00157        double m_fillTrans;
00158        bool   m_fillRule;
00159        int    m_fillMode;                 // 0 = none, 1 = solid, 2 = gradient
00160        int    m_gradientMode;             // 1 = linear, 2 = radial
00161 /* Stroking */
00162        ScColorShade m_strokeColor;
00163        double m_strokeTrans;
00164        double m_lineWidth;
00165 /* Grayscale conversion option */
00166        bool   m_convertToGray;
00167 
00168 /* Line End Style */
00169        Qt::PenCapStyle m_lineEnd;
00170 /* Line Join Style */
00171        Qt::PenJoinStyle m_lineJoin;
00172 /* The Dash Array */
00173        QValueList<double> m_array;
00174        double m_offset;
00175 /* Transformation Stack */
00176        QValueStack<QWMatrix> m_stack;
00177 
00178 /* Some data to describe state of drawing */     
00179        bool m_pathIsClosed;
00180        bool m_drawingClosedPath;
00181 /* Drawing surface dimensions */
00182        double m_deviceDimX;
00183        double m_deviceDimY;
00184 /* Device resolutions */
00185        double m_deviceResX;
00186        double m_deviceResY;
00187 
00188 /* Device context */
00189        HDC m_dc;
00190 /* Handle to a bitmap */
00191        HBITMAP m_hBmp;
00192 /* Handle to the msimg32.dll (contains the GradientFill function) */
00193        HMODULE m_hMsImg32;
00194 /* Address of the GradientFill function */
00195        gradientFillFunc m_gradientFill;
00196 
00197 /* Color conversion function */
00198        QColor transformColor( ScColorShade& colorShade, double trans );
00199        void   transformImage( QImage* image, uchar* data, int scan);
00200 
00201 #ifdef SC_USE_GDIPLUS
00202 /* GDI+ needed data */
00203        QValueStack<int> m_gStates;
00204        Gdiplus::Graphics* m_graphics;
00205        Gdiplus::GraphicsPath* m_graphicsPath;
00206        double m_positionX;
00207        double m_positionY;
00208 #endif
00209 };
00210 
00211 #endif