Merge "Text improvement 1. Circular text implementation. * Adds to dali-adaptor...
[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::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 bool FontClient::IsCharacterSupportedByFont( FontId fontId, Character character )
141 {
142   CreatePlugin();
143
144   return mPlugin->IsCharacterSupportedByFont( fontId, character );
145 }
146
147 void FontClient::GetSystemFonts( FontList& systemFonts )
148 {
149   CreatePlugin();
150
151   mPlugin->GetSystemFonts( systemFonts );
152 }
153
154 FontId FontClient::FindDefaultFont( Character charcode,
155                                     PointSize26Dot6 requestedPointSize,
156                                     bool preferColor )
157 {
158   CreatePlugin();
159
160   return mPlugin->FindDefaultFont( charcode,
161                                    requestedPointSize,
162                                    preferColor );
163 }
164
165 FontId FontClient::FindFallbackFont( Character charcode,
166                                      const FontDescription& preferredFontDescription,
167                                      PointSize26Dot6 requestedPointSize,
168                                      bool preferColor )
169 {
170   CreatePlugin();
171
172   return mPlugin->FindFallbackFont( charcode,
173                                     preferredFontDescription,
174                                     requestedPointSize,
175                                     preferColor );
176 }
177
178 bool FontClient::IsScalable( const FontPath& path )
179 {
180   CreatePlugin();
181
182   return mPlugin->IsScalable( path );
183 }
184
185 bool FontClient::IsScalable( const FontDescription& fontDescription )
186 {
187   CreatePlugin();
188
189   return mPlugin->IsScalable( fontDescription );
190 }
191
192 void FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
193 {
194   CreatePlugin();
195
196   mPlugin->GetFixedSizes( path, sizes );
197 }
198
199 void FontClient::GetFixedSizes( const FontDescription& fontDescription,
200                                 Dali::Vector< PointSize26Dot6 >& sizes )
201 {
202   CreatePlugin();
203
204   mPlugin->GetFixedSizes( fontDescription, sizes );
205 }
206
207 bool FontClient::HasItalicStyle( FontId fontId ) const
208 {
209   if( !mPlugin )
210   {
211     return false;
212   }
213
214   return mPlugin->HasItalicStyle( fontId );
215 }
216
217 FontId FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
218 {
219   CreatePlugin();
220
221   return mPlugin->GetFontId( path,
222                              requestedPointSize,
223                              faceIndex,
224                              true );
225 }
226
227 FontId FontClient::GetFontId( const FontDescription& fontDescription,
228                               PointSize26Dot6 requestedPointSize,
229                               FaceIndex faceIndex )
230 {
231   CreatePlugin();
232
233   return mPlugin->GetFontId( fontDescription,
234                              requestedPointSize,
235                              faceIndex );
236 }
237
238 FontId FontClient::GetFontId( const BitmapFont& bitmapFont )
239 {
240   CreatePlugin();
241
242   return mPlugin->GetFontId( bitmapFont );
243 }
244
245 void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
246 {
247   CreatePlugin();
248
249   mPlugin->GetFontMetrics( fontId, metrics );
250 }
251
252 GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
253 {
254   CreatePlugin();
255
256   return mPlugin->GetGlyphIndex( fontId, charcode );
257 }
258
259 bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal )
260 {
261   CreatePlugin();
262
263   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
264 }
265
266 void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
267 {
268   CreatePlugin();
269
270   mPlugin->CreateBitmap( fontId, glyphIndex, isItalicRequired, isBoldRequired, data, outlineWidth );
271 }
272
273 PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
274 {
275   CreatePlugin();
276
277   return mPlugin->CreateBitmap( fontId, glyphIndex, outlineWidth );
278 }
279
280 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
281 {
282   CreatePlugin();
283
284   mPlugin->CreateVectorBlob( fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
285 }
286
287 const GlyphInfo& FontClient::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
288 {
289   CreatePlugin();
290
291   return mPlugin->GetEllipsisGlyph( requestedPointSize );
292 }
293
294 bool FontClient::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
295 {
296   CreatePlugin();
297
298   return mPlugin->IsColorGlyph( fontId, glyphIndex );
299 }
300
301 GlyphIndex FontClient::CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat)
302 {
303   CreatePlugin();
304
305   return mPlugin->CreateEmbeddedItem( description, pixelFormat );
306 }
307
308 FT_FaceRec_* FontClient::GetFreetypeFace( FontId fontId )
309 {
310   CreatePlugin();
311
312   return mPlugin->GetFreetypeFace( fontId );
313 }
314
315 FontDescription::Type FontClient::GetFontType( FontId fontId )
316 {
317   CreatePlugin();
318
319   return mPlugin->GetFontType( fontId );
320 }
321
322 bool FontClient::AddCustomFontDirectory( const FontPath& path )
323 {
324   CreatePlugin();
325
326   return mPlugin->AddCustomFontDirectory( path );
327 }
328
329 void FontClient::CreatePlugin()
330 {
331   if( !mPlugin )
332   {
333     mPlugin = new Plugin( mDpiHorizontal, mDpiVertical );
334   }
335 }
336
337 } // namespace Internal
338
339 } // namespace TextAbstraction
340
341 } // namespace Dali