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 #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
00068 VDocument doc;
00069 doc.load( docNode );
00070
00071
00072 VComputeBoundingBox bbox( true );
00073 doc.accept( bbox );
00074 const KoRect &rect = bbox.boundingRect();
00075
00076
00077 QImage img( int( rect.width() ), int( rect.height() ), 32 );
00078
00079
00080
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
00090 mirrored.save( m_chain->outputFile(), "PNG" );
00091
00092 return KoFilter::OK;
00093 }
00094
00095 #include "pngexport.moc"
00096
|