filters
pngexport.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00038 #include <kdebug.h>
00039
00040
00041 typedef KGenericFactory<PngExport, KoFilter> PngExportFactory;
00042 K_EXPORT_COMPONENT_FACTORY( libkarbonpngexport, PngExportFactory( "kofficefilters" ) )
00043
00044
00045 PngExport::PngExport( KoFilter*, const char*, const QStringList& )
00046 : KoFilter()
00047 {
00048 }
00049
00050 KoFilter::ConversionStatus
00051 PngExport::convert( const QCString& from, const QCString& to )
00052 {
00053 if ( to != "image/png" || from != "application/x-karbon" )
00054 {
00055 return KoFilter::NotImplemented;
00056 }
00057
00058 KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
00059 if( !storeIn )
00060 return KoFilter::StupidError;
00061
00062 QDomDocument domIn;
00063 domIn.setContent( storeIn );
00064 QDomElement docNode = domIn.documentElement();
00065
00066
00067 VDocument doc;
00068 doc.load( docNode );
00069
00070 VLayerListIterator layerItr( doc.layers() );
00071 VLayer *currentLayer;
00072
00073 for( ; currentLayer = layerItr.current(); ++layerItr )
00074 {
00075 if( currentLayer->state() == VObject::normal || currentLayer->state() == VObject::normal_locked || currentLayer->state() == VObject::selected )
00076 {
00077 doc.selection()->append(currentLayer->objects());
00078 }
00079 }
00080
00081
00082 const KoRect& rect = doc.selection()->boundingBox();
00083
00084
00085 QImage img( int( rect.width() ), int( rect.height() ), 32 );
00086
00087
00088
00089 VKoPainter p( img.bits(), rect.width(), rect.height() );
00090 p.clear( qRgba( 0xFF, 0xFF, 0xFF, 0xFF ) );
00091 p.setWorldMatrix( QWMatrix().translate( -rect.x(), -rect.y() ) );
00092 VObjectList objects = doc.selection()->objects();
00093 VObjectListIterator itr = objects;
00094
00095
00096 doc.selection()->clear();
00097
00098
00099 for ( ; itr.current(); ++itr )
00100 itr.current()->draw( &p, &rect );
00101
00102 QImage image = img.swapRGB();
00103 QImage mirrored = image.mirror( false, true );
00104
00105 mirrored.save( m_chain->outputFile(), "PNG" );
00106
00107 return KoFilter::OK;
00108 }
00109
00110 #include "pngexport.moc"
00111
|