Merge "Add set of APIs for emoji-character-properties" into 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) 2021 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 /**
36  * Implementation of the FontClient
37  */
38 class FontClient : public BaseObject
39 {
40 public:
41   /**
42    * Constructor
43    */
44   FontClient();
45
46   /**
47    * Destructor
48    */
49   ~FontClient();
50
51   /**
52    * @copydoc Dali::TextAbstraction::FontClient::Get()
53    */
54   static Dali::TextAbstraction::FontClient Get();
55
56   /**
57    * @brief This is used to improve application launch performance
58    *
59    * @return A pre-initialized FontClient
60    */
61   static Dali::TextAbstraction::FontClient PreInitialize();
62
63   /**
64    * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
65    */
66   void ClearCache();
67
68   /**
69    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
70    */
71   void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi);
72
73   /**
74    * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
75    */
76   void GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi);
77
78   /**
79    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
80    */
81   int GetDefaultFontSize();
82
83   /**
84    * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
85    */
86   void ResetSystemDefaults();
87
88   /**
89    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
90    */
91   void GetDefaultFonts(FontList& defaultFonts);
92
93   /**
94    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
95    */
96   void GetDefaultPlatformFontDescription(FontDescription& fontDescription);
97
98   /**
99    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
100    */
101   void GetSystemFonts(FontList& systemFonts);
102
103   /**
104    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
105    */
106   void GetDescription(FontId id, FontDescription& fontDescription);
107
108   /**
109    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
110    */
111   PointSize26Dot6 GetPointSize(FontId id);
112
113   /**
114    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
115    */
116   bool IsCharacterSupportedByFont(FontId fontId, Character character);
117
118   /**
119    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
120    */
121   FontId FindDefaultFont(Character       charcode,
122                          PointSize26Dot6 requestedPointSize,
123                          bool            preferColor);
124
125   /**
126    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
127    */
128   FontId FindFallbackFont(Character              charcode,
129                           const FontDescription& preferredFontDescription,
130                           PointSize26Dot6        requestedPointSize,
131                           bool                   preferColor);
132
133   /**
134    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
135    */
136   FontId GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex);
137
138   /**
139    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
140    */
141   FontId GetFontId(const FontDescription& fontDescription,
142                    PointSize26Dot6        requestedPointSize,
143                    FaceIndex              faceIndex);
144
145   /**
146    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
147    */
148   FontId GetFontId(const BitmapFont& bitmapFont);
149
150   /**
151    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
152    */
153   bool IsScalable(const FontPath& path);
154
155   /**
156    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
157    */
158   bool IsScalable(const FontDescription& fontDescription);
159
160   /**
161    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
162    */
163   void GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes);
164
165   /**
166    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
167    */
168   void GetFixedSizes(const FontDescription&         fontDescription,
169                      Dali::Vector<PointSize26Dot6>& sizes);
170
171   /**
172    * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
173    */
174   bool HasItalicStyle(FontId fontId) const;
175
176   /**
177    * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
178    */
179   void GetFontMetrics(FontId fontId, FontMetrics& metrics);
180
181   /**
182    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
183    */
184   GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
185
186   /**
187    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
188    */
189   GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector);
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    * @copydoc Dali::TextAbstraction::FontClient::EnableAtlasLimitation(bool enabled)
228    */
229   void EnableAtlasLimitation(bool enabled);
230
231   /**
232    * @copydoc Dali::TextAbstraction::FontClient::IsAtlasLimitationEnabled()
233    */
234   bool IsAtlasLimitationEnabled() const;
235
236   /**
237    * @copydoc Dali::TextAbstraction::FontClient::GetMaximumTextAtlasSize()
238    */
239   Size GetMaximumTextAtlasSize() const;
240
241   /**
242    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultTextAtlasSize()
243    */
244   Size GetDefaultTextAtlasSize() const;
245
246   /**
247    * @copydoc Dali::TextAbstraction::FontClient::GetCurrentMaximumBlockSizeFitInAtlas()
248    */
249   Size GetCurrentMaximumBlockSizeFitInAtlas() const;
250
251   /**
252    * @copydoc Dali::TextAbstraction::FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
253    */
254   bool SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas);
255
256   /**
257    * @copydoc Dali::TextAbstraction::FontClient::GetNumberOfPointsPerOneUnitOfPointSize()
258    */
259   uint32_t GetNumberOfPointsPerOneUnitOfPointSize() const;
260
261   /**
262    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
263    *
264    * @param[in] fontId The font id.
265    *
266    * @return The pointer to the FreeType Font Face.
267    */
268   FT_FaceRec_* GetFreetypeFace(FontId fontId);
269
270   /**
271    * @brief Retrieves the type of font.
272    *
273    * @param[in] fontId The font id.
274    *
275    * @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.
276    */
277   FontDescription::Type GetFontType(FontId fontId);
278
279   /**
280    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
281    */
282   bool AddCustomFontDirectory(const FontPath& path);
283
284 private:
285   /**
286    * Helper for lazy initialization.
287    */
288   void CreatePlugin();
289
290   // Undefined copy constructor.
291   FontClient(const FontClient&);
292
293   // Undefined assignment constructor.
294   FontClient& operator=(const FontClient&);
295
296 private:
297   struct Plugin;
298   Plugin* mPlugin;
299
300   // Allows DPI to be set without loading plugin
301   unsigned int mDpiHorizontal;
302   unsigned int mDpiVertical;
303
304   static Dali::TextAbstraction::FontClient gPreInitializedFontClient;
305
306 }; // class FontClient
307
308 } // namespace Internal
309
310 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
311 {
312   DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
313   BaseObject& handle = fontClient.GetBaseObject();
314   return static_cast<Internal::FontClient&>(handle);
315 }
316
317 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
318 {
319   DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
320   const BaseObject& handle = fontClient.GetBaseObject();
321   return static_cast<const Internal::FontClient&>(handle);
322 }
323
324 } // namespace TextAbstraction
325
326 } // namespace Dali
327
328 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H