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 
21 #include <unotools/configmgr.hxx>
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 
31 sal_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 
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 
190 bool 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 
219 void DXF2GDIMetaFile::DrawLineEntity(const DXFLineEntity & rE, const DXFTransform & rTransform)
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*3.14159265359/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*3.14159265359/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 
301 void 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 
312 void 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(fA1/180.0*3.14159265359),sin(fA1/180.0*3.14159265359),0.0);
326  aVS*=rE.fRadius;
327  aVS+=rE.aP0;
328  DXFVector aVE(cos((fA1+fdA)/180.0*3.14159265359),sin((fA1+fdA)/180.0*3.14159265359),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  }
340  pVirDev->DrawArc(
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=3.14159265359/180.0 * ( 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=3.14159265359/180.0 * ( 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 
429 void DXF2GDIMetaFile::DrawTextEntity(const DXFTextEntity & rE, const DXFTransform & rTransform)
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) {
473  DXFLayer * pLayer=pDXF->aTables.SearchLayer(rE.m_sLayer);
474  if (pLayer!=nullptr) {
475  nParentLayerColor=pLayer->nColor;
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 
574 void DXF2GDIMetaFile::DrawHatchEntity(const DXFHatchEntity & rE, const DXFTransform & rTransform )
575 {
576  if ( !rE.nBoundaryPathCount )
577  return;
578 
579  SetAreaAttribute( rE );
580  sal_Int32 j = 0;
581  tools::PolyPolygon aPolyPoly;
582  for ( j = 0; j < rE.nBoundaryPathCount; j++ )
583  {
584  std::vector< Point > aPtAry;
585  const DXFBoundaryPathData& rPathData = rE.pBoundaryPathData[ j ];
586  if ( rPathData.bIsPolyLine )
587  {
588  for (const auto& a : rPathData.aP)
589  {
590  Point aPt;
591  rTransform.Transform(a, aPt);
592  aPtAry.push_back( aPt );
593  }
594  }
595  else
596  {
597  for ( auto& rEdge : rPathData.aEdges )
598  {
599  const DXFEdgeType* pEdge = rEdge.get();
600  switch( pEdge->nEdgeType )
601  {
602  case 1 :
603  {
604  Point aPt;
605  rTransform.Transform( static_cast<const DXFEdgeTypeLine*>(pEdge)->aStartPoint, aPt );
606  aPtAry.push_back( aPt );
607  rTransform.Transform( static_cast<const DXFEdgeTypeLine*>(pEdge)->aEndPoint, aPt );
608  aPtAry.push_back( aPt );
609  }
610  break;
611  case 2 :
612  case 3 :
613  case 4 :
614  break;
615  }
616  }
617  }
618  sal_uInt16 i, nSize = static_cast<sal_uInt16>(aPtAry.size());
619  if ( nSize )
620  {
621  tools::Polygon aPoly( nSize );
622  for ( i = 0; i < nSize; i++ )
623  aPoly[ i ] = aPtAry[ i ];
624  aPolyPoly.Insert( aPoly );
625  }
626  }
627  if ( aPolyPoly.Count() )
628  pVirDev->DrawPolyPolygon( aPolyPoly );
629 }
630 
632 {
633  sal_uInt16 nN,i;
634  if (!SetLineAttribute(rE))
635  return;
636 
637  if (rE.aP2==rE.aP3) nN=3; else nN=4;
638  tools::Polygon aPoly(nN);
639  rTransform.Transform(rE.aP0,aPoly[0]);
640  rTransform.Transform(rE.aP1,aPoly[1]);
641  rTransform.Transform(rE.aP2,aPoly[2]);
642  if (nN>3) rTransform.Transform(rE.aP3,aPoly[3]);
643  if ((rE.nIEFlags&0x0f)==0) pVirDev->DrawPolygon(aPoly);
644  else {
645  for (i=0; i<nN; i++) {
646  if ( (rE.nIEFlags & (static_cast<tools::Long>(1)<<i)) == 0 ) {
647  DrawLine(aPoly[i],aPoly[(i+1)%nN]);
648  }
649  }
650  }
651 }
652 
654 {
655  const DXFBlock * pB;
657  if (pB==nullptr)
658  return;
659 
660  DXFTransform aT(
661  DXFTransform(1.0,1.0,1.0,DXFVector(0.0,0.0,0.0)-pB->aBasePoint),
662  rTransform
663  );
664  tools::Long nSavedBlockColor, nSavedParentLayerColor;
665  DXFLineInfo aSavedBlockDXFLineInfo, aSavedParentLayerDXFLineInfo;
666  nSavedBlockColor=nBlockColor;
667  nSavedParentLayerColor=nParentLayerColor;
668  aSavedBlockDXFLineInfo=aBlockDXFLineInfo;
669  aSavedParentLayerDXFLineInfo=aParentLayerDXFLineInfo;
672  if (rE.m_sLayer.getLength() > 1) {
673  DXFLayer * pLayer=pDXF->aTables.SearchLayer(rE.m_sLayer);
674  if (pLayer!=nullptr) {
675  nParentLayerColor=pLayer->nColor;
677  }
678  }
679  DrawEntities(*pB,aT);
680  aBlockDXFLineInfo=aSavedBlockDXFLineInfo;
681  aParentLayerDXFLineInfo=aSavedParentLayerDXFLineInfo;
682  nBlockColor=nSavedBlockColor;
683  nParentLayerColor=nSavedParentLayerColor;
684 }
685 
686 
688  const DXFTransform & rTransform)
689 {
690  if (rEntities.mbBeingDrawn)
691  return;
692  rEntities.mbBeingDrawn = true;
693 
694  DXFTransform aET;
695  const DXFTransform * pT;
696 
697  const DXFBasicEntity * pE=rEntities.pFirst;
698 
699  while (pE!=nullptr && bStatus) {
700  if (pE->nSpace==0) {
701  if (pE->aExtrusion.fz==1.0) {
702  pT=&rTransform;
703  }
704  else {
705  aET=DXFTransform(DXFTransform(pE->aExtrusion),rTransform);
706  pT=&aET;
707  }
708  switch (pE->eType) {
709  case DXF_LINE:
710  DrawLineEntity(static_cast<const DXFLineEntity&>(*pE),*pT);
711  break;
712  case DXF_POINT:
713  DrawPointEntity(static_cast<const DXFPointEntity&>(*pE),*pT);
714  break;
715  case DXF_CIRCLE:
716  DrawCircleEntity(static_cast<const DXFCircleEntity&>(*pE),*pT);
717  break;
718  case DXF_ARC:
719  DrawArcEntity(static_cast<const DXFArcEntity&>(*pE),*pT);
720  break;
721  case DXF_TRACE:
722  DrawTraceEntity(static_cast<const DXFTraceEntity&>(*pE),*pT);
723  break;
724  case DXF_SOLID:
725  DrawSolidEntity(static_cast<const DXFSolidEntity&>(*pE),*pT);
726  break;
727  case DXF_TEXT:
728  DrawTextEntity(static_cast<const DXFTextEntity&>(*pE),*pT);
729  break;
730  case DXF_INSERT:
731  DrawInsertEntity(static_cast<const DXFInsertEntity&>(*pE),*pT);
732  break;
733  case DXF_ATTRIB:
734  DrawAttribEntity(static_cast<const DXFAttribEntity&>(*pE),*pT);
735  break;
736  case DXF_POLYLINE:
737  DrawPolyLineEntity(static_cast<const DXFPolyLineEntity&>(*pE),*pT);
738  break;
739  case DXF_LWPOLYLINE :
740  DrawLWPolyLineEntity(static_cast<const DXFLWPolyLineEntity&>(*pE), *pT);
741  break;
742  case DXF_HATCH :
743  DrawHatchEntity(static_cast<const DXFHatchEntity&>(*pE), *pT);
744  break;
745  case DXF_3DFACE:
746  Draw3DFaceEntity(static_cast<const DXF3DFaceEntity&>(*pE),*pT);
747  break;
748  case DXF_DIMENSION:
749  DrawDimensionEntity(static_cast<const DXFDimensionEntity&>(*pE),*pT);
750  break;
751  default:
752  break; // four other values not handled -Wall
753  }
754  }
755  pE=pE->pSucc;
756  }
757 
758  rEntities.mbBeingDrawn = false;
759 }
760 
761 
763  : pVirDev(nullptr)
764  , pDXF(nullptr)
765  , bStatus(false)
766  , OptPointsPerCircle(0)
767  , nMinPercent(0)
768  , nMaxPercent(0)
769  , nLastPercent(0)
770  , nMainEntitiesCount(0)
771  , nBlockColor(0)
772  , nParentLayerColor(0)
773 {
774 }
775 
776 
778 {
779 }
780 
781 
782 bool DXF2GDIMetaFile::Convert(const DXFRepresentation & rDXF, GDIMetaFile & rMTF, sal_uInt16 nminpercent, sal_uInt16 nmaxpercent)
783 {
784  double fWidth,fHeight,fScale(0.0);
785  DXFTransform aTransform;
786  Size aPrefSize;
787  const DXFLayer * pLayer;
788  const DXFVPort * pVPort;
789 
791  pDXF = &rDXF;
792  bStatus = true;
793 
795 
796  nMinPercent=nminpercent;
797  nMaxPercent=nmaxpercent;
800 
801  nBlockColor=7;
808 
809  pLayer=pDXF->aTables.SearchLayer("0");
810  if (pLayer!=nullptr) {
811  nParentLayerColor=pLayer->nColor & 0xff;
813  }
814  else {
822  }
823 
824  pVirDev->EnableOutput(false);
825  if (!utl::ConfigManager::IsFuzzing()) // for fuzzing don't bother recording the drawing
826  rMTF.Record(pVirDev);
827 
830  aActFont = pVirDev->GetFont();
831 
832  pVPort=pDXF->aTables.SearchVPort("*ACTIVE");
833  if (pVPort!=nullptr) {
834  if (pVPort->aDirection.fx==0 && pVPort->aDirection.fy==0)
835  pVPort=nullptr;
836  }
837 
838  if (pVPort==nullptr) {
839  if (pDXF->aBoundingBox.bEmpty)
840  bStatus=false;
841  else {
844  if (fWidth<=0 || fHeight<=0) {
845  bStatus=false;
846  }
847  else {
848  if (fWidth>fHeight)
849  fScale=10000.0/fWidth;
850  else
851  fScale=10000.0/fHeight;
852  aTransform=DXFTransform(fScale,-fScale,fScale,
853  DXFVector(-pDXF->aBoundingBox.fMinX*fScale,
854  pDXF->aBoundingBox.fMaxY*fScale,
855  -pDXF->aBoundingBox.fMinZ*fScale));
856  }
857  aPrefSize.setWidth(static_cast<tools::Long>(fWidth*fScale+1.5) );
858  aPrefSize.setHeight(static_cast<tools::Long>(fHeight*fScale+1.5) );
859  }
860  }
861  else {
862  fHeight=pVPort->fHeight;
863  fWidth=fHeight*pVPort->fAspectRatio;
864  if (fWidth<=0 || fHeight<=0) {
865  bStatus=false;
866  } else {
867  if (fWidth>fHeight)
868  fScale=10000.0/fWidth;
869  else
870  fScale=10000.0/fHeight;
871  aTransform=DXFTransform(
872  DXFTransform(pVPort->aDirection,pVPort->aTarget),
873  DXFTransform(
874  DXFTransform(1.0,-1.0,1.0,DXFVector(fWidth/2-pVPort->fCenterX,fHeight/2+pVPort->fCenterY,0)),
875  DXFTransform(fScale,fScale,fScale,DXFVector(0,0,0))
876  )
877  );
878  }
879  aPrefSize.setWidth(static_cast<tools::Long>(fWidth*fScale+1.5) );
880  aPrefSize.setHeight(static_cast<tools::Long>(fHeight*fScale+1.5) );
881  }
882 
883  if (bStatus)
884  DrawEntities(pDXF->aEntities,aTransform);
885 
886  rMTF.Stop();
887 
888  if ( bStatus )
889  {
890  rMTF.SetPrefSize( aPrefSize );
891  // simply set map mode to 1/100-mm (1/10-mm) if the graphic
892  // does not get not too small (<0.5cm)
893  if( ( aPrefSize.Width() < 500 ) && ( aPrefSize.Height() < 500 ) )
894  rMTF.SetPrefMapMode( MapMode( MapUnit::Map10thMM ) );
895  else
896  rMTF.SetPrefMapMode( MapMode( MapUnit::Map100thMM ) );
897  }
898 
900  return bStatus;
901 }
902 
903 
904 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetFamily(FontFamily)
Definition: font/font.cxx:133
sal_uInt16 Count() const
void EnableOutput(bool bEnable=true)
Definition: outdev.cxx:335
DXFEntityType eType
Definition: dxfentrd.hxx:60
DXFLineInfo LTypeToDXFLineInfo(std::string_view rLineType)
Definition: dxf2mtf.cxx:67
DXFVector aP0
Definition: dxfentrd.hxx:114
double fx
Definition: dxfvec.hxx:55
double fAspectRatio
Definition: dxftblrd.hxx:123
double fCenterY
Definition: dxftblrd.hxx:113
double fCenterX
Definition: dxftblrd.hxx:112
DXFVector aP3
Definition: dxfentrd.hxx:176
DXFBlocks aBlocks
Definition: dxfreprd.hxx:86
void SetFontSize(const Size &)
Definition: font/font.cxx:127
DXFVector aP0
Definition: dxfentrd.hxx:481
double fMinZ
Definition: dxfreprd.hxx:38
DXFVector aExtrusion
Definition: dxfentrd.hxx:70
sal_uInt8 GetGreen(sal_uInt8 nIndex) const
Definition: dxfreprd.hxx:124
FormulaCommand pE
tools::Long nDashCount
Definition: dxftblrd.hxx:45
OUString ToOUString(std::string_view s) const
Definition: dxfreprd.cxx:442
void setWidth(tools::Long nWidth)
sal_uInt8 GetBlue(sal_uInt8 nIndex) const
Definition: dxfreprd.hxx:125
DXFVector aDirection
Definition: dxftblrd.hxx:120
void DrawCircleEntity(const DXFCircleEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:260
double fThickness
Definition: dxfentrd.hxx:67
bool SetAreaAttribute(const DXFBasicEntity &rE)
Definition: dxf2mtf.cxx:168
void DrawEntities(const DXFEntities &rEntities, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:687
double fEnd
Definition: dxfentrd.hxx:144
void DrawInsertEntity(const DXFInsertEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:451
DXFVector aP0
Definition: dxfentrd.hxx:141
sal_uInt8 GetRed(sal_uInt8 nIndex) const
Definition: dxfreprd.hxx:123
Color ConvertColor(sal_uInt8 nColor)
Definition: dxf2mtf.cxx:41
long Long
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
void disposeAndClear()
Definition: vclptr.hxx:200
double fHeight
Definition: dxfentrd.hxx:190
void DrawPolygon(const tools::Polygon &rPoly)
Render the given polygon.
Definition: polygon.cxx:156
VclPtr< VirtualDevice > pVirDev
Definition: dxf2mtf.hxx:36
void SetPrefSize(const Size &rSize)
Definition: gdimtf.hxx:173
tools::Long nIEFlags
Definition: dxfentrd.hxx:485
DXFVector aP1
Definition: dxfentrd.hxx:101
void DrawPolyLine(const tools::Polygon &rPoly)
Render the given polygon as a line stroke.
Definition: polyline.cxx:33
bool Convert(const DXFRepresentation &rDXF, GDIMetaFile &rMTF, sal_uInt16 nMinPercent, sal_uInt16 nMaxPercent)
Definition: dxf2mtf.cxx:782
std::vector< DXFVector > aP
Definition: dxfentrd.hxx:415
double fHeight
Definition: dxftblrd.hxx:122
GDIMetaFile * GetConnectMetaFile() const
Definition: outdev.hxx:285
DXFLineInfo aParentLayerDXFLineInfo
Definition: dxf2mtf.hxx:50
void DrawLWPolyLineEntity(const DXFLWPolyLineEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:554
OString m_sText
Definition: dxfentrd.hxx:282
tools::Long nBlockColor
Definition: dxf2mtf.hxx:47
double fStart
Definition: dxfentrd.hxx:143
tools::Long GetEntityColor(const DXFBasicEntity &rE)
Definition: dxf2mtf.cxx:49
float x
DXFVector aP0
Definition: dxfentrd.hxx:157
void Transform(const DXFVector &rSrc, DXFVector &rTgt) const
Definition: dxfvec.cxx:143
double fMinX
Definition: dxfreprd.hxx:36
double fMaxY
Definition: dxfreprd.hxx:40
double fMaxX
Definition: dxfreprd.hxx:39
DXFVector aP1
Definition: dxfentrd.hxx:482
double fRotAngle
Definition: dxfentrd.hxx:192
DXFVector aP0
Definition: dxfentrd.hxx:100
constexpr tools::Long Width() const
void Record(OutputDevice *pOutDev)
Definition: gdimtf.cxx:311
sal_Int32 nEdgeType
Definition: dxfentrd.hxx:346
double fDashLen
Definition: dxfvec.hxx:32
DXFBlock * Search(std::string_view rName) const
Definition: dxfblkrd.cxx:103
double fz
Definition: dxfvec.hxx:55
const vcl::Font & GetFont() const
Definition: outdev.hxx:526
std::vector< DXFVector > aP
Definition: dxfentrd.hxx:334
tools::Long nFlags
Definition: dxfentrd.hxx:306
Color aActLineColor
Definition: dxf2mtf.hxx:51
static bool IsFuzzing()
sal_Int32 nDashCount
Definition: dxfvec.hxx:31
OString m_sName
Definition: dxfentrd.hxx:231
sal_Int32 nDotCount
Definition: dxfvec.hxx:33
DXFVector aP3
Definition: dxfentrd.hxx:484
void Insert(const tools::Polygon &rPoly, sal_uInt16 nPos=POLYPOLY_APPEND)
OString m_sLayer
Definition: dxfentrd.hxx:65
DXFPalette aPalette
Definition: dxfreprd.hxx:76
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:160
bool SetLineAttribute(const DXFBasicEntity &rE)
Definition: dxf2mtf.cxx:146
double fDotLen
Definition: dxfvec.hxx:34
bool mbBeingDrawn
Definition: dxfentrd.hxx:525
OString m_sText
Definition: dxfentrd.hxx:191
static sal_uInt64 CountEntities(const DXFEntities &rEntities)
Definition: dxf2mtf.cxx:31
double fDistance
Definition: dxfvec.hxx:35
void DrawTextEntity(const DXFTextEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:429
void SetLineColor()
Definition: line.cxx:36
double CalcRotAngle() const
Definition: dxfvec.cxx:222
ALIGN_BASELINE
std::vector< std::unique_ptr< DXFEdgeType > > aEdges
Definition: dxfentrd.hxx:416
DXFVector aP0
Definition: dxfentrd.hxx:189
tools::Long nColor
Definition: dxftblrd.hxx:65
int i
uno_Any a
void DrawTraceEntity(const DXFTraceEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:375
void TransDir(const DXFVector &rSrc, DXFVector &rTgt) const
Definition: dxfvec.cxx:158
OString m_sLineType
Definition: dxfentrd.hxx:66
void SetOrientation(Degree10 nLineOrientation)
Definition: font/font.cxx:202
sal_uInt16 OptPointsPerCircle
Definition: dxf2mtf.hxx:40
DXFVector aP0
Definition: dxfentrd.hxx:232
double fDash[DXF_MAX_DASH_COUNT]
Definition: dxftblrd.hxx:47
DXFVector aP2
Definition: dxfentrd.hxx:175
void DrawArc(const tools::Rectangle &rRect, const Point &rStartPt, const Point &rEndPt)
DXFVector aP2
Definition: dxfentrd.hxx:159
DXFVector aBasePoint
Definition: dxfblkrd.hxx:44
sal_uInt16 nMinPercent
Definition: dxf2mtf.hxx:42
double fRotAngle
Definition: dxfentrd.hxx:286
double fy
Definition: dxfvec.hxx:55
DXFVector aP2
Definition: dxfentrd.hxx:483
void SetFillColor()
Definition: fill.cxx:29
sal_uInt16 nMaxPercent
Definition: dxf2mtf.hxx:43
const Color & GetLineColor() const
Definition: outdev.hxx:507
std::unique_ptr< DXFBoundaryPathData[]> pBoundaryPathData
Definition: dxfentrd.hxx:443
void DrawLineEntity(const DXFLineEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:219
tools::Long nParentLayerColor
Definition: dxf2mtf.hxx:49
void DrawSolidEntity(const DXFSolidEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:400
DXFTables aTables
Definition: dxfreprd.hxx:83
double fXScale
Definition: dxfentrd.hxx:193
void DrawPointEntity(const DXFPointEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:244
void DrawHatchEntity(const DXFHatchEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:574
void DrawPixel(const Point &rPt)
Definition: pixel.cxx:56
DXFLineInfo GetEntityDXFLineInfo(const DXFBasicEntity &rE)
Definition: dxf2mtf.cxx:114
double fMinY
Definition: dxfreprd.hxx:37
double fRotAngle
Definition: dxfentrd.hxx:236
void SetColor(const Color &)
Definition: font/font.cxx:90
double getGlobalLineTypeScale() const
Definition: dxfreprd.hxx:105
double Abs() const
Definition: dxfvec.cxx:29
void SetAlignment(TextAlign)
Definition: font/font.cxx:111
DXFVector aTarget
Definition: dxftblrd.hxx:121
sal_uInt16 nLastPercent
Definition: dxf2mtf.hxx:44
void Stop()
Definition: gdimtf.cxx:536
DXFBoundingBox aBoundingBox
Definition: dxfreprd.hxx:79
Color aActFillColor
Definition: dxf2mtf.hxx:52
const LineInfo aDefaultLineInfo
Definition: dxf2mtf.hxx:54
sal_Int32 nBoundaryPathCount
Definition: dxfentrd.hxx:433
DXFBasicEntity * pSucc
Definition: dxfentrd.hxx:57
DXFVPort * SearchVPort(std::string_view rName) const
Definition: dxftblrd.cxx:371
tools::Long nSpace
Definition: dxfentrd.hxx:69
DXFLayer * SearchLayer(std::string_view rName) const
Definition: dxftblrd.cxx:361
OString m_sLineType
Definition: dxftblrd.hxx:66
DXFVector aP0
Definition: dxfentrd.hxx:173
constexpr tools::Long Height() const
unsigned char sal_uInt8
void SetFont(const vcl::Font &rNewFont)
Definition: outdev/font.cxx:52
DXFVector aP3
Definition: dxfentrd.hxx:160
void Draw3DFaceEntity(const DXF3DFaceEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:631
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:562
void SetTransparent(bool bTransparent)
Definition: font/font.cxx:105
LineStyle eStyle
Definition: dxfvec.hxx:30
FAMILY_SWISS
DXFEntities aEntities
Definition: dxfreprd.hxx:89
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
DXFLType * SearchLType(std::string_view rName) const
Definition: dxftblrd.cxx:351
const DXFRepresentation * pDXF
Definition: dxf2mtf.hxx:37
void DrawPolyPolygon(const tools::PolyPolygon &rPolyPoly)
Render the given poly-polygon.
Definition: polygon.cxx:36
bool TransCircleToEllipse(double fRadius, double &rEx, double &rEy) const
Definition: dxfvec.cxx:166
sal_uInt16 nMainEntitiesCount
Definition: dxf2mtf.hxx:45
void DrawEllipse(const tools::Rectangle &rRect)
void setHeight(tools::Long nHeight)
bool Mirror() const
Definition: dxfvec.cxx:227
void DrawAttribEntity(const DXFAttribEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:487
DXFVector aP0
Definition: dxfentrd.hxx:127
DXFVector aP1
Definition: dxfentrd.hxx:174
void DrawArcEntity(const DXFArcEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:312
bool SetFontAttribute(const DXFBasicEntity &rE, short nAngle, sal_uInt16 nHeight)
Definition: dxf2mtf.cxx:190
DXFLineInfo aBlockDXFLineInfo
Definition: dxf2mtf.hxx:48
DXFBasicEntity * pFirst
Definition: dxfentrd.hxx:524
double fRadius
Definition: dxfentrd.hxx:142
DXFVector aP0
Definition: dxfentrd.hxx:280
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:772
OString m_sPseudoBlock
Definition: dxfentrd.hxx:498
tools::Long nAttrFlags
Definition: dxfentrd.hxx:284
void DrawLine(const Point &rA, const Point &rB)
Definition: dxf2mtf.cxx:301
tools::Long nColor
Definition: dxfentrd.hxx:68
void DrawDimensionEntity(const DXFDimensionEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:653
DXFVector aP1
Definition: dxfentrd.hxx:158
vcl::Font aActFont
Definition: dxf2mtf.hxx:53
const Color & GetFillColor() const
Definition: outdev.hxx:512
void DrawPolyLineEntity(const DXFPolyLineEntity &rE, const DXFTransform &rTransform)
Definition: dxf2mtf.cxx:512
void SetPrefMapMode(const MapMode &rMapMode)
Definition: gdimtf.hxx:176