23#include <kgenericfactory.h>
24#include <KoFilterChain.h>
26#include <KoStoreDevice.h>
29#include "vcomposite.h"
30#include "vdashpattern.h"
38#include "vflattencmd.h"
41#include "kowmfwrite.h"
47typedef KGenericFactory<WmfExport, KoFilter> WmfExportFactory;
48K_EXPORT_COMPONENT_FACTORY( libwmfexport, WmfExportFactory(
"kofficefilters" ) )
51WmfExport::WmfExport( KoFilter *, const
char *, const TQStringList&) :
56WmfExport::~WmfExport()
60KoFilter::ConversionStatus WmfExport::convert(
const TQCString& from,
const TQCString& to )
62 if( to !=
"image/x-wmf" || from !=
"application/x-karbon" ) {
63 return KoFilter::NotImplemented;
66 KoStoreDevice* storeIn = m_chain->storageFile(
"root", KoStore::Read );
69 return KoFilter::StupidError;
73 mWmf =
new KoWmfWrite( m_chain->outputFile() );
74 if( !mWmf->begin() ) {
76 return KoFilter::WrongFormat;
80 domIn.setContent( storeIn );
81 TQDomElement docNode = domIn.documentElement();
85 mDoc->load( docNode );
88 mDoc->accept( *
this );
99void WmfExport::visitVDocument( VDocument& document ) {
104 mListPa.setAutoDelete(
true );
108 width = (int)(POINT_TO_INCH( document.width() ) * mDpi);
109 height = (int)(POINT_TO_INCH( document.height() ) * mDpi);
111 mWmf->setDefaultDpi( mDpi );
112 mWmf->setWindow( 0, 0, width, height );
114 if ( (document.width() != 0) && (document.height() != 0) ) {
115 mScaleX = (double)width / document.width();
116 mScaleY = (double)height / document.height();
120 VVisitor::visitVDocument( document );
125void WmfExport::visitVPath( VPath& composite ) {
129 getPen( pen, composite.stroke() );
130 getBrush( brush, composite.fill() );
132 VVisitor::visitVPath( composite );
134 if ( mListPa.count() > 0 ) {
136 if( (brush.style() == TQt::NoBrush)
137 && (mListPa.count() == 1) ) {
138 mWmf->drawPolyline( *mListPa.first() );
141 mWmf->setBrush( brush );
143 if ( mListPa.count() == 1 ) {
144 mWmf->drawPolygon( *mListPa.first() );
148 mWmf->drawPolyPolygon( mListPa );
157void WmfExport::visitVSubpath( VSubpath& path ) {
159 VSubpathIterator itr( path );
160 VFlattenCmd cmd( 0L, INCH_TO_POINT(0.3 / (
double)mDpi) );
161 TQPointArray *pa =
new TQPointArray( path.count() );
164 for( ; itr.current(); ++itr ) {
165 VSegment *segment= itr.current();
166 if (segment->isCurve()) {
167 newPath =
new VSubpath( mDoc );
170 newPath->moveTo( itr.current()->prev()->knot() );
171 newPath->append( itr.current()->clone() );
172 while( itr.current()->next() ) {
173 if ( itr.current()->next()->isCurve() ) {
174 newPath->append( itr.current()->next()->clone() );
183 cmd.visit( *newPath );
186 pa->resize( pa->size() + newPath->count() - 2 );
190 while( newPath->next() ) {
191 pa->setPoint( nbrPoint++, coordX( newPath->current()->knot().x() ),
192 coordY( newPath->current()->knot().y() ) );
195 }
else if (segment->isLine()) {
196 pa->setPoint( nbrPoint++, coordX( itr.current()->knot().x() ),
197 coordY( itr.current()->knot().y() ) );
198 }
else if (segment->isBegin()) {
200 pa->setPoint( nbrPoint++, coordX( itr.current()->knot().x() ),
201 coordY( itr.current()->knot().y() ) );
206 if ( nbrPoint > 1 ) {
207 pa->resize( nbrPoint );
208 mListPa.append( pa );
213 kdDebug() <<
"WmfExport::visitVSubpath : Empty path ?" << endl;
218void WmfExport::visitVText( VText& text ) {
220 visitVSubpath( text.basePath() );
224void WmfExport::getBrush( TQBrush& brush,
const VFill *fill ) {
225 if( (fill->type() == VFill::solid) || (fill->type() == VFill::grad)
226 || (fill->type() == VFill::patt) ) {
227 if ( fill->color().opacity() < 0.1 ) {
228 brush.setStyle( TQt::NoBrush );
231 brush.setStyle( TQt::SolidPattern );
232 brush.setColor( fill->color() );
236 brush.setStyle( TQt::NoBrush );
241void WmfExport::getPen( TQPen& pen,
const VStroke *stroke ) {
242 if( (stroke->type() == VStroke::solid) || (stroke->type() == VStroke::grad)
243 || (stroke->type() == VStroke::patt) ) {
246 if ( stroke->lineCap() == VStroke::capRound ) {
247 pen.setCapStyle( TQt::RoundCap );
250 pen.setCapStyle( TQt::SquareCap );
252 pen.setStyle( TQt::SolidLine );
253 pen.setColor( stroke->color() );
254 pen.setWidth( coordX( stroke->lineWidth() ) );
257 pen.setStyle( TQt::NoPen );
262#include <wmfexport.moc>