6c71899df4155a83c33b00d76820f7d8b95f1673
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / font-client-impl.cpp
1 /*
2  * Copyright (c) 2017 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( 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 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 FontId FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
208 {
209   CreatePlugin();
210
211   return mPlugin->GetFontId( path,
212                              requestedPointSize,
213                              faceIndex,
214                              true );
215 }
216
217 FontId FontClient::GetFontId( const FontDescription& fontDescription,
218                               PointSize26Dot6 requestedPointSize,
219                               FaceIndex faceIndex )
220 {
221   CreatePlugin();
222
223   return mPlugin->GetFontId( fontDescription,
224                              requestedPointSize,
225                              faceIndex );
226 }
227
228 void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
229 {
230   CreatePlugin();
231
232   return mPlugin->GetFontMetrics( fontId, metrics );
233 }
234
235 GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
236 {
237   CreatePlugin();
238
239   return mPlugin->GetGlyphIndex( fontId, charcode );
240 }
241
242 bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal )
243 {
244   CreatePlugin();
245
246   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
247 }
248
249 void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
250 {
251   CreatePlugin();
252
253   mPlugin->CreateBitmap( fontId, glyphIndex, data, outlineWidth );
254 }
255
256 PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
257 {
258   CreatePlugin();
259
260   return mPlugin->CreateBitmap( fontId, glyphIndex, outlineWidth );
261 }
262
263 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
264 {
265   CreatePlugin();
266
267   return mPlugin->CreateVectorBlob( fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
268 }
269
270 const GlyphInfo& FontClient::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
271 {
272   CreatePlugin();
273
274   return mPlugin->GetEllipsisGlyph( requestedPointSize );
275 }
276
277 bool FontClient::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
278 {
279   CreatePlugin();
280
281   return mPlugin->IsColorGlyph( fontId, glyphIndex );
282 }
283
284 bool FontClient::AddCustomFontDirectory( const FontPath& path )
285 {
286   CreatePlugin();
287
288   return mPlugin->AddCustomFontDirectory( path );
289 }
290
291 void FontClient::CreatePlugin()
292 {
293   if( !mPlugin )
294   {
295     mPlugin = new Plugin( mDpiHorizontal, mDpiVertical );
296   }
297 }
298
299 } // namespace Internal
300
301 } // namespace TextAbstraction
302
303 } // namespace Dali