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