1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
/* This file is part of the KDE libraries
* Copyright (c) 1998 Stefan Taferner
* 2001/2003 thierry lorthiois (lorthioist@wanadoo.fr)
* With the help of WMF documentation by Caolan Mc Namara
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KOWMFREADPRIVATE_H_
#define _KOWMFREADPRIVATE_H_
#include <qpen.h>
#include <qcolor.h>
#include <qfont.h>
#include <qrect.h>
#include <qregion.h>
#include <qbuffer.h>
#include <qstring.h>
#include "kowmfstruct.h"
#include "kowmfstack.h"
class KoWmfRead;
/**
* KoWmfReadPrivate allows to read WMF files
*
*/
class KoWmfReadPrivate
{
public:
KoWmfReadPrivate();
virtual ~KoWmfReadPrivate();
/**
* Load WMF file. Returns true on success.
*/
bool load( const QByteArray& array );
/**
* Plays a metafile in @p readKwmf and returns true on success.
* To draw on a device you have to inherit the class ReadKwmf
*/
bool play( KoWmfRead* readKwmf );
/* Metafile painter methods */
/// set window origin
void setWindowOrg( Q_UINT32 size, QDataStream& stream );
/// set window extents
void setWindowExt( Q_UINT32 size, QDataStream& stream );
/// scale window extents
void ScaleWindowExt( Q_UINT32, QDataStream& stream );
/// offset in window origin
void OffsetWindowOrg( Q_UINT32, QDataStream& stream );
/****************** Drawing *******************/
/// draw line to coord
void lineTo( Q_UINT32 size, QDataStream& stream );
/// move pen to coord
void moveTo( Q_UINT32 size, QDataStream& stream );
/// draw ellipse
void ellipse( Q_UINT32 size, QDataStream& stream );
/// draw polygon
void polygon( Q_UINT32 size, QDataStream& stream );
/// draw a list of polygons
void polyPolygon( Q_UINT32 size, QDataStream& stream );
/// draw series of lines
void polyline( Q_UINT32 size, QDataStream& stream );
/// draw a rectangle
void rectangle( Q_UINT32 size, QDataStream& stream );
/// draw round rectangle
void roundRect( Q_UINT32 size, QDataStream& stream );
/// draw arc
void arc( Q_UINT32 size, QDataStream& stream );
/// draw chord
void chord( Q_UINT32 size, QDataStream& stream );
/// draw pie
void pie( Q_UINT32 size, QDataStream& stream );
/// set polygon fill mode
void setPolyFillMode( Q_UINT32 size, QDataStream& stream );
/// set background pen color
void setBkColor( Q_UINT32 size, QDataStream& stream );
/// set background pen mode
void setBkMode( Q_UINT32 size, QDataStream& stream );
/// set a pixel
void setPixel( Q_UINT32 size, QDataStream& stream );
/// set raster operation mode
void setRop( Q_UINT32 size, QDataStream& stream );
/// save device context */
void saveDC( Q_UINT32 size, QDataStream& stream );
/// restore device context
void restoreDC( Q_UINT32 size, QDataStream& stream );
/// clipping region is the intersection of this region and the original region
void intersectClipRect( Q_UINT32 size, QDataStream& stream );
/// delete a clipping rectangle of the original region
void excludeClipRect( Q_UINT32 size, QDataStream& stream );
/****************** Text *******************/
/// set text color
void setTextColor( Q_UINT32 size, QDataStream& stream );
/// set text alignment
void setTextAlign( Q_UINT32 size, QDataStream& stream );
/// draw text
void textOut( Q_UINT32 size, QDataStream& stream );
void extTextOut( Q_UINT32 size, QDataStream& stream );
/****************** Bitmap *******************/
void SetStretchBltMode( Q_UINT32, QDataStream& stream );
/// copies a DIB into a dest location
void dibBitBlt( Q_UINT32 size, QDataStream& stream );
/// stretches a DIB into a dest location
void dibStretchBlt( Q_UINT32 size, QDataStream& stream );
void stretchDib( Q_UINT32 size, QDataStream& stream );
/// create a pattern brush
void dibCreatePatternBrush( Q_UINT32 size, QDataStream& stream );
/****************** Object handle *******************/
/// activate object handle
void selectObject( Q_UINT32 size, QDataStream& stream );
/// free object handle
void deleteObject( Q_UINT32 size, QDataStream& stream );
/// create an empty object in the object list
void createEmptyObject();
/// create a logical brush
void createBrushIndirect( Q_UINT32 size, QDataStream& stream );
/// create a logical pen
void createPenIndirect( Q_UINT32 size, QDataStream& stream );
/// create a logical font
void createFontIndirect( Q_UINT32 size, QDataStream& stream );
/****************** misc *******************/
/// end of meta file
void end( Q_UINT32, QDataStream& stream );
/** Calculate header checksum */
static Q_UINT16 calcCheckSum( WmfPlaceableHeader* );
// function unimplemented
void notyet( Q_UINT32, QDataStream& stream );
void region( Q_UINT32, QDataStream& stream );
void palette( Q_UINT32, QDataStream& stream );
void escape( Q_UINT32, QDataStream& stream );
void setRelAbs( Q_UINT32, QDataStream& stream );
void setMapMode( Q_UINT32, QDataStream& stream );
void extFloodFill( Q_UINT32, QDataStream& stream );
void startDoc( Q_UINT32, QDataStream& stream );
void startPage( Q_UINT32, QDataStream& stream );
void endDoc( Q_UINT32, QDataStream& stream );
void endPage( Q_UINT32, QDataStream& stream );
void resetDC( Q_UINT32, QDataStream& stream );
void bitBlt( Q_UINT32, QDataStream& stream );
void setDibToDev( Q_UINT32, QDataStream& stream );
void createBrush( Q_UINT32, QDataStream& stream );
void createPatternBrush( Q_UINT32, QDataStream& stream );
void createBitmap( Q_UINT32, QDataStream& stream );
void createBitmapIndirect( Q_UINT32, QDataStream& stream );
void createPalette( Q_UINT32, QDataStream& stream );
void createRegion( Q_UINT32, QDataStream& stream );
private:
//-----------------------------------------------------------------------------
// Utilities and conversion Wmf -> Qt
/** Handle win-object-handles */
bool addHandle( KoWmfHandle* );
void deleteHandle( int );
/** Convert QINT16 points into QPointArray */
void pointArray( QDataStream& stream, QPointArray& pa );
/** Convertion between windows color and QColor */
QColor qtColor( Q_UINT32 color ) const
{ return QColor( color & 0xFF, (color>>8) & 0xFF, (color>>16) & 0xFF ); }
/** Convert (x1,y1) and (x2, y2) positions in angle and angleLength */
void xyToAngle( int xStart, int yStart, int xEnd, int yEnd, int& angle, int& aLength );
/** Convert windows rasterOp in QT rasterOp */
Qt::RasterOp winToQtRaster( Q_UINT16 param ) const;
Qt::RasterOp winToQtRaster( Q_UINT32 param ) const;
/** Converts DIB to BMP */
bool dibToBmp( QImage& bmp, QDataStream& stream, Q_UINT32 size);
public:
// state of the WMF
bool mValid;
bool mStandard;
bool mPlaceable;
bool mEnhanced;
/// bounding rectangle
QRect mBBox; // placeable file : this is the header
// standard file : this is the value in setWindowOrg and setWindowExt
/// number of points per inch for the default size
int mDpi;
/// number of functions to draw (==0 for all)
int mNbrFunc;
private:
// the output
KoWmfRead *mReadWmf;
// current coordinate != mBBox
QRect mWindow;
// current state of the drawing
QColor mTextColor;
Q_UINT16 mTextAlign;
int mTextRotation;
bool mWinding;
// memory allocation for WMF file
QBuffer* mBuffer;
int mOffsetFirstRecord;
// stack of object handle
KoWmfHandle** mObjHandleTab;
// number of object on the stack
int mNbrObject;
bool mStackOverflow;
};
/**
* static data
*/
static const struct KoWmfFunc {
void ( KoWmfReadPrivate::*method )( Q_UINT32, QDataStream& );
} koWmfFunc[] = {
{ &KoWmfReadPrivate::end }, // 0
{ &KoWmfReadPrivate::setBkColor }, // 1
{ &KoWmfReadPrivate::setBkMode }, // 2
{ &KoWmfReadPrivate::setMapMode }, // 3
{ &KoWmfReadPrivate::setRop }, // 4
{ &KoWmfReadPrivate::setRelAbs }, // 5
{ &KoWmfReadPrivate::setPolyFillMode }, // 6
{ &KoWmfReadPrivate::SetStretchBltMode }, // 7
{ &KoWmfReadPrivate::notyet }, // 8
{ &KoWmfReadPrivate::setTextColor }, // 9
{ &KoWmfReadPrivate::ScaleWindowExt }, // 10
{ &KoWmfReadPrivate::setWindowOrg }, // 11
{ &KoWmfReadPrivate::setWindowExt }, // 12
{ &KoWmfReadPrivate::notyet }, // 13
{ &KoWmfReadPrivate::notyet }, // 14
{ &KoWmfReadPrivate::OffsetWindowOrg }, // 15
{ &KoWmfReadPrivate::notyet }, // 16
{ &KoWmfReadPrivate::notyet }, // 17
{ &KoWmfReadPrivate::notyet }, // 18
{ &KoWmfReadPrivate::lineTo }, // 19
{ &KoWmfReadPrivate::moveTo }, // 20
{ &KoWmfReadPrivate::excludeClipRect }, // 21
{ &KoWmfReadPrivate::intersectClipRect }, // 22
{ &KoWmfReadPrivate::arc }, // 23
{ &KoWmfReadPrivate::ellipse }, // 24
{ &KoWmfReadPrivate::notyet }, // 25
{ &KoWmfReadPrivate::pie }, // 26
{ &KoWmfReadPrivate::rectangle }, // 27
{ &KoWmfReadPrivate::roundRect }, // 28
{ &KoWmfReadPrivate::notyet }, // 29
{ &KoWmfReadPrivate::saveDC }, // 30
{ &KoWmfReadPrivate::setPixel }, // 31
{ &KoWmfReadPrivate::notyet }, // 32
{ &KoWmfReadPrivate::textOut }, // 33
{ &KoWmfReadPrivate::bitBlt }, // 34
{ &KoWmfReadPrivate::notyet }, // 35
{ &KoWmfReadPrivate::polygon }, // 36
{ &KoWmfReadPrivate::polyline }, // 37
{ &KoWmfReadPrivate::escape }, // 38
{ &KoWmfReadPrivate::restoreDC }, // 39
{ &KoWmfReadPrivate::region }, // 40
{ &KoWmfReadPrivate::region }, // 41
{ &KoWmfReadPrivate::region }, // 42
{ &KoWmfReadPrivate::region }, // 43
{ &KoWmfReadPrivate::region }, // 44
{ &KoWmfReadPrivate::selectObject }, // 45
{ &KoWmfReadPrivate::setTextAlign }, // 46
{ 0 }, // 47
{ &KoWmfReadPrivate::chord }, // 48
{ &KoWmfReadPrivate::notyet }, // 49
{ &KoWmfReadPrivate::extTextOut }, // 50
{ &KoWmfReadPrivate::setDibToDev }, // 51
{ &KoWmfReadPrivate::palette }, // 52
{ &KoWmfReadPrivate::palette }, // 53
{ &KoWmfReadPrivate::palette }, // 54
{ &KoWmfReadPrivate::palette }, // 55
{ &KoWmfReadPrivate::polyPolygon }, // 56
{ &KoWmfReadPrivate::palette }, // 57
{ 0 }, // 58
{ 0 }, // 59
{ 0 }, // 60
{ 0 }, // 61
{ 0 }, // 62
{ 0 }, // 63
{ &KoWmfReadPrivate::dibBitBlt }, // 64
{ &KoWmfReadPrivate::dibStretchBlt }, // 65
{ &KoWmfReadPrivate::dibCreatePatternBrush }, // 66
{ &KoWmfReadPrivate::stretchDib }, // 67
{ 0 }, // 68
{ 0 }, // 69
{ 0 }, // 70
{ 0 }, // 71
{ &KoWmfReadPrivate::extFloodFill }, // 72
{ 0 }, // 73
{ 0 }, // 74
{ 0 }, // 75
{ &KoWmfReadPrivate::resetDC }, // 76
{ &KoWmfReadPrivate::startDoc }, // 77
{ 0 }, // 78
{ &KoWmfReadPrivate::startPage }, // 79
{ &KoWmfReadPrivate::endPage }, // 80
{ 0 }, // 81
{ 0 }, // 82
{ 0 }, // 83
{ 0 }, // 84
{ 0 }, // 85
{ 0 }, // 86
{ 0 }, // 87
{ 0 }, // 88
{ 0 }, // 89
{ 0 }, // 90
{ 0 }, // 91
{ 0 }, // 92
{ 0 }, // 93
{ &KoWmfReadPrivate::endDoc }, // 94
{ 0 }, // 95
// 0x5F last function until 0xF0
{ &KoWmfReadPrivate::deleteObject }, // 96
{ 0 }, // 97
{ 0 }, // 98
{ 0 }, // 99
{ 0 }, // 100
{ 0 }, // 101
{ 0 }, // 102
{ &KoWmfReadPrivate::createPalette }, // 103
{ &KoWmfReadPrivate::createBrush }, // 104
{ &KoWmfReadPrivate::createPatternBrush }, // 105
{ &KoWmfReadPrivate::createPenIndirect }, // 106
{ &KoWmfReadPrivate::createFontIndirect }, // 107
{ &KoWmfReadPrivate::createBrushIndirect }, //108
{ &KoWmfReadPrivate::createBitmapIndirect }, //109
{ &KoWmfReadPrivate::createBitmap }, // 110
{ &KoWmfReadPrivate::createRegion } // 111
};
#endif
|