1 #ifndef DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H
2 #define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_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/devel-api/adaptor-framework/pixel-buffer.h>
23 #include <dali/devel-api/text-abstraction/bitmap-font.h>
24 #include <dali/devel-api/text-abstraction/font-metrics.h>
25 #include <dali/devel-api/text-abstraction/glyph-info.h>
26 #include <dali/internal/text/text-abstraction/font-client-impl.h>
27 #include <dali/internal/text/text-abstraction/plugin/bitmap-font-cache-item.h>
28 #include <dali/internal/text/text-abstraction/plugin/embedded-item.h>
29 #include <dali/internal/text/text-abstraction/plugin/font-face-cache-item.h>
30 #include <dali/internal/text/text-abstraction/plugin/pixel-buffer-cache-item.h>
32 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
33 #include <third-party/glyphy/vector-font-cache.h>
35 class VectorFontCache;
39 #include <unordered_map>
42 #include FT_FREETYPE_H
45 #include FT_SYNTHESIS_H
47 // forward declarations of font config types.
54 namespace TextAbstraction
59 * @brief Type used for indices addressing the vector with front descriptions of validated fonts.
61 typedef uint32_t FontDescriptionId;
64 * @brief Vector of character sets.
66 typedef Vector<_FcCharSet*> CharacterSetList;
69 * @brief FontClient implementation.
71 struct FontClient::Plugin
73 public: // Dali::TextAbstraction::FontClient
77 * Initializes the FreeType library.
78 * Initializes the dpi values.
80 * @param[in] horizontalDpi The horizontal dpi.
81 * @param[in] verticalDpi The vertical dpi.
83 Plugin(unsigned int horizontalDpi, unsigned int verticalDpi);
88 * Frees any allocated resource.
93 * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
95 void ClearCache() const;
98 * @copydoc Dali::TextAbstraction::FontClient::ClearCacheOnLocaleChanged()
100 void ClearCacheOnLocaleChanged() const;
103 * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
105 void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi);
108 * @copydoc Dali::TextAbstraction::FontClient::ResetSystemDefaults()
110 void ResetSystemDefaults() const;
113 * @copydoc Dali::TextAbstraction::FontClient::InitDefaultFontDescription()
115 void InitDefaultFontDescription() const;
118 * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
120 void GetDefaultPlatformFontDescription(FontDescription& fontDescription) const;
123 * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
125 void GetDefaultFonts(FontList& defaultFonts) const;
128 * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
130 void GetSystemFonts(FontList& systemFonts) const;
133 * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
135 void GetDescription(FontId fontId, FontDescription& fontDescription) const;
138 * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
140 PointSize26Dot6 GetPointSize(FontId fontId) const;
143 * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
145 bool IsCharacterSupportedByFont(FontId fontId, Character character) const;
148 * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
150 FontId FindDefaultFont(Character charcode,
151 PointSize26Dot6 requestedPointSize,
152 bool preferColor) const;
155 * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
157 FontId FindFallbackFont(Character charcode,
158 const FontDescription& preferredFontDescription,
159 PointSize26Dot6 requestedPointSize,
160 bool preferColor) const;
163 * @see Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
165 * @param[in] cacheDescription Whether to cache the font description.
167 FontId GetFontIdByPath(const FontPath& path,
168 PointSize26Dot6 requestedPointSize,
170 bool cacheDescription) const;
173 * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& preferredFontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
175 FontId GetFontId(const FontDescription& fontDescription,
176 PointSize26Dot6 requestedPointSize,
177 FaceIndex faceIndex) const;
180 * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
182 FontId GetFontId(const BitmapFont& bitmapFont) const;
185 * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
187 bool IsScalable(const FontPath& path) const;
190 * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
192 bool IsScalable(const FontDescription& fontDescription) const;
195 * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
197 void GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes) const;
200 * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
202 void GetFixedSizes(const FontDescription& fontDescription,
203 Dali::Vector<PointSize26Dot6>& sizes) const;
206 * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
208 bool HasItalicStyle(FontId fontId) const;
211 * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
213 void GetFontMetrics(FontId fontId, FontMetrics& metrics) const;
216 * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
218 GlyphIndex GetGlyphIndex(FontId fontId, Character charcode) const;
221 * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
223 GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector) const;
226 * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
228 bool GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal) const;
231 * Helper for GetGlyphMetrics when using bitmaps
233 bool GetBitmapMetrics(GlyphInfo* array, uint32_t size, bool horizontal) const;
236 * Helper for GetGlyphMetrics when using vectors
238 bool GetVectorMetrics(GlyphInfo* array, uint32_t size, bool horizontal) const;
241 * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth )
243 void CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth) const;
246 * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
248 PixelData CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth) const;
251 * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
253 void CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight) const;
256 * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
258 const GlyphInfo& GetEllipsisGlyph(PointSize26Dot6 requestedPointSize) const;
261 * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
263 bool IsColorGlyph(FontId fontId, GlyphIndex glyphIndex) const;
266 * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
268 GlyphIndex CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat) const;
271 * @copydoc Dali::TextAbstraction::FontClient::EnableAtlasLimitation(bool enabled)
273 void EnableAtlasLimitation(bool enabled);
276 * @copydoc Dali::TextAbstraction::FontClient::IsAtlasLimitationEnabled()
278 bool IsAtlasLimitationEnabled() const;
281 * @copydoc Dali::TextAbstraction::FontClient::GetMaximumTextAtlasSize()
283 Size GetMaximumTextAtlasSize() const;
286 * @copydoc Dali::TextAbstraction::FontClient::GetDefaultTextAtlasSize()
288 Size GetDefaultTextAtlasSize() const;
291 * @copydoc Dali::TextAbstraction::FontClient::GetCurrentMaximumBlockSizeFitInAtlas()
293 Size GetCurrentMaximumBlockSizeFitInAtlas() const;
296 * @copydoc Dali::TextAbstraction::FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
298 bool SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas);
301 * @copydoc Dali::TextAbstraction::FontClient::GetNumberOfPointsPerOneUnitOfPointSize()
303 uint32_t GetNumberOfPointsPerOneUnitOfPointSize() const;
306 * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
308 bool AddCustomFontDirectory(const FontPath& path);
310 public: // Dali::TextAbstraction::Internal::FontClient
312 * @copydoc Dali::TextAbstraction::Internal::FontClient::GetFreetypeFace()
314 FT_FaceRec_* GetFreetypeFace(FontId fontId) const;
317 * @copydoc Dali::TextAbstraction::Internal::FontClient::GetFontType()
319 FontDescription::Type GetFontType(FontId fontId) const;
322 * @copydoc Dali::TextAbstraction::Internal::FontClient::GetHarfBuzzFont()
324 HarfBuzzFontHandle GetHarfBuzzFont(FontId fontId) const;
327 * @copydoc Dali::TextAbstraction::Internal::FontClient::FontPreCache()
329 void FontPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily) const;
332 * @copydoc Dali::TextAbstraction::Internal::FontClient::FontPreLoad()
334 void FontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList) const;
338 * Get the cached font item for the given font
339 * @param[in] fontId The font id to search for
340 * @return the matching cached font item
342 const FontCacheItemInterface* GetCachedFontItem(FontId fontId) const;
345 * @brief Finds within the @p fontList a font which support the @p carcode.
347 * @param[in] fontList A list of font paths, family, width, weight and slant.
348 * @param[in] characterSetList A list that contains a character set for each description of the font list.
349 * @param[in] charcode The character for which a font is needed.
350 * @param[in] requestedPointSize The point size in 26.6 fractional points.
351 * @param[in] preferColor @e true if a color font is preferred.
353 * @return A valid font identifier, or zero if no font is found.
355 FontId FindFontForCharacter(const FontList& fontList,
356 const CharacterSetList& characterSetList,
358 PointSize26Dot6 requestedPointSize,
359 bool preferColor) const;
362 * @brief Creates a font.
364 * @param[in] path The path to the font file name.
365 * @param[in] requestedPointSize The requested point size.
366 * @param[in] faceIndex A face index.
367 * @param[in] cacheDescription Whether to cache the font description.
369 * @return The font identifier.
371 FontId CreateFont(const FontPath& path,
372 PointSize26Dot6 requestedPointSize,
374 bool cacheDescription) const;
378 * @brief Caches font data for the specified font path if it is not already cached.
380 * If the font data is not already cached, this function will load the font file
381 * from disk and cache the data for future use.
383 * @param[in] fontPath The font path to cache the data for.
385 void CacheFontDataFromFile(const std::string& fontPath) const;
388 * @brief Caches FreeType face for the specified font path if it is not already cached.
390 * If the font face is not already cached, this function will perform the new face
391 * from font file and cache the face for future use.
393 * @param[in] fontPath The font path to cache the face for.
395 void CacheFontFaceFromFile(const std::string& fontPath) const;
398 Plugin(const Plugin&) = delete;
399 Plugin& operator=(const Plugin&) = delete;
402 FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
404 unsigned int mDpiHorizontal; ///< Horizontal dpi.
405 unsigned int mDpiVertical; ///< Vertical dpi.
407 bool mIsAtlasLimitationEnabled : 1; ///< Whether the validation on maximum atlas block size, then reduce block size to fit into it is enabled or not.
408 Vector2 mCurrentMaximumBlockSizeFitInAtlas; ///< The current maximum size (width, height) of text-atlas-block.
411 VectorFontCache* mVectorFontCache; ///< Separate cache for vector data blobs etc.
414 CacheHandler* mCacheHandler; ///< Seperate cache for font data.
417 } // namespace Internal
419 } // namespace TextAbstraction
423 #endif // DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H