LibreOffice Module vcl (master) 1
dxf2mtf.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
22#include <vcl/gdimtf.hxx>
23#include <vcl/metaact.hxx>
24#include <vcl/virdev.hxx>
25#include <tools/poly.hxx>
26#include "dxf2mtf.hxx"
27
28#include <math.h>
29
30
31sal_uInt64 DXF2GDIMetaFile::CountEntities(const DXFEntities & rEntities)
32{
33 const DXFBasicEntity * pBE;
34 sal_uInt64 nRes;
35
36 nRes=0;
37 for (pBE=rEntities.pFirst; pBE!=nullptr; pBE=pBE->pSucc) nRes++;
38 return nRes;
39}
40
42{
43 return Color(
44 pDXF->aPalette.GetRed( nColor ),
45 pDXF->aPalette.GetGreen( nColor ),
46 pDXF->aPalette.GetBlue( nColor ) );
47}
48
50{
51 tools::Long nColor;
52
53 nColor=rE.nColor;
54 if (nColor==256) {
55 if (rE.m_sLayer.getLength() < 2) {
56 nColor=nParentLayerColor;
57 } else {
58 const DXFLayer * pLayer=pDXF->aTables.SearchLayer(rE.m_sLayer);
59 if (pLayer!=nullptr) nColor=pLayer->nColor;
60 else nColor=nParentLayerColor;
61 }
62 }
63 else if (nColor==0) nColor=nBlockColor;
64 return nColor;
65}
66
67DXFLineInfo DXF2GDIMetaFile::LTypeToDXFLineInfo(std::string_view rLineType) const
68{
69 const DXFLType * pLT;
70 DXFLineInfo aDXFLineInfo;
71
72 pLT = pDXF->aTables.SearchLType(rLineType);
73 if (pLT==nullptr || pLT->nDashCount == 0) {
74 aDXFLineInfo.eStyle = LineStyle::Solid;
75 }
76 else {
77 aDXFLineInfo.eStyle = LineStyle::Dash;
78 for (tools::Long i=0; i < (pLT->nDashCount); i++) {
79 const double x = pLT->fDash[i] * pDXF->getGlobalLineTypeScale();
80 if ( x >= 0.0 ) {
81 if ( aDXFLineInfo.nDotCount == 0 ) {
82 aDXFLineInfo.nDotCount ++;
83 aDXFLineInfo.fDotLen = x;
84 }
85 else if ( aDXFLineInfo.fDotLen == x ) {
86 aDXFLineInfo.nDotCount ++;
87 }
88 else if ( aDXFLineInfo.nDashCount == 0 ) {
89 aDXFLineInfo.nDashCount ++;
90 aDXFLineInfo.fDashLen = x;
91 }
92 else if ( aDXFLineInfo.fDashLen == x ) {
93 aDXFLineInfo.nDashCount ++;
94 }
95 else {
96 // It is impossible to be converted.
97 }
98 }
99 else {
100 if ( aDXFLineInfo.fDistance == 0 ) {
101 aDXFLineInfo.fDistance = -1 * x;
102 }
103 else {
104 // It is impossible to be converted.
105 }
106 }
107
108 }
109 }
110
111 return aDXFLineInfo;
112}
113
115{
116 DXFLineInfo aDXFLineInfo;
117
118 aDXFLineInfo.eStyle = LineStyle::Solid;
119 aDXFLineInfo.nDashCount = 0;
120 aDXFLineInfo.fDashLen = 0;
121 aDXFLineInfo.nDotCount = 0;
122 aDXFLineInfo.fDotLen = 0;
123 aDXFLineInfo.fDistance = 0;
124
125 if (rE.m_sLineType == "BYLAYER") {
126 if (rE.m_sLayer.getLength() < 2) {
127 aDXFLineInfo=aParentLayerDXFLineInfo;
128 } else {
129 const DXFLayer * pLayer=pDXF->aTables.SearchLayer(rE.m_sLayer);
130 if (pLayer!=nullptr) {
131 aDXFLineInfo = LTypeToDXFLineInfo(pLayer->m_sLineType);
132 }
133 else aDXFLineInfo=aParentLayerDXFLineInfo;
134 }
135 }
136 else if (rE.m_sLineType == "BYBLOCK") {
137 aDXFLineInfo=aBlockDXFLineInfo;
138 }
139 else {
140 aDXFLineInfo = LTypeToDXFLineInfo(rE.m_sLineType);
141 }
142 return aDXFLineInfo;
143}
144
145
147{
148 tools::Long nColor;
149 Color aColor;
150
151 nColor=GetEntityColor(rE);
152 if (nColor<0) return false;
153 aColor=ConvertColor(static_cast<sal_uInt8>(nColor));
154
155 if (aActLineColor!=aColor) {
156 aActLineColor = aColor;
158 }
159
163 }
164 return true;
165}
166
167
169{
170 tools::Long nColor;
171 Color aColor;
172
173 nColor=GetEntityColor(rE);
174 if (nColor<0) return false;
175 aColor=ConvertColor(static_cast<sal_uInt8>(nColor));
176
177 if (aActLineColor!=aColor) {
178 aActLineColor = aColor;
180 }
181
182 if ( aActFillColor == COL_TRANSPARENT || aActFillColor != aColor) {
183 aActFillColor = aColor;
185 }
186 return true;
187}
188
189
190bool DXF2GDIMetaFile::SetFontAttribute(const DXFBasicEntity & rE, short nAngle, sal_uInt16 nHeight)
191{
192 tools::Long nColor;
193 Color aColor;
194 vcl::Font aFont;
195
196 nAngle=-nAngle;
197 while (nAngle>=3600) nAngle-=3600;
198 while (nAngle<0) nAngle+=3600;
199
200 nColor=GetEntityColor(rE);
201 if (nColor<0) return false;
202 aColor=ConvertColor(static_cast<sal_uInt8>(nColor));
203
204 aFont.SetColor(aColor);
205 aFont.SetTransparent(true);
206 aFont.SetFamily(FAMILY_SWISS);
207 aFont.SetFontSize(Size(0,nHeight));
209 aFont.SetOrientation(Degree10(nAngle));
210 if (aActFont!=aFont) {
211 aActFont=aFont;
213 }
214
215 return true;
216}
217
218
220{
221 if (!SetLineAttribute(rE))
222 return;
223
224 Point aP0,aP1;
225 rTransform.Transform(rE.aP0,aP0);
226 rTransform.Transform(rE.aP1,aP1);
227
228 DXFLineInfo aDXFLineInfo=GetEntityDXFLineInfo(rE);
229 LineInfo aLineInfo;
230 aLineInfo = rTransform.Transform(aDXFLineInfo);
231
232 pVirDev->DrawLine(aP0,aP1,aLineInfo);
233 if (rE.fThickness!=0) {
234 Point aP2,aP3;
235 rTransform.Transform(rE.aP0+DXFVector(0,0,rE.fThickness),aP2);
236 rTransform.Transform(rE.aP1+DXFVector(0,0,rE.fThickness),aP3);
237 DrawLine(aP2,aP3);
238 DrawLine(aP0,aP2);
239 DrawLine(aP1,aP3);
240 }
241}
242
243
245{
246
247 if (SetLineAttribute(rE)) {
248 Point aP0;
249 rTransform.Transform(rE.aP0,aP0);
250 if (rE.fThickness==0) pVirDev->DrawPixel(aP0);
251 else {
252 Point aP1;
253 rTransform.Transform(rE.aP0+DXFVector(0,0,rE.fThickness),aP1);
254 DrawLine(aP0,aP1);
255 }
256 }
257}
258
259
261{
262 double frx,fry;
263 sal_uInt16 nPoints,i;
264 DXFVector aC;
265
266 if (!SetLineAttribute(rE)) return;
267 rTransform.Transform(rE.aP0,aC);
268 if (rE.fThickness==0 && rTransform.TransCircleToEllipse(rE.fRadius,frx,fry)) {
270 tools::Rectangle(static_cast<tools::Long>(aC.fx-frx+0.5),static_cast<tools::Long>(aC.fy-fry+0.5),
271 static_cast<tools::Long>(aC.fx+frx+0.5),static_cast<tools::Long>(aC.fy+fry+0.5)));
272 }
273 else {
274 double fAng;
275 nPoints=OptPointsPerCircle;
276 tools::Polygon aPoly(nPoints);
277 for (i=0; i<nPoints; i++) {
278 fAng=2*M_PI/static_cast<double>(nPoints-1)*static_cast<double>(i);
279 rTransform.Transform(
280 rE.aP0+DXFVector(rE.fRadius*cos(fAng),rE.fRadius*sin(fAng),0),
281 aPoly[i]
282 );
283 }
284 pVirDev->DrawPolyLine(aPoly);
285 if (rE.fThickness!=0) {
286 tools::Polygon aPoly2(nPoints);
287 for (i=0; i<nPoints; i++) {
288 fAng=2*M_PI/static_cast<double>(nPoints-1)*static_cast<double>(i);
289 rTransform.Transform(
290 rE.aP0+DXFVector(rE.fRadius*cos(fAng),rE.fRadius*sin(fAng),rE.fThickness),
291 aPoly2[i]
292 );
293
294 }
295 pVirDev->DrawPolyLine(aPoly2);
296 for (i=0; i<nPoints-1; i++) DrawLine(aPoly[i],aPoly2[i]);
297 }
298 }
299}
300
301void DXF2GDIMetaFile::DrawLine(const Point& rA, const Point& rB)
302{
304 return;
305 GDIMetaFile* pMetaFile = pVirDev->GetConnectMetaFile();
306 assert(pMetaFile);
307 //use AddAction instead of OutputDevice::DrawLine so that we can explicitly share
308 //the aDefaultLineInfo between the MetaLineActions to reduce memory use
309 pMetaFile->AddAction(new MetaLineAction(rA, rB, aDefaultLineInfo));
310}
311
312void DXF2GDIMetaFile::DrawArcEntity(const DXFArcEntity & rE, const DXFTransform & rTransform)
313{
314 double frx,fry;
315 sal_uInt16 nPoints,i;
316 DXFVector aC;
317
318 if (!SetLineAttribute(rE)) return;
319 double fA1=rE.fStart;
320 double fdA=rE.fEnd-fA1;
321 fdA = fmod(fdA, 360.0);
322 if (fdA<=0) fdA+=360.0;
323 rTransform.Transform(rE.aP0,aC);
324 if (rE.fThickness==0 && fdA>5.0 && rTransform.TransCircleToEllipse(rE.fRadius,frx,fry)) {
325 DXFVector aVS(cos(basegfx::deg2rad(fA1)),sin(basegfx::deg2rad(fA1)),0.0);
326 aVS*=rE.fRadius;
327 aVS+=rE.aP0;
328 DXFVector aVE(cos(basegfx::deg2rad(fA1+fdA)),sin(basegfx::deg2rad(fA1+fdA)),0.0);
329 aVE*=rE.fRadius;
330 aVE+=rE.aP0;
331 Point aPS,aPE;
332 if (rTransform.Mirror()) {
333 rTransform.Transform(aVS,aPS);
334 rTransform.Transform(aVE,aPE);
335 }
336 else {
337 rTransform.Transform(aVS,aPE);
338 rTransform.Transform(aVE,aPS);
339 }
341 tools::Rectangle(static_cast<tools::Long>(aC.fx-frx+0.5),static_cast<tools::Long>(aC.fy-fry+0.5),
342 static_cast<tools::Long>(aC.fx+frx+0.5),static_cast<tools::Long>(aC.fy+fry+0.5)),
343 aPS,aPE
344 );
345 }
346 else {
347 double fAng;
348 nPoints=static_cast<sal_uInt16>(fdA/360.0*static_cast<double>(OptPointsPerCircle)+0.5);
349 if (nPoints<2) nPoints=2;
350 tools::Polygon aPoly(nPoints);
351 for (i=0; i<nPoints; i++) {
352 fAng=basegfx::deg2rad( fA1 + fdA/static_cast<double>(nPoints-1)*static_cast<double>(i) );
353 rTransform.Transform(
354 rE.aP0+DXFVector(rE.fRadius*cos(fAng),rE.fRadius*sin(fAng),0),
355 aPoly[i]
356 );
357 }
358 pVirDev->DrawPolyLine(aPoly);
359 if (rE.fThickness!=0) {
360 tools::Polygon aPoly2(nPoints);
361 for (i=0; i<nPoints; i++) {
362 fAng=basegfx::deg2rad( fA1 + fdA/static_cast<double>(nPoints-1)*static_cast<double>(i) );
363 rTransform.Transform(
364 rE.aP0+DXFVector(rE.fRadius*cos(fAng),rE.fRadius*sin(fAng),rE.fThickness),
365 aPoly2[i]
366 );
367 }
368 pVirDev->DrawPolyLine(aPoly2);
369 for (i=0; i<nPoints; i++)
370 DrawLine(aPoly[i], aPoly2[i]);
371 }
372 }
373}
374
376{
377 if (!SetLineAttribute(rE))
378 return;
379
380 tools::Polygon aPoly(4);
381 rTransform.Transform(rE.aP0,aPoly[0]);
382 rTransform.Transform(rE.aP1,aPoly[1]);
383 rTransform.Transform(rE.aP3,aPoly[2]);
384 rTransform.Transform(rE.aP2,aPoly[3]);
385 pVirDev->DrawPolygon(aPoly);
386 if (rE.fThickness!=0) {
387 sal_uInt16 i;
388 tools::Polygon aPoly2(4);
389 DXFVector aVAdd(0,0,rE.fThickness);
390 rTransform.Transform(rE.aP0+aVAdd,aPoly2[0]);
391 rTransform.Transform(rE.aP1+aVAdd,aPoly2[1]);
392 rTransform.Transform(rE.aP3+aVAdd,aPoly2[2]);
393 rTransform.Transform(rE.aP2+aVAdd,aPoly2[3]);
394 pVirDev->DrawPolygon(aPoly2);
395 for (i=0; i<4; i++) DrawLine(aPoly[i],aPoly2[i]);
396 }
397}
398
399
401{
402 if (!SetAreaAttribute(rE))
403 return;
404
405 sal_uInt16 nN;
406 if (rE.aP2==rE.aP3) nN=3; else nN=4;
407 tools::Polygon aPoly(nN);
408 rTransform.Transform(rE.aP0,aPoly[0]);
409 rTransform.Transform(rE.aP1,aPoly[1]);
410 rTransform.Transform(rE.aP3,aPoly[2]);
411 if (nN>3) rTransform.Transform(rE.aP2,aPoly[3]);
412 pVirDev->DrawPolygon(aPoly);
413 if (rE.fThickness==0) return;
414
415 tools::Polygon aPoly2(nN);
416 DXFVector aVAdd(0,0,rE.fThickness);
417 rTransform.Transform(rE.aP0+aVAdd,aPoly2[0]);
418 rTransform.Transform(rE.aP1+aVAdd,aPoly2[1]);
419 rTransform.Transform(rE.aP3+aVAdd,aPoly2[2]);
420 if (nN>3) rTransform.Transform(rE.aP2+aVAdd,aPoly2[3]);
421 pVirDev->DrawPolygon(aPoly2);
422 if (SetLineAttribute(rE)) {
423 sal_uInt16 i;
424 for (i=0; i<nN; i++) DrawLine(aPoly[i],aPoly2[i]);
425 }
426}
427
428
430{
431 DXFVector aV;
432 double fA;
433 sal_uInt16 nHeight;
434 short nAng;
435 DXFTransform aT( DXFTransform(rE.fXScale,rE.fHeight,1.0,rE.fRotAngle,rE.aP0), rTransform );
436 aT.TransDir(DXFVector(0,1,0),aV);
437 nHeight=static_cast<sal_uInt16>(aV.Abs()+0.5);
438 fA=aT.CalcRotAngle();
439 nAng=static_cast<short>(fA*10.0+0.5);
440 aT.TransDir(DXFVector(1,0,0),aV);
441 if ( SetFontAttribute( rE,nAng, nHeight ) )
442 {
443 OUString const aUString(pDXF->ToOUString(rE.m_sText));
444 Point aPt;
445 aT.Transform( DXFVector( 0, 0, 0 ), aPt );
446 pVirDev->DrawText( aPt, aUString );
447 }
448}
449
450
452{
453 const DXFBlock * pB;
454 pB=pDXF->aBlocks.Search(rE.m_sName);
455 if (pB==nullptr)
456 return;
457
458 DXFTransform aDXFTransform1(1.0,1.0,1.0,DXFVector(0.0,0.0,0.0)-pB->aBasePoint);
459 DXFTransform aDXFTransform2(rE.fXScale,rE.fYScale,rE.fZScale,rE.fRotAngle,rE.aP0);
460 DXFTransform aT(
461 DXFTransform( aDXFTransform1, aDXFTransform2 ),
462 rTransform
463 );
464 tools::Long nSavedBlockColor, nSavedParentLayerColor;
465 DXFLineInfo aSavedBlockDXFLineInfo, aSavedParentLayerDXFLineInfo;
466 nSavedBlockColor=nBlockColor;
467 nSavedParentLayerColor=nParentLayerColor;
468 aSavedBlockDXFLineInfo=aBlockDXFLineInfo;
469 aSavedParentLayerDXFLineInfo=aParentLayerDXFLineInfo;
472 if (rE.m_sLayer.getLength() > 1) {
474 if (pLayer!=nullptr) {
477 }
478 }
479 DrawEntities(*pB,aT);
480 aBlockDXFLineInfo=aSavedBlockDXFLineInfo;
481 aParentLayerDXFLineInfo=aSavedParentLayerDXFLineInfo;
482 nBlockColor=nSavedBlockColor;
483 nParentLayerColor=nSavedParentLayerColor;
484}
485
486
488{
489 if ((rE.nAttrFlags&1)!=0)
490 return;
491
492 DXFVector aV;
493 double fA;
494 sal_uInt16 nHeight;
495 short nAng;
496 DXFTransform aT( DXFTransform( rE.fXScale, rE.fHeight, 1.0, rE.fRotAngle, rE.aP0 ), rTransform );
497 aT.TransDir(DXFVector(0,1,0),aV);
498 nHeight=static_cast<sal_uInt16>(aV.Abs()+0.5);
499 fA=aT.CalcRotAngle();
500 nAng=static_cast<short>(fA*10.0+0.5);
501 aT.TransDir(DXFVector(1,0,0),aV);
502 if (SetFontAttribute(rE,nAng,nHeight))
503 {
504 OUString const aUString(pDXF->ToOUString(rE.m_sText));
505 Point aPt;
506 aT.Transform( DXFVector( 0, 0, 0 ), aPt );
507 pVirDev->DrawText( aPt, aUString );
508 }
509}
510
511
513{
514 sal_uInt16 i,nPolySize;
515 const DXFBasicEntity * pBE;
516
517 nPolySize=0;
518 pBE=rE.pSucc;
519 while (pBE!=nullptr && pBE->eType==DXF_VERTEX) {
520 nPolySize++;
521 pBE=pBE->pSucc;
522 }
523 if (nPolySize<2)
524 return;
525 tools::Polygon aPoly(nPolySize);
526 pBE=rE.pSucc;
527 for (i=0; i<nPolySize; i++) {
528 rTransform.Transform(static_cast<const DXFVertexEntity*>(pBE)->aP0,aPoly[i]);
529 pBE=pBE->pSucc;
530 }
531
532 if (!SetLineAttribute(rE))
533 return;
534
535 if ((rE.nFlags&1)!=0) pVirDev->DrawPolygon(aPoly);
536 else pVirDev->DrawPolyLine(aPoly);
537 if (rE.fThickness==0)
538 return;
539
540 tools::Polygon aPoly2(nPolySize);
541 pBE=rE.pSucc;
542 for (i=0; i<nPolySize; i++) {
543 rTransform.Transform(
544 (static_cast<const DXFVertexEntity*>(pBE)->aP0)+DXFVector(0,0,rE.fThickness),
545 aPoly2[i]
546 );
547 pBE=pBE->pSucc;
548 }
549 if ((rE.nFlags&1)!=0) pVirDev->DrawPolygon(aPoly2);
550 else pVirDev->DrawPolyLine(aPoly2);
551 for (i=0; i<nPolySize; i++) DrawLine(aPoly[i],aPoly2[i]);
552}
553
555{
556 sal_Int32 nPolySize = rE.aP.size();
557 if (!nPolySize)
558 return;
559
560 tools::Polygon aPoly( static_cast<sal_uInt16>(nPolySize));
561 for (sal_Int32 i = 0; i < nPolySize; ++i)
562 {
563 rTransform.Transform( rE.aP[ static_cast<sal_uInt16>(i) ], aPoly[ static_cast<sal_uInt16>(i) ] );
564 }
565 if ( SetLineAttribute( rE ) )
566 {
567 if ( ( rE.nFlags & 1 ) != 0 )
568 pVirDev->DrawPolygon( aPoly );
569 else
570 pVirDev->DrawPolyLine( aPoly );
571 }
572}
573
575{
576 if (rE.aBoundaryPathData.empty())
577 return;
578
579 SetAreaAttribute( rE );
580 tools::PolyPolygon aPolyPoly;
581 for (const DXFBoundaryPathData& rPathData : rE.aBoundaryPathData)
582 {
583 std::vector< Point > aPtAry;
584 if ( rPathData.bIsPolyLine )
585 {
586 for (const auto& a : rPathData.aP)
587 {
588 Point aPt;
589 rTransform.Transform(a, aPt);
590 aPtAry.push_back( aPt );
591 }
592 }
593 else
594 {
595 for ( auto& rEdge : rPathData.aEdges )
596 {
597 const DXFEdgeType* pEdge = rEdge.get();
598 switch( pEdge->nEdgeType )
599 {
600 case 1 :
601 {
602 Point aPt;
603 rTransform.Transform( static_cast<const DXFEdgeTypeLine*>(pEdge)->aStartPoint, aPt );
604 aPtAry.push_back( aPt );
605 rTransform.Transform( static_cast<const DXFEdgeTypeLine*>(pEdge)->aEndPoint, aPt );
606 aPtAry.push_back( aPt );
607 }
608 break;
609 case 2 :
610 case 3 :
611 case 4 :
612 break;
613 }
614 }
615 }
616 sal_uInt16 i, nSize = static_cast<sal_uInt16>(aPtAry.size());
617 if ( nSize )
618 {
619 tools::Polygon aPoly( nSize );
620 for ( i = 0; i < nSize; i++ )
621 aPoly[ i ] = aPtAry[ i ];
622 aPolyPoly.Insert( aPoly );
623 }
624 }
625 if ( aPolyPoly.Count() )
626 pVirDev->DrawPolyPolygon( aPolyPoly );
627}
628
630{
631 sal_uInt16 nN,i;
632 if (!SetLineAttribute(rE))
633 return;
634
635 if (rE.aP2==rE.aP3) nN=3; else nN=4;
636 tools::Polygon aPoly(nN);
637 rTransform.Transform(rE.aP0,aPoly[0]);
638 rTransform.Transform(rE.aP1,aPoly[1]);
639 rTransform.Transform(rE.aP2,aPoly[2]);
640 if (nN>3) rTransform.Transform(rE.aP3,aPoly[3]);
641 if ((rE.nIEFlags&0x0f)==0) pVirDev->DrawPolygon(aPoly);
642 else {
643 for (i=0; i<nN; i++) {
644 if ( (rE.nIEFlags & (static_cast<tools::Long>(1)<<i)) == 0 ) {
645 DrawLine(aPoly[i],aPoly[(i+1)%nN]);
646 }
647 }
648 }
649}
650
652{
653 const DXFBlock * pB;
655 if (pB==nullptr)
656 return;
657
658 DXFTransform aT(
659 DXFTransform(1.0,1.0,1.0,DXFVector(0.0,0.0,0.0)-pB->aBasePoint),
660 rTransform
661 );
662 tools::Long nSavedBlockColor, nSavedParentLayerColor;
663 DXFLineInfo aSavedBlockDXFLineInfo, aSavedParentLayerDXFLineInfo;
664 nSavedBlockColor=nBlockColor;
665 nSavedParentLayerColor=nParentLayerColor;
666 aSavedBlockDXFLineInfo=aBlockDXFLineInfo;
667 aSavedParentLayerDXFLineInfo=aParentLayerDXFLineInfo;
670 if (rE.m_sLayer.getLength() > 1) {
672 if (pLayer!=nullptr) {
675 }
676 }
677 DrawEntities(*pB,aT);
678 aBlockDXFLineInfo=aSavedBlockDXFLineInfo;
679 aParentLayerDXFLineInfo=aSavedParentLayerDXFLineInfo;
680 nBlockColor=nSavedBlockColor;
681 nParentLayerColor=nSavedParentLayerColor;
682}
683
684
686 const DXFTransform & rTransform)
687{
688 if (rEntities.mbBeingDrawn)
689 return;
690 rEntities.mbBeingDrawn = true;
691
692 DXFTransform aET;
693 const DXFTransform * pT;
694
695 const DXFBasicEntity * pE=rEntities.pFirst;
696
697 while (pE!=nullptr && bStatus) {
698 if (pE->nSpace==0) {
699 if (pE->aExtrusion.fz==1.0) {
700 pT=&rTransform;
701 }
702 else {
703 aET=DXFTransform(DXFTransform(pE->aExtrusion),rTransform);
704 pT=&aET;
705 }
706 switch (pE->eType) {
707 case DXF_LINE:
708 DrawLineEntity(static_cast<const DXFLineEntity&>(*pE),*pT);
709 break;
710 case DXF_POINT:
711 DrawPointEntity(static_cast<const DXFPointEntity&>(*pE),*pT);
712 break;
713 case DXF_CIRCLE:
714 DrawCircleEntity(static_cast<const DXFCircleEntity&>(*pE),*pT);
715 break;
716 case DXF_ARC:
717 DrawArcEntity(static_cast<const DXFArcEntity&>(*pE),*pT);
718 break;
719 case DXF_TRACE:
720 DrawTraceEntity(static_cast<const DXFTraceEntity&>(*pE),*pT);
721 break;
722 case DXF_SOLID:
723 DrawSolidEntity(static_cast<const DXFSolidEntity&>(*pE),*pT);
724 break;
725 case DXF_TEXT:
726 DrawTextEntity(static_cast<const DXFTextEntity&>(*pE),*pT);
727 break;
728 case DXF_INSERT:
729 DrawInsertEntity(static_cast<const DXFInsertEntity&>(*pE),*pT);
730 break;
731 case DXF_ATTRIB:
732 DrawAttribEntity(static_cast<const DXFAttribEntity&>(*pE),*pT);
733 break;
734 case DXF_POLYLINE:
735 DrawPolyLineEntity(static_cast<const DXFPolyLineEntity&>(*pE),*pT);
736 break;
737 case DXF_LWPOLYLINE :
738 DrawLWPolyLineEntity(static_cast<const DXFLWPolyLineEntity&>(*pE), *pT);
739 break;
740 case DXF_HATCH :
741 DrawHatchEntity(static_cast<const DXFHatchEntity&>(*pE), *pT);
742 break;
743 case DXF_3DFACE:
744 Draw3DFaceEntity(static_cast<const DXF3DFaceEntity&>(*pE),*pT);
745 break;
746 case DXF_DIMENSION:
747 DrawDimensionEntity(static_cast<const DXFDimensionEntity&>(*pE),*pT);
748 break;
749 default:
750 break; // four other values not handled -Wall
751 }
752 }
753 pE=pE->pSucc;
754 }
755
756 rEntities.mbBeingDrawn = false;
757}
758
759
761 : pVirDev(nullptr)
762 , pDXF(nullptr)
763 , bStatus(false)
764 , OptPointsPerCircle(0)
765 , nMinPercent(0)
766 , nMaxPercent(0)
767 , nLastPercent(0)
768 , nMainEntitiesCount(0)
769 , nBlockColor(0)
770 , nParentLayerColor(0)
771{
772}
773
774
776{
777}
778
779
780bool DXF2GDIMetaFile::Convert(const DXFRepresentation & rDXF, GDIMetaFile & rMTF, sal_uInt16 nminpercent, sal_uInt16 nmaxpercent)
781{
782 double fWidth,fHeight,fScale(0.0);
783 DXFTransform aTransform;
784 Size aPrefSize;
785 const DXFLayer * pLayer;
786 const DXFVPort * pVPort;
787
789 pDXF = &rDXF;
790 bStatus = true;
791
793
794 nMinPercent=nminpercent;
795 nMaxPercent=nmaxpercent;
798
799 nBlockColor=7;
806
807 pLayer=pDXF->aTables.SearchLayer("0");
808 if (pLayer!=nullptr) {
809 nParentLayerColor=pLayer->nColor & 0xff;
811 }
812 else {
820 }
821
822 pVirDev->EnableOutput(false);
823 if (!utl::ConfigManager::IsFuzzing()) // for fuzzing don't bother recording the drawing
824 rMTF.Record(pVirDev);
825
829
830 pVPort=pDXF->aTables.SearchVPort("*ACTIVE");
831 if (pVPort!=nullptr) {
832 if (pVPort->aDirection.fx==0 && pVPort->aDirection.fy==0)
833 pVPort=nullptr;
834 }
835
836 if (pVPort==nullptr) {
838 bStatus=false;
839 else {
842 if (fWidth<=0 || fHeight<=0) {
843 bStatus=false;
844 }
845 else {
846 if (fWidth>fHeight)
847 fScale=10000.0/fWidth;
848 else
849 fScale=10000.0/fHeight;
850 aTransform=DXFTransform(fScale,-fScale,fScale,
852 pDXF->aBoundingBox.fMaxY*fScale,
853 -pDXF->aBoundingBox.fMinZ*fScale));
854 }
855 aPrefSize.setWidth(static_cast<tools::Long>(fWidth*fScale+1.5) );
856 aPrefSize.setHeight(static_cast<tools::Long>(fHeight*fScale+1.5) );
857 }
858 }
859 else {
860 fHeight=pVPort->fHeight;
861 fWidth=fHeight*pVPort->fAspectRatio;
862 if (fWidth<=0 || fHeight<=0) {
863 bStatus=false;
864 } else {
865 if (fWidth>fHeight)
866 fScale=10000.0/fWidth;
867 else
868 fScale=10000.0/fHeight;
869 aTransform=DXFTransform(
870 DXFTransform(pVPort->aDirection,pVPort->aTarget),
872 DXFTransform(1.0,-1.0,1.0,DXFVector(fWidth/2-pVPort->fCenterX,fHeight/2+pVPort->fCenterY,0)),
873 DXFTransform(fScale,fScale,fScale,DXFVector(0,0,0))
874 )
875 );
876 }
877 aPrefSize.setWidth(static_cast<tools::Long>(fWidth*fScale+1.5) );
878 aPrefSize.setHeight(static_cast<tools::Long>(fHeight*fScale+1.5) );
879 }
880
881 if (bStatus)
882 DrawEntities(pDXF->aEntities,aTransform);
883
884 rMTF.Stop();
885
886 if ( bStatus )
887 {
888 rMTF.SetPrefSize( aPrefSize );
889 // simply set map mode to 1/100-mm (1/10-mm) if the graphic
890 // does not get not too small (<0.5cm)
891 if( ( aPrefSize.Width() < 500 ) && ( aPrefSize.Height() < 500 ) )
892 rMTF.SetPrefMapMode( MapMode( MapUnit::Map10thMM ) );
893 else
894 rMTF.SetPrefMapMode( MapMode( MapUnit::Map100thMM ) );
895 }
896
898 return bStatus;
899}
900
901
902/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long nParentLayerColor
Definition: dxf2mtf.hxx:49
void DrawDimensionEntity(const DXFDimensionEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:651
sal_uInt16 nLastPercent
Definition: dxf2mtf.hxx:44
tools::Long GetEntityColor(const DXFBasicEntity &rE) const
Definition: dxf2mtf.cxx:49
sal_uInt16 nMinPercent
Definition: dxf2mtf.hxx:42
void Draw3DFaceEntity(const DXF3DFaceEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:629
DXFLineInfo GetEntityDXFLineInfo(const DXFBasicEntity &rE)
Definition: dxf2mtf.cxx:114
vcl::Font aActFont
Definition: dxf2mtf.hxx:53
DXFLineInfo aParentLayerDXFLineInfo
Definition: dxf2mtf.hxx:50
static sal_uInt64 CountEntities(const DXFEntities &rEntities)
Definition: dxf2mtf.cxx:31
void DrawLWPolyLineEntity(const DXFLWPolyLineEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:554
bool SetFontAttribute(const DXFBasicEntity &rE, short nAngle, sal_uInt16 nHeight)
Definition: dxf2mtf.cxx:190
void DrawHatchEntity(const DXFHatchEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:574
void DrawEntities(const DXFEntities &rEntities, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:685
void DrawPolyLineEntity(const DXFPolyLineEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:512
void DrawTextEntity(const DXFTextEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:429
void DrawPointEntity(const DXFPointEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:244
sal_uInt16 nMainEntitiesCount
Definition: dxf2mtf.hxx:45
void DrawTraceEntity(const DXFTraceEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:375
sal_uInt16 OptPointsPerCircle
Definition: dxf2mtf.hxx:40
bool SetLineAttribute(const DXFBasicEntity &rE)
Definition: dxf2mtf.cxx:146
void DrawLineEntity(const DXFLineEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:219
bool SetAreaAttribute(const DXFBasicEntity &rE)
Definition: dxf2mtf.cxx:168
void DrawInsertEntity(const DXFInsertEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:451
void DrawArcEntity(const DXFArcEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:312
Color ConvertColor(sal_uInt8 nColor) const
Definition: dxf2mtf.cxx:41
Color aActFillColor
Definition: dxf2mtf.hxx:52
void DrawSolidEntity(const DXFSolidEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:400
DXFLineInfo LTypeToDXFLineInfo(std::string_view rLineType) const
Definition: dxf2mtf.cxx:67
VclPtr< VirtualDevice > pVirDev
Definition: dxf2mtf.hxx:36
DXFLineInfo aBlockDXFLineInfo
Definition: dxf2mtf.hxx:48
tools::Long nBlockColor
Definition: dxf2mtf.hxx:47
Color aActLineColor
Definition: dxf2mtf.hxx:51
void DrawAttribEntity(const DXFAttribEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:487
void DrawLine(const Point &rA, const Point &rB)
Definition: dxf2mtf.cxx:301
bool Convert(const DXFRepresentation &rDXF, GDIMetaFile &rMTF, sal_uInt16 nMinPercent, sal_uInt16 nMaxPercent)
Definition: dxf2mtf.cxx:780
void DrawCircleEntity(const DXFCircleEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:260
sal_uInt16 nMaxPercent
Definition: dxf2mtf.hxx:43
const LineInfo aDefaultLineInfo
Definition: dxf2mtf.hxx:54
const DXFRepresentation * pDXF
Definition: dxf2mtf.hxx:37
tools::Long nIEFlags
Definition: dxfentrd.hxx:484
DXFVector aP3
Definition: dxfentrd.hxx:483
DXFVector aP0
Definition: dxfentrd.hxx:480
DXFVector aP1
Definition: dxfentrd.hxx:481
DXFVector aP2
Definition: dxfentrd.hxx:482
double fStart
Definition: dxfentrd.hxx:143
double fRadius
Definition: dxfentrd.hxx:142
double fEnd
Definition: dxfentrd.hxx:144
DXFVector aP0
Definition: dxfentrd.hxx:141
OString m_sText
Definition: dxfentrd.hxx:282
tools::Long nAttrFlags
Definition: dxfentrd.hxx:284
DXFVector aP0
Definition: dxfentrd.hxx:280
double fRotAngle
Definition: dxfentrd.hxx:286
DXFBasicEntity * pSucc
Definition: dxfentrd.hxx:57
OString m_sLineType
Definition: dxfentrd.hxx:66
OString m_sLayer
Definition: dxfentrd.hxx:65
double fThickness
Definition: dxfentrd.hxx:67
DXFEntityType eType
Definition: dxfentrd.hxx:60
tools::Long nColor
Definition: dxfentrd.hxx:68
DXFVector aBasePoint
Definition: dxfblkrd.hxx:44
DXFBlock * Search(std::string_view rName) const
Definition: dxfblkrd.cxx:103
double fMinY
Definition: dxfreprd.hxx:37
double fMinZ
Definition: dxfreprd.hxx:38
double fMinX
Definition: dxfreprd.hxx:36
double fMaxY
Definition: dxfreprd.hxx:40
double fMaxX
Definition: dxfreprd.hxx:39
DXFVector aP0
Definition: dxfentrd.hxx:127
OString m_sPseudoBlock
Definition: dxfentrd.hxx:497
bool mbBeingDrawn
Definition: dxfentrd.hxx:524
DXFBasicEntity * pFirst
Definition: dxfentrd.hxx:523
std::vector< DXFBoundaryPathData > aBoundaryPathData
Definition: dxfentrd.hxx:442
OString m_sName
Definition: dxfentrd.hxx:231
double fRotAngle
Definition: dxfentrd.hxx:236
DXFVector aP0
Definition: dxfentrd.hxx:232
tools::Long nDashCount
Definition: dxftblrd.hxx:45
double fDash[DXF_MAX_DASH_COUNT]
Definition: dxftblrd.hxx:47
std::vector< DXFVector > aP
Definition: dxfentrd.hxx:334
OString m_sLineType
Definition: dxftblrd.hxx:66
tools::Long nColor
Definition: dxftblrd.hxx:65
DXFVector aP1
Definition: dxfentrd.hxx:101
DXFVector aP0
Definition: dxfentrd.hxx:100
sal_Int32 nDashCount
Definition: dxfvec.hxx:31
double fDashLen
Definition: dxfvec.hxx:32
LineStyle eStyle
Definition: dxfvec.hxx:30
sal_Int32 nDotCount
Definition: dxfvec.hxx:33
double fDistance
Definition: dxfvec.hxx:35
double fDotLen
Definition: dxfvec.hxx:34
sal_uInt8 GetGreen(sal_uInt8 nIndex) const
Definition: dxfreprd.hxx:123
sal_uInt8 GetRed(sal_uInt8 nIndex) const
Definition: dxfreprd.hxx:122
sal_uInt8 GetBlue(sal_uInt8 nIndex) const
Definition: dxfreprd.hxx:124
DXFVector aP0
Definition: dxfentrd.hxx:114
tools::Long nFlags
Definition: dxfentrd.hxx:306
OUString ToOUString(std::string_view s) const
Definition: dxfreprd.cxx:437
double getGlobalLineTypeScale() const
Definition: dxfreprd.hxx:104
DXFTables aTables
Definition: dxfreprd.hxx:82
DXFPalette aPalette
Definition: dxfreprd.hxx:75
DXFBlocks aBlocks
Definition: dxfreprd.hxx:85
DXFBoundingBox aBoundingBox
Definition: dxfreprd.hxx:78
DXFEntities aEntities
Definition: dxfreprd.hxx:88
DXFVector aP3
Definition: dxfentrd.hxx:176
DXFVector aP0
Definition: dxfentrd.hxx:173
DXFVector aP2
Definition: dxfentrd.hxx:175
DXFVector aP1
Definition: dxfentrd.hxx:174
DXFVPort * SearchVPort(std::string_view rName) const
Definition: dxftblrd.cxx:371
DXFLayer * SearchLayer(std::string_view rName) const
Definition: dxftblrd.cxx:361
DXFLType * SearchLType(std::string_view rName) const
Definition: dxftblrd.cxx:351
DXFVector aP0
Definition: dxfentrd.hxx:189
double fXScale
Definition: dxfentrd.hxx:193
double fHeight
Definition: dxfentrd.hxx:190
double fRotAngle
Definition: dxfentrd.hxx:192
OString m_sText
Definition: dxfentrd.hxx:191
DXFVector aP0
Definition: dxfentrd.hxx:157
DXFVector aP1
Definition: dxfentrd.hxx:158
DXFVector aP2
Definition: dxfentrd.hxx:159
DXFVector aP3
Definition: dxfentrd.hxx:160
void TransDir(const DXFVector &rSrc, DXFVector &rTgt) const
Definition: dxfvec.cxx:158
void Transform(const DXFVector &rSrc, DXFVector &rTgt) const
Definition: dxfvec.cxx:143
bool Mirror() const
Definition: dxfvec.cxx:227
double CalcRotAngle() const
Definition: dxfvec.cxx:222
bool TransCircleToEllipse(double fRadius, double &rEx, double &rEy) const
Definition: dxfvec.cxx:166
double fCenterY
Definition: dxftblrd.hxx:113
double fCenterX
Definition: dxftblrd.hxx:112
DXFVector aTarget
Definition: dxftblrd.hxx:121
double fHeight
Definition: dxftblrd.hxx:122
DXFVector aDirection
Definition: dxftblrd.hxx:120
double fAspectRatio
Definition: dxftblrd.hxx:123
double fx
Definition: dxfvec.hxx:55
double Abs() const
Definition: dxfvec.cxx:29
double fy
Definition: dxfvec.hxx:55
void Stop()
Definition: gdimtf.cxx:555
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:581
void SetPrefMapMode(const MapMode &rMapMode)
Definition: gdimtf.hxx:176
void Record(OutputDevice *pOutDev)
Definition: gdimtf.cxx:311
void SetPrefSize(const Size &rSize)
Definition: gdimtf.hxx:173
GDIMetaFile * GetConnectMetaFile() const
Definition: outdev.hxx:286
const vcl::Font & GetFont() const
Definition: outdev.hxx:530
void DrawPolyLine(const tools::Polygon &rPoly)
Render the given polygon as a line stroke.
Definition: polyline.cxx:33
void EnableOutput(bool bEnable=true)
Definition: outdev.cxx:342
void SetFont(const vcl::Font &rNewFont)
Definition: outdev/font.cxx:56
void DrawEllipse(const tools::Rectangle &rRect)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:161
void SetLineColor()
Definition: line.cxx:37
void DrawPolygon(const tools::Polygon &rPoly)
Render the given polygon.
Definition: polygon.cxx:156
void DrawPixel(const Point &rPt)
Definition: pixel.cxx:56
void SetFillColor()
Definition: fill.cxx:29
const Color & GetLineColor() const
Definition: outdev.hxx:511
void DrawArc(const tools::Rectangle &rRect, const Point &rStartPt, const Point &rEndPt)
void DrawPolyPolygon(const tools::PolyPolygon &rPolyPoly)
Render the given poly-polygon.
Definition: polygon.cxx:36
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
Definition: text.cxx:797
const Color & GetFillColor() const
Definition: outdev.hxx:516
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
void disposeAndClear()
Definition: vclptr.hxx:200
static VclPtr< reference_type > Create(Arg &&... arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
sal_uInt16 Count() const
void Insert(const tools::Polygon &rPoly, sal_uInt16 nPos=POLYPOLY_APPEND)
static bool IsFuzzing()
void SetFontSize(const Size &)
Definition: font/font.cxx:149
void SetOrientation(Degree10 nLineOrientation)
Definition: font/font.cxx:227
void SetTransparent(bool bTransparent)
Definition: font/font.cxx:125
void SetColor(const Color &)
Definition: font/font.cxx:107
void SetFamily(FontFamily)
Definition: font/font.cxx:155
void SetAlignment(TextAlign)
Definition: font/font.cxx:131
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
FormulaCommand pE
float x
@ DXF_CIRCLE
Definition: dxfentrd.hxx:33
@ DXF_POINT
Definition: dxfentrd.hxx:32
@ DXF_TEXT
Definition: dxfentrd.hxx:37
@ DXF_SOLID
Definition: dxfentrd.hxx:36
@ DXF_ARC
Definition: dxfentrd.hxx:34
@ DXF_INSERT
Definition: dxfentrd.hxx:39
@ DXF_POLYLINE
Definition: dxfentrd.hxx:42
@ DXF_DIMENSION
Definition: dxfentrd.hxx:46
@ DXF_VERTEX
Definition: dxfentrd.hxx:43
@ DXF_3DFACE
Definition: dxfentrd.hxx:45
@ DXF_ATTRIB
Definition: dxfentrd.hxx:41
@ DXF_TRACE
Definition: dxfentrd.hxx:35
@ DXF_HATCH
Definition: dxfentrd.hxx:48
@ DXF_LWPOLYLINE
Definition: dxfentrd.hxx:47
@ DXF_LINE
Definition: dxfentrd.hxx:31
ALIGN_BASELINE
FAMILY_SWISS
uno_Any a
constexpr double deg2rad(double v)
int i
long Long
std::vector< DXFVector > aP
Definition: dxfentrd.hxx:415
std::vector< std::unique_ptr< DXFEdgeType > > aEdges
Definition: dxfentrd.hxx:416
sal_Int32 nEdgeType
Definition: dxfentrd.hxx:346
unsigned char sal_uInt8