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