1 #ifndef DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H
2 #define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/base-object.h>
25 #include <dali/devel-api/text-abstraction/font-client.h>
31 namespace TextAbstraction
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.
38 * Implementation of the FontClient
40 class FontClient : public BaseObject
53 public: // API for Dali::TextAbstraction::FontClient used.
55 * @copydoc Dali::TextAbstraction::FontClient::Get()
57 static Dali::TextAbstraction::FontClient Get();
60 * @brief This is used to improve application launch performance
62 * @return A pre-initialized FontClient
64 static Dali::TextAbstraction::FontClient PreInitialize();
67 * @brief This is used to pre-cache FontConfig in order to improve the runtime performance of the application.
69 * @see Dali::TextAbstraction::FontClientPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread, bool syncCreation);
71 static void PreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread, bool syncCreation);
74 * @brief This is used to creates a global font client and pre-caches the FontConfig.
76 static void PreCacheRun(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool syncCreation);
79 * @brief This is used to pre-load FreeType font face in order to improve the runtime performance of the application.
81 * @see Dali::TextAbstraction:FontClientFontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation);
83 static void PreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation);
86 * @brief This is used to creates a global font client and pre-loads the FreeType font face.
88 static void PreLoadRun(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool syncCreation);
91 * @brief Joins font threads, waiting for their execution to complete.
93 static void JoinFontThreads();
96 * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
101 * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
103 void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi);
106 * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
108 void GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi);
111 * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
113 int GetDefaultFontSize();
116 * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
118 void ResetSystemDefaults();
121 * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
123 void GetDefaultFonts(FontList& defaultFonts);
126 * @copydoc Dali::TextAbstraction::FontClient::InitDefaultFontDescription()
128 void InitDefaultFontDescription();
131 * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
133 void GetDefaultPlatformFontDescription(FontDescription& fontDescription);
136 * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
138 void GetSystemFonts(FontList& systemFonts);
141 * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
143 void GetDescription(FontId fontId, FontDescription& fontDescription);
146 * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
148 PointSize26Dot6 GetPointSize(FontId fontId);
151 * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
153 bool IsCharacterSupportedByFont(FontId fontId, Character character);
156 * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
158 FontId FindDefaultFont(Character charcode,
159 PointSize26Dot6 requestedPointSize,
163 * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
165 FontId FindFallbackFont(Character charcode,
166 const FontDescription& preferredFontDescription,
167 PointSize26Dot6 requestedPointSize,
171 * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
173 FontId GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex);
176 * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
178 FontId GetFontId(const FontDescription& fontDescription,
179 PointSize26Dot6 requestedPointSize,
180 FaceIndex faceIndex);
183 * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
185 FontId GetFontId(const BitmapFont& bitmapFont);
188 * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
190 bool IsScalable(const FontPath& path);
193 * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
195 bool IsScalable(const FontDescription& fontDescription);
198 * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
200 void GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes);
203 * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
205 void GetFixedSizes(const FontDescription& fontDescription,
206 Dali::Vector<PointSize26Dot6>& sizes);
209 * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
211 bool HasItalicStyle(FontId fontId) const;
214 * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
216 void GetFontMetrics(FontId fontId, FontMetrics& metrics);
219 * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
221 GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
224 * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
226 GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector);
229 * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
231 bool GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal);
234 * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth )
236 void CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth);
239 * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
241 PixelData CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth);
244 * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
246 void CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight);
249 * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
251 const GlyphInfo& GetEllipsisGlyph(PointSize26Dot6 requestedPointSize);
254 * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
256 bool IsColorGlyph(FontId fontId, GlyphIndex glyphIndex);
259 * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
261 GlyphIndex CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat);
264 * @copydoc Dali::TextAbstraction::FontClient::EnableAtlasLimitation(bool enabled)
266 void EnableAtlasLimitation(bool enabled);
269 * @copydoc Dali::TextAbstraction::FontClient::IsAtlasLimitationEnabled()
271 bool IsAtlasLimitationEnabled() const;
274 * @copydoc Dali::TextAbstraction::FontClient::GetMaximumTextAtlasSize()
276 Size GetMaximumTextAtlasSize() const;
279 * @copydoc Dali::TextAbstraction::FontClient::GetDefaultTextAtlasSize()
281 Size GetDefaultTextAtlasSize() const;
284 * @copydoc Dali::TextAbstraction::FontClient::GetCurrentMaximumBlockSizeFitInAtlas()
286 Size GetCurrentMaximumBlockSizeFitInAtlas() const;
289 * @copydoc Dali::TextAbstraction::FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
291 bool SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas);
294 * @copydoc Dali::TextAbstraction::FontClient::GetNumberOfPointsPerOneUnitOfPointSize()
296 uint32_t GetNumberOfPointsPerOneUnitOfPointSize() const;
299 * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
301 bool AddCustomFontDirectory(const FontPath& path);
303 public: // API for Dali::TextAbstraction::Internal::FontClient used.
305 * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
307 * @param[in] fontId The font id.
309 * @return The pointer to the FreeType Font Face.
311 FT_FaceRec_* GetFreetypeFace(FontId fontId);
314 * @brief Retrieves the type of font.
316 * @param[in] fontId The font id.
318 * @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.
320 FontDescription::Type GetFontType(FontId fontId);
323 * @brief Get the harfbuzz font data of font.
325 * @param fontId The font id.
326 * @return The harfbuzz font data, or nullptr if failed.
328 HarfBuzzFontHandle GetHarfBuzzFont(FontId fontId);
331 * @brief This is used to pre-cache fonts in order to improve the runtime performance of the application.
333 * @param[in] fallbackFamilyList A list of fallback font families to be pre-cached.
334 * @param[in] extraFamilyList A list of additional font families to be pre-cached.
335 * @param[in] localeFamily A locale font family to be pre-cached.
337 void FontPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily);
340 * @brief This is used to pre-load FreeType font face in order to improve the runtime performance of the application.
342 * @param[in] fontPathList A list of font paths to be pre-loaded.
343 * @param[in] memoryFontPathList A list of memory font paths to be pre-loaded.
344 * @param[in] useThread True if the font client should create thread and perform font pre-loading, false otherwise.
346 void FontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList);
351 * Helper for lazy initialization.
355 // Undefined copy constructor.
356 FontClient(const FontClient&);
358 // Undefined assignment constructor.
359 FontClient& operator=(const FontClient&);
365 // Allows DPI to be set without loading plugin
366 unsigned int mDpiHorizontal;
367 unsigned int mDpiVertical;
369 static Dali::TextAbstraction::FontClient gPreCreatedFontClient;
371 }; // class FontClient
373 } // namespace Internal
375 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
377 DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
378 BaseObject& handle = fontClient.GetBaseObject();
379 return static_cast<Internal::FontClient&>(handle);
382 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
384 DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
385 const BaseObject& handle = fontClient.GetBaseObject();
386 return static_cast<const Internal::FontClient&>(handle);
389 } // namespace TextAbstraction
393 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H