File indexing completed on 2026-05-10 15:32:18
0001 /* This file is part of the KDE project 0002 Copyright (C) 2002 Lars Siebold <khandha5@gmx.net> 0003 Copyright (C) 2002-2003,2005 Rob Buis <buis@kde.org> 0004 Copyright (C) 2002,2005-2006 David Faure <faure@kde.org> 0005 Copyright (C) 2002 Werner Trobin <trobin@kde.org> 0006 Copyright (C) 2002 Lennart Kudling <kudling@kde.org> 0007 Copyright (C) 2004 Nicolas Goutte <nicolasg@snafu.de> 0008 Copyright (C) 2005 Boudewijn Rempt <boud@valdyas.org> 0009 Copyright (C) 2005 Raphael Langerhorst <raphael.langerhorst@kdemail.net> 0010 Copyright (C) 2005 Thomas Zander <zander@kde.org> 0011 Copyright (C) 2005,2007-2008 Jan Hambrecht <jaham@gmx.net> 0012 Copyright (C) 2006 Inge Wallin <inge@lysator.liu.se> 0013 Copyright (C) 2006 Martin Pfeiffer <hubipete@gmx.net> 0014 Copyright (C) 2006 Gábor Lehel <illissius@gmail.com> 0015 Copyright (C) 2006 Laurent Montel <montel@kde.org> 0016 Copyright (C) 2006 Christian Mueller <cmueller@gmx.de> 0017 Copyright (C) 2006 Ariya Hidayat <ariya@kde.org> 0018 Copyright (C) 2010 Thorsten Zachmann <zachmann@kde.org> 0019 0020 This library is free software; you can redistribute it and/or 0021 modify it under the terms of the GNU Library General Public 0022 License as published by the Free Software Foundation; either 0023 version 2 of the License, or (at your option) any later version. 0024 0025 This library is distributed in the hope that it will be useful, 0026 but WITHOUT ANY WARRANTY; without even the implied warranty of 0027 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0028 Library General Public License for more details. 0029 0030 You should have received a copy of the GNU Library General Public License 0031 along with this library; see the file COPYING.LIB. If not, write to 0032 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0033 * Boston, MA 02110-1301, USA. 0034 */ 0035 0036 #include "SvgExport.h" 0037 #include <SvgWriter.h> 0038 0039 #include <KarbonDocument.h> 0040 #include <KarbonPart.h> 0041 0042 #include <KoDocument.h> 0043 #include <KoFilterChain.h> 0044 #include <KoPAPageBase.h> 0045 #include <KoPageLayout.h> 0046 0047 #include <kpluginfactory.h> 0048 0049 #include <QString> 0050 0051 K_PLUGIN_FACTORY_WITH_JSON(SvgExportFactory, "calligra_filter_karbon2svg.json", 0052 registerPlugin<SvgExport>();) 0053 0054 SvgExport::SvgExport(QObject*parent, const QVariantList&) 0055 : KoFilter(parent) 0056 { 0057 } 0058 0059 KoFilter::ConversionStatus SvgExport::convert(const QByteArray& from, const QByteArray& to) 0060 { 0061 if (to != "image/svg+xml" || from != "application/vnd.oasis.opendocument.graphics") 0062 return KoFilter::NotImplemented; 0063 0064 KoDocument * document = m_chain->inputDocument(); 0065 if (!document) 0066 return KoFilter::ParsingError; 0067 0068 KarbonDocument * karbonPart = dynamic_cast<KarbonDocument*>(document); 0069 if (!karbonPart) 0070 return KoFilter::WrongFormat; 0071 0072 KoPAPageBase *page = karbonPart->pages().value(0); 0073 if (!page) { 0074 return KoFilter::WrongFormat; 0075 } 0076 const KoPageLayout &layout = page->pageLayout(); 0077 const QSizeF size(layout.width, layout.height); 0078 SvgWriter writer(page->shapes(), size); 0079 if (!writer.save(m_chain->outputFile(), true)) 0080 return KoFilter::CreationError; 0081 0082 return KoFilter::OK; 0083 } 0084 0085 #include "SvgExport.moc"