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

Generated by: LCOV version 1.10