f7731dbf93a9ef15879c039408603d2d682b618a
[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) 2022 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 fonts 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);
70    */
71   static void PreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useUiThread);
72
73   /**
74    * @brief This is used to creates a global font client and pre-caches the fonts.
75    */
76   static void PreCacheRun(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily);
77
78   /**
79    * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
80    */
81   void ClearCache();
82
83   /**
84    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
85    */
86   void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi);
87
88   /**
89    * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
90    */
91   void GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi);
92
93   /**
94    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
95    */
96   int GetDefaultFontSize();
97
98   /**
99    * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
100    */
101   void ResetSystemDefaults();
102
103   /**
104    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
105    */
106   void GetDefaultFonts(FontList& defaultFonts);
107
108   /**
109    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
110    */
111   void GetDefaultPlatformFontDescription(FontDescription& fontDescription);
112
113   /**
114    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
115    */
116   void GetSystemFonts(FontList& systemFonts);
117
118   /**
119    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
120    */
121   void GetDescription(FontId fontId, FontDescription& fontDescription);
122
123   /**
124    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
125    */
126   PointSize26Dot6 GetPointSize(FontId fontId);
127
128   /**
129    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
130    */
131   bool IsCharacterSupportedByFont(FontId fontId, Character character);
132
133   /**
134    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
135    */
136   FontId FindDefaultFont(Character       charcode,
137                          PointSize26Dot6 requestedPointSize,
138                          bool            preferColor);
139
140   /**
141    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
142    */
143   FontId FindFallbackFont(Character              charcode,
144                           const FontDescription& preferredFontDescription,
145                           PointSize26Dot6        requestedPointSize,
146                           bool                   preferColor);
147
148   /**
149    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
150    */
151   FontId GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex);
152
153   /**
154    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
155    */
156   FontId GetFontId(const FontDescription& fontDescription,
157                    PointSize26Dot6        requestedPointSize,
158                    FaceIndex              faceIndex);
159
160   /**
161    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
162    */
163   FontId GetFontId(const BitmapFont& bitmapFont);
164
165   /**
166    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
167    */
168   bool IsScalable(const FontPath& path);
169
170   /**
171    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
172    */
173   bool IsScalable(const FontDescription& fontDescription);
174
175   /**
176    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
177    */
178   void GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes);
179
180   /**
181    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
182    */
183   void GetFixedSizes(const FontDescription&         fontDescription,
184                      Dali::Vector<PointSize26Dot6>& sizes);
185
186   /**
187    * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
188    */
189   bool HasItalicStyle(FontId fontId) const;
190
191   /**
192    * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
193    */
194   void GetFontMetrics(FontId fontId, FontMetrics& metrics);
195
196   /**
197    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
198    */
199   GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
200
201   /**
202    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
203    */
204   GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector);
205
206   /**
207    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
208    */
209   bool GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal);
210
211   /**
212    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
213    */
214   void CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth);
215
216   /**
217    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
218    */
219   PixelData CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth);
220
221   /**
222    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
223    */
224   void CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight);
225
226   /**
227    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
228    */
229   const GlyphInfo& GetEllipsisGlyph(PointSize26Dot6 requestedPointSize);
230
231   /**
232    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
233    */
234   bool IsColorGlyph(FontId fontId, GlyphIndex glyphIndex);
235
236   /**
237    * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
238    */
239   GlyphIndex CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat);
240
241   /**
242    * @copydoc Dali::TextAbstraction::FontClient::EnableAtlasLimitation(bool enabled)
243    */
244   void EnableAtlasLimitation(bool enabled);
245
246   /**
247    * @copydoc Dali::TextAbstraction::FontClient::IsAtlasLimitationEnabled()
248    */
249   bool IsAtlasLimitationEnabled() const;
250
251   /**
252    * @copydoc Dali::TextAbstraction::FontClient::GetMaximumTextAtlasSize()
253    */
254   Size GetMaximumTextAtlasSize() const;
255
256   /**
257    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultTextAtlasSize()
258    */
259   Size GetDefaultTextAtlasSize() const;
260
261   /**
262    * @copydoc Dali::TextAbstraction::FontClient::GetCurrentMaximumBlockSizeFitInAtlas()
263    */
264   Size GetCurrentMaximumBlockSizeFitInAtlas() const;
265
266   /**
267    * @copydoc Dali::TextAbstraction::FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
268    */
269   bool SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas);
270
271   /**
272    * @copydoc Dali::TextAbstraction::FontClient::GetNumberOfPointsPerOneUnitOfPointSize()
273    */
274   uint32_t GetNumberOfPointsPerOneUnitOfPointSize() const;
275
276   /**
277    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
278    */
279   bool AddCustomFontDirectory(const FontPath& path);
280
281 public: // API for Dali::TextAbstraction::Internal::FontClient used.
282   /**
283    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
284    *
285    * @param[in] fontId The font id.
286    *
287    * @return The pointer to the FreeType Font Face.
288    */
289   FT_FaceRec_* GetFreetypeFace(FontId fontId);
290
291   /**
292    * @brief Retrieves the type of font.
293    *
294    * @param[in] fontId The font id.
295    *
296    * @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.
297    */
298   FontDescription::Type GetFontType(FontId fontId);
299
300   /**
301    * @brief Get the harfbuzz font data of font.
302    *
303    * @param fontId The font id.
304    * @return The harfbuzz font data, or nullptr if failed.
305    */
306   HarfBuzzFontHandle GetHarfBuzzFont(FontId fontId);
307
308   /**
309    * @brief This is used to pre-cache fonts in order to improve the runtime performance of the application.
310    *
311    * @param[in] fallbackFamilyList A list of fallback font families to be pre-cached.
312    * @param[in] extraFamilyList A list of additional font families to be pre-cached.
313    * @param[in] localeFamily A locale font family to be pre-cached.
314    */
315   void FontPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily);
316
317 private:
318   /**
319    * Helper for lazy initialization.
320    */
321   void CreatePlugin();
322
323   // Undefined copy constructor.
324   FontClient(const FontClient&);
325
326   // Undefined assignment constructor.
327   FontClient& operator=(const FontClient&);
328
329 private:
330   struct Plugin;
331   Plugin* mPlugin;
332
333   // Allows DPI to be set without loading plugin
334   unsigned int mDpiHorizontal;
335   unsigned int mDpiVertical;
336
337   static Dali::TextAbstraction::FontClient gPreCreatedFontClient;
338
339 }; // class FontClient
340
341 } // namespace Internal
342
343 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
344 {
345   DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
346   BaseObject& handle = fontClient.GetBaseObject();
347   return static_cast<Internal::FontClient&>(handle);
348 }
349
350 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
351 {
352   DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
353   const BaseObject& handle = fontClient.GetBaseObject();
354   return static_cast<const Internal::FontClient&>(handle);
355 }
356
357 } // namespace TextAbstraction
358
359 } // namespace Dali
360
361 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H