kpresenter/svg/svgexport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Laurent Montel <montel@kde.org>
3 code based on svgexport.cpp from Inge Wallin <inge@lysator.liu.se>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA.
19*/
20
21#include <tqpicture.h>
22#include <tqpainter.h>
23
24#include <tdemessagebox.h>
25
26#include <KoFilterChain.h>
27#include <KoStore.h>
28//#include <KoStoreDevice.h>
29#include <kgenericfactory.h>
30
31#include "KPrDocument.h"
32#include "KPrView.h"
33#include "KPrCanvas.h"
34
35#include "svgexport.h"
36
37
38typedef KGenericFactory<SvgExport, KoFilter> SvgExportFactory;
39K_EXPORT_COMPONENT_FACTORY( libkpresentersvgexport, SvgExportFactory( "svgexport" ) )
40
41SvgExport::SvgExport(KoFilter *, const char *, const TQStringList&)
42 : KoFilter()
43{
44}
45
46SvgExport::~SvgExport()
47{
48}
49
50
51KoFilter::ConversionStatus
52SvgExport::convert(const TQCString& from, const TQCString& to)
53{
54 KoDocument * document = m_chain->inputDocument();
55
56 if ( !document )
57 return KoFilter::StupidError;
58
59 if ( strcmp(document->className(), "KPrDocument") != 0)
60 {
61 kdWarning() << "document isn't a KPrDocument but a "
62 << document->className() << endl;
63 return KoFilter::NotImplemented;
64 }
65
66 // Check for proper conversion.
67 if ( from != "application/x-kpresenter" || to != "image/svg+xml" )
68 {
69 kdWarning() << "Invalid mimetypes " << to << " " << from << endl;
70 return KoFilter::NotImplemented;
71 }
72 KPrDocument * kpresenterdoc = const_cast<KPrDocument *>(static_cast<const KPrDocument *>(document));
73
74 if ( kpresenterdoc->mimeType() != "application/x-kpresenter" )
75 {
76 kdWarning() << "Invalid document mimetype " << kpresenterdoc->mimeType() << endl;
77 return KoFilter::NotImplemented;
78 }
79 KoPageLayout layoutPage= kpresenterdoc->pageLayout();
80 int width = int( layoutPage.ptWidth );
81 int height = int( layoutPage.ptHeight );
82
83 TQPicture picture;
84 TQPainter painter(&picture);
85 TQRect rect(TQPoint(0, 0), TQPoint(width, height));
86 kpresenterdoc->paintContent(painter, rect, false);
87 painter.end();
88
89 if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
90 KMessageBox::error( 0, i18n( "Failed to write file." ),
91 i18n( "SVG Export Error" ) );
92 }
93
94 return KoFilter::OK;
95}
96
97
98#include "svgexport.moc"
99
100