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 <kapplication.h>
00025 #include <kmessagebox.h>
00026
00027 #include <KoFilterChain.h>
00028 #include <KoStore.h>
00029
00030 #include <kgenericfactory.h>
00031
00032 #include <kformulacontainer.h>
00033 #include "kformuladocument.h"
00034
00035 #include "svgexport.h"
00036
00037
00038 typedef KGenericFactory<SvgExport, KoFilter> SvgExportFactory;
00039 K_EXPORT_COMPONENT_FACTORY( libkfosvgexport, 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
00055 if ( from != "application/x-kformula" || to != "image/svg+xml" )
00056 return KoFilter::NotImplemented;
00057
00058
00059 KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
00060 if ( !storeIn ) {
00061 KMessageBox::error( 0, i18n("Failed to read data." ),
00062 i18n( "SVG Export Error" ) );
00063 return KoFilter::FileNotFound;
00064 }
00065
00066
00067 QDomDocument domIn;
00068 domIn.setContent( storeIn );
00069 QDomElement docNode = domIn.documentElement();
00070
00071
00072 KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper( kapp->config(), 0 );
00073 KFormula::Document* kformulaDoc = new KFormula::Document;
00074 wrapper->document( kformulaDoc );
00075 KFormula::Container* formula = kformulaDoc->createFormula();
00076
00077 if ( !kformulaDoc->loadXML( domIn ) ) {
00078 KMessageBox::error( 0, i18n( "Malformed XML data." ),
00079 i18n( "SVG Export Error" ) );
00080 return KoFilter::WrongFormat;
00081 }
00082
00083
00084 QPicture picture;
00085 QPainter painter(&picture);
00086 QRect rect(QPoint(0, 0), QPoint(500, 400));
00087 formula->draw( painter, rect, false );
00088 painter.end();
00089
00090
00091 if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
00092 KMessageBox::error( 0, i18n( "Failed to write file." ),
00093 i18n( "SVG Export Error" ) );
00094 }
00095
00096 delete formula;
00097 delete wrapper;
00098 return KoFilter::OK;
00099 }
00100
00101
00102 #include <svgexport.moc>
|