1 /* 2 Copyright 2008 Brad Hards <bradh@frogmouth.net> 3 Copyright 2009 Inge Wallin <inge@lysator.liu.se> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef EMFRECORDS_H 20 #define EMFRECORDS_H 21 22 #include <QDataStream> 23 #include <QColor> 24 #include <QImage> 25 #include <QRect> // also provides QSize 26 #include <QString> 27 28 #include "Bitmap.h" 29 /** 30 \file 31 32 Primary definitions for EMF Records 33 */ 34 35 /** 36 Namespace for Enhanced Metafile (EMF) classes 37 */ 38 namespace Libemf 39 { 40 41 class EmrTextObject; 42 43 44 /*****************************************************************************/ 45 46 /** 47 Simple representation of an EMR_BITBLT record 48 49 See MS-EMF Section 2.3.1.2 for details 50 */ 51 class BitBltRecord 52 { 53 public: 54 /** 55 Constructor for record type 56 57 \param stream the stream to read the record structure from 58 \param recordSize the record size 59 */ 60 BitBltRecord( QDataStream &stream, quint32 recordSize ); 61 ~BitBltRecord(); 62 63 /** 64 The X origin of the destination rectangle 65 */ xDest()66 qint32 xDest() const { return m_xDest; }; 67 68 /** 69 The Y origin of the destination rectangle 70 */ yDest()71 qint32 yDest() const { return m_yDest; }; 72 73 /** 74 The width of the destination rectangle 75 */ cxDest()76 qint32 cxDest() const { return m_cxDest; }; 77 78 /** 79 The height of the destination rectangle 80 */ cyDest()81 qint32 cyDest() const { return m_cyDest; }; 82 rasterOperation()83 quint32 rasterOperation() const { return m_BitBltRasterOperation; } 84 bkColorSrc()85 QColor bkColorSrc() const { return QColor(m_red, m_green, m_blue, m_reserved); } 86 87 /** 88 The destination rectangle 89 */ destinationRectangle()90 QRect destinationRectangle() const { return QRect( xDest(), yDest(), cxDest(), cyDest() ); }; 91 92 /** 93 The image to display 94 */ 95 QImage image(); 96 97 /** 98 Whether there is a valid image in this BitBlt record 99 */ 100 bool hasImage() const; 101 102 private: 103 // No copying for now, because we will get into trouble with the pointers. 104 // The remedy is to write a real operator=() and BitBltRecord(BitBltRecord&). 105 explicit BitBltRecord(BitBltRecord&); 106 BitBltRecord &operator=(BitBltRecord&); 107 108 private: 109 QRect m_bounds; 110 qint32 m_xDest; 111 qint32 m_yDest; 112 qint32 m_cxDest; 113 qint32 m_cyDest; 114 quint32 m_BitBltRasterOperation; 115 qint32 m_xSrc; 116 qint32 m_ySrc; 117 QTransform m_XFormSrc; 118 119 // Background color - elements below 120 quint8 m_red; 121 quint8 m_green; 122 quint8 m_blue; 123 quint8 m_reserved; 124 125 // Color table interpretation 126 quint32 m_UsageSrc; 127 128 // The source bitmap meta data 129 quint32 m_offBmiSrc; 130 quint32 m_cbBmiSrc; 131 quint32 m_offBitsSrc; 132 quint32 m_cbBitsSrc; 133 134 Bitmap *m_bitmap; // The source bitmap 135 136 //QByteArray m_imageData; 137 //QImage *m_image; 138 }; 139 140 /*****************************************************************************/ 141 142 /** 143 Simple representation of an EMR_STRETCHDIBITS record 144 145 See MS-EMF Section 2.3.1.7 for details 146 */ 147 class StretchDiBitsRecord 148 { 149 public: 150 /** 151 Constructor for record type 152 153 \param stream the stream to read the record structure from 154 \param recordSize the record size 155 */ 156 StretchDiBitsRecord( QDataStream &stream, quint32 recordSize ); 157 ~StretchDiBitsRecord(); 158 159 /** 160 The bounds of the affected area, in device units 161 */ 162 QRect bounds() const; 163 164 /** 165 The X origin of the destination rectangle 166 */ xDest()167 qint32 xDest() const { return m_xDest; }; 168 169 /** 170 The Y origin of the destination rectangle 171 */ yDest()172 qint32 yDest() const { return m_yDest; }; 173 174 /** 175 The width of the destination rectangle 176 */ cxDest()177 qint32 cxDest() const { return m_cxDest; }; 178 179 /** 180 The height of the destination rectangle 181 */ cyDest()182 qint32 cyDest() const { return m_cyDest; }; 183 184 /** 185 The destination rectangle 186 */ destinationRectangle()187 QRect destinationRectangle() const { return QRect( xDest(), yDest(), cxDest(), cyDest() ); }; 188 189 /** 190 The X origin of the source rectangle 191 */ xSrc()192 qint32 xSrc() const { return m_xSrc; }; 193 194 /** 195 The Y origin of the source rectangle 196 */ ySrc()197 qint32 ySrc() const { return m_ySrc; }; 198 199 /** 200 The width of the source rectangle 201 */ cxSrc()202 qint32 cxSrc() const { return m_cxSrc; }; 203 204 /** 205 The height of the source rectangle 206 */ cySrc()207 qint32 cySrc() const { return m_cySrc; }; 208 209 /** 210 The source rectangle 211 */ sourceRectangle()212 QRect sourceRectangle() const { return QRect( xSrc(), ySrc(), cxSrc(), cySrc() ); }; 213 214 /** 215 The raster operation 216 */ rasterOperation()217 qint32 rasterOperation() const { return m_BitBltRasterOperation; }; 218 usageSrc()219 quint32 usageSrc() const { return m_UsageSrc; }; 220 221 /** 222 The image to display 223 */ 224 QImage image(); 225 /** 226 Whether there is a valid image in this StretchDiBitsRecord record 227 */ 228 bool hasImage() const; 229 230 private: 231 // No copying for now, because we will get into trouble with the pointers. 232 // The remedy is to write a real operator=() and StretchDiBitsRecord(StretchDiBitsRecord&). 233 explicit StretchDiBitsRecord(StretchDiBitsRecord&); 234 StretchDiBitsRecord &operator=(StretchDiBitsRecord&); 235 236 private: 237 QRect m_Bounds; 238 qint32 m_xDest; 239 qint32 m_yDest; 240 qint32 m_xSrc; 241 qint32 m_ySrc; 242 qint32 m_cxSrc; 243 qint32 m_cySrc; 244 quint32 m_offBmiSrc; 245 quint32 m_cbBmiSrc; 246 quint32 m_offBitsSrc; 247 quint32 m_cbBitsSrc; 248 quint32 m_UsageSrc; 249 quint32 m_BitBltRasterOperation; 250 qint32 m_cxDest; 251 qint32 m_cyDest; 252 253 Bitmap *m_bitmap; // The source bitmap 254 }; 255 256 /*****************************************************************************/ 257 258 /** 259 Simple representation of an EMR_EXTCREATEFONTINDIRECTW record 260 261 See MS-EMF Section 2.3.7.8 for details 262 */ 263 class ExtCreateFontIndirectWRecord 264 { 265 public: 266 /** 267 Constructor for record type 268 269 \param stream the stream to read the record structure from 270 \param size the number of bytes in this record 271 */ 272 ExtCreateFontIndirectWRecord( QDataStream &stream, quint32 size ); 273 ~ExtCreateFontIndirectWRecord(); 274 275 276 /** 277 The font handle index 278 */ ihFonts()279 quint32 ihFonts() const { return m_ihFonts; }; 280 281 /** 282 The height of the font 283 */ height()284 qint32 height() const { return m_height; }; 285 286 /** 287 Whether this is a italic font 288 */ italic()289 quint8 italic() const { return m_italic; }; 290 291 /** 292 Whether this is a underlined font 293 */ underline()294 quint8 underline() const { return m_underline; }; 295 296 /** 297 The weight of this font 298 */ weight()299 quint32 weight() const { return m_weight; }; 300 301 /** 302 The name of the font face 303 */ fontFace()304 QString fontFace() const { return m_facename; }; 305 306 private: 307 quint32 m_ihFonts; 308 309 qint32 m_height; 310 qint32 m_width; 311 qint32 m_escapement; 312 qint32 m_orientation; 313 qint32 m_weight; 314 quint8 m_italic; 315 quint8 m_underline; 316 quint8 m_strikeout; 317 quint8 m_charSet; 318 quint8 m_outPrecision; 319 quint8 m_clipPrecision; 320 quint8 m_quality; 321 quint8 m_pitchAndFamily; 322 QString m_facename; 323 QString m_fullName; 324 QString m_style; 325 QString m_script; 326 327 // Routine to throw away a specific number of bytes 328 void soakBytes( QDataStream &stream, int numBytes ); 329 }; 330 331 } 332 333 #endif 334