2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/text/text-abstraction/plugin/font-client-plugin-impl.h>
22 #include <dali/devel-api/text-abstraction/font-list.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/integration-api/platform-abstraction.h>
25 #include <dali/integration-api/trace.h>
26 #include <dali/internal/adaptor/common/adaptor-impl.h>
27 #include <dali/internal/imaging/common/image-operations.h>
28 #include <dali/internal/system/common/logging.h>
29 #include <dali/internal/text/text-abstraction/plugin/bitmap-font-cache-item.h>
30 #include <dali/internal/text/text-abstraction/plugin/embedded-item.h>
31 #include <dali/internal/text/text-abstraction/plugin/font-client-plugin-cache-handler.h>
32 #include <dali/internal/text/text-abstraction/plugin/font-client-utils.h>
33 #include <dali/internal/text/text-abstraction/plugin/font-face-cache-item.h>
34 #include <dali/public-api/common/dali-vector.h>
35 #include <dali/public-api/common/vector-wrapper.h>
38 #include <fontconfig/fontconfig.h>
42 // Use this macro only if need to log messages before the log function is set.
43 #define FONT_LOG_MESSAGE(level, format, ...) \
47 int result = std::snprintf(buffer, sizeof(buffer), format, ##__VA_ARGS__); \
48 if(result >= static_cast<int>(sizeof(buffer))) \
50 std::string log("Font log message is too long to fit in the buffer.\n"); \
51 Dali::TizenPlatform::LogMessage(Dali::Integration::Log::ERROR, log); \
54 std::string log(buffer); \
55 Dali::TizenPlatform::LogMessage(level, log); \
58 #if defined(DEBUG_ENABLED)
60 // Note, to turn on trace and verbose logging, use "export LOG_FONT_CLIENT=3,true"
61 // Or re-define the following filter using Verbose,true instead of NoLogging,false,
62 // Or, add DALI_LOG_FILTER_ENABLE_TRACE(gFontClientLogFilter) in the code below.
64 Dali::Integration::Log::Filter* gFontClientLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_FONT_CLIENT");
66 #define FONT_LOG_DESCRIPTION(fontDescription, prefix) \
67 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, #prefix " description; family : [%s]\n", fontDescription.family.c_str()); \
68 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, \
72 " slant : [%s]\n\n", \
73 fontDescription.path.c_str(), \
74 FontWidth::Name[fontDescription.width], \
75 FontWeight::Name[fontDescription.weight], \
76 FontSlant::Name[fontDescription.slant])
78 #define FONT_LOG_REQUEST(charcode, requestedPointSize, preferColor) \
79 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, \
81 " requestedPointSize : %d\n" \
82 " preferColor : %s\n", \
85 (preferColor ? "true" : "false"))
89 #define FONT_LOG_DESCRIPTION(fontDescription, prefix)
90 #define FONT_LOG_REQUEST(charcode, requestedPointSize, preferColor)
96 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_FONT_PERFORMANCE_MARKER, false);
99 * Conversion from Fractional26.6 to float
101 const float FROM_266 = 1.0f / 64.0f;
102 const float POINTS_PER_INCH = 72.f;
104 const uint32_t ELLIPSIS_CHARACTER = 0x2026;
110 namespace Dali::TextAbstraction::Internal
115 * @brief Check if @p ftFace and @p requestedPointSize produces block that fit into atlas block
117 * @param[in/out] ftFace Face type object.
118 * @param[in] horizontalDpi The horizontal dpi.
119 * @param[in] verticalDpi The vertical dpi.
120 * @param[in] maxSizeFitInAtlas The maximum size of block to fit into atlas
121 * @param[in] requestedPointSize The requested point-size.
122 * @return whether the ftFace's block can fit into atlas
124 bool IsFitIntoAtlas(FT_Face& ftFace, int& error, const unsigned int& horizontalDpi, const unsigned int& verticalDpi, const Size& maxSizeFitInAtlas, const uint32_t& requestedPointSize)
128 error = FT_Set_Char_Size(ftFace,
130 FT_F26Dot6(requestedPointSize),
134 if(error == FT_Err_Ok)
136 //Check width and height of block for requestedPointSize
137 //If the width or height is greater than the maximum-size then decrement by one unit of point-size.
138 if(static_cast<float>(ftFace->size->metrics.height) * FROM_266 <= maxSizeFitInAtlas.height && (static_cast<float>(ftFace->size->metrics.ascender) - static_cast<float>(ftFace->size->metrics.descender)) * FROM_266 <= maxSizeFitInAtlas.width)
148 * @brief Search on proper @p requestedPointSize that produces block that fit into atlas block considering on @p ftFace, @p horizontalDpi, and @p verticalDpi
150 * @param[in/out] ftFace Face type object.
151 * @param[in] horizontalDpi The horizontal dpi.
152 * @param[in] verticalDpi The vertical dpi.
153 * @param[in] maxSizeFitInAtlas The maximum size of block to fit into atlas
154 * @param[in/out] requestedPointSize The requested point-size.
155 * @return FreeType error code. 0 means success when requesting the nominal size (in points).
157 int SearchOnProperPointSize(FT_Face& ftFace, const unsigned int& horizontalDpi, const unsigned int& verticalDpi, const Size& maxSizeFitInAtlas, uint32_t& requestedPointSize)
159 //To improve performance of sequential search. This code is applying Exponential search then followed by Binary search.
160 const uint32_t& pointSizePerOneUnit = TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
162 int error; // FreeType error code.
164 canFitInAtlas = IsFitIntoAtlas(ftFace, error, horizontalDpi, verticalDpi, maxSizeFitInAtlas, requestedPointSize);
165 if(FT_Err_Ok != error)
173 uint32_t exponentialDecrement = 1;
175 while(!canFitInAtlas && requestedPointSize > pointSizePerOneUnit * exponentialDecrement)
177 requestedPointSize -= (pointSizePerOneUnit * exponentialDecrement);
178 canFitInAtlas = IsFitIntoAtlas(ftFace, error, horizontalDpi, verticalDpi, maxSizeFitInAtlas, requestedPointSize);
179 if(FT_Err_Ok != error)
184 exponentialDecrement *= 2;
188 uint32_t minPointSize;
189 uint32_t maxPointSize;
193 exponentialDecrement /= 2;
194 minPointSize = requestedPointSize;
195 maxPointSize = requestedPointSize + (pointSizePerOneUnit * exponentialDecrement);
200 maxPointSize = requestedPointSize;
203 while(minPointSize < maxPointSize)
205 requestedPointSize = ((maxPointSize / pointSizePerOneUnit - minPointSize / pointSizePerOneUnit) / 2) * pointSizePerOneUnit + minPointSize;
206 canFitInAtlas = IsFitIntoAtlas(ftFace, error, horizontalDpi, verticalDpi, maxSizeFitInAtlas, requestedPointSize);
207 if(FT_Err_Ok != error)
214 if(minPointSize == requestedPointSize)
216 //Found targeted point-size
220 minPointSize = requestedPointSize;
224 maxPointSize = requestedPointSize;
234 FontClient::Plugin::Plugin(unsigned int horizontalDpi,
235 unsigned int verticalDpi)
236 : mFreeTypeLibrary(nullptr),
237 mDpiHorizontal(horizontalDpi),
238 mDpiVertical(verticalDpi),
239 mIsAtlasLimitationEnabled(TextAbstraction::FontClient::DEFAULT_ATLAS_LIMITATION_ENABLED),
240 mCurrentMaximumBlockSizeFitInAtlas(TextAbstraction::FontClient::MAX_SIZE_FIT_IN_ATLAS),
241 mVectorFontCache(nullptr),
242 mCacheHandler(new CacheHandler())
244 int error = FT_Init_FreeType(&mFreeTypeLibrary);
245 if(FT_Err_Ok != error)
247 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FreeType Init error: %d\n", error);
250 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
251 mVectorFontCache = new VectorFontCache(mFreeTypeLibrary);
255 FontClient::Plugin::~Plugin()
257 // Delete cache hanlder before remove mFreeTypeLibrary
258 delete mCacheHandler;
260 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
261 delete mVectorFontCache;
264 FT_Done_FreeType(mFreeTypeLibrary);
267 void FontClient::Plugin::ClearCache() const
269 mCacheHandler->ClearCache();
272 void FontClient::Plugin::SetDpi(unsigned int horizontalDpi,
273 unsigned int verticalDpi)
275 mDpiHorizontal = horizontalDpi;
276 mDpiVertical = verticalDpi;
279 void FontClient::Plugin::ResetSystemDefaults() const
281 mCacheHandler->ResetSystemDefaults();
284 void FontClient::Plugin::CacheFontDataFromFile(const std::string& fontPath) const
291 if(mCacheHandler->FindFontData(fontPath))
293 // Font data is already cached, no need to reload
297 Dali::Vector<uint8_t> fontDataBuffer;
298 std::streampos dataSize = 0;
299 if(!mCacheHandler->LoadFontDataFromFile(fontPath, fontDataBuffer, dataSize))
301 fontDataBuffer.Clear();
302 FONT_LOG_MESSAGE(Dali::Integration::Log::ERROR, "Failed to load font data : %s\n", fontPath.c_str());
307 mCacheHandler->CacheFontData(fontPath, fontDataBuffer, dataSize);
310 void FontClient::Plugin::CacheFontFaceFromFile(const std::string& fontPath) const
317 if(mCacheHandler->FindFontFace(fontPath))
319 // Font face is already cached, no need to reload
324 int error = FT_New_Face(mFreeTypeLibrary, fontPath.c_str(), 0, &ftFace);
325 if(FT_Err_Ok != error)
327 FONT_LOG_MESSAGE(Dali::Integration::Log::ERROR, "Failed to load font face : %s\n", fontPath.c_str());
332 mCacheHandler->CacheFontFace(fontPath, ftFace);
333 FONT_LOG_MESSAGE(Dali::Integration::Log::INFO, "PreLoad font new face : %s\n", fontPath.c_str());
336 void FontClient::Plugin::FontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList) const
338 for(const auto& fontPath : fontPathList)
340 CacheFontFaceFromFile(fontPath);
343 for(const auto& memoryFontPath : memoryFontPathList)
345 CacheFontDataFromFile(memoryFontPath);
349 void FontClient::Plugin::FontPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily) const
351 mCacheHandler->InitDefaultFontDescription();
353 FontFamilyList familyList;
354 familyList.reserve(extraFamilyList.size() + 1);
356 for(const auto& fallbackFont : fallbackFamilyList)
358 FontList* fontList = nullptr;
359 CharacterSetList* characterSetList = nullptr;
360 FontDescriptionId fontDescriptionId = 0u;
361 FontDescription fontDescription;
362 fontDescription.family = FontFamily(fallbackFont);
363 fontDescription.weight = DefaultFontWeight();
364 fontDescription.width = DefaultFontWidth();
365 fontDescription.slant = DefaultFontSlant();
367 if(!mCacheHandler->FindFallbackFontList(fontDescription, fontList, characterSetList))
369 FontDescription copiedFontDescription = fontDescription;
370 mCacheHandler->CacheFallbackFontList(std::move(copiedFontDescription), fontList, characterSetList);
372 if(!mCacheHandler->FindValidatedFont(fontDescription, fontDescriptionId))
374 mCacheHandler->ValidateFont(fontDescription, fontDescriptionId);
377 if(extraFamilyList.empty() && localeFamily.empty())
383 familyList.insert(familyList.end(), extraFamilyList.begin(), extraFamilyList.end());
384 if(!localeFamily.empty())
386 familyList.push_back(localeFamily);
389 for(const auto& font : *fontList)
391 auto it = std::find(familyList.begin(), familyList.end(), font.family);
392 if(it != familyList.end())
394 if(!mCacheHandler->FindValidatedFont(font, fontDescriptionId))
396 mCacheHandler->ValidateFont(font, fontDescriptionId);
398 familyList.erase(it);
404 void FontClient::Plugin::InitDefaultFontDescription() const
406 mCacheHandler->InitDefaultFontDescription();
409 void FontClient::Plugin::GetDefaultPlatformFontDescription(FontDescription& fontDescription) const
411 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
413 mCacheHandler->InitDefaultFontDescription();
414 fontDescription = mCacheHandler->mDefaultFontDescription;
416 FONT_LOG_DESCRIPTION(fontDescription, "");
419 void FontClient::Plugin::GetDefaultFonts(FontList& defaultFonts) const
421 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
423 mCacheHandler->InitDefaultFonts();
424 defaultFonts = mCacheHandler->mDefaultFonts;
426 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " number of default fonts : [%d]\n", mCacheHandler->mDefaultFonts.size());
429 void FontClient::Plugin::GetSystemFonts(FontList& systemFonts) const
431 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
433 mCacheHandler->InitSystemFonts();
434 systemFonts = mCacheHandler->mSystemFonts;
436 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " number of system fonts : [%d]\n", mCacheHandler->mSystemFonts.size());
439 void FontClient::Plugin::GetDescription(FontId fontId,
440 FontDescription& fontDescription) const
442 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
443 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
445 if((fontId > 0u) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
447 const auto& fontIdCacheItem = mCacheHandler->mFontIdCache[fontId - 1u];
448 switch(fontIdCacheItem.type)
450 case FontDescription::FACE_FONT:
452 for(const auto& item : mCacheHandler->mFontDescriptionSizeCache)
454 if(item.second == fontIdCacheItem.index)
456 fontDescription = *(mCacheHandler->mFontDescriptionCache.begin() + item.first.fontDescriptionId - 1u);
458 FONT_LOG_DESCRIPTION(fontDescription, "");
464 case FontDescription::BITMAP_FONT:
466 fontDescription.type = FontDescription::BITMAP_FONT;
467 fontDescription.family = mCacheHandler->mBitmapFontCache[fontIdCacheItem.index].font.name;
472 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " Invalid type of font\n");
473 fontDescription.type = FontDescription::INVALID;
474 fontDescription.family.clear();
479 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " No description found for the font id %d\n", fontId);
482 PointSize26Dot6 FontClient::Plugin::GetPointSize(FontId fontId) const
484 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
485 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
487 PointSize26Dot6 pointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
488 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
489 if(fontCacheItem != nullptr)
491 pointSize = fontCacheItem->GetPointSize();
493 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " point size : %d\n", pointSize);
498 bool FontClient::Plugin::IsCharacterSupportedByFont(FontId fontId, Character character) const
500 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
501 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
502 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " character : %p\n", character);
504 bool isSupported = false;
505 auto fontCacheItem = const_cast<FontCacheItemInterface*>(GetCachedFontItem(fontId));
506 if(fontCacheItem != nullptr)
508 isSupported = fontCacheItem->IsCharacterSupported(character); // May cache
511 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " is supported : %s\n", (isSupported ? "true" : "false"));
515 const FontCacheItemInterface* FontClient::Plugin::GetCachedFontItem(FontId fontId) const
517 if((fontId > 0u) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
519 const auto& fontIdCacheItem = mCacheHandler->mFontIdCache[fontId - 1u];
520 switch(fontIdCacheItem.type)
522 case FontDescription::FACE_FONT:
524 return &mCacheHandler->mFontFaceCache[fontIdCacheItem.index];
526 case FontDescription::BITMAP_FONT:
528 return &mCacheHandler->mBitmapFontCache[fontIdCacheItem.index];
532 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " Invalid type of font\n");
539 FontId FontClient::Plugin::FindFontForCharacter(const FontList& fontList,
540 const CharacterSetList& characterSetList,
542 PointSize26Dot6 requestedPointSize,
543 bool preferColor) const
545 DALI_ASSERT_DEBUG((fontList.size() == characterSetList.Count()) && "FontClient::Plugin::FindFontForCharacter. Different number of fonts and character sets.");
546 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
547 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " character : %p\n", character);
548 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
549 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " preferColor : %s\n", (preferColor ? "true" : "false"));
552 bool foundColor = false;
554 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " number of fonts : %d\n", fontList.size());
556 // Traverse the list of fonts.
557 // Check for each font if supports the character.
558 for(unsigned int index = 0u, numberOfFonts = fontList.size(); index < numberOfFonts; ++index)
560 const FontDescription& description = fontList[index];
561 const FcCharSet* const characterSet = characterSetList[index];
563 FONT_LOG_DESCRIPTION(description, "");
565 bool foundInRanges = false;
566 if(nullptr != characterSet)
568 foundInRanges = FcCharSetHasChar(characterSet, character);
573 fontId = GetFontId(description, requestedPointSize, 0u);
575 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " font id : %d\n", fontId);
579 if((fontId > 0) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
581 const FontFaceCacheItem& item = mCacheHandler->mFontFaceCache[mCacheHandler->mFontIdCache[fontId - 1u].index];
583 foundColor = item.mHasColorTables;
586 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " foundColor : %s\n", (foundColor ? "true" : "false"));
589 // Keep going unless we prefer a different (color) font.
590 if(!preferColor || foundColor)
597 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
601 FontId FontClient::Plugin::FindDefaultFont(Character charcode,
602 PointSize26Dot6 requestedPointSize,
603 bool preferColor) const
605 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
606 FONT_LOG_REQUEST(charcode, requestedPointSize, preferColor);
610 // Create the list of default fonts if it has not been created.
611 mCacheHandler->InitDefaultFonts();
612 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " number of default fonts : %d\n", mCacheHandler->mDefaultFonts.size());
614 // Traverse the list of default fonts.
615 // Check for each default font if supports the character.
616 fontId = FindFontForCharacter(mCacheHandler->mDefaultFonts, mCacheHandler->mDefaultFontCharacterSets, charcode, requestedPointSize, preferColor);
618 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
622 FontId FontClient::Plugin::FindFallbackFont(Character charcode,
623 const FontDescription& preferredFontDescription,
624 PointSize26Dot6 requestedPointSize,
625 bool preferColor) const
627 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
628 FONT_LOG_REQUEST(charcode, requestedPointSize, preferColor);
630 DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_FIND_FALLBACKFONT");
632 // The font id to be returned.
635 FontDescription fontDescription;
637 // Fill the font description with the preferred font description and complete with the defaults.
638 fontDescription.family = preferredFontDescription.family.empty() ? DefaultFontFamily() : preferredFontDescription.family;
639 fontDescription.weight = ((FontWeight::NONE == preferredFontDescription.weight) ? DefaultFontWeight() : preferredFontDescription.weight);
640 fontDescription.width = ((FontWidth::NONE == preferredFontDescription.width) ? DefaultFontWidth() : preferredFontDescription.width);
641 fontDescription.slant = ((FontSlant::NONE == preferredFontDescription.slant) ? DefaultFontSlant() : preferredFontDescription.slant);
643 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " preferredFontDescription --> fontDescription\n");
644 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " [%s] --> [%s]\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str());
645 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWeight::Name[preferredFontDescription.weight], FontWeight::Name[fontDescription.weight]);
646 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWidth::Name[preferredFontDescription.width], FontWidth::Name[fontDescription.width]);
647 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontSlant::Name[preferredFontDescription.slant], FontSlant::Name[fontDescription.slant]);
649 #if defined(TRACE_ENABLED)
650 if(gTraceFilter && gTraceFilter->IsTraceEnabled())
652 DALI_LOG_DEBUG_INFO("DALI_TEXT_FIND_FALLBACKFONT : %s -> %s\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str());
656 // Check first if the font's description has been queried before.
657 FontList* fontList = nullptr;
658 CharacterSetList* characterSetList = nullptr;
660 if(!mCacheHandler->FindFallbackFontList(fontDescription, fontList, characterSetList))
662 mCacheHandler->CacheFallbackFontList(std::move(fontDescription), fontList, characterSetList);
665 if(fontList && characterSetList)
667 fontId = FindFontForCharacter(*fontList, *characterSetList, charcode, requestedPointSize, preferColor);
670 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
674 FontId FontClient::Plugin::GetFontIdByPath(const FontPath& path,
675 PointSize26Dot6 requestedPointSize,
677 bool cacheDescription) const
679 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
680 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " path : [%s]\n", path.c_str());
681 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
685 if(nullptr != mFreeTypeLibrary)
688 if(mCacheHandler->FindFontByPath(path, requestedPointSize, faceIndex, foundId))
694 id = CreateFont(path, requestedPointSize, faceIndex, cacheDescription);
698 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", id);
702 FontId FontClient::Plugin::GetFontId(const FontDescription& fontDescription,
703 PointSize26Dot6 requestedPointSize,
704 FaceIndex faceIndex) const
706 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
707 FONT_LOG_DESCRIPTION(fontDescription, "");
709 // Special case when font Description don't have family information.
710 // In this case, we just use default description family and path.
711 const FontDescription& realFontDescription = fontDescription.family.empty() ? FontDescription(mCacheHandler->mDefaultFontDescription.path,
712 mCacheHandler->mDefaultFontDescription.family,
713 fontDescription.width,
714 fontDescription.weight,
715 fontDescription.slant,
716 fontDescription.type)
719 FONT_LOG_DESCRIPTION(realFontDescription, "");
720 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
722 // This method uses three vectors which caches:
723 // * The bitmap font cache
724 // * Pairs of non validated font descriptions and an index to a vector with paths to font file names.
725 // * The path to font file names.
726 // * The font ids of pairs 'font point size, index to the vector with paths to font file names'.
728 // 1) Checks if the font description matches with a previously loaded bitmap font.
729 // Returns if a font is found.
730 // 2) Checks in the cache if the font's description has been validated before.
731 // If it was it gets an index to the vector with paths to font file names. Otherwise,
732 // retrieves using font config a path to a font file name which matches with the
733 // font's description. The path is stored in the cache.
735 // 3) Checks in the cache if the pair 'font point size, index to the vector with paths to
736 // font file names' exists. If exists, it gets the font id. If it doesn't it calls
737 // the GetFontId() method with the path to the font file name and the point size to
740 // The font id to be returned.
743 // Check first if the font description matches with a previously loaded bitmap font.
744 if(mCacheHandler->FindBitmapFont(realFontDescription.family, fontId))
749 // Check if the font's description have been validated before.
750 FontDescriptionId fontDescriptionId = 0u;
752 if(!mCacheHandler->FindValidatedFont(realFontDescription, fontDescriptionId))
754 // Use font config to validate the font's description.
755 mCacheHandler->ValidateFont(realFontDescription, fontDescriptionId);
758 using FontCacheIndex = CacheHandler::FontCacheIndex;
759 FontCacheIndex fontCacheIndex = 0u;
760 // Check if exists a pair 'fontDescriptionId, requestedPointSize' in the cache.
761 if(!mCacheHandler->FindFont(fontDescriptionId, requestedPointSize, fontCacheIndex))
763 // Retrieve the font file name path.
764 const FontDescription& description = *(mCacheHandler->mFontDescriptionCache.begin() + fontDescriptionId - 1u);
766 // Retrieve the font id. Do not cache the description as it has been already cached.
767 // Note : CacheFontPath() API call ValidateFont() + setup CharacterSet + cache the font description.
768 // So set cacheDescription=false, that we don't call CacheFontPath().
769 fontId = GetFontIdByPath(description.path, requestedPointSize, faceIndex, false);
771 if((fontId > 0u) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
773 fontCacheIndex = mCacheHandler->mFontIdCache[fontId - 1u].index;
774 mCacheHandler->mFontFaceCache[fontCacheIndex].mCharacterSet = FcCharSetCopy(mCacheHandler->mCharacterSetCache[fontDescriptionId - 1u]);
776 // Cache the pair 'fontDescriptionId, requestedPointSize' to improve the following queries.
777 mCacheHandler->CacheFontDescriptionSize(fontDescriptionId, requestedPointSize, fontCacheIndex);
782 fontId = mCacheHandler->mFontFaceCache[fontCacheIndex].mFontId + 1u;
785 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
789 FontId FontClient::Plugin::GetFontId(const BitmapFont& bitmapFont) const
791 // The font id to be returned.
793 if(!mCacheHandler->FindBitmapFont(bitmapFont.name, fontId))
795 BitmapFontCacheItem bitmapFontCacheItem(bitmapFont);
797 fontId = mCacheHandler->CacheBitmapFontCacheItem(std::move(bitmapFontCacheItem));
802 void FontClient::Plugin::GetFontMetrics(FontId fontId,
803 FontMetrics& metrics) const
805 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
806 if(fontCacheItem != nullptr)
808 fontCacheItem->GetFontMetrics(metrics, mDpiVertical);
812 GlyphIndex FontClient::Plugin::GetGlyphIndex(FontId fontId,
813 Character charcode) const
815 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
816 if(fontCacheItem != nullptr)
818 return fontCacheItem->GetGlyphIndex(charcode);
824 GlyphIndex FontClient::Plugin::GetGlyphIndex(FontId fontId,
826 Character variantSelector) const
828 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
829 if(fontCacheItem != nullptr)
831 return fontCacheItem->GetGlyphIndex(charcode, variantSelector);
837 bool FontClient::Plugin::GetGlyphMetrics(GlyphInfo* array,
840 bool horizontal) const
842 if(VECTOR_GLYPH == type)
844 return GetVectorMetrics(array, size, horizontal);
847 return GetBitmapMetrics(array, size, horizontal);
850 bool FontClient::Plugin::GetBitmapMetrics(GlyphInfo* array,
852 bool horizontal) const
854 bool success(size > 0u);
856 for(unsigned int i = 0; i < size; ++i)
858 GlyphInfo& glyph = array[i];
860 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(glyph.fontId);
861 if(fontCacheItem != nullptr)
863 success &= fontCacheItem->GetGlyphMetrics(glyph, mDpiVertical, horizontal);
865 // Check if it's an embedded image.
866 else if((0u == glyph.fontId) && (0u != glyph.index) && (glyph.index <= mCacheHandler->mEmbeddedItemCache.size()))
868 mCacheHandler->mEmbeddedItemCache[glyph.index - 1u].GetGlyphMetrics(glyph);
879 bool FontClient::Plugin::GetVectorMetrics(GlyphInfo* array,
881 bool horizontal) const
883 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
886 for(unsigned int i = 0u; i < size; ++i)
888 FontId fontId = array[i].fontId;
891 (fontId - 1u) < mCacheHandler->mFontIdCache.size())
893 FontFaceCacheItem& font = mCacheHandler->mFontFaceCache[mCacheHandler->mFontIdCache[fontId - 1u].index];
895 if(!font.mVectorFontId)
897 font.mVectorFontId = mVectorFontCache->GetFontId(font.mPath);
900 mVectorFontCache->GetGlyphMetrics(font.mVectorFontId, array[i]);
902 // Vector metrics are in EMs, convert to pixels
903 const float scale = (static_cast<float>(font.mRequestedPointSize) * FROM_266) * static_cast<float>(mDpiVertical) / POINTS_PER_INCH;
904 array[i].width *= scale;
905 array[i].height *= scale;
906 array[i].xBearing *= scale;
907 array[i].yBearing *= scale;
908 array[i].advance *= scale;
922 void FontClient::Plugin::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth) const
924 data.isColorBitmap = false;
925 data.isColorEmoji = false;
926 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
927 if(fontCacheItem != nullptr)
929 fontCacheItem->CreateBitmap(glyphIndex, data, outlineWidth, isItalicRequired, isBoldRequired);
931 else if((0u != glyphIndex) && (glyphIndex <= mCacheHandler->mEmbeddedItemCache.size()))
933 // It's an embedded item.
934 mCacheHandler->mEmbeddedItemCache[glyphIndex - 1u].CreateBitmap(mCacheHandler->mPixelBufferCache, data);
938 PixelData FontClient::Plugin::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth) const
940 TextAbstraction::GlyphBufferData data;
942 CreateBitmap(fontId, glyphIndex, false, false, data, outlineWidth);
944 // If data is compressed or not owned buffer, copy this.
945 if(!data.isBufferOwned || data.compressionType != TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION)
947 uint8_t* newBuffer = (uint8_t*)malloc(data.width * data.height * Pixel::GetBytesPerPixel(data.format));
948 TextAbstraction::GlyphBufferData::Decompress(data, newBuffer);
949 if(data.isBufferOwned)
954 data.buffer = newBuffer;
955 data.isBufferOwned = true;
956 data.compressionType = TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION;
959 return PixelData::New(data.buffer,
960 data.width * data.height * Pixel::GetBytesPerPixel(data.format),
967 void FontClient::Plugin::CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight) const
972 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
974 (fontId - 1u < mCacheHandler->mFontIdCache.size()))
976 using FontCacheIndex = CacheHandler::FontCacheIndex;
977 const FontCacheIndex fontCacheIndex = mCacheHandler->mFontIdCache[fontId - 1u].index;
978 FontFaceCacheItem& font = mCacheHandler->mFontFaceCache[fontCacheIndex];
980 if(!font.mVectorFontId)
982 font.mVectorFontId = mVectorFontCache->GetFontId(font.mPath);
985 mVectorFontCache->GetVectorBlob(font.mVectorFontId, fontCacheIndex, glyphIndex, blob, blobLength, nominalWidth, nominalHeight);
990 const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph(PointSize26Dot6 requestedPointSize) const
992 using EllipsisCacheIndex = CacheHandler::EllipsisCacheIndex;
993 using EllipsisItem = CacheHandler::EllipsisItem;
994 EllipsisCacheIndex ellipsisCacheIndex = 0u;
996 if(!mCacheHandler->FindEllipsis(requestedPointSize, ellipsisCacheIndex))
998 // No glyph has been found. Create one.
1001 item.requestedPointSize = requestedPointSize;
1002 item.index = ellipsisCacheIndex;
1004 // Find a font for the ellipsis glyph.
1005 item.glyph.fontId = FindDefaultFont(ELLIPSIS_CHARACTER,
1009 // Set the character index to access the glyph inside the font.
1010 item.glyph.index = GetGlyphIndex(item.glyph.fontId, ELLIPSIS_CHARACTER);
1012 // Get glyph informations.
1013 GetBitmapMetrics(&item.glyph, 1u, true);
1015 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index);
1016 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font %d.\n", item.glyph.fontId);
1018 ellipsisCacheIndex = mCacheHandler->CacheEllipsis(std::move(item));
1020 return mCacheHandler->mEllipsisCache[ellipsisCacheIndex].glyph;
1023 bool FontClient::Plugin::IsColorGlyph(FontId fontId, GlyphIndex glyphIndex) const
1025 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1026 return fontCacheItem && fontCacheItem->IsColorGlyph(glyphIndex);
1029 FT_FaceRec_* FontClient::Plugin::GetFreetypeFace(FontId fontId) const
1031 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1032 if(fontCacheItem != nullptr)
1034 return fontCacheItem->GetTypeface();
1039 FontDescription::Type FontClient::Plugin::GetFontType(FontId fontId) const
1041 const FontId index = fontId - 1u;
1042 if((fontId > 0u) && (index < mCacheHandler->mFontIdCache.size()))
1044 return mCacheHandler->mFontIdCache[index].type;
1046 return FontDescription::INVALID;
1049 bool FontClient::Plugin::AddCustomFontDirectory(const FontPath& path)
1051 // nullptr as first parameter means the current configuration is used.
1052 return FcConfigAppFontAddDir(nullptr, reinterpret_cast<const FcChar8*>(path.c_str()));
1055 HarfBuzzFontHandle FontClient::Plugin::GetHarfBuzzFont(FontId fontId) const
1057 FontCacheItemInterface* fontCacheItem = const_cast<FontCacheItemInterface*>(GetCachedFontItem(fontId));
1058 if(fontCacheItem != nullptr)
1060 return fontCacheItem->GetHarfBuzzFont(mDpiHorizontal, mDpiVertical); // May cache
1065 GlyphIndex FontClient::Plugin::CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat) const
1067 EmbeddedItem embeddedItem;
1069 embeddedItem.pixelBufferId = 0u;
1070 embeddedItem.width = description.width;
1071 embeddedItem.height = description.height;
1073 pixelFormat = Pixel::A8;
1075 if(!description.url.empty())
1077 // Check if the url is in the cache.
1078 Devel::PixelBuffer pixelBuffer;
1079 if(!mCacheHandler->FindEmbeddedPixelBufferId(description.url, embeddedItem.pixelBufferId))
1081 // The pixel buffer is not in the cache. Create one and cache it.
1082 embeddedItem.pixelBufferId = mCacheHandler->CacheEmbeddedPixelBuffer(description.url);
1085 if((embeddedItem.pixelBufferId > 0u) && (embeddedItem.pixelBufferId - 1u) < mCacheHandler->mPixelBufferCache.size())
1087 // Retrieve the pixel buffer from the cache to set the pixel format.
1088 pixelBuffer = mCacheHandler->mPixelBufferCache[embeddedItem.pixelBufferId - 1u].pixelBuffer;
1093 // Set the size of the embedded item if it has not been set.
1094 if(0u == embeddedItem.width)
1096 embeddedItem.width = static_cast<unsigned int>(pixelBuffer.GetWidth());
1099 if(0u == embeddedItem.height)
1101 embeddedItem.height = static_cast<unsigned int>(pixelBuffer.GetHeight());
1104 // Set the pixel format.
1105 pixelFormat = pixelBuffer.GetPixelFormat();
1109 // Find if the same embeddedItem has already been created.
1110 GlyphIndex index = 0u;
1111 if(!mCacheHandler->FindEmbeddedItem(embeddedItem.pixelBufferId, embeddedItem.width, embeddedItem.height, index))
1113 index = mCacheHandler->CacheEmbeddedItem(std::move(embeddedItem));
1118 void FontClient::Plugin::EnableAtlasLimitation(bool enabled)
1120 mIsAtlasLimitationEnabled = enabled;
1123 bool FontClient::Plugin::IsAtlasLimitationEnabled() const
1125 return mIsAtlasLimitationEnabled;
1128 Size FontClient::Plugin::GetMaximumTextAtlasSize() const
1130 return TextAbstraction::FontClient::MAX_TEXT_ATLAS_SIZE;
1133 Size FontClient::Plugin::GetDefaultTextAtlasSize() const
1135 return TextAbstraction::FontClient::DEFAULT_TEXT_ATLAS_SIZE;
1138 Size FontClient::Plugin::GetCurrentMaximumBlockSizeFitInAtlas() const
1140 return mCurrentMaximumBlockSizeFitInAtlas;
1143 bool FontClient::Plugin::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
1145 bool isChanged = false;
1146 const Size& maxTextAtlasSize = TextAbstraction::FontClient::MAX_TEXT_ATLAS_SIZE;
1147 const uint16_t& padding = TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK;
1149 if(currentMaximumBlockSizeFitInAtlas.width <= maxTextAtlasSize.width - padding && currentMaximumBlockSizeFitInAtlas.height <= maxTextAtlasSize.height - padding)
1151 mCurrentMaximumBlockSizeFitInAtlas = currentMaximumBlockSizeFitInAtlas;
1158 uint32_t FontClient::Plugin::GetNumberOfPointsPerOneUnitOfPointSize() const
1160 return TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
1163 FontId FontClient::Plugin::CreateFont(const FontPath& path,
1164 PointSize26Dot6 requestedPointSize,
1165 FaceIndex faceIndex,
1166 bool cacheDescription) const
1168 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
1169 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " path : [%s]\n", path.c_str());
1170 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
1172 DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_CREATE_FONT");
1178 uint8_t* fontDataPtr = nullptr;
1179 std::streampos dataSize = 0;
1180 bool fontDataFound = mCacheHandler->FindFontData(path, fontDataPtr, dataSize);
1184 // Create & cache new font face from pre-loaded font
1185 error = FT_New_Memory_Face(mFreeTypeLibrary, reinterpret_cast<FT_Byte*>(fontDataPtr), static_cast<FT_Long>(dataSize), 0, &ftFace);
1186 #if defined(TRACE_ENABLED)
1187 if(gTraceFilter && gTraceFilter->IsTraceEnabled())
1189 DALI_LOG_DEBUG_INFO("DALI_TEXT_CREATE_FONT : FT_New_Memory_Face : %s\n", path.c_str());
1195 // Create & cache new font face
1196 error = FT_New_Face(mFreeTypeLibrary, path.c_str(), 0, &ftFace);
1197 #if defined(TRACE_ENABLED)
1198 if(gTraceFilter && gTraceFilter->IsTraceEnabled())
1200 DALI_LOG_DEBUG_INFO("DALI_TEXT_CREATE_FONT : FT_New_Face : %s\n", path.c_str());
1205 if(FT_Err_Ok == error)
1207 // Check if a font is scalable.
1208 const bool isScalable = (0 != (ftFace->face_flags & FT_FACE_FLAG_SCALABLE));
1209 const bool hasFixedSizedBitmaps = (0 != (ftFace->face_flags & FT_FACE_FLAG_FIXED_SIZES)) && (0 != ftFace->num_fixed_sizes);
1210 const bool hasColorTables = (0 != (ftFace->face_flags & FT_FACE_FLAG_COLOR));
1212 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " isScalable : [%s]\n", (isScalable ? "true" : "false"));
1213 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " hasFixedSizedBitmaps : [%s]\n", (hasFixedSizedBitmaps ? "true" : "false"));
1214 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " hasColorTables : [%s]\n", (hasColorTables ? "true" : "false"));
1216 // Check to see if the font contains fixed sizes?
1217 if(!isScalable && hasFixedSizedBitmaps)
1219 PointSize26Dot6 actualPointSize = 0u;
1220 int fixedSizeIndex = 0;
1221 for(; fixedSizeIndex < ftFace->num_fixed_sizes; ++fixedSizeIndex)
1223 const PointSize26Dot6 fixedSize = static_cast<PointSize26Dot6>(ftFace->available_sizes[fixedSizeIndex].size);
1224 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " size index : %d, size : %d\n", fixedSizeIndex, fixedSize);
1226 if(fixedSize >= requestedPointSize)
1228 actualPointSize = fixedSize;
1233 if(0u == actualPointSize)
1235 // The requested point size is bigger than the bigest fixed size.
1236 fixedSizeIndex = ftFace->num_fixed_sizes - 1;
1237 actualPointSize = static_cast<PointSize26Dot6>(ftFace->available_sizes[fixedSizeIndex].size);
1240 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " size index : %d, actual size : %d\n", fixedSizeIndex, actualPointSize);
1242 // Tell Freetype to use this size
1243 error = FT_Select_Size(ftFace, fixedSizeIndex);
1244 if(FT_Err_Ok != error)
1246 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FreeType Select_Size error: %d\n", error);
1250 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1252 FontMetrics metrics(static_cast<float>(ftMetrics.ascender) * FROM_266,
1253 static_cast<float>(ftMetrics.descender) * FROM_266,
1254 static_cast<float>(ftMetrics.height) * FROM_266,
1255 static_cast<float>(ftFace->underline_position) * FROM_266,
1256 static_cast<float>(ftFace->underline_thickness) * FROM_266);
1258 const float fixedWidth = static_cast<float>(ftFace->available_sizes[fixedSizeIndex].width);
1259 const float fixedHeight = static_cast<float>(ftFace->available_sizes[fixedSizeIndex].height);
1261 // Create the FreeType font face item to cache.
1262 FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, mCacheHandler->GetGlyphCacheManager(), path, requestedPointSize, faceIndex, metrics, fixedSizeIndex, fixedWidth, fixedHeight, hasColorTables);
1264 fontId = mCacheHandler->CacheFontFaceCacheItem(std::move(fontFaceCacheItem));
1269 if(mIsAtlasLimitationEnabled)
1271 //There is limitation on block size to fit in predefined atlas size.
1272 //If the block size cannot fit into atlas size, then the system cannot draw block.
1273 //This is workaround to avoid issue in advance
1274 //Decrementing point-size until arriving to maximum allowed block size.
1275 auto requestedPointSizeBackup = requestedPointSize;
1276 const Size& maxSizeFitInAtlas = GetCurrentMaximumBlockSizeFitInAtlas();
1277 error = SearchOnProperPointSize(ftFace, mDpiHorizontal, mDpiVertical, maxSizeFitInAtlas, requestedPointSize);
1279 if(requestedPointSize != requestedPointSizeBackup)
1281 DALI_LOG_WARNING(" The requested-point-size : %d, is reduced to point-size : %d\n", requestedPointSizeBackup, requestedPointSize);
1286 error = FT_Set_Char_Size(ftFace,
1288 FT_F26Dot6(requestedPointSize),
1293 if(FT_Err_Ok == error)
1295 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1297 FontMetrics metrics(static_cast<float>(ftMetrics.ascender) * FROM_266,
1298 static_cast<float>(ftMetrics.descender) * FROM_266,
1299 static_cast<float>(ftMetrics.height) * FROM_266,
1300 static_cast<float>(ftFace->underline_position) * FROM_266,
1301 static_cast<float>(ftFace->underline_thickness) * FROM_266);
1303 // Create the FreeType font face item to cache.
1304 FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, mCacheHandler->GetGlyphCacheManager(), path, requestedPointSize, faceIndex, metrics);
1306 fontId = mCacheHandler->CacheFontFaceCacheItem(std::move(fontFaceCacheItem));
1310 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " FreeType Set_Char_Size error: %d for pointSize %d\n", error, requestedPointSize);
1316 if(cacheDescription)
1318 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " Cache Font Path at font id : %d [%s]\n", fontId, path.c_str());
1319 mCacheHandler->CacheFontPath(ftFace, fontId, requestedPointSize, path);
1325 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " FreeType New_Face error: %d for [%s]\n", error, path.c_str());
1328 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
1332 bool FontClient::Plugin::IsScalable(const FontPath& path) const
1334 bool isScalable = false;
1336 FT_Face ftFace = nullptr;
1337 int error = FT_New_Face(mFreeTypeLibrary,
1341 if(FT_Err_Ok != error)
1343 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: %s\n", path.c_str());
1347 isScalable = ftFace->face_flags & FT_FACE_FLAG_SCALABLE;
1352 FT_Done_Face(ftFace);
1358 bool FontClient::Plugin::IsScalable(const FontDescription& fontDescription) const
1360 // Create a font pattern.
1361 FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1363 FcResult result = FcResultMatch;
1365 // match the pattern
1366 FcPattern* match = FcFontMatch(nullptr /* use default configure */, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1367 bool isScalable = false;
1371 // Get the path to the font file name.
1373 GetFcString(match, FC_FILE, path);
1374 isScalable = IsScalable(path);
1378 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str());
1381 // Destroys the created patterns.
1382 FcPatternDestroy(match);
1383 FcPatternDestroy(fontFamilyPattern);
1388 void FontClient::Plugin::GetFixedSizes(const FontPath& path, Vector<PointSize26Dot6>& sizes) const
1390 // Empty the caller container
1393 FT_Face ftFace = nullptr;
1394 int error = FT_New_Face(mFreeTypeLibrary,
1398 if(FT_Err_Ok != error)
1400 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font path : [%s]\n", path.c_str());
1405 // Fetch the number of fixed sizes available
1406 if(ftFace->num_fixed_sizes && ftFace->available_sizes)
1408 for(int i = 0; i < ftFace->num_fixed_sizes; ++i)
1410 sizes.PushBack(ftFace->available_sizes[i].size);
1414 FT_Done_Face(ftFace);
1418 void FontClient::Plugin::GetFixedSizes(const FontDescription& fontDescription,
1419 Vector<PointSize26Dot6>& sizes) const
1421 // Create a font pattern.
1422 FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1424 FcResult result = FcResultMatch;
1426 // match the pattern
1427 FcPattern* match = FcFontMatch(nullptr /* use default configure */, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1431 // Get the path to the font file name.
1433 GetFcString(match, FC_FILE, path);
1434 GetFixedSizes(path, sizes);
1438 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str());
1441 // Destroys the created patterns.
1442 FcPatternDestroy(match);
1443 FcPatternDestroy(fontFamilyPattern);
1446 bool FontClient::Plugin::HasItalicStyle(FontId fontId) const
1448 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1449 if(fontCacheItem != nullptr)
1451 return fontCacheItem->HasItalicStyle();
1456 } // namespace Dali::TextAbstraction::Internal