LCOV - code coverage report
Current view: top level - basic/source/classes - image.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 274 32.8 %
Date: 2012-08-25 Functions: 9 19 47.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 34 311 10.9 %

           Branch data     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 <tools/stream.hxx>
      21                 :            : #include <tools/tenccvt.hxx>
      22                 :            : #include <basic/sbx.hxx>
      23                 :            : #include "sb.hxx"
      24                 :            : #include <string.h>     // memset() etc
      25                 :            : #include "image.hxx"
      26                 :            : #include <codegen.hxx>
      27 [ +  - ][ +  - ]:         65 : SbiImage::SbiImage()
      28                 :            : {
      29                 :         65 :     pStringOff = NULL;
      30                 :         65 :     pStrings   = NULL;
      31                 :         65 :     pCode      = NULL;
      32                 :         65 :     pLegacyPCode       = NULL;
      33                 :         65 :     nFlags     = 0;
      34                 :         65 :     nStrings   = 0;
      35                 :         65 :     nStringSize= 0;
      36                 :         65 :     nCodeSize  = 0;
      37                 :            :     nLegacyCodeSize  =
      38                 :         65 :     nDimBase   = 0;
      39                 :            :     bInit      =
      40                 :         65 :     bError     = false;
      41                 :         65 :     bFirstInit = true;
      42         [ +  - ]:         65 :     eCharSet   = osl_getThreadTextEncoding();
      43                 :         65 : }
      44                 :            : 
      45 [ +  - ][ +  - ]:         63 : SbiImage::~SbiImage()
                 [ +  - ]
      46                 :            : {
      47         [ +  - ]:         63 :     Clear();
      48                 :         63 : }
      49                 :            : 
      50                 :         63 : void SbiImage::Clear()
      51                 :            : {
      52         [ +  - ]:         63 :     delete[] pStringOff;
      53         [ +  - ]:         63 :     delete[] pStrings;
      54         [ +  - ]:         63 :     delete[] pCode;
      55                 :         63 :     ReleaseLegacyBuffer();
      56                 :         63 :     pStringOff = NULL;
      57                 :         63 :     pStrings   = NULL;
      58                 :         63 :     pCode      = NULL;
      59                 :         63 :     nFlags     = 0;
      60                 :         63 :     nStrings   = 0;
      61                 :         63 :     nStringSize= 0;
      62                 :         63 :     nLegacyCodeSize  = 0;
      63                 :         63 :     nCodeSize  = 0;
      64                 :         63 :     eCharSet   = osl_getThreadTextEncoding();
      65                 :         63 :     nDimBase   = 0;
      66                 :         63 :     bError     = false;
      67                 :         63 : }
      68                 :            : 
      69                 :            : /**************************************************************************
      70                 :            : *
      71                 :            : *    Service-Routines for Load/Store
      72                 :            : *
      73                 :            : **************************************************************************/
      74                 :            : 
      75                 :          0 : bool SbiGood( SvStream& r )
      76                 :            : {
      77 [ #  # ][ #  # ]:          0 :     return !r.IsEof() && r.GetError() == SVSTREAM_OK;
      78                 :            : }
      79                 :            : 
      80                 :            : // Open Record
      81                 :          0 : sal_uIntPtr SbiOpenRecord( SvStream& r, sal_uInt16 nSignature, sal_uInt16 nElem )
      82                 :            : {
      83                 :          0 :     sal_uIntPtr nPos = r.Tell();
      84                 :          0 :     r << nSignature << (sal_Int32) 0 << nElem;
      85                 :          0 :     return nPos;
      86                 :            : }
      87                 :            : 
      88                 :            : // Close Record
      89                 :          0 : void SbiCloseRecord( SvStream& r, sal_uIntPtr nOff )
      90                 :            : {
      91                 :          0 :     sal_uIntPtr nPos = r.Tell();
      92                 :          0 :     r.Seek( nOff + 2 );
      93                 :          0 :     r << (sal_Int32) ( nPos - nOff - 8 );
      94                 :          0 :     r.Seek( nPos );
      95                 :          0 : }
      96                 :            : 
      97                 :            : /**************************************************************************
      98                 :            : *
      99                 :            : *    Load/Store
     100                 :            : *
     101                 :            : **************************************************************************/
     102                 :            : 
     103                 :          0 : bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
     104                 :            : {
     105                 :            : 
     106                 :            :     sal_uInt16 nSign, nCount;
     107                 :            :     sal_uInt32 nLen, nOff;
     108                 :            : 
     109         [ #  # ]:          0 :     Clear();
     110                 :            :     // Read Master-Record
     111 [ #  # ][ #  # ]:          0 :     r >> nSign >> nLen >> nCount;
                 [ #  # ]
     112                 :          0 :     sal_uIntPtr nLast = r.Tell() + nLen;
     113                 :            :     sal_uInt32 nCharSet;               // System charset
     114                 :            :     sal_uInt32 lDimBase;
     115                 :            :     sal_uInt16 nReserved1;
     116                 :            :     sal_uInt32 nReserved2;
     117                 :            :     sal_uInt32 nReserved3;
     118                 :          0 :     sal_Bool bBadVer = sal_False;
     119         [ #  # ]:          0 :     if( nSign == B_MODULE )
     120                 :            :     {
     121 [ #  # ][ #  # ]:          0 :         r >> nVersion >> nCharSet >> lDimBase
                 [ #  # ]
     122 [ #  # ][ #  # ]:          0 :           >> nFlags >> nReserved1 >> nReserved2 >> nReserved3;
         [ #  # ][ #  # ]
     123                 :          0 :         eCharSet = (CharSet) nCharSet;
     124         [ #  # ]:          0 :         eCharSet = GetSOLoadTextEncoding( eCharSet );
     125                 :          0 :         bBadVer  = sal_Bool( nVersion > B_CURVERSION );
     126                 :          0 :         nDimBase = (sal_uInt16) lDimBase;
     127                 :            :     }
     128                 :            : 
     129                 :          0 :     bool bLegacy = ( nVersion < B_EXT_IMG_VERSION );
     130                 :            : 
     131                 :            :     sal_uIntPtr nNext;
     132         [ #  # ]:          0 :     while( ( nNext = r.Tell() ) < nLast )
     133                 :            :     {
     134                 :            : 
     135 [ #  # ][ #  # ]:          0 :         r >> nSign >> nLen >> nCount;
                 [ #  # ]
     136                 :          0 :         nNext += nLen + 8;
     137         [ #  # ]:          0 :         if( r.GetError() == SVSTREAM_OK )
     138   [ #  #  #  #  :          0 :           switch( nSign )
             #  #  #  #  
                      # ]
     139                 :            :         {
     140                 :            :             case B_NAME:
     141 [ #  # ][ #  # ]:          0 :                 aName = r.ReadUniOrByteString(eCharSet);
     142                 :          0 :                 break;
     143                 :            :             case B_COMMENT:
     144 [ #  # ][ #  # ]:          0 :                 aComment = r.ReadUniOrByteString(eCharSet );
     145                 :          0 :                 break;
     146                 :            :             case B_SOURCE:
     147                 :            :             {
     148         [ #  # ]:          0 :                 aOUSource = r.ReadUniOrByteString(eCharSet);
     149                 :          0 :                 break;
     150                 :            :             }
     151                 :            :             case B_EXTSOURCE:
     152                 :            :             {
     153         [ #  # ]:          0 :                 for( sal_uInt16 j = 0 ; j < nCount ; j++ )
     154                 :            :                 {
     155 [ #  # ][ #  # ]:          0 :                     String aTmp = r.ReadUniOrByteString(eCharSet);
     156         [ #  # ]:          0 :                     aOUSource += aTmp;
     157         [ #  # ]:          0 :                 }
     158                 :          0 :                 break;
     159                 :            :             }
     160                 :            :             case B_PCODE:
     161         [ #  # ]:          0 :                 if( bBadVer ) break;
     162         [ #  # ]:          0 :                 pCode = new char[ nLen ];
     163                 :          0 :                 nCodeSize = nLen;
     164         [ #  # ]:          0 :                 r.Read( pCode, nCodeSize );
     165         [ #  # ]:          0 :                 if ( bLegacy )
     166                 :            :                 {
     167                 :          0 :                     ReleaseLegacyBuffer(); // release any previously held buffer
     168                 :          0 :                     nLegacyCodeSize = (sal_uInt16) nCodeSize;
     169                 :          0 :                     pLegacyPCode = pCode;
     170                 :            : 
     171         [ #  # ]:          0 :                     PCodeBuffConvertor< sal_uInt16, sal_uInt32 > aLegacyToNew( (sal_uInt8*)pLegacyPCode, nLegacyCodeSize );
     172         [ #  # ]:          0 :                     aLegacyToNew.convert();
     173                 :          0 :                     pCode = (char*)aLegacyToNew.GetBuffer();
     174                 :          0 :                     nCodeSize = aLegacyToNew.GetSize();
     175                 :            :                     // we don't release the legacy buffer
     176                 :            :                     // right now, thats because the module
     177                 :            :                     // needs it to fix up the method
     178                 :            :                     // nStart members. When that is done
     179                 :            :                     // the module can release the buffer
     180                 :            :                     // or it can wait until this routine
     181                 :            :                     // is called again or when this class                       // destructs all of which will trigger
     182                 :            :                     // release of the buffer.
     183                 :            :                 }
     184                 :          0 :                 break;
     185                 :            :             case B_PUBLICS:
     186                 :            :             case B_POOLDIR:
     187                 :            :             case B_SYMPOOL:
     188                 :            :             case B_LINERANGES:
     189                 :          0 :                 break;
     190                 :            :             case B_STRINGPOOL:
     191         [ #  # ]:          0 :                 if( bBadVer ) break;
     192         [ #  # ]:          0 :                 MakeStrings( nCount );
     193                 :            :                 short i;
     194 [ #  # ][ #  # ]:          0 :                 for( i = 0; i < nStrings && SbiGood( r ); i++ )
                 [ #  # ]
     195                 :            :                 {
     196         [ #  # ]:          0 :                     r >> nOff;
     197                 :          0 :                     pStringOff[ i ] = (sal_uInt16) nOff;
     198                 :            :                 }
     199         [ #  # ]:          0 :                 r >> nLen;
     200         [ #  # ]:          0 :                 if( SbiGood( r ) )
     201                 :            :                 {
     202         [ #  # ]:          0 :                     delete [] pStrings;
     203         [ #  # ]:          0 :                     pStrings = new sal_Unicode[ nLen ];
     204                 :          0 :                     nStringSize = (sal_uInt16) nLen;
     205                 :            : 
     206         [ #  # ]:          0 :                     char* pByteStrings = new char[ nLen ];
     207         [ #  # ]:          0 :                     r.Read( pByteStrings, nStringSize );
     208         [ #  # ]:          0 :                     for( short j = 0; j < nStrings; j++ )
     209                 :            :                     {
     210                 :          0 :                         sal_uInt16 nOff2 = (sal_uInt16) pStringOff[ j ];
     211         [ #  # ]:          0 :                         String aStr( pByteStrings + nOff2, eCharSet );
     212                 :          0 :                         memcpy( pStrings + nOff2, aStr.GetBuffer(), (aStr.Len() + 1) * sizeof( sal_Unicode ) );
     213         [ #  # ]:          0 :                     }
     214         [ #  # ]:          0 :                     delete[] pByteStrings;
     215                 :          0 :                 } break;
     216                 :            :             case B_MODEND:
     217                 :          0 :                 goto done;
     218                 :            :             default:
     219                 :          0 :                 break;
     220                 :            :         }
     221                 :            :         else
     222                 :          0 :             break;
     223         [ #  # ]:          0 :         r.Seek( nNext );
     224                 :            :     }
     225                 :            : done:
     226         [ #  # ]:          0 :     r.Seek( nLast );
     227         [ #  # ]:          0 :     if( !SbiGood( r ) )
     228                 :          0 :         bError = true;
     229                 :          0 :     return !bError;
     230                 :            : }
     231                 :            : 
     232                 :          0 : bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
     233                 :            : {
     234                 :          0 :     bool bLegacy = ( nVer < B_EXT_IMG_VERSION );
     235                 :            : 
     236                 :            :     // detect if old code exceeds legacy limits
     237                 :            :     // if so, then disallow save
     238 [ #  # ][ #  # ]:          0 :     if ( bLegacy && ExceedsLegacyLimits() )
                 [ #  # ]
     239                 :            :     {
     240         [ #  # ]:          0 :         SbiImage aEmptyImg;
     241         [ #  # ]:          0 :         aEmptyImg.aName = aName;
     242         [ #  # ]:          0 :         aEmptyImg.Save( r, B_LEGACYVERSION );
     243         [ #  # ]:          0 :         return true;
     244                 :            :     }
     245                 :            :     // First of all the header
     246                 :          0 :     sal_uIntPtr nStart = SbiOpenRecord( r, B_MODULE, 1 );
     247                 :            :     sal_uIntPtr nPos;
     248                 :            : 
     249                 :          0 :     eCharSet = GetSOStoreTextEncoding( eCharSet );
     250         [ #  # ]:          0 :     if ( bLegacy )
     251                 :          0 :         r << (sal_Int32) B_LEGACYVERSION;
     252                 :            :     else
     253                 :          0 :         r << (sal_Int32) B_CURVERSION;
     254                 :          0 :     r  << (sal_Int32) eCharSet
     255                 :          0 :       << (sal_Int32) nDimBase
     256                 :          0 :       << (sal_Int16) nFlags
     257                 :          0 :       << (sal_Int16) 0
     258                 :          0 :       << (sal_Int32) 0
     259                 :          0 :       << (sal_Int32) 0;
     260                 :            : 
     261                 :            :     // Name?
     262 [ #  # ][ #  # ]:          0 :     if( aName.Len() && SbiGood( r ) )
                 [ #  # ]
     263                 :            :     {
     264                 :          0 :         nPos = SbiOpenRecord( r, B_NAME, 1 );
     265         [ #  # ]:          0 :         r.WriteUniOrByteString( aName, eCharSet );
     266                 :          0 :         SbiCloseRecord( r, nPos );
     267                 :            :     }
     268                 :            :     // Comment?
     269 [ #  # ][ #  # ]:          0 :     if( aComment.Len() && SbiGood( r ) )
                 [ #  # ]
     270                 :            :     {
     271                 :          0 :         nPos = SbiOpenRecord( r, B_COMMENT, 1 );
     272         [ #  # ]:          0 :         r.WriteUniOrByteString( aComment, eCharSet );
     273                 :          0 :         SbiCloseRecord( r, nPos );
     274                 :            :     }
     275                 :            :     // Source?
     276 [ #  # ][ #  # ]:          0 :     if( !aOUSource.isEmpty() && SbiGood( r ) )
                 [ #  # ]
     277                 :            :     {
     278         [ #  # ]:          0 :         nPos = SbiOpenRecord( r, B_SOURCE, 1 );
     279         [ #  # ]:          0 :         String aTmp;
     280                 :          0 :         sal_Int32 nLen = aOUSource.getLength();
     281                 :          0 :         const sal_Int32 nMaxUnitSize = STRING_MAXLEN - 1;
     282         [ #  # ]:          0 :         if( nLen > STRING_MAXLEN )
     283         [ #  # ]:          0 :             aTmp = aOUSource.copy( 0, nMaxUnitSize );
     284                 :            :         else
     285         [ #  # ]:          0 :             aTmp = aOUSource;
     286 [ #  # ][ #  # ]:          0 :         r.WriteUniOrByteString( aTmp, eCharSet );
     287         [ #  # ]:          0 :         SbiCloseRecord( r, nPos );
     288                 :            : 
     289         [ #  # ]:          0 :         if( nLen > STRING_MAXLEN )
     290                 :            :         {
     291                 :          0 :             sal_Int32 nRemainingLen = nLen - nMaxUnitSize;
     292                 :          0 :             sal_uInt16 nUnitCount = sal_uInt16( (nRemainingLen + nMaxUnitSize - 1) / nMaxUnitSize );
     293         [ #  # ]:          0 :             nPos = SbiOpenRecord( r, B_EXTSOURCE, nUnitCount );
     294         [ #  # ]:          0 :             for( sal_uInt16 i = 0 ; i < nUnitCount ; i++ )
     295                 :            :             {
     296                 :            :                 sal_Int32 nCopyLen =
     297                 :          0 :                     (nRemainingLen > nMaxUnitSize) ? nMaxUnitSize : nRemainingLen;
     298         [ #  # ]:          0 :                 String aTmp2 = aOUSource.copy( (i+1) * nMaxUnitSize, nCopyLen );
     299                 :          0 :                 nRemainingLen -= nCopyLen;
     300 [ #  # ][ #  # ]:          0 :                 r.WriteUniOrByteString( aTmp2, eCharSet );
     301         [ #  # ]:          0 :             }
     302         [ #  # ]:          0 :             SbiCloseRecord( r, nPos );
     303         [ #  # ]:          0 :         }
     304                 :            :     }
     305                 :            :     // Binary data?
     306 [ #  # ][ #  # ]:          0 :     if( pCode && SbiGood( r ) )
                 [ #  # ]
     307                 :            :     {
     308                 :          0 :         nPos = SbiOpenRecord( r, B_PCODE, 1 );
     309         [ #  # ]:          0 :         if ( bLegacy )
     310                 :            :         {
     311                 :          0 :             ReleaseLegacyBuffer(); // release any previously held buffer
     312         [ #  # ]:          0 :             PCodeBuffConvertor< sal_uInt32, sal_uInt16 > aNewToLegacy( (sal_uInt8*)pCode, nCodeSize );
     313         [ #  # ]:          0 :             aNewToLegacy.convert();
     314                 :          0 :             pLegacyPCode = (char*)aNewToLegacy.GetBuffer();
     315                 :          0 :             nLegacyCodeSize = aNewToLegacy.GetSize();
     316         [ #  # ]:          0 :                 r.Write( pLegacyPCode, nLegacyCodeSize );
     317                 :            :         }
     318                 :            :         else
     319                 :          0 :             r.Write( pCode, nCodeSize );
     320                 :          0 :         SbiCloseRecord( r, nPos );
     321                 :            :     }
     322                 :            :     // String-Pool?
     323         [ #  # ]:          0 :     if( nStrings )
     324                 :            :     {
     325                 :          0 :         nPos = SbiOpenRecord( r, B_STRINGPOOL, nStrings );
     326                 :            :         // For every String:
     327                 :            :         //  sal_uInt32 Offset of the Strings in the Stringblock
     328                 :            :         short i;
     329                 :            : 
     330 [ #  # ][ #  # ]:          0 :         for( i = 0; i < nStrings && SbiGood( r ); i++ )
                 [ #  # ]
     331                 :          0 :             r << (sal_uInt32) pStringOff[ i ];
     332                 :            : 
     333                 :            :         // Then the String-Block
     334                 :          0 :         char* pByteStrings = new char[ nStringSize ];
     335         [ #  # ]:          0 :         for( i = 0; i < nStrings; i++ )
     336                 :            :         {
     337                 :          0 :             sal_uInt16 nOff = (sal_uInt16) pStringOff[ i ];
     338         [ #  # ]:          0 :             rtl::OString aStr(rtl::OUStringToOString(rtl::OUString(pStrings + nOff), eCharSet));
     339                 :          0 :             memcpy( pByteStrings + nOff, aStr.getStr(), (aStr.getLength() + 1) * sizeof( char ) );
     340                 :          0 :         }
     341                 :          0 :         r << (sal_uInt32) nStringSize;
     342                 :          0 :         r.Write( pByteStrings, nStringSize );
     343                 :            : 
     344         [ #  # ]:          0 :         delete[] pByteStrings;
     345                 :          0 :         SbiCloseRecord( r, nPos );
     346                 :            :     }
     347                 :            :     // Set overall length
     348                 :          0 :     SbiCloseRecord( r, nStart );
     349         [ #  # ]:          0 :     if( !SbiGood( r ) )
     350                 :          0 :         bError = true;
     351                 :          0 :     return !bError;
     352                 :            : }
     353                 :            : 
     354                 :            : /**************************************************************************
     355                 :            : *
     356                 :            : *    Routines called by the compiler
     357                 :            : *
     358                 :            : **************************************************************************/
     359                 :            : 
     360                 :         65 : void SbiImage::MakeStrings( short nSize )
     361                 :            : {
     362                 :         65 :     nStrings = 0;
     363                 :         65 :     nStringIdx = 0;
     364                 :         65 :     nStringOff = 0;
     365                 :         65 :     nStringSize = 1024;
     366                 :         65 :     pStrings = new sal_Unicode[ nStringSize ];
     367                 :         65 :     pStringOff = new sal_uInt32[ nSize ];
     368 [ +  - ][ +  - ]:         65 :     if( pStrings && pStringOff )
     369                 :            :     {
     370                 :         65 :         nStrings = nSize;
     371                 :         65 :         memset( pStringOff, 0, nSize * sizeof( sal_uInt32 ) );
     372                 :         65 :         memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
     373                 :            :     }
     374                 :            :     else
     375                 :          0 :         bError = true;
     376                 :         65 : }
     377                 :            : 
     378                 :            : // Add a string to StringPool. The String buffer is dynamically
     379                 :            : // growing in 1K-Steps
     380                 :       2655 : void SbiImage::AddString( const String& r )
     381                 :            : {
     382         [ -  + ]:       2655 :     if( nStringIdx >= nStrings )
     383                 :          0 :         bError = true;
     384         [ +  - ]:       2655 :     if( !bError )
     385                 :            :     {
     386                 :       2655 :         xub_StrLen  len = r.Len() + 1;
     387                 :       2655 :         sal_uInt32 needed = nStringOff + len;
     388         [ -  + ]:       2655 :         if( needed > 0xFFFFFF00L )
     389                 :          0 :             bError = true;  // out of mem!
     390         [ +  + ]:       2655 :         else if( needed > nStringSize )
     391                 :            :         {
     392                 :         24 :             sal_uInt32 nNewLen = needed + 1024;
     393                 :         24 :             nNewLen &= 0xFFFFFC00;  // trim to 1K border
     394         [ -  + ]:         24 :             if( nNewLen > 0xFFFFFF00L )
     395                 :          0 :                 nNewLen = 0xFFFFFF00L;
     396                 :         24 :             sal_Unicode* p = NULL;
     397         [ +  - ]:         24 :             if( (p = new sal_Unicode[ nNewLen ]) != NULL )
     398                 :            :             {
     399                 :         24 :                 memcpy( p, pStrings, nStringSize * sizeof( sal_Unicode ) );
     400         [ +  - ]:         24 :                 delete[] pStrings;
     401                 :         24 :                 pStrings = p;
     402                 :         24 :                 nStringSize = sal::static_int_cast< sal_uInt16 >(nNewLen);
     403                 :            :             }
     404                 :            :             else
     405                 :          0 :                 bError = true;
     406                 :            :         }
     407         [ +  - ]:       2655 :         if( !bError )
     408                 :            :         {
     409                 :       2655 :             pStringOff[ nStringIdx++ ] = nStringOff;
     410                 :       2655 :             memcpy( pStrings + nStringOff, r.GetBuffer(), len * sizeof( sal_Unicode ) );
     411                 :       2655 :             nStringOff = nStringOff + len;
     412                 :            :             // Last String? The update the size of the buffer
     413         [ +  + ]:       2655 :             if( nStringIdx >= nStrings )
     414                 :         65 :                 nStringSize = nStringOff;
     415                 :            :         }
     416                 :            :     }
     417                 :       2655 : }
     418                 :            : 
     419                 :            : // Add code block
     420                 :            : // The block was fetched by the compiler from class SbBuffer and
     421                 :            : // is already created with new. Additionally it contains all Integers
     422                 :            : // in Big Endian format, so can be directly read/written.
     423                 :         65 : void SbiImage::AddCode( char* p, sal_uInt32 s )
     424                 :            : {
     425                 :         65 :     pCode = p;
     426                 :         65 :     nCodeSize = s;
     427                 :         65 : }
     428                 :            : 
     429                 :            : // Add user type
     430                 :          0 : void SbiImage::AddType(SbxObject* pObject)
     431                 :            : {
     432         [ #  # ]:          0 :     if( !rTypes.Is() )
     433         [ #  # ]:          0 :         rTypes = new SbxArray;
     434         [ #  # ]:          0 :     SbxObject *pCopyObject = new SbxObject(*pObject);
     435                 :          0 :     rTypes->Insert (pCopyObject,rTypes->Count());
     436                 :          0 : }
     437                 :            : 
     438                 :          0 : void SbiImage::AddEnum(SbxObject* pObject) // Register enum type
     439                 :            : {
     440         [ #  # ]:          0 :     if( !rEnums.Is() )
     441         [ #  # ]:          0 :         rEnums = new SbxArray;
     442                 :          0 :     rEnums->Insert( pObject, rEnums->Count() );
     443                 :          0 : }
     444                 :            : 
     445                 :            : 
     446                 :            : /**************************************************************************
     447                 :            : *
     448                 :            : *    Accessing the image
     449                 :            : *
     450                 :            : **************************************************************************/
     451                 :            : 
     452                 :            : // Note: IDs start with 1
     453                 :      15258 : String SbiImage::GetString( short nId ) const
     454                 :            : {
     455 [ +  - ][ +  - ]:      15258 :     if( nId && nId <= nStrings )
     456                 :            :     {
     457                 :      15258 :         sal_uInt32 nOff = pStringOff[ nId - 1 ];
     458                 :      15258 :         sal_Unicode* pStr = pStrings + nOff;
     459                 :            : 
     460                 :            :         // #i42467: Special treatment for vbNullChar
     461         [ +  + ]:      15258 :         if( *pStr == 0 )
     462                 :            :         {
     463         [ +  - ]:        286 :             sal_uInt32 nNextOff = (nId < nStrings) ? pStringOff[ nId ] : nStringOff;
     464                 :        286 :             sal_uInt32 nLen = nNextOff - nOff - 1;
     465         [ -  + ]:        286 :             if( nLen == 1 )
     466                 :            :             {
     467                 :            :                 // Force length 1 and make char 0 afterwards
     468         [ #  # ]:          0 :                 String aNullCharStr( rtl::OUString(" ") );
     469         [ #  # ]:          0 :                 aNullCharStr.SetChar( 0, 0 );
     470 [ #  # ][ #  # ]:          0 :                 return aNullCharStr;
     471                 :            :             }
     472                 :            :         }
     473                 :            :         else
     474         [ +  - ]:      14972 :             return rtl::OUString(pStr);
     475                 :            :     }
     476         [ +  - ]:      15258 :     return rtl::OUString();
     477                 :            : }
     478                 :            : 
     479                 :         24 : const SbxObject* SbiImage::FindType (String aTypeName) const
     480                 :            : {
     481 [ -  + ][ #  # ]:         24 :     return rTypes.Is() ? (SbxObject*)rTypes->Find(aTypeName,SbxCLASS_OBJECT) : NULL;
         [ #  # ][ -  + ]
                 [ #  # ]
     482                 :            : }
     483                 :            : 
     484                 :          0 : sal_uInt16 SbiImage::CalcLegacyOffset( sal_Int32 nOffset )
     485                 :            : {
     486                 :          0 :     return SbiCodeGen::calcLegacyOffSet( (sal_uInt8*)pCode, nOffset ) ;
     487                 :            : }
     488                 :            : 
     489                 :          0 : sal_uInt32 SbiImage::CalcNewOffset( sal_Int16 nOffset )
     490                 :            : {
     491                 :          0 :     return SbiCodeGen::calcNewOffSet( (sal_uInt8*)pLegacyPCode, nOffset ) ;
     492                 :            : }
     493                 :            : 
     494                 :         63 : void  SbiImage::ReleaseLegacyBuffer()
     495                 :            : {
     496         [ -  + ]:         63 :     delete[] pLegacyPCode;
     497                 :         63 :     pLegacyPCode = NULL;
     498                 :         63 :     nLegacyCodeSize = 0;
     499                 :         63 : }
     500                 :            : 
     501                 :          0 : bool SbiImage::ExceedsLegacyLimits()
     502                 :            : {
     503 [ #  # ][ #  # ]:          0 :     return ( nStringSize > 0xFF00L ) || ( CalcLegacyOffset( nCodeSize ) > 0xFF00L );
     504                 :            : }
     505                 :            : 
     506                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10