LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/icgm - cgm.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 367 0.0 %
Date: 2012-08-25 Functions: 0 30 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10