Merge "Remove unused mEglImageKHRContainer from NativeImageSource and add error check...
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / text-abstraction / font-client-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/text-abstraction/font-client-impl.h>
20
21 // EXTERNAL INCLUDES
22 #ifndef DALI_PROFILE_UBUNTU
23 #include <vconf.h>
24 #endif
25
26 // INTERNAL INCLUDES
27 #include <singleton-service.h>
28 #include <dali/internal/text-abstraction/font-client-plugin-impl.h>
29
30 namespace Dali
31 {
32
33 namespace TextAbstraction
34 {
35
36 namespace Internal
37 {
38
39 FontClient::FontClient()
40 : mPlugin( NULL ),
41   mDpiHorizontal( 0 ),
42   mDpiVertical( 0 )
43 {
44 }
45
46 FontClient::~FontClient()
47 {
48   delete mPlugin;
49 }
50
51 Dali::TextAbstraction::FontClient FontClient::Get()
52 {
53   Dali::TextAbstraction::FontClient fontClientHandle;
54
55   Dali::SingletonService service( SingletonService::Get() );
56   if ( service )
57   {
58     // Check whether the singleton is already created
59     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::TextAbstraction::FontClient ) );
60     if(handle)
61     {
62       // If so, downcast the handle
63       FontClient* impl = dynamic_cast< Dali::TextAbstraction::Internal::FontClient* >( handle.GetObjectPtr() );
64       fontClientHandle = Dali::TextAbstraction::FontClient( impl );
65     }
66     else // create and register the object
67     {
68       fontClientHandle = Dali::TextAbstraction::FontClient( new FontClient );
69       service.Register( typeid( fontClientHandle ), fontClientHandle );
70     }
71   }
72
73   return fontClientHandle;
74 }
75
76 void FontClient::SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi  )
77 {
78   mDpiHorizontal = horizontalDpi;
79   mDpiVertical = verticalDpi;
80
81   // Allow DPI to be set without loading plugin
82   if( mPlugin )
83   {
84     mPlugin->SetDpi( horizontalDpi, verticalDpi  );
85   }
86 }
87
88 void FontClient::GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi )
89 {
90   horizontalDpi = mDpiHorizontal;
91   verticalDpi = mDpiVertical;
92 }
93
94 int FontClient::GetDefaultFontSize()
95 {
96   int fontSize( -1 );
97
98 #ifndef DALI_PROFILE_UBUNTU
99   vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
100 #endif // DALI_PROFILE_UBUNTU
101
102   return fontSize;
103 }
104
105 void FontClient::ResetSystemDefaults()
106 {
107   CreatePlugin();
108
109   mPlugin->ResetSystemDefaults();
110 }
111
112 void FontClient::GetDefaultFonts( FontList& defaultFonts )
113 {
114   CreatePlugin();
115
116   mPlugin->GetDefaultFonts( defaultFonts );
117 }
118
119 void FontClient::GetDefaultPlatformFontDescription( FontDescription& fontDescription )
120 {
121   CreatePlugin();
122
123   mPlugin->GetDefaultPlatformFontDescription( fontDescription );
124 }
125
126 void FontClient::GetDescription( FontId id, FontDescription& fontDescription )
127 {
128   CreatePlugin();
129
130   mPlugin->GetDescription( id, fontDescription );
131 }
132
133 PointSize26Dot6 FontClient::GetPointSize( FontId id )
134 {
135   CreatePlugin();
136
137   return mPlugin->GetPointSize( id );
138 }
139
140 void FontClient::GetSystemFonts( FontList& systemFonts )
141 {
142   CreatePlugin();
143
144   mPlugin->GetSystemFonts( systemFonts );
145 }
146
147 FontId FontClient::FindDefaultFont( Character charcode,
148                                     PointSize26Dot6 requestedPointSize,
149                                     bool preferColor )
150 {
151   CreatePlugin();
152
153   return mPlugin->FindDefaultFont( charcode,
154                                    requestedPointSize,
155                                    preferColor );
156 }
157
158 FontId FontClient::FindFallbackFont( Character charcode,
159                                      const FontDescription& preferredFontDescription,
160                                      PointSize26Dot6 requestedPointSize,
161                                      bool preferColor )
162 {
163   CreatePlugin();
164
165   return mPlugin->FindFallbackFont( charcode,
166                                     preferredFontDescription,
167                                     requestedPointSize,
168                                     preferColor );
169 }
170
171 bool FontClient::IsScalable( const FontPath& path )
172 {
173   CreatePlugin();
174
175   return mPlugin->IsScalable( path );
176 }
177
178 bool FontClient::IsScalable( const FontDescription& fontDescription )
179 {
180   CreatePlugin();
181
182   return mPlugin->IsScalable( fontDescription );
183 }
184
185 void FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
186 {
187   CreatePlugin();
188
189   mPlugin->GetFixedSizes( path, sizes );
190 }
191
192 void FontClient::GetFixedSizes( const FontDescription& fontDescription,
193                                 Dali::Vector< PointSize26Dot6 >& sizes )
194 {
195   CreatePlugin();
196
197   mPlugin->GetFixedSizes( fontDescription, sizes );
198 }
199
200 FontId FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
201 {
202   CreatePlugin();
203
204   return mPlugin->GetFontId( path,
205                              requestedPointSize,
206                              requestedPointSize,
207                              faceIndex );
208 }
209
210 FontId FontClient::GetFontId( const FontDescription& fontDescription,
211                               PointSize26Dot6 requestedPointSize,
212                               FaceIndex faceIndex )
213 {
214   CreatePlugin();
215
216   return mPlugin->GetFontId( fontDescription,
217                              requestedPointSize,
218                              requestedPointSize,
219                              faceIndex );
220 }
221
222 void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
223 {
224   CreatePlugin();
225
226   return mPlugin->GetFontMetrics( fontId, metrics );
227 }
228
229 GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
230 {
231   CreatePlugin();
232
233   return mPlugin->GetGlyphIndex( fontId, charcode );
234 }
235
236 bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal )
237 {
238   CreatePlugin();
239
240   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
241 }
242
243 void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data )
244 {
245   CreatePlugin();
246
247   mPlugin->CreateBitmap( fontId, glyphIndex, data );
248 }
249
250 PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
251 {
252   CreatePlugin();
253
254   return mPlugin->CreateBitmap( fontId, glyphIndex );
255 }
256
257 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
258 {
259   CreatePlugin();
260
261   return mPlugin->CreateVectorBlob( fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
262 }
263
264 const GlyphInfo& FontClient::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
265 {
266   CreatePlugin();
267
268   return mPlugin->GetEllipsisGlyph( requestedPointSize );
269 }
270
271 bool FontClient::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
272 {
273   CreatePlugin();
274
275   return mPlugin->IsColorGlyph( fontId, glyphIndex );
276 }
277
278 void FontClient::CreatePlugin()
279 {
280   if( !mPlugin )
281   {
282     mPlugin = new Plugin( mDpiHorizontal, mDpiVertical );
283   }
284 }
285
286 } // namespace Internal
287
288 } // namespace TextAbstraction
289
290 } // namespace Dali