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::load(
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)
00106 {
00107
00108 Q_ULONG size=io->writeBlock(m_rawData);
00109
return (size==m_rawData.size());
00110 }
00111
00112
bool KoPictureWmf::saveAsKOffice1Dot1(
QIODevice* io,
const QString& )
00113 {
00114
QPicture picture(3);
00115
00116
bool result=
false;
00117
KoWmfPaint wmf;
00118
if (wmf.
load(m_rawData))
00119 {
00120 wmf.
play(picture,
true);
00121 result=picture.save(io,NULL);
00122 }
00123
return result;
00124 }
00125
00126
QSize KoPictureWmf::getOriginalSize(
void)
const
00127
{
00128
return m_originalSize;
00129 }
00130
00131
QPixmap KoPictureWmf::generatePixmap(
const QSize& size,
bool )
00132 {
00133
00134
QPixmap pixmap(size);
00135
QPainter p;
00136
00137 p.begin( &pixmap );
00138 p.setBackgroundColor( Qt::white );
00139 pixmap.fill( Qt::white );
00140
00141
if ( m_originalSize.width() && m_originalSize.height() )
00142 p.
scale( (
double)pixmap.width() / (
double)m_originalSize.width(), (
double)pixmap.height() / (
double)m_originalSize.height() );
00143 p.drawPicture( m_clipart );
00144 p.end();
00145
return pixmap;
00146 }
00147
00148
bool KoPictureWmf::isClipartAsKOffice1Dot1(
void)
const
00149
{
00150
return true;
00151 }
00152
00153
QString KoPictureWmf::getMimeType(
const QString& )
const
00154
{
00155
return "image/x-wmf";
00156 }