Fix for PreInitialize, including FontClient
[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) 2019 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    * @brief This is used to improve application launch performance
63    *
64    * @return A pre-initialized FontClient
65    */
66   static Dali::TextAbstraction::FontClient PreInitialize();
67
68   /**
69    * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
70    */
71   void ClearCache();
72
73   /**
74    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
75    */
76   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
77
78   /**
79    * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
80    */
81   void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
82
83   /**
84    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
85    */
86   int GetDefaultFontSize();
87
88   /**
89    * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
90    */
91   void ResetSystemDefaults();
92
93   /**
94    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
95    */
96   void GetDefaultFonts( FontList& defaultFonts );
97
98   /**
99    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
100    */
101   void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
102
103   /**
104    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
105    */
106   void GetSystemFonts( FontList& systemFonts );
107
108   /**
109    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
110    */
111   void GetDescription( FontId id, FontDescription& fontDescription );
112
113   /**
114    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
115    */
116   PointSize26Dot6 GetPointSize( FontId id );
117
118   /**
119    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
120    */
121   bool IsCharacterSupportedByFont( FontId fontId, Character character );
122
123   /**
124    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
125    */
126   FontId FindDefaultFont( Character charcode,
127                           PointSize26Dot6 requestedPointSize,
128                           bool preferColor );
129
130   /**
131    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
132    */
133   FontId FindFallbackFont( Character charcode,
134                            const FontDescription& preferredFontDescription,
135                            PointSize26Dot6 requestedPointSize,
136                            bool preferColor );
137
138   /**
139    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
140    */
141   FontId GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex );
142
143   /**
144    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
145    */
146   FontId GetFontId( const FontDescription& fontDescription,
147                     PointSize26Dot6 requestedPointSize,
148                     FaceIndex faceIndex );
149
150   /**
151    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
152    */
153   FontId GetFontId( const BitmapFont& bitmapFont );
154
155   /**
156    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
157    */
158   bool IsScalable( const FontPath& path );
159
160   /**
161    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
162    */
163   bool IsScalable( const FontDescription& fontDescription );
164
165   /**
166    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
167    */
168   void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
169
170   /**
171    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
172    */
173   void GetFixedSizes( const FontDescription& fontDescription,
174                       Dali::Vector< PointSize26Dot6 >& sizes );
175
176   /**
177    * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
178    */
179   bool HasItalicStyle( FontId fontId ) const;
180
181   /**
182    * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
183    */
184   void GetFontMetrics( FontId fontId, FontMetrics& metrics );
185
186   /**
187    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
188    */
189   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
190
191   /**
192    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
193    */
194   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal );
195
196   /**
197    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
198    */
199   void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
200
201   /**
202    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
203    */
204   PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
205
206   /**
207    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
208    */
209   void CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight );
210
211   /**
212    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
213    */
214   const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 requestedPointSize );
215
216   /**
217    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
218    */
219   bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex );
220
221   /**
222    * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
223    */
224   GlyphIndex CreateEmbeddedItem( const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat );
225
226   /**
227    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
228    *
229    * @param[in] fontId The font id.
230    *
231    * @return The pointer to the FreeType Font Face.
232    */
233   FT_FaceRec_* GetFreetypeFace( FontId fontId );
234
235   /**
236    * @brief Retrieves the type of font.
237    *
238    * @param[in] fontId The font id.
239    *
240    * @return FACE_FONT if the font has been loaded by FreeType, BITMAP_FONT if it's a font that has been loaded from images or INVALID if it's a non valid font.
241    */
242   FontDescription::Type GetFontType( FontId fontId );
243
244   /**
245    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
246    */
247   bool AddCustomFontDirectory( const FontPath& path );
248
249 private:
250
251   /**
252    * Helper for lazy initialization.
253    */
254   void CreatePlugin();
255
256   // Undefined copy constructor.
257   FontClient( const FontClient& );
258
259   // Undefined assignment constructor.
260   FontClient& operator=( const FontClient& );
261
262 private:
263
264   struct Plugin;
265   Plugin* mPlugin;
266
267   // Allows DPI to be set without loading plugin
268   unsigned int mDpiHorizontal;
269   unsigned int mDpiVertical;
270
271   static Dali::TextAbstraction::FontClient gPreInitializedFontClient;
272
273 }; // class FontClient
274
275 } // namespace Internal
276
277 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
278 {
279   DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
280   BaseObject& handle = fontClient.GetBaseObject();
281   return static_cast<Internal::FontClient&>(handle);
282 }
283
284 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
285 {
286   DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
287   const BaseObject& handle = fontClient.GetBaseObject();
288   return static_cast<const Internal::FontClient&>(handle);
289 }
290
291 } // namespace TextAbstraction
292
293 } // namespace Dali
294
295 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H