1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dxf2mtf.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
35 #include <vcl/gdimtf.hxx>
36 #include <vcl/virdev.hxx>
37 #include <tools/poly.hxx>
38 #include "dxf2mtf.hxx"
43 ULONG
DXF2GDIMetaFile::CountEntities(const DXFEntities
& rEntities
)
45 const DXFBasicEntity
* pBE
;
49 for (pBE
=rEntities
.pFirst
; pBE
!=NULL
; pBE
=pBE
->pSucc
) nRes
++;
54 void DXF2GDIMetaFile::MayCallback(ULONG
/*nMainEntitiesProcessed*/)
58 if (pCallback!=NULL && nMainEntitiesCount!=0) {
59 nPercent=nMinPercent+(nMaxPercent-nMinPercent)*nMainEntitiesProcessed/nMainEntitiesCount;
60 if (nPercent>=nLastPercent+4) {
61 if (((*pCallback)(pCallerData,(USHORT)nPercent))==TRUE) bStatus=FALSE;
62 nLastPercent=nPercent;
68 Color
DXF2GDIMetaFile::ConvertColor(BYTE nColor
)
71 pDXF
->aPalette
.GetRed( nColor
),
72 pDXF
->aPalette
.GetGreen( nColor
),
73 pDXF
->aPalette
.GetBlue( nColor
) );
76 long DXF2GDIMetaFile::GetEntityColor(const DXFBasicEntity
& rE
)
79 const DXFLayer
* pLayer
;
83 if (rE
.sLayer
[0]=='0' && rE
.sLayer
[1]==0) nColor
=nParentLayerColor
;
85 pLayer
=pDXF
->aTables
.SearchLayer(rE
.sLayer
);
86 if (pLayer
!=NULL
) nColor
=pLayer
->nColor
;
87 else nColor
=nParentLayerColor
;
90 else if (nColor
==0) nColor
=nBlockColor
;
94 DXFLineInfo
DXF2GDIMetaFile::LTypeToDXFLineInfo(const char * sLineType
)
97 DXFLineInfo aDXFLineInfo
;
99 pLT
=pDXF
->aTables
.SearchLType(sLineType
);
100 if (pLT
==NULL
|| pLT
->nDashCount
== 0) {
101 aDXFLineInfo
.eStyle
= LINE_SOLID
;
106 aDXFLineInfo
.eStyle
= LINE_DASH
;
107 for (i
=0; i
< (pLT
->nDashCount
); i
++) {
108 x
= pLT
->fDash
[i
] * pDXF
->getGlobalLineTypeScale();
110 // x = (sal_Int32) rTransform.TransLineWidth( pLT->fDash[i] * pDXF->getGlobalLineTypeScale() );
112 if ( aDXFLineInfo
.nDotCount
== 0 ) {
113 aDXFLineInfo
.nDotCount
++;
114 aDXFLineInfo
.fDotLen
= x
;
116 else if ( aDXFLineInfo
.fDotLen
== x
) {
117 aDXFLineInfo
.nDotCount
++;
119 else if ( aDXFLineInfo
.nDashCount
== 0 ) {
120 aDXFLineInfo
.nDashCount
++;
121 aDXFLineInfo
.fDashLen
= x
;
123 else if ( aDXFLineInfo
.fDashLen
== x
) {
124 aDXFLineInfo
.nDashCount
++;
127 // It is impossible to be converted.
131 if ( aDXFLineInfo
.fDistance
== 0 ) {
132 aDXFLineInfo
.fDistance
= -1 * x
;
135 // It is impossible to be converted.
143 if (aDXFLineInfo
.DashCount
> 0 && aDXFLineInfo
.DashLen
== 0.0)
144 aDXFLineInfo
.DashLen ( 1 );
145 if (aDXFLineInfo
.DotCount
> 0 && aDXFLineInfo
.DotLen() == 0.0)
146 aDXFLineInfo
.SetDotLen( 1 );
147 if (aDXFLineInfo
.GetDashCount
> 0 || aDXFLineInfo
.GetDotCount
> 0)
148 if (aDXFLineInfo
.GetDistance() == 0)
149 aDXFLineInfo
.SetDistance( 1 );
155 DXFLineInfo
DXF2GDIMetaFile::GetEntityDXFLineInfo(const DXFBasicEntity
& rE
)
157 DXFLineInfo aDXFLineInfo
;
158 const DXFLayer
* pLayer
;
160 aDXFLineInfo
.eStyle
= LINE_SOLID
;
161 aDXFLineInfo
.fWidth
= 0;
162 aDXFLineInfo
.nDashCount
= 0;
163 aDXFLineInfo
.fDashLen
= 0;
164 aDXFLineInfo
.nDotCount
= 0;
165 aDXFLineInfo
.fDotLen
= 0;
166 aDXFLineInfo
.fDistance
= 0;
168 if (strcmp(rE
.sLineType
,"BYLAYER")==0) {
169 if (rE
.sLayer
[0]=='0' && rE
.sLayer
[1]==0) aDXFLineInfo
=aParentLayerDXFLineInfo
;
171 pLayer
=pDXF
->aTables
.SearchLayer(rE
.sLayer
);
172 if (pLayer
!=NULL
) aDXFLineInfo
=LTypeToDXFLineInfo(pLayer
->sLineType
);
173 else aDXFLineInfo
=aParentLayerDXFLineInfo
;
176 else if (strcmp(rE
.sLineType
,"BYBLOCK")==0) {
177 aDXFLineInfo
=aBlockDXFLineInfo
;
179 else aDXFLineInfo
=LTypeToDXFLineInfo(rE
.sLineType
);
184 BOOL
DXF2GDIMetaFile::SetLineAttribute(const DXFBasicEntity
& rE
, ULONG
/*nWidth*/)
189 nColor
=GetEntityColor(rE
);
190 if (nColor
<0) return FALSE
;
191 aColor
=ConvertColor((BYTE
)nColor
);
193 if (aActLineColor
!=aColor
) {
194 pVirDev
->SetLineColor( aActLineColor
= aColor
);
197 if (aActFillColor
!=Color( COL_TRANSPARENT
)) {
198 pVirDev
->SetFillColor(aActFillColor
= Color( COL_TRANSPARENT
));
204 BOOL
DXF2GDIMetaFile::SetAreaAttribute(const DXFBasicEntity
& rE
)
209 nColor
=GetEntityColor(rE
);
210 if (nColor
<0) return FALSE
;
211 aColor
=ConvertColor((BYTE
)nColor
);
213 if (aActLineColor
!=aColor
) {
214 pVirDev
->SetLineColor( aActLineColor
= aColor
);
217 if ( aActFillColor
== Color( COL_TRANSPARENT
) || aActFillColor
!= aColor
) {
218 pVirDev
->SetFillColor( aActFillColor
= aColor
);
224 BOOL
DXF2GDIMetaFile::SetFontAttribute(const DXFBasicEntity
& rE
, short nAngle
, USHORT nHeight
, double /*fWidthScale*/)
231 while (nAngle
>3600) nAngle
-=3600;
232 while (nAngle
<0) nAngle
+=3600;
234 nColor
=GetEntityColor(rE
);
235 if (nColor
<0) return FALSE
;
236 aColor
=ConvertColor((BYTE
)nColor
);
238 aFont
.SetColor(aColor
);
239 aFont
.SetTransparent(TRUE
);
240 aFont
.SetFamily(FAMILY_SWISS
);
241 aFont
.SetSize(Size(0,nHeight
));
242 aFont
.SetAlign(ALIGN_BASELINE
);
243 aFont
.SetOrientation(nAngle
);
244 if (aActFont
!=aFont
) {
246 pVirDev
->SetFont(aActFont
);
253 void DXF2GDIMetaFile::DrawLineEntity(const DXFLineEntity
& rE
, const DXFTransform
& rTransform
)
255 if (SetLineAttribute(rE
)) {
257 rTransform
.Transform(rE
.aP0
,aP0
);
258 rTransform
.Transform(rE
.aP1
,aP1
);
260 DXFLineInfo aDXFLineInfo
;
261 aDXFLineInfo
=GetEntityDXFLineInfo(rE
);
263 aLineInfo
= rTransform
.Transform(aDXFLineInfo
);
266 printf("%f\n", rTransform
.TransLineWidth(1000.0));
268 // LINE_NONE = 0, LINE_SOLID = 1, LINE_DASH = 2, LineStyle_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
269 aLineInfo
.SetStyle( LINE_DASH
);
270 aLineInfo
.SetWidth( 300 );
271 aLineInfo
.SetDashCount( 2 );
272 aLineInfo
.SetDashLen( 100 );
273 aLineInfo
.SetDotCount( 1 );
274 aLineInfo
.SetDotLen( 0 );
275 aLineInfo
.SetDistance( 500 );
278 pVirDev
->DrawLine(aP0
,aP1
,aLineInfo
);
279 if (rE
.fThickness
!=0) {
281 rTransform
.Transform(rE
.aP0
+DXFVector(0,0,rE
.fThickness
),aP2
);
282 rTransform
.Transform(rE
.aP1
+DXFVector(0,0,rE
.fThickness
),aP3
);
283 pVirDev
->DrawLine(aP2
,aP3
);
284 pVirDev
->DrawLine(aP0
,aP2
);
285 pVirDev
->DrawLine(aP1
,aP3
);
291 void DXF2GDIMetaFile::DrawPointEntity(const DXFPointEntity
& rE
, const DXFTransform
& rTransform
)
294 if (SetLineAttribute(rE
)) {
296 rTransform
.Transform(rE
.aP0
,aP0
);
297 if (rE
.fThickness
==0) pVirDev
->DrawPixel(aP0
);
300 rTransform
.Transform(rE
.aP0
+DXFVector(0,0,rE
.fThickness
),aP1
);
301 pVirDev
->DrawLine(aP0
,aP1
);
307 void DXF2GDIMetaFile::DrawCircleEntity(const DXFCircleEntity
& rE
, const DXFTransform
& rTransform
)
313 if (SetLineAttribute(rE
)==FALSE
) return;
314 rTransform
.Transform(rE
.aP0
,aC
);
315 if (rE
.fThickness
==0 && rTransform
.TransCircleToEllipse(rE
.fRadius
,frx
,fry
)==TRUE
) {
316 pVirDev
->DrawEllipse(
317 Rectangle((long)(aC
.fx
-frx
+0.5),(long)(aC
.fy
-fry
+0.5),
318 (long)(aC
.fx
+frx
+0.5),(long)(aC
.fy
+fry
+0.5)));
321 nPoints
=OptPointsPerCircle
;
322 Polygon
aPoly(nPoints
);
323 for (i
=0; i
<nPoints
; i
++) {
324 fAng
=2*3.14159265359/(double)(nPoints
-1)*(double)i
;
325 rTransform
.Transform(
326 rE
.aP0
+DXFVector(rE
.fRadius
*cos(fAng
),rE
.fRadius
*sin(fAng
),0),
330 pVirDev
->DrawPolyLine(aPoly
);
331 if (rE
.fThickness
!=0) {
332 Polygon
aPoly2(nPoints
);
333 for (i
=0; i
<nPoints
; i
++) {
334 fAng
=2*3.14159265359/(double)(nPoints
-1)*(double)i
;
335 rTransform
.Transform(
336 rE
.aP0
+DXFVector(rE
.fRadius
*cos(fAng
),rE
.fRadius
*sin(fAng
),rE
.fThickness
),
341 pVirDev
->DrawPolyLine(aPoly2
);
342 for (i
=0; i
<nPoints
-1; i
++) pVirDev
->DrawLine(aPoly
[i
],aPoly2
[i
]);
348 void DXF2GDIMetaFile::DrawArcEntity(const DXFArcEntity
& rE
, const DXFTransform
& rTransform
)
350 double frx
,fry
,fA1
,fdA
,fAng
;
355 if (SetLineAttribute(rE
)==FALSE
) return;
358 while (fdA
>=360.0) fdA
-=360.0;
359 while (fdA
<=0) fdA
+=360.0;
360 rTransform
.Transform(rE
.aP0
,aC
);
361 if (rE
.fThickness
==0 && fdA
>5.0 && rTransform
.TransCircleToEllipse(rE
.fRadius
,frx
,fry
)==TRUE
) {
362 DXFVector
aVS(cos(fA1
/180.0*3.14159265359),sin(fA1
/180.0*3.14159265359),0.0);
365 DXFVector
aVE(cos((fA1
+fdA
)/180.0*3.14159265359),sin((fA1
+fdA
)/180.0*3.14159265359),0.0);
368 if (rTransform
.Mirror()==TRUE
) {
369 rTransform
.Transform(aVS
,aPS
);
370 rTransform
.Transform(aVE
,aPE
);
373 rTransform
.Transform(aVS
,aPE
);
374 rTransform
.Transform(aVE
,aPS
);
377 Rectangle((long)(aC
.fx
-frx
+0.5),(long)(aC
.fy
-fry
+0.5),
378 (long)(aC
.fx
+frx
+0.5),(long)(aC
.fy
+fry
+0.5)),
383 nPoints
=(USHORT
)(fdA
/360.0*(double)OptPointsPerCircle
+0.5);
384 if (nPoints
<2) nPoints
=2;
385 Polygon
aPoly(nPoints
);
386 for (i
=0; i
<nPoints
; i
++) {
387 fAng
=3.14159265359/180.0 * ( fA1
+ fdA
/(double)(nPoints
-1)*(double)i
);
388 rTransform
.Transform(
389 rE
.aP0
+DXFVector(rE
.fRadius
*cos(fAng
),rE
.fRadius
*sin(fAng
),0),
393 pVirDev
->DrawPolyLine(aPoly
);
394 if (rE
.fThickness
!=0) {
395 Polygon
aPoly2(nPoints
);
396 for (i
=0; i
<nPoints
; i
++) {
397 fAng
=3.14159265359/180.0 * ( fA1
+ fdA
/(double)(nPoints
-1)*(double)i
);
398 rTransform
.Transform(
399 rE
.aP0
+DXFVector(rE
.fRadius
*cos(fAng
),rE
.fRadius
*sin(fAng
),rE
.fThickness
),
403 pVirDev
->DrawPolyLine(aPoly2
);
404 for (i
=0; i
<nPoints
; i
++) pVirDev
->DrawLine(aPoly
[i
],aPoly2
[i
]);
410 void DXF2GDIMetaFile::DrawTraceEntity(const DXFTraceEntity
& rE
, const DXFTransform
& rTransform
)
412 if (SetLineAttribute(rE
)) {
414 rTransform
.Transform(rE
.aP0
,aPoly
[0]);
415 rTransform
.Transform(rE
.aP1
,aPoly
[1]);
416 rTransform
.Transform(rE
.aP3
,aPoly
[2]);
417 rTransform
.Transform(rE
.aP2
,aPoly
[3]);
418 pVirDev
->DrawPolygon(aPoly
);
419 if (rE
.fThickness
!=0) {
422 DXFVector
aVAdd(0,0,rE
.fThickness
);
423 rTransform
.Transform(rE
.aP0
+aVAdd
,aPoly2
[0]);
424 rTransform
.Transform(rE
.aP1
+aVAdd
,aPoly2
[1]);
425 rTransform
.Transform(rE
.aP3
+aVAdd
,aPoly2
[2]);
426 rTransform
.Transform(rE
.aP2
+aVAdd
,aPoly2
[3]);
427 pVirDev
->DrawPolygon(aPoly2
);
428 for (i
=0; i
<4; i
++) pVirDev
->DrawLine(aPoly
[i
],aPoly2
[i
]);
434 void DXF2GDIMetaFile::DrawSolidEntity(const DXFSolidEntity
& rE
, const DXFTransform
& rTransform
)
436 if (SetAreaAttribute(rE
)) {
438 if (rE
.aP2
==rE
.aP3
) nN
=3; else nN
=4;
440 rTransform
.Transform(rE
.aP0
,aPoly
[0]);
441 rTransform
.Transform(rE
.aP1
,aPoly
[1]);
442 rTransform
.Transform(rE
.aP3
,aPoly
[2]);
443 if (nN
>3) rTransform
.Transform(rE
.aP2
,aPoly
[3]);
444 pVirDev
->DrawPolygon(aPoly
);
445 if (rE
.fThickness
!=0) {
447 DXFVector
aVAdd(0,0,rE
.fThickness
);
448 rTransform
.Transform(rE
.aP0
+aVAdd
,aPoly2
[0]);
449 rTransform
.Transform(rE
.aP1
+aVAdd
,aPoly2
[1]);
450 rTransform
.Transform(rE
.aP3
+aVAdd
,aPoly2
[2]);
451 if (nN
>3) rTransform
.Transform(rE
.aP2
+aVAdd
,aPoly2
[3]);
452 pVirDev
->DrawPolygon(aPoly2
);
453 if (SetLineAttribute(rE
)) {
455 for (i
=0; i
<nN
; i
++) pVirDev
->DrawLine(aPoly
[i
],aPoly2
[i
]);
462 void DXF2GDIMetaFile::DrawTextEntity(const DXFTextEntity
& rE
, const DXFTransform
& rTransform
)
469 ByteString
aStr( rE
.sText
);
470 DXFTransform
aT( DXFTransform(rE
.fXScale
,rE
.fHeight
,1.0,rE
.fRotAngle
,rE
.aP0
), rTransform
);
471 aT
.TransDir(DXFVector(0,1,0),aV
);
472 nHeight
=(USHORT
)(aV
.Abs()+0.5);
473 fA
=aT
.CalcRotAngle();
474 nAng
=(short)(fA
*10.0+0.5);
475 aT
.TransDir(DXFVector(1,0,0),aV
);
476 if ( SetFontAttribute( rE
,nAng
, nHeight
, aV
. Abs() ) )
478 String
aUString( aStr
, pDXF
->getTextEncoding() );
479 aT
.Transform( DXFVector( 0, 0, 0 ), aPt
);
480 pVirDev
->DrawText( aPt
, aUString
);
485 void DXF2GDIMetaFile::DrawInsertEntity(const DXFInsertEntity
& rE
, const DXFTransform
& rTransform
)
488 pB
=pDXF
->aBlocks
.Search(rE
.sName
);
490 DXFTransform
aDXFTransform1(1.0,1.0,1.0,DXFVector(0.0,0.0,0.0)-pB
->aBasePoint
);
491 DXFTransform
aDXFTransform2(rE
.fXScale
,rE
.fYScale
,rE
.fZScale
,rE
.fRotAngle
,rE
.aP0
);
493 DXFTransform( aDXFTransform1
, aDXFTransform2
),
496 long nSavedBlockColor
, nSavedParentLayerColor
;
497 DXFLineInfo aSavedBlockDXFLineInfo
, aSavedParentLayerDXFLineInfo
;
498 nSavedBlockColor
=nBlockColor
;
499 nSavedParentLayerColor
=nParentLayerColor
;
500 aSavedBlockDXFLineInfo
=aBlockDXFLineInfo
;
501 aSavedParentLayerDXFLineInfo
=aParentLayerDXFLineInfo
;
502 nBlockColor
=GetEntityColor(rE
);
503 aBlockDXFLineInfo
=GetEntityDXFLineInfo(rE
);
504 if (rE
.sLayer
[0]!='0' || rE
.sLayer
[1]!=0) {
505 DXFLayer
* pLayer
=pDXF
->aTables
.SearchLayer(rE
.sLayer
);
507 nParentLayerColor
=pLayer
->nColor
;
508 aParentLayerDXFLineInfo
=LTypeToDXFLineInfo(pLayer
->sLineType
);
511 DrawEntities(*pB
,aT
,FALSE
);
512 aBlockDXFLineInfo
=aSavedBlockDXFLineInfo
;
513 aParentLayerDXFLineInfo
=aSavedParentLayerDXFLineInfo
;
514 nBlockColor
=nSavedBlockColor
;
515 nParentLayerColor
=nSavedParentLayerColor
;
520 void DXF2GDIMetaFile::DrawAttribEntity(const DXFAttribEntity
& rE
, const DXFTransform
& rTransform
)
522 if ((rE
.nAttrFlags
&1)==0) {
528 ByteString
aStr( rE
.sText
);
529 DXFTransform
aT( DXFTransform( rE
.fXScale
, rE
.fHeight
, 1.0, rE
.fRotAngle
, rE
.aP0
), rTransform
);
530 aT
.TransDir(DXFVector(0,1,0),aV
);
531 nHeight
=(USHORT
)(aV
.Abs()+0.5);
532 fA
=aT
.CalcRotAngle();
533 nAng
=(short)(fA
*10.0+0.5);
534 aT
.TransDir(DXFVector(1,0,0),aV
);
535 if (SetFontAttribute(rE
,nAng
,nHeight
,aV
.Abs()))
537 String
aUString( aStr
, pDXF
->getTextEncoding() );
538 aT
.Transform( DXFVector( 0, 0, 0 ), aPt
);
539 pVirDev
->DrawText( aPt
, aUString
);
545 void DXF2GDIMetaFile::DrawPolyLineEntity(const DXFPolyLineEntity
& rE
, const DXFTransform
& rTransform
)
549 const DXFBasicEntity
* pBE
;
553 while (pBE
!=NULL
&& pBE
->eType
==DXF_VERTEX
) {
557 if (nPolySize
<2) return;
558 Polygon
aPoly(nPolySize
);
561 for (i
=0; i
<nPolySize
; i
++) {
562 rTransform
.Transform(((DXFVertexEntity
*)pBE
)->aP0
,aPoly
[i
]);
563 if (i
+1<nPolySize
|| (rE
.nFlags
&1)!=0) {
564 if (((DXFVertexEntity
*)pBE
)->fSWidth
>=0.0) fW
+=((DXFVertexEntity
*)pBE
)->fSWidth
;
566 if (((DXFVertexEntity
*)pBE
)->fEWidth
>=0.0) fW
+=((DXFVertexEntity
*)pBE
)->fEWidth
;
572 if ((rE
.nFlags
&1)!=0) fW
/=(double)nPolySize
;
573 else fW
/=(double)(nPolySize
-1);
574 if (SetLineAttribute(rE
,rTransform
.TransLineWidth(fW
))) {
575 if ((rE
.nFlags
&1)!=0) pVirDev
->DrawPolygon(aPoly
);
576 else pVirDev
->DrawPolyLine(aPoly
);
577 if (rE
.fThickness
!=0) {
578 Polygon
aPoly2(nPolySize
);
580 for (i
=0; i
<nPolySize
; i
++) {
581 rTransform
.Transform(
582 (((DXFVertexEntity
*)pBE
)->aP0
)+DXFVector(0,0,rE
.fThickness
),
587 if ((rE
.nFlags
&1)!=0) pVirDev
->DrawPolygon(aPoly2
);
588 else pVirDev
->DrawPolyLine(aPoly2
);
589 for (i
=0; i
<nPolySize
; i
++) pVirDev
->DrawLine(aPoly
[i
],aPoly2
[i
]);
594 void DXF2GDIMetaFile::DrawLWPolyLineEntity(const DXFLWPolyLineEntity
& rE
, const DXFTransform
& rTransform
)
596 sal_Int32 i
, nPolySize
= rE
.nCount
;
597 if ( nPolySize
&& rE
.pP
)
599 Polygon
aPoly( (sal_uInt16
)nPolySize
);
600 for ( i
= 0; i
< nPolySize
; i
++ )
602 rTransform
.Transform( rE
.pP
[ (sal_uInt16
)i
], aPoly
[ (sal_uInt16
)i
] );
604 double fW
= rE
.fConstantWidth
;
605 if ( SetLineAttribute( rE
, rTransform
.TransLineWidth( fW
) ) )
607 if ( ( rE
.nFlags
& 1 ) != 0 )
608 pVirDev
->DrawPolygon( aPoly
);
610 pVirDev
->DrawPolyLine( aPoly
);
612 //pVirDev->DrawPolyLine( aPoly, aDXFLineInfo );
617 void DXF2GDIMetaFile::DrawHatchEntity(const DXFHatchEntity
& rE
, const DXFTransform
& rTransform
)
619 if ( rE
.nBoundaryPathCount
)
621 SetAreaAttribute( rE
);
623 PolyPolygon aPolyPoly
;
624 for ( j
= 0; j
< rE
.nBoundaryPathCount
; j
++ )
626 DXFPointArray aPtAry
;
627 const DXFBoundaryPathData
& rPathData
= rE
.pBoundaryPathData
[ j
];
628 if ( rPathData
.bIsPolyLine
)
631 for( i
= 0; i
< rPathData
.nPointCount
; i
++ )
634 rTransform
.Transform( rPathData
.pP
[ i
], aPt
);
635 aPtAry
.push_back( aPt
);
641 for ( i
= 0; i
< rPathData
.aEdges
.size(); i
++ )
643 const DXFEdgeType
* pEdge
= rPathData
.aEdges
[ i
];
644 switch( pEdge
->nEdgeType
)
649 rTransform
.Transform( ((DXFEdgeTypeLine
*)pEdge
)->aStartPoint
, aPt
);
650 aPtAry
.push_back( aPt
);
651 rTransform
.Transform( ((DXFEdgeTypeLine
*)pEdge
)->aEndPoint
, aPt
);
652 aPtAry
.push_back( aPt
);
658 double frx,fry,fA1,fdA,fAng;
662 fA1=((DXFEdgeTypeCircularArc*)pEdge)->fStartAngle;
663 fdA=((DXFEdgeTypeCircularArc*)pEdge)->fEndAngle - fA1;
664 while ( fdA >= 360.0 )
668 rTransform.Transform(((DXFEdgeTypeCircularArc*)pEdge)->aCenter, aC);
669 if ( fdA > 5.0 && rTransform.TransCircleToEllipse(((DXFEdgeTypeCircularArc*)pEdge)->fRadius,frx,fry ) == TRUE )
671 DXFVector aVS(cos(fA1/180.0*3.14159265359),sin(fA1/180.0*3.14159265359),0.0);
672 aVS*=((DXFEdgeTypeCircularArc*)pEdge)->fRadius;
673 aVS+=((DXFEdgeTypeCircularArc*)pEdge)->aCenter;
674 DXFVector aVE(cos((fA1+fdA)/180.0*3.14159265359),sin((fA1+fdA)/180.0*3.14159265359),0.0);
675 aVE*=((DXFEdgeTypeCircularArc*)pEdge)->fRadius;
676 aVE+=((DXFEdgeTypeCircularArc*)pEdge)->aCenter;
677 if ( rTransform.Mirror() == TRUE )
679 rTransform.Transform(aVS,aPS);
680 rTransform.Transform(aVE,aPE);
684 rTransform.Transform(aVS,aPE);
685 rTransform.Transform(aVE,aPS);
688 Rectangle((long)(aC.fx-frx+0.5),(long)(aC.fy-fry+0.5),
689 (long)(aC.fx+frx+0.5),(long)(aC.fy+fry+0.5)),
702 sal_uInt16 i
, nSize
= (sal_uInt16
)aPtAry
.size();
705 Polygon
aPoly( nSize
);
706 for ( i
= 0; i
< nSize
; i
++ )
707 aPoly
[ i
] = aPtAry
[ i
];
708 aPolyPoly
.Insert( aPoly
, POLYPOLY_APPEND
);
711 if ( aPolyPoly
.Count() )
712 pVirDev
->DrawPolyPolygon( aPolyPoly
);
716 void DXF2GDIMetaFile::Draw3DFaceEntity(const DXF3DFaceEntity
& rE
, const DXFTransform
& rTransform
)
719 if (SetLineAttribute(rE
)) {
720 if (rE
.aP2
==rE
.aP3
) nN
=3; else nN
=4;
722 rTransform
.Transform(rE
.aP0
,aPoly
[0]);
723 rTransform
.Transform(rE
.aP1
,aPoly
[1]);
724 rTransform
.Transform(rE
.aP2
,aPoly
[2]);
725 if (nN
>3) rTransform
.Transform(rE
.aP3
,aPoly
[3]);
726 if ((rE
.nIEFlags
&0x0f)==0) pVirDev
->DrawPolygon(aPoly
);
728 for (i
=0; i
<nN
; i
++) {
729 if ( (rE
.nIEFlags
& (1<<i
)) == 0 ) {
730 pVirDev
->DrawLine(aPoly
[i
],aPoly
[(i
+1)%nN
]);
738 void DXF2GDIMetaFile::DrawDimensionEntity(const DXFDimensionEntity
& rE
, const DXFTransform
& rTransform
)
741 pB
=pDXF
->aBlocks
.Search(rE
.sPseudoBlock
);
744 DXFTransform(1.0,1.0,1.0,DXFVector(0.0,0.0,0.0)-pB
->aBasePoint
),
747 long nSavedBlockColor
, nSavedParentLayerColor
;
748 DXFLineInfo aSavedBlockDXFLineInfo
, aSavedParentLayerDXFLineInfo
;
749 nSavedBlockColor
=nBlockColor
;
750 nSavedParentLayerColor
=nParentLayerColor
;
751 aSavedBlockDXFLineInfo
=aBlockDXFLineInfo
;
752 aSavedParentLayerDXFLineInfo
=aParentLayerDXFLineInfo
;
753 nBlockColor
=GetEntityColor(rE
);
754 aBlockDXFLineInfo
=GetEntityDXFLineInfo(rE
);
755 if (rE
.sLayer
[0]!='0' || rE
.sLayer
[1]!=0) {
756 DXFLayer
* pLayer
=pDXF
->aTables
.SearchLayer(rE
.sLayer
);
758 nParentLayerColor
=pLayer
->nColor
;
759 aParentLayerDXFLineInfo
=LTypeToDXFLineInfo(pLayer
->sLineType
);
762 DrawEntities(*pB
,aT
,FALSE
);
763 aBlockDXFLineInfo
=aSavedBlockDXFLineInfo
;
764 aParentLayerDXFLineInfo
=aSavedParentLayerDXFLineInfo
;
765 nBlockColor
=nSavedBlockColor
;
766 nParentLayerColor
=nSavedParentLayerColor
;
771 void DXF2GDIMetaFile::DrawEntities(const DXFEntities
& rEntities
,
772 const DXFTransform
& rTransform
,
777 const DXFTransform
* pT
;
779 const DXFBasicEntity
* pE
=rEntities
.pFirst
;
781 while (pE
!=NULL
&& bStatus
==TRUE
) {
783 if (pE
->aExtrusion
.fz
==1.0) {
787 aET
=DXFTransform(DXFTransform(pE
->aExtrusion
),rTransform
);
792 DrawLineEntity((DXFLineEntity
&)*pE
,*pT
);
795 DrawPointEntity((DXFPointEntity
&)*pE
,*pT
);
798 DrawCircleEntity((DXFCircleEntity
&)*pE
,*pT
);
801 DrawArcEntity((DXFArcEntity
&)*pE
,*pT
);
804 DrawTraceEntity((DXFTraceEntity
&)*pE
,*pT
);
807 DrawSolidEntity((DXFSolidEntity
&)*pE
,*pT
);
810 DrawTextEntity((DXFTextEntity
&)*pE
,*pT
);
813 DrawInsertEntity((DXFInsertEntity
&)*pE
,*pT
);
816 DrawAttribEntity((DXFAttribEntity
&)*pE
,*pT
);
819 DrawPolyLineEntity((DXFPolyLineEntity
&)*pE
,*pT
);
821 case DXF_LWPOLYLINE
:
822 DrawLWPolyLineEntity((DXFLWPolyLineEntity
&)*pE
, *pT
);
825 DrawHatchEntity((DXFHatchEntity
&)*pE
, *pT
);
828 Draw3DFaceEntity((DXF3DFaceEntity
&)*pE
,*pT
);
831 DrawDimensionEntity((DXFDimensionEntity
&)*pE
,*pT
);
834 break; // four other values not handled -Wall
839 if (bTopEntities
) MayCallback(nCount
);
844 DXF2GDIMetaFile::DXF2GDIMetaFile()
849 DXF2GDIMetaFile::~DXF2GDIMetaFile()
854 BOOL
DXF2GDIMetaFile::Convert(const DXFRepresentation
& rDXF
, GDIMetaFile
& rMTF
, USHORT nminpercent
, USHORT nmaxpercent
)
856 double fWidth
,fHeight
,fScale
;
857 DXFTransform aTransform
;
859 const DXFLayer
* pLayer
;
860 const DXFVPort
* pVPort
;
862 pVirDev
= new VirtualDevice
;
866 OptPointsPerCircle
=50;
868 nMinPercent
=(ULONG
)nminpercent
;
869 nMaxPercent
=(ULONG
)nmaxpercent
;
870 nLastPercent
=nMinPercent
;
871 nMainEntitiesCount
=CountEntities(pDXF
->aEntities
);
874 aBlockDXFLineInfo
.eStyle
= LINE_SOLID
;
875 aBlockDXFLineInfo
.fWidth
= 0;
876 aBlockDXFLineInfo
.nDashCount
= 0;
877 aBlockDXFLineInfo
.fDashLen
= 0;
878 aBlockDXFLineInfo
.nDotCount
= 0;
879 aBlockDXFLineInfo
.fDotLen
= 0;
880 aBlockDXFLineInfo
.fDistance
= 0;
882 pLayer
=pDXF
->aTables
.SearchLayer("0");
884 nParentLayerColor
=pLayer
->nColor
& 0xff;
885 aParentLayerDXFLineInfo
=LTypeToDXFLineInfo(pLayer
->sLineType
);
889 aParentLayerDXFLineInfo
.eStyle
= LINE_SOLID
;
890 aParentLayerDXFLineInfo
.fWidth
= 0;
891 aParentLayerDXFLineInfo
.nDashCount
= 0;
892 aParentLayerDXFLineInfo
.fDashLen
= 0;
893 aParentLayerDXFLineInfo
.nDotCount
= 0;
894 aParentLayerDXFLineInfo
.fDotLen
= 0;
895 aParentLayerDXFLineInfo
.fDistance
= 0;
898 pVirDev
->EnableOutput(FALSE
);
899 rMTF
.Record(pVirDev
);
901 aActLineColor
= pVirDev
->GetLineColor();
902 aActFillColor
= pVirDev
->GetFillColor();
903 aActFont
= pVirDev
->GetFont();
905 pVPort
=pDXF
->aTables
.SearchVPort("*ACTIVE");
907 if (pVPort
->aDirection
.fx
==0 && pVPort
->aDirection
.fy
==0)
912 if (pDXF
->aBoundingBox
.bEmpty
==TRUE
)
915 fWidth
=pDXF
->aBoundingBox
.fMaxX
-pDXF
->aBoundingBox
.fMinX
;
916 fHeight
=pDXF
->aBoundingBox
.fMaxY
-pDXF
->aBoundingBox
.fMinY
;
917 if (fWidth
<=0 || fHeight
<=0) {
919 fScale
= 0; // -Wall added this...
922 // if (fWidth<500.0 || fHeight<500.0 || fWidth>32767.0 || fHeight>32767.0) {
924 fScale
=10000.0/fWidth
;
926 fScale
=10000.0/fHeight
;
930 aTransform
=DXFTransform(fScale
,-fScale
,fScale
,
931 DXFVector(-pDXF
->aBoundingBox
.fMinX
*fScale
,
932 pDXF
->aBoundingBox
.fMaxY
*fScale
,
933 -pDXF
->aBoundingBox
.fMinZ
*fScale
));
935 aPrefSize
.Width() =(long)(fWidth
*fScale
+1.5);
936 aPrefSize
.Height()=(long)(fHeight
*fScale
+1.5);
940 fHeight
=pVPort
->fHeight
;
941 fWidth
=fHeight
*pVPort
->fAspectRatio
;
942 // if (fWidth<500.0 || fHeight<500.0 || fWidth>32767.0 || fHeight>32767.0) {
944 fScale
=10000.0/fWidth
;
946 fScale
=10000.0/fHeight
;
950 aTransform
=DXFTransform(
951 DXFTransform(pVPort
->aDirection
,pVPort
->aTarget
),
953 DXFTransform(1.0,-1.0,1.0,DXFVector(fWidth
/2-pVPort
->fCenterX
,fHeight
/2+pVPort
->fCenterY
,0)),
954 DXFTransform(fScale
,fScale
,fScale
,DXFVector(0,0,0))
957 aPrefSize
.Width() =(long)(fWidth
*fScale
+1.5);
958 aPrefSize
.Height()=(long)(fHeight
*fScale
+1.5);
962 DrawEntities(pDXF
->aEntities
,aTransform
,TRUE
);
968 rMTF
.SetPrefSize( aPrefSize
);
970 // MapMode einfach, falls Grafik dann nicht zu klein wird (<0,5cm),
971 // auf 1/100-mm (1/10-mm) setzen
972 if( ( aPrefSize
.Width() < 500 ) && ( aPrefSize
.Height() < 500 ) )
973 rMTF
.SetPrefMapMode( MapMode( MAP_10TH_MM
) );
975 rMTF
.SetPrefMapMode( MapMode( MAP_100TH_MM
) );