modify license, permission and remove ^M char
[platform/framework/native/uifw.git] / src / ui / FUi_BidiUtils.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an ”AS IS” BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUi_BidiUtils.cpp
20  * @brief               This is the implementation file for the _BidiUtils class.
21  */
22
23 #include <fribidi.h>
24 #include <FLclLocaleManager.h>
25 #include <FSysSettingInfo.h>
26 #include "FUi_BidiUtils.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Locales;
30
31 namespace Tizen { namespace Ui
32 {
33
34 _BidiUtils::_BidiUtils(void)
35 {
36 }
37
38 _BidiUtils::~_BidiUtils(void)
39 {
40 }
41
42 bool
43 _BidiUtils::IsRTL(const Tizen::Base::String& text)
44 {
45         int length = text.GetLength();
46         wchar_t* pString = const_cast<wchar_t*>(text.GetPointer());
47
48         if (pString != null && length > 0)
49         {
50                 for (int i = 0 ; i< length ; i++)
51                 {
52                         if(*pString == null)
53                         {
54                                 break;
55                         }
56                         FriBidiChar bidiText[1] = { *pString };
57                         FriBidiCharType type[1] = { 0 };
58                         fribidi_get_bidi_types(bidiText, 1, type);
59
60                         if ((type[0] & FRIBIDI_MASK_RTL) != 0)
61                         {
62                                 return true;
63                         }
64                         else if (((type[0] & FRIBIDI_MASK_STRONG) != 0) && ((type[0] & FRIBIDI_MASK_LETTER) != 0))
65                         {
66                                 return false;
67                         }
68
69                         pString++;
70                 }
71         }
72
73         if (IsBidiLanguage(GetDisplayLanguage()))
74         {
75                 return true;
76         }
77         return false;
78 }
79
80 bool
81 _BidiUtils::IsBidiLanguage(LanguageCode languageCode)
82 {
83         switch (languageCode)
84         {
85         case LANGUAGE_ARA: // arabic
86         case LANGUAGE_FAS: // farsi (iran)
87         case LANGUAGE_HEB: // hebrew (israel)
88         case LANGUAGE_URD: // urdu (parkistan)
89                 return true;
90         default:
91                 break;
92         }
93
94         return false;
95 }
96
97 LanguageCode
98 _BidiUtils::GetDisplayLanguage(void)
99 {
100         result r = E_SUCCESS;
101         LanguageCode languageCode = LANGUAGE_INVALID;
102         String displayLanguage;
103         String threeLetterLanguageCode;
104         String key(L"http://tizen.org/setting/locale.language");
105
106         r = Tizen::System::SettingInfo::GetValue(key, displayLanguage);
107
108         if (r == E_SUCCESS)
109         {
110                 displayLanguage.SubString(0, 3, threeLetterLanguageCode);
111                 languageCode = Locale::StringToLanguageCode(threeLetterLanguageCode);
112         }
113
114         return languageCode;
115 }
116
117 }} // Tizen::Ui