00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qbuffer.h>
00023 #include <qpainter.h>
00024 #include <qpicture.h>
00025 #include <qpixmap.h>
00026
00027 #include <kdebug.h>
00028 #include <kdeversion.h>
00029 #if ! KDE_IS_VERSION( 3,1,90 )
00030 #include <kdebugclasses.h>
00031 #endif
00032
00033 #include <kowmfpaint.h>
00034 #include "KoPictureKey.h"
00035 #include "KoPictureBase.h"
00036 #include "KoPictureWmf.h"
00037
00038 KoPictureWmf::KoPictureWmf(void) : m_clipart(KoPictureType::formatVersionQPicture)
00039 {
00040 }
00041
00042 KoPictureWmf::~KoPictureWmf(void)
00043 {
00044 }
00045
00046 KoPictureBase* KoPictureWmf::newCopy(void) const
00047 {
00048 return new KoPictureWmf(*this);
00049 }
00050
00051 KoPictureType::Type KoPictureWmf::getType(void) const
00052 {
00053 return KoPictureType::TypeWmf;
00054 }
00055
00056 bool KoPictureWmf::isNull(void) const
00057 {
00058 return m_clipart.isNull();
00059 }
00060
00061 void KoPictureWmf::drawQPicture(QPicture& clipart, QPainter& painter,
00062 int x, int y, int width, int height, int sx, int sy, int sw, int sh)
00063 {
00064 kdDebug(30003) << "Drawing KoPictureWmf " << this << endl;
00065 kdDebug(30003) << " x=" << x << " y=" << y << " width=" << width << " height=" << height << endl;
00066 kdDebug(30003) << " sx=" << sx << " sy=" << sy << " sw=" << sw << " sh=" << sh << endl;
00067 painter.save();
00068
00069 QRect br = clipart.boundingRect();
00070 kdDebug(30003) << " Bounding rect. " << br << endl;
00071
00072 painter.translate(x,y);
00073 if ( br.width() && br.height() )
00074 painter.scale(double(width)/double(br.width()),double(height)/double(br.height()));
00075 else
00076 kdWarning(30003) << "Null bounding rectangle: " << br.width() << " x " << br.height() << endl;
00077 painter.drawPicture(0,0,clipart);
00078 painter.restore();
00079 }
00080
00081 void KoPictureWmf::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool )
00082 {
00083 drawQPicture(m_clipart, painter, x, y, width, height, sx, sy, sw, sh);
00084 }
00085
00086 bool KoPictureWmf::loadData(const QByteArray& array, const QString& )
00087 {
00088
00089 kdDebug(30003) << "Trying to load clipart... (Size:" << array.size() << ")" << endl;
00090 m_rawData=array;
00091
00092 KoWmfPaint wmf;
00093 if (!wmf.load(array))
00094 {
00095 kdWarning(30003) << "Loading WMF has failed! (KoPictureWmf::load)" << endl;
00096 return false;
00097 }
00098 m_originalSize = wmf.boundingRect().size();
00099
00100 wmf.play(m_clipart, true);
00101
00102 return true;
00103 }
00104
00105 bool KoPictureWmf::save(QIODevice* io) const
00106 {
00107
00108 Q_ULONG size=io->writeBlock(m_rawData);
00109 return (size==m_rawData.size());
00110 }
00111
00112 QSize KoPictureWmf::getOriginalSize(void) const
00113 {
00114 return m_originalSize;
00115 }
00116
00117 QPixmap KoPictureWmf::generatePixmap(const QSize& size, bool )
00118 {
00119
00120 QPixmap pixmap(size);
00121 QPainter p;
00122
00123 p.begin( &pixmap );
00124 p.setBackgroundColor( Qt::white );
00125 pixmap.fill( Qt::white );
00126
00127 if ( m_originalSize.width() && m_originalSize.height() )
00128 p.scale( (double)pixmap.width() / (double)m_originalSize.width(), (double)pixmap.height() / (double)m_originalSize.height() );
00129 p.drawPicture( m_clipart );
00130 p.end();
00131 return pixmap;
00132 }
00133
00134 QString KoPictureWmf::getMimeType(const QString& ) const
00135 {
00136 return "image/x-wmf";
00137 }