SVN_SILENT made messages (.desktop file) - always resolve ours
[kdepim.git] / ktnef / qwmf.h
blob57a5052343fbc689c3ce20ffd68e03c36b558a42
1 /* Windows Meta File Loader
3 * Copyright ( C ) 1998 Stefan Taferner
4 * Modified 2002 thierry lorthiois
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or ( at your
9 * option ) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details. You should have received a copy
15 * of the GNU General Public License along with this program; if not, write
16 * to the Free Software Foundation, Inc, 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
19 #ifndef qwmf_h
20 #define qwmf_h
22 #include <QString>
23 #include <QPainter>
24 #include <QMatrix>
25 #include <QColor>
26 #include <QImage>
27 #include <QRect>
29 class QBuffer;
30 class QString;
31 class WmfCmd;
32 class WinObjHandle;
33 struct WmfPlaceableHeader;
35 /**
36 * QWinMetaFile is a WMF viewer based on Qt toolkit
37 * How to use QWinMetaFile :
38 * @code
39 * QWinMetaFile wmf;
40 * QPicture pic; // or QImage pic;
41 * if ( wmf.load( filename )
42 * wmf.paint( &pic );
43 * @endcode
46 class QWinMetaFile
48 public:
49 QWinMetaFile();
50 virtual ~QWinMetaFile();
52 /**
53 * Load WMF file.
54 * @return true on success.
56 virtual bool load(const QString &fileName);
57 virtual bool load(QBuffer &buffer);
59 /**
60 * Paint metafile to given paint-device using absolute or relative coordinate.
61 * - absolute coord. Reset the world transfomation Matrix
62 * - relative coord. Use the existing world transfomation Matrix
64 * @return true on success.
66 virtual bool paint(QPaintDevice *target, bool absolute = false);
68 /**
69 * @return true if the metafile is placeable.
71 bool isPlaceable(void) const
73 return mIsPlaceable;
76 /**
77 * @return true if the metafile is enhanced.
79 bool isEnhanced(void) const
81 return mIsEnhanced;
84 /**
85 * @return bounding rectangle
87 QRect bbox(void) const
89 return mBBox;
92 public: // should be protected but cannot
93 /* Metafile painter methods */
95 /** set window origin */
96 void setWindowOrg(long num, short *parms);
97 /** set window extents */
98 void setWindowExt(long num, short *parms);
100 /****************** Drawing *******************/
101 /** draw line to coord */
102 void lineTo(long num, short *parms);
103 /** move pen to coord */
104 void moveTo(long num, short *parms);
105 /** draw ellipse */
106 void ellipse(long num, short *parms);
107 /** draw polygon */
108 void polygon(long num, short *parms);
109 /** draw a list of polygons */
110 void polyPolygon(long num, short *parms);
111 /** draw series of lines */
112 void polyline(long num, short *parms);
113 /** draw a rectangle */
114 void rectangle(long num, short *parms);
115 /** draw round rectangle */
116 void roundRect(long num, short *parms);
117 /** draw arc */
118 void arc(long num, short *parms);
119 /** draw chord */
120 void chord(long num, short *parms);
121 /** draw pie */
122 void pie(long num, short *parms);
123 /** set polygon fill mode */
124 void setPolyFillMode(long num, short *parms);
125 /** set background pen color */
126 void setBkColor(long num, short *parms);
127 /** set background pen mode */
128 void setBkMode(long num, short *parms);
129 /** set a pixel */
130 void setPixel(long num, short *parms);
131 /** Set raster operation mode */
132 void setRop(long num, short *parms);
133 /** save device context */
134 void saveDC(long num, short *parms);
135 /** restore device context */
136 void restoreDC(long num, short *parms);
137 /** clipping region is the intersection of this region and the original region */
138 void intersectClipRect(long num, short *parms);
139 /** delete a clipping rectangle of the original region */
140 void excludeClipRect(long num, short *parms);
142 /****************** Text *******************/
143 /** set text color */
144 void setTextColor(long num, short *parms);
145 /** set text alignment */
146 void setTextAlign(long num, short *parms);
147 /** draw text */
148 void textOut(long num, short *parms);
149 void extTextOut(long num, short *parms);
151 /****************** Bitmap *******************/
152 /** copies a DIB into a dest location */
153 void dibBitBlt(long num, short *parms);
154 /** stretches a DIB into a dest location */
155 void dibStretchBlt(long num, short *parms);
156 void stretchDib(long num, short *parms);
157 /** create a pattern brush */
158 void dibCreatePatternBrush(long num, short *parms);
160 /****************** Object handle *******************/
161 /** Activate object handle */
162 void selectObject(long num, short *parms);
163 /** Free object handle */
164 void deleteObject(long num, short *parms);
165 /** create an empty object in the object list */
166 void createEmptyObject(long num, short *parms);
167 /** create a logical brush */
168 void createBrushIndirect(long num, short *parms);
169 /** create a logical pen */
170 void createPenIndirect(long num, short *parms);
171 /** create a logical font */
172 void createFontIndirect(long num, short *parms);
174 /****************** misc *******************/
175 /** nothing to do */
176 void noop(long, short *);
177 /** end of meta file */
178 void end(long /*num*/, short * /*parms*/);
179 /** Resolution of the image in dots per inch */
180 int dpi(void) const
182 return mDpi;
185 protected:
186 /** Calculate header checksum */
187 unsigned short calcCheckSum(WmfPlaceableHeader *);
189 /** Find function in metafunc table by metafile-function.
190 Returns index or -1 if not found. */
191 virtual int findFunc(unsigned short aFunc) const;
193 /** Fills given parms into mPoints. */
194 QPolygon *pointArray(short num, short *parms);
196 /** Returns color given by the two parameters */
197 QColor color(short *parm);
199 /** Converts two parameters to long */
200 unsigned int toDWord(short *parm);
202 /** Convert (x1,y1) and (x2, y2) positions in angle and angleLength */
203 void xyToAngle(int xStart, int yStart, int xEnd, int yEnd, int &angle, int &aLength);
205 /** Handle win-object-handles */
206 void addHandle(WinObjHandle *);
207 void deleteHandle(int);
209 /** Convert windows rasterOp in QT rasterOp */
210 QPainter::CompositionMode winToQtComposition(short parm) const;
211 QPainter::CompositionMode winToQtComposition(long parm) const;
213 /** Converts DIB to BMP */
214 bool dibToBmp(QImage &bmp, const char *dib, long size);
216 protected:
217 QPainter mPainter;
218 bool mIsPlaceable, mIsEnhanced, mValid;
220 // coordinate system
221 bool mAbsoluteCoord;
222 QMatrix mInternalWorldMatrix; // memorisation of WMF matrix transformation
223 QRect mHeaderBoundingBox;
224 QRect mBBox;
226 // information shared between Metafile Functions
227 QColor mTextColor;
228 int mTextAlign, mRotation;
229 bool mWinding;
231 WmfCmd *mFirstCmd;
232 WinObjHandle **mObjHandleTab;
233 QPolygon mPoints;
234 int mDpi;
235 QPoint mLastPos;
238 #endif /*qwmf_h*/