Merge remote-tracking branch 'origin/tizen' into new_text
[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::SetDefaultFontFamily( const std::string& fontFamilyName,
84                                        const std::string& fontStyle )
85 {
86   CreatePlugin();
87
88   mPlugin->SetDefaultFontFamily( fontFamilyName, fontStyle );
89 }
90
91 void FontClient::GetDefaultFonts( FontList& defaultFonts )
92 {
93   CreatePlugin();
94
95   mPlugin->GetDefaultFonts( defaultFonts );
96 }
97
98 void FontClient::GetDescription( FontId id, FontDescription& fontDescription )
99 {
100   CreatePlugin();
101
102   mPlugin->GetDescription( id, fontDescription );
103 }
104
105 PointSize26Dot6 FontClient::GetPointSize( FontId id )
106 {
107   CreatePlugin();
108
109   return mPlugin->GetPointSize( id );
110 }
111
112 void FontClient::GetSystemFonts( FontList& systemFonts )
113 {
114   CreatePlugin();
115
116   mPlugin->GetSystemFonts( systemFonts );
117 }
118
119 FontId FontClient::FindDefaultFont( Character charcode, PointSize26Dot6 pointSize )
120 {
121   CreatePlugin();
122
123   return mPlugin->FindDefaultFont( charcode, pointSize );
124 }
125
126 FontId FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
127 {
128   CreatePlugin();
129
130   return mPlugin->GetFontId( path, pointSize, faceIndex );
131 }
132
133 FontId FontClient::GetFontId( const FontFamily& fontFamily,
134                               const FontStyle& fontStyle,
135                               PointSize26Dot6 pointSize,
136                               FaceIndex faceIndex )
137 {
138   CreatePlugin();
139
140   return mPlugin->GetFontId( fontFamily,
141                              fontStyle,
142                              pointSize,
143                              faceIndex );
144 }
145
146 void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
147 {
148   CreatePlugin();
149
150   return mPlugin->GetFontMetrics( fontId, metrics );
151 }
152
153 GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
154 {
155   CreatePlugin();
156
157   return mPlugin->GetGlyphIndex( fontId, charcode );
158 }
159
160 bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal )
161 {
162   CreatePlugin();
163
164   return mPlugin->GetGlyphMetrics( array, size, horizontal );
165 }
166
167 BitmapImage FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
168 {
169   CreatePlugin();
170
171   return mPlugin->CreateBitmap( fontId, glyphIndex );
172 }
173
174 void FontClient::CreatePlugin()
175 {
176   if( !mPlugin )
177   {
178     mPlugin = new Plugin( mDpiHorizontal, mDpiVertical );
179   }
180 }
181
182 } // namespace Internal
183
184 } // namespace TextAbstraction
185
186 } // namespace Dali