Merge "[AT-SPI] Add API for blocking automatic Bridge initialization" into devel...
[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::GetGlyphMetrics()
188    */
189   bool GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal);
190
191   /**
192    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
193    */
194   void CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth);
195
196   /**
197    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
198    */
199   PixelData CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth);
200
201   /**
202    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
203    */
204   void CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight);
205
206   /**
207    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
208    */
209   const GlyphInfo& GetEllipsisGlyph(PointSize26Dot6 requestedPointSize);
210
211   /**
212    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
213    */
214   bool IsColorGlyph(FontId fontId, GlyphIndex glyphIndex);
215
216   /**
217    * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
218    */
219   GlyphIndex CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat);
220
221   /**
222    * @copydoc Dali::TextAbstraction::FontClient::EnableAtlasLimitation(bool enabled)
223    */
224   void EnableAtlasLimitation(bool enabled);
225
226   /**
227    * @copydoc Dali::TextAbstraction::FontClient::IsAtlasLimitationEnabled()
228    */
229   bool IsAtlasLimitationEnabled() const;
230
231   /**
232    * @copydoc Dali::TextAbstraction::FontClient::GetMaximumTextAtlasSize()
233    */
234   Size GetMaximumTextAtlasSize() const;
235
236    /**
237    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultTextAtlasSize()
238    */
239   Size GetDefaultTextAtlasSize() const;
240
241   /**
242    * @copydoc Dali::TextAbstraction::FontClient::GetCurrentMaximumBlockSizeFitInAtlas()
243    */
244   Size GetCurrentMaximumBlockSizeFitInAtlas() const;
245
246   /**
247    * @copydoc Dali::TextAbstraction::FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
248    */
249   bool SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas);
250
251   /**
252    * @copydoc Dali::TextAbstraction::FontClient::GetNumberOfPointsPerOneUnitOfPointSize()
253    */
254   uint32_t GetNumberOfPointsPerOneUnitOfPointSize() const;
255
256   /**
257    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
258    *
259    * @param[in] fontId The font id.
260    *
261    * @return The pointer to the FreeType Font Face.
262    */
263   FT_FaceRec_* GetFreetypeFace(FontId fontId);
264
265   /**
266    * @brief Retrieves the type of font.
267    *
268    * @param[in] fontId The font id.
269    *
270    * @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.
271    */
272   FontDescription::Type GetFontType(FontId fontId);
273
274   /**
275    * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
276    */
277   bool AddCustomFontDirectory(const FontPath& path);
278
279 private:
280   /**
281    * Helper for lazy initialization.
282    */
283   void CreatePlugin();
284
285   // Undefined copy constructor.
286   FontClient(const FontClient&);
287
288   // Undefined assignment constructor.
289   FontClient& operator=(const FontClient&);
290
291 private:
292   struct Plugin;
293   Plugin* mPlugin;
294
295   // Allows DPI to be set without loading plugin
296   unsigned int mDpiHorizontal;
297   unsigned int mDpiVertical;
298
299   static Dali::TextAbstraction::FontClient gPreInitializedFontClient;
300
301 }; // class FontClient
302
303 } // namespace Internal
304
305 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
306 {
307   DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
308   BaseObject& handle = fontClient.GetBaseObject();
309   return static_cast<Internal::FontClient&>(handle);
310 }
311
312 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
313 {
314   DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
315   const BaseObject& handle = fontClient.GetBaseObject();
316   return static_cast<const Internal::FontClient&>(handle);
317 }
318
319 } // namespace TextAbstraction
320
321 } // namespace Dali
322
323 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H