filters
svgexport.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qpicture.h>
00022 #include <qpainter.h>
00023
00024 #include <kmessagebox.h>
00025
00026 #include <KoFilterChain.h>
00027 #include <KoStore.h>
00028
00029 #include <kgenericfactory.h>
00030
00031 #include "KPrDocument.h"
00032 #include "KPrView.h"
00033 #include "KPrCanvas.h"
00034
00035 #include "svgexport.h"
00036
00037
00038 typedef KGenericFactory<SvgExport, KoFilter> SvgExportFactory;
00039 K_EXPORT_COMPONENT_FACTORY( libkpresentersvgexport, SvgExportFactory( "svgexport" ) )
00040
00041 SvgExport::SvgExport(KoFilter *, const char *, const QStringList&)
00042 : KoFilter()
00043 {
00044 }
00045
00046 SvgExport::~SvgExport()
00047 {
00048 }
00049
00050
00051 KoFilter::ConversionStatus
00052 SvgExport::convert(const QCString& from, const QCString& to)
00053 {
00054 KoDocument * document = m_chain->inputDocument();
00055
00056 if ( !document )
00057 return KoFilter::StupidError;
00058
00059 if ( strcmp(document->className(), "KPrDocument") != 0)
00060 {
00061 kdWarning() << "document isn't a KPrDocument but a "
00062 << document->className() << endl;
00063 return KoFilter::NotImplemented;
00064 }
00065
00066
00067 if ( from != "application/x-kpresenter" || to != "image/svg+xml" )
00068 {
00069 kdWarning() << "Invalid mimetypes " << to << " " << from << endl;
00070 return KoFilter::NotImplemented;
00071 }
00072 KPrDocument * kpresenterdoc = const_cast<KPrDocument *>(static_cast<const KPrDocument *>(document));
00073
00074 if ( kpresenterdoc->mimeType() != "application/x-kpresenter" )
00075 {
00076 kdWarning() << "Invalid document mimetype " << kpresenterdoc->mimeType() << endl;
00077 return KoFilter::NotImplemented;
00078 }
00079 KoPageLayout layoutPage= kpresenterdoc->pageLayout();
00080 int width = int( layoutPage.ptWidth );
00081 int height = int( layoutPage.ptHeight );
00082
00083 QPicture picture;
00084 QPainter painter(&picture);
00085 QRect rect(QPoint(0, 0), QPoint(width, height));
00086 kpresenterdoc->paintContent(painter, rect, false);
00087 painter.end();
00088
00089 if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
00090 KMessageBox::error( 0, i18n( "Failed to write file." ),
00091 i18n( "SVG Export Error" ) );
00092 }
00093
00094 return KoFilter::OK;
00095 }
00096
00097
00098 #include "svgexport.moc"
00099
00100
|