filters

kchart/svg/svgexport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Inge Wallin <inge@lysator.liu.se>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301 USA.
18*/
19
20#include <tqpicture.h>
21#include <tqpainter.h>
22
23#include <tdemessagebox.h>
24
25#include <KoFilterChain.h>
26#include <KoStore.h>
27//#include <KoStoreDevice.h>
28#include <kgenericfactory.h>
29
30#include "kchart_part.h"
31
32#include "svgexport.h"
33
34
35typedef KGenericFactory<SvgExport, KoFilter> SvgExportFactory;
36K_EXPORT_COMPONENT_FACTORY( libkchartsvgexport, SvgExportFactory( "svgexport" ) )
37
38SvgExport::SvgExport(KoFilter *, const char *, const TQStringList&)
39 : KoFilter()
40{
41}
42
43SvgExport::~SvgExport()
44{
45}
46
47
48KoFilter::ConversionStatus
49SvgExport::convert(const TQCString& from, const TQCString& to)
50{
51 // Check for proper conversion.
52 if ( from != "application/x-kchart" || to != "image/svg+xml" )
53 return KoFilter::NotImplemented;
54
55 // Read the contents of the KChart file
56 KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
57 if ( !storeIn ) {
58 KMessageBox::error( 0, i18n("Failed to read data." ),
59 i18n( "SVG Export Error" ) );
60 return KoFilter::FileNotFound;
61 }
62
63 // Get the XML tree.
64 TQDomDocument domIn;
65 domIn.setContent( storeIn );
66 TQDomElement docNode = domIn.documentElement();
67
68 // Read the document from the XML tree.
69 KChart::KChartPart kchartDoc;
70 if ( !kchartDoc.loadXML(0, domIn) ) {
71 KMessageBox::error( 0, i18n( "Malformed XML data." ),
72 i18n( "SVG Export Error" ) );
73 return KoFilter::WrongFormat;
74 }
75
76 // Draw the actual bitmap.
77 TQPicture picture;
78 TQPainter painter(&picture);
79 TQRect rect(TQPoint(0, 0), TQPoint(500, 400));
80 kchartDoc.paintContent(painter, rect, false);
81 painter.end();
82
83 // Save the image.
84 if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
85 KMessageBox::error( 0, i18n( "Failed to write file." ),
86 i18n( "SVG Export Error" ) );
87 }
88
89 return KoFilter::OK;
90}
91
92
93#include <svgexport.moc>