Merge "Fix and add missed doxygen" into devel/master
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / text-abstraction / font-client-impl.cpp
1 /*
2  * Copyright (c) 2015 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-abstraction/font-client-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <singleton-service.h>
23 #include <dali/internal/text-abstraction/font-client-plugin-impl.h>
24
25 namespace Dali
26 {
27
28 namespace TextAbstraction
29 {
30
31 namespace Internal
32 {
33
34 FontClient::FontClient()
35 : mPlugin( NULL ),
36   mDpiHorizontal( 0 ),
37   mDpiVertical( 0 )
38 {
39 }
40
41 FontClient::~FontClient()
42 {
43   delete mPlugin;
44 }
45
46 Dali::TextAbstraction::FontClient FontClient::Get()
47 {
48   Dali::TextAbstraction::FontClient fontClientHandle;
49
50   Dali::SingletonService service( SingletonService::Get() );
51   if ( service )
52   {
53     // Check whether the singleton is already created
54     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::TextAbstraction::FontClient ) );
55     if(handle)
56     {
57       // If so, downcast the handle
58       FontClient* impl = dynamic_cast< Dali::TextAbstraction::Internal::FontClient* >( handle.GetObjectPtr() );
59       fontClientHandle = Dali::TextAbstraction::FontClient( impl );
60     }
61     else // create and register the object
62     {
63       fontClientHandle = Dali::TextAbstraction::FontClient( new FontClient );
64       service.Register( typeid( fontClientHandle ), fontClientHandle );
65     }
66   }
67
68   return fontClientHandle;
69 }
70
71 void FontClient::SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi  )
72 {
73   mDpiHorizontal = horizontalDpi;
74   mDpiVertical = verticalDpi;
75
76   // Allow DPI to be set without loading plugin
77   if( mPlugin )
78   {
79     mPlugin->SetDpi( horizontalDpi, verticalDpi  );
80   }
81 }
82
83 void FontClient::GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi )
84 {
85   horizontalDpi = mDpiHorizontal;
86   verticalDpi = mDpiVertical;
87 }
88
89 void FontClient::ResetSystemDefaults()
90 {
91   CreatePlugin();
92
93   mPlugin->ResetSystemDefaults();
94 }
95
96 void FontClient::GetDefaultFonts( FontList& defaultFonts )
97 {
98   CreatePlugin();
99
100   mPlugin->GetDefaultFonts( defaultFonts );
101 }
102
103 void FontClient::GetDefaultPlatformFontDescription( FontDescription& fontDescription )
104 {
105   CreatePlugin();
106
107   mPlugin->GetDefaultPlatformFontDescription( fontDescription );
108 }
109
110 void FontClient::GetDescription( FontId id, FontDescription& fontDescription )
111 {
112   CreatePlugin();
113
114   mPlugin->GetDescription( id, fontDescription );
115 }
116
117 PointSize26Dot6 FontClient::GetPointSize( FontId id )
118 {
119   CreatePlugin();
120
121   return mPlugin->GetPointSize( id );
122 }
123
124 void FontClient::GetSystemFonts( FontList& systemFonts )
125 {
126   CreatePlugin();
127
128   mPlugin->GetSystemFonts( systemFonts );
129 }
130
131 FontId FontClient::FindDefaultFont( Character charcode,
132                                     PointSize26Dot6 requestedPointSize,
133                                     bool preferColor )
134 {
135   CreatePlugin();
136
137   return mPlugin->FindDefaultFont( charcode,
138                                    requestedPointSize,
139                                    preferColor );
140 }
141
142 FontId FontClient::FindFallbackFont( Character charcode,
143                                      const FontDescription& preferredFontDescription,
144                                      PointSize26Dot6 requestedPointSize,
145                                      bool preferColor )
146 {
147   CreatePlugin();
148
149   return mPlugin->FindFallbackFont( charcode,
150                                     preferredFontDescription,
151                                     requestedPointSize,
152                                     preferColor );
153 }
154
155 bool FontClient::IsScalable( const FontPath& path )
156 {
157   CreatePlugin();
158
159   return mPlugin->IsScalable( path );
160 }
161
162 bool FontClient::IsScalable( const FontDescription& fontDescription )
163 {
164   CreatePlugin();
165
166   return mPlugin->IsScalable( fontDescription );
167 }
168
169 void FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
170 {
171   CreatePlugin();
172
173   mPlugin->GetFixedSizes( path, sizes );
174 }
175
176 void FontClient::GetFixedSizes( const FontDescription& fontDescription,
177                                 Dali::Vector< PointSize26Dot6 >& sizes )
178 {
179   CreatePlugin();
180
181   mPlugin->GetFixedSizes( fontDescription, sizes );
182 }
183
184 FontId FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
185 {
186   CreatePlugin();
187
188   return mPlugin->GetFontId( path,
189                              requestedPointSize,
190                              requestedPointSize,
191                              faceIndex );
192 }
193
194 FontId FontClient::GetFontId( const FontDescription& fontDescription,
195                               PointSize26Dot6 requestedPointSize,
196                               FaceIndex faceIndex )
197 {
198   CreatePlugin();
199
200   return mPlugin->GetFontId( fontDescription,
201                              requestedPointSize,
202                              requestedPointSize,
203                              faceIndex );
204 }
205
206 void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
207 {
208   CreatePlugin();
209
210   return mPlugin->GetFontMetrics( fontId, metrics );
211 }
212
213 GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
214 {
215   CreatePlugin();
216
217   return mPlugin->GetGlyphIndex( fontId, charcode );
218 }
219
220 bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal )
221 {
222   CreatePlugin();
223
224   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
225 }
226
227 void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data )
228 {
229   CreatePlugin();
230
231   mPlugin->CreateBitmap( fontId, glyphIndex, data );
232 }
233
234 PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
235 {
236   CreatePlugin();
237
238   return mPlugin->CreateBitmap( fontId, glyphIndex );
239 }
240
241 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
242 {
243   CreatePlugin();
244
245   return mPlugin->CreateVectorBlob( fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
246 }
247
248 const GlyphInfo& FontClient::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
249 {
250   CreatePlugin();
251
252   return mPlugin->GetEllipsisGlyph( requestedPointSize );
253 }
254
255 bool FontClient::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
256 {
257   CreatePlugin();
258
259   return mPlugin->IsColorGlyph( fontId, glyphIndex );
260 }
261
262 void FontClient::CreatePlugin()
263 {
264   if( !mPlugin )
265   {
266     mPlugin = new Plugin( mDpiHorizontal, mDpiVertical );
267   }
268 }
269
270 } // namespace Internal
271
272 } // namespace TextAbstraction
273
274 } // namespace Dali