KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
7.2KB

  1. /* Windows Meta File Loader
  2. *
  3. * Copyright ( C ) 1998 Stefan Taferner
  4. * Modified 2002 thierry lorthiois
  5. *
  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.
  10. *
  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.
  18. */
  19. #ifndef qwmf_h
  20. #define qwmf_h
  21. #include <tqstring.h>
  22. #include <tqpainter.h>
  23. #include <tqwmatrix.h>
  24. #include <tqpointarray.h>
  25. #include <tqpen.h>
  26. #include <tqcolor.h>
  27. #include <tqimage.h>
  28. #include <tqrect.h>
  29. class TQBuffer;
  30. class TQString;
  31. class WmfCmd;
  32. class WinObjHandle;
  33. class WinObjPenHandle;
  34. class WinObjBrushHandle;
  35. struct WmfPlaceableHeader;
  36. /**
  37. * QWinMetaFile is a WMF viewer based on QT toolkit
  38. * How to use QWinMetaFile :
  39. * <pre>
  40. * #include "qwmf.h"
  41. * QWinMetaFile wmf;
  42. * TQPicture pic; // or TQImage pic;
  43. * if ( wmf.load( filename )
  44. *   wmf.paint( &pic );
  45. * </pre>
  46. */
  47. class QWinMetaFile
  48. {
  49. public:
  50. QWinMetaFile();
  51. virtual ~QWinMetaFile();
  52. /**
  53. * Load WMF file.
  54. * @return true on success.
  55. */
  56. virtual bool load( const TQString &fileName );
  57. virtual bool load( TQBuffer &buffer );
  58. /**
  59. * Paint metafile to given paint-device using absolute or relative coordinate.
  60. * - absolute coord. Reset the world transfomation Matrix
  61. * - relative coord. Use the existing world transfomation Matrix
  62. *
  63. * @return true on success.
  64. */
  65. virtual bool paint( const TQPaintDevice* target, bool absolute=false );
  66. /**
  67. * @return true if the metafile is placeable.
  68. */
  69. bool isPlaceable( void ) const { return mIsPlaceable; }
  70. /**
  71. * @return true if the metafile is enhanced.
  72. */
  73. bool isEnhanced( void ) const { return mIsEnhanced; }
  74. /**
  75. * @return bounding rectangle
  76. */
  77. TQRect bbox( void ) const { return mBBox; }
  78. public: // should be protected but cannot
  79. /* Metafile painter methods */
  80. /** set window origin */
  81. void setWindowOrg( long num, short* parms );
  82. /** set window extents */
  83. void setWindowExt( long num, short* parms );
  84. /****************** Drawing *******************/
  85. /** draw line to coord */
  86. void lineTo( long num, short* parms );
  87. /** move pen to coord */
  88. void moveTo( long num, short* parms );
  89. /** draw ellipse */
  90. void ellipse( long num, short* parms );
  91. /** draw polygon */
  92. void polygon( long num, short* parms );
  93. /** draw a list of polygons */
  94. void polyPolygon( long num, short* parms );
  95. /** draw series of lines */
  96. void polyline( long num, short* parms );
  97. /** draw a rectangle */
  98. void rectangle( long num, short* parms );
  99. /** draw round rectangle */
  100. void roundRect( long num, short* parms );
  101. /** draw arc */
  102. void arc( long num, short* parms );
  103. /** draw chord */
  104. void chord( long num, short* parms );
  105. /** draw pie */
  106. void pie( long num, short* parms );
  107. /** set polygon fill mode */
  108. void setPolyFillMode( long num, short* parms );
  109. /** set background pen color */
  110. void setBkColor( long num, short* parms );
  111. /** set background pen mode */
  112. void setBkMode( long num, short* parms );
  113. /** set a pixel */
  114. void setPixel( long num, short* parms );
  115. /** Set raster operation mode */
  116. void setRop( long num, short* parms );
  117. /** save device context */
  118. void saveDC( long num, short* parms );
  119. /** restore device context */
  120. void restoreDC( long num, short* parms );
  121. /** clipping region is the intersection of this region and the original region */
  122. void intersectClipRect( long num, short* parms );
  123. /** delete a clipping rectangle of the original region */
  124. void excludeClipRect( long num, short* parms );
  125. /****************** Text *******************/
  126. /** set text color */
  127. void setTextColor( long num, short* parms );
  128. /** set text alignment */
  129. void setTextAlign( long num, short* parms );
  130. /** draw text */
  131. void textOut( long num, short* parms );
  132. void extTextOut( long num, short* parms );
  133. /****************** Bitmap *******************/
  134. /** copies a DIB into a dest location */
  135. void dibBitBlt( long num, short* parms );
  136. /** stretches a DIB into a dest location */
  137. void dibStretchBlt( long num, short* parms );
  138. void stretchDib( long num, short* parms );
  139. /** create a pattern brush */
  140. void dibCreatePatternBrush( long num, short* parms );
  141. /****************** Object handle *******************/
  142. /** Activate object handle */
  143. void selectObject( long num, short* parms );
  144. /** Free object handle */
  145. void deleteObject( long num, short* parms );
  146. /** create an empty object in the object list */
  147. void createEmptyObject( long num, short* parms );
  148. /** create a logical brush */
  149. void createBrushIndirect( long num, short* parms );
  150. /** create a logical pen */
  151. void createPenIndirect( long num, short* parms );
  152. /** create a logical font */
  153. void createFontIndirect( long num, short* parms );
  154. /****************** misc *******************/
  155. /** nothing to do */
  156. void noop( long , short* );
  157. /** end of meta file */
  158. void end( long /*num*/, short* /*parms*/ );
  159. /** Resolution of the image in dots per inch */
  160. int dpi( void ) const { return mDpi; }
  161. protected:
  162. /** Calculate header checksum */
  163. unsigned short calcCheckSum( WmfPlaceableHeader* );
  164. /** Find function in metafunc table by metafile-function.
  165. Returns index or -1 if not found. */
  166. virtual int findFunc( unsigned short aFunc ) const;
  167. /** Fills given parms into mPoints. */
  168. TQPointArray* pointArray( short num, short* parms );
  169. /** Returns color given by the two parameters */
  170. TQColor color( short* parm );
  171. /** Converts two parameters to long */
  172. unsigned int toDWord( short* parm );
  173. /** Convert (x1,y1) and (x2, y2) positions in angle and angleLength */
  174. void xyToAngle( int xStart, int yStart, int xEnd, int yEnd, int& angle, int& aLength );
  175. /** Handle win-object-handles */
  176. void addHandle( WinObjHandle* );
  177. void deleteHandle( int );
  178. /** Convert windows rasterOp in QT rasterOp */
  179. TQt::RasterOp winToTQtRaster( short parm ) const;
  180. TQt::RasterOp winToTQtRaster( long parm ) const;
  181. /** Converts DIB to BMP */
  182. bool dibToBmp( TQImage& bmp, const char* dib, long size);
  183. protected:
  184. TQPainter mPainter;
  185. bool mIsPlaceable, mIsEnhanced, mValid;
  186. // coordinate system
  187. bool mAbsoluteCoord;
  188. TQWMatrix mInternalWorldMatrix; // memorisation of WMF matrix transformation
  189. TQRect mHeaderBoundingBox;
  190. TQRect mBBox;
  191. // information shared between Metafile Functions
  192. TQColor mTextColor;
  193. int mTextAlign, mRotation;
  194. bool mWinding;
  195. WmfCmd* mFirstCmd;
  196. WinObjHandle** mObjHandleTab;
  197. TQPointArray mPoints;
  198. int mDpi;
  199. };
  200. #endif /*qwmf_h*/