20#include <shapes/vellipse.h>
21#include <shapes/vrectangle.h>
22#include <shapes/vpolygon.h>
23#include <core/vstroke.h>
24#include <core/vfill.h>
26#include "wmfimportparser.h"
32WMFImportParser::WMFImportParser() : KoWmfRead() {
39 mScaleX = mScaleY = 1;
42 return KoWmfRead::play( );
49bool WMFImportParser::begin() {
50 TQRect bounding = boundingRect();
52 mBackgroundMode = TQt::TransparentMode;
53 mCurrentOrg.setX( bounding.left() );
54 mCurrentOrg.setY( bounding.top() );
57 mDoc->setUnit( KoUnit::U_PT );
58 mDoc->setWidth( bounding.width() );
59 mDoc->setHeight( bounding.height() );
65 mDoc->setUnit( KoUnit::U_MM );
66 mDoc->setWidth( INCH_TO_POINT( (
double)bounding.width() / defaultDpi() ) );
67 mDoc->setHeight( INCH_TO_POINT( (
double)bounding.height() / defaultDpi() ) );
69 if ( (bounding.width() != 0) && (bounding.height() != 0) ) {
70 mScaleX = mDoc->width() / (double)bounding.width();
71 mScaleY = mDoc->height() / (double)bounding.height();
77bool WMFImportParser::end() {
82void WMFImportParser::save() {
86void WMFImportParser::restore() {
90void WMFImportParser::setFont(
const TQFont & ) {
94void WMFImportParser::setPen(
const TQPen &pen ) {
99const TQPen &WMFImportParser::pen()
const {
104void WMFImportParser::setBrush(
const TQBrush &brush ) {
109void WMFImportParser::setBackgroundColor(
const TQColor &c ) {
110 mBackgroundColor = c;
114void WMFImportParser::setBackgroundMode( TQt::BGMode mode ) {
115 mBackgroundMode = mode;
119void WMFImportParser::setRasterOp( TQt::RasterOp ) {
123void WMFImportParser::setWindowOrg(
int left,
int top ) {
124 mCurrentOrg.setX( left );
125 mCurrentOrg.setY( top );
129void WMFImportParser::setWindowExt(
int width,
int height ) {
131 if ( (width != 0) && (height != 0) ) {
132 mScaleX = mDoc->width() / (double)width;
133 mScaleY = mDoc->height() / (double)height;
138void WMFImportParser::setWorldMatrix(
const TQWMatrix &,
bool ) {
142void WMFImportParser::setClipRegion(
const TQRegion & ) {
146TQRegion WMFImportParser::clipRegion() {
147 return mClippingRegion;
151void WMFImportParser::moveTo(
int left,
int top ) {
152 mCurrentPoint.setX( left );
153 mCurrentPoint.setY( top );
157void WMFImportParser::lineTo(
int left,
int top ) {
158 VPath *line =
new VPath( mDoc );
159 line->moveTo( KoPoint( coordX(mCurrentPoint.x()), coordY(mCurrentPoint.y()) ) );
160 line->lineTo( KoPoint( coordX(left), coordY(top) ) );
163 mDoc->append( line );
164 mCurrentPoint.setX( left );
165 mCurrentPoint.setY( top );
169void WMFImportParser::drawRect(
int left,
int top,
int width,
int height ) {
170 VRectangle *rectangle;
172 rectangle =
new VRectangle( mDoc, KoPoint( coordX(left), coordY(top) ), scaleW(width), scaleH(height), 0 );
173 appendPen( *rectangle );
174 appendBrush( *rectangle );
176 mDoc->append( rectangle );
180void WMFImportParser::drawRoundRect(
int left,
int top,
int width,
int height,
int roudw,
int ) {
181 VRectangle *rectangle;
184 rectangle =
new VRectangle( mDoc, KoPoint( coordX(left), coordY(top) ), scaleW(width), scaleH(height), roudw );
185 appendPen( *rectangle );
186 appendBrush( *rectangle );
188 mDoc->append( rectangle );
192void WMFImportParser::drawEllipse(
int left,
int top,
int width,
int height ) {
195 ellipse =
new VEllipse( mDoc, KoPoint( coordX(left), coordY(top+height) ), scaleW(width), scaleH(height) );
196 appendPen( *ellipse );
197 appendBrush( *ellipse );
199 mDoc->append( ellipse );
203void WMFImportParser::drawArc(
int x,
int y,
int w,
int h,
int aStart,
int aLen ) {
204 double start = (aStart * 180) / 2880.0;
205 double end = (aLen * 180) / 2880.0;
207 VEllipse::VEllipseType type = VEllipse::arc;
209 VEllipse *arc =
new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end );
216void WMFImportParser::drawPie(
int x,
int y,
int w,
int h,
int aStart,
int aLen ) {
217 double start = (aStart * 180) / 2880.0;
218 double end = (aLen * 180) / 2880.0;
220 VEllipse::VEllipseType type = VEllipse::cut;
222 VEllipse *arc =
new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end );
230void WMFImportParser::drawChord(
int x,
int y,
int w,
int h,
int aStart,
int aLen ) {
231 double start = (aStart * 180) / 2880.0;
232 double end = (aLen * 180) / 2880.0;
234 VEllipse::VEllipseType type = VEllipse::section;
236 VEllipse *arc =
new VEllipse( mDoc, KoPoint( coordX(x), coordY(y+h) ), scaleW(w), scaleH(h), type, start, end );
244void WMFImportParser::drawPolyline(
const TQPointArray &pa ) {
245 VPath *polyline =
new VPath( mDoc );
246 appendPen( *polyline );
247 appendPoints( *polyline, pa );
249 mDoc->append( polyline );
253void WMFImportParser::drawPolygon(
const TQPointArray &pa,
bool ) {
254 VPath *polygon =
new VPath( mDoc );
255 appendPen( *polygon );
256 appendBrush( *polygon );
257 appendPoints( *polygon, pa );
260 mDoc->append( polygon );
264void WMFImportParser::drawPolyPolygon( TQPtrList<TQPointArray>& listPa,
bool ) {
265 VPath *path =
new VPath( mDoc );
267 if ( listPa.count() > 0 ) {
269 appendBrush( *path );
270 appendPoints( *path, *listPa.first() );
273 while ( listPa.next() ) {
274 VPath *newPath =
new VPath( mDoc );
275 appendPoints( *newPath, *listPa.current() );
277 path->combine( *newPath );
280 mDoc->append( path );
285void WMFImportParser::drawImage(
int ,
int ,
const TQImage &,
int ,
int ,
int ,
int ) {}
288void WMFImportParser::drawText(
int ,
int ,
int ,
int ,
int ,
const TQString& ,
double ) {}
294void WMFImportParser::appendPen( VObject& obj )
296 VStroke stroke( mDoc );
297 stroke.setLineCap( VStroke::capRound );
299 if ( mPen.style() == TQt::NoPen ) {
300 stroke.setType( VStroke::none );
303 TQValueList<float> dashes;
304 stroke.setType( VStroke::solid );
305 switch ( mPen.style() ) {
307 stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(2) );
310 stroke.dashPattern().setArray( dashes << MM_TO_POINT(1) << MM_TO_POINT(1) );
312 case TQt::DashDotLine :
313 stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) );
315 case TQt::DashDotDotLine :
316 stroke.dashPattern().setArray( dashes << MM_TO_POINT(3) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) << MM_TO_POINT(1) );
322 stroke.setColor( TQColor(mPen.color()) );
323 double width = mPen.width() * mScaleX;
324 stroke.setLineWidth( ((width < 0.99) ? 1 : width) );
325 obj.setStroke( stroke );
329void WMFImportParser::appendBrush( VObject& obj )
331 VFill fill( mBackgroundColor );
332 fill.setColor( TQColor(mBrush.color()) );
334 switch ( mBrush.style() ) {
336 fill.setType( VFill::none );
338 case TQt::SolidPattern :
339 fill.setType( VFill::solid );
341 case TQt::CustomPattern :
343 fill.setType( VFill::solid );
348 if ( mBackgroundMode == TQt::OpaqueMode ) {
349 fill.setColor( mBackgroundColor );
350 fill.setType( VFill::solid );
353 fill.setType( VFill::none );
361void WMFImportParser::appendPoints(VPath &path,
const TQPointArray& pa)
364 if ( pa.size() > 0 ) {
365 path.moveTo( KoPoint( coordX(pa.point(0).x()), coordY(pa.point(0).y()) ) );
367 for ( uint i=1 ; i < pa.size() ; i++ ) {
368 path.lineTo( KoPoint( coordX(pa.point(i).x()), coordY(pa.point(i).y()) ) );
bool play(VDocument &doc)
play WMF file on a VDocument.