lib

kowmfpaint.cpp
1/* This file is part of the KDE libraries
2 * Copyright (c) 2003 thierry lorthiois (lorthioist@wanadoo.fr)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17*/
18
19#include <kdebug.h>
20
21#include "kowmfpaint.h"
22
23KoWmfPaint::KoWmfPaint() : KoWmfRead() {
24 mTarget = 0;
25}
26
27
28bool KoWmfPaint::play( TQPaintDevice& target, bool relativeCoord )
29{
30 if ( mPainter.isActive() ) return false;
31 mTarget = &target;
32 mRelativeCoord = relativeCoord;
33
34 // Play the wmf file
35 return KoWmfRead::play( );
36}
37
38
39//-----------------------------------------------------------------------------
40// Virtual Painter
41
42bool KoWmfPaint::begin() {
43 bool ret = mPainter.begin( mTarget );
44
45 if ( ret ) {
46 if ( mRelativeCoord ) {
47 mInternalWorldMatrix.reset();
48 }
49 else {
50 // some wmf files doesn't call setwindowOrg and setWindowExt, so it's better to do :
51 TQRect rec = boundingRect();
52 mPainter.setWindow( rec.left(), rec.top(), rec.width(), rec.height() );
53 }
54 }
55 return ret;
56}
57
58
59bool KoWmfPaint::end() {
60 if ( mRelativeCoord ) {
61 TQRect rec = boundingRect();
62
63 // Draw 2 invisible points
64 // because TQPicture::setBoundingRect() doesn't give expected result (QT3.1.2)
65 // setBoundingRect( boundingRect() );
66// mPainter.setPen( TQt::NoPen );
67// mPainter.drawPoint( rec.left(), rec.top() );
68// mPainter.drawPoint( rec.right(), rec.bottom() );
69 }
70 return mPainter.end();
71}
72
73
74void KoWmfPaint::save() {
75 mPainter.save();
76}
77
78
79void KoWmfPaint::restore() {
80 mPainter.restore();
81}
82
83
84void KoWmfPaint::setFont( const TQFont &font ) {
85 mPainter.setFont( font );
86}
87
88
89void KoWmfPaint::setPen( const TQPen &pen ) {
90 TQPen p = pen;
91 int width = pen.width();
92
93 if ( mTarget->isExtDev() ) {
94 width = 0;
95 }
96 else {
97 // WMF spec : width of pen in logical coordinate
98 // => width of pen proportional with device context width
99 TQRect devRec = mPainter.xForm( mPainter.window() );
100 TQRect rec = mPainter.window();
101 if ( rec.width() != 0 )
102 width = ( width * devRec.width() ) / rec.width() ;
103 else
104 width = 0;
105 }
106
107 p.setWidth( width );
108 mPainter.setPen( p );
109}
110
111
112const TQPen &KoWmfPaint::pen() const {
113 return mPainter.pen();
114}
115
116
117void KoWmfPaint::setBrush( const TQBrush &brush ) {
118 mPainter.setBrush( brush );
119}
120
121
122void KoWmfPaint::setBackgroundColor( const TQColor &c ) {
123 mPainter.setBackgroundColor( c );
124}
125
126
127void KoWmfPaint::setBackgroundMode( TQt::BGMode mode ) {
128 mPainter.setBackgroundMode( mode );
129}
130
131
132void KoWmfPaint::setRasterOp( TQt::RasterOp op ) {
133 mPainter.setRasterOp( op );
134}
135
136
137// ---------------------------------------------------------------------
138// To change those functions it's better to have
139// a large set of WMF files. WMF special case includes :
140// - without call to setWindowOrg and setWindowExt
141// - change the origin or the scale in the middle of the drawing
142// - negative width or height
143// and relative/absolute coordinate
144void KoWmfPaint::setWindowOrg( int left, int top ) {
145 if ( mRelativeCoord ) {
146 double dx = mInternalWorldMatrix.dx();
147 double dy = mInternalWorldMatrix.dy();
148
149 // translation : Don't use setWindow()
150 mInternalWorldMatrix.translate( -dx, -dy );
151 mPainter.translate( -dx, -dy );
152 mInternalWorldMatrix.translate( -left, -top );
153 mPainter.translate( -left, -top );
154 }
155 else {
156 TQRect rec = mPainter.window();
157 mPainter.setWindow( left, top, rec.width(), rec.height() );
158 }
159}
160
161
162void KoWmfPaint::setWindowExt( int w, int h ) {
163 if ( mRelativeCoord ) {
164 TQRect r = mPainter.window();
165 double dx = mInternalWorldMatrix.dx();
166 double dy = mInternalWorldMatrix.dy();
167 double sx = mInternalWorldMatrix.m11();
168 double sy = mInternalWorldMatrix.m22();
169
170 // scale : don't use setWindow()
171 mInternalWorldMatrix.translate( -dx, -dy );
172 mPainter.translate( -dx, -dy );
173 mInternalWorldMatrix.scale( 1/sx, 1/sy );
174 mPainter.scale( 1/sx, 1/sy );
175
176 sx = (double)r.width() / (double)w;
177 sy = (double)r.height() / (double)h;
178
179 mInternalWorldMatrix.scale( sx, sy );
180 mPainter.scale( sx, sy );
181 mInternalWorldMatrix.translate( dx, dy );
182 mPainter.translate( dx, dy );
183 }
184 else {
185 TQRect rec = mPainter.window();
186 mPainter.setWindow( rec.left(), rec.top(), w, h );
187 }
188}
189
190
191void KoWmfPaint::setWorldMatrix( const TQWMatrix &wm, bool combine ) {
192 mPainter.setWorldMatrix( wm, combine );
193}
194
195
196void KoWmfPaint::setClipRegion( const TQRegion &rec ) {
197 mPainter.setClipRegion( rec, TQPainter::CoordPainter );
198}
199
200
201TQRegion KoWmfPaint::clipRegion() {
202 return mPainter.clipRegion( TQPainter::CoordPainter );
203}
204
205
206void KoWmfPaint::moveTo( int x, int y ) {
207 mPainter.moveTo( x, y );
208}
209
210
211void KoWmfPaint::lineTo( int x, int y ) {
212 mPainter.lineTo( x, y );
213}
214
215
216void KoWmfPaint::drawRect( int x, int y, int w, int h ) {
217 mPainter.drawRect( x, y, w, h );
218}
219
220
221void KoWmfPaint::drawRoundRect( int x, int y, int w, int h, int roudw, int roudh ) {
222 mPainter.drawRoundRect( x, y, w, h, roudw, roudh );
223}
224
225
226void KoWmfPaint::drawEllipse( int x, int y, int w, int h ) {
227 mPainter.drawEllipse( x, y, w, h );
228}
229
230
231void KoWmfPaint::drawArc( int x, int y, int w, int h, int a, int alen ) {
232 mPainter.drawArc( x, y, w, h, a, alen );
233}
234
235
236void KoWmfPaint::drawPie( int x, int y, int w, int h, int a, int alen ) {
237 mPainter.drawPie( x, y, w, h, a, alen );
238}
239
240
241void KoWmfPaint::drawChord( int x, int y, int w, int h, int a, int alen ) {
242 mPainter.drawChord( x, y, w, h, a, alen );
243}
244
245
246void KoWmfPaint::drawPolyline( const TQPointArray &pa ) {
247 mPainter.drawPolyline( pa );
248}
249
250
251void KoWmfPaint::drawPolygon( const TQPointArray &pa, bool winding ) {
252 mPainter.drawPolygon( pa, winding );
253}
254
255
256void KoWmfPaint::drawPolyPolygon( TQPtrList<TQPointArray>& listPa, bool winding ) {
257 TQPointArray *pa;
258
259 mPainter.save();
260 TQBrush brush = mPainter.brush();
261
262 // define clipping region
263 TQRegion region;
264 for ( pa = listPa.first() ; pa ; pa = listPa.next() ) {
265 region = region.eor( *pa );
266 }
267 mPainter.setClipRegion( region, TQPainter::CoordPainter );
268
269 // fill polygons
270 if ( brush != TQt::NoBrush ) {
271 mPainter.fillRect( region.boundingRect(), brush );
272 }
273
274 // draw polygon's border
275 mPainter.setClipping( false );
276 if ( mPainter.pen().style() != TQt::NoPen ) {
277 mPainter.setBrush( TQt::NoBrush );
278 for ( pa = listPa.first() ; pa ; pa = listPa.next() ) {
279 mPainter.drawPolygon( *pa, winding );
280 }
281 }
282
283 // restore previous state
284 mPainter.restore();
285}
286
287
288void KoWmfPaint::drawImage( int x, int y, const TQImage &img, int sx, int sy, int sw, int sh ) {
289 mPainter.drawImage( x, y, img, sx, sy, sw, sh );
290}
291
292
293void KoWmfPaint::drawText( int x, int y, int w, int h, int flags, const TQString& s, double ) {
294 mPainter.drawText( x, y, w, h, flags, s );
295}
296
297
KoWmfRead allows the redirection of the actions stored in a WMF file.
Definition kowmfread.h:47
virtual bool play()
play the WMF file => call virtuals functions
Definition kowmfread.cpp:57
virtual TQRect boundingRect(void) const
Returns the bounding rectangle Standard Meta File : return the bounding box from setWindowOrg and set...
Definition kowmfread.cpp:83