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::ClearCacheOnLocaleChanged() const
274 mCacheHandler->ClearCacheOnLocaleChanged();
277 void FontClient::Plugin::SetDpi(unsigned int horizontalDpi,
278 unsigned int verticalDpi)
280 mDpiHorizontal = horizontalDpi;
281 mDpiVertical = verticalDpi;
284 void FontClient::Plugin::ResetSystemDefaults() const
286 mCacheHandler->ResetSystemDefaults();
289 void FontClient::Plugin::CacheFontDataFromFile(const std::string& fontPath) const
296 if(mCacheHandler->FindFontData(fontPath))
298 // Font data is already cached, no need to reload
302 Dali::Vector<uint8_t> fontDataBuffer;
303 std::streampos dataSize = 0;
304 if(!mCacheHandler->LoadFontDataFromFile(fontPath, fontDataBuffer, dataSize))
306 fontDataBuffer.Clear();
307 FONT_LOG_MESSAGE(Dali::Integration::Log::ERROR, "Failed to load font data : %s\n", fontPath.c_str());
312 mCacheHandler->CacheFontData(fontPath, fontDataBuffer, dataSize);
315 void FontClient::Plugin::CacheFontFaceFromFile(const std::string& fontPath) const
322 if(mCacheHandler->FindFontFace(fontPath))
324 // Font face is already cached, no need to reload
329 int error = FT_New_Face(mFreeTypeLibrary, fontPath.c_str(), 0, &ftFace);
330 if(FT_Err_Ok != error)
332 FONT_LOG_MESSAGE(Dali::Integration::Log::ERROR, "Failed to load font face : %s\n", fontPath.c_str());
337 mCacheHandler->CacheFontFace(fontPath, ftFace);
338 FONT_LOG_MESSAGE(Dali::Integration::Log::INFO, "PreLoad font new face : %s\n", fontPath.c_str());
341 void FontClient::Plugin::FontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList) const
343 for(const auto& fontPath : fontPathList)
345 CacheFontFaceFromFile(fontPath);
348 for(const auto& memoryFontPath : memoryFontPathList)
350 CacheFontDataFromFile(memoryFontPath);
354 void FontClient::Plugin::FontPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily) const
356 mCacheHandler->InitDefaultFontDescription();
358 FontFamilyList familyList;
359 familyList.reserve(extraFamilyList.size() + 1);
361 for(const auto& fallbackFont : fallbackFamilyList)
363 FontList* fontList = nullptr;
364 CharacterSetList* characterSetList = nullptr;
365 FontDescriptionId fontDescriptionId = 0u;
366 FontDescription fontDescription;
367 fontDescription.family = FontFamily(fallbackFont);
368 fontDescription.weight = DefaultFontWeight();
369 fontDescription.width = DefaultFontWidth();
370 fontDescription.slant = DefaultFontSlant();
372 if(!mCacheHandler->FindFallbackFontList(fontDescription, fontList, characterSetList))
374 FontDescription copiedFontDescription = fontDescription;
375 mCacheHandler->CacheFallbackFontList(std::move(copiedFontDescription), fontList, characterSetList);
377 if(!mCacheHandler->FindValidatedFont(fontDescription, fontDescriptionId))
379 mCacheHandler->ValidateFont(fontDescription, fontDescriptionId);
382 if(extraFamilyList.empty() && localeFamily.empty())
388 familyList.insert(familyList.end(), extraFamilyList.begin(), extraFamilyList.end());
389 if(!localeFamily.empty())
391 familyList.push_back(localeFamily);
394 for(const auto& font : *fontList)
396 auto it = std::find(familyList.begin(), familyList.end(), font.family);
397 if(it != familyList.end())
399 if(!mCacheHandler->FindValidatedFont(font, fontDescriptionId))
401 mCacheHandler->ValidateFont(font, fontDescriptionId);
403 familyList.erase(it);
409 void FontClient::Plugin::InitDefaultFontDescription() const
411 mCacheHandler->InitDefaultFontDescription();
414 void FontClient::Plugin::GetDefaultPlatformFontDescription(FontDescription& fontDescription) const
416 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
418 mCacheHandler->InitDefaultFontDescription();
419 fontDescription = mCacheHandler->mDefaultFontDescription;
421 FONT_LOG_DESCRIPTION(fontDescription, "");
424 void FontClient::Plugin::GetDefaultFonts(FontList& defaultFonts) const
426 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
428 mCacheHandler->InitDefaultFonts();
429 defaultFonts = mCacheHandler->mDefaultFonts;
431 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " number of default fonts : [%d]\n", mCacheHandler->mDefaultFonts.size());
434 void FontClient::Plugin::GetSystemFonts(FontList& systemFonts) const
436 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
438 mCacheHandler->InitSystemFonts();
439 systemFonts = mCacheHandler->mSystemFonts;
441 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " number of system fonts : [%d]\n", mCacheHandler->mSystemFonts.size());
444 void FontClient::Plugin::GetDescription(FontId fontId,
445 FontDescription& fontDescription) const
447 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
448 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
450 if((fontId > 0u) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
452 const auto& fontIdCacheItem = mCacheHandler->mFontIdCache[fontId - 1u];
453 switch(fontIdCacheItem.type)
455 case FontDescription::FACE_FONT:
457 for(const auto& item : mCacheHandler->mFontDescriptionSizeCache)
459 if(item.second == fontIdCacheItem.index)
461 fontDescription = *(mCacheHandler->mFontDescriptionCache.begin() + item.first.fontDescriptionId - 1u);
463 FONT_LOG_DESCRIPTION(fontDescription, "");
469 case FontDescription::BITMAP_FONT:
471 fontDescription.type = FontDescription::BITMAP_FONT;
472 fontDescription.family = mCacheHandler->mBitmapFontCache[fontIdCacheItem.index].font.name;
477 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " Invalid type of font\n");
478 fontDescription.type = FontDescription::INVALID;
479 fontDescription.family.clear();
484 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " No description found for the font id %d\n", fontId);
487 PointSize26Dot6 FontClient::Plugin::GetPointSize(FontId fontId) const
489 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
490 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
492 PointSize26Dot6 pointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
493 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
494 if(fontCacheItem != nullptr)
496 pointSize = fontCacheItem->GetPointSize();
498 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " point size : %d\n", pointSize);
503 bool FontClient::Plugin::IsCharacterSupportedByFont(FontId fontId, Character character) const
505 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
506 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
507 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " character : %p\n", character);
509 bool isSupported = false;
510 auto fontCacheItem = const_cast<FontCacheItemInterface*>(GetCachedFontItem(fontId));
511 if(fontCacheItem != nullptr)
513 isSupported = fontCacheItem->IsCharacterSupported(character); // May cache
516 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " is supported : %s\n", (isSupported ? "true" : "false"));
520 const FontCacheItemInterface* FontClient::Plugin::GetCachedFontItem(FontId fontId) const
522 if((fontId > 0u) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
524 const auto& fontIdCacheItem = mCacheHandler->mFontIdCache[fontId - 1u];
525 switch(fontIdCacheItem.type)
527 case FontDescription::FACE_FONT:
529 return &mCacheHandler->mFontFaceCache[fontIdCacheItem.index];
531 case FontDescription::BITMAP_FONT:
533 return &mCacheHandler->mBitmapFontCache[fontIdCacheItem.index];
537 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " Invalid type of font\n");
544 FontId FontClient::Plugin::FindFontForCharacter(const FontList& fontList,
545 const CharacterSetList& characterSetList,
547 PointSize26Dot6 requestedPointSize,
548 bool preferColor) const
550 DALI_ASSERT_DEBUG((fontList.size() == characterSetList.Count()) && "FontClient::Plugin::FindFontForCharacter. Different number of fonts and character sets.");
551 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
552 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " character : %p\n", character);
553 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
554 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " preferColor : %s\n", (preferColor ? "true" : "false"));
557 bool foundColor = false;
559 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " number of fonts : %d\n", fontList.size());
561 // Traverse the list of fonts.
562 // Check for each font if supports the character.
563 for(unsigned int index = 0u, numberOfFonts = fontList.size(); index < numberOfFonts; ++index)
565 const FontDescription& description = fontList[index];
566 const FcCharSet* const characterSet = characterSetList[index];
568 FONT_LOG_DESCRIPTION(description, "");
570 bool foundInRanges = false;
571 if(nullptr != characterSet)
573 foundInRanges = FcCharSetHasChar(characterSet, character);
578 fontId = GetFontId(description, requestedPointSize, 0u);
580 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " font id : %d\n", fontId);
584 if((fontId > 0) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
586 const FontFaceCacheItem& item = mCacheHandler->mFontFaceCache[mCacheHandler->mFontIdCache[fontId - 1u].index];
588 foundColor = item.mHasColorTables;
591 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " foundColor : %s\n", (foundColor ? "true" : "false"));
594 // Keep going unless we prefer a different (color) font.
595 if(!preferColor || foundColor)
602 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
606 FontId FontClient::Plugin::FindDefaultFont(Character charcode,
607 PointSize26Dot6 requestedPointSize,
608 bool preferColor) const
610 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
611 FONT_LOG_REQUEST(charcode, requestedPointSize, preferColor);
615 // Create the list of default fonts if it has not been created.
616 mCacheHandler->InitDefaultFonts();
617 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " number of default fonts : %d\n", mCacheHandler->mDefaultFonts.size());
619 // Traverse the list of default fonts.
620 // Check for each default font if supports the character.
621 fontId = FindFontForCharacter(mCacheHandler->mDefaultFonts, mCacheHandler->mDefaultFontCharacterSets, charcode, requestedPointSize, preferColor);
623 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
627 FontId FontClient::Plugin::FindFallbackFont(Character charcode,
628 const FontDescription& preferredFontDescription,
629 PointSize26Dot6 requestedPointSize,
630 bool preferColor) const
632 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
633 FONT_LOG_REQUEST(charcode, requestedPointSize, preferColor);
635 DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_FIND_FALLBACKFONT");
637 // The font id to be returned.
640 FontDescription fontDescription;
642 // Fill the font description with the preferred font description and complete with the defaults.
643 fontDescription.family = preferredFontDescription.family.empty() ? DefaultFontFamily() : preferredFontDescription.family;
644 fontDescription.weight = ((FontWeight::NONE == preferredFontDescription.weight) ? DefaultFontWeight() : preferredFontDescription.weight);
645 fontDescription.width = ((FontWidth::NONE == preferredFontDescription.width) ? DefaultFontWidth() : preferredFontDescription.width);
646 fontDescription.slant = ((FontSlant::NONE == preferredFontDescription.slant) ? DefaultFontSlant() : preferredFontDescription.slant);
648 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " preferredFontDescription --> fontDescription\n");
649 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " [%s] --> [%s]\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str());
650 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWeight::Name[preferredFontDescription.weight], FontWeight::Name[fontDescription.weight]);
651 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWidth::Name[preferredFontDescription.width], FontWidth::Name[fontDescription.width]);
652 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontSlant::Name[preferredFontDescription.slant], FontSlant::Name[fontDescription.slant]);
654 #if defined(TRACE_ENABLED)
655 if(gTraceFilter && gTraceFilter->IsTraceEnabled())
657 DALI_LOG_DEBUG_INFO("DALI_TEXT_FIND_FALLBACKFONT : %s -> %s\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str());
661 // Check first if the font's description has been queried before.
662 FontList* fontList = nullptr;
663 CharacterSetList* characterSetList = nullptr;
665 if(!mCacheHandler->FindFallbackFontList(fontDescription, fontList, characterSetList))
667 mCacheHandler->CacheFallbackFontList(std::move(fontDescription), fontList, characterSetList);
670 if(fontList && characterSetList)
672 fontId = FindFontForCharacter(*fontList, *characterSetList, charcode, requestedPointSize, preferColor);
675 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
679 FontId FontClient::Plugin::GetFontIdByPath(const FontPath& path,
680 PointSize26Dot6 requestedPointSize,
682 bool cacheDescription) const
684 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
685 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " path : [%s]\n", path.c_str());
686 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
690 if(nullptr != mFreeTypeLibrary)
693 if(mCacheHandler->FindFontByPath(path, requestedPointSize, faceIndex, foundId))
699 id = CreateFont(path, requestedPointSize, faceIndex, cacheDescription);
703 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", id);
707 FontId FontClient::Plugin::GetFontId(const FontDescription& fontDescription,
708 PointSize26Dot6 requestedPointSize,
709 FaceIndex faceIndex) const
711 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
712 FONT_LOG_DESCRIPTION(fontDescription, "");
714 // Special case when font Description don't have family information.
715 // In this case, we just use default description family and path.
716 const FontDescription& realFontDescription = fontDescription.family.empty() ? FontDescription(mCacheHandler->mDefaultFontDescription.path,
717 mCacheHandler->mDefaultFontDescription.family,
718 fontDescription.width,
719 fontDescription.weight,
720 fontDescription.slant,
721 fontDescription.type)
724 FONT_LOG_DESCRIPTION(realFontDescription, "");
725 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
727 // This method uses three vectors which caches:
728 // * The bitmap font cache
729 // * Pairs of non validated font descriptions and an index to a vector with paths to font file names.
730 // * The path to font file names.
731 // * The font ids of pairs 'font point size, index to the vector with paths to font file names'.
733 // 1) Checks if the font description matches with a previously loaded bitmap font.
734 // Returns if a font is found.
735 // 2) Checks in the cache if the font's description has been validated before.
736 // If it was it gets an index to the vector with paths to font file names. Otherwise,
737 // retrieves using font config a path to a font file name which matches with the
738 // font's description. The path is stored in the cache.
740 // 3) Checks in the cache if the pair 'font point size, index to the vector with paths to
741 // font file names' exists. If exists, it gets the font id. If it doesn't it calls
742 // the GetFontId() method with the path to the font file name and the point size to
745 // The font id to be returned.
748 // Check first if the font description matches with a previously loaded bitmap font.
749 if(mCacheHandler->FindBitmapFont(realFontDescription.family, fontId))
754 // Check if the font's description have been validated before.
755 FontDescriptionId fontDescriptionId = 0u;
757 if(!mCacheHandler->FindValidatedFont(realFontDescription, fontDescriptionId))
759 // Use font config to validate the font's description.
760 mCacheHandler->ValidateFont(realFontDescription, fontDescriptionId);
763 using FontCacheIndex = CacheHandler::FontCacheIndex;
764 FontCacheIndex fontCacheIndex = 0u;
765 // Check if exists a pair 'fontDescriptionId, requestedPointSize' in the cache.
766 if(!mCacheHandler->FindFont(fontDescriptionId, requestedPointSize, fontCacheIndex))
768 // Retrieve the font file name path.
769 const FontDescription& description = *(mCacheHandler->mFontDescriptionCache.begin() + fontDescriptionId - 1u);
771 // Retrieve the font id. Do not cache the description as it has been already cached.
772 // Note : CacheFontPath() API call ValidateFont() + setup CharacterSet + cache the font description.
773 // So set cacheDescription=false, that we don't call CacheFontPath().
774 fontId = GetFontIdByPath(description.path, requestedPointSize, faceIndex, false);
776 if((fontId > 0u) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
778 fontCacheIndex = mCacheHandler->mFontIdCache[fontId - 1u].index;
779 mCacheHandler->mFontFaceCache[fontCacheIndex].mCharacterSet = FcCharSetCopy(mCacheHandler->mCharacterSetCache[fontDescriptionId - 1u]);
781 // Cache the pair 'fontDescriptionId, requestedPointSize' to improve the following queries.
782 mCacheHandler->CacheFontDescriptionSize(fontDescriptionId, requestedPointSize, fontCacheIndex);
787 fontId = mCacheHandler->mFontFaceCache[fontCacheIndex].mFontId + 1u;
790 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
794 FontId FontClient::Plugin::GetFontId(const BitmapFont& bitmapFont) const
796 // The font id to be returned.
798 if(!mCacheHandler->FindBitmapFont(bitmapFont.name, fontId))
800 BitmapFontCacheItem bitmapFontCacheItem(bitmapFont);
802 fontId = mCacheHandler->CacheBitmapFontCacheItem(std::move(bitmapFontCacheItem));
807 void FontClient::Plugin::GetFontMetrics(FontId fontId,
808 FontMetrics& metrics) const
810 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
811 if(fontCacheItem != nullptr)
813 fontCacheItem->GetFontMetrics(metrics, mDpiVertical);
817 GlyphIndex FontClient::Plugin::GetGlyphIndex(FontId fontId,
818 Character charcode) const
820 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
821 if(fontCacheItem != nullptr)
823 return fontCacheItem->GetGlyphIndex(charcode);
829 GlyphIndex FontClient::Plugin::GetGlyphIndex(FontId fontId,
831 Character variantSelector) const
833 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
834 if(fontCacheItem != nullptr)
836 return fontCacheItem->GetGlyphIndex(charcode, variantSelector);
842 bool FontClient::Plugin::GetGlyphMetrics(GlyphInfo* array,
845 bool horizontal) const
847 if(VECTOR_GLYPH == type)
849 return GetVectorMetrics(array, size, horizontal);
852 return GetBitmapMetrics(array, size, horizontal);
855 bool FontClient::Plugin::GetBitmapMetrics(GlyphInfo* array,
857 bool horizontal) const
859 bool success(size > 0u);
861 for(unsigned int i = 0; i < size; ++i)
863 GlyphInfo& glyph = array[i];
865 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(glyph.fontId);
866 if(fontCacheItem != nullptr)
868 success &= fontCacheItem->GetGlyphMetrics(glyph, mDpiVertical, horizontal);
870 // Check if it's an embedded image.
871 else if((0u == glyph.fontId) && (0u != glyph.index) && (glyph.index <= mCacheHandler->mEmbeddedItemCache.size()))
873 mCacheHandler->mEmbeddedItemCache[glyph.index - 1u].GetGlyphMetrics(glyph);
884 bool FontClient::Plugin::GetVectorMetrics(GlyphInfo* array,
886 bool horizontal) const
888 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
891 for(unsigned int i = 0u; i < size; ++i)
893 FontId fontId = array[i].fontId;
896 (fontId - 1u) < mCacheHandler->mFontIdCache.size())
898 FontFaceCacheItem& font = mCacheHandler->mFontFaceCache[mCacheHandler->mFontIdCache[fontId - 1u].index];
900 if(!font.mVectorFontId)
902 font.mVectorFontId = mVectorFontCache->GetFontId(font.mPath);
905 mVectorFontCache->GetGlyphMetrics(font.mVectorFontId, array[i]);
907 // Vector metrics are in EMs, convert to pixels
908 const float scale = (static_cast<float>(font.mRequestedPointSize) * FROM_266) * static_cast<float>(mDpiVertical) / POINTS_PER_INCH;
909 array[i].width *= scale;
910 array[i].height *= scale;
911 array[i].xBearing *= scale;
912 array[i].yBearing *= scale;
913 array[i].advance *= scale;
927 void FontClient::Plugin::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth) const
929 data.isColorBitmap = false;
930 data.isColorEmoji = false;
931 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
932 if(fontCacheItem != nullptr)
934 fontCacheItem->CreateBitmap(glyphIndex, data, outlineWidth, isItalicRequired, isBoldRequired);
936 else if((0u != glyphIndex) && (glyphIndex <= mCacheHandler->mEmbeddedItemCache.size()))
938 // It's an embedded item.
939 mCacheHandler->mEmbeddedItemCache[glyphIndex - 1u].CreateBitmap(mCacheHandler->mPixelBufferCache, data);
943 PixelData FontClient::Plugin::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth) const
945 TextAbstraction::GlyphBufferData data;
947 CreateBitmap(fontId, glyphIndex, false, false, data, outlineWidth);
949 // If data is compressed or not owned buffer, copy this.
950 if(!data.isBufferOwned || data.compressionType != TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION)
952 uint8_t* newBuffer = (uint8_t*)malloc(data.width * data.height * Pixel::GetBytesPerPixel(data.format));
953 TextAbstraction::GlyphBufferData::Decompress(data, newBuffer);
954 if(data.isBufferOwned)
959 data.buffer = newBuffer;
960 data.isBufferOwned = true;
961 data.compressionType = TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION;
964 return PixelData::New(data.buffer,
965 data.width * data.height * Pixel::GetBytesPerPixel(data.format),
972 void FontClient::Plugin::CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight) const
977 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
979 (fontId - 1u < mCacheHandler->mFontIdCache.size()))
981 using FontCacheIndex = CacheHandler::FontCacheIndex;
982 const FontCacheIndex fontCacheIndex = mCacheHandler->mFontIdCache[fontId - 1u].index;
983 FontFaceCacheItem& font = mCacheHandler->mFontFaceCache[fontCacheIndex];
985 if(!font.mVectorFontId)
987 font.mVectorFontId = mVectorFontCache->GetFontId(font.mPath);
990 mVectorFontCache->GetVectorBlob(font.mVectorFontId, fontCacheIndex, glyphIndex, blob, blobLength, nominalWidth, nominalHeight);
995 const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph(PointSize26Dot6 requestedPointSize) const
997 using EllipsisCacheIndex = CacheHandler::EllipsisCacheIndex;
998 using EllipsisItem = CacheHandler::EllipsisItem;
999 EllipsisCacheIndex ellipsisCacheIndex = 0u;
1001 if(!mCacheHandler->FindEllipsis(requestedPointSize, ellipsisCacheIndex))
1003 // No glyph has been found. Create one.
1006 item.requestedPointSize = requestedPointSize;
1007 item.index = ellipsisCacheIndex;
1009 // Find a font for the ellipsis glyph.
1010 item.glyph.fontId = FindDefaultFont(ELLIPSIS_CHARACTER,
1014 // Set the character index to access the glyph inside the font.
1015 item.glyph.index = GetGlyphIndex(item.glyph.fontId, ELLIPSIS_CHARACTER);
1017 // Get glyph informations.
1018 GetBitmapMetrics(&item.glyph, 1u, true);
1020 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index);
1021 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font %d.\n", item.glyph.fontId);
1023 ellipsisCacheIndex = mCacheHandler->CacheEllipsis(std::move(item));
1025 return mCacheHandler->mEllipsisCache[ellipsisCacheIndex].glyph;
1028 bool FontClient::Plugin::IsColorGlyph(FontId fontId, GlyphIndex glyphIndex) const
1030 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1031 return fontCacheItem && fontCacheItem->IsColorGlyph(glyphIndex);
1034 FT_FaceRec_* FontClient::Plugin::GetFreetypeFace(FontId fontId) const
1036 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1037 if(fontCacheItem != nullptr)
1039 return fontCacheItem->GetTypeface();
1044 FontDescription::Type FontClient::Plugin::GetFontType(FontId fontId) const
1046 const FontId index = fontId - 1u;
1047 if((fontId > 0u) && (index < mCacheHandler->mFontIdCache.size()))
1049 return mCacheHandler->mFontIdCache[index].type;
1051 return FontDescription::INVALID;
1054 bool FontClient::Plugin::AddCustomFontDirectory(const FontPath& path)
1056 // nullptr as first parameter means the current configuration is used.
1057 return FcConfigAppFontAddDir(nullptr, reinterpret_cast<const FcChar8*>(path.c_str()));
1060 HarfBuzzFontHandle FontClient::Plugin::GetHarfBuzzFont(FontId fontId) const
1062 FontCacheItemInterface* fontCacheItem = const_cast<FontCacheItemInterface*>(GetCachedFontItem(fontId));
1063 if(fontCacheItem != nullptr)
1065 return fontCacheItem->GetHarfBuzzFont(mDpiHorizontal, mDpiVertical); // May cache
1070 GlyphIndex FontClient::Plugin::CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat) const
1072 EmbeddedItem embeddedItem;
1074 embeddedItem.pixelBufferId = 0u;
1075 embeddedItem.width = description.width;
1076 embeddedItem.height = description.height;
1078 pixelFormat = Pixel::A8;
1080 if(!description.url.empty())
1082 // Check if the url is in the cache.
1083 Devel::PixelBuffer pixelBuffer;
1084 if(!mCacheHandler->FindEmbeddedPixelBufferId(description.url, embeddedItem.pixelBufferId))
1086 // The pixel buffer is not in the cache. Create one and cache it.
1087 embeddedItem.pixelBufferId = mCacheHandler->CacheEmbeddedPixelBuffer(description.url);
1090 if((embeddedItem.pixelBufferId > 0u) && (embeddedItem.pixelBufferId - 1u) < mCacheHandler->mPixelBufferCache.size())
1092 // Retrieve the pixel buffer from the cache to set the pixel format.
1093 pixelBuffer = mCacheHandler->mPixelBufferCache[embeddedItem.pixelBufferId - 1u].pixelBuffer;
1098 // Set the size of the embedded item if it has not been set.
1099 if(0u == embeddedItem.width)
1101 embeddedItem.width = static_cast<unsigned int>(pixelBuffer.GetWidth());
1104 if(0u == embeddedItem.height)
1106 embeddedItem.height = static_cast<unsigned int>(pixelBuffer.GetHeight());
1109 // Set the pixel format.
1110 pixelFormat = pixelBuffer.GetPixelFormat();
1114 // Find if the same embeddedItem has already been created.
1115 GlyphIndex index = 0u;
1116 if(!mCacheHandler->FindEmbeddedItem(embeddedItem.pixelBufferId, embeddedItem.width, embeddedItem.height, index))
1118 index = mCacheHandler->CacheEmbeddedItem(std::move(embeddedItem));
1123 void FontClient::Plugin::EnableAtlasLimitation(bool enabled)
1125 mIsAtlasLimitationEnabled = enabled;
1128 bool FontClient::Plugin::IsAtlasLimitationEnabled() const
1130 return mIsAtlasLimitationEnabled;
1133 Size FontClient::Plugin::GetMaximumTextAtlasSize() const
1135 return TextAbstraction::FontClient::MAX_TEXT_ATLAS_SIZE;
1138 Size FontClient::Plugin::GetDefaultTextAtlasSize() const
1140 return TextAbstraction::FontClient::DEFAULT_TEXT_ATLAS_SIZE;
1143 Size FontClient::Plugin::GetCurrentMaximumBlockSizeFitInAtlas() const
1145 return mCurrentMaximumBlockSizeFitInAtlas;
1148 bool FontClient::Plugin::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
1150 bool isChanged = false;
1151 const Size& maxTextAtlasSize = TextAbstraction::FontClient::MAX_TEXT_ATLAS_SIZE;
1152 const uint16_t& padding = TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK;
1154 if(currentMaximumBlockSizeFitInAtlas.width <= maxTextAtlasSize.width - padding && currentMaximumBlockSizeFitInAtlas.height <= maxTextAtlasSize.height - padding)
1156 mCurrentMaximumBlockSizeFitInAtlas = currentMaximumBlockSizeFitInAtlas;
1163 uint32_t FontClient::Plugin::GetNumberOfPointsPerOneUnitOfPointSize() const
1165 return TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
1168 FontId FontClient::Plugin::CreateFont(const FontPath& path,
1169 PointSize26Dot6 requestedPointSize,
1170 FaceIndex faceIndex,
1171 bool cacheDescription) const
1173 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
1174 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " path : [%s]\n", path.c_str());
1175 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
1177 DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_CREATE_FONT");
1183 uint8_t* fontDataPtr = nullptr;
1184 std::streampos dataSize = 0;
1185 bool fontDataFound = mCacheHandler->FindFontData(path, fontDataPtr, dataSize);
1189 // Create & cache new font face from pre-loaded font
1190 error = FT_New_Memory_Face(mFreeTypeLibrary, reinterpret_cast<FT_Byte*>(fontDataPtr), static_cast<FT_Long>(dataSize), 0, &ftFace);
1191 #if defined(TRACE_ENABLED)
1192 if(gTraceFilter && gTraceFilter->IsTraceEnabled())
1194 DALI_LOG_DEBUG_INFO("DALI_TEXT_CREATE_FONT : FT_New_Memory_Face : %s\n", path.c_str());
1200 // Create & cache new font face
1201 error = FT_New_Face(mFreeTypeLibrary, path.c_str(), 0, &ftFace);
1202 #if defined(TRACE_ENABLED)
1203 if(gTraceFilter && gTraceFilter->IsTraceEnabled())
1205 DALI_LOG_DEBUG_INFO("DALI_TEXT_CREATE_FONT : FT_New_Face : %s\n", path.c_str());
1210 if(FT_Err_Ok == error)
1212 // Check if a font is scalable.
1213 const bool isScalable = (0 != (ftFace->face_flags & FT_FACE_FLAG_SCALABLE));
1214 const bool hasFixedSizedBitmaps = (0 != (ftFace->face_flags & FT_FACE_FLAG_FIXED_SIZES)) && (0 != ftFace->num_fixed_sizes);
1215 const bool hasColorTables = (0 != (ftFace->face_flags & FT_FACE_FLAG_COLOR));
1217 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " isScalable : [%s]\n", (isScalable ? "true" : "false"));
1218 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " hasFixedSizedBitmaps : [%s]\n", (hasFixedSizedBitmaps ? "true" : "false"));
1219 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " hasColorTables : [%s]\n", (hasColorTables ? "true" : "false"));
1221 // Check to see if the font contains fixed sizes?
1222 if(!isScalable && hasFixedSizedBitmaps)
1224 PointSize26Dot6 actualPointSize = 0u;
1225 int fixedSizeIndex = 0;
1226 for(; fixedSizeIndex < ftFace->num_fixed_sizes; ++fixedSizeIndex)
1228 const PointSize26Dot6 fixedSize = static_cast<PointSize26Dot6>(ftFace->available_sizes[fixedSizeIndex].size);
1229 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " size index : %d, size : %d\n", fixedSizeIndex, fixedSize);
1231 if(fixedSize >= requestedPointSize)
1233 actualPointSize = fixedSize;
1238 if(0u == actualPointSize)
1240 // The requested point size is bigger than the bigest fixed size.
1241 fixedSizeIndex = ftFace->num_fixed_sizes - 1;
1242 actualPointSize = static_cast<PointSize26Dot6>(ftFace->available_sizes[fixedSizeIndex].size);
1245 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " size index : %d, actual size : %d\n", fixedSizeIndex, actualPointSize);
1247 // Tell Freetype to use this size
1248 error = FT_Select_Size(ftFace, fixedSizeIndex);
1249 if(FT_Err_Ok != error)
1251 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FreeType Select_Size error: %d\n", error);
1255 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1257 FontMetrics metrics(static_cast<float>(ftMetrics.ascender) * FROM_266,
1258 static_cast<float>(ftMetrics.descender) * FROM_266,
1259 static_cast<float>(ftMetrics.height) * FROM_266,
1260 static_cast<float>(ftFace->underline_position) * FROM_266,
1261 static_cast<float>(ftFace->underline_thickness) * FROM_266);
1263 const float fixedWidth = static_cast<float>(ftFace->available_sizes[fixedSizeIndex].width);
1264 const float fixedHeight = static_cast<float>(ftFace->available_sizes[fixedSizeIndex].height);
1266 // Create the FreeType font face item to cache.
1267 FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, mCacheHandler->GetGlyphCacheManager(), path, requestedPointSize, faceIndex, metrics, fixedSizeIndex, fixedWidth, fixedHeight, hasColorTables);
1269 fontId = mCacheHandler->CacheFontFaceCacheItem(std::move(fontFaceCacheItem));
1274 if(mIsAtlasLimitationEnabled)
1276 //There is limitation on block size to fit in predefined atlas size.
1277 //If the block size cannot fit into atlas size, then the system cannot draw block.
1278 //This is workaround to avoid issue in advance
1279 //Decrementing point-size until arriving to maximum allowed block size.
1280 auto requestedPointSizeBackup = requestedPointSize;
1281 const Size& maxSizeFitInAtlas = GetCurrentMaximumBlockSizeFitInAtlas();
1282 error = SearchOnProperPointSize(ftFace, mDpiHorizontal, mDpiVertical, maxSizeFitInAtlas, requestedPointSize);
1284 if(requestedPointSize != requestedPointSizeBackup)
1286 DALI_LOG_WARNING(" The requested-point-size : %d, is reduced to point-size : %d\n", requestedPointSizeBackup, requestedPointSize);
1291 error = FT_Set_Char_Size(ftFace,
1293 FT_F26Dot6(requestedPointSize),
1298 if(FT_Err_Ok == error)
1300 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1302 FontMetrics metrics(static_cast<float>(ftMetrics.ascender) * FROM_266,
1303 static_cast<float>(ftMetrics.descender) * FROM_266,
1304 static_cast<float>(ftMetrics.height) * FROM_266,
1305 static_cast<float>(ftFace->underline_position) * FROM_266,
1306 static_cast<float>(ftFace->underline_thickness) * FROM_266);
1308 // Create the FreeType font face item to cache.
1309 FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, mCacheHandler->GetGlyphCacheManager(), path, requestedPointSize, faceIndex, metrics);
1311 fontId = mCacheHandler->CacheFontFaceCacheItem(std::move(fontFaceCacheItem));
1315 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " FreeType Set_Char_Size error: %d for pointSize %d\n", error, requestedPointSize);
1321 if(cacheDescription)
1323 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " Cache Font Path at font id : %d [%s]\n", fontId, path.c_str());
1324 mCacheHandler->CacheFontPath(ftFace, fontId, requestedPointSize, path);
1330 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " FreeType New_Face error: %d for [%s]\n", error, path.c_str());
1333 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
1337 bool FontClient::Plugin::IsScalable(const FontPath& path) const
1339 bool isScalable = false;
1341 FT_Face ftFace = nullptr;
1342 int error = FT_New_Face(mFreeTypeLibrary,
1346 if(FT_Err_Ok != error)
1348 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: %s\n", path.c_str());
1352 isScalable = ftFace->face_flags & FT_FACE_FLAG_SCALABLE;
1357 FT_Done_Face(ftFace);
1363 bool FontClient::Plugin::IsScalable(const FontDescription& fontDescription) const
1365 // Create a font pattern.
1366 FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1368 FcResult result = FcResultMatch;
1370 // match the pattern
1371 FcPattern* match = FcFontMatch(nullptr /* use default configure */, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1372 bool isScalable = false;
1376 // Get the path to the font file name.
1378 GetFcString(match, FC_FILE, path);
1379 isScalable = IsScalable(path);
1383 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str());
1386 // Destroys the created patterns.
1387 FcPatternDestroy(match);
1388 FcPatternDestroy(fontFamilyPattern);
1393 void FontClient::Plugin::GetFixedSizes(const FontPath& path, Vector<PointSize26Dot6>& sizes) const
1395 // Empty the caller container
1398 FT_Face ftFace = nullptr;
1399 int error = FT_New_Face(mFreeTypeLibrary,
1403 if(FT_Err_Ok != error)
1405 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font path : [%s]\n", path.c_str());
1410 // Fetch the number of fixed sizes available
1411 if(ftFace->num_fixed_sizes && ftFace->available_sizes)
1413 for(int i = 0; i < ftFace->num_fixed_sizes; ++i)
1415 sizes.PushBack(ftFace->available_sizes[i].size);
1419 FT_Done_Face(ftFace);
1423 void FontClient::Plugin::GetFixedSizes(const FontDescription& fontDescription,
1424 Vector<PointSize26Dot6>& sizes) const
1426 // Create a font pattern.
1427 FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1429 FcResult result = FcResultMatch;
1431 // match the pattern
1432 FcPattern* match = FcFontMatch(nullptr /* use default configure */, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1436 // Get the path to the font file name.
1438 GetFcString(match, FC_FILE, path);
1439 GetFixedSizes(path, sizes);
1443 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str());
1446 // Destroys the created patterns.
1447 FcPatternDestroy(match);
1448 FcPatternDestroy(fontFamilyPattern);
1451 bool FontClient::Plugin::HasItalicStyle(FontId fontId) const
1453 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1454 if(fontCacheItem != nullptr)
1456 return fontCacheItem->HasItalicStyle();
1461 } // namespace Dali::TextAbstraction::Internal