[dali_2.3.25] Merge branch 'devel/master'
[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) 2023 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 struct FT_FaceRec_;
28
29 namespace Dali
30 {
31 namespace TextAbstraction
32 {
33 namespace Internal
34 {
35 using HarfBuzzFontHandle = void*; ///< @note We don't want to make other class include harfbuzz header. So we will keep harfbuzz font data as HarfBuzzFontHandle.
36
37 /**
38  * Implementation of the FontClient
39  */
40 class FontClient : public BaseObject
41 {
42 public:
43   /**
44    * Constructor
45    */
46   FontClient();
47
48   /**
49    * Destructor
50    */
51   ~FontClient();
52
53 public: // API for Dali::TextAbstraction::FontClient used.
54   /**
55    * @copydoc Dali::TextAbstraction::FontClient::Get()
56    */
57   static Dali::TextAbstraction::FontClient Get();
58
59   /**
60    * @brief This is used to improve application launch performance
61    *
62    * @return A pre-initialized FontClient
63    */
64   static Dali::TextAbstraction::FontClient PreInitialize();
65
66   /**
67    * @brief This is used to pre-cache FontConfig in order to improve the runtime performance of the application.
68    *
69    * @see Dali::TextAbstraction::FontClientPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread, bool syncCreation);
70    */
71   static void PreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread, bool syncCreation);
72
73   /**
74    * @brief This is used to creates a global font client and pre-caches the FontConfig.
75    */
76   static void PreCacheRun(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool syncCreation);
77
78   /**
79    * @brief This is used to pre-load FreeType font face in order to improve the runtime performance of the application.
80    *
81    * @see Dali::TextAbstraction:FontClientFontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation);
82    */
83   static void PreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation);
84
85   /**
86    * @brief This is used to creates a global font client and pre-loads the FreeType font face.
87    */
88   static void PreLoadRun(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool syncCreation);
89
90   /**
91    * @brief Joins font threads, waiting for their execution to complete.
92    */
93   static void JoinFontThreads();
94
95   /**
96    * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
97    */
98   void ClearCache();
99
100   /**
101    * @copydoc Dali::TextAbstraction::FontClient::ClearCacheOnLocaleChanged()
102    */
103   void ClearCacheOnLocaleChanged();
104
105   /**
106    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
107    */
108   void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi);
109
110   /**
111    * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
112    */
113   void GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi);
114
115   /**
116    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
117    */
118   int GetDefaultFontSize();
119
120   /**
121    * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
122    */
123   void ResetSystemDefaults();
124
125   /**
126    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
127    */
128   void GetDefaultFonts(FontList& defaultFonts);
129
130   /**
131    * @copydoc Dali::TextAbstraction::FontClient::InitDefaultFontDescription()
132    */
133   void InitDefaultFontDescription();
134
135   /**
136    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
137    */
138   void GetDefaultPlatformFontDescription(FontDescription& fontDescription);
139
140   /**
141    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
142    */
143   void GetSystemFonts(FontList& systemFonts);
144
145   /**
146    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
147    */
148   void GetDescription(FontId fontId, FontDescription& fontDescription);
149
150   /**
151    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
152    */
153   PointSize26Dot6 GetPointSize(FontId fontId);
154
155   /**
156    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
157    */
158   bool IsCharacterSupportedByFont(FontId fontId, Character character);
159
160   /**
161    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
162    */
163   FontId FindDefaultFont(Character       charcode,
164                          PointSize26Dot6 requestedPointSize,
165                          bool            preferColor);
166
167   /**
168    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
169    */
170   FontId FindFallbackFont(Character              charcode,
171                           const FontDescription& preferredFontDescription,
172                           PointSize26Dot6        requestedPointSize,
173                           bool                   preferColor);
174
175   /**
176    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
177    */
178   FontId GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex);
179
180   /**
181    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
182    */
183   FontId GetFontId(const FontDescription& fontDescription,
184                    PointSize26Dot6        requestedPointSize,
185                    FaceIndex              faceIndex);
186
187   /**
188    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
189    */
190   FontId GetFontId(const BitmapFont& bitmapFont);
191
192   /**
193    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
194    */
195   bool IsScalable(const FontPath& path);
196
197   /**
198    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
199    */
200   bool IsScalable(const FontDescription& fontDescription);
201
202   /**
203    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
204    */
205   void GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes);
206
207   /**
208    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
209    */
210   void GetFixedSizes(const FontDescription&         fontDescription,
211                      Dali::Vector<PointSize26Dot6>& sizes);
212
213   /**
214    * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
215    */
216   bool HasItalicStyle(FontId fontId) const;
217
218   /**
219    * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
220    */
221   void GetFontMetrics(FontId fontId, FontMetrics& metrics);
222
223   /**
224    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
225    */
226   GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
227
228   /**
229    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
230    */
231   GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector);
232
233   /**
234    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
235    */
236   bool GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal);
237
238   /**
239    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth )
240    */
241   void CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth);
242
243   /**
244    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
245    */
246   PixelData CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth);
247
248   /**
249    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
250    */
251   void CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight);
252
253   /**
254    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
255    */
256   const GlyphInfo& GetEllipsisGlyph(PointSize26Dot6 requestedPointSize);
257
258   /**
259    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
260    */
261   bool IsColorGlyph(FontId fontId, GlyphIndex glyphIndex);
262
263   /**
264    * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
265    */
266   GlyphIndex CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat);
267
268   /**
269    * @copydoc Dali::TextAbstraction::FontClient::EnableAtlasLimitation(bool enabled)
270    */
271   void EnableAtlasLimitation(bool enabled);
272
273   /**
274    * @copydoc Dali::TextAbstraction::FontClient::IsAtlasLimitationEnabled()
275    */
276   bool IsAtlasLimitationEnabled() const;
277
278   /**
279    * @copydoc Dali::TextAbstraction::FontClient::GetMaximumTextAtlasSize()
280    */
281   Size GetMaximumTextAtlasSize() const;
282
283   /**
284    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultTextAtlasSize()
285    */
286   Size GetDefaultTextAtlasSize() const;
287
288   /**
289    * @copydoc Dali::TextAbstraction::FontClient::GetCurrentMaximumBlockSizeFitInAtlas()
290    */
291   Size GetCurrentMaximumBlockSizeFitInAtlas() const;
292
293   /**
294    * @copydoc Dali::TextAbstraction::FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
295    */
296   bool SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas);
297
298   /**
299    * @copydoc Dali::TextAbstraction::FontClient::GetNumberOfPointsPerOneUnitOfPointSize()
300    */
301   uint32_t GetNumberOfPointsPerOneUnitOfPointSize() const;
302
303   /**
304    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
305    */
306   bool AddCustomFontDirectory(const FontPath& path);
307
308 public: // API for Dali::TextAbstraction::Internal::FontClient used.
309   /**
310    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
311    *
312    * @param[in] fontId The font id.
313    *
314    * @return The pointer to the FreeType Font Face.
315    */
316   FT_FaceRec_* GetFreetypeFace(FontId fontId);
317
318   /**
319    * @brief Retrieves the type of font.
320    *
321    * @param[in] fontId The font id.
322    *
323    * @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.
324    */
325   FontDescription::Type GetFontType(FontId fontId);
326
327   /**
328    * @brief Get the harfbuzz font data of font.
329    *
330    * @param fontId The font id.
331    * @return The harfbuzz font data, or nullptr if failed.
332    */
333   HarfBuzzFontHandle GetHarfBuzzFont(FontId fontId);
334
335   /**
336    * @brief This is used to pre-cache fonts in order to improve the runtime performance of the application.
337    *
338    * @param[in] fallbackFamilyList A list of fallback font families to be pre-cached.
339    * @param[in] extraFamilyList A list of additional font families to be pre-cached.
340    * @param[in] localeFamily A locale font family to be pre-cached.
341    */
342   void FontPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily);
343
344   /**
345    * @brief This is used to pre-load FreeType font face in order to improve the runtime performance of the application.
346    *
347    * @param[in] fontPathList A list of font paths to be pre-loaded.
348    * @param[in] memoryFontPathList A list of memory font paths to be pre-loaded.
349    * @param[in] useThread True if the font client should create thread and perform font pre-loading, false otherwise.
350    */
351   void FontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList);
352
353
354 private:
355   /**
356    * Helper for lazy initialization.
357    */
358   void CreatePlugin();
359
360   // Undefined copy constructor.
361   FontClient(const FontClient&);
362
363   // Undefined assignment constructor.
364   FontClient& operator=(const FontClient&);
365
366 private:
367   struct Plugin;
368   Plugin* mPlugin;
369
370   // Allows DPI to be set without loading plugin
371   unsigned int mDpiHorizontal;
372   unsigned int mDpiVertical;
373
374   static Dali::TextAbstraction::FontClient gPreCreatedFontClient;
375
376 }; // class FontClient
377
378 } // namespace Internal
379
380 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
381 {
382   DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
383   BaseObject& handle = fontClient.GetBaseObject();
384   return static_cast<Internal::FontClient&>(handle);
385 }
386
387 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
388 {
389   DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
390   const BaseObject& handle = fontClient.GetBaseObject();
391   return static_cast<const Internal::FontClient&>(handle);
392 }
393
394 } // namespace TextAbstraction
395
396 } // namespace Dali
397
398 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H