Support custom fonts registration
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / font-client-impl.h
1 #ifndef DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H
2 #define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/text-abstraction/font-client.h>
26
27
28 struct FT_FaceRec_;
29
30 namespace Dali
31 {
32
33 namespace TextAbstraction
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * Implementation of the FontClient
41  */
42 class FontClient : public BaseObject
43 {
44 public:
45
46   /**
47    * Constructor
48    */
49   FontClient();
50
51   /**
52    * Destructor
53    */
54   ~FontClient();
55
56   /**
57    * @copydoc Dali::TextAbstraction::FontClient::Get()
58    */
59   static Dali::TextAbstraction::FontClient Get();
60
61   /**
62    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
63    */
64   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
65
66   /**
67    * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
68    */
69   void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
70
71   /**
72    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
73    */
74   int GetDefaultFontSize();
75
76   /**
77    * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
78    */
79   void ResetSystemDefaults();
80
81   /**
82    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
83    */
84   void GetDefaultFonts( FontList& defaultFonts );
85
86   /**
87    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
88    */
89   void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
90
91   /**
92    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
93    */
94   void GetSystemFonts( FontList& systemFonts );
95
96   /**
97    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
98    */
99   void GetDescription( FontId id, FontDescription& fontDescription );
100
101   /**
102    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
103    */
104   PointSize26Dot6 GetPointSize( FontId id );
105
106   /**
107    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
108    */
109   bool IsCharacterSupportedByFont( FontId fontId, Character character );
110
111   /**
112    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
113    */
114   FontId FindDefaultFont( Character charcode,
115                           PointSize26Dot6 requestedPointSize,
116                           bool preferColor );
117
118   /**
119    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
120    */
121   FontId FindFallbackFont( Character charcode,
122                            const FontDescription& preferredFontDescription,
123                            PointSize26Dot6 requestedPointSize,
124                            bool preferColor );
125
126   /**
127    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
128    */
129   FontId GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex );
130
131   /**
132    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
133    */
134   FontId GetFontId( const FontDescription& fontDescription,
135                     PointSize26Dot6 requestedPointSize,
136                     FaceIndex faceIndex );
137
138   /**
139    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
140    */
141   bool IsScalable( const FontPath& path );
142
143   /**
144    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
145    */
146   bool IsScalable( const FontDescription& fontDescription );
147
148   /**
149    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
150    */
151   void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
152
153   /**
154    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
155    */
156   void GetFixedSizes( const FontDescription& fontDescription,
157                       Dali::Vector< PointSize26Dot6 >& sizes );
158
159   /**
160    * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
161    */
162   void GetFontMetrics( FontId fontId, FontMetrics& metrics );
163
164   /**
165    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
166    */
167   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
168
169   /**
170    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
171    */
172   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal );
173
174   /**
175    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
176    */
177   void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
178
179   /**
180    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
181    */
182   PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
183
184   /**
185    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
186    */
187   void CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight );
188
189   /**
190    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
191    */
192   const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 requestedPointSize );
193
194   /**
195    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
196    */
197   bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex );
198
199   /**
200    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
201    *
202    * @param[in] fontId The font id.
203    *
204    * @return The pointer to the FreeType Font Face.
205    */
206   FT_FaceRec_* GetFreetypeFace( FontId fontId );
207
208   /**
209    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
210    */
211   bool AddCustomFontDirectory( const FontPath& path );
212
213 private:
214
215   /**
216    * Helper for lazy initialization.
217    */
218   void CreatePlugin();
219
220   // Undefined copy constructor.
221   FontClient( const FontClient& );
222
223   // Undefined assignment constructor.
224   FontClient& operator=( const FontClient& );
225
226 private:
227
228   struct Plugin;
229   Plugin* mPlugin;
230
231   // Allows DPI to be set without loading plugin
232   unsigned int mDpiHorizontal;
233   unsigned int mDpiVertical;
234
235 }; // class FontClient
236
237 } // namespace Internal
238
239 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
240 {
241   DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
242   BaseObject& handle = fontClient.GetBaseObject();
243   return static_cast<Internal::FontClient&>(handle);
244 }
245
246 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
247 {
248   DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
249   const BaseObject& handle = fontClient.GetBaseObject();
250   return static_cast<const Internal::FontClient&>(handle);
251 }
252
253 } // namespace TextAbstraction
254
255 } // namespace Dali
256
257 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H