21#include <tqdatastream.h>
25#include "kowmfstruct.h"
26#include "kowmfreadprivate.h"
27#include "kowmfwrite.h"
32class KoWmfWritePrivate
46KoWmfWrite::KoWmfWrite(
const TQString& fileName ) {
47 d =
new KoWmfWritePrivate;
50 d->mMaxRecordSize = 0;
51 d->mFileOut.setName( fileName );
54KoWmfWrite::~KoWmfWrite() {
69 if ( !d->mFileOut.open( IO_WriteOnly ) )
71 kdDebug() <<
"Cannot open file " << TQString(TQFile::encodeName(d->mFileOut.name())) << endl;
74 d->mSt.setDevice( &d->mFileOut );
75 d->mSt.setByteOrder( TQDataStream::LittleEndian );
78 for (
int i=0 ; i < 10 ; i++ ) {
79 d->mSt << (TQ_UINT32)0;
84 d->mSt << (TQ_UINT32)8 << (TQ_UINT16)0x02FA;
85 d->mSt << (TQ_UINT16)5 << (TQ_UINT16)0 << (TQ_UINT16)0 << (TQ_UINT32)0;
87 d->mSt << (TQ_UINT32)7 << (TQ_UINT16)0x02FC;
88 d->mSt << (TQ_UINT16)1 << (TQ_UINT32)0 << (TQ_UINT16)0;
89 for (
int i=0 ; i < 4 ; i++ ) {
90 d->mSt << (TQ_UINT32)8 << (TQ_UINT16)0x02FA << (TQ_UINT16)0 << (TQ_UINT32)0 << (TQ_UINT32)0;
92 d->mMaxRecordSize = 8;
99 WmfPlaceableHeader pheader = { 0x9AC6CDD7, 0, 0, 0, 0, 0, 0, 0, 0 };
103 d->mSt << (TQ_UINT32)3 << (TQ_UINT16)0;
106 pheader.left = d->mBBox.left();
107 pheader.top = d->mBBox.top();
108 pheader.right = d->mBBox.right();
109 pheader.bottom = d->mBBox.bottom();
110 pheader.inch = d->mDpi;
115 d->mSt << (TQ_UINT32)0x9AC6CDD7 << (TQ_UINT16)0;
116 d->mSt << (TQ_INT16)d->mBBox.left() << (TQ_INT16)d->mBBox.top() << (TQ_INT16)d->mBBox.right() << (TQ_INT16)d->mBBox.bottom();
117 d->mSt << (TQ_UINT16)d->mDpi << (TQ_UINT32)0 << checksum;
118 d->mSt << (TQ_UINT16)1 << (TQ_UINT16)9 << (TQ_UINT16)0x300 << (TQ_UINT32)(d->mFileOut.size()/2);
119 d->mSt << (TQ_UINT16)6 << (TQ_UINT32)d->mMaxRecordSize << (TQ_UINT16)0;
127void KoWmfWrite::save() {
128 d->mSt << (TQ_UINT32)3 << (TQ_UINT16)0x001E;
132void KoWmfWrite::restore() {
133 d->mSt << (TQ_UINT32)4 << (TQ_UINT16)0x0127 << (TQ_UINT16)1;
137void KoWmfWrite::setPen(
const TQPen &pen ) {
139 int max =
sizeof(koWmfStylePen) /
sizeof(TQt::SolidLine);
143 d->mSt << (TQ_UINT32)4 << (TQ_UINT16)0x012D << (TQ_UINT16)0;
145 d->mSt << (TQ_UINT32)4 << (TQ_UINT16)0x01f0 << (TQ_UINT16)2;
147 for ( style=0 ; style < max ; style++ ) {
148 if ( koWmfStylePen[ style ] == pen.style() )
break;
150 if ( style == max ) {
154 d->mSt << (TQ_UINT32)8 << (TQ_UINT16)0x02FA;
155 d->mSt << (TQ_UINT16)style << (TQ_UINT16)pen.width() << (TQ_UINT16)0 << (TQ_UINT32)winColor( pen.color() );
158 d->mSt << (TQ_UINT32)4 << (TQ_UINT16)0x012D << (TQ_UINT16)2;
162void KoWmfWrite::setBrush(
const TQBrush &brush ) {
164 int max =
sizeof(koWmfStyleBrush) /
sizeof(TQt::NoBrush);
168 d->mSt << (TQ_UINT32)4 << (TQ_UINT16)0x012D << (TQ_UINT16)1;
170 d->mSt << (TQ_UINT32)4 << (TQ_UINT16)0x01f0 << (TQ_UINT16)3;
172 for ( style=0 ; style < max ; style++ ) {
173 if ( koWmfStyleBrush[ style ] == brush.style() )
break;
175 if ( style == max ) {
179 d->mSt << (TQ_UINT32)7 << (TQ_UINT16)0x02FC;
180 d->mSt << (TQ_UINT16)style << (TQ_UINT32)winColor( brush.color() ) << (TQ_UINT16)0;
183 d->mSt << (TQ_UINT32)4 << (TQ_UINT16)0x012D << (TQ_UINT16)3;
187void KoWmfWrite::setFont(
const TQFont & ) {
191void KoWmfWrite::setBackgroundColor(
const TQColor &c ) {
192 d->mSt << (TQ_UINT32)5 << (TQ_UINT16)0x0201 << (TQ_UINT32)winColor( c );
196void KoWmfWrite::setBackgroundMode( TQt::BGMode mode ) {
197 d->mSt << (TQ_UINT32)4 << (TQ_UINT16)0x0102;
198 if ( mode == TQt::TransparentMode )
199 d->mSt << (TQ_UINT16)1;
201 d->mSt << (TQ_UINT16)0;
205void KoWmfWrite::setRasterOp( TQt::RasterOp op ) {
206 d->mSt << (TQ_UINT32)5 << (TQ_UINT16)0x0104 << (TQ_UINT32)qtRasterToWin32( op );
210void KoWmfWrite::setWindow(
int left,
int top,
int width,
int height ) {
211 d->mBBox.setRect( left, top, width, height );
214 d->mSt << (TQ_UINT32)5 << (TQ_UINT16)0x020B << (TQ_UINT16)top << (TQ_UINT16)left;
217 d->mSt << (TQ_UINT32)5 << (TQ_UINT16)0x020C << (TQ_UINT16)height << (TQ_UINT16)width;
221void KoWmfWrite::setClipRegion(
const TQRegion & ) {
226void KoWmfWrite::clipping(
bool enable ) {
229 setClipRegion( d->mBBox );
234void KoWmfWrite::moveTo(
int left,
int top ) {
235 d->mSt << (TQ_UINT32)5 << (TQ_UINT16)0x0214 << (TQ_UINT16)top << (TQ_UINT16)left;
239void KoWmfWrite::lineTo(
int left,
int top ) {
240 d->mSt << (TQ_UINT32)5 << (TQ_UINT16)0x0213 << (TQ_UINT16)top << (TQ_UINT16)left;
244void KoWmfWrite::drawRect(
int left,
int top,
int width,
int height ) {
245 TQRect rec( left, top, width, height );
247 d->mSt << (TQ_UINT32)7 << (TQ_UINT16)0x041B;
248 d->mSt << (TQ_UINT16)rec.bottom() << (TQ_UINT16)rec.right() << (TQ_UINT16)rec.top() << (TQ_UINT16)rec.left();
252void KoWmfWrite::drawRoundRect(
int left,
int top,
int width,
int height ,
int roudw,
int roudh ) {
253 int widthCorner, heightCorner;
254 TQRect rec( left, top, width, height );
257 widthCorner = ( roudw * width ) / 100;
258 heightCorner = ( roudh * height ) / 100;
260 d->mSt << (TQ_UINT32)9 << (TQ_UINT16)0x061C << (TQ_UINT16)heightCorner << (TQ_UINT16)widthCorner;
261 d->mSt << (TQ_UINT16)rec.bottom() << (TQ_UINT16)rec.right() << (TQ_UINT16)rec.top() << (TQ_UINT16)rec.left();
263 d->mMaxRecordSize = TQMAX( d->mMaxRecordSize, 9 );
267void KoWmfWrite::drawEllipse(
int left,
int top,
int width,
int height ) {
268 TQRect rec( left, top, width, height );
270 d->mSt << (TQ_UINT32)7 << (TQ_UINT16)0x0418;
271 d->mSt << (TQ_UINT16)rec.bottom() << (TQ_UINT16)rec.right() << (TQ_UINT16)rec.top() << (TQ_UINT16)rec.left();
275void KoWmfWrite::drawArc(
int left,
int top,
int width,
int height ,
int a,
int alen ) {
276 int xCenter, yCenter;
277 int offXStart, offYStart, offXEnd, offYEnd;
279 angleToxy( offXStart, offYStart, offXEnd, offYEnd, a, alen );
280 xCenter = left + (width / 2);
281 yCenter = top + (height / 2);
283 d->mSt << (TQ_UINT32)11 << (TQ_UINT16)0x0817;
284 d->mSt << (TQ_UINT16)(yCenter + offYEnd) << (TQ_UINT16)(xCenter + offXEnd);
285 d->mSt << (TQ_UINT16)(yCenter + offYStart) << (TQ_UINT16)(xCenter + offXStart);
286 d->mSt << (TQ_UINT16)(top + height) << (TQ_UINT16)(left + width);
287 d->mSt << (TQ_UINT16)top << (TQ_UINT16)left;
289 d->mMaxRecordSize = TQMAX( d->mMaxRecordSize, 11 );
293void KoWmfWrite::drawPie(
int left,
int top,
int width,
int height ,
int a,
int alen ) {
294 int xCenter, yCenter;
295 int offXStart, offYStart, offXEnd, offYEnd;
297 angleToxy( offXStart, offYStart, offXEnd, offYEnd, a, alen );
298 xCenter = left + (width / 2);
299 yCenter = top + (height / 2);
301 d->mSt << (TQ_UINT32)11 << (TQ_UINT16)0x081A;
302 d->mSt << (TQ_UINT16)(yCenter + offYEnd) << (TQ_UINT16)(xCenter + offXEnd);
303 d->mSt << (TQ_UINT16)(yCenter + offYStart) << (TQ_UINT16)(xCenter + offXStart);
304 d->mSt << (TQ_UINT16)(top + height) << (TQ_UINT16)(left + width);
305 d->mSt << (TQ_UINT16)top << (TQ_UINT16)left;
307 d->mMaxRecordSize = TQMAX( d->mMaxRecordSize, 11 );
311void KoWmfWrite::drawChord(
int left,
int top,
int width,
int height ,
int a,
int alen ) {
312 int xCenter, yCenter;
313 int offXStart, offYStart, offXEnd, offYEnd;
315 angleToxy( offXStart, offYStart, offXEnd, offYEnd, a, alen );
316 xCenter = left + (width / 2);
317 yCenter = top + (height / 2);
319 d->mSt << (TQ_UINT32)11 << (TQ_UINT16)0x0830;
320 d->mSt << (TQ_UINT16)(yCenter + offYEnd) << (TQ_UINT16)(xCenter + offXEnd);
321 d->mSt << (TQ_UINT16)(yCenter + offYStart) << (TQ_UINT16)(xCenter + offXStart);
322 d->mSt << (TQ_UINT16)(top + height) << (TQ_UINT16)(left + width);
323 d->mSt << (TQ_UINT16)top << (TQ_UINT16)left;
325 d->mMaxRecordSize = TQMAX( d->mMaxRecordSize, 11 );
329void KoWmfWrite::drawPolyline(
const TQPointArray &pa ) {
330 int size = 4 + (pa.size() * 2);
332 d->mSt << (TQ_UINT32)size << (TQ_UINT16)0x0325 << (TQ_UINT16)pa.size();
335 d->mMaxRecordSize = TQMAX( d->mMaxRecordSize, size );
339void KoWmfWrite::drawPolygon(
const TQPointArray &pa,
bool ) {
340 int size = 4 + (pa.size() * 2);
342 d->mSt << (TQ_UINT32)size << (TQ_UINT16)0x0324 << (TQ_UINT16)pa.size();
345 d->mMaxRecordSize = TQMAX( d->mMaxRecordSize, size );
349void KoWmfWrite::drawPolyPolygon( TQPtrList<TQPointArray>& listPa,
bool ) {
352 int sizeArrayPoly = 0;
354 for ( pa = listPa.first() ; pa ; pa = listPa.next() ) {
355 sizeArrayPoly += (pa->size() * 2);
357 int size = 4 + listPa.count() + sizeArrayPoly;
358 d->mSt << (TQ_UINT32)size << (TQ_UINT16)0x0538 << (TQ_UINT16)listPa.count();
361 for ( pa = listPa.first() ; pa ; pa = listPa.next() ) {
362 d->mSt << (TQ_UINT16)pa->size();
366 for ( pa = listPa.first() ; pa ; pa = listPa.next() ) {
370 d->mMaxRecordSize = TQMAX( d->mMaxRecordSize, size );
375void KoWmfWrite::drawImage(
int ,
int ,
const TQImage &,
int ,
int ,
int ,
int ) {
389void KoWmfWrite::drawText(
int ,
int ,
int ,
int ,
int ,
const TQString& ,
double ) {
396void KoWmfWrite::pointArray(
const TQPointArray &pa ) {
397 int left, top, i, max;
399 for ( i=0, max=pa.size() ; i < max ; i++ ) {
400 pa.point( i, &left, &top );
401 d->mSt << (TQ_INT16)left << (TQ_INT16)top;
406TQ_UINT32 KoWmfWrite::winColor( TQColor color ) {
409 c = (color.red() & 0xFF);
410 c += ( (color.green() & 0xFF) << 8 );
411 c += ( (color.blue() & 0xFF) << 16 );
417void KoWmfWrite::angleToxy(
int &xStart,
int &yStart,
int &xEnd,
int &yEnd,
int a,
int alen ) {
418 double angleStart, angleLength;
420 angleStart = ((double)a * 3.14166) / 2880;
421 angleLength = ((double)alen * 3.14166) / 2880;
423 xStart = (int)(cos(angleStart) * 50);
424 yStart = -(int)(sin(angleStart) * 50);
425 xEnd = (int)(cos(angleLength) * 50);
426 yEnd = -(int)(sin(angleLength) * 50);
430TQ_UINT16 KoWmfWrite::qtRasterToWin16( TQt::RasterOp op )
const {
433 for ( i=0 ; i < 17 ; i++ ) {
434 if ( koWmfOpTab16[ i ] == op )
break;
444TQ_UINT32 KoWmfWrite::qtRasterToWin32( TQt::RasterOp op )
const {
447 for ( i=0 ; i < 15 ; i++ ) {
448 if ( koWmfOpTab32[ i ].qtRasterOp == op )
break;
452 return koWmfOpTab32[ i ].winRasterOp;
454 return koWmfOpTab32[ 0 ].winRasterOp;
static TQ_UINT16 calcCheckSum(WmfPlaceableHeader *)
Calculate header checksum.
void setDefaultDpi(int dpi)
Placeable WMF's use logical coordinates and have a default DPI.
bool begin()
Open the file.
bool end()
Close the file.