clear cache when locale is changed
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / font-client-impl.cpp
1 /*
2  * Copyright (c) 2019 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/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 <dali/devel-api/adaptor-framework/singleton-service.h>
28 #include <dali/internal/text/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( nullptr ),
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::ClearCache()
77 {
78   if( mPlugin )
79   {
80     mPlugin->ClearCache();
81   }
82 }
83
84
85 void FontClient::SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi  )
86 {
87   mDpiHorizontal = horizontalDpi;
88   mDpiVertical = verticalDpi;
89
90   // Allow DPI to be set without loading plugin
91   if( mPlugin )
92   {
93     mPlugin->SetDpi( horizontalDpi, verticalDpi  );
94   }
95 }
96
97 void FontClient::GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi )
98 {
99   horizontalDpi = mDpiHorizontal;
100   verticalDpi = mDpiVertical;
101 }
102
103 int FontClient::GetDefaultFontSize()
104 {
105   int fontSize( -1 );
106
107 #ifndef DALI_PROFILE_UBUNTU
108   vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
109 #endif // DALI_PROFILE_UBUNTU
110
111   return fontSize;
112 }
113
114 void FontClient::ResetSystemDefaults()
115 {
116   CreatePlugin();
117
118   mPlugin->ResetSystemDefaults();
119 }
120
121 void FontClient::GetDefaultFonts( FontList& defaultFonts )
122 {
123   CreatePlugin();
124
125   mPlugin->GetDefaultFonts( defaultFonts );
126 }
127
128 void FontClient::GetDefaultPlatformFontDescription( FontDescription& fontDescription )
129 {
130   CreatePlugin();
131
132   mPlugin->GetDefaultPlatformFontDescription( fontDescription );
133 }
134
135 void FontClient::GetDescription( FontId id, FontDescription& fontDescription )
136 {
137   CreatePlugin();
138
139   mPlugin->GetDescription( id, fontDescription );
140 }
141
142 PointSize26Dot6 FontClient::GetPointSize( FontId id )
143 {
144   CreatePlugin();
145
146   return mPlugin->GetPointSize( id );
147 }
148
149 bool FontClient::IsCharacterSupportedByFont( FontId fontId, Character character )
150 {
151   CreatePlugin();
152
153   return mPlugin->IsCharacterSupportedByFont( fontId, character );
154 }
155
156 void FontClient::GetSystemFonts( FontList& systemFonts )
157 {
158   CreatePlugin();
159
160   mPlugin->GetSystemFonts( systemFonts );
161 }
162
163 FontId FontClient::FindDefaultFont( Character charcode,
164                                     PointSize26Dot6 requestedPointSize,
165                                     bool preferColor )
166 {
167   CreatePlugin();
168
169   return mPlugin->FindDefaultFont( charcode,
170                                    requestedPointSize,
171                                    preferColor );
172 }
173
174 FontId FontClient::FindFallbackFont( Character charcode,
175                                      const FontDescription& preferredFontDescription,
176                                      PointSize26Dot6 requestedPointSize,
177                                      bool preferColor )
178 {
179   CreatePlugin();
180
181   return mPlugin->FindFallbackFont( charcode,
182                                     preferredFontDescription,
183                                     requestedPointSize,
184                                     preferColor );
185 }
186
187 bool FontClient::IsScalable( const FontPath& path )
188 {
189   CreatePlugin();
190
191   return mPlugin->IsScalable( path );
192 }
193
194 bool FontClient::IsScalable( const FontDescription& fontDescription )
195 {
196   CreatePlugin();
197
198   return mPlugin->IsScalable( fontDescription );
199 }
200
201 void FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
202 {
203   CreatePlugin();
204
205   mPlugin->GetFixedSizes( path, sizes );
206 }
207
208 void FontClient::GetFixedSizes( const FontDescription& fontDescription,
209                                 Dali::Vector< PointSize26Dot6 >& sizes )
210 {
211   CreatePlugin();
212
213   mPlugin->GetFixedSizes( fontDescription, sizes );
214 }
215
216 bool FontClient::HasItalicStyle( FontId fontId ) const
217 {
218   if( !mPlugin )
219   {
220     return false;
221   }
222
223   return mPlugin->HasItalicStyle( fontId );
224 }
225
226 FontId FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
227 {
228   CreatePlugin();
229
230   return mPlugin->GetFontId( path,
231                              requestedPointSize,
232                              faceIndex,
233                              true );
234 }
235
236 FontId FontClient::GetFontId( const FontDescription& fontDescription,
237                               PointSize26Dot6 requestedPointSize,
238                               FaceIndex faceIndex )
239 {
240   CreatePlugin();
241
242   return mPlugin->GetFontId( fontDescription,
243                              requestedPointSize,
244                              faceIndex );
245 }
246
247 FontId FontClient::GetFontId( const BitmapFont& bitmapFont )
248 {
249   CreatePlugin();
250
251   return mPlugin->GetFontId( bitmapFont );
252 }
253
254 void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
255 {
256   CreatePlugin();
257
258   mPlugin->GetFontMetrics( fontId, metrics );
259 }
260
261 GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
262 {
263   CreatePlugin();
264
265   return mPlugin->GetGlyphIndex( fontId, charcode );
266 }
267
268 bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal )
269 {
270   CreatePlugin();
271
272   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
273 }
274
275 void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
276 {
277   CreatePlugin();
278
279   mPlugin->CreateBitmap( fontId, glyphIndex, isItalicRequired, isBoldRequired, data, outlineWidth );
280 }
281
282 PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
283 {
284   CreatePlugin();
285
286   return mPlugin->CreateBitmap( fontId, glyphIndex, outlineWidth );
287 }
288
289 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
290 {
291   CreatePlugin();
292
293   mPlugin->CreateVectorBlob( fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
294 }
295
296 const GlyphInfo& FontClient::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
297 {
298   CreatePlugin();
299
300   return mPlugin->GetEllipsisGlyph( requestedPointSize );
301 }
302
303 bool FontClient::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
304 {
305   CreatePlugin();
306
307   return mPlugin->IsColorGlyph( fontId, glyphIndex );
308 }
309
310 GlyphIndex FontClient::CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
311 {
312   CreatePlugin();
313
314   return mPlugin->CreateEmbeddedItem( description, pixelFormat );
315 }
316
317 FT_FaceRec_* FontClient::GetFreetypeFace( FontId fontId )
318 {
319   CreatePlugin();
320
321   return mPlugin->GetFreetypeFace( fontId );
322 }
323
324 FontDescription::Type FontClient::GetFontType( FontId fontId )
325 {
326   CreatePlugin();
327
328   return mPlugin->GetFontType( fontId );
329 }
330
331 bool FontClient::AddCustomFontDirectory( const FontPath& path )
332 {
333   CreatePlugin();
334
335   return mPlugin->AddCustomFontDirectory( path );
336 }
337
338 void FontClient::CreatePlugin()
339 {
340   if( !mPlugin )
341   {
342     mPlugin = new Plugin( mDpiHorizontal, mDpiVertical );
343   }
344 }
345
346 } // namespace Internal
347
348 } // namespace TextAbstraction
349
350 } // namespace Dali