LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/misc - langtab.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 61 0.0 %
Date: 2012-12-27 Functions: 0 8 0.0 %
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 <boost/static_assert.hpp>
      21             : 
      22             : #include <tools/shl.hxx>
      23             : 
      24             : #include <com/sun/star/i18n/DirectionProperty.hpp>
      25             : 
      26             : #include <i18npool/lang.h>
      27             : #include <i18npool/mslangid.hxx>
      28             : #include <i18npool/languagetag.hxx>
      29             : 
      30             : #include <svtools/svtools.hrc>
      31             : #include <svtools/svtresid.hxx>
      32             : #include <svtools/langtab.hxx>
      33             : #include <unotools/syslocale.hxx>
      34             : 
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38             : //------------------------------------------------------------------------
      39             : 
      40           0 : SVT_DLLPUBLIC const String ApplyLreOrRleEmbedding( const String &rText )
      41             : {
      42           0 :     const sal_uInt16 nLen = rText.Len();
      43           0 :     if (nLen == 0)
      44           0 :         return String();
      45             : 
      46           0 :     const sal_Unicode cLRE_Embedding  = 0x202A;      // the start char of an LRE embedding
      47           0 :     const sal_Unicode cRLE_Embedding  = 0x202B;      // the start char of an RLE embedding
      48           0 :     const sal_Unicode cPopDirectionalFormat = 0x202C;   // the unicode PDF (POP_DIRECTIONAL_FORMAT) char that terminates an LRE/RLE embedding
      49             : 
      50             :     // check if there are alreay embedding characters at the strings start
      51             :     // if so change nothing
      52           0 :     const sal_Unicode cChar = rText.GetBuffer()[0];
      53           0 :     if (cChar == cLRE_Embedding || cChar == cRLE_Embedding)
      54           0 :         return rText;
      55             : 
      56             :     // since we only call the function getCharacterDirection
      57             :     // it does not matter which locale the CharClass is for.
      58             :     // Thus we can readily make use of SvtSysLocale::GetCharClass()
      59             :     // which should come at no cost...
      60           0 :     SvtSysLocale aSysLocale;
      61           0 :     const CharClass &rCharClass = aSysLocale.GetCharClass();
      62             : 
      63             :     // we should look for the first non-neutral LTR or RTL character
      64             :     // and use that to determine the embedding of the whole text...
      65             :     // Thus we can avoid to check every character of the text.
      66           0 :     bool bFound     = false;
      67           0 :     bool bIsRtlText = false;
      68           0 :     for (sal_uInt16 i = 0;  i < nLen && !bFound;  ++i)
      69             :     {
      70           0 :         sal_Int16 nDirection = rCharClass.getCharacterDirection( rText, i );
      71           0 :         switch (nDirection)
      72             :         {
      73             :             case i18n::DirectionProperty_LEFT_TO_RIGHT :
      74             :             case i18n::DirectionProperty_LEFT_TO_RIGHT_EMBEDDING :
      75             :             case i18n::DirectionProperty_LEFT_TO_RIGHT_OVERRIDE :
      76             :             case i18n::DirectionProperty_EUROPEAN_NUMBER :
      77             :             case i18n::DirectionProperty_ARABIC_NUMBER :        // yes! arabic numbers are written from left to right
      78             :             {
      79           0 :                 bIsRtlText  = false;
      80           0 :                 bFound      = true;
      81           0 :                 break;
      82             :             }
      83             : 
      84             :             case i18n::DirectionProperty_RIGHT_TO_LEFT :
      85             :             case i18n::DirectionProperty_RIGHT_TO_LEFT_ARABIC :
      86             :             case i18n::DirectionProperty_RIGHT_TO_LEFT_EMBEDDING :
      87             :             case i18n::DirectionProperty_RIGHT_TO_LEFT_OVERRIDE :
      88             :             {
      89           0 :                 bIsRtlText  = true;
      90           0 :                 bFound      = true;
      91           0 :                 break;
      92             :             }
      93             : 
      94             :             default:
      95             :             {
      96             :                 // nothing to be done, character is considered to be neutral we need to look further ...
      97             :             }
      98             :         }
      99             :     }
     100             : 
     101           0 :     sal_Unicode cStart  = cLRE_Embedding;   // default is to use LRE embedding characters
     102           0 :     if (bIsRtlText)
     103           0 :         cStart = cRLE_Embedding;            // then use RLE embedding
     104             : 
     105             :     // add embedding start and end chars to the text if the direction could be determined
     106           0 :     String aRes( rText );
     107           0 :     if (bFound)
     108             :     {
     109           0 :         aRes.Insert( cStart, 0 );
     110           0 :         aRes.Insert( cPopDirectionalFormat );
     111             :     }
     112             : 
     113           0 :     return aRes;
     114             : }
     115             : 
     116             : //------------------------------------------------------------------------
     117             : 
     118             : namespace {
     119             :     BOOST_STATIC_ASSERT(
     120             :         16642 == STR_ARR_SVT_LANGUAGE_TABLE);
     121             : //        "The value of STR_ARR_SVT_LANGUAGE_TABLE has changed. wizards/com/sun/star/wizards/letter/LocaleCodes.java has this value hard coded, please adapt it to your change."
     122             : }
     123             : 
     124           0 : SvtLanguageTable::SvtLanguageTable() :
     125           0 :     ResStringArray( SvtResId( STR_ARR_SVT_LANGUAGE_TABLE ) )
     126             : {
     127           0 : }
     128             : 
     129             : //------------------------------------------------------------------------
     130             : 
     131           0 : SvtLanguageTable::~SvtLanguageTable()
     132             : {
     133           0 : }
     134             : 
     135             : //------------------------------------------------------------------------
     136             : 
     137           0 : const rtl::OUString SvtLanguageTable::GetString( const LanguageType eType, bool bUserInterfaceSelection ) const
     138             : {
     139           0 :     LanguageType eLang = MsLangId::getReplacementForObsoleteLanguage( eType, bUserInterfaceSelection);
     140           0 :     sal_uInt32 nPos = FindIndex( eLang );
     141             : 
     142           0 :     if ( RESARRAY_INDEX_NOTFOUND != nPos && nPos < Count() )
     143           0 :         return ResStringArray::GetString( nPos );
     144             : 
     145             :     //Rather than return a fairly useless "Unknown" name, return a geeky but usable-in-a-pinch lang-tag
     146           0 :     OUString sLangTag(LanguageTag(eType).getBcp47());
     147             :     SAL_WARN("svtools", "Language: 0x"
     148             :         << std::hex << eType
     149             :         << " with unknown name, so returning lang-tag of: "
     150             :         << sLangTag);
     151           0 :     return sLangTag;
     152             : }
     153             : 
     154           0 : String SvtLanguageTable::GetLanguageString( const LanguageType eType )
     155             : {
     156           0 :     static const SvtLanguageTable aLangTable;
     157           0 :     return aLangTable.GetString( eType );
     158             : }
     159             : 
     160             : //------------------------------------------------------------------------
     161             : 
     162           0 : LanguageType SvtLanguageTable::GetType( const String& rStr ) const
     163             : {
     164           0 :     LanguageType eType = LANGUAGE_DONTKNOW;
     165           0 :     sal_uInt32 nCount = Count();
     166             : 
     167           0 :     for ( sal_uInt32 i = 0; i < nCount; ++i )
     168             :     {
     169           0 :         if (ResStringArray::GetString( i ).equals(rStr))
     170             :         {
     171           0 :             eType = LanguageType( GetValue( i ) );
     172           0 :             break;
     173             :         }
     174             :     }
     175           0 :     return eType;
     176             : }
     177             : 
     178             : //------------------------------------------------------------------------
     179             : 
     180           0 : sal_uInt32 SvtLanguageTable::GetEntryCount() const
     181             : {
     182           0 :     return Count();
     183             : }
     184             : 
     185             : //------------------------------------------------------------------------
     186             : 
     187           0 : LanguageType SvtLanguageTable::GetTypeAtIndex( sal_uInt32 nIndex ) const
     188             : {
     189           0 :     LanguageType nType = LANGUAGE_DONTKNOW;
     190           0 :     if (nIndex < Count())
     191           0 :         nType = LanguageType( GetValue( nIndex ) );
     192           0 :     return nType;
     193             : }
     194             : 
     195             : //------------------------------------------------------------------------
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10