LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/idxf - dxf2mtf.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 5 531 0.9 %
Date: 2015-06-13 12:38:46 Functions: 2 26 7.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <string.h>
      22             : #include <vcl/gdimtf.hxx>
      23             : #include <vcl/virdev.hxx>
      24             : #include <tools/poly.hxx>
      25             : #include "dxf2mtf.hxx"
      26             : 
      27             : #include <math.h>
      28             : 
      29             : 
      30           0 : sal_uLong DXF2GDIMetaFile::CountEntities(const DXFEntities & rEntities)
      31             : {
      32             :     const DXFBasicEntity * pBE;
      33             :     sal_uLong nRes;
      34             : 
      35           0 :     nRes=0;
      36           0 :     for (pBE=rEntities.pFirst; pBE!=NULL; pBE=pBE->pSucc) nRes++;
      37           0 :     return nRes;
      38             : }
      39             : 
      40           0 : Color DXF2GDIMetaFile::ConvertColor(sal_uInt8 nColor)
      41             : {
      42             :     return Color(
      43           0 :         pDXF->aPalette.GetRed( nColor ),
      44           0 :         pDXF->aPalette.GetGreen( nColor ),
      45           0 :         pDXF->aPalette.GetBlue( nColor ) );
      46             : }
      47             : 
      48           0 : long DXF2GDIMetaFile::GetEntityColor(const DXFBasicEntity & rE)
      49             : {
      50             :     long nColor;
      51             :     const DXFLayer * pLayer;
      52             : 
      53           0 :     nColor=rE.nColor;
      54           0 :     if (nColor==256) {
      55           0 :         if (rE.m_sLayer.getLength() < 2) {
      56           0 :             nColor=nParentLayerColor;
      57             :         } else {
      58           0 :             pLayer=pDXF->aTables.SearchLayer(rE.m_sLayer);
      59           0 :             if (pLayer!=NULL) nColor=pLayer->nColor;
      60           0 :             else nColor=nParentLayerColor;
      61             :         }
      62             :     }
      63           0 :     else if (nColor==0) nColor=nBlockColor;
      64           0 :     return nColor;
      65             : }
      66             : 
      67           0 : DXFLineInfo DXF2GDIMetaFile::LTypeToDXFLineInfo(OString const& rLineType)
      68             : {
      69             :     const DXFLType * pLT;
      70           0 :     DXFLineInfo aDXFLineInfo;
      71             : 
      72           0 :     pLT = pDXF->aTables.SearchLType(rLineType);
      73           0 :     if (pLT==NULL || pLT->nDashCount == 0) {
      74           0 :         aDXFLineInfo.eStyle = LINE_SOLID;
      75             :     }
      76             :     else {
      77             :         sal_Int32 i;
      78           0 :         aDXFLineInfo.eStyle = LINE_DASH;
      79           0 :         for (i=0; i < (pLT->nDashCount); i++) {
      80           0 :             const double x = pLT->fDash[i] * pDXF->getGlobalLineTypeScale();
      81           0 :             if ( x >= 0.0 ) {
      82           0 :                 if ( aDXFLineInfo.nDotCount == 0 ) {
      83           0 :                     aDXFLineInfo.nDotCount ++;
      84           0 :                     aDXFLineInfo.fDotLen = x;
      85             :                 }
      86           0 :                 else if ( aDXFLineInfo.fDotLen == x ) {
      87           0 :                     aDXFLineInfo.nDotCount ++;
      88             :                 }
      89           0 :                 else if ( aDXFLineInfo.nDashCount == 0 ) {
      90           0 :                     aDXFLineInfo.nDashCount ++;
      91           0 :                     aDXFLineInfo.fDashLen = x;
      92             :                 }
      93           0 :                 else if ( aDXFLineInfo.fDashLen == x ) {
      94           0 :                     aDXFLineInfo.nDashCount ++;
      95             :                 }
      96             :                 else {
      97             :                     // It is impossible to be converted.
      98             :                 }
      99             :             }
     100             :             else {
     101           0 :                 if ( aDXFLineInfo.fDistance == 0 ) {
     102           0 :                     aDXFLineInfo.fDistance = -1 * x;
     103             :                 }
     104             :                 else {
     105             :                     // It is impossible to be converted.
     106             :                 }
     107             :             }
     108             : 
     109             :         }
     110             :     }
     111             : 
     112           0 :     return aDXFLineInfo;
     113             : }
     114             : 
     115           0 : DXFLineInfo DXF2GDIMetaFile::GetEntityDXFLineInfo(const DXFBasicEntity & rE)
     116             : {
     117           0 :     DXFLineInfo aDXFLineInfo;
     118             : 
     119           0 :     aDXFLineInfo.eStyle = LINE_SOLID;
     120           0 :     aDXFLineInfo.fWidth = 0;
     121           0 :     aDXFLineInfo.nDashCount = 0;
     122           0 :     aDXFLineInfo.fDashLen = 0;
     123           0 :     aDXFLineInfo.nDotCount = 0;
     124           0 :     aDXFLineInfo.fDotLen = 0;
     125           0 :     aDXFLineInfo.fDistance = 0;
     126             : 
     127           0 :     if (rE.m_sLineType == "BYLAYER") {
     128           0 :         if (rE.m_sLayer.getLength() < 2) {
     129           0 :             aDXFLineInfo=aParentLayerDXFLineInfo;
     130             :         } else {
     131           0 :             const DXFLayer * pLayer=pDXF->aTables.SearchLayer(rE.m_sLayer);
     132           0 :             if (pLayer!=NULL) {
     133           0 :                 aDXFLineInfo = LTypeToDXFLineInfo(pLayer->m_sLineType);
     134             :             }
     135           0 :             else aDXFLineInfo=aParentLayerDXFLineInfo;
     136             :         }
     137             :     }
     138           0 :     else if (rE.m_sLineType == "BYBLOCK") {
     139           0 :         aDXFLineInfo=aBlockDXFLineInfo;
     140             :     }
     141             :     else {
     142           0 :         aDXFLineInfo = LTypeToDXFLineInfo(rE.m_sLineType);
     143             :     }
     144           0 :     return aDXFLineInfo;
     145             : }
     146             : 
     147             : 
     148           0 : bool DXF2GDIMetaFile::SetLineAttribute(const DXFBasicEntity & rE, sal_uLong /*nWidth*/)
     149             : {
     150             :     long nColor;
     151           0 :     Color aColor;
     152             : 
     153           0 :     nColor=GetEntityColor(rE);
     154           0 :     if (nColor<0) return false;
     155           0 :     aColor=ConvertColor((sal_uInt8)nColor);
     156             : 
     157           0 :     if (aActLineColor!=aColor) {
     158           0 :         pVirDev->SetLineColor( aActLineColor = aColor );
     159             :     }
     160             : 
     161           0 :     if (aActFillColor!=Color( COL_TRANSPARENT )) {
     162           0 :         pVirDev->SetFillColor(aActFillColor = Color( COL_TRANSPARENT ));
     163             :     }
     164           0 :     return true;
     165             : }
     166             : 
     167             : 
     168           0 : bool DXF2GDIMetaFile::SetAreaAttribute(const DXFBasicEntity & rE)
     169             : {
     170             :     long nColor;
     171           0 :     Color aColor;
     172             : 
     173           0 :     nColor=GetEntityColor(rE);
     174           0 :     if (nColor<0) return false;
     175           0 :     aColor=ConvertColor((sal_uInt8)nColor);
     176             : 
     177           0 :     if (aActLineColor!=aColor) {
     178           0 :         pVirDev->SetLineColor( aActLineColor = aColor );
     179             :     }
     180             : 
     181           0 :     if ( aActFillColor == Color( COL_TRANSPARENT ) || aActFillColor != aColor) {
     182           0 :         pVirDev->SetFillColor( aActFillColor = aColor );
     183             :     }
     184           0 :     return true;
     185             : }
     186             : 
     187             : 
     188           0 : bool DXF2GDIMetaFile::SetFontAttribute(const DXFBasicEntity & rE, short nAngle, sal_uInt16 nHeight, double /*fWidthScale*/)
     189             : {
     190             :     long nColor;
     191           0 :     Color aColor;
     192           0 :     vcl::Font aFont;
     193             : 
     194           0 :     nAngle=-nAngle;
     195           0 :     while (nAngle>3600) nAngle-=3600;
     196           0 :     while (nAngle<0) nAngle+=3600;
     197             : 
     198           0 :     nColor=GetEntityColor(rE);
     199           0 :     if (nColor<0) return false;
     200           0 :     aColor=ConvertColor((sal_uInt8)nColor);
     201             : 
     202           0 :     aFont.SetColor(aColor);
     203           0 :     aFont.SetTransparent(true);
     204           0 :     aFont.SetFamily(FAMILY_SWISS);
     205           0 :     aFont.SetSize(Size(0,nHeight));
     206           0 :     aFont.SetAlign(ALIGN_BASELINE);
     207           0 :     aFont.SetOrientation(nAngle);
     208           0 :     if (aActFont!=aFont) {
     209           0 :         aActFont=aFont;
     210           0 :         pVirDev->SetFont(aActFont);
     211             :     }
     212             : 
     213           0 :     return true;
     214             : }
     215             : 
     216             : 
     217           0 : void DXF2GDIMetaFile::DrawLineEntity(const DXFLineEntity & rE, const DXFTransform & rTransform)
     218             : {
     219           0 :     if (SetLineAttribute(rE)) {
     220           0 :         Point aP0,aP1;
     221           0 :         rTransform.Transform(rE.aP0,aP0);
     222           0 :         rTransform.Transform(rE.aP1,aP1);
     223             : 
     224           0 :         DXFLineInfo aDXFLineInfo;
     225           0 :         aDXFLineInfo=GetEntityDXFLineInfo(rE);
     226           0 :         LineInfo aLineInfo;
     227           0 :         aLineInfo = rTransform.Transform(aDXFLineInfo);
     228             : 
     229           0 :         pVirDev->DrawLine(aP0,aP1,aLineInfo);
     230           0 :         if (rE.fThickness!=0) {
     231           0 :             Point aP2,aP3;
     232           0 :             rTransform.Transform(rE.aP0+DXFVector(0,0,rE.fThickness),aP2);
     233           0 :             rTransform.Transform(rE.aP1+DXFVector(0,0,rE.fThickness),aP3);
     234           0 :             pVirDev->DrawLine(aP2,aP3);
     235           0 :             pVirDev->DrawLine(aP0,aP2);
     236           0 :             pVirDev->DrawLine(aP1,aP3);
     237           0 :         }
     238             :     }
     239           0 : }
     240             : 
     241             : 
     242           0 : void DXF2GDIMetaFile::DrawPointEntity(const DXFPointEntity & rE, const DXFTransform & rTransform)
     243             : {
     244             : 
     245           0 :     if (SetLineAttribute(rE)) {
     246           0 :         Point aP0;
     247           0 :         rTransform.Transform(rE.aP0,aP0);
     248           0 :         if (rE.fThickness==0) pVirDev->DrawPixel(aP0);
     249             :         else {
     250           0 :             Point aP1;
     251           0 :             rTransform.Transform(rE.aP0+DXFVector(0,0,rE.fThickness),aP1);
     252           0 :             pVirDev->DrawLine(aP0,aP1);
     253             :         }
     254             :     }
     255           0 : }
     256             : 
     257             : 
     258           0 : void DXF2GDIMetaFile::DrawCircleEntity(const DXFCircleEntity & rE, const DXFTransform & rTransform)
     259             : {
     260             :     double frx,fry;
     261             :     sal_uInt16 nPoints,i;
     262           0 :     DXFVector aC;
     263             : 
     264           0 :     if (!SetLineAttribute(rE)) return;
     265           0 :     rTransform.Transform(rE.aP0,aC);
     266           0 :     if (rE.fThickness==0 && rTransform.TransCircleToEllipse(rE.fRadius,frx,fry)) {
     267           0 :         pVirDev->DrawEllipse(
     268           0 :             Rectangle((long)(aC.fx-frx+0.5),(long)(aC.fy-fry+0.5),
     269           0 :                       (long)(aC.fx+frx+0.5),(long)(aC.fy+fry+0.5)));
     270             :     }
     271             :     else {
     272             :         double fAng;
     273           0 :         nPoints=OptPointsPerCircle;
     274           0 :         Polygon aPoly(nPoints);
     275           0 :         for (i=0; i<nPoints; i++) {
     276           0 :             fAng=2*3.14159265359/(double)(nPoints-1)*(double)i;
     277             :             rTransform.Transform(
     278           0 :                 rE.aP0+DXFVector(rE.fRadius*cos(fAng),rE.fRadius*sin(fAng),0),
     279           0 :                 aPoly[i]
     280           0 :             );
     281             :         }
     282           0 :         pVirDev->DrawPolyLine(aPoly);
     283           0 :         if (rE.fThickness!=0) {
     284           0 :             Polygon aPoly2(nPoints);
     285           0 :             for (i=0; i<nPoints; i++) {
     286           0 :                 fAng=2*3.14159265359/(double)(nPoints-1)*(double)i;
     287             :                 rTransform.Transform(
     288           0 :                     rE.aP0+DXFVector(rE.fRadius*cos(fAng),rE.fRadius*sin(fAng),rE.fThickness),
     289           0 :                     aPoly2[i]
     290           0 :                 );
     291             : 
     292             :             }
     293           0 :             pVirDev->DrawPolyLine(aPoly2);
     294           0 :             for (i=0; i<nPoints-1; i++) pVirDev->DrawLine(aPoly[i],aPoly2[i]);
     295           0 :         }
     296             :     }
     297             : }
     298             : 
     299             : 
     300           0 : void DXF2GDIMetaFile::DrawArcEntity(const DXFArcEntity & rE, const DXFTransform & rTransform)
     301             : {
     302             :     double frx,fry,fA1,fdA;
     303             :     sal_uInt16 nPoints,i;
     304           0 :     DXFVector aC;
     305           0 :     Point aPS,aPE;
     306             : 
     307           0 :     if (!SetLineAttribute(rE)) return;
     308           0 :     fA1=rE.fStart;
     309           0 :     fdA=rE.fEnd-fA1;
     310           0 :     while (fdA>=360.0) fdA-=360.0;
     311           0 :     while (fdA<=0) fdA+=360.0;
     312           0 :     rTransform.Transform(rE.aP0,aC);
     313           0 :     if (rE.fThickness==0 && fdA>5.0 && rTransform.TransCircleToEllipse(rE.fRadius,frx,fry)) {
     314           0 :         DXFVector aVS(cos(fA1/180.0*3.14159265359),sin(fA1/180.0*3.14159265359),0.0);
     315           0 :         aVS*=rE.fRadius;
     316           0 :         aVS+=rE.aP0;
     317           0 :         DXFVector aVE(cos((fA1+fdA)/180.0*3.14159265359),sin((fA1+fdA)/180.0*3.14159265359),0.0);
     318           0 :         aVE*=rE.fRadius;
     319           0 :         aVE+=rE.aP0;
     320           0 :         if (rTransform.Mirror()) {
     321           0 :             rTransform.Transform(aVS,aPS);
     322           0 :             rTransform.Transform(aVE,aPE);
     323             :         }
     324             :         else {
     325           0 :             rTransform.Transform(aVS,aPE);
     326           0 :             rTransform.Transform(aVE,aPS);
     327             :         }
     328           0 :         pVirDev->DrawArc(
     329           0 :             Rectangle((long)(aC.fx-frx+0.5),(long)(aC.fy-fry+0.5),
     330           0 :                       (long)(aC.fx+frx+0.5),(long)(aC.fy+fry+0.5)),
     331             :             aPS,aPE
     332           0 :         );
     333             :     }
     334             :     else {
     335             :         double fAng;
     336           0 :         nPoints=(sal_uInt16)(fdA/360.0*(double)OptPointsPerCircle+0.5);
     337           0 :         if (nPoints<2) nPoints=2;
     338           0 :         Polygon aPoly(nPoints);
     339           0 :         for (i=0; i<nPoints; i++) {
     340           0 :             fAng=3.14159265359/180.0 * ( fA1 + fdA/(double)(nPoints-1)*(double)i );
     341             :             rTransform.Transform(
     342           0 :                 rE.aP0+DXFVector(rE.fRadius*cos(fAng),rE.fRadius*sin(fAng),0),
     343           0 :                 aPoly[i]
     344           0 :             );
     345             :         }
     346           0 :         pVirDev->DrawPolyLine(aPoly);
     347           0 :         if (rE.fThickness!=0) {
     348           0 :             Polygon aPoly2(nPoints);
     349           0 :             for (i=0; i<nPoints; i++) {
     350           0 :                 fAng=3.14159265359/180.0 * ( fA1 + fdA/(double)(nPoints-1)*(double)i );
     351             :                 rTransform.Transform(
     352           0 :                     rE.aP0+DXFVector(rE.fRadius*cos(fAng),rE.fRadius*sin(fAng),rE.fThickness),
     353           0 :                     aPoly2[i]
     354           0 :                 );
     355             :             }
     356           0 :             pVirDev->DrawPolyLine(aPoly2);
     357           0 :             for (i=0; i<nPoints; i++) pVirDev->DrawLine(aPoly[i],aPoly2[i]);
     358           0 :         }
     359             :     }
     360             : }
     361             : 
     362             : 
     363           0 : void DXF2GDIMetaFile::DrawTraceEntity(const DXFTraceEntity & rE, const DXFTransform & rTransform)
     364             : {
     365           0 :     if (SetLineAttribute(rE)) {
     366           0 :         Polygon aPoly(4);
     367           0 :         rTransform.Transform(rE.aP0,aPoly[0]);
     368           0 :         rTransform.Transform(rE.aP1,aPoly[1]);
     369           0 :         rTransform.Transform(rE.aP3,aPoly[2]);
     370           0 :         rTransform.Transform(rE.aP2,aPoly[3]);
     371           0 :         pVirDev->DrawPolygon(aPoly);
     372           0 :         if (rE.fThickness!=0) {
     373             :             sal_uInt16 i;
     374           0 :             Polygon aPoly2(4);
     375           0 :             DXFVector aVAdd(0,0,rE.fThickness);
     376           0 :             rTransform.Transform(rE.aP0+aVAdd,aPoly2[0]);
     377           0 :             rTransform.Transform(rE.aP1+aVAdd,aPoly2[1]);
     378           0 :             rTransform.Transform(rE.aP3+aVAdd,aPoly2[2]);
     379           0 :             rTransform.Transform(rE.aP2+aVAdd,aPoly2[3]);
     380           0 :             pVirDev->DrawPolygon(aPoly2);
     381           0 :             for (i=0; i<4; i++) pVirDev->DrawLine(aPoly[i],aPoly2[i]);
     382           0 :         }
     383             :     }
     384           0 : }
     385             : 
     386             : 
     387           0 : void DXF2GDIMetaFile::DrawSolidEntity(const DXFSolidEntity & rE, const DXFTransform & rTransform)
     388             : {
     389           0 :     if (SetAreaAttribute(rE)) {
     390             :         sal_uInt16 nN;
     391           0 :         if (rE.aP2==rE.aP3) nN=3; else nN=4;
     392           0 :         Polygon aPoly(nN);
     393           0 :         rTransform.Transform(rE.aP0,aPoly[0]);
     394           0 :         rTransform.Transform(rE.aP1,aPoly[1]);
     395           0 :         rTransform.Transform(rE.aP3,aPoly[2]);
     396           0 :         if (nN>3) rTransform.Transform(rE.aP2,aPoly[3]);
     397           0 :         pVirDev->DrawPolygon(aPoly);
     398           0 :         if (rE.fThickness!=0) {
     399           0 :             Polygon aPoly2(nN);
     400           0 :             DXFVector aVAdd(0,0,rE.fThickness);
     401           0 :             rTransform.Transform(rE.aP0+aVAdd,aPoly2[0]);
     402           0 :             rTransform.Transform(rE.aP1+aVAdd,aPoly2[1]);
     403           0 :             rTransform.Transform(rE.aP3+aVAdd,aPoly2[2]);
     404           0 :             if (nN>3) rTransform.Transform(rE.aP2+aVAdd,aPoly2[3]);
     405           0 :             pVirDev->DrawPolygon(aPoly2);
     406           0 :             if (SetLineAttribute(rE)) {
     407             :                 sal_uInt16 i;
     408           0 :                 for (i=0; i<nN; i++) pVirDev->DrawLine(aPoly[i],aPoly2[i]);
     409           0 :             }
     410           0 :         }
     411             :     }
     412           0 : }
     413             : 
     414             : 
     415           0 : void DXF2GDIMetaFile::DrawTextEntity(const DXFTextEntity & rE, const DXFTransform & rTransform)
     416             : {
     417           0 :     DXFVector aV;
     418           0 :     Point aPt;
     419             :     double fA;
     420             :     sal_uInt16 nHeight;
     421             :     short nAng;
     422           0 :     DXFTransform aT( DXFTransform(rE.fXScale,rE.fHeight,1.0,rE.fRotAngle,rE.aP0), rTransform );
     423           0 :     aT.TransDir(DXFVector(0,1,0),aV);
     424           0 :     nHeight=(sal_uInt16)(aV.Abs()+0.5);
     425           0 :     fA=aT.CalcRotAngle();
     426           0 :     nAng=(short)(fA*10.0+0.5);
     427           0 :     aT.TransDir(DXFVector(1,0,0),aV);
     428           0 :     if ( SetFontAttribute( rE,nAng, nHeight, aV. Abs() ) )
     429             :     {
     430           0 :         OUString const aUString(pDXF->ToOUString(rE.m_sText, true));
     431           0 :         aT.Transform( DXFVector( 0, 0, 0 ), aPt );
     432           0 :         pVirDev->DrawText( aPt, aUString );
     433             :     }
     434           0 : }
     435             : 
     436             : 
     437           0 : void DXF2GDIMetaFile::DrawInsertEntity(const DXFInsertEntity & rE, const DXFTransform & rTransform)
     438             : {
     439             :     const DXFBlock * pB;
     440           0 :     pB=pDXF->aBlocks.Search(rE.m_sName);
     441           0 :     if (pB!=NULL) {
     442           0 :         DXFTransform aDXFTransform1(1.0,1.0,1.0,DXFVector(0.0,0.0,0.0)-pB->aBasePoint);
     443           0 :         DXFTransform aDXFTransform2(rE.fXScale,rE.fYScale,rE.fZScale,rE.fRotAngle,rE.aP0);
     444             :         DXFTransform aT(
     445             :             DXFTransform( aDXFTransform1, aDXFTransform2 ),
     446             :             rTransform
     447           0 :         );
     448             :         long nSavedBlockColor, nSavedParentLayerColor;
     449           0 :         DXFLineInfo aSavedBlockDXFLineInfo, aSavedParentLayerDXFLineInfo;
     450           0 :         nSavedBlockColor=nBlockColor;
     451           0 :         nSavedParentLayerColor=nParentLayerColor;
     452           0 :         aSavedBlockDXFLineInfo=aBlockDXFLineInfo;
     453           0 :         aSavedParentLayerDXFLineInfo=aParentLayerDXFLineInfo;
     454           0 :         nBlockColor=GetEntityColor(rE);
     455           0 :         aBlockDXFLineInfo=GetEntityDXFLineInfo(rE);
     456           0 :         if (rE.m_sLayer.getLength() > 1) {
     457           0 :             DXFLayer * pLayer=pDXF->aTables.SearchLayer(rE.m_sLayer);
     458           0 :             if (pLayer!=NULL) {
     459           0 :                 nParentLayerColor=pLayer->nColor;
     460           0 :                 aParentLayerDXFLineInfo = LTypeToDXFLineInfo(pLayer->m_sLineType);
     461             :             }
     462             :         }
     463           0 :         DrawEntities(*pB,aT);
     464           0 :         aBlockDXFLineInfo=aSavedBlockDXFLineInfo;
     465           0 :         aParentLayerDXFLineInfo=aSavedParentLayerDXFLineInfo;
     466           0 :         nBlockColor=nSavedBlockColor;
     467           0 :         nParentLayerColor=nSavedParentLayerColor;
     468             :     }
     469           0 : }
     470             : 
     471             : 
     472           0 : void DXF2GDIMetaFile::DrawAttribEntity(const DXFAttribEntity & rE, const DXFTransform & rTransform)
     473             : {
     474           0 :     if ((rE.nAttrFlags&1)==0) {
     475           0 :         DXFVector aV;
     476           0 :         Point aPt;
     477             :         double fA;
     478             :         sal_uInt16 nHeight;
     479             :         short nAng;
     480           0 :         DXFTransform aT( DXFTransform( rE.fXScale, rE.fHeight, 1.0, rE.fRotAngle, rE.aP0 ), rTransform );
     481           0 :         aT.TransDir(DXFVector(0,1,0),aV);
     482           0 :         nHeight=(sal_uInt16)(aV.Abs()+0.5);
     483           0 :         fA=aT.CalcRotAngle();
     484           0 :         nAng=(short)(fA*10.0+0.5);
     485           0 :         aT.TransDir(DXFVector(1,0,0),aV);
     486           0 :         if (SetFontAttribute(rE,nAng,nHeight,aV.Abs()))
     487             :         {
     488           0 :             OUString const aUString(pDXF->ToOUString(rE.m_sText, true));
     489           0 :             aT.Transform( DXFVector( 0, 0, 0 ), aPt );
     490           0 :             pVirDev->DrawText( aPt, aUString );
     491             :         }
     492             :     }
     493           0 : }
     494             : 
     495             : 
     496           0 : void DXF2GDIMetaFile::DrawPolyLineEntity(const DXFPolyLineEntity & rE, const DXFTransform & rTransform)
     497             : {
     498             :     sal_uInt16 i,nPolySize;
     499             :     double fW;
     500             :     const DXFBasicEntity * pBE;
     501             : 
     502           0 :     nPolySize=0;
     503           0 :     pBE=rE.pSucc;
     504           0 :     while (pBE!=NULL && pBE->eType==DXF_VERTEX) {
     505           0 :         nPolySize++;
     506           0 :         pBE=pBE->pSucc;
     507             :     }
     508           0 :     if (nPolySize<2) return;
     509           0 :     Polygon aPoly(nPolySize);
     510           0 :     fW=0.0;
     511           0 :     pBE=rE.pSucc;
     512           0 :     for (i=0; i<nPolySize; i++) {
     513           0 :         rTransform.Transform(static_cast<const DXFVertexEntity*>(pBE)->aP0,aPoly[i]);
     514           0 :         if (i+1<nPolySize || (rE.nFlags&1)!=0) {
     515           0 :             if (static_cast<const DXFVertexEntity*>(pBE)->fSWidth>=0.0) fW+=static_cast<const DXFVertexEntity*>(pBE)->fSWidth;
     516           0 :             else fW+=rE.fSWidth;
     517           0 :             if (static_cast<const DXFVertexEntity*>(pBE)->fEWidth>=0.0) fW+=static_cast<const DXFVertexEntity*>(pBE)->fEWidth;
     518           0 :             else fW+=rE.fEWidth;
     519             :         }
     520           0 :         pBE=pBE->pSucc;
     521             :     }
     522           0 :     fW/=2.0;
     523           0 :     if ((rE.nFlags&1)!=0) fW/=(double)nPolySize;
     524           0 :     else fW/=(double)(nPolySize-1);
     525           0 :     if (SetLineAttribute(rE,rTransform.TransLineWidth(fW))) {
     526           0 :         if ((rE.nFlags&1)!=0) pVirDev->DrawPolygon(aPoly);
     527           0 :         else pVirDev->DrawPolyLine(aPoly);
     528           0 :         if (rE.fThickness!=0) {
     529           0 :             Polygon aPoly2(nPolySize);
     530           0 :             pBE=rE.pSucc;
     531           0 :             for (i=0; i<nPolySize; i++) {
     532             :                 rTransform.Transform(
     533           0 :                    (static_cast<const DXFVertexEntity*>(pBE)->aP0)+DXFVector(0,0,rE.fThickness),
     534           0 :                    aPoly2[i]
     535           0 :                 );
     536           0 :                 pBE=pBE->pSucc;
     537             :             }
     538           0 :             if ((rE.nFlags&1)!=0) pVirDev->DrawPolygon(aPoly2);
     539           0 :             else pVirDev->DrawPolyLine(aPoly2);
     540           0 :             for (i=0; i<nPolySize; i++) pVirDev->DrawLine(aPoly[i],aPoly2[i]);
     541             :         }
     542           0 :     }
     543             : }
     544             : 
     545           0 : void DXF2GDIMetaFile::DrawLWPolyLineEntity(const DXFLWPolyLineEntity & rE, const DXFTransform & rTransform )
     546             : {
     547           0 :     sal_Int32 i, nPolySize = rE.nCount;
     548           0 :     if ( nPolySize && rE.pP )
     549             :     {
     550           0 :         Polygon aPoly( (sal_uInt16)nPolySize);
     551           0 :         for ( i = 0; i < nPolySize; i++ )
     552             :         {
     553           0 :             rTransform.Transform( rE.pP[ (sal_uInt16)i ], aPoly[ (sal_uInt16)i ] );
     554             :         }
     555           0 :         double fW = rE.fConstantWidth;
     556           0 :         if ( SetLineAttribute( rE, rTransform.TransLineWidth( fW ) ) )
     557             :         {
     558           0 :             if ( ( rE.nFlags & 1 ) != 0 )
     559           0 :                 pVirDev->DrawPolygon( aPoly );
     560             :             else
     561           0 :                 pVirDev->DrawPolyLine( aPoly );
     562           0 :         }
     563             :     }
     564           0 : }
     565             : 
     566           0 : void DXF2GDIMetaFile::DrawHatchEntity(const DXFHatchEntity & rE, const DXFTransform & rTransform )
     567             : {
     568           0 :     if ( rE.nBoundaryPathCount )
     569             :     {
     570           0 :         SetAreaAttribute( rE );
     571           0 :         sal_Int32 j = 0;
     572           0 :         tools::PolyPolygon aPolyPoly;
     573           0 :         for ( j = 0; j < rE.nBoundaryPathCount; j++ )
     574             :         {
     575           0 :             DXFPointArray aPtAry;
     576           0 :             const DXFBoundaryPathData& rPathData = rE.pBoundaryPathData[ j ];
     577           0 :             if ( rPathData.bIsPolyLine )
     578             :             {
     579             :                 sal_Int32 i;
     580           0 :                 for( i = 0; i < rPathData.nPointCount; i++ )
     581             :                 {
     582           0 :                     Point aPt;
     583           0 :                     rTransform.Transform( rPathData.pP[ i ], aPt );
     584           0 :                     aPtAry.push_back( aPt );
     585             :                 }
     586             :             }
     587             :             else
     588             :             {
     589             :                 sal_uInt32 i;
     590           0 :                 for ( i = 0; i < rPathData.aEdges.size(); i++ )
     591             :                 {
     592           0 :                     const DXFEdgeType* pEdge = rPathData.aEdges[ i ];
     593           0 :                     switch( pEdge->nEdgeType )
     594             :                     {
     595             :                         case 1 :
     596             :                         {
     597           0 :                             Point aPt;
     598           0 :                             rTransform.Transform( static_cast<const DXFEdgeTypeLine*>(pEdge)->aStartPoint, aPt );
     599           0 :                             aPtAry.push_back( aPt );
     600           0 :                             rTransform.Transform( static_cast<const DXFEdgeTypeLine*>(pEdge)->aEndPoint, aPt );
     601           0 :                             aPtAry.push_back( aPt );
     602             :                         }
     603           0 :                         break;
     604             :                         case 2 :
     605             :                         case 3 :
     606             :                         case 4 :
     607           0 :                         break;
     608             :                     }
     609             :                 }
     610             :             }
     611           0 :             sal_uInt16 i, nSize = (sal_uInt16)aPtAry.size();
     612           0 :             if ( nSize )
     613             :             {
     614           0 :                 Polygon aPoly( nSize );
     615           0 :                 for ( i = 0; i < nSize; i++ )
     616           0 :                     aPoly[ i ] = aPtAry[ i ];
     617           0 :                 aPolyPoly.Insert( aPoly, POLYPOLY_APPEND );
     618             :             }
     619           0 :         }
     620           0 :         if ( aPolyPoly.Count() )
     621           0 :             pVirDev->DrawPolyPolygon( aPolyPoly );
     622             :     }
     623           0 : }
     624             : 
     625           0 : void DXF2GDIMetaFile::Draw3DFaceEntity(const DXF3DFaceEntity & rE, const DXFTransform & rTransform)
     626             : {
     627             :     sal_uInt16 nN,i;
     628           0 :     if (SetLineAttribute(rE)) {
     629           0 :         if (rE.aP2==rE.aP3) nN=3; else nN=4;
     630           0 :         Polygon aPoly(nN);
     631           0 :         rTransform.Transform(rE.aP0,aPoly[0]);
     632           0 :         rTransform.Transform(rE.aP1,aPoly[1]);
     633           0 :         rTransform.Transform(rE.aP2,aPoly[2]);
     634           0 :         if (nN>3) rTransform.Transform(rE.aP3,aPoly[3]);
     635           0 :         if ((rE.nIEFlags&0x0f)==0) pVirDev->DrawPolygon(aPoly);
     636             :         else {
     637           0 :             for (i=0; i<nN; i++) {
     638           0 :                 if ( (rE.nIEFlags & (1<<i)) == 0 ) {
     639           0 :                     pVirDev->DrawLine(aPoly[i],aPoly[(i+1)%nN]);
     640             :                 }
     641             :             }
     642           0 :         }
     643             :     }
     644           0 : }
     645             : 
     646             : 
     647           0 : void DXF2GDIMetaFile::DrawDimensionEntity(const DXFDimensionEntity & rE, const DXFTransform & rTransform)
     648             : {
     649             :     const DXFBlock * pB;
     650           0 :     pB=pDXF->aBlocks.Search(rE.m_sPseudoBlock);
     651           0 :     if (pB!=NULL) {
     652             :         DXFTransform aT(
     653           0 :             DXFTransform(1.0,1.0,1.0,DXFVector(0.0,0.0,0.0)-pB->aBasePoint),
     654             :             rTransform
     655           0 :         );
     656             :         long nSavedBlockColor, nSavedParentLayerColor;
     657           0 :         DXFLineInfo aSavedBlockDXFLineInfo, aSavedParentLayerDXFLineInfo;
     658           0 :         nSavedBlockColor=nBlockColor;
     659           0 :         nSavedParentLayerColor=nParentLayerColor;
     660           0 :         aSavedBlockDXFLineInfo=aBlockDXFLineInfo;
     661           0 :         aSavedParentLayerDXFLineInfo=aParentLayerDXFLineInfo;
     662           0 :         nBlockColor=GetEntityColor(rE);
     663           0 :         aBlockDXFLineInfo=GetEntityDXFLineInfo(rE);
     664           0 :         if (rE.m_sLayer.getLength() > 1) {
     665           0 :             DXFLayer * pLayer=pDXF->aTables.SearchLayer(rE.m_sLayer);
     666           0 :             if (pLayer!=NULL) {
     667           0 :                 nParentLayerColor=pLayer->nColor;
     668           0 :                 aParentLayerDXFLineInfo = LTypeToDXFLineInfo(pLayer->m_sLineType);
     669             :             }
     670             :         }
     671           0 :         DrawEntities(*pB,aT);
     672           0 :         aBlockDXFLineInfo=aSavedBlockDXFLineInfo;
     673           0 :         aParentLayerDXFLineInfo=aSavedParentLayerDXFLineInfo;
     674           0 :         nBlockColor=nSavedBlockColor;
     675           0 :         nParentLayerColor=nSavedParentLayerColor;
     676             :     }
     677           0 : }
     678             : 
     679             : 
     680           0 : void DXF2GDIMetaFile::DrawEntities(const DXFEntities & rEntities,
     681             :                                    const DXFTransform & rTransform)
     682             : {
     683           0 :     sal_uLong nCount=0;
     684           0 :     DXFTransform aET;
     685             :     const DXFTransform * pT;
     686             : 
     687           0 :     const DXFBasicEntity * pE=rEntities.pFirst;
     688             : 
     689           0 :     while (pE!=NULL && bStatus) {
     690           0 :         if (pE->nSpace==0) {
     691           0 :             if (pE->aExtrusion.fz==1.0) {
     692           0 :                 pT=&rTransform;
     693             :             }
     694             :             else {
     695           0 :                 aET=DXFTransform(DXFTransform(pE->aExtrusion),rTransform);
     696           0 :                 pT=&aET;
     697             :             }
     698           0 :             switch (pE->eType) {
     699             :             case DXF_LINE:
     700           0 :                 DrawLineEntity(static_cast<const DXFLineEntity&>(*pE),*pT);
     701           0 :                 break;
     702             :             case DXF_POINT:
     703           0 :                 DrawPointEntity(static_cast<const DXFPointEntity&>(*pE),*pT);
     704           0 :                 break;
     705             :             case DXF_CIRCLE:
     706           0 :                 DrawCircleEntity(static_cast<const DXFCircleEntity&>(*pE),*pT);
     707           0 :                 break;
     708             :             case DXF_ARC:
     709           0 :                 DrawArcEntity(static_cast<const DXFArcEntity&>(*pE),*pT);
     710           0 :                 break;
     711             :             case DXF_TRACE:
     712           0 :                 DrawTraceEntity(static_cast<const DXFTraceEntity&>(*pE),*pT);
     713           0 :                 break;
     714             :             case DXF_SOLID:
     715           0 :                 DrawSolidEntity(static_cast<const DXFSolidEntity&>(*pE),*pT);
     716           0 :                 break;
     717             :             case DXF_TEXT:
     718           0 :                 DrawTextEntity(static_cast<const DXFTextEntity&>(*pE),*pT);
     719           0 :                 break;
     720             :             case DXF_INSERT:
     721           0 :                 DrawInsertEntity(static_cast<const DXFInsertEntity&>(*pE),*pT);
     722           0 :                 break;
     723             :             case DXF_ATTRIB:
     724           0 :                 DrawAttribEntity(static_cast<const DXFAttribEntity&>(*pE),*pT);
     725           0 :                 break;
     726             :             case DXF_POLYLINE:
     727           0 :                 DrawPolyLineEntity(static_cast<const DXFPolyLineEntity&>(*pE),*pT);
     728           0 :                 break;
     729             :             case DXF_LWPOLYLINE :
     730           0 :                 DrawLWPolyLineEntity(static_cast<const DXFLWPolyLineEntity&>(*pE), *pT);
     731           0 :                 break;
     732             :             case DXF_HATCH :
     733           0 :                 DrawHatchEntity(static_cast<const DXFHatchEntity&>(*pE), *pT);
     734           0 :                 break;
     735             :             case DXF_3DFACE:
     736           0 :                 Draw3DFaceEntity(static_cast<const DXF3DFaceEntity&>(*pE),*pT);
     737           0 :                 break;
     738             :             case DXF_DIMENSION:
     739           0 :                 DrawDimensionEntity(static_cast<const DXFDimensionEntity&>(*pE),*pT);
     740           0 :                 break;
     741             :             default:
     742           0 :                 break;  // four other values not handled -Wall
     743             :             }
     744             :         }
     745           0 :         pE=pE->pSucc;
     746           0 :         nCount++;
     747             :     }
     748           0 : }
     749             : 
     750             : 
     751           1 : DXF2GDIMetaFile::DXF2GDIMetaFile()
     752             :     : pVirDev(NULL)
     753             :     , pDXF(NULL)
     754             :     , bStatus(false)
     755             :     , OptPointsPerCircle(0)
     756             :     , nMinPercent(0)
     757             :     , nMaxPercent(0)
     758             :     , nLastPercent(0)
     759             :     , nMainEntitiesCount(0)
     760             :     , nBlockColor(0)
     761           1 :     , nParentLayerColor(0)
     762             : {
     763           1 : }
     764             : 
     765             : 
     766           1 : DXF2GDIMetaFile::~DXF2GDIMetaFile()
     767             : {
     768           1 : }
     769             : 
     770             : 
     771           0 : bool DXF2GDIMetaFile::Convert(const DXFRepresentation & rDXF, GDIMetaFile & rMTF, sal_uInt16 nminpercent, sal_uInt16 nmaxpercent)
     772             : {
     773             :     double fWidth,fHeight,fScale;
     774           0 :     DXFTransform aTransform;
     775           0 :     Size aPrefSize;
     776             :     const DXFLayer * pLayer;
     777             :     const DXFVPort * pVPort;
     778             : 
     779           0 :     pVirDev = VclPtr<VirtualDevice>::Create();
     780           0 :     pDXF    = &rDXF;
     781           0 :     bStatus = true;
     782             : 
     783           0 :     OptPointsPerCircle=50;
     784             : 
     785           0 :     nMinPercent=(sal_uLong)nminpercent;
     786           0 :     nMaxPercent=(sal_uLong)nmaxpercent;
     787           0 :     nLastPercent=nMinPercent;
     788           0 :     nMainEntitiesCount=CountEntities(pDXF->aEntities);
     789             : 
     790           0 :     nBlockColor=7;
     791           0 :     aBlockDXFLineInfo.eStyle = LINE_SOLID;
     792           0 :     aBlockDXFLineInfo.fWidth = 0;
     793           0 :     aBlockDXFLineInfo.nDashCount = 0;
     794           0 :     aBlockDXFLineInfo.fDashLen = 0;
     795           0 :     aBlockDXFLineInfo.nDotCount = 0;
     796           0 :     aBlockDXFLineInfo.fDotLen = 0;
     797           0 :     aBlockDXFLineInfo.fDistance = 0;
     798             : 
     799           0 :     pLayer=pDXF->aTables.SearchLayer("0");
     800           0 :     if (pLayer!=NULL) {
     801           0 :         nParentLayerColor=pLayer->nColor & 0xff;
     802           0 :         aParentLayerDXFLineInfo = LTypeToDXFLineInfo(pLayer->m_sLineType);
     803             :     }
     804             :     else {
     805           0 :         nParentLayerColor=7;
     806           0 :         aParentLayerDXFLineInfo.eStyle = LINE_SOLID;
     807           0 :         aParentLayerDXFLineInfo.fWidth = 0;
     808           0 :         aParentLayerDXFLineInfo.nDashCount = 0;
     809           0 :         aParentLayerDXFLineInfo.fDashLen = 0;
     810           0 :         aParentLayerDXFLineInfo.nDotCount = 0;
     811           0 :         aParentLayerDXFLineInfo.fDotLen = 0;
     812           0 :         aParentLayerDXFLineInfo.fDistance = 0;
     813             :     }
     814             : 
     815           0 :     pVirDev->EnableOutput(false);
     816           0 :     rMTF.Record(pVirDev);
     817             : 
     818           0 :     aActLineColor = pVirDev->GetLineColor();
     819           0 :     aActFillColor = pVirDev->GetFillColor();
     820           0 :     aActFont = pVirDev->GetFont();
     821             : 
     822           0 :     pVPort=pDXF->aTables.SearchVPort("*ACTIVE");
     823           0 :     if (pVPort!=NULL) {
     824           0 :         if (pVPort->aDirection.fx==0 && pVPort->aDirection.fy==0)
     825           0 :             pVPort=NULL;
     826             :     }
     827             : 
     828           0 :     if (pVPort==NULL) {
     829           0 :         if (pDXF->aBoundingBox.bEmpty)
     830           0 :             bStatus=false;
     831             :         else {
     832           0 :             fWidth=pDXF->aBoundingBox.fMaxX-pDXF->aBoundingBox.fMinX;
     833           0 :             fHeight=pDXF->aBoundingBox.fMaxY-pDXF->aBoundingBox.fMinY;
     834           0 :             if (fWidth<=0 || fHeight<=0) {
     835           0 :                 bStatus=false;
     836           0 :                 fScale = 0;  // -Wall added this...
     837             :             }
     838             :             else {
     839           0 :                     if (fWidth>fHeight)
     840           0 :                         fScale=10000.0/fWidth;
     841             :                     else
     842           0 :                         fScale=10000.0/fHeight;
     843             :                 aTransform=DXFTransform(fScale,-fScale,fScale,
     844             :                                         DXFVector(-pDXF->aBoundingBox.fMinX*fScale,
     845             :                                                    pDXF->aBoundingBox.fMaxY*fScale,
     846           0 :                                                   -pDXF->aBoundingBox.fMinZ*fScale));
     847             :             }
     848           0 :             aPrefSize.Width() =(long)(fWidth*fScale+1.5);
     849           0 :             aPrefSize.Height()=(long)(fHeight*fScale+1.5);
     850             :         }
     851             :     }
     852             :     else {
     853           0 :         fHeight=pVPort->fHeight;
     854           0 :         fWidth=fHeight*pVPort->fAspectRatio;
     855           0 :             if (fWidth>fHeight)
     856           0 :                 fScale=10000.0/fWidth;
     857             :             else
     858           0 :                 fScale=10000.0/fHeight;
     859             :         aTransform=DXFTransform(
     860             :             DXFTransform(pVPort->aDirection,pVPort->aTarget),
     861             :             DXFTransform(
     862           0 :                 DXFTransform(1.0,-1.0,1.0,DXFVector(fWidth/2-pVPort->fCenterX,fHeight/2+pVPort->fCenterY,0)),
     863             :                 DXFTransform(fScale,fScale,fScale,DXFVector(0,0,0))
     864             :             )
     865           0 :         );
     866           0 :         aPrefSize.Width() =(long)(fWidth*fScale+1.5);
     867           0 :         aPrefSize.Height()=(long)(fHeight*fScale+1.5);
     868             :     }
     869             : 
     870           0 :     if (bStatus)
     871           0 :         DrawEntities(pDXF->aEntities,aTransform);
     872             : 
     873           0 :     rMTF.Stop();
     874             : 
     875           0 :     if ( bStatus )
     876             :     {
     877           0 :         rMTF.SetPrefSize( aPrefSize );
     878             :         // simply set map mode to 1/100-mm (1/10-mm) if the graphic
     879             :         // does not get not too small (<0.5cm)
     880           0 :         if( ( aPrefSize.Width() < 500 ) && ( aPrefSize.Height() < 500 ) )
     881           0 :             rMTF.SetPrefMapMode( MapMode( MAP_10TH_MM ) );
     882             :         else
     883           0 :             rMTF.SetPrefMapMode( MapMode( MAP_100TH_MM ) );
     884             :     }
     885             : 
     886           0 :     pVirDev.disposeAndClear();
     887           0 :     return bStatus;
     888             : }
     889             : 
     890             : 
     891             : 
     892             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11