filters

svgexport.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Inge Wallin <inge@lysator.liu.se>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA  02110-1301  USA.
00018 */
00019 
00020 #include <qpicture.h>
00021 #include <qpainter.h>
00022 
00023 #include <kmessagebox.h>
00024 
00025 #include <KoFilterChain.h>
00026 #include <KoStore.h>
00027 //#include <KoStoreDevice.h>
00028 #include <kgenericfactory.h>
00029 
00030 #include "kchart_part.h"
00031 
00032 #include "svgexport.h"
00033 
00034 
00035 typedef KGenericFactory<SvgExport, KoFilter> SvgExportFactory;
00036 K_EXPORT_COMPONENT_FACTORY( libkchartsvgexport, SvgExportFactory( "svgexport" ) )
00037 
00038 SvgExport::SvgExport(KoFilter *, const char *, const QStringList&) 
00039     : KoFilter()
00040 {
00041 }
00042 
00043 SvgExport::~SvgExport()
00044 {
00045 }
00046 
00047 
00048 KoFilter::ConversionStatus
00049 SvgExport::convert(const QCString& from, const QCString& to)
00050 {
00051     // Check for proper conversion.
00052     if ( from != "application/x-kchart" || to != "image/svg+xml" )
00053         return KoFilter::NotImplemented;
00054 
00055     // Read the contents of the KChart file
00056     KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
00057     if ( !storeIn ) {
00058     KMessageBox::error( 0, i18n("Failed to read data." ), 
00059                 i18n( "SVG Export Error" ) );
00060     return KoFilter::FileNotFound;
00061     }
00062 
00063     // Get the XML tree.
00064     QDomDocument  domIn;
00065     domIn.setContent( storeIn );
00066     QDomElement   docNode = domIn.documentElement();
00067 
00068     // Read the document from the XML tree.
00069     KChart::KChartPart  kchartDoc;
00070     if ( !kchartDoc.loadXML(0, domIn) ) {
00071         KMessageBox::error( 0, i18n( "Malformed XML data." ), 
00072                 i18n( "SVG Export Error" ) );
00073         return KoFilter::WrongFormat;
00074     }
00075 
00076     // Draw the actual bitmap.
00077     QPicture  picture;
00078     QPainter  painter(&picture);
00079     QRect     rect(QPoint(0, 0), QPoint(500, 400));
00080     kchartDoc.paintContent(painter, rect, false);
00081     painter.end();
00082 
00083     // Save the image.
00084     if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
00085         KMessageBox::error( 0, i18n( "Failed to write file." ), 
00086                 i18n( "SVG Export Error" ) );
00087     }
00088 
00089     return KoFilter::OK;
00090 }
00091 
00092 
00093 #include <svgexport.moc>
KDE Home | KDE Accessibility Home | Description of Access Keys