LCOV - code coverage report
Current view: top level - sc/source/core/data - documen6.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 69 87 79.3 %
Date: 2015-06-13 12:38:46 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       32069 : const uno::Reference< i18n::XBreakIterator >& ScDocument::GetBreakIterator()
      44             : {
      45       32069 :     if ( !pScriptTypeData )
      46         461 :         pScriptTypeData = new ScScriptTypeData;
      47       32069 :     if ( !pScriptTypeData->xBreakIter.is() )
      48             :     {
      49         461 :         pScriptTypeData->xBreakIter = i18n::BreakIterator::create( comphelper::getProcessComponentContext() );
      50             :     }
      51       32069 :     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       31532 : SvtScriptType ScDocument::GetStringScriptType( const OUString& rString )
      80             : {
      81       31532 :     SvtScriptType nRet = SvtScriptType::NONE;
      82       31532 :     if (!rString.isEmpty())
      83             :     {
      84       31107 :         uno::Reference<i18n::XBreakIterator> xBreakIter = GetBreakIterator();
      85       31107 :         if ( xBreakIter.is() )
      86             :         {
      87       31107 :             sal_Int32 nLen = rString.getLength();
      88             : 
      89       31107 :             sal_Int32 nPos = 0;
      90       31122 :             do
      91             :             {
      92       31122 :                 sal_Int16 nType = xBreakIter->getScriptType( rString, nPos );
      93       31122 :                 switch ( nType )
      94             :                 {
      95             :                     case i18n::ScriptType::LATIN:
      96       31078 :                         nRet |= SvtScriptType::LATIN;
      97       31078 :                         break;
      98             :                     case i18n::ScriptType::ASIAN:
      99           1 :                         nRet |= SvtScriptType::ASIAN;
     100           1 :                         break;
     101             :                     case i18n::ScriptType::COMPLEX:
     102           0 :                         nRet |= SvtScriptType::COMPLEX;
     103           0 :                         break;
     104             :                     // WEAK is ignored
     105             :                 }
     106       31122 :                 nPos = xBreakIter->endOfScript( rString, nPos, nType );
     107             :             }
     108       31122 :             while ( nPos >= 0 && nPos < nLen );
     109       31107 :         }
     110             :     }
     111       31532 :     return nRet;
     112             : }
     113             : 
     114       27655 : SvtScriptType ScDocument::GetCellScriptType( const ScAddress& rPos, sal_uLong nNumberFormat )
     115             : {
     116       27655 :     SvtScriptType nStored = GetScriptType(rPos);
     117       27655 :     if ( nStored != SvtScriptType::UNKNOWN )         // stored value valid?
     118       24160 :         return nStored;                             // use stored value
     119             : 
     120             :     Color* pColor;
     121        3495 :     OUString aStr = ScCellFormat::GetString(*this, rPos, nNumberFormat, &pColor, *xPoolHelper->GetFormTable());
     122             : 
     123        3495 :     SvtScriptType nRet = GetStringScriptType( aStr );
     124             : 
     125        3495 :     SetScriptType(rPos, nRet);       // store for later calls
     126             : 
     127        3495 :     return nRet;
     128             : }
     129             : 
     130        3570 : SvtScriptType ScDocument::GetScriptType( SCCOL nCol, SCROW nRow, SCTAB nTab )
     131             : {
     132             :     // if script type is set, don't have to get number formats
     133             : 
     134        3570 :     ScAddress aPos(nCol, nRow, nTab);
     135        3570 :     SvtScriptType nStored = GetScriptType(aPos);
     136        3570 :     if ( nStored != SvtScriptType::UNKNOWN )         // stored value valid?
     137        3091 :         return nStored;                             // use stored value
     138             : 
     139             :     // include number formats from conditional formatting
     140             : 
     141         479 :     const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
     142         479 :     if (!pPattern) return SvtScriptType::NONE;
     143         479 :     const SfxItemSet* pCondSet = NULL;
     144         479 :     if ( !static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData().empty() )
     145           0 :         pCondSet = GetCondResult( nCol, nRow, nTab );
     146             : 
     147         479 :     sal_uLong nFormat = pPattern->GetNumberFormat( xPoolHelper->GetFormTable(), pCondSet );
     148             : 
     149         479 :     return GetCellScriptType(aPos, nFormat);
     150             : }
     151             : 
     152             : namespace {
     153             : 
     154          20 : class ScriptTypeAggregator : public sc::ColumnSpanSet::Action
     155             : {
     156             :     ScDocument& mrDoc;
     157             :     sc::ColumnBlockPosition maBlockPos;
     158             :     SvtScriptType mnScriptType;
     159             : 
     160             : public:
     161          20 :     ScriptTypeAggregator(ScDocument& rDoc) : mrDoc(rDoc), mnScriptType(SvtScriptType::NONE) {}
     162             : 
     163         100 :     virtual void startColumn(SCTAB nTab, SCCOL nCol) SAL_OVERRIDE
     164             :     {
     165         100 :         mrDoc.InitColumnBlockPosition(maBlockPos, nTab, nCol);
     166         100 :     }
     167             : 
     168         200 :     virtual void execute(const ScAddress& rPos, SCROW nLength, bool bVal) SAL_OVERRIDE
     169             :     {
     170         200 :         if (!bVal)
     171         300 :             return;
     172             : 
     173         100 :         mnScriptType |= mrDoc.GetRangeScriptType(maBlockPos, rPos, nLength);
     174             :     };
     175             : 
     176          20 :     SvtScriptType getScriptType() const { return mnScriptType; }
     177             : };
     178             : 
     179             : }
     180             : 
     181         100 : SvtScriptType ScDocument::GetRangeScriptType(
     182             :     sc::ColumnBlockPosition& rBlockPos, const ScAddress& rPos, SCROW nLength )
     183             : {
     184         100 :     if (!TableExists(rPos.Tab()))
     185           0 :         return SvtScriptType::NONE;
     186             : 
     187         100 :     return maTabs[rPos.Tab()]->GetRangeScriptType(rBlockPos, rPos.Col(), rPos.Row(), rPos.Row()+nLength-1);
     188             : }
     189             : 
     190          20 : SvtScriptType ScDocument::GetRangeScriptType( const ScRangeList& rRanges )
     191             : {
     192          20 :     sc::ColumnSpanSet aSet(false);
     193          40 :     for (size_t i = 0, n = rRanges.size(); i < n; ++i)
     194             :     {
     195          20 :         const ScRange& rRange = *rRanges[i];
     196          20 :         SCTAB nTab = rRange.aStart.Tab();
     197          20 :         SCROW nRow1 = rRange.aStart.Row();
     198          20 :         SCROW nRow2 = rRange.aEnd.Row();
     199         120 :         for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
     200         100 :             aSet.set(nTab, nCol, nRow1, nRow2, true);
     201             :     }
     202             : 
     203          40 :     ScriptTypeAggregator aAction(*this);
     204          20 :     aSet.executeAction(aAction);
     205          40 :     return aAction.getScriptType();
     206         156 : }
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11