40
40
typedef KGenericFactory<SvgExport> SvgExportFactory;
41
K_EXPORT_COMPONENT_FACTORY( libkfosvgexport, SvgExportFactory( "svgexport" ) )
41
K_EXPORT_COMPONENT_FACTORY(libkfosvgexport, SvgExportFactory("svgexport"))
43
43
SvgExport::SvgExport(QObject* parent, const QStringList&)
54
54
SvgExport::convert(const QByteArray& from, const QByteArray& to)
56
56
// Check for proper conversion.
57
if ( from != "application/x-kformula" || to != "image/svg+xml" )
57
if (from != "application/x-kformula" || to != "image/svg+xml")
58
58
return KoFilter::NotImplemented;
60
60
// Read the contents of the KFormula file
61
KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
63
KMessageBox::error( 0, i18n("Failed to read data." ),
64
i18n( "SVG Export Error" ) );
65
return KoFilter::FileNotFound;
61
KoStoreDevice* storeIn = m_chain->storageFile("root", KoStore::Read);
63
KMessageBox::error(0, i18n("Failed to read data."),
64
i18n("SVG Export Error"));
65
return KoFilter::FileNotFound;
68
68
// Get the XML tree.
69
69
QDomDocument domIn;
70
domIn.setContent( storeIn );
70
domIn.setContent(storeIn);
71
71
QDomElement docNode = domIn.documentElement();
73
73
// Read the document from the XML tree.
74
KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper( KGlobal::config(), 0 );
74
KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper(KGlobal::config(), 0);
75
75
KFormula::Document* kformulaDoc = new KFormula::Document;
76
wrapper->document( kformulaDoc );
76
wrapper->document(kformulaDoc);
77
77
KFormula::Container* formula = kformulaDoc->createFormula();
79
if ( !kformulaDoc->loadXML( domIn ) ) {
80
KMessageBox::error( 0, i18n( "Malformed XML data." ),
81
i18n( "SVG Export Error" ) );
79
if (!kformulaDoc->loadXML(domIn)) {
80
KMessageBox::error(0, i18n("Malformed XML data."),
81
i18n("SVG Export Error"));
82
82
return KoFilter::WrongFormat;
87
87
QPainter painter(&picture);
88
88
QRect rect(QPoint(0, 0), QPoint(500, 400));
89
formula->draw( painter, rect, false );
89
formula->draw(painter, rect, false);
93
if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
94
KMessageBox::error( 0, i18n( "Failed to write file." ),
95
i18n( "SVG Export Error" ) );
93
if (!picture.save(m_chain->outputFile(), "SVG")) {
94
KMessageBox::error(0, i18n("Failed to write file."),
95
i18n("SVG Export Error"));