File indexing completed on 2025-11-30 14:29:58
0001 /* This file is part of the KDE project 0002 * Copyright (c) 2003 thierry lorthiois <lorthioist@wanadoo.fr> 0003 * Copyright (c) 2007 Jan Hambrecht <jaham@gmx.net> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License version 2 as published by the Free Software Foundation. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 #ifndef _WMFIMPORTPARSER_H_ 0020 #define _WMFIMPORTPARSER_H_ 0021 0022 #include <WmfAbstractBackend.h> 0023 #include <QPainter> 0024 #include <QMatrix> 0025 0026 class WmfDeviceContext; 0027 class KoXmlWriter; 0028 0029 /** 0030 * WMFImportParser inherits WmfAbstractBackend and translates WMF functions 0031 */ 0032 class WMFImportParser : public Libwmf::WmfAbstractBackend 0033 { 0034 public: 0035 explicit WMFImportParser(KoXmlWriter &svgWriter); 0036 ~WMFImportParser() override; 0037 0038 private: 0039 // ------------------------------------------------------------------------- 0040 // A virtual QPainter 0041 bool begin(const QRect &boundingBox) override; 0042 bool end() override; 0043 void save() override; 0044 void restore() override; 0045 0046 // Drawing attributes/modes 0047 void setCompositionMode(QPainter::CompositionMode) override; 0048 0049 /** 0050 * Change logical Coordinate 0051 * some wmf files call those functions several times in the middle of a drawing 0052 * others wmf files doesn't call setWindow* at all 0053 * negative width and height are possible 0054 */ 0055 void setWindowOrg(int left, int top) override; 0056 void setWindowExt(int width, int height) override; 0057 void setViewportOrg(int left, int top) override; 0058 void setViewportExt(int width, int height) override; 0059 0060 // Clipping 0061 // the 'CoordinateMode' is omitted : always CoordPainter in wmf 0062 // setClipRegion() is often used with save() and restore() => implement all or none 0063 void setClipRegion(Libwmf::WmfDeviceContext &context, const QRegion &rec); 0064 QRegion clipRegion(); 0065 0066 // Graphics drawing functions 0067 void setPixel(Libwmf::WmfDeviceContext &context, int x, int y, const QColor &color) override; 0068 void moveTo(Libwmf::WmfDeviceContext &context, int x, int y); 0069 void lineTo(Libwmf::WmfDeviceContext &context, int x, int y) override; 0070 void drawRect(Libwmf::WmfDeviceContext &context, int x, int y, int w, int h) override; 0071 void drawRoundRect(Libwmf::WmfDeviceContext &context, int x, int y, int w, int h, int = 25, int = 25) override; 0072 void drawEllipse(Libwmf::WmfDeviceContext &context, int x, int y, int w, int h) override; 0073 void drawArc(Libwmf::WmfDeviceContext &context, int x, int y, int w, int h, int a, int alen) override; 0074 void drawPie(Libwmf::WmfDeviceContext &context, int x, int y, int w, int h, int a, int alen) override; 0075 void drawChord(Libwmf::WmfDeviceContext &context, int x, int y, int w, int h, int a, int alen) override; 0076 void drawPolyline(Libwmf::WmfDeviceContext &context, const QPolygon &pa) override; 0077 void drawPolygon(Libwmf::WmfDeviceContext &context, const QPolygon &pa) override; 0078 /** 0079 * drawPolyPolygon draw the XOR of a list of polygons 0080 * listPa : list of polygons 0081 */ 0082 void drawPolyPolygon(Libwmf::WmfDeviceContext &context, QList<QPolygon>& listPa) override; 0083 void drawImage(Libwmf::WmfDeviceContext &context, int x, int y, const QImage &, 0084 int sx = 0, int sy = 0, int sw = -1, int sh = -1) override; 0085 void patBlt(Libwmf::WmfDeviceContext &context, int x, int y, int width, int height, 0086 quint32 rasterOperation) override; 0087 0088 // Text drawing 0089 // rotation = the degrees of rotation in counterclockwise 0090 // not yet implemented in KWinMetaFile 0091 void drawText(Libwmf::WmfDeviceContext &context, int x, int y, const QString &s) override; 0092 0093 // matrix transformation : only used in some bitmap manipulation 0094 void setMatrix(Libwmf::WmfDeviceContext &context, const QMatrix &matrix, bool combine = false) override; 0095 0096 //----------------------------------------------------------------------------- 0097 // Utilities 0098 // Add pen, brush and points to a path 0099 QString saveStroke(Libwmf::WmfDeviceContext &context); 0100 QString saveFill(Libwmf::WmfDeviceContext &context); 0101 0102 // coordinate transformation 0103 QRectF boundBox(int left, int top, int width, int height); 0104 QPointF coord(const QPoint &p); 0105 QSizeF size(const QSize &s); 0106 0107 private: 0108 void updateTransform(); 0109 0110 KoXmlWriter &m_svgWriter; 0111 0112 QSizeF m_pageSize; 0113 0114 struct CoordData { 0115 CoordData() : org(0,0), ext(0,0), extIsValid(false) {} 0116 QPointF org; 0117 QSizeF ext; 0118 bool extIsValid; 0119 }; 0120 0121 CoordData m_window; 0122 CoordData m_viewport; 0123 qreal m_scaleX; 0124 qreal m_scaleY; 0125 QMatrix m_matrix; 0126 }; 0127 0128 #endif // _WMFIMPORTPARSER_H_