LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/ftools - ftools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 154 48.7 %
Date: 2012-12-27 Functions: 20 33 60.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10