LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/core/data - documen6.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 70 87 80.5 %
Date: 2013-07-09 Functions: 13 15 86.7 %
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 "scitems.hxx"
      21             : #include <editeng/scripttypeitem.hxx>
      22             : 
      23             : #include <com/sun/star/i18n/BreakIterator.hpp>
      24             : #include <com/sun/star/i18n/ScriptType.hpp>
      25             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      26             : #include <comphelper/processfactory.hxx>
      27             : 
      28             : #include "document.hxx"
      29             : #include "cellform.hxx"
      30             : #include "patattr.hxx"
      31             : #include "scrdata.hxx"
      32             : #include "poolhelp.hxx"
      33             : #include "attrib.hxx"
      34             : #include "globalnames.hxx"
      35             : #include "columnspanset.hxx"
      36             : #include "table.hxx"
      37             : 
      38             : using namespace com::sun::star;
      39             : 
      40             : //
      41             : //  this file is compiled with exceptions enabled
      42             : //  put functions here that need exceptions!
      43             : //
      44             : 
      45             : // -----------------------------------------------------------------------
      46             : 
      47       25900 : const uno::Reference< i18n::XBreakIterator >& ScDocument::GetBreakIterator()
      48             : {
      49       25900 :     if ( !pScriptTypeData )
      50         185 :         pScriptTypeData = new ScScriptTypeData;
      51       25900 :     if ( !pScriptTypeData->xBreakIter.is() )
      52             :     {
      53         185 :         pScriptTypeData->xBreakIter = i18n::BreakIterator::create( comphelper::getProcessComponentContext() );
      54             :     }
      55       25900 :     return pScriptTypeData->xBreakIter;
      56             : }
      57             : 
      58           0 : bool ScDocument::HasStringWeakCharacters( const OUString& rString )
      59             : {
      60           0 :     if (!rString.isEmpty())
      61             :     {
      62           0 :         uno::Reference<i18n::XBreakIterator> xBreakIter = GetBreakIterator();
      63           0 :         if ( xBreakIter.is() )
      64             :         {
      65           0 :             sal_Int32 nLen = rString.getLength();
      66             : 
      67           0 :             sal_Int32 nPos = 0;
      68           0 :             do
      69             :             {
      70           0 :                 sal_Int16 nType = xBreakIter->getScriptType( rString, nPos );
      71           0 :                 if ( nType == i18n::ScriptType::WEAK )
      72           0 :                     return true;                            // found
      73             : 
      74           0 :                 nPos = xBreakIter->endOfScript( rString, nPos, nType );
      75             :             }
      76           0 :             while ( nPos >= 0 && nPos < nLen );
      77           0 :         }
      78             :     }
      79             : 
      80           0 :     return false;       // none found
      81             : }
      82             : 
      83       26109 : sal_uInt8 ScDocument::GetStringScriptType( const OUString& rString )
      84             : {
      85             : 
      86       26109 :     sal_uInt8 nRet = 0;
      87       26109 :     if (!rString.isEmpty())
      88             :     {
      89       25876 :         uno::Reference<i18n::XBreakIterator> xBreakIter = GetBreakIterator();
      90       25876 :         if ( xBreakIter.is() )
      91             :         {
      92       25876 :             sal_Int32 nLen = rString.getLength();
      93             : 
      94       25876 :             sal_Int32 nPos = 0;
      95       25891 :             do
      96             :             {
      97       25891 :                 sal_Int16 nType = xBreakIter->getScriptType( rString, nPos );
      98       25891 :                 switch ( nType )
      99             :                 {
     100             :                     case i18n::ScriptType::LATIN:
     101       25847 :                         nRet |= SCRIPTTYPE_LATIN;
     102       25847 :                         break;
     103             :                     case i18n::ScriptType::ASIAN:
     104           1 :                         nRet |= SCRIPTTYPE_ASIAN;
     105           1 :                         break;
     106             :                     case i18n::ScriptType::COMPLEX:
     107           0 :                         nRet |= SCRIPTTYPE_COMPLEX;
     108           0 :                         break;
     109             :                     // WEAK is ignored
     110             :                 }
     111       25891 :                 nPos = xBreakIter->endOfScript( rString, nPos, nType );
     112             :             }
     113       25891 :             while ( nPos >= 0 && nPos < nLen );
     114       25876 :         }
     115             :     }
     116       26109 :     return nRet;
     117             : }
     118             : 
     119       12112 : sal_uInt8 ScDocument::GetCellScriptType( const ScAddress& rPos, sal_uLong nNumberFormat )
     120             : {
     121       12112 :     sal_uInt8 nStored = GetScriptType(rPos);
     122       12112 :     if ( nStored != SC_SCRIPTTYPE_UNKNOWN )         // stored value valid?
     123        9672 :         return nStored;                             // use stored value
     124             : 
     125             :     Color* pColor;
     126        2440 :     OUString aStr = ScCellFormat::GetString(*this, rPos, nNumberFormat, &pColor, *xPoolHelper->GetFormTable());
     127             : 
     128        2440 :     sal_uInt8 nRet = GetStringScriptType( aStr );
     129             : 
     130        2440 :     SetScriptType(rPos, nRet);       // store for later calls
     131             : 
     132        2440 :     return nRet;
     133             : }
     134             : 
     135        2341 : sal_uInt8 ScDocument::GetScriptType( SCCOL nCol, SCROW nRow, SCTAB nTab )
     136             : {
     137             :     // if script type is set, don't have to get number formats
     138             : 
     139        2341 :     ScAddress aPos(nCol, nRow, nTab);
     140        2341 :     sal_uInt8 nStored = GetScriptType(aPos);
     141        2341 :     if ( nStored != SC_SCRIPTTYPE_UNKNOWN )         // stored value valid?
     142        2121 :         return nStored;                             // use stored value
     143             : 
     144             :     // include number formats from conditional formatting
     145             : 
     146         220 :     const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
     147         220 :     if (!pPattern) return 0;
     148         220 :     const SfxItemSet* pCondSet = NULL;
     149         220 :     if ( !((const ScCondFormatItem&)pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData().empty() )
     150          21 :         pCondSet = GetCondResult( nCol, nRow, nTab );
     151             : 
     152         220 :     sal_uLong nFormat = pPattern->GetNumberFormat( xPoolHelper->GetFormTable(), pCondSet );
     153             : 
     154         220 :     return GetCellScriptType(aPos, nFormat);
     155             : }
     156             : 
     157             : namespace {
     158             : 
     159          14 : class ScriptTypeAggregator : public sc::ColumnSpanSet::Action
     160             : {
     161             :     ScDocument& mrDoc;
     162             :     sc::ColumnBlockPosition maBlockPos;
     163             :     sal_uInt8 mnScriptType;
     164             : 
     165             : public:
     166          14 :     ScriptTypeAggregator(ScDocument& rDoc) : mrDoc(rDoc), mnScriptType(0) {}
     167             : 
     168          70 :     virtual void startColumn(SCTAB nTab, SCCOL nCol)
     169             :     {
     170          70 :         mrDoc.InitColumnBlockPosition(maBlockPos, nTab, nCol);
     171          70 :     }
     172             : 
     173         140 :     virtual void execute(const ScAddress& rPos, SCROW nLength, bool bVal)
     174             :     {
     175         140 :         if (!bVal)
     176         210 :             return;
     177             : 
     178          70 :         mnScriptType |= mrDoc.GetRangeScriptType(maBlockPos, rPos, nLength);
     179             :     };
     180             : 
     181          14 :     sal_uInt8 getScriptType() const { return mnScriptType; }
     182             : };
     183             : 
     184             : }
     185             : 
     186          70 : sal_uInt8 ScDocument::GetRangeScriptType(
     187             :     sc::ColumnBlockPosition& rBlockPos, const ScAddress& rPos, SCROW nLength )
     188             : {
     189          70 :     if (!TableExists(rPos.Tab()))
     190           0 :         return 0;
     191             : 
     192          70 :     return maTabs[rPos.Tab()]->GetRangeScriptType(rBlockPos, rPos.Col(), rPos.Row(), rPos.Row()+nLength-1);
     193             : }
     194             : 
     195          14 : sal_uInt8 ScDocument::GetRangeScriptType( const ScRangeList& rRanges )
     196             : {
     197          14 :     sc::ColumnSpanSet aSet(false);
     198          28 :     for (size_t i = 0, n = rRanges.size(); i < n; ++i)
     199             :     {
     200          14 :         const ScRange& rRange = *rRanges[i];
     201          14 :         SCTAB nTab = rRange.aStart.Tab();
     202          14 :         SCROW nRow1 = rRange.aStart.Row();
     203          14 :         SCROW nRow2 = rRange.aEnd.Row();
     204          84 :         for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
     205          70 :             aSet.set(nTab, nCol, nRow1, nRow2, true);
     206             :     }
     207             : 
     208          28 :     ScriptTypeAggregator aAction(*this);
     209          14 :     aSet.executeAction(aAction);
     210          28 :     return aAction.getScriptType();
     211          93 : }
     212             : 
     213             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10