00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <kdebug.h>
00020
00021 #include "kowmfpaint.h"
00022
00023 #include <QPolygon>
00024 #include <Q3PtrList>
00025 #include <QPrinter>
00026
00027 KoWmfPaint::KoWmfPaint() : KoWmfRead() {
00028 mTarget = 0;
00029 }
00030
00031
00032 bool KoWmfPaint::play( QPaintDevice& target, bool relativeCoord )
00033 {
00034 if ( mPainter.isActive() ) return false;
00035 mTarget = ⌖
00036 mRelativeCoord = relativeCoord;
00037
00038
00039 return KoWmfRead::play( );
00040 }
00041
00042
00043
00044
00045
00046 bool KoWmfPaint::begin() {
00047 bool ret = mPainter.begin( mTarget );
00048
00049 if ( ret ) {
00050 if ( mRelativeCoord ) {
00051 mInternalWorldMatrix.reset();
00052 }
00053 else {
00054
00055 QRect rec = boundingRect();
00056 mPainter.setWindow( rec.left(), rec.top(), rec.width(), rec.height() );
00057 }
00058 }
00059 return ret;
00060 }
00061
00062
00063 bool KoWmfPaint::end() {
00064 if ( mRelativeCoord ) {
00065 QRect rec = boundingRect();
00066
00067
00068
00069
00070
00071
00072
00073 }
00074 return mPainter.end();
00075 }
00076
00077
00078 void KoWmfPaint::save() {
00079 mPainter.save();
00080 }
00081
00082
00083 void KoWmfPaint::restore() {
00084 mPainter.restore();
00085 }
00086
00087
00088 void KoWmfPaint::setFont( const QFont &font ) {
00089 mPainter.setFont( font );
00090 }
00091
00092
00093 void KoWmfPaint::setPen( const QPen &pen ) {
00094 QPen p = pen;
00095 int width = pen.width();
00096
00097 if ( dynamic_cast<QPrinter *>( mTarget ) ) {
00098 width = 0;
00099 }
00100 else {
00101
00102
00103 QRect rec = mPainter.window();
00104
00105 #if 0
00106 QRect devRec = rec * mPainter.matrix();
00107 if ( rec.width() != 0 )
00108 width = ( width * devRec.width() ) / rec.width() ;
00109 else
00110 width = 0;
00111 #endif
00112 }
00113
00114 p.setWidth( width );
00115 mPainter.setPen( p );
00116 }
00117
00118
00119 const QPen &KoWmfPaint::pen() const {
00120 return mPainter.pen();
00121 }
00122
00123
00124 void KoWmfPaint::setBrush( const QBrush &brush ) {
00125 mPainter.setBrush( brush );
00126 }
00127
00128
00129 void KoWmfPaint::setBackgroundColor( const QColor &c ) {
00130 mPainter.setBackground( QBrush( c ) );
00131 }
00132
00133
00134 void KoWmfPaint::setBackgroundMode( Qt::BGMode mode ) {
00135 mPainter.setBackgroundMode( mode );
00136 }
00137
00138
00139 void KoWmfPaint::setCompositionMode( QPainter::CompositionMode mode ) {
00140 mPainter.setCompositionMode( mode );
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 void KoWmfPaint::setWindowOrg( int left, int top ) {
00152 if ( mRelativeCoord ) {
00153 double dx = mInternalWorldMatrix.dx();
00154 double dy = mInternalWorldMatrix.dy();
00155
00156
00157 mInternalWorldMatrix.translate( -dx, -dy );
00158 mPainter.translate( -dx, -dy );
00159 mInternalWorldMatrix.translate( -left, -top );
00160 mPainter.translate( -left, -top );
00161 }
00162 else {
00163 QRect rec = mPainter.window();
00164 mPainter.setWindow( left, top, rec.width(), rec.height() );
00165 }
00166 }
00167
00168
00169 void KoWmfPaint::setWindowExt( int w, int h ) {
00170 if ( mRelativeCoord ) {
00171 QRect r = mPainter.window();
00172 double dx = mInternalWorldMatrix.dx();
00173 double dy = mInternalWorldMatrix.dy();
00174 double sx = mInternalWorldMatrix.m11();
00175 double sy = mInternalWorldMatrix.m22();
00176
00177
00178 mInternalWorldMatrix.translate( -dx, -dy );
00179 mPainter.translate( -dx, -dy );
00180 mInternalWorldMatrix.scale( 1/sx, 1/sy );
00181 mPainter.scale( 1/sx, 1/sy );
00182
00183 sx = (double)r.width() / (double)w;
00184 sy = (double)r.height() / (double)h;
00185
00186 mInternalWorldMatrix.scale( sx, sy );
00187 mPainter.scale( sx, sy );
00188 mInternalWorldMatrix.translate( dx, dy );
00189 mPainter.translate( dx, dy );
00190 }
00191 else {
00192 QRect rec = mPainter.window();
00193 mPainter.setWindow( rec.left(), rec.top(), w, h );
00194 }
00195 }
00196
00197
00198 void KoWmfPaint::setMatrix( const QMatrix &wm, bool combine ) {
00199 mPainter.setMatrix( wm, combine );
00200 }
00201
00202
00203 void KoWmfPaint::setClipRegion( const QRegion &rec ) {
00204 mPainter.setClipRegion( rec );
00205 }
00206
00207
00208 QRegion KoWmfPaint::clipRegion() {
00209 return mPainter.clipRegion();
00210 }
00211
00212
00213 void KoWmfPaint::moveTo( int x, int y ) {
00214 mLastPos = QPoint( x, y );
00215 }
00216
00217
00218 void KoWmfPaint::lineTo( int x, int y ) {
00219 mPainter.drawLine( mLastPos, QPoint( x, y ) );
00220 }
00221
00222
00223 void KoWmfPaint::drawRect( int x, int y, int w, int h ) {
00224 mPainter.drawRect( x, y, w, h );
00225 }
00226
00227
00228 void KoWmfPaint::drawRoundRect( int x, int y, int w, int h, int roudw, int roudh ) {
00229 mPainter.drawRoundRect( x, y, w, h, roudw, roudh );
00230 }
00231
00232
00233 void KoWmfPaint::drawEllipse( int x, int y, int w, int h ) {
00234 mPainter.drawEllipse( x, y, w, h );
00235 }
00236
00237
00238 void KoWmfPaint::drawArc( int x, int y, int w, int h, int a, int alen ) {
00239 mPainter.drawArc( x, y, w, h, a, alen );
00240 }
00241
00242
00243 void KoWmfPaint::drawPie( int x, int y, int w, int h, int a, int alen ) {
00244 mPainter.drawPie( x, y, w, h, a, alen );
00245 }
00246
00247
00248 void KoWmfPaint::drawChord( int x, int y, int w, int h, int a, int alen ) {
00249 mPainter.drawChord( x, y, w, h, a, alen );
00250 }
00251
00252
00253 void KoWmfPaint::drawPolyline( const QPolygon &pa ) {
00254 mPainter.drawPolyline( pa );
00255 }
00256
00257
00258 void KoWmfPaint::drawPolygon( const QPolygon &pa, bool winding ) {
00259 if( winding )
00260 mPainter.drawPolygon( pa, Qt::WindingFill );
00261 else
00262 mPainter.drawPolygon( pa, Qt::OddEvenFill );
00263 }
00264
00265
00266 void KoWmfPaint::drawPolyPolygon( Q3PtrList<QPolygon>& listPa, bool winding ) {
00267 QPolygon *pa;
00268
00269 mPainter.save();
00270 QBrush brush = mPainter.brush();
00271
00272
00273 QRegion region;
00274 for ( pa = listPa.first() ; pa ; pa = listPa.next() ) {
00275 region = region.eor( *pa );
00276 }
00277 mPainter.setClipRegion( region );
00278
00279
00280 if ( brush != Qt::NoBrush ) {
00281 mPainter.fillRect( region.boundingRect(), brush );
00282 }
00283
00284
00285 mPainter.setClipping( false );
00286 if ( mPainter.pen().style() != Qt::NoPen ) {
00287 mPainter.setBrush( Qt::NoBrush );
00288 for ( pa = listPa.first() ; pa ; pa = listPa.next() )
00289 {
00290 if( winding )
00291 mPainter.drawPolygon( *pa, Qt::WindingFill );
00292 else
00293 mPainter.drawPolygon( *pa, Qt::OddEvenFill );
00294 }
00295 }
00296
00297
00298 mPainter.restore();
00299 }
00300
00301
00302 void KoWmfPaint::drawImage( int x, int y, const QImage &img, int sx, int sy, int sw, int sh ) {
00303 mPainter.drawImage( x, y, img, sx, sy, sw, sh );
00304 }
00305
00306
00307 void KoWmfPaint::drawText( int x, int y, int w, int h, int flags, const QString& s, double ) {
00308 mPainter.drawText( x, y, w, h, flags, s );
00309 }
00310
00311