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