~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/libkowmf/kowmfpaint.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* This file is part of the KDE libraries
2
2
 * Copyright (c) 2003 thierry lorthiois (lorthioist@wanadoo.fr)
 
3
 *               2009-2010 Inge Wallin <inge@lysator.liu.se>
3
4
 *
4
5
 * This library is free software; you can redistribute it and/or
5
6
 * modify it under the terms of the GNU Library General Public
20
21
 
21
22
#include <QPolygon>
22
23
#include <QPrinter>
 
24
#include <QFontMetrics>
23
25
 
24
26
#include <kdebug.h>
25
27
 
26
 
KoWmfPaint::KoWmfPaint() : KoWmfRead() {
 
28
#include "kowmfenums.h"
 
29
 
 
30
 
 
31
KoWmfPaint::KoWmfPaint()
 
32
    : KoWmfRead()
 
33
    , mTextPen()
 
34
{
27
35
    mTarget = 0;
 
36
    mIsInternalPainter = true;
 
37
    mPainter = 0;
28
38
}
29
39
 
30
40
 
31
 
bool KoWmfPaint::play( QPaintDevice& target, bool relativeCoord )
 
41
bool KoWmfPaint::play(QPaintDevice& target, bool relativeCoord)
32
42
{
33
 
    if ( mPainter.isActive() ) return false;
 
43
    if (!mPainter)
 
44
        mPainter = new QPainter(&target);
 
45
    mIsInternalPainter = true;
 
46
 
 
47
    if (mPainter->isActive()) return false;
34
48
    mTarget = &target;
35
49
    mRelativeCoord = relativeCoord;
36
50
 
37
51
    // Play the wmf file
38
 
    return KoWmfRead::play( );
 
52
    return KoWmfRead::play();
 
53
}
 
54
 
 
55
bool KoWmfPaint::play(QPainter &painter, bool relativeCoord)
 
56
{
 
57
    // If there is already a painter and it's owned by us, then delete i
 
58
    if (mPainter && mIsInternalPainter)
 
59
        delete mPainter;
 
60
 
 
61
    // Set the new painter
 
62
    mIsInternalPainter = false;
 
63
    mPainter = &painter;
 
64
 
 
65
    mTarget = mPainter->device();
 
66
    mRelativeCoord = relativeCoord;
 
67
 
 
68
    // Play the wmf file
 
69
    return KoWmfRead::play();
39
70
}
40
71
 
41
72
 
42
73
//-----------------------------------------------------------------------------
43
74
// Virtual Painter
44
75
 
45
 
bool KoWmfPaint::begin() {
46
 
    bool ret = mPainter.begin( mTarget );
47
 
 
48
 
    if ( ret ) {
49
 
        if ( mRelativeCoord ) {
 
76
bool KoWmfPaint::begin()
 
77
{
 
78
    bool ret = true;
 
79
 
 
80
    // If the painter is our own, we have to call begin() on it.
 
81
    // If it's external, we suppose that it's already done for us.
 
82
    if (mIsInternalPainter)
 
83
        ret = mPainter->begin(mTarget);
 
84
 
 
85
    if (ret) {
 
86
        if (mRelativeCoord) {
50
87
            mInternalWorldMatrix.reset();
51
 
        }
52
 
        else {
53
 
            // some wmf files doesn't call setwindowOrg and setWindowExt, so it's better to do :
 
88
 
 
89
            // This window is used for scaling in setWindowExt().
 
90
            mPainter->setWindow(boundingRect());
 
91
        } else {
 
92
            // Some WMF files don't call setwindowOrg and
 
93
            // setWindowExt, so it's better to do it here.  Note that
 
94
            // boundingRect() is the rect of the WMF file, not the device.
54
95
            QRect rec = boundingRect();
55
 
            mPainter.setWindow( rec.left(), rec.top(), rec.width(), rec.height() );
 
96
            //kDebug(31000) << "BoundingRect: " << rec;
 
97
            mPainter->setWindow(rec);
56
98
        }
57
99
    }
58
 
    return ret;
59
 
}
60
 
 
61
 
 
62
 
bool KoWmfPaint::end() {
63
 
    if ( mRelativeCoord ) {
64
 
       QRect rec = boundingRect();
65
 
 
66
 
        // Draw 2 invisible points
67
 
        // because QPicture::setBoundingRect() doesn't give expected result (QT3.1.2)
68
 
        // setBoundingRect( boundingRect() );
69
 
//        mPainter.setPen( Qt::NoPen );
70
 
//        mPainter.drawPoint( rec.left(), rec.top() );
71
 
//        mPainter.drawPoint( rec.right(), rec.bottom() );
72
 
    }
73
 
    return mPainter.end();
74
 
}
75
 
 
76
 
 
77
 
void KoWmfPaint::save() {
78
 
    mPainter.save();
79
 
}
80
 
 
81
 
 
82
 
void KoWmfPaint::restore() {
83
 
    mPainter.restore();
84
 
}
85
 
 
86
 
 
87
 
void KoWmfPaint::setFont( const QFont &font ) {
88
 
    mPainter.setFont( font );
89
 
}
90
 
 
91
 
 
92
 
void KoWmfPaint::setPen( const QPen &pen ) {
 
100
 
 
101
#if DEBUG_WMFPAINT
 
102
    kDebug(31000) << "Using QPainter: " << mPainter->pen() << mPainter->brush() 
 
103
                  << "Background: " << mPainter->background() << " " << mPainter->backgroundMode();
 
104
    kDebug(31000) << "KoWmfPaint::begin returns " << ret;
 
105
#endif
 
106
 
 
107
    return ret;
 
108
}
 
109
 
 
110
 
 
111
bool KoWmfPaint::end()
 
112
{
 
113
    bool ret = true;
 
114
    if (mIsInternalPainter)
 
115
        ret = mPainter->end();
 
116
 
 
117
    return ret;
 
118
}
 
119
 
 
120
 
 
121
void KoWmfPaint::save()
 
122
{
 
123
    mPainter->save();
 
124
}
 
125
 
 
126
 
 
127
void KoWmfPaint::restore()
 
128
{
 
129
    mPainter->restore();
 
130
}
 
131
 
 
132
 
 
133
void KoWmfPaint::setFont(const QFont &font)
 
134
{
 
135
#if DEBUG_WMFPAINT
 
136
    kDebug(31000) << font;
 
137
#endif
 
138
    mPainter->setFont(font);
 
139
}
 
140
 
 
141
 
 
142
void KoWmfPaint::setTextPen(const QPen &pen)
 
143
{
 
144
#if DEBUG_WMFPAINT
 
145
    kDebug(31000) << pen;
 
146
#endif
 
147
 
 
148
    mTextPen = pen;
 
149
}
 
150
 
 
151
void KoWmfPaint::setPen(const QPen &pen)
 
152
{
 
153
#if DEBUG_WMFPAINT
 
154
    kDebug(31000) << pen;
 
155
#endif
 
156
 
93
157
    QPen p = pen;
94
158
    int width = pen.width();
95
159
 
96
 
    if ( dynamic_cast<QPrinter *>( mTarget ) ) {
 
160
    if (dynamic_cast<QPrinter *>(mTarget)) {
97
161
        width = 0;
98
 
    }
99
 
    else {
100
 
        // WMF spec : width of pen in logical coordinate
 
162
    } else {
 
163
        // WMF spec: width of pen in logical coordinate
101
164
        // => width of pen proportional with device context width
102
 
        QRect rec = mPainter.window();
 
165
        QRect rec = mPainter->window();
103
166
        // QPainter documentation says this is equivalent of xFormDev, but it doesn't compile. Bug reported.
104
167
#if 0
105
 
        QRect devRec = rec * mPainter.matrix();
106
 
        if ( rec.width() != 0 )
107
 
            width = ( width * devRec.width() ) / rec.width() ;
 
168
        QRect devRec = rec * mPainter->matrix();
 
169
        if (rec.width() != 0)
 
170
            width = (width * devRec.width()) / rec.width() ;
108
171
        else
109
172
            width = 0;
110
173
#endif
111
174
    }
112
175
 
113
 
    p.setWidth( width );
114
 
    mPainter.setPen( p );
115
 
}
116
 
 
117
 
 
118
 
const QPen &KoWmfPaint::pen() const {
119
 
    return mPainter.pen();
120
 
}
121
 
 
122
 
 
123
 
void KoWmfPaint::setBrush( const QBrush &brush ) {
124
 
    mPainter.setBrush( brush );
125
 
}
126
 
 
127
 
 
128
 
void KoWmfPaint::setBackgroundColor( const QColor &c ) {
129
 
    mPainter.setBackground( QBrush( c ) );
130
 
}
131
 
 
132
 
 
133
 
void KoWmfPaint::setBackgroundMode( Qt::BGMode mode ) {
134
 
    mPainter.setBackgroundMode( mode );
135
 
}
136
 
 
137
 
 
138
 
void KoWmfPaint::setCompositionMode( QPainter::CompositionMode mode ) {
139
 
    mPainter.setCompositionMode( mode );
 
176
    p.setWidth(width);
 
177
    mPainter->setPen(p);
 
178
}
 
179
 
 
180
 
 
181
const QPen &KoWmfPaint::pen() const
 
182
{
 
183
    return mPainter->pen();
 
184
}
 
185
 
 
186
 
 
187
void KoWmfPaint::setBrush(const QBrush &brush)
 
188
{
 
189
#if DEBUG_WMFPAINT
 
190
    kDebug(31000) << brush;
 
191
#endif
 
192
    mPainter->setBrush(brush);
 
193
}
 
194
 
 
195
 
 
196
void KoWmfPaint::setBackgroundColor(const QColor &c)
 
197
{
 
198
#if DEBUG_WMFPAINT
 
199
    kDebug(31000) << c;
 
200
#endif
 
201
    // FIXME: This needs more investigation, but it seems that the
 
202
    //        concept of "background" in WMF is the same as the
 
203
    //        "brush" in QPainter.
 
204
    // Update: No, it wasn't.  I changed back now because it didn't work.  I'm leaving
 
205
    //         the fixme and this comment to remind the next fixer that calling
 
206
    //         setBrush() is not the solution.  I hope nothing breaks now.
 
207
    //         The date is now 2010-01-20.  If nothing breaks in a couple of months,
 
208
    //         all this commentry can be removed.
 
209
    //mPainter->setBrush(QBrush(c));
 
210
    mPainter->setBackground(QBrush(c));
 
211
}
 
212
 
 
213
 
 
214
void KoWmfPaint::setBackgroundMode(Qt::BGMode mode)
 
215
{
 
216
#if DEBUG_WMFPAINT
 
217
    kDebug(31000) << mode << "(ignored)";
 
218
#endif
 
219
 
 
220
    mPainter->setBackgroundMode(mode);
 
221
}
 
222
 
 
223
 
 
224
void KoWmfPaint::setCompositionMode(QPainter::CompositionMode mode)
 
225
{
 
226
#if DEBUG_WMFPAINT
 
227
    kDebug(31000) << mode << "(ignored)";
 
228
#endif
 
229
 
 
230
    // FIXME: This doesn't work.  I don't understand why, but when I
 
231
    //        enable this all backgrounds become black. /iw
 
232
    Q_UNUSED(mode);
 
233
    //mPainter->setCompositionMode(mode);
140
234
}
141
235
 
142
236
 
147
241
// - change the origin or the scale in the middle of the drawing
148
242
// - negative width or height
149
243
// and relative/absolute coordinate
150
 
void KoWmfPaint::setWindowOrg( int left, int top ) {
151
 
    if ( mRelativeCoord ) {
152
 
        double dx = mInternalWorldMatrix.dx();
153
 
        double dy = mInternalWorldMatrix.dy();
154
 
 
155
 
        // translation : Don't use setWindow()
156
 
        mInternalWorldMatrix.translate( -dx, -dy );
157
 
        mPainter.translate( -dx, -dy );
158
 
        mInternalWorldMatrix.translate( -left, -top );
159
 
        mPainter.translate( -left, -top );
160
 
    }
161
 
    else {
162
 
        QRect rec = mPainter.window();
163
 
        mPainter.setWindow( left, top, rec.width(), rec.height() );
164
 
    }
165
 
}
166
 
 
167
 
 
168
 
void KoWmfPaint::setWindowExt( int w, int h ) {
169
 
    if ( mRelativeCoord ) {
170
 
        QRect r = mPainter.window();
171
 
        double dx = mInternalWorldMatrix.dx();
172
 
        double dy = mInternalWorldMatrix.dy();
173
 
        double sx = mInternalWorldMatrix.m11();
174
 
        double sy = mInternalWorldMatrix.m22();
175
 
 
176
 
        // scale : don't use setWindow()
177
 
        mInternalWorldMatrix.translate( -dx, -dy );
178
 
        mPainter.translate( -dx, -dy );
179
 
        mInternalWorldMatrix.scale( 1/sx, 1/sy );
180
 
        mPainter.scale( 1/sx, 1/sy );
181
 
 
182
 
        sx = (double)r.width() / (double)w;
183
 
        sy = (double)r.height() / (double)h;
184
 
 
185
 
        mInternalWorldMatrix.scale( sx, sy );
186
 
        mPainter.scale( sx, sy );
187
 
        mInternalWorldMatrix.translate( dx, dy );
188
 
        mPainter.translate( dx, dy );
189
 
    }
190
 
    else {
191
 
        QRect rec = mPainter.window();
192
 
        mPainter.setWindow( rec.left(), rec.top(), w, h );
193
 
    }
194
 
}
195
 
 
196
 
 
197
 
void KoWmfPaint::setMatrix( const QMatrix &wm, bool combine ) {
198
 
    mPainter.setMatrix( wm, combine );
199
 
}
200
 
 
201
 
 
202
 
void KoWmfPaint::setClipRegion( const QRegion &rec ) {
203
 
    mPainter.setClipRegion( rec );
204
 
}
205
 
 
206
 
 
207
 
QRegion KoWmfPaint::clipRegion() {
208
 
    return mPainter.clipRegion();
209
 
}
210
 
 
211
 
 
212
 
void KoWmfPaint::moveTo( int x, int y ) {
213
 
    mLastPos = QPoint( x, y );
214
 
}
215
 
 
216
 
 
217
 
void KoWmfPaint::lineTo( int x, int y ) {
218
 
    mPainter.drawLine( mLastPos, QPoint( x, y ) );
219
 
}
220
 
 
221
 
 
222
 
void KoWmfPaint::drawRect( int x, int y, int w, int h ) {
223
 
    mPainter.drawRect( x, y, w, h );
224
 
}
225
 
 
226
 
 
227
 
void KoWmfPaint::drawRoundRect( int x, int y, int w, int h, int roudw, int roudh ) {
228
 
    mPainter.drawRoundRect( x, y, w, h, roudw, roudh );
229
 
}
230
 
 
231
 
 
232
 
void KoWmfPaint::drawEllipse( int x, int y, int w, int h ) {
233
 
    mPainter.drawEllipse( x, y, w, h );
234
 
}
235
 
 
236
 
 
237
 
void KoWmfPaint::drawArc( int x, int y, int w, int h, int a, int alen ) {
238
 
    mPainter.drawArc( x, y, w, h, a, alen );
239
 
}
240
 
 
241
 
 
242
 
void KoWmfPaint::drawPie( int x, int y, int w, int h, int a, int alen ) {
243
 
    mPainter.drawPie( x, y, w, h, a, alen );
244
 
}
245
 
 
246
 
 
247
 
void KoWmfPaint::drawChord( int x, int y, int w, int h, int a, int alen ) {
248
 
    mPainter.drawChord( x, y, w, h, a, alen );
249
 
}
250
 
 
251
 
 
252
 
void KoWmfPaint::drawPolyline( const QPolygon &pa ) {
253
 
    mPainter.drawPolyline( pa );
254
 
}
255
 
 
256
 
 
257
 
void KoWmfPaint::drawPolygon( const QPolygon &pa, bool winding ) {
258
 
    if( winding )
259
 
        mPainter.drawPolygon( pa, Qt::WindingFill );
 
244
 
 
245
void KoWmfPaint::setWindowOrg(int orgX, int orgY) // Love that parameter name...
 
246
{
 
247
#if DEBUG_WMFPAINT
 
248
    kDebug(31000) << orgX << " " << orgY;
 
249
#endif
 
250
 
 
251
    mOrgX = orgX;
 
252
    mOrgY = orgY;
 
253
 
 
254
    if (mRelativeCoord) {
 
255
        // Translate back from last translation to the origin.
 
256
        qreal dx = mInternalWorldMatrix.dx();
 
257
        qreal dy = mInternalWorldMatrix.dy();
 
258
        //kDebug(31000) << "old translation: " << dx << dy;
 
259
        //kDebug(31000) << mInternalWorldMatrix;
 
260
        //kDebug(31000) << "new translation: " << -orgX << -orgY;
 
261
        mInternalWorldMatrix.translate(-dx, -dy);
 
262
        mPainter->translate(-dx, -dy);
 
263
 
 
264
        // Translate to the new origin.
 
265
        mInternalWorldMatrix.translate(-orgX, -orgY);
 
266
        mPainter->translate(-orgX, -orgY);
 
267
    } else {
 
268
        QRect rec = mPainter->window();
 
269
        mPainter->setWindow(orgX, orgY, rec.width(), rec.height());
 
270
    }
 
271
}
 
272
 
 
273
 
 
274
void KoWmfPaint::setWindowExt(int width, int height)
 
275
{
 
276
#if DEBUG_WMFPAINT
 
277
    kDebug(31000) << width << " " << height;
 
278
#endif
 
279
 
 
280
    mExtWidth = width;
 
281
    mExtHeight = height;
 
282
 
 
283
    if (mRelativeCoord) {
 
284
        QRect r = mPainter->window();
 
285
        qreal dx = mInternalWorldMatrix.dx();
 
286
        qreal dy = mInternalWorldMatrix.dy();
 
287
        qreal sx = mInternalWorldMatrix.m11();
 
288
        qreal sy = mInternalWorldMatrix.m22();
 
289
 
 
290
        // Translate and scale back from the last window.
 
291
        mInternalWorldMatrix.translate(-dx, -dy);
 
292
        mPainter->translate(-dx, -dy);
 
293
        mInternalWorldMatrix.scale(1 / sx, 1 / sy);
 
294
        mPainter->scale(1 / sx, 1 / sy);
 
295
 
 
296
        sx = (qreal)r.width()  / (qreal)width;
 
297
        sy = (qreal)r.height() / (qreal)height;
 
298
 
 
299
        // Scale and translate into the new window
 
300
        mInternalWorldMatrix.scale(sx, sy);
 
301
        mPainter->scale(sx, sy);
 
302
        mInternalWorldMatrix.translate(dx, dy);
 
303
        mPainter->translate(dx, dy);
 
304
    } else {
 
305
        QRect rec = mPainter->window();
 
306
        mPainter->setWindow(rec.left(), rec.top(), width, height);
 
307
    }
 
308
#if 0
 
309
    mPainter->save();
 
310
    mPainter->setPen(Qt::black);
 
311
    mPainter->drawRect(QRect(QPoint(mOrgX, mOrgY),
 
312
                             QSize(mExtWidth, mExtHeight)));
 
313
    mPainter->setPen(Qt::red);
 
314
    mPainter->drawRect(boundingRect());
 
315
    mPainter->restore();
 
316
#endif
 
317
}
 
318
 
 
319
 
 
320
void KoWmfPaint::setMatrix(const QMatrix &wm, bool combine)
 
321
{
 
322
#if DEBUG_WMFPAINT
 
323
    kDebug(31000) << wm << " " << combine;
 
324
#endif
 
325
    mPainter->setMatrix(wm, combine);
 
326
}
 
327
 
 
328
 
 
329
void KoWmfPaint::setClipRegion(const QRegion &rec)
 
330
{
 
331
    mPainter->setClipRegion(rec);
 
332
}
 
333
 
 
334
 
 
335
QRegion KoWmfPaint::clipRegion()
 
336
{
 
337
    return mPainter->clipRegion();
 
338
}
 
339
 
 
340
 
 
341
void KoWmfPaint::moveTo(int x, int y)
 
342
{
 
343
#if DEBUG_WMFPAINT
 
344
    kDebug(31000)<< x << ", " << y;
 
345
#endif
 
346
    mLastPos = QPoint(x, y);
 
347
}
 
348
 
 
349
 
 
350
void KoWmfPaint::lineTo(int x, int y)
 
351
{
 
352
#if DEBUG_WMFPAINT
 
353
    kDebug(31000) << x << ", " << y << " using " << mPainter->pen()
 
354
                  << "linewidth: " << mPainter->pen().width();
 
355
#endif
 
356
 
 
357
    QPoint newPoint(x, y);
 
358
    mPainter->drawLine(mLastPos, newPoint);
 
359
    mLastPos = newPoint;
 
360
}
 
361
 
 
362
 
 
363
void KoWmfPaint::drawRect(int x, int y, int w, int h)
 
364
{
 
365
#if DEBUG_WMFPAINT
 
366
    kDebug(31000) << x << ", " << y << ", " << w << ", " << h;
 
367
    kDebug(31000) << "Using QPainter: " << mPainter->pen() << mPainter->brush();
 
368
#endif
 
369
 
 
370
    mPainter->drawRect(x, y, w, h);
 
371
}
 
372
 
 
373
 
 
374
void KoWmfPaint::drawRoundRect(int x, int y, int w, int h, int roudw, int roudh)
 
375
{
 
376
#if DEBUG_WMFPAINT
 
377
    kDebug(31000) << x << ", " << y << ", " << w << ", " << h;
 
378
#endif
 
379
    mPainter->drawRoundRect(x, y, w, h, roudw, roudh);
 
380
}
 
381
 
 
382
 
 
383
void KoWmfPaint::drawEllipse(int x, int y, int w, int h)
 
384
{
 
385
#if DEBUG_WMFPAINT
 
386
    kDebug(31000) << x << ", " << y << ", " << w << ", " << h;
 
387
#endif
 
388
    mPainter->drawEllipse(x, y, w, h);
 
389
}
 
390
 
 
391
 
 
392
void KoWmfPaint::drawArc(int x, int y, int w, int h, int a, int alen)
 
393
{
 
394
#if DEBUG_WMFPAINT
 
395
    kDebug(31000) << x << ", " << y << ", " << w << ", " << h;
 
396
#endif
 
397
    mPainter->drawArc(x, y, w, h, a, alen);
 
398
}
 
399
 
 
400
 
 
401
void KoWmfPaint::drawPie(int x, int y, int w, int h, int a, int alen)
 
402
{
 
403
#if DEBUG_WMFPAINT
 
404
    kDebug(31000) << x << ", " << y << ", " << w << ", " << h;
 
405
#endif
 
406
    mPainter->drawPie(x, y, w, h, a, alen);
 
407
}
 
408
 
 
409
 
 
410
void KoWmfPaint::drawChord(int x, int y, int w, int h, int a, int alen)
 
411
{
 
412
#if DEBUG_WMFPAINT
 
413
    kDebug(31000) << x << ", " << y << ", " << w << ", " << h
 
414
                  << ", " << a << ", " << alen;
 
415
#endif
 
416
    mPainter->drawChord(x, y, w, h, a, alen);
 
417
}
 
418
 
 
419
 
 
420
void KoWmfPaint::drawPolyline(const QPolygon &pa)
 
421
{
 
422
#if DEBUG_WMFPAINT
 
423
    kDebug(31000) << pa;
 
424
#endif
 
425
    mPainter->drawPolyline(pa);
 
426
}
 
427
 
 
428
 
 
429
void KoWmfPaint::drawPolygon(const QPolygon &pa, bool winding)
 
430
{
 
431
#if DEBUG_WMFPAINT
 
432
    kDebug(31000) << pa << winding;
 
433
    kDebug(31000) << "Using QPainter: " << mPainter->pen() << mPainter->brush();
 
434
#endif
 
435
 
 
436
    if (winding)
 
437
        mPainter->drawPolygon(pa, Qt::WindingFill);
260
438
    else
261
 
        mPainter.drawPolygon( pa, Qt::OddEvenFill );
 
439
        mPainter->drawPolygon(pa, Qt::OddEvenFill);
262
440
}
263
441
 
264
442
 
265
 
void KoWmfPaint::drawPolyPolygon( QList<QPolygon>& listPa, bool winding ) {
266
 
    mPainter.save();
267
 
    QBrush brush = mPainter.brush();
 
443
void KoWmfPaint::drawPolyPolygon(QList<QPolygon>& listPa, bool winding)
 
444
{
 
445
#if DEBUG_WMFPAINT
 
446
    kDebug(31000);
 
447
#endif
 
448
 
 
449
    mPainter->save();
 
450
    QBrush brush = mPainter->brush();
268
451
 
269
452
    // define clipping region
270
453
    QRegion region;
271
 
    foreach ( const QPolygon & pa, listPa ) {
272
 
        region = region.xored( pa );
 
454
    foreach(const QPolygon & pa, listPa) {
 
455
        region = region.xored(pa);
273
456
    }
274
 
    mPainter.setClipRegion( region );
 
457
    mPainter->setClipRegion(region);
275
458
 
276
459
    // fill polygons
277
 
    if ( brush != Qt::NoBrush ) {
278
 
        mPainter.fillRect( region.boundingRect(), brush );
 
460
    if (brush != Qt::NoBrush) {
 
461
        kDebug(31000) << "Filling polygon with " << brush;
 
462
        mPainter->fillRect(region.boundingRect(), brush);
279
463
    }
280
464
 
281
465
    // draw polygon's border
282
 
    mPainter.setClipping( false );
283
 
    if ( mPainter.pen().style() != Qt::NoPen ) {
284
 
        mPainter.setBrush( Qt::NoBrush );
285
 
        foreach ( const QPolygon & pa, listPa )
286
 
        {
287
 
            if( winding )
288
 
                mPainter.drawPolygon( pa, Qt::WindingFill );
 
466
    mPainter->setClipping(false);
 
467
    if (mPainter->pen().style() != Qt::NoPen) {
 
468
        mPainter->setBrush(Qt::NoBrush);
 
469
        foreach(const QPolygon & pa, listPa) {
 
470
#if DEBUG_WMFPAINT
 
471
            kDebug(31000) << pa;
 
472
#endif
 
473
            if (winding)
 
474
                mPainter->drawPolygon(pa, Qt::WindingFill);
289
475
            else
290
 
                mPainter.drawPolygon( pa, Qt::OddEvenFill );
 
476
                mPainter->drawPolygon(pa, Qt::OddEvenFill);
291
477
        }
292
478
    }
293
479
 
294
480
    // restore previous state
295
 
    mPainter.restore();
296
 
}
297
 
 
298
 
 
299
 
void KoWmfPaint::drawImage( int x, int y, const QImage &img, int sx, int sy, int sw, int sh ) {
300
 
    mPainter.drawImage( x, y, img, sx, sy, sw, sh );
301
 
}
302
 
 
303
 
 
304
 
void KoWmfPaint::drawText( int x, int y, int w, int h, int flags, const QString& s, double ) {
305
 
    mPainter.drawText( x, y, w, h, flags, s );
306
 
}
307
 
 
308
 
 
 
481
    mPainter->restore();
 
482
}
 
483
 
 
484
 
 
485
void KoWmfPaint::drawImage(int x, int y, const QImage &img, int sx, int sy, int sw, int sh)
 
486
{
 
487
#if DEBUG_WMFPAINT
 
488
    kDebug(31000) << x << " " << y << " " << sx << " " << sy << " " << sw << " " << sh;
 
489
#endif
 
490
    mPainter->drawImage(x, y, img, sx, sy, sw, sh);
 
491
}
 
492
 
 
493
 
 
494
void KoWmfPaint::patBlt(int x, int y, int width, int height, quint32 rasterOperation)
 
495
{
 
496
#if DEBUG_WMFPAINT
 
497
    kDebug(31000) << x << y << width << height << hex << rasterOperation << dec;
 
498
#endif
 
499
 
 
500
    // 0x00f00021 is the PatCopy raster operation which just fills a rectangle with a brush.
 
501
    // This seems to be the most common one.
 
502
    //
 
503
    // FIXME: Implement the rest of the raster operations.
 
504
    if (rasterOperation == 0x00f00021) {
 
505
        // Would have been nice if we didn't have to pull out the
 
506
        // brush to use it with fillRect()...
 
507
        QBrush brush = mPainter->brush();
 
508
        mPainter->fillRect(x, y, width, height, brush);
 
509
    }
 
510
}
 
511
 
 
512
 
 
513
void KoWmfPaint::drawText(int x, int y, int w, int h, int textAlign, const QString& text, double)
 
514
{
 
515
#if DEBUG_WMFPAINT
 
516
    kDebug(31000) << x << y << w << h << hex << textAlign << dec << text;
 
517
#endif
 
518
 
 
519
    // The TA_UPDATECP flag tells us to use the current position
 
520
    if (textAlign & TA_UPDATECP) {
 
521
        // (left, top) position = current logical position
 
522
        x = mLastPos.x();
 
523
        y = mLastPos.y();
 
524
    }
 
525
 
 
526
    QFontMetrics  fm(mPainter->font(), mTarget);
 
527
    int width  = fm.width(text) + fm.descent();    // fm.width(text) isn't right with Italic text
 
528
    int height = fm.height();
 
529
 
 
530
    // Horizontal align.  These flags are supposed to be mutually exclusive.
 
531
    if ((textAlign & TA_CENTER) == TA_CENTER)
 
532
        x -= (width / 2);
 
533
    else if ((textAlign & TA_RIGHT) == TA_RIGHT)
 
534
        x -= width;
 
535
 
 
536
    // Vertical align. 
 
537
    if ((textAlign & TA_BASELINE) == TA_BASELINE)
 
538
        y -= fm.ascent();  // (height - fm.descent()) is used in qwmf.  This should be the same.
 
539
    else if ((textAlign & TA_BOTTOM) == TA_BOTTOM) {
 
540
        y -= height;
 
541
 
 
542
#if DEBUG_WMFPAINT
 
543
        kDebug(31000) << "font = " << mPainter->font() << " pointSize = " << mPainter->font().pointSize()
 
544
                      << "ascent = " << fm.ascent() << " height = " << fm.height()
 
545
                      << "leading = " << fm.leading();
 
546
#endif
 
547
    }
 
548
 
 
549
    // Use the special pen defined by mTextPen for text.
 
550
    QPen  savePen = mPainter->pen();
 
551
    mPainter->setPen(mTextPen);
 
552
 
 
553
    // Sometimes it happens that w and/or h == -1, and then the bounding box
 
554
    // isn't valid any more.  In that case, use our own calculated values.
 
555
    if (w == -1 || h == -1) {
 
556
        mPainter->drawText(x, y, width, height, Qt::AlignLeft|Qt::AlignTop, text);
 
557
    }
 
558
    else {
 
559
        mPainter->drawText(x, y, w, h, Qt::AlignLeft|Qt::AlignTop, text);
 
560
    }
 
561
 
 
562
    mPainter->setPen(savePen);
 
563
}