LCOV - code coverage report
Current view: top level - sc/source/core/data - documen6.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 67 73.1 %
Date: 2012-08-25 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 41 86 47.7 %

           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 "scitems.hxx"
      30                 :            : #include <editeng/scripttypeitem.hxx>
      31                 :            : 
      32                 :            : #include <com/sun/star/i18n/XBreakIterator.hpp>
      33                 :            : #include <com/sun/star/i18n/ScriptType.hpp>
      34                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35                 :            : 
      36                 :            : #include "document.hxx"
      37                 :            : #include "cell.hxx"
      38                 :            : #include "cellform.hxx"
      39                 :            : #include "patattr.hxx"
      40                 :            : #include "scrdata.hxx"
      41                 :            : #include "poolhelp.hxx"
      42                 :            : 
      43                 :            : using namespace com::sun::star;
      44                 :            : 
      45                 :            : #define SC_BREAKITER_SERVICE    "com.sun.star.i18n.BreakIterator"
      46                 :            : 
      47                 :            : //
      48                 :            : //  this file is compiled with exceptions enabled
      49                 :            : //  put functions here that need exceptions!
      50                 :            : //
      51                 :            : 
      52                 :            : // -----------------------------------------------------------------------
      53                 :            : 
      54                 :      31048 : const uno::Reference< i18n::XBreakIterator >& ScDocument::GetBreakIterator()
      55                 :            : {
      56         [ +  + ]:      31048 :     if ( !pScriptTypeData )
      57         [ +  - ]:        256 :         pScriptTypeData = new ScScriptTypeData;
      58         [ +  + ]:      31048 :     if ( !pScriptTypeData->xBreakIter.is() )
      59                 :            :     {
      60         [ +  - ]:        256 :         uno::Reference< uno::XInterface > xInterface = xServiceManager->createInstance(
      61 [ +  - ][ +  - ]:        256 :                             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_BREAKITER_SERVICE )) );
      62 [ +  - ][ +  - ]:        256 :         pScriptTypeData->xBreakIter = uno::Reference< i18n::XBreakIterator >( xInterface, uno::UNO_QUERY );
      63                 :        256 :         OSL_ENSURE( pScriptTypeData->xBreakIter.is(), "can't get BreakIterator" );
      64                 :            :     }
      65                 :      31048 :     return pScriptTypeData->xBreakIter;
      66                 :            : }
      67                 :            : 
      68                 :          0 : bool ScDocument::HasStringWeakCharacters( const rtl::OUString& rString )
      69                 :            : {
      70         [ #  # ]:          0 :     if (!rString.isEmpty())
      71                 :            :     {
      72         [ #  # ]:          0 :         uno::Reference<i18n::XBreakIterator> xBreakIter = GetBreakIterator();
      73         [ #  # ]:          0 :         if ( xBreakIter.is() )
      74                 :            :         {
      75                 :          0 :             sal_Int32 nLen = rString.getLength();
      76                 :            : 
      77                 :          0 :             sal_Int32 nPos = 0;
      78 [ #  # ][ #  # ]:          0 :             do
                 [ #  # ]
      79                 :            :             {
      80 [ #  # ][ #  # ]:          0 :                 sal_Int16 nType = xBreakIter->getScriptType( rString, nPos );
      81         [ #  # ]:          0 :                 if ( nType == i18n::ScriptType::WEAK )
      82                 :          0 :                     return true;                            // found
      83                 :            : 
      84 [ #  # ][ #  # ]:          0 :                 nPos = xBreakIter->endOfScript( rString, nPos, nType );
      85                 :            :             }
      86                 :            :             while ( nPos >= 0 && nPos < nLen );
      87         [ #  # ]:          0 :         }
      88                 :            :     }
      89                 :            : 
      90                 :          0 :     return false;       // none found
      91                 :            : }
      92                 :            : 
      93                 :      31290 : sal_uInt8 ScDocument::GetStringScriptType( const rtl::OUString& rString )
      94                 :            : {
      95                 :            : 
      96                 :      31290 :     sal_uInt8 nRet = 0;
      97         [ +  + ]:      31290 :     if (!rString.isEmpty())
      98                 :            :     {
      99         [ +  - ]:      31048 :         uno::Reference<i18n::XBreakIterator> xBreakIter = GetBreakIterator();
     100         [ +  - ]:      31048 :         if ( xBreakIter.is() )
     101                 :            :         {
     102                 :      31048 :             sal_Int32 nLen = rString.getLength();
     103                 :            : 
     104                 :      31048 :             sal_Int32 nPos = 0;
     105 [ +  - ][ +  + ]:      31073 :             do
                 [ +  + ]
     106                 :            :             {
     107 [ +  - ][ +  - ]:      31073 :                 sal_Int16 nType = xBreakIter->getScriptType( rString, nPos );
     108   [ +  -  -  + ]:      31073 :                 switch ( nType )
     109                 :            :                 {
     110                 :            :                     case i18n::ScriptType::LATIN:
     111                 :      30961 :                         nRet |= SCRIPTTYPE_LATIN;
     112                 :      30961 :                         break;
     113                 :            :                     case i18n::ScriptType::ASIAN:
     114                 :          0 :                         nRet |= SCRIPTTYPE_ASIAN;
     115                 :          0 :                         break;
     116                 :            :                     case i18n::ScriptType::COMPLEX:
     117                 :          0 :                         nRet |= SCRIPTTYPE_COMPLEX;
     118                 :          0 :                         break;
     119                 :            :                     // WEAK is ignored
     120                 :            :                 }
     121 [ +  - ][ +  - ]:      31073 :                 nPos = xBreakIter->endOfScript( rString, nPos, nType );
     122                 :            :             }
     123                 :            :             while ( nPos >= 0 && nPos < nLen );
     124                 :      31048 :         }
     125                 :            :     }
     126                 :      31290 :     return nRet;
     127                 :            : }
     128                 :            : 
     129                 :      40105 : sal_uInt8 ScDocument::GetCellScriptType( ScBaseCell* pCell, sal_uLong nNumberFormat )
     130                 :            : {
     131         [ -  + ]:      40105 :     if ( !pCell )
     132                 :          0 :         return 0;       // empty
     133                 :            : 
     134                 :      40105 :     sal_uInt8 nStored = pCell->GetScriptType();
     135         [ +  + ]:      40105 :     if ( nStored != SC_SCRIPTTYPE_UNKNOWN )         // stored value valid?
     136                 :       9187 :         return nStored;                             // use stored value
     137                 :            : 
     138                 :      30918 :     rtl::OUString aStr;
     139                 :            :     Color* pColor;
     140 [ +  - ][ +  - ]:      30918 :     ScCellFormat::GetString( pCell, nNumberFormat, aStr, &pColor, *xPoolHelper->GetFormTable() );
     141                 :            : 
     142         [ +  - ]:      30918 :     sal_uInt8 nRet = GetStringScriptType( aStr );
     143                 :            : 
     144                 :      30918 :     pCell->SetScriptType( nRet );       // store for later calls
     145                 :            : 
     146                 :      40105 :     return nRet;
     147                 :            : }
     148                 :            : 
     149                 :      89433 : sal_uInt8 ScDocument::GetScriptType( SCCOL nCol, SCROW nRow, SCTAB nTab, ScBaseCell* pCell )
     150                 :            : {
     151                 :            :     // if cell is not passed, take from document
     152                 :            : 
     153         [ +  + ]:      89433 :     if (!pCell)
     154                 :            :     {
     155         [ +  - ]:       1102 :         pCell = GetCell( ScAddress( nCol, nRow, nTab ) );
     156         [ +  + ]:       1102 :         if ( !pCell )
     157                 :        959 :             return 0;       // empty
     158                 :            :     }
     159                 :            : 
     160                 :            :     // if script type is set, don't have to get number formats
     161                 :            : 
     162                 :      88474 :     sal_uInt8 nStored = pCell->GetScriptType();
     163         [ +  + ]:      88474 :     if ( nStored != SC_SCRIPTTYPE_UNKNOWN )         // stored value valid?
     164                 :      59855 :         return nStored;                             // use stored value
     165                 :            : 
     166                 :            :     // include number formats from conditional formatting
     167                 :            : 
     168                 :      28619 :     const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
     169         [ -  + ]:      28619 :     if (!pPattern) return 0;
     170                 :      28619 :     const SfxItemSet* pCondSet = NULL;
     171         [ +  + ]:      28619 :     if ( ((const SfxUInt32Item&)pPattern->GetItem(ATTR_CONDITIONAL)).GetValue() )
     172                 :         50 :         pCondSet = GetCondResult( nCol, nRow, nTab );
     173                 :            : 
     174                 :      28619 :     sal_uLong nFormat = pPattern->GetNumberFormat( xPoolHelper->GetFormTable(), pCondSet );
     175                 :      89433 :     return GetCellScriptType( pCell, nFormat );
     176                 :            : }
     177                 :            : 
     178                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10