1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <boost/static_assert.hpp>
22 #include <tools/shl.hxx>
24 #include <com/sun/star/i18n/DirectionProperty.hpp>
26 #include <i18nlangtag/lang.h>
27 #include <i18nlangtag/mslangid.hxx>
28 #include <i18nlangtag/languagetag.hxx>
30 #include <svtools/svtools.hrc>
31 #include <svtools/svtresid.hxx>
32 #include <svtools/langtab.hxx>
33 #include <unotools/syslocale.hxx>
36 using namespace ::com::sun::star
;
38 //------------------------------------------------------------------------
40 SVT_DLLPUBLIC
const String
ApplyLreOrRleEmbedding( const String
&rText
)
42 const sal_uInt16 nLen
= rText
.Len();
46 const sal_Unicode cLRE_Embedding
= 0x202A; // the start char of an LRE embedding
47 const sal_Unicode cRLE_Embedding
= 0x202B; // the start char of an RLE embedding
48 const sal_Unicode cPopDirectionalFormat
= 0x202C; // the unicode PDF (POP_DIRECTIONAL_FORMAT) char that terminates an LRE/RLE embedding
50 // check if there are alreay embedding characters at the strings start
51 // if so change nothing
52 const sal_Unicode cChar
= rText
.GetBuffer()[0];
53 if (cChar
== cLRE_Embedding
|| cChar
== cRLE_Embedding
)
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 SvtSysLocale aSysLocale
;
61 const CharClass
&rCharClass
= aSysLocale
.GetCharClass();
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.
67 bool bIsRtlText
= false;
68 for (sal_uInt16 i
= 0; i
< nLen
&& !bFound
; ++i
)
70 sal_Int16 nDirection
= rCharClass
.getCharacterDirection( rText
, i
);
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
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
:
96 // nothing to be done, character is considered to be neutral we need to look further ...
101 sal_Unicode cStart
= cLRE_Embedding
; // default is to use LRE embedding characters
103 cStart
= cRLE_Embedding
; // then use RLE embedding
105 // add embedding start and end chars to the text if the direction could be determined
106 String
aRes( rText
);
109 aRes
.Insert( cStart
, 0 );
110 aRes
.Insert( cPopDirectionalFormat
);
116 //------------------------------------------------------------------------
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."
124 SvtLanguageTable::SvtLanguageTable() :
125 ResStringArray( SvtResId( STR_ARR_SVT_LANGUAGE_TABLE
) )
129 //------------------------------------------------------------------------
131 SvtLanguageTable::~SvtLanguageTable()
135 //------------------------------------------------------------------------
137 const OUString
SvtLanguageTable::GetString( const LanguageType eType
, bool bUserInterfaceSelection
) const
139 LanguageType eLang
= MsLangId::getReplacementForObsoleteLanguage( eType
, bUserInterfaceSelection
);
140 sal_uInt32 nPos
= FindIndex( eLang
);
142 if ( RESARRAY_INDEX_NOTFOUND
!= nPos
&& nPos
< Count() )
143 return ResStringArray::GetString( nPos
);
145 //Rather than return a fairly useless "Unknown" name, return a geeky but usable-in-a-pinch lang-tag
146 OUString
sLangTag(LanguageTag(eType
).getBcp47());
147 SAL_WARN("svtools.misc", "Language: 0x"
149 << " with unknown name, so returning lang-tag of: "
154 String
SvtLanguageTable::GetLanguageString( const LanguageType eType
)
156 static const SvtLanguageTable aLangTable
;
157 return aLangTable
.GetString( eType
);
160 //------------------------------------------------------------------------
162 LanguageType
SvtLanguageTable::GetType( const String
& rStr
) const
164 LanguageType eType
= LANGUAGE_DONTKNOW
;
165 sal_uInt32 nCount
= Count();
167 for ( sal_uInt32 i
= 0; i
< nCount
; ++i
)
169 if (ResStringArray::GetString( i
).equals(rStr
))
171 eType
= LanguageType( GetValue( i
) );
178 //------------------------------------------------------------------------
180 sal_uInt32
SvtLanguageTable::GetEntryCount() const
185 //------------------------------------------------------------------------
187 LanguageType
SvtLanguageTable::GetTypeAtIndex( sal_uInt32 nIndex
) const
189 LanguageType nType
= LANGUAGE_DONTKNOW
;
190 if (nIndex
< Count())
191 nType
= LanguageType( GetValue( nIndex
) );
195 //------------------------------------------------------------------------
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */