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