filters

svgexport.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Laurent Montel <montel@kde.org>
00003    code based on svgexport.cc from Inge Wallin <inge@lysator.liu.se>
00004    
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA  02110-1301  USA.
00019 */
00020 
00021 #include <qpicture.h>
00022 #include <qpainter.h>
00023 
00024 #include <kmessagebox.h>
00025 
00026 #include <KoFilterChain.h>
00027 #include <KoStore.h>
00028 //#include <KoStoreDevice.h>
00029 #include <kgenericfactory.h>
00030 
00031 #include "KPrDocument.h"
00032 #include "KPrView.h"
00033 #include "KPrCanvas.h"
00034 
00035 #include "svgexport.h"
00036 
00037 
00038 typedef KGenericFactory<SvgExport, KoFilter> SvgExportFactory;
00039 K_EXPORT_COMPONENT_FACTORY( libkpresentersvgexport, SvgExportFactory( "svgexport" ) )
00040 
00041 SvgExport::SvgExport(KoFilter *, const char *, const QStringList&) 
00042     : KoFilter()
00043 {
00044 }
00045 
00046 SvgExport::~SvgExport()
00047 {
00048 }
00049 
00050 
00051 KoFilter::ConversionStatus
00052 SvgExport::convert(const QCString& from, const QCString& to)
00053 {
00054     KoDocument * document = m_chain->inputDocument();
00055 
00056     if ( !document )
00057         return KoFilter::StupidError;
00058 
00059     if ( strcmp(document->className(), "KPrDocument") != 0)
00060     {
00061         kdWarning() << "document isn't a KPrDocument but a "
00062                      << document->className() << endl;
00063         return KoFilter::NotImplemented;
00064     }
00065 
00066     // Check for proper conversion.
00067     if ( from != "application/x-kpresenter" || to != "image/svg+xml" )
00068     {
00069         kdWarning() << "Invalid mimetypes " << to << " " << from << endl;
00070         return KoFilter::NotImplemented;
00071     }
00072     KPrDocument * kpresenterdoc = const_cast<KPrDocument *>(static_cast<const KPrDocument *>(document));
00073 
00074     if ( kpresenterdoc->mimeType() != "application/x-kpresenter" )
00075     {
00076         kdWarning() << "Invalid document mimetype " << kpresenterdoc->mimeType() << endl;
00077         return KoFilter::NotImplemented;
00078     }
00079     KoPageLayout layoutPage= kpresenterdoc->pageLayout();
00080     int width =  int( layoutPage.ptWidth );
00081     int height = int( layoutPage.ptHeight );
00082     
00083     QPicture  picture;
00084     QPainter  painter(&picture);
00085     QRect     rect(QPoint(0, 0), QPoint(width, height));
00086     kpresenterdoc->paintContent(painter, rect, false);
00087     painter.end();
00088     
00089     if ( !picture.save( m_chain->outputFile(), "SVG" ) ) {
00090         KMessageBox::error( 0, i18n( "Failed to write file." ),
00091                             i18n( "SVG Export Error" ) );
00092     }
00093     
00094     return KoFilter::OK;
00095 }
00096 
00097 
00098 #include "svgexport.moc"
00099 
00100 
KDE Home | KDE Accessibility Home | Description of Access Keys