1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: langtab.cxx,v $
10 * $Revision: 1.3.140.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 // include ---------------------------------------------------------------
36 #include <tools/shl.hxx>
37 #include <tools/debug.hxx>
39 //#include <com/sun/star/i18n/XCharacterClassification.hpp>
40 #include <com/sun/star/i18n/DirectionProperty.hpp>
42 #include <i18npool/lang.h>
43 #include <i18npool/mslangid.hxx>
45 #include <svtools/svtools.hrc>
46 #include <svtools/svtdata.hxx>
47 #include <svtools/langtab.hxx>
48 #include <svtools/syslocale.hxx>
51 using namespace ::com::sun::star
;
53 //------------------------------------------------------------------------
55 SVT_DLLPUBLIC
const String
ApplyLreOrRleEmbedding( const String
&rText
)
57 const USHORT nLen
= rText
.Len();
61 const sal_Unicode cLRE_Embedding
= 0x202A; // the start char of an LRE embedding
62 const sal_Unicode cRLE_Embedding
= 0x202B; // the start char of an RLE embedding
63 const sal_Unicode cPopDirectionalFormat
= 0x202C; // the unicode PDF (POP_DIRECTIONAL_FORMAT) char that terminates an LRE/RLE embedding
65 // check if there are alreay embedding characters at the strings start
66 // if so change nothing
67 const sal_Unicode cChar
= rText
.GetBuffer()[0];
68 if (cChar
== cLRE_Embedding
|| cChar
== cRLE_Embedding
)
71 // since we only call the function getCharacterDirection
72 // it does not matter which locale the CharClass is for.
73 // Thus we can readily make use of SvtSysLocale::GetCharClass()
74 // which should come at no cost...
75 SvtSysLocale aSysLocale
;
76 const CharClass
&rCharClass
= aSysLocale
.GetCharClass();
78 // we should look for the first non-neutral LTR or RTL character
79 // and use that to determine the embedding of the whole text...
80 // Thus we can avoid to check every character of the text.
82 bool bIsRtlText
= false;
83 for (USHORT i
= 0; i
< nLen
&& !bFound
; ++i
)
85 sal_Int16 nDirection
= rCharClass
.getCharacterDirection( rText
, i
);
88 case i18n::DirectionProperty_LEFT_TO_RIGHT
:
89 case i18n::DirectionProperty_LEFT_TO_RIGHT_EMBEDDING
:
90 case i18n::DirectionProperty_LEFT_TO_RIGHT_OVERRIDE
:
91 case i18n::DirectionProperty_EUROPEAN_NUMBER
:
92 case i18n::DirectionProperty_ARABIC_NUMBER
: // yes! arabic numbers are written from left to right
99 case i18n::DirectionProperty_RIGHT_TO_LEFT
:
100 case i18n::DirectionProperty_RIGHT_TO_LEFT_ARABIC
:
101 case i18n::DirectionProperty_RIGHT_TO_LEFT_EMBEDDING
:
102 case i18n::DirectionProperty_RIGHT_TO_LEFT_OVERRIDE
:
111 // nothing to be done, character is considered to be neutral we need to look further ...
116 sal_Unicode cStart
= cLRE_Embedding
; // default is to use LRE embedding characters
118 cStart
= cRLE_Embedding
; // then use RLE embedding
120 // add embedding start and end chars to the text if the direction could be determined
121 String
aRes( rText
);
124 aRes
.Insert( cStart
, 0 );
125 aRes
.Insert( cPopDirectionalFormat
);
131 //------------------------------------------------------------------------
133 SvtLanguageTable::SvtLanguageTable() :
134 ResStringArray( SvtResId( STR_ARR_SVT_LANGUAGE_TABLE
) )
138 //------------------------------------------------------------------------
140 SvtLanguageTable::~SvtLanguageTable()
144 //------------------------------------------------------------------------
146 const String
& SvtLanguageTable::GetString( const LanguageType eType
) const
148 LanguageType eLang
= MsLangId::getReplacementForObsoleteLanguage( eType
);
149 sal_uInt32 nPos
= FindIndex( eLang
);
151 if ( RESARRAY_INDEX_NOTFOUND
!= nPos
&& nPos
< Count() )
152 return ResStringArray::GetString( nPos
);
155 // If we knew what a simple "en" should alias to (en_US?) we could
156 // generally raise an error.
158 eLang
== LANGUAGE_ENGLISH
, "language entry not found in resource" );
160 nPos
= FindIndex( LANGUAGE_DONTKNOW
);
162 if ( RESARRAY_INDEX_NOTFOUND
!= nPos
&& nPos
< Count() )
163 return ResStringArray::GetString( nPos
);
165 static String aEmptyStr
;
169 //------------------------------------------------------------------------
171 LanguageType
SvtLanguageTable::GetType( const String
& rStr
) const
173 LanguageType eType
= LANGUAGE_DONTKNOW
;
174 sal_uInt32 nCount
= Count();
176 for ( sal_uInt32 i
= 0; i
< nCount
; ++i
)
178 if ( rStr
== ResStringArray::GetString( i
) )
180 eType
= LanguageType( GetValue( i
) );
187 //------------------------------------------------------------------------
189 sal_uInt32
SvtLanguageTable::GetEntryCount() const
194 //------------------------------------------------------------------------
196 LanguageType
SvtLanguageTable::GetTypeAtIndex( sal_uInt32 nIndex
) const
198 LanguageType nType
= LANGUAGE_DONTKNOW
;
199 if (nIndex
< Count())
200 nType
= LanguageType( GetValue( nIndex
) );
204 //------------------------------------------------------------------------