LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/icgm - cgm.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 249 366 68.0 %
Date: 2014-11-03 Functions: 27 30 90.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             : #include <com/sun/star/task/XStatusIndicator.hpp>
      21             : #include <unotools/ucbstreamhelper.hxx>
      22             : 
      23             : #include <osl/endian.h>
      24             : #include <vcl/virdev.hxx>
      25             : #include <vcl/graph.hxx>
      26             : #include <tools/stream.hxx>
      27             : #include <chart.hxx>
      28             : #include <main.hxx>
      29             : #include <elements.hxx>
      30             : #include <outact.hxx>
      31             : #include <boost/scoped_ptr.hpp>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : 
      35           4 : CGM::CGM( sal_uInt32 nMode, uno::Reference< frame::XModel > const & rModel )
      36             :     : mnOutdx(28000)
      37             :     , mnOutdy(21000)
      38             :     , mnVDCXadd(0)
      39             :     , mnVDCYadd(0)
      40             :     , mnVDCXmul(0)
      41             :     , mnVDCYmul(0)
      42             :     , mnVDCdx(0)
      43             :     , mnVDCdy(0)
      44             :     , mnXFraction(0)
      45             :     , mnYFraction(0)
      46             :     , mbAngReverse(false)
      47             :     , mpGraphic(NULL)
      48             :     , mbStatus(true)
      49             :     , mbMetaFile(false)
      50             :     , mbIsFinished(false)
      51             :     , mbPicture(false)
      52             :     , mbPictureBody(false)
      53             :     , mbFigure(false)
      54             :     , mbFirstOutPut(false)
      55             :     , mnAct4PostReset(0)
      56             :     , mpBitmapInUse(NULL)
      57             :     , mpChart(NULL)
      58           4 :     , mpOutAct(new CGMImpressOutAct(*this, rModel))
      59             :     , mpSource(NULL)
      60             :     , mpEndValidSource(NULL)
      61             :     , mnParaSize(0)
      62             :     , mnActCount(0)
      63             :     , mpBuf(NULL)
      64           4 :     , mnMode(nMode | CGM_EXPORT_IMPRESS)
      65             :     , mnEscape(0)
      66             :     , mnElementClass(0)
      67             :     , mnElementID(0)
      68             :     , mnElementSize(0)
      69             :     , mpVirDev(NULL)
      70          12 :     , mpGDIMetaFile(NULL)
      71             : {
      72           4 :     pElement = new CGMElements( *this );
      73           4 :     pCopyOfE = new CGMElements( *this );
      74           4 : }
      75             : 
      76           8 : CGM::~CGM()
      77             : {
      78           4 :     if ( mpGraphic )
      79             :     {
      80           0 :         mpGDIMetaFile->Stop();
      81           0 :         mpGDIMetaFile->SetPrefMapMode( MapMode() );
      82           0 :         mpGDIMetaFile->SetPrefSize( Size( static_cast< long >( mnOutdx ), static_cast< long >( mnOutdy ) ) );
      83           0 :         delete mpVirDev;
      84           0 :         *mpGraphic = Graphic( *mpGDIMetaFile );
      85             :     }
      86           6 :     for( size_t i = 0, n = maDefRepList.size(); i < n; ++i )
      87           2 :         delete [] maDefRepList[i];
      88           4 :     maDefRepList.clear();
      89           4 :     maDefRepSizeList.clear();
      90           4 :     delete mpBitmapInUse;
      91           4 :     delete mpChart;
      92           4 :     delete mpOutAct;
      93           4 :     delete pCopyOfE;
      94           4 :     delete pElement;
      95           4 :     delete [] mpBuf;
      96           4 : };
      97             : 
      98           2 : sal_uInt32 CGM::GetBackGroundColor()
      99             : {
     100           2 :     return ( pElement ) ? pElement->aColorTable[ 0 ] : 0;
     101             : }
     102             : 
     103         894 : sal_uInt32 CGM::ImplGetUI16( sal_uInt32 /*nAlign*/ )
     104             : {
     105         894 :     sal_uInt8* pSource = mpSource + mnParaSize;
     106         894 :     if (pSource + 2 > mpEndValidSource)
     107           0 :         throw css::uno::Exception("attempt to read past end of input", 0);
     108         894 :     mnParaSize += 2;
     109         894 :     return ( pSource[ 0 ] << 8 ) +  pSource[ 1 ];
     110             : };
     111             : 
     112           0 : sal_uInt8 CGM::ImplGetByte( sal_uInt32 nSource, sal_uInt32 nPrecision )
     113             : {
     114           0 :     return (sal_uInt8)( nSource >> ( ( nPrecision - 1 ) << 3 ) );
     115             : };
     116             : 
     117         240 : sal_Int32 CGM::ImplGetI( sal_uInt32 nPrecision )
     118             : {
     119         240 :     sal_uInt8* pSource = mpSource + mnParaSize;
     120         240 :     if (pSource + nPrecision > mpEndValidSource)
     121           2 :         throw css::uno::Exception("attempt to read past end of input", 0);
     122         238 :     mnParaSize += nPrecision;
     123         238 :     switch( nPrecision )
     124             :     {
     125             :         case 1 :
     126             :         {
     127           0 :             return  (char)*pSource;
     128             :         }
     129             : 
     130             :         case 2 :
     131             :         {
     132         238 :             return (sal_Int16)( ( pSource[ 0 ] << 8 ) | pSource[ 1 ] );
     133             :         }
     134             : 
     135             :         case 3 :
     136             :         {
     137           0 :             return ( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | pSource[ 2 ] << 8 ) >> 8;
     138             :         }
     139             :         case 4:
     140             :         {
     141           0 :             return (sal_Int32)( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | ( pSource[ 2 ] << 8 ) | ( pSource[ 3 ] ) );
     142             :         }
     143             :         default:
     144           0 :             mbStatus = false;
     145           0 :             return 0;
     146             :     }
     147             : }
     148             : 
     149          28 : sal_uInt32 CGM::ImplGetUI( sal_uInt32 nPrecision )
     150             : {
     151          28 :     sal_uInt8* pSource = mpSource + mnParaSize;
     152          28 :     if (pSource + nPrecision > mpEndValidSource)
     153           0 :         throw css::uno::Exception("attempt to read past end of input", 0);
     154          28 :     mnParaSize += nPrecision;
     155          28 :     switch( nPrecision )
     156             :     {
     157             :         case 1 :
     158           0 :             return  (sal_Int8)*pSource;
     159             :         case 2 :
     160             :         {
     161          28 :             return (sal_uInt16)( ( pSource[ 0 ] << 8 ) | pSource[ 1 ] );
     162             :         }
     163             :         case 3 :
     164             :         {
     165           0 :             return ( pSource[ 0 ] << 16 ) | ( pSource[ 1 ] << 8 ) | pSource[ 2 ];
     166             :         }
     167             :         case 4:
     168             :         {
     169           0 :             return (sal_uInt32)( ( pSource[ 0 ] << 24 ) | ( pSource[ 1 ] << 16 ) | ( pSource[ 2 ] << 8 ) | ( pSource[ 3 ] ) );
     170             :         }
     171             :         default:
     172           0 :             mbStatus = false;
     173           0 :             return 0;
     174             :     }
     175             : }
     176             : 
     177        1434 : void CGM::ImplGetSwitch4( sal_uInt8* pSource, sal_uInt8* pDest )
     178             : {
     179        7170 :     for ( int i = 0; i < 4; i++ )
     180             :     {
     181        5736 :         pDest[ i ] = pSource[ i ^ 3 ];          // Little Endian <-> Big Endian switch
     182             :     }
     183        1434 : }
     184             : 
     185           0 : void CGM::ImplGetSwitch8( sal_uInt8* pSource, sal_uInt8* pDest )
     186             : {
     187           0 :     for ( int i = 0; i < 8; i++ )
     188             :     {
     189           0 :         pDest[ i ] = pSource[ i ^ 7 ];          // Little Endian <-> Big Endian switch
     190             :     }
     191           0 : }
     192             : 
     193        1434 : double CGM::ImplGetFloat( RealPrecision eRealPrecision, sal_uInt32 nRealSize )
     194             : {
     195             :     void*   pPtr;
     196             :     sal_uInt8   aBuf[8];
     197             :     double  nRetValue;
     198             :     double  fDoubleBuf;
     199             :     float   fFloatBuf;
     200             : 
     201             : #ifdef OSL_BIGENDIAN
     202             :     const bool bCompatible = true;
     203             : #else
     204        1434 :     const bool bCompatible = false;
     205             : #endif
     206             : 
     207        1434 :     if (mpSource + mnParaSize + nRealSize > mpEndValidSource)
     208           0 :         throw css::uno::Exception("attempt to read past end of input", 0);
     209             : 
     210             :     if ( bCompatible )
     211             :     {
     212             :         pPtr = mpSource + mnParaSize;
     213             :     }
     214             :     else
     215             :     {
     216        1434 :         if ( nRealSize == 4 )
     217        1434 :             ImplGetSwitch4( mpSource + mnParaSize, &aBuf[0] );
     218             :         else
     219           0 :             ImplGetSwitch8( mpSource + mnParaSize, &aBuf[0] );
     220        1434 :         pPtr = &aBuf;
     221             :     }
     222        1434 :     if ( eRealPrecision == RP_FLOAT )
     223             :     {
     224           0 :         if ( nRealSize == 4 )
     225             :         {
     226           0 :             memcpy( (void*)&fFloatBuf, pPtr, 4 );
     227           0 :             nRetValue = (double)fFloatBuf;
     228             :         }
     229             :         else
     230             :         {
     231           0 :             memcpy( (void*)&fDoubleBuf, pPtr, 8 );
     232           0 :             nRetValue = fDoubleBuf;
     233             :         }
     234             :     }
     235             :     else // ->RP_FIXED
     236             :     {
     237             :         long    nVal;
     238        1434 :         int     nSwitch = ( bCompatible ) ? 0 : 1 ;
     239        1434 :         if ( nRealSize == 4 )
     240             :         {
     241        1434 :             sal_uInt16* pShort = (sal_uInt16*)pPtr;
     242        1434 :             nVal = pShort[ nSwitch ];
     243        1434 :             nVal <<= 16;
     244        1434 :             nVal |= pShort[ nSwitch ^ 1 ];
     245        1434 :             nRetValue = (double)nVal;
     246        1434 :             nRetValue /= 65536;
     247             :         }
     248             :         else
     249             :         {
     250           0 :             sal_Int32* pLong = (sal_Int32*)pPtr;
     251           0 :             nRetValue = (double)abs( pLong[ nSwitch ] );
     252           0 :             nRetValue *= 65536;
     253           0 :             nVal = (sal_uInt32)( pLong[ nSwitch ^ 1 ] );
     254           0 :             nVal >>= 16;
     255           0 :             nRetValue += (double)nVal;
     256           0 :             if ( pLong[ nSwitch ] < 0 )
     257             :             {
     258           0 :                 nRetValue = -nRetValue;
     259             :             }
     260           0 :             nRetValue /= 65536;
     261             :         }
     262             :     }
     263        1434 :     mnParaSize += nRealSize;
     264        1434 :     return nRetValue;
     265             : }
     266             : 
     267          56 : sal_uInt32 CGM::ImplGetPointSize()
     268             : {
     269          56 :     if ( pElement->eVDCType == VDC_INTEGER )
     270           0 :         return pElement->nVDCIntegerPrecision << 1;
     271             :     else
     272          56 :         return pElement->nVDCRealSize << 1;
     273             : }
     274             : 
     275           4 : inline double CGM::ImplGetIX()
     276             : {
     277           4 :     return ( ( ImplGetI( pElement->nVDCIntegerPrecision ) + mnVDCXadd ) * mnVDCXmul );
     278             : }
     279             : 
     280         462 : inline double CGM::ImplGetFX()
     281             : {
     282         462 :     return ( ( ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize ) + mnVDCXadd ) * mnVDCXmul );
     283             : }
     284             : 
     285           2 : inline double CGM::ImplGetIY()
     286             : {
     287           2 :     return ( ( ImplGetI( pElement->nVDCIntegerPrecision ) + mnVDCYadd ) * mnVDCYmul );
     288             : }
     289             : 
     290         462 : inline double CGM::ImplGetFY()
     291             : {
     292         462 :     return ( ( ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize ) + mnVDCYadd ) * mnVDCYmul );
     293             : }
     294             : 
     295         422 : void CGM::ImplGetPoint( FloatPoint& rFloatPoint, bool bMap )
     296             : {
     297         422 :     if ( pElement->eVDCType == VDC_INTEGER )
     298             :     {
     299           4 :         rFloatPoint.X = ImplGetIX();
     300           2 :         rFloatPoint.Y = ImplGetIY();
     301             :     }
     302             :     else // ->floating points
     303             :     {
     304         418 :         rFloatPoint.X = ImplGetFX();
     305         418 :         rFloatPoint.Y = ImplGetFY();
     306             :     }
     307         420 :     if ( bMap )
     308         408 :         ImplMapPoint( rFloatPoint );
     309         420 : }
     310             : 
     311          22 : void CGM::ImplGetRectangle( FloatRect& rFloatRect, bool bMap )
     312             : {
     313          22 :     if ( pElement->eVDCType == VDC_INTEGER )
     314             :     {
     315           0 :         rFloatRect.Left = ImplGetIX();
     316           0 :         rFloatRect.Bottom = ImplGetIY();
     317           0 :         rFloatRect.Right = ImplGetIX();
     318           0 :         rFloatRect.Top = ImplGetIY();
     319             :     }
     320             :     else // ->floating points
     321             :     {
     322          22 :         rFloatRect.Left = ImplGetFX();
     323          22 :         rFloatRect.Bottom = ImplGetFY();
     324          22 :         rFloatRect.Right = ImplGetFX();
     325          22 :         rFloatRect.Top = ImplGetFY();
     326             :     }
     327          22 :     if ( bMap )
     328             :     {
     329          22 :         ImplMapX( rFloatRect.Left );
     330          22 :         ImplMapX( rFloatRect.Right );
     331          22 :         ImplMapY( rFloatRect.Top );
     332          22 :         ImplMapY( rFloatRect.Bottom );
     333          22 :         rFloatRect.Justify();
     334             :     }
     335          22 : }
     336             : 
     337          34 : void CGM::ImplGetRectangleNS( FloatRect& rFloatRect )
     338             : {
     339          34 :     if ( pElement->eVDCType == VDC_INTEGER )
     340             :     {
     341           0 :         rFloatRect.Left = ImplGetI( pElement->nVDCIntegerPrecision );
     342           0 :         rFloatRect.Bottom = ImplGetI( pElement->nVDCIntegerPrecision );
     343           0 :         rFloatRect.Right = ImplGetI( pElement->nVDCIntegerPrecision );
     344           0 :         rFloatRect.Top = ImplGetI( pElement->nVDCIntegerPrecision );
     345             :     }
     346             :     else // ->floating points
     347             :     {
     348          34 :         rFloatRect.Left = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
     349          34 :         rFloatRect.Bottom = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
     350          34 :         rFloatRect.Right = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
     351          34 :         rFloatRect.Top = ImplGetFloat( pElement->eVDCRealPrecision, pElement->nVDCRealSize );
     352             :     }
     353          34 : }
     354             : 
     355           0 : sal_uInt32 CGM::ImplGetBitmapColor( bool bDirect )
     356             : {
     357             :     // the background color is always a direct color
     358             : 
     359             :     sal_uInt32  nTmp;
     360           0 :     if ( ( pElement->eColorSelectionMode == CSM_DIRECT ) || bDirect )
     361             :     {
     362           0 :         sal_uInt32      nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
     363           0 :         sal_uInt32      nDiff = pElement->nColorValueExtent[ 3 ] - pElement->nColorValueExtent[ 0 ] + 1;
     364             : 
     365           0 :         if ( !nDiff )
     366           0 :             nDiff++;
     367           0 :         nColor = ( ( nColor - pElement->nColorValueExtent[ 0 ] ) << 8 ) / nDiff;
     368           0 :         nTmp = nColor << 16 & 0xff0000;
     369             : 
     370           0 :         nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
     371           0 :         nDiff = pElement->nColorValueExtent[ 4 ] - pElement->nColorValueExtent[ 1 ] + 1;
     372           0 :         if ( !nDiff )
     373           0 :             nDiff++;
     374           0 :         nColor = ( ( nColor - pElement->nColorValueExtent[ 1 ] ) << 8 ) / nDiff;
     375           0 :         nTmp |= nColor << 8 & 0xff00;
     376             : 
     377           0 :         nColor = ImplGetByte( ImplGetUI( pElement->nColorPrecision ), 1 );
     378           0 :         nDiff = pElement->nColorValueExtent[ 5 ] - pElement->nColorValueExtent[ 2 ] + 1;
     379           0 :         if ( !nDiff )
     380           0 :             nDiff++;
     381           0 :         nColor = ( ( nColor - pElement->nColorValueExtent[ 2 ] ) << 8 ) / nDiff;
     382           0 :         nTmp |= (sal_uInt8)nColor;
     383             :     }
     384             :     else
     385             :     {
     386           0 :         sal_uInt32 nIndex = ImplGetUI( pElement->nColorIndexPrecision );
     387           0 :         nTmp = pElement->aColorTable[ (sal_uInt8)( nIndex ) ] ;
     388             :     }
     389           0 :     return nTmp;
     390             : }
     391             : 
     392             : // call this function each time after the mapmode settings has been changed
     393          64 : void CGM::ImplSetMapMode()
     394             : {
     395          64 :     int nAngReverse = 1;
     396          64 :     mnVDCdx = pElement->aVDCExtent.Right - pElement->aVDCExtent.Left;
     397             : 
     398          64 :     mnVDCXadd = -pElement->aVDCExtent.Left;
     399          64 :     mnVDCXmul = 1;
     400          64 :     if ( mnVDCdx < 0 )
     401             :     {
     402           4 :         nAngReverse ^= 1;
     403           4 :         mnVDCdx = -mnVDCdx;
     404           4 :         mnVDCXmul = -1;
     405             :     }
     406             : 
     407          64 :     mnVDCdy = pElement->aVDCExtent.Bottom - pElement->aVDCExtent.Top;
     408          64 :     mnVDCYadd = -pElement->aVDCExtent.Top;
     409          64 :     mnVDCYmul = 1;
     410          64 :     if ( mnVDCdy < 0 )
     411             :     {
     412          60 :         nAngReverse ^= 1;
     413          60 :         mnVDCdy = -mnVDCdy;
     414          60 :         mnVDCYmul = -1;
     415             :     }
     416          64 :     if ( nAngReverse )
     417           4 :         mbAngReverse = true;
     418             :     else
     419          60 :         mbAngReverse = false;
     420             : 
     421          64 :     double fQuo1 = mnVDCdx / mnVDCdy;
     422          64 :     double fQuo2 = mnOutdx / mnOutdy;
     423          64 :     if ( fQuo2 < fQuo1 )
     424             :     {
     425           0 :         mnXFraction = mnOutdx / mnVDCdx;
     426           0 :         mnYFraction = mnOutdy * ( fQuo2 / fQuo1 ) / mnVDCdy;
     427             :     }
     428             :     else
     429             :     {
     430          64 :         mnXFraction = mnOutdx * ( fQuo1 / fQuo2 ) / mnVDCdx;
     431          64 :         mnYFraction = mnOutdy / mnVDCdy;
     432             :     }
     433          64 : }
     434             : 
     435          92 : void CGM::ImplMapDouble( double& nNumb )
     436             : {
     437          92 :     if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
     438             :     {
     439             :         // point is 1mm * ScalingFactor
     440          92 :         switch ( pElement->eDeviceViewPortMode )
     441             :         {
     442             :             case DVPM_FRACTION :
     443             :             {
     444          92 :                 nNumb *= ( mnXFraction + mnYFraction ) / 2;
     445             :             }
     446          92 :             break;
     447             : 
     448             :             case DVPM_METRIC :
     449             :             {
     450             :                 // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
     451           0 :                 nNumb *= ( mnXFraction + mnYFraction ) / 2;
     452           0 :                 if ( pElement->nDeviceViewPortScale < 0 )
     453           0 :                     nNumb = -nNumb;
     454             :             }
     455           0 :             break;
     456             : 
     457             :             case DVPM_DEVICE :
     458             :             {
     459             : 
     460             :             }
     461           0 :             break;
     462             : 
     463             :             default:
     464             : 
     465           0 :                 break;
     466             :         }
     467             :     }
     468             :     else
     469             :     {
     470             : 
     471             : 
     472             :     }
     473          92 : }
     474             : 
     475          44 : void CGM::ImplMapX( double& nNumb )
     476             : {
     477          44 :     if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
     478             :     {
     479             :         // point is 1mm * ScalingFactor
     480          44 :         switch ( pElement->eDeviceViewPortMode )
     481             :         {
     482             :             case DVPM_FRACTION :
     483             :             {
     484          44 :                 nNumb *= mnXFraction;
     485             :             }
     486          44 :             break;
     487             : 
     488             :             case DVPM_METRIC :
     489             :             {
     490             :                 // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
     491           0 :                 nNumb *= mnXFraction;
     492           0 :                 if ( pElement->nDeviceViewPortScale < 0 )
     493           0 :                     nNumb = -nNumb;
     494             :             }
     495           0 :             break;
     496             : 
     497             :             case DVPM_DEVICE :
     498             :             {
     499             : 
     500             :             }
     501           0 :             break;
     502             : 
     503             :             default:
     504             : 
     505           0 :                 break;
     506             :         }
     507             :     }
     508             :     else
     509             :     {
     510             : 
     511             : 
     512             :     }
     513          44 : }
     514             : 
     515          44 : void CGM::ImplMapY( double& nNumb )
     516             : {
     517          44 :     if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
     518             :     {
     519             :         // point is 1mm * ScalingFactor
     520          44 :         switch ( pElement->eDeviceViewPortMode )
     521             :         {
     522             :             case DVPM_FRACTION :
     523             :             {
     524          44 :                 nNumb *= mnYFraction;
     525             :             }
     526          44 :             break;
     527             : 
     528             :             case DVPM_METRIC :
     529             :             {
     530             :                 // nNumb *= ( 100 * pElement->nDeviceViewPortScale );
     531           0 :                 nNumb *= mnYFraction;
     532           0 :                 if ( pElement->nDeviceViewPortScale < 0 )
     533           0 :                     nNumb = -nNumb;
     534             :             }
     535           0 :             break;
     536             : 
     537             :             case DVPM_DEVICE :
     538             :             {
     539             : 
     540             :             }
     541           0 :             break;
     542             : 
     543             :             default:
     544             : 
     545           0 :                 break;
     546             :         }
     547             :     }
     548             :     else
     549             :     {
     550             : 
     551             : 
     552             :     }
     553          44 : }
     554             : 
     555             : // convert a point to the current VC mapmode (1/100TH mm)
     556         408 : void CGM::ImplMapPoint( FloatPoint& rFloatPoint )
     557             : {
     558         408 :     if ( pElement->eDeviceViewPortMap == DVPM_FORCED )
     559             :     {
     560             :         // point is 1mm * ScalingFactor
     561         408 :         switch ( pElement->eDeviceViewPortMode )
     562             :         {
     563             :             case DVPM_FRACTION :
     564             :             {
     565         408 :                 rFloatPoint.X *= mnXFraction;
     566         408 :                 rFloatPoint.Y *= mnYFraction;
     567             :             }
     568         408 :             break;
     569             : 
     570             :             case DVPM_METRIC :
     571             :             {
     572           0 :                 rFloatPoint.X *= mnXFraction;
     573           0 :                 rFloatPoint.Y *= mnYFraction;
     574           0 :                 if ( pElement->nDeviceViewPortScale < 0 )
     575             :                 {
     576           0 :                     rFloatPoint.X = -rFloatPoint.X;
     577           0 :                     rFloatPoint.Y = -rFloatPoint.Y;
     578             :                 }
     579             :             }
     580           0 :             break;
     581             : 
     582             :             case DVPM_DEVICE :
     583             :             {
     584             : 
     585             :             }
     586           0 :             break;
     587             : 
     588             :             default:
     589             : 
     590           0 :                 break;
     591             :         }
     592             :     }
     593             :     else
     594             :     {
     595             : 
     596             : 
     597             :     }
     598         408 : }
     599             : 
     600         620 : void CGM::ImplDoClass()
     601             : {
     602         620 :     switch ( mnElementClass )
     603             :     {
     604          88 :         case 0 : ImplDoClass0(); break;
     605           8 :         case 1 : ImplDoClass1(); break;
     606          34 :         case 2 : ImplDoClass2(); break;
     607          60 :         case 3 : ImplDoClass3(); break;
     608             :         case 4 :
     609             :         {
     610         206 :             ImplDoClass4();
     611         204 :             mnAct4PostReset = 0;
     612             :         }
     613         204 :         break;
     614         224 :         case 5 : ImplDoClass5(); break;
     615           0 :         case 6 : ImplDoClass6(); break;
     616           0 :         case 7 : ImplDoClass7(); break;
     617           0 :         case 8 : ImplDoClass8(); break;
     618           0 :         case 9 : ImplDoClass9(); break;
     619           0 :         case 15 :ImplDoClass15(); break;
     620           0 :         default: break;
     621             :     }
     622         618 :     mnActCount++;
     623         618 : };
     624             : 
     625          28 : void CGM::ImplDefaultReplacement()
     626             : {
     627          28 :     if ( !maDefRepList.empty() )
     628             :     {
     629          28 :         sal_uInt32  nOldEscape = mnEscape;
     630          28 :         sal_uInt32  nOldElementClass = mnElementClass;
     631          28 :         sal_uInt32  nOldElementID = mnElementID;
     632          28 :         sal_uInt32  nOldElementSize = mnElementSize;
     633          28 :         sal_uInt8*  pOldBuf = mpSource;
     634          28 :         sal_uInt8*  pOldEndValidSource = mpEndValidSource;
     635             : 
     636          56 :         for ( size_t i = 0, n = maDefRepList.size(); i < n; ++i )
     637             :         {
     638          28 :             sal_uInt8*  pBuf = maDefRepList[ i ];
     639          28 :             sal_uInt32  nElementSize = maDefRepSizeList[ i ];
     640          28 :             mpEndValidSource = pBuf + nElementSize;
     641          28 :             sal_uInt32  nCount = 0;
     642         196 :             while ( mbStatus && ( nCount < nElementSize ) )
     643             :             {
     644         140 :                 mpSource = pBuf + nCount;
     645         140 :                 mnParaSize = 0;
     646         140 :                 mnEscape = ImplGetUI16();
     647         140 :                 mnElementClass = mnEscape >> 12;
     648         140 :                 mnElementID = ( mnEscape & 0x0fe0 ) >> 5;
     649         140 :                 mnElementSize = mnEscape & 0x1f;
     650         140 :                 if ( mnElementSize == 31 )
     651             :                 {
     652           0 :                     mnElementSize = ImplGetUI16();
     653             :                 }
     654         140 :                 nCount += mnParaSize;
     655         140 :                 mnParaSize = 0;
     656         140 :                 mpSource = pBuf + nCount;
     657         140 :                 if ( mnElementSize & 1 )
     658           0 :                     nCount++;
     659         140 :                 nCount += mnElementSize;
     660         140 :                 if ( ( mnElementClass != 1 ) || ( mnElementID != 0xc ) )    // recursion is not possible here!!
     661         140 :                     ImplDoClass();
     662             :             }
     663             :         }
     664          28 :         mnEscape = nOldEscape;
     665          28 :         mnElementClass = nOldElementClass;
     666          28 :         mnElementID = nOldElementID;
     667          28 :         mnParaSize = mnElementSize = nOldElementSize;
     668          28 :         mpSource = pOldBuf;
     669          28 :         mpEndValidSource = pOldEndValidSource;
     670             :     }
     671          28 : }
     672             : 
     673         480 : bool CGM::Write( SvStream& rIStm )
     674             : {
     675         480 :     if ( !mpBuf )
     676           4 :         mpBuf = new sal_uInt8[ 0xffff ];
     677             : 
     678         480 :     mnParaSize = 0;
     679         480 :     mpSource = mpBuf;
     680         480 :     if (rIStm.Read(mpSource, 2) != 2)
     681           0 :         return false;
     682         480 :     mpEndValidSource = mpSource + 2;
     683         480 :     mnEscape = ImplGetUI16();
     684         480 :     mnElementClass = mnEscape >> 12;
     685         480 :     mnElementID = ( mnEscape & 0x0fe0 ) >> 5;
     686         480 :     mnElementSize = mnEscape & 0x1f;
     687             : 
     688         480 :     if ( mnElementSize == 31 )
     689             :     {
     690          86 :         if (rIStm.Read(mpSource + mnParaSize, 2) != 2)
     691           0 :             return false;
     692          86 :         mpEndValidSource = mpSource + mnParaSize + 2;
     693          86 :         mnElementSize = ImplGetUI16();
     694             :     }
     695         480 :     mnParaSize = 0;
     696         480 :     if (mnElementSize)
     697             :     {
     698         422 :         if (rIStm.Read(mpSource, mnElementSize) != mnElementSize)
     699           0 :             return false;
     700         422 :         mpEndValidSource = mpSource + mnElementSize;
     701             :     }
     702             : 
     703         480 :     if ( mnElementSize & 1 )
     704          58 :         rIStm.SeekRel( 1 );
     705         480 :     ImplDoClass();
     706             : 
     707         478 :     return mbStatus;
     708             : };
     709             : 
     710             : // GraphicImport - the exported function
     711             : extern "C" SAL_DLLPUBLIC_EXPORT sal_uInt32 SAL_CALL
     712           4 : ImportCGM( OUString const & rFileName, uno::Reference< frame::XModel > const & rXModel, sal_uInt32 nMode, css::uno::Reference<css::task::XStatusIndicator> const & aXStatInd )
     713             : {
     714             : 
     715           4 :     sal_uInt32  nStatus = 0;            // retvalue == 0 -> ERROR
     716             :                                         //          == 0xffrrggbb -> background color in the lower 24 bits
     717           4 :     bool    bProgressBar = false;
     718             : 
     719           4 :     if( rXModel.is() )
     720             :     {
     721             :         try
     722             :         {
     723           4 :             boost::scoped_ptr<CGM> pCGM(new CGM( nMode, rXModel ));
     724           4 :             if ( pCGM && pCGM->IsValid() )
     725             :             {
     726           4 :                 if ( nMode & CGM_IMPORT_CGM )
     727             :                 {
     728           4 :                     boost::scoped_ptr<SvStream> pIn(::utl::UcbStreamHelper::CreateStream( rFileName, STREAM_READ ));
     729           4 :                     if ( pIn )
     730             :                     {
     731           4 :                         pIn->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
     732           4 :                         sal_uInt64 const nInSize = pIn->remainingSize();
     733           4 :                         pIn->Seek( 0 );
     734             : 
     735           4 :                         sal_uInt32  nNext = 0;
     736           4 :                         sal_uInt32  nAdd = nInSize / 20;
     737           4 :                         bProgressBar = aXStatInd.is();
     738           4 :                         if ( bProgressBar )
     739           0 :                             aXStatInd->start( "CGM Import" , nInSize );
     740             : 
     741         486 :                         while ( pCGM->IsValid() && ( pIn->Tell() < nInSize ) && !pCGM->IsFinished() )
     742             :                         {
     743         480 :                             if ( bProgressBar )
     744             :                             {
     745           0 :                                 sal_uInt32 nCurrentPos = pIn->Tell();
     746           0 :                                 if ( nCurrentPos >= nNext )
     747             :                                 {
     748           0 :                                     aXStatInd->setValue( nCurrentPos );
     749           0 :                                     nNext = nCurrentPos + nAdd;
     750             :                                 }
     751             :                             }
     752             : 
     753         480 :                             if ( pCGM->Write( *pIn ) == false )
     754           0 :                                 break;
     755             :                         }
     756           2 :                         if ( pCGM->IsValid() )
     757             :                         {
     758           2 :                             nStatus = pCGM->GetBackGroundColor() | 0xff000000;
     759             :                         }
     760           2 :                         if ( bProgressBar )
     761           0 :                             aXStatInd->end();
     762           4 :                     }
     763             :                 }
     764           4 :             }
     765             :         }
     766           4 :         catch (const css::uno::Exception&)
     767             :         {
     768           2 :             nStatus = 0;
     769             :         }
     770             :     }
     771           4 :     return nStatus;
     772          12 : }
     773             : 
     774             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10