1 /* This file is part of the KDE libraries 2 * 3 * Copyright (c) 1998 Stefan Taferner 4 * 2001/2003 thierry lorthiois (lorthioist@wanadoo.fr) 5 * 2009-2011 Inge Wallin <inge@lysator.liu.se> 6 * With the help of WMF documentation by Caolan Mc Namara 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Library General Public 10 License version 2 as published by the Free Software Foundation. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Library General Public License for more details. 16 17 You should have received a copy of the GNU Library General Public License 18 along with this library; see the file COPYING.LIB. If not, write to 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #ifndef _WMFPARSER_H_ 24 #define _WMFPARSER_H_ 25 26 #include <QColor> 27 #include <QRect> 28 29 #include "WmfEnums.h" 30 #include "WmfStructs.h" 31 #include "WmfDeviceContext.h" 32 #include "WmfStack.h" 33 34 class WmfAbstractBackend; 35 class QBuffer; 36 class QPolygon; 37 38 /** 39 Namespace for Windows Metafile (WMF) classes 40 */ 41 namespace Libwmf 42 { 43 44 45 /** 46 * WmfParser allows to read WMF files 47 * 48 */ 49 50 class WmfParser 51 { 52 public: 53 WmfParser(); 54 virtual ~WmfParser(); 55 56 /** 57 * Load WMF file. Returns true on success. 58 */ 59 bool load(const QByteArray& array); 60 61 /** 62 * Plays a metafile using @p backend as backend and returns true on success. 63 * To draw on a device you have to inherit the class WmfAbstractBackend. 64 */ 65 bool play(WmfAbstractBackend* backend); 66 67 /****************** Object handle *******************/ 68 /// create an empty object in the object list 69 void createEmptyObject(); 70 71 /****************** misc *******************/ 72 73 /** Calculate header checksum */ 74 static quint16 calcCheckSum(WmfPlaceableHeader*); 75 76 private: 77 //----------------------------------------------------------------------------- 78 // Utilities and conversion Wmf -> Qt 79 80 // Create a boundingbox from all set{Window,Viewport}{Org,Ext} records. 81 void createBoundingBox(QDataStream &st); 82 83 /** Handle win-object-handles */ 84 bool addHandle(KoWmfHandle*); 85 void deleteHandle(int); 86 87 /** Convert QINT16 points into QPointArray */ 88 void pointArray(QDataStream& stream, QPolygon& pa); 89 90 /** Conversion between windows color and QColor */ qtColor(quint32 color)91 QColor qtColor(quint32 color) const { 92 return QColor(color & 0xFF, (color >> 8) & 0xFF, (color >> 16) & 0xFF); 93 } 94 95 /** Convert (x1,y1) and (x2, y2) positions in angle and angleLength */ 96 void xyToAngle(int xStart, int yStart, int xEnd, int yEnd, int& angle, int& aLength); 97 98 /** Convert windows rasterOp in QT rasterOp */ 99 QPainter::CompositionMode winToQtComposition(quint16 param) const; 100 QPainter::CompositionMode winToQtComposition(quint32 param) const; 101 102 /** Converts DIB to BMP */ 103 bool dibToBmp(QImage& bmp, QDataStream& stream, quint32 size); 104 105 106 public: 107 // state of the WMF 108 bool mValid; 109 bool mStandard; 110 bool mPlaceable; 111 bool mEnhanced; 112 113 // Bounding rectangle. In a placeable file this is in the header, 114 // otherwise its comprised of calls to setWindowOrg and setWindowExt. 115 // 116 // We can't use a QRect here because width and/or height may be negative. 117 qint16 mBBoxTop; 118 qint16 mBBoxLeft; 119 qint16 mBBoxRight; 120 qint16 mBBoxBottom; 121 qint16 mMaxWidth; 122 qint16 mMaxHeight; 123 124 // standard file : this is the value in setWindowOrg and setWindowExt 125 // number of points per inch for the default size 126 int mDpi; 127 128 /// number of functions to draw (==0 for all) 129 int mNbrFunc; 130 131 private: 132 // the output strategy 133 WmfAbstractBackend *m_backend; 134 135 // Current state of the drawing 136 WmfDeviceContext mDeviceContext; 137 138 WmfLayout mLayout; 139 QColor mTextColor; 140 bool mWinding; 141 quint16 mMapMode; 142 143 // Memory allocation for WMF file 144 QBuffer* mBuffer; 145 int mOffsetFirstRecord; 146 147 // stack of object handle 148 KoWmfHandle** mObjHandleTab; 149 int mNbrObject; // number of object on the stack 150 bool mStackOverflow; 151 }; 152 153 154 } 155 156 #endif 157 158