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

Generated by: LCOV version 1.10