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#include <tdeversion.h>
29#if ! KDE_IS_VERSION( 3,1,90 )
30#include <kdebugclasses.h>
31#endif
32
33#include <kowmfpaint.h>
34#include "KoPictureKey.h"
35#include "KoPictureBase.h"
36#include "KoPictureWmf.h"
37
38KoPictureWmf::KoPictureWmf(void) : m_clipart(KoPictureType::formatVersionTQPicture)
39{
40}
41
42KoPictureWmf::~KoPictureWmf(void)
43{
44}
45
46KoPictureBase* KoPictureWmf::newCopy(void) const
47{
48 return new KoPictureWmf(*this);
49}
50
51KoPictureType::Type KoPictureWmf::getType(void) const
52{
53 return KoPictureType::TypeWmf;
54}
55
56bool KoPictureWmf::isNull(void) const
57{
58 return m_clipart.isNull();
59}
60
61void KoPictureWmf::drawTQPicture(TQPicture& clipart, TQPainter& painter,
62 int x, int y, int width, int height, int sx, int sy, int sw, int sh)
63{
64 kdDebug(30003) << "Drawing KoPictureWmf " << this << endl;
65 kdDebug(30003) << " x=" << x << " y=" << y << " width=" << width << " height=" << height << endl;
66 kdDebug(30003) << " sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh << endl;
67 painter.save();
68 // Thanks to Harri, TQt3 makes it much easier than TQt2 ;)
69 TQRect br = clipart.boundingRect();
70 kdDebug(30003) << " Bounding rect. " << br << endl;
71
72 painter.translate(x,y); // Translating must be done before scaling!
73 if ( br.width() && br.height() )
74 painter.scale(double(width)/double(br.width()),double(height)/double(br.height()));
75 else
76 kdWarning(30003) << "Null bounding rectangle: " << br.width() << " x " << br.height() << endl;
77 painter.drawPicture(0,0,clipart);
78 painter.restore();
79}
80
81void KoPictureWmf::draw(TQPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool /*fastMode*/)
82{
83 drawTQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
84}
85
86bool KoPictureWmf::loadData(const TQByteArray& array, const TQString& /* extension */)
87{
88 // Second, create the original clipart
89 kdDebug(30003) << "Trying to load clipart... (Size:" << array.size() << ")" << endl;
90 m_rawData=array;
91
92 KoWmfPaint wmf;
93 if (!wmf.load(array))
94 {
95 kdWarning(30003) << "Loading WMF has failed! (KoPictureWmf::load)" << endl;
96 return false;
97 }
98 m_originalSize = wmf.boundingRect().size();
99 // draw wmf file with relative coordinate
100 wmf.play(m_clipart, true);
101
102 return true;
103}
104
105bool KoPictureWmf::save(TQIODevice* io) const
106{
107 // We save the raw data, as the SVG supposrt in TQPicture is poor
108 TQ_ULONG size=io->writeBlock(m_rawData); // WARNING: writeBlock returns TQ_LONG but size() TQ_ULONG!
109 return (size==m_rawData.size());
110}
111
112TQSize KoPictureWmf::getOriginalSize(void) const
113{
114 return m_originalSize;
115}
116
117TQPixmap KoPictureWmf::generatePixmap(const TQSize& size, bool /*smoothScale*/)
118{
119 // Not sure if it works, but it worked for KoPictureFilePreviewWidget::setClipart
120 TQPixmap pixmap(size);
121 TQPainter p;
122
123 p.begin( &pixmap );
124 p.setBackgroundColor( TQt::white );
125 pixmap.fill( TQt::white );
126
127 if ( m_originalSize.width() && m_originalSize.height() )
128 p.scale( (double)pixmap.width() / (double)m_originalSize.width(), (double)pixmap.height() / (double)m_originalSize.height() );
129 p.drawPicture( m_clipart );
130 p.end();
131 return pixmap;
132}
133
134TQString KoPictureWmf::getMimeType(const TQString& /* extension */) const
135{
136 return "image/x-wmf";
137}
KoWmfPaint inherits the abstract class KoWmfRead and redirects WMF actions onto a TQPaintDevice.
Definition kowmfpaint.h:43
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