lib Library API Documentation

kowmfpaint.cc

00001 /* This file is part of the KDE libraries
00002  * Copyright (c) 2003 thierry lorthiois (lorthioist@wanadoo.fr)
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License version 2 as published by the Free Software Foundation.
00007  *
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * Library General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Library General Public License
00014  * along with this library; see the file COPYING.LIB.  If not, write to
00015  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016  * Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include <kdebug.h>
00020 
00021 #include "kowmfpaint.h"
00022 
00023 KoWmfPaint::KoWmfPaint() : KoWmfRead() {
00024     mTarget = 0;
00025 }
00026 
00027 
00028 bool KoWmfPaint::play( QPaintDevice& target, bool relativeCoord )
00029 {
00030     if ( mPainter.isActive() ) return false;
00031     mTarget = &target;
00032     mRelativeCoord = relativeCoord;
00033         
00034     // Play the wmf file
00035     return KoWmfRead::play( );
00036 }
00037 
00038 
00039 //-----------------------------------------------------------------------------
00040 // Virtual Painter
00041 
00042 bool KoWmfPaint::begin() {
00043     bool ret = mPainter.begin( mTarget );
00044 
00045     if ( ret ) {
00046         if ( mRelativeCoord ) {
00047             mInternalWorldMatrix.reset();
00048         }
00049         else {
00050             // some wmf files doesn't call setwindowOrg and setWindowExt, so it's better to do :
00051             QRect rec = boundingRect();
00052             mPainter.setWindow( rec.left(), rec.top(), rec.width(), rec.height() );
00053         }
00054     }
00055     return ret;
00056 }
00057 
00058 
00059 bool KoWmfPaint::end() {
00060     if ( mRelativeCoord ) {
00061        QRect rec = boundingRect();
00062 
00063         // Draw 2 invisible points
00064         // because QPicture::setBoundingRect() doesn't give expected result (QT3.1.2)
00065         // setBoundingRect( boundingRect() );
00066 //        mPainter.setPen( Qt::NoPen ); 
00067 //        mPainter.drawPoint( rec.left(), rec.top() );
00068 //        mPainter.drawPoint( rec.right(), rec.bottom() );
00069     }
00070     return mPainter.end();
00071 }
00072 
00073 
00074 void KoWmfPaint::save() {
00075     mPainter.save();
00076 }
00077 
00078 
00079 void KoWmfPaint::restore() {
00080     mPainter.restore();
00081 }
00082 
00083 
00084 void KoWmfPaint::setFont( const QFont &font ) {
00085     mPainter.setFont( font );
00086 }
00087 
00088 
00089 void KoWmfPaint::setPen( const QPen &pen ) {
00090     QPen p = pen;
00091     int width = pen.width();
00092     
00093     if ( mTarget->isExtDev() ) {
00094         width = 0;
00095     }
00096     else {
00097         // WMF spec : width of pen in logical coordinate
00098         // => width of pen proportional with device context width
00099         QRect devRec = mPainter.xForm( mPainter.window() );
00100         QRect rec = mPainter.window();
00101         if ( rec.width() != 0 )
00102             width = ( width * devRec.width() ) / rec.width() ;
00103         else
00104             width = 0;
00105     }
00106     
00107     p.setWidth( width );
00108     mPainter.setPen( p );
00109 }
00110 
00111 
00112 const QPen &KoWmfPaint::pen() const {
00113     return mPainter.pen();
00114 }
00115 
00116 
00117 void KoWmfPaint::setBrush( const QBrush &brush ) {
00118     mPainter.setBrush( brush );
00119 }
00120 
00121 
00122 void KoWmfPaint::setBackgroundColor( const QColor &c ) {
00123     mPainter.setBackgroundColor( c );
00124 }
00125 
00126 
00127 void KoWmfPaint::setBackgroundMode( Qt::BGMode mode ) {
00128     mPainter.setBackgroundMode( mode );
00129 }
00130 
00131 
00132 void KoWmfPaint::setRasterOp( Qt::RasterOp op ) {
00133     mPainter.setRasterOp( op );
00134 }
00135 
00136 
00137 // ---------------------------------------------------------------------
00138 // To change those functions it's better to have
00139 // a large set of WMF files. WMF special case includes :
00140 // - without call to setWindowOrg and setWindowExt
00141 // - change the origin or the scale in the middle of the drawing
00142 // - negative width or height
00143 // and relative/absolute coordinate
00144 void KoWmfPaint::setWindowOrg( int left, int top ) {
00145     if ( mRelativeCoord ) {
00146         double dx = mInternalWorldMatrix.dx();
00147         double dy = mInternalWorldMatrix.dy();
00148 
00149         // translation : Don't use setWindow() 
00150         mInternalWorldMatrix.translate( -dx, -dy );
00151         mPainter.translate( -dx, -dy );
00152         mInternalWorldMatrix.translate( -left, -top );
00153         mPainter.translate( -left, -top );
00154     }
00155     else {
00156         QRect rec = mPainter.window();
00157         mPainter.setWindow( left, top, rec.width(), rec.height() );
00158     }
00159 }
00160 
00161 
00162 void KoWmfPaint::setWindowExt( int w, int h ) {
00163     if ( mRelativeCoord ) {
00164         QRect r = mPainter.window();
00165         double dx = mInternalWorldMatrix.dx();
00166         double dy = mInternalWorldMatrix.dy();
00167         double sx = mInternalWorldMatrix.m11();
00168         double sy = mInternalWorldMatrix.m22();
00169 
00170         // scale : don't use setWindow()
00171         mInternalWorldMatrix.translate( -dx, -dy );
00172         mPainter.translate( -dx, -dy );
00173         mInternalWorldMatrix.scale( 1/sx, 1/sy );
00174         mPainter.scale( 1/sx, 1/sy );
00175 
00176         sx = (double)r.width() / (double)w;
00177         sy = (double)r.height() / (double)h;
00178 
00179         mInternalWorldMatrix.scale( sx, sy );
00180         mPainter.scale( sx, sy );
00181         mInternalWorldMatrix.translate( dx, dy );
00182         mPainter.translate( dx, dy );
00183     }
00184     else {
00185         QRect rec = mPainter.window();
00186         mPainter.setWindow( rec.left(), rec.top(), w, h );
00187     }
00188 }
00189 
00190 
00191 void KoWmfPaint::setWorldMatrix( const QWMatrix &wm, bool combine ) {
00192     mPainter.setWorldMatrix( wm, combine );
00193 }
00194 
00195 
00196 void KoWmfPaint::setClipRegion( const QRegion &rec ) {
00197     mPainter.setClipRegion( rec, QPainter::CoordPainter );
00198 }
00199 
00200 
00201 QRegion KoWmfPaint::clipRegion() {
00202     return mPainter.clipRegion( QPainter::CoordPainter );
00203 }
00204 
00205 
00206 void KoWmfPaint::moveTo( int x, int y ) {
00207     mPainter.moveTo( x, y );
00208 }
00209 
00210 
00211 void KoWmfPaint::lineTo( int x, int y ) {
00212     mPainter.lineTo( x, y );
00213 }
00214 
00215 
00216 void KoWmfPaint::drawRect( int x, int y, int w, int h ) {
00217     mPainter.drawRect( x, y, w, h );
00218 }
00219 
00220 
00221 void KoWmfPaint::drawRoundRect( int x, int y, int w, int h, int roudw, int roudh ) {
00222     mPainter.drawRoundRect( x, y, w, h, roudw, roudh );
00223 }
00224 
00225 
00226 void KoWmfPaint::drawEllipse( int x, int y, int w, int h ) {
00227     mPainter.drawEllipse( x, y, w, h );
00228 }
00229 
00230 
00231 void KoWmfPaint::drawArc( int x, int y, int w, int h, int a, int alen ) {
00232     mPainter.drawArc( x, y, w, h, a, alen );
00233 }
00234 
00235 
00236 void KoWmfPaint::drawPie( int x, int y, int w, int h, int a, int alen ) {
00237     mPainter.drawPie( x, y, w, h, a, alen );
00238 }
00239 
00240 
00241 void KoWmfPaint::drawChord( int x, int y, int w, int h, int a, int alen ) {
00242     mPainter.drawChord( x, y, w, h, a, alen );
00243 }
00244 
00245 
00246 void KoWmfPaint::drawPolyline( const QPointArray &pa ) {
00247     mPainter.drawPolyline( pa );
00248 }
00249 
00250 
00251 void KoWmfPaint::drawPolygon( const QPointArray &pa, bool winding ) {
00252     mPainter.drawPolygon( pa, winding );
00253 }
00254 
00255 
00256 void KoWmfPaint::drawPolyPolygon( QPtrList<QPointArray>& listPa, bool winding ) {
00257     QPointArray *pa;
00258     
00259     mPainter.save();
00260     QBrush brush = mPainter.brush();
00261 
00262     // define clipping region
00263     QRegion region;
00264     for ( pa = listPa.first() ; pa ; pa = listPa.next() ) {
00265         region = region.eor( *pa );
00266     }
00267     mPainter.setClipRegion( region, QPainter::CoordPainter );
00268 
00269     // fill polygons
00270     if ( brush != Qt::NoBrush ) {
00271         mPainter.fillRect( region.boundingRect(), brush );
00272     }
00273 
00274     // draw polygon's border
00275     mPainter.setClipping( false );
00276     if ( mPainter.pen().style() != Qt::NoPen ) {
00277         mPainter.setBrush( Qt::NoBrush );
00278         for ( pa = listPa.first() ; pa ; pa = listPa.next() ) {
00279             mPainter.drawPolygon( *pa, winding );
00280         }
00281     }
00282 
00283     // restore previous state
00284     mPainter.restore();
00285 }
00286 
00287 
00288 void KoWmfPaint::drawImage( int x, int y, const QImage &img, int sx, int sy, int sw, int sh ) {
00289     mPainter.drawImage( x, y, img, sx, sy, sw, sh );
00290 }
00291 
00292 
00293 void KoWmfPaint::drawText( int x, int y, int w, int h, int flags, const QString& s, double ) {
00294     mPainter.drawText( x, y, w, h, flags, s );
00295 }
00296 
00297 
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 13:19:27 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2003