filters

pngexport.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, The Karbon Developers
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 <qcstring.h>
00021 #include <qdom.h>
00022 #include <qfile.h>
00023 #include <qstring.h>
00024 #include <qvaluelist.h>
00025 #include <qimage.h>
00026 
00027 #include <kgenericfactory.h>
00028 #include <KoFilter.h>
00029 #include <KoFilterChain.h>
00030 #include <KoStore.h>
00031 
00032 #include "pngexport.h"
00033 #include "vdocument.h"
00034 #include "vselection.h"
00035 #include "vkopainter.h"
00036 #include "vlayer.h"
00037 #include "vcomputeboundingbox.h"
00038 
00039 #include <kdebug.h>
00040 
00041 
00042 typedef KGenericFactory<PngExport, KoFilter> PngExportFactory;
00043 K_EXPORT_COMPONENT_FACTORY( libkarbonpngexport, PngExportFactory( "kofficefilters" ) )
00044 
00045 
00046 PngExport::PngExport( KoFilter*, const char*, const QStringList& )
00047     : KoFilter()
00048 {
00049 }
00050 
00051 KoFilter::ConversionStatus
00052 PngExport::convert( const QCString& from, const QCString& to )
00053 {
00054     if ( to != "image/png" || from != "application/x-karbon" )
00055     {
00056         return KoFilter::NotImplemented;
00057     }
00058 
00059     KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
00060     if( !storeIn )
00061         return KoFilter::StupidError;
00062 
00063     QDomDocument domIn;
00064     domIn.setContent( storeIn );
00065     QDomElement docNode = domIn.documentElement();
00066 
00067     // load the document and export it:
00068     VDocument doc;
00069     doc.load( docNode );
00070 
00071     // calculate the documents bounding box
00072     VComputeBoundingBox bbox( true );
00073     doc.accept( bbox );
00074     const KoRect &rect = bbox.boundingRect();
00075 
00076     // create image with correct width and height
00077     QImage img( int( rect.width() ), int( rect.height() ), 32 );
00078     //img.setAlphaBuffer( true );
00079 
00080     // Create painter and set up objects to draw
00081     VKoPainter p( img.bits(), rect.width(), rect.height() );
00082     p.clear( qRgba( 0xFF, 0xFF, 0xFF, 0xFF ) );
00083     p.setWorldMatrix( QWMatrix().translate( -rect.x(), -rect.y() ) );
00084 
00085     doc.draw( &p, &rect );
00086 
00087     QImage image = img.swapRGB();
00088     QImage mirrored = image.mirror( false, true );
00089     // save png
00090     mirrored.save( m_chain->outputFile(), "PNG" );
00091 
00092     return KoFilter::OK;
00093 }
00094 
00095 #include "pngexport.moc"
00096 
KDE Home | KDE Accessibility Home | Description of Access Keys