LCOV - code coverage report
Current view: top level - sc/source/filter/ftools - ftools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 151 44.4 %
Date: 2012-08-25 Functions: 17 30 56.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 51 174 29.3 %

           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 "ftools.hxx"
      30                 :            : #include <rtl/strbuf.hxx>
      31                 :            : #include <tools/color.hxx>
      32                 :            : #include <unotools/charclass.hxx>
      33                 :            : #include <svl/itempool.hxx>
      34                 :            : #include <svl/itemset.hxx>
      35                 :            : #include <svl/poolitem.hxx>
      36                 :            : #include <sot/storage.hxx>
      37                 :            : 
      38                 :            : #include <math.h>
      39                 :            : #include "global.hxx"
      40                 :            : #include "document.hxx"
      41                 :            : #include "stlpool.hxx"
      42                 :            : #include "stlsheet.hxx"
      43                 :            : #include "compiler.hxx"
      44                 :            : 
      45                 :            : #include <stdio.h>
      46                 :            : 
      47                 :            : // ============================================================================
      48                 :            : // ScFilterTools::ReadLongDouble()
      49                 :            : 
      50                 :            : #ifdef _MSC_VER
      51                 :            : #if _MSC_VER <= 800
      52                 :            : #undef __SIMPLE_FUNC
      53                 :            : #define __SIMPLE_FUNC
      54                 :            : #endif
      55                 :            : #endif
      56                 :            : 
      57                 :          0 : double ScfTools::ReadLongDouble( SvStream& rStrm )
      58                 :            : 
      59                 :            : #ifdef __SIMPLE_FUNC                // for <=VC 1.5
      60                 :            : {
      61                 :            :     long double fRet;
      62                 :            :     rStrm.Read( &fRet, 10 );
      63                 :            :     return static_cast< double >( fRet );
      64                 :            : }
      65                 :            : #undef __SIMPLE_FUNC
      66                 :            : 
      67                 :            : #else                               // detailed for all others
      68                 :            : {
      69                 :            : 
      70                 :            : /*
      71                 :            : " M a p p i n g - G u i d e " 10-Byte Intel
      72                 :            : 
      73                 :            : 77777777 77666666 66665555 55555544 44444444 33333333 33222222 22221111 11111100 00000000   x10
      74                 :            : 98765432 10987654 32109876 54321098 76543210 98765432 10987654 32109876 54321098 76543210   Bit-# total
      75                 :            : 9      9 8      8 7      7 6      6 5      5 4      4 3      3 2      2 1      1 0      0   Byte-#
      76                 :            : 76543210 76543210 76543210 76543210 76543210 76543210 76543210 76543210 76543210 76543210   Bit-# in Byte
      77                 :            : SEEEEEEE EEEEEEEE IMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM   Group
      78                 :            : 01111110 00000000 06665555 55555544 44444444 33333333 33222222 22221111 11111100 00000000       x10
      79                 :            : 14321098 76543210 02109876 54321098 76543210 98765432 10987654 32109876 54321098 76543210   Bit in Group
      80                 :            : */
      81                 :            : 
      82                 :          0 :     register long double lfDouble = 0.0;
      83                 :          0 :     register long double lfFakt = 256.0;
      84                 :            :     sal_uInt8 pDouble10[ 10 ];
      85                 :            : 
      86         [ #  # ]:          0 :     rStrm.Read( pDouble10, 10 );            // Intel-10 in pDouble10
      87                 :            : 
      88                 :          0 :     lfDouble  = static_cast< long double >( pDouble10[ 7 ] );   // Byte 7
      89                 :          0 :     lfDouble *= lfFakt;
      90                 :          0 :     lfDouble += static_cast< long double >( pDouble10[ 6 ] );   // Byte 6
      91                 :          0 :     lfDouble *= lfFakt;
      92                 :          0 :     lfDouble += static_cast< long double >( pDouble10[ 5 ] );   // Byte 5
      93                 :          0 :     lfDouble *= lfFakt;
      94                 :          0 :     lfDouble += static_cast< long double >( pDouble10[ 4 ] );   // Byte 4
      95                 :          0 :     lfDouble *= lfFakt;
      96                 :          0 :     lfDouble += static_cast< long double >( pDouble10[ 3 ] );   // Byte 3
      97                 :          0 :     lfDouble *= lfFakt;
      98                 :          0 :     lfDouble += static_cast< long double >( pDouble10[ 2 ] );   // Byte 2
      99                 :          0 :     lfDouble *= lfFakt;
     100                 :          0 :     lfDouble += static_cast< long double >( pDouble10[ 1 ] );   // Byte 1
     101                 :          0 :     lfDouble *= lfFakt;
     102                 :          0 :     lfDouble += static_cast< long double >( pDouble10[ 0 ] );   // Byte 0
     103                 :            : 
     104                 :            :     //  For value 0.0 all bits are zero; pow(2.0,-16446) does not work with CSet compilers
     105         [ #  # ]:          0 :     if( lfDouble != 0.0 )
     106                 :            :     {
     107                 :            :         // exponent
     108                 :            :         register sal_Int32 nExp;
     109                 :          0 :         nExp = pDouble10[ 9 ] & 0x7F;
     110                 :          0 :         nExp <<= 8;
     111                 :          0 :         nExp += pDouble10[ 8 ];
     112                 :          0 :         nExp -= 16446;
     113                 :            : 
     114                 :          0 :         lfDouble *= pow( 2.0, static_cast< double >( nExp ) );
     115                 :            :     }
     116                 :            : 
     117                 :            :     // sign
     118         [ #  # ]:          0 :     if( pDouble10[ 9 ] & 0x80 )
     119                 :          0 :         lfDouble *= static_cast< long double >( -1.0 );
     120                 :            : 
     121                 :          0 :     return static_cast< double >( lfDouble );
     122                 :            : }
     123                 :            : #endif
     124                 :            : 
     125                 :            : // *** common methods *** -----------------------------------------------------
     126                 :            : 
     127                 :        345 : rtl_TextEncoding ScfTools::GetSystemTextEncoding()
     128                 :            : {
     129                 :        345 :     return osl_getThreadTextEncoding();
     130                 :            : }
     131                 :            : 
     132                 :          3 : String ScfTools::GetHexStr( sal_uInt16 nValue )
     133                 :            : {
     134                 :          3 :     const sal_Char pHex[] = "0123456789ABCDEF";
     135         [ +  - ]:          3 :     String aStr;
     136                 :            : 
     137         [ +  - ]:          3 :     aStr += pHex[ nValue >> 12 ];
     138         [ +  - ]:          3 :     aStr += pHex[ (nValue >> 8) & 0x000F ];
     139         [ +  - ]:          3 :     aStr += pHex[ (nValue >> 4) & 0x000F ];
     140         [ +  - ]:          3 :     aStr += pHex[ nValue & 0x000F ];
     141                 :          3 :     return aStr;
     142                 :            : }
     143                 :            : 
     144                 :        903 : sal_uInt8 ScfTools::GetMixedColorComp( sal_uInt8 nFore, sal_uInt8 nBack, sal_uInt8 nTrans )
     145                 :            : {
     146                 :        903 :     sal_Int32 nTemp = ((static_cast< sal_Int32 >( nBack ) - nFore) * nTrans) / 0x80 + nFore;
     147                 :        903 :     return static_cast< sal_uInt8 >( nTemp );
     148                 :            : }
     149                 :            : 
     150                 :        301 : Color ScfTools::GetMixedColor( const Color& rFore, const Color& rBack, sal_uInt8 nTrans )
     151                 :            : {
     152                 :            :     return Color(
     153                 :        301 :         GetMixedColorComp( rFore.GetRed(), rBack.GetRed(), nTrans ),
     154                 :        301 :         GetMixedColorComp( rFore.GetGreen(), rBack.GetGreen(), nTrans ),
     155                 :        602 :         GetMixedColorComp( rFore.GetBlue(), rBack.GetBlue(), nTrans ) );
     156                 :            : }
     157                 :            : 
     158                 :            : // *** conversion of names *** ------------------------------------------------
     159                 :            : 
     160                 :            : /* XXX As in sc/source/core/tool/rangenam.cxx ScRangeData::IsValidName() */
     161                 :            : 
     162                 :         48 : void ScfTools::ConvertToScDefinedName( String& rName )
     163                 :            : {
     164                 :            :     //fdo#37872: we don't allow points in range names any more
     165                 :            :     rName.SearchAndReplaceAll(static_cast<sal_Unicode>('.'),
     166                 :         48 :         static_cast<sal_Unicode>('_'));
     167                 :         48 :     xub_StrLen nLen = rName.Len();
     168 [ -  + ][ -  + ]:         48 :     if( nLen && !ScCompiler::IsCharFlagAllConventions( rName, 0, SC_COMPILER_C_CHAR_NAME ) )
                 [ +  - ]
     169                 :          0 :         rName.SetChar( 0, '_' );
     170         [ +  + ]:        468 :     for( xub_StrLen nPos = 1; nPos < nLen; ++nPos )
     171         [ -  + ]:        420 :         if( !ScCompiler::IsCharFlagAllConventions( rName, nPos, SC_COMPILER_C_NAME ) )
     172                 :          0 :             rName.SetChar( nPos, '_' );
     173                 :         48 : }
     174                 :            : 
     175                 :            : // *** streams and storages *** -----------------------------------------------
     176                 :            : 
     177                 :          3 : SotStorageRef ScfTools::OpenStorageRead( SotStorageRef xStrg, const String& rStrgName )
     178                 :            : {
     179                 :          3 :     SotStorageRef xSubStrg;
     180 [ +  - ][ +  - ]:          3 :     if( xStrg.Is() && xStrg->IsContained( rStrgName ) )
         [ +  - ][ +  - ]
     181 [ +  - ][ +  - ]:          3 :         xSubStrg = xStrg->OpenSotStorage( rStrgName, STREAM_STD_READ );
     182                 :          3 :     return xSubStrg;
     183                 :            : }
     184                 :            : 
     185                 :          0 : SotStorageRef ScfTools::OpenStorageWrite( SotStorageRef xStrg, const String& rStrgName )
     186                 :            : {
     187                 :          0 :     SotStorageRef xSubStrg;
     188         [ #  # ]:          0 :     if( xStrg.Is() )
     189 [ #  # ][ #  # ]:          0 :         xSubStrg = xStrg->OpenSotStorage( rStrgName, STREAM_STD_WRITE );
     190                 :          0 :     return xSubStrg;
     191                 :            : }
     192                 :            : 
     193                 :        185 : SotStorageStreamRef ScfTools::OpenStorageStreamRead( SotStorageRef xStrg, const String& rStrmName )
     194                 :            : {
     195                 :        185 :     SotStorageStreamRef xStrm;
     196 [ +  - ][ +  + ]:        185 :     if( xStrg.Is() && xStrg->IsContained( rStrmName ) && xStrg->IsStream( rStrmName ) )
         [ +  - ][ +  - ]
         [ +  + ][ +  - ]
     197 [ +  - ][ +  - ]:         63 :         xStrm = xStrg->OpenSotStream( rStrmName, STREAM_STD_READ );
     198                 :        185 :     return xStrm;
     199                 :            : }
     200                 :            : 
     201                 :          0 : SotStorageStreamRef ScfTools::OpenStorageStreamWrite( SotStorageRef xStrg, const String& rStrmName )
     202                 :            : {
     203                 :            :     OSL_ENSURE( !xStrg || !xStrg->IsContained( rStrmName ), "ScfTools::OpenStorageStreamWrite - stream exists already" );
     204                 :          0 :     SotStorageStreamRef xStrm;
     205         [ #  # ]:          0 :     if( xStrg.Is() )
     206 [ #  # ][ #  # ]:          0 :         xStrm = xStrg->OpenSotStream( rStrmName, STREAM_STD_WRITE | STREAM_TRUNC );
     207                 :          0 :     return xStrm;
     208                 :            : }
     209                 :            : 
     210                 :            : // *** item handling *** ------------------------------------------------------
     211                 :            : 
     212                 :          0 : bool ScfTools::CheckItem( const SfxItemSet& rItemSet, sal_uInt16 nWhichId, bool bDeep )
     213                 :            : {
     214                 :          0 :     return rItemSet.GetItemState( nWhichId, bDeep ) == SFX_ITEM_SET;
     215                 :            : }
     216                 :            : 
     217                 :          0 : bool ScfTools::CheckItems( const SfxItemSet& rItemSet, const sal_uInt16* pnWhichIds, bool bDeep )
     218                 :            : {
     219                 :            :     OSL_ENSURE( pnWhichIds, "ScfTools::CheckItems - no which id list" );
     220         [ #  # ]:          0 :     for( const sal_uInt16* pnWhichId = pnWhichIds; *pnWhichId != 0; ++pnWhichId )
     221         [ #  # ]:          0 :         if( CheckItem( rItemSet, *pnWhichId, bDeep ) )
     222                 :          0 :             return true;
     223                 :          0 :     return false;
     224                 :            : }
     225                 :            : 
     226                 :      25843 : void ScfTools::PutItem( SfxItemSet& rItemSet, const SfxPoolItem& rItem, sal_uInt16 nWhichId, bool bSkipPoolDef )
     227                 :            : {
     228 [ +  + ][ +  + ]:      25843 :     if( !bSkipPoolDef || (rItem != rItemSet.GetPool()->GetDefaultItem( nWhichId )) )
                 [ +  + ]
     229                 :      23192 :         rItemSet.Put( rItem, nWhichId );
     230                 :      25843 : }
     231                 :            : 
     232                 :       8019 : void ScfTools::PutItem( SfxItemSet& rItemSet, const SfxPoolItem& rItem, bool bSkipPoolDef )
     233                 :            : {
     234                 :       8019 :     PutItem( rItemSet, rItem, rItem.Which(), bSkipPoolDef );
     235                 :       8019 : }
     236                 :            : 
     237                 :            : // *** style sheet handling *** -----------------------------------------------
     238                 :            : 
     239                 :            : namespace {
     240                 :            : 
     241                 :        165 : ScStyleSheet& lclMakeStyleSheet( ScStyleSheetPool& rPool, const String& rStyleName, SfxStyleFamily eFamily, bool bForceName )
     242                 :            : {
     243                 :            :     // find an unused name
     244         [ +  - ]:        165 :     String aNewName( rStyleName );
     245                 :        165 :     sal_Int32 nIndex = 0;
     246                 :        165 :     SfxStyleSheetBase* pOldStyleSheet = 0;
     247 [ +  - ][ +  - ]:        165 :     while( SfxStyleSheetBase* pStyleSheet = rPool.Find( aNewName, eFamily ) )
     248                 :            :     {
     249         [ #  # ]:          0 :         if( !pOldStyleSheet )
     250                 :          0 :             pOldStyleSheet = pStyleSheet;
     251 [ #  # ][ #  # ]:          0 :         aNewName.Assign( rStyleName ).Append( ' ' ).Append( String::CreateFromInt32( ++nIndex ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     252                 :            :     }
     253                 :            : 
     254                 :            :     // rename existing style
     255 [ -  + ][ #  # ]:        165 :     if( pOldStyleSheet && bForceName )
     256                 :            :     {
     257         [ #  # ]:          0 :         pOldStyleSheet->SetName( aNewName );
     258         [ #  # ]:          0 :         aNewName = rStyleName;
     259                 :            :     }
     260                 :            : 
     261                 :            :     // create new style sheet
     262 [ +  - ][ +  - ]:        165 :     return static_cast< ScStyleSheet& >( rPool.Make( aNewName, eFamily, SFXSTYLEBIT_USERDEF ) );
     263                 :            : }
     264                 :            : 
     265                 :            : } // namespace
     266                 :            : 
     267                 :          0 : ScStyleSheet& ScfTools::MakeCellStyleSheet( ScStyleSheetPool& rPool, const String& rStyleName, bool bForceName )
     268                 :            : {
     269                 :          0 :     return lclMakeStyleSheet( rPool, rStyleName, SFX_STYLE_FAMILY_PARA, bForceName );
     270                 :            : }
     271                 :            : 
     272                 :        165 : ScStyleSheet& ScfTools::MakePageStyleSheet( ScStyleSheetPool& rPool, const String& rStyleName, bool bForceName )
     273                 :            : {
     274                 :        165 :     return lclMakeStyleSheet( rPool, rStyleName, SFX_STYLE_FAMILY_PAGE, bForceName );
     275                 :            : }
     276                 :            : 
     277                 :            : // *** byte string import operations *** --------------------------------------
     278                 :            : 
     279                 :          0 : rtl::OString ScfTools::read_zeroTerminated_uInt8s_ToOString(SvStream& rStrm, sal_Int32& rnBytesLeft)
     280                 :            : {
     281                 :          0 :     rtl::OString aRet(::read_zeroTerminated_uInt8s_ToOString(rStrm));
     282                 :          0 :     rnBytesLeft -= aRet.getLength(); //we read this number of bytes anyway
     283         [ #  # ]:          0 :     if (rStrm.good()) //if the stream is happy we read the null terminator as well
     284                 :          0 :         --rnBytesLeft;
     285                 :          0 :     return aRet;
     286                 :            : }
     287                 :            : 
     288                 :          0 : void ScfTools::AppendCString( SvStream& rStrm, String& rString, rtl_TextEncoding eTextEnc )
     289                 :            : {
     290         [ #  # ]:          0 :     rString += ::read_zeroTerminated_uInt8s_ToOUString(rStrm, eTextEnc);
     291                 :          0 : }
     292                 :            : 
     293                 :            : // *** HTML table names <-> named range names *** -----------------------------
     294                 :            : 
     295                 :          3 : const String& ScfTools::GetHTMLDocName()
     296                 :            : {
     297 [ +  - ][ +  - ]:          3 :     static const String saHTMLDoc( RTL_CONSTASCII_USTRINGPARAM( "HTML_all" ) );
         [ +  - ][ #  # ]
     298                 :          3 :     return saHTMLDoc;
     299                 :            : }
     300                 :            : 
     301                 :          3 : const String& ScfTools::GetHTMLTablesName()
     302                 :            : {
     303 [ +  - ][ +  - ]:          3 :     static const String saHTMLTables( RTL_CONSTASCII_USTRINGPARAM( "HTML_tables" ) );
         [ +  - ][ #  # ]
     304                 :          3 :     return saHTMLTables;
     305                 :            : }
     306                 :            : 
     307                 :          3 : const String& ScfTools::GetHTMLIndexPrefix()
     308                 :            : {
     309 [ +  - ][ +  - ]:          3 :     static const String saHTMLIndexPrefix( RTL_CONSTASCII_USTRINGPARAM( "HTML_" ) );
         [ +  - ][ #  # ]
     310                 :          3 :     return saHTMLIndexPrefix;
     311                 :            : 
     312                 :            : }
     313                 :            : 
     314                 :          0 : const String& ScfTools::GetHTMLNamePrefix()
     315                 :            : {
     316 [ #  # ][ #  # ]:          0 :     static const String saHTMLNamePrefix( RTL_CONSTASCII_USTRINGPARAM( "HTML__" ) );
         [ #  # ][ #  # ]
     317                 :          0 :     return saHTMLNamePrefix;
     318                 :            : }
     319                 :            : 
     320                 :          3 : String ScfTools::GetNameFromHTMLIndex( sal_uInt32 nIndex )
     321                 :            : {
     322                 :          3 :     String aName( GetHTMLIndexPrefix() );
     323 [ +  - ][ +  - ]:          3 :     aName += String::CreateFromInt32( static_cast< sal_Int32 >( nIndex ) );
                 [ +  - ]
     324                 :          3 :     return aName;
     325                 :            : }
     326                 :            : 
     327                 :          0 : String ScfTools::GetNameFromHTMLName( const String& rTabName )
     328                 :            : {
     329                 :          0 :     String aName( GetHTMLNamePrefix() );
     330         [ #  # ]:          0 :     aName += rTabName;
     331                 :          0 :     return aName;
     332                 :            : }
     333                 :            : 
     334                 :          0 : bool ScfTools::IsHTMLDocName( const String& rSource )
     335                 :            : {
     336                 :          0 :     return rSource.EqualsIgnoreCaseAscii( GetHTMLDocName() );
     337                 :            : }
     338                 :            : 
     339                 :          0 : bool ScfTools::IsHTMLTablesName( const String& rSource )
     340                 :            : {
     341                 :          0 :     return rSource.EqualsIgnoreCaseAscii( GetHTMLTablesName() );
     342                 :            : }
     343                 :            : 
     344                 :          0 : bool ScfTools::GetHTMLNameFromName( const String& rSource, String& rName )
     345                 :            : {
     346                 :          0 :     rName.Erase();
     347         [ #  # ]:          0 :     if( rSource.EqualsIgnoreCaseAscii( GetHTMLNamePrefix(), 0, GetHTMLNamePrefix().Len() ) )
     348                 :            :     {
     349         [ #  # ]:          0 :         rName = rSource.Copy( GetHTMLNamePrefix().Len() );
     350                 :          0 :         ScGlobal::AddQuotes( rName, '"', false );
     351                 :            :     }
     352         [ #  # ]:          0 :     else if( rSource.EqualsIgnoreCaseAscii( GetHTMLIndexPrefix(), 0, GetHTMLIndexPrefix().Len() ) )
     353                 :            :     {
     354 [ #  # ][ #  # ]:          0 :         String aIndex( rSource.Copy( GetHTMLIndexPrefix().Len() ) );
     355 [ #  # ][ #  # ]:          0 :         if( CharClass::isAsciiNumeric( aIndex ) && (aIndex.ToInt32() > 0) )
         [ #  # ][ #  # ]
                 [ #  # ]
     356 [ #  # ][ #  # ]:          0 :             rName = aIndex;
     357                 :            :     }
     358                 :          0 :     return rName.Len() > 0;
     359                 :            : }
     360                 :            : 
     361                 :            : // ============================================================================
     362                 :            : 
     363                 :          8 : ScFormatFilterPluginImpl::ScFormatFilterPluginImpl()
     364                 :            : {
     365                 :          8 : }
     366                 :            : 
     367                 :          8 : SAL_DLLPUBLIC_EXPORT ScFormatFilterPlugin * SAL_CALL ScFilterCreate(void)
     368                 :            : {
     369                 :          8 :     return new ScFormatFilterPluginImpl();
     370                 :            : }
     371                 :            : 
     372                 :            : // implementation class inside the filters
     373                 :            : 
     374                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10