lib

KoPictureWmf.cpp
1/* This file is part of the KDE project
2 Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
3 Copyright (c) 2001 David Faure <faure@kde.org>
4 Copyright (C) 2002 Nicolas GOUTTE <goutte@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include <tqbuffer.h>
23#include <tqpainter.h>
24#include <tqpicture.h>
25#include <tqpixmap.h>
26
27#include <kdebug.h>
28
29#include <kowmfpaint.h>
30#include "KoPictureKey.h"
31#include "KoPictureBase.h"
32#include "KoPictureWmf.h"
33
34KoPictureWmf::KoPictureWmf(void) : m_clipart(KoPictureType::formatVersionTQPicture)
35{
36}
37
38KoPictureWmf::~KoPictureWmf(void)
39{
40}
41
42KoPictureBase* KoPictureWmf::newCopy(void) const
43{
44 return new KoPictureWmf(*this);
45}
46
47KoPictureType::Type KoPictureWmf::getType(void) const
48{
49 return KoPictureType::TypeWmf;
50}
51
52bool KoPictureWmf::isNull(void) const
53{
54 return m_clipart.isNull();
55}
56
57void KoPictureWmf::drawTQPicture(TQPicture& clipart, TQPainter& painter,
58 int x, int y, int width, int height, int sx, int sy, int sw, int sh)
59{
60 kdDebug(30003) << "Drawing KoPictureWmf " << this << endl;
61 kdDebug(30003) << " x=" << x << " y=" << y << " width=" << width << " height=" << height << endl;
62 kdDebug(30003) << " sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh << endl;
63 painter.save();
64 // Thanks to Harri, TQt3 makes it much easier than TQt2 ;)
65 TQRect br = clipart.boundingRect();
66 kdDebug(30003) << " Bounding rect. " << br << endl;
67
68 painter.translate(x,y); // Translating must be done before scaling!
69 if ( br.width() && br.height() )
70 painter.scale(double(width)/double(br.width()),double(height)/double(br.height()));
71 else
72 kdWarning(30003) << "Null bounding rectangle: " << br.width() << " x " << br.height() << endl;
73 painter.drawPicture(0,0,clipart);
74 painter.restore();
75}
76
77void KoPictureWmf::draw(TQPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool /*fastMode*/)
78{
79 drawTQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
80}
81
82bool KoPictureWmf::loadData(const TQByteArray& array, const TQString& /* extension */)
83{
84 // Second, create the original clipart
85 kdDebug(30003) << "Trying to load clipart... (Size:" << array.size() << ")" << endl;
86 m_rawData=array;
87
88 KoWmfPaint wmf;
89 if (!wmf.load(array))
90 {
91 kdWarning(30003) << "Loading WMF has failed! (KoPictureWmf::load)" << endl;
92 return false;
93 }
94 m_originalSize = wmf.boundingRect().size();
95 // draw wmf file with relative coordinate
96 wmf.play(m_clipart, true);
97
98 return true;
99}
100
101bool KoPictureWmf::save(TQIODevice* io) const
102{
103 // We save the raw data, as the SVG supposrt in TQPicture is poor
104 TQ_ULONG size=io->writeBlock(m_rawData); // WARNING: writeBlock returns TQ_LONG but size() TQ_ULONG!
105 return (size==m_rawData.size());
106}
107
108TQSize KoPictureWmf::getOriginalSize(void) const
109{
110 return m_originalSize;
111}
112
113TQPixmap KoPictureWmf::generatePixmap(const TQSize& size, bool /*smoothScale*/)
114{
115 // Not sure if it works, but it worked for KoPictureFilePreviewWidget::setClipart
116 TQPixmap pixmap(size);
117 TQPainter p;
118
119 p.begin( &pixmap );
120 p.setBackgroundColor( TQt::white );
121 pixmap.fill( TQt::white );
122
123 if ( m_originalSize.width() && m_originalSize.height() )
124 p.scale( (double)pixmap.width() / (double)m_originalSize.width(), (double)pixmap.height() / (double)m_originalSize.height() );
125 p.drawPicture( m_clipart );
126 p.end();
127 return pixmap;
128}
129
130TQString KoPictureWmf::getMimeType(const TQString& /* extension */) const
131{
132 return "image/x-wmf";
133}
bool play(TQPaintDevice &target, bool relativeCoord=false)
play WMF file on a TQPaintDevice.
virtual bool load(const TQString &fileName)
Load WMF file.
Definition kowmfread.cpp:34
virtual TQRect boundingRect(void) const
Returns the bounding rectangle Standard Meta File : return the bounding box from setWindowOrg and set...
Definition kowmfread.cpp:83