2 * Copyright (c) 2024 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 if(fontDescriptionId > 0u && fontDescriptionId <= mCacheHandler->mCharacterSetCache.Count())
770 // Retrieve the font file name path.
771 const FontDescription& description = *(mCacheHandler->mFontDescriptionCache.begin() + fontDescriptionId - 1u);
773 // Retrieve the font id. Do not cache the description as it has been already cached.
774 // Note : CacheFontPath() API call ValidateFont() + setup CharacterSet + cache the font description.
775 // So set cacheDescription=false, that we don't call CacheFontPath().
776 fontId = GetFontIdByPath(description.path, requestedPointSize, faceIndex, false);
778 if((fontId > 0u) && (fontId - 1u < mCacheHandler->mFontIdCache.size()))
780 fontCacheIndex = mCacheHandler->mFontIdCache[fontId - 1u].index;
781 mCacheHandler->mFontFaceCache[fontCacheIndex].mCharacterSet = FcCharSetCopy(mCacheHandler->mCharacterSetCache[fontDescriptionId - 1u]);
783 // Cache the pair 'fontDescriptionId, requestedPointSize' to improve the following queries.
784 mCacheHandler->CacheFontDescriptionSize(fontDescriptionId, requestedPointSize, fontCacheIndex);
790 fontId = mCacheHandler->mFontFaceCache[fontCacheIndex].mFontId + 1u;
793 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
797 FontId FontClient::Plugin::GetFontId(const BitmapFont& bitmapFont) const
799 // The font id to be returned.
801 if(!mCacheHandler->FindBitmapFont(bitmapFont.name, fontId))
803 BitmapFontCacheItem bitmapFontCacheItem(bitmapFont);
805 fontId = mCacheHandler->CacheBitmapFontCacheItem(std::move(bitmapFontCacheItem));
810 void FontClient::Plugin::GetFontMetrics(FontId fontId,
811 FontMetrics& metrics) const
813 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
814 if(fontCacheItem != nullptr)
816 fontCacheItem->GetFontMetrics(metrics, mDpiVertical);
820 GlyphIndex FontClient::Plugin::GetGlyphIndex(FontId fontId,
821 Character charcode) const
823 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
824 if(fontCacheItem != nullptr)
826 return fontCacheItem->GetGlyphIndex(charcode);
832 GlyphIndex FontClient::Plugin::GetGlyphIndex(FontId fontId,
834 Character variantSelector) const
836 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
837 if(fontCacheItem != nullptr)
839 return fontCacheItem->GetGlyphIndex(charcode, variantSelector);
845 bool FontClient::Plugin::GetGlyphMetrics(GlyphInfo* array,
848 bool horizontal) const
850 if(VECTOR_GLYPH == type)
852 return GetVectorMetrics(array, size, horizontal);
855 return GetBitmapMetrics(array, size, horizontal);
858 bool FontClient::Plugin::GetBitmapMetrics(GlyphInfo* array,
860 bool horizontal) const
862 bool success(size > 0u);
864 for(unsigned int i = 0; i < size; ++i)
866 GlyphInfo& glyph = array[i];
868 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(glyph.fontId);
869 if(fontCacheItem != nullptr)
871 success &= fontCacheItem->GetGlyphMetrics(glyph, mDpiVertical, horizontal);
873 // Check if it's an embedded image.
874 else if((0u == glyph.fontId) && (0u != glyph.index) && (glyph.index <= mCacheHandler->mEmbeddedItemCache.size()))
876 mCacheHandler->mEmbeddedItemCache[glyph.index - 1u].GetGlyphMetrics(glyph);
887 bool FontClient::Plugin::GetVectorMetrics(GlyphInfo* array,
889 bool horizontal) const
891 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
894 for(unsigned int i = 0u; i < size; ++i)
896 FontId fontId = array[i].fontId;
899 (fontId - 1u) < mCacheHandler->mFontIdCache.size())
901 FontFaceCacheItem& font = mCacheHandler->mFontFaceCache[mCacheHandler->mFontIdCache[fontId - 1u].index];
903 if(!font.mVectorFontId)
905 font.mVectorFontId = mVectorFontCache->GetFontId(font.mPath);
908 mVectorFontCache->GetGlyphMetrics(font.mVectorFontId, array[i]);
910 // Vector metrics are in EMs, convert to pixels
911 const float scale = (static_cast<float>(font.mRequestedPointSize) * FROM_266) * static_cast<float>(mDpiVertical) / POINTS_PER_INCH;
912 array[i].width *= scale;
913 array[i].height *= scale;
914 array[i].xBearing *= scale;
915 array[i].yBearing *= scale;
916 array[i].advance *= scale;
930 void FontClient::Plugin::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::GlyphBufferData& data, int outlineWidth) const
932 data.isColorBitmap = false;
933 data.isColorEmoji = false;
934 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
935 if(fontCacheItem != nullptr)
937 fontCacheItem->CreateBitmap(glyphIndex, data, outlineWidth, isItalicRequired, isBoldRequired);
939 else if((0u != glyphIndex) && (glyphIndex <= mCacheHandler->mEmbeddedItemCache.size()))
941 // It's an embedded item.
942 mCacheHandler->mEmbeddedItemCache[glyphIndex - 1u].CreateBitmap(mCacheHandler->mPixelBufferCache, data);
946 PixelData FontClient::Plugin::CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth) const
948 TextAbstraction::GlyphBufferData data;
950 CreateBitmap(fontId, glyphIndex, false, false, data, outlineWidth);
952 // If data is compressed or not owned buffer, copy this.
953 if(!data.isBufferOwned || data.compressionType != TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION)
955 uint8_t* newBuffer = (uint8_t*)malloc(data.width * data.height * Pixel::GetBytesPerPixel(data.format));
956 TextAbstraction::GlyphBufferData::Decompress(data, newBuffer);
957 if(data.isBufferOwned)
962 data.buffer = newBuffer;
963 data.isBufferOwned = true;
964 data.compressionType = TextAbstraction::GlyphBufferData::CompressionType::NO_COMPRESSION;
967 return PixelData::New(data.buffer,
968 data.width * data.height * Pixel::GetBytesPerPixel(data.format),
975 void FontClient::Plugin::CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight) const
980 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
982 (fontId - 1u < mCacheHandler->mFontIdCache.size()))
984 using FontCacheIndex = CacheHandler::FontCacheIndex;
985 const FontCacheIndex fontCacheIndex = mCacheHandler->mFontIdCache[fontId - 1u].index;
986 FontFaceCacheItem& font = mCacheHandler->mFontFaceCache[fontCacheIndex];
988 if(!font.mVectorFontId)
990 font.mVectorFontId = mVectorFontCache->GetFontId(font.mPath);
993 mVectorFontCache->GetVectorBlob(font.mVectorFontId, fontCacheIndex, glyphIndex, blob, blobLength, nominalWidth, nominalHeight);
998 const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph(PointSize26Dot6 requestedPointSize) const
1000 using EllipsisCacheIndex = CacheHandler::EllipsisCacheIndex;
1001 using EllipsisItem = CacheHandler::EllipsisItem;
1002 EllipsisCacheIndex ellipsisCacheIndex = 0u;
1004 if(!mCacheHandler->FindEllipsis(requestedPointSize, ellipsisCacheIndex))
1006 // No glyph has been found. Create one.
1009 item.requestedPointSize = requestedPointSize;
1011 // Find a font for the ellipsis glyph.
1012 item.glyph.fontId = FindDefaultFont(ELLIPSIS_CHARACTER,
1016 // Set the character index to access the glyph inside the font.
1017 item.glyph.index = GetGlyphIndex(item.glyph.fontId, ELLIPSIS_CHARACTER);
1019 // Get glyph informations.
1020 GetBitmapMetrics(&item.glyph, 1u, true);
1022 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index);
1023 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font %d.\n", item.glyph.fontId);
1025 // EllipsisCacheIndex is stored in item.index.
1026 ellipsisCacheIndex = mCacheHandler->CacheEllipsis(std::move(item));
1027 if(!mCacheHandler->mEllipsisCache.empty())
1029 mCacheHandler->mEllipsisCache.back().index = ellipsisCacheIndex;
1032 return mCacheHandler->mEllipsisCache[ellipsisCacheIndex].glyph;
1035 bool FontClient::Plugin::IsColorGlyph(FontId fontId, GlyphIndex glyphIndex) const
1037 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1038 return fontCacheItem && fontCacheItem->IsColorGlyph(glyphIndex);
1041 FT_FaceRec_* FontClient::Plugin::GetFreetypeFace(FontId fontId) const
1043 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1044 if(fontCacheItem != nullptr)
1046 return fontCacheItem->GetTypeface();
1051 FontDescription::Type FontClient::Plugin::GetFontType(FontId fontId) const
1053 const FontId index = fontId - 1u;
1054 if((fontId > 0u) && (index < mCacheHandler->mFontIdCache.size()))
1056 return mCacheHandler->mFontIdCache[index].type;
1058 return FontDescription::INVALID;
1061 bool FontClient::Plugin::AddCustomFontDirectory(const FontPath& path)
1063 // nullptr as first parameter means the current configuration is used.
1064 return FcConfigAppFontAddDir(nullptr, reinterpret_cast<const FcChar8*>(path.c_str()));
1067 HarfBuzzFontHandle FontClient::Plugin::GetHarfBuzzFont(FontId fontId) const
1069 FontCacheItemInterface* fontCacheItem = const_cast<FontCacheItemInterface*>(GetCachedFontItem(fontId));
1070 if(fontCacheItem != nullptr)
1072 return fontCacheItem->GetHarfBuzzFont(mDpiHorizontal, mDpiVertical); // May cache
1077 GlyphIndex FontClient::Plugin::CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat) const
1079 EmbeddedItem embeddedItem;
1081 embeddedItem.pixelBufferId = 0u;
1082 embeddedItem.width = description.width;
1083 embeddedItem.height = description.height;
1085 pixelFormat = Pixel::A8;
1087 if(!description.url.empty())
1089 // Check if the url is in the cache.
1090 Devel::PixelBuffer pixelBuffer;
1091 if(!mCacheHandler->FindEmbeddedPixelBufferId(description.url, embeddedItem.pixelBufferId))
1093 // The pixel buffer is not in the cache. Create one and cache it.
1094 embeddedItem.pixelBufferId = mCacheHandler->CacheEmbeddedPixelBuffer(description.url);
1097 if((embeddedItem.pixelBufferId > 0u) && (embeddedItem.pixelBufferId - 1u) < mCacheHandler->mPixelBufferCache.size())
1099 // Retrieve the pixel buffer from the cache to set the pixel format.
1100 pixelBuffer = mCacheHandler->mPixelBufferCache[embeddedItem.pixelBufferId - 1u].pixelBuffer;
1105 // Set the size of the embedded item if it has not been set.
1106 if(0u == embeddedItem.width)
1108 embeddedItem.width = static_cast<unsigned int>(pixelBuffer.GetWidth());
1111 if(0u == embeddedItem.height)
1113 embeddedItem.height = static_cast<unsigned int>(pixelBuffer.GetHeight());
1116 // Set the pixel format.
1117 pixelFormat = pixelBuffer.GetPixelFormat();
1121 // Find if the same embeddedItem has already been created.
1122 GlyphIndex index = 0u;
1123 if(!mCacheHandler->FindEmbeddedItem(embeddedItem.pixelBufferId, embeddedItem.width, embeddedItem.height, index))
1125 index = mCacheHandler->CacheEmbeddedItem(std::move(embeddedItem));
1130 void FontClient::Plugin::EnableAtlasLimitation(bool enabled)
1132 mIsAtlasLimitationEnabled = enabled;
1135 bool FontClient::Plugin::IsAtlasLimitationEnabled() const
1137 return mIsAtlasLimitationEnabled;
1140 Size FontClient::Plugin::GetMaximumTextAtlasSize() const
1142 return TextAbstraction::FontClient::MAX_TEXT_ATLAS_SIZE;
1145 Size FontClient::Plugin::GetDefaultTextAtlasSize() const
1147 return TextAbstraction::FontClient::DEFAULT_TEXT_ATLAS_SIZE;
1150 Size FontClient::Plugin::GetCurrentMaximumBlockSizeFitInAtlas() const
1152 return mCurrentMaximumBlockSizeFitInAtlas;
1155 bool FontClient::Plugin::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
1157 bool isChanged = false;
1158 const Size& maxTextAtlasSize = TextAbstraction::FontClient::MAX_TEXT_ATLAS_SIZE;
1159 const uint16_t& padding = TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK;
1161 if(currentMaximumBlockSizeFitInAtlas.width <= maxTextAtlasSize.width - padding && currentMaximumBlockSizeFitInAtlas.height <= maxTextAtlasSize.height - padding)
1163 mCurrentMaximumBlockSizeFitInAtlas = currentMaximumBlockSizeFitInAtlas;
1170 uint32_t FontClient::Plugin::GetNumberOfPointsPerOneUnitOfPointSize() const
1172 return TextAbstraction::FontClient::NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE;
1175 FontId FontClient::Plugin::CreateFont(const FontPath& path,
1176 PointSize26Dot6 requestedPointSize,
1177 FaceIndex faceIndex,
1178 bool cacheDescription) const
1180 DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
1181 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " path : [%s]\n", path.c_str());
1182 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize);
1184 DALI_TRACE_SCOPE(gTraceFilter, "DALI_TEXT_CREATE_FONT");
1190 uint8_t* fontDataPtr = nullptr;
1191 std::streampos dataSize = 0;
1192 bool fontDataFound = mCacheHandler->FindFontData(path, fontDataPtr, dataSize);
1196 // Create & cache new font face from pre-loaded font
1197 error = FT_New_Memory_Face(mFreeTypeLibrary, reinterpret_cast<FT_Byte*>(fontDataPtr), static_cast<FT_Long>(dataSize), 0, &ftFace);
1198 #if defined(TRACE_ENABLED)
1199 if(gTraceFilter && gTraceFilter->IsTraceEnabled())
1201 DALI_LOG_DEBUG_INFO("DALI_TEXT_CREATE_FONT : FT_New_Memory_Face : %s\n", path.c_str());
1207 // Create & cache new font face
1208 error = FT_New_Face(mFreeTypeLibrary, path.c_str(), 0, &ftFace);
1209 #if defined(TRACE_ENABLED)
1210 if(gTraceFilter && gTraceFilter->IsTraceEnabled())
1212 DALI_LOG_DEBUG_INFO("DALI_TEXT_CREATE_FONT : FT_New_Face : %s\n", path.c_str());
1217 if(FT_Err_Ok == error)
1219 // Check if a font is scalable.
1220 const bool isScalable = (0 != (ftFace->face_flags & FT_FACE_FLAG_SCALABLE));
1221 const bool hasFixedSizedBitmaps = (0 != (ftFace->face_flags & FT_FACE_FLAG_FIXED_SIZES)) && (0 != ftFace->num_fixed_sizes);
1222 const bool hasColorTables = (0 != (ftFace->face_flags & FT_FACE_FLAG_COLOR));
1224 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " isScalable : [%s]\n", (isScalable ? "true" : "false"));
1225 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " hasFixedSizedBitmaps : [%s]\n", (hasFixedSizedBitmaps ? "true" : "false"));
1226 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " hasColorTables : [%s]\n", (hasColorTables ? "true" : "false"));
1228 // Check to see if the font contains fixed sizes?
1229 if(!isScalable && hasFixedSizedBitmaps)
1231 PointSize26Dot6 actualPointSize = 0u;
1232 int fixedSizeIndex = 0;
1233 for(; fixedSizeIndex < ftFace->num_fixed_sizes; ++fixedSizeIndex)
1235 const PointSize26Dot6 fixedSize = static_cast<PointSize26Dot6>(ftFace->available_sizes[fixedSizeIndex].size);
1236 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " size index : %d, size : %d\n", fixedSizeIndex, fixedSize);
1238 if(fixedSize >= requestedPointSize)
1240 actualPointSize = fixedSize;
1245 if(0u == actualPointSize)
1247 // The requested point size is bigger than the bigest fixed size.
1248 fixedSizeIndex = ftFace->num_fixed_sizes - 1;
1249 actualPointSize = static_cast<PointSize26Dot6>(ftFace->available_sizes[fixedSizeIndex].size);
1252 DALI_LOG_INFO(gFontClientLogFilter, Debug::Verbose, " size index : %d, actual size : %d\n", fixedSizeIndex, actualPointSize);
1254 // Tell Freetype to use this size
1255 error = FT_Select_Size(ftFace, fixedSizeIndex);
1256 if(FT_Err_Ok != error)
1258 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FreeType Select_Size error: %d\n", error);
1262 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1264 FontMetrics metrics(static_cast<float>(ftMetrics.ascender) * FROM_266,
1265 static_cast<float>(ftMetrics.descender) * FROM_266,
1266 static_cast<float>(ftMetrics.height) * FROM_266,
1267 static_cast<float>(ftFace->underline_position) * FROM_266,
1268 static_cast<float>(ftFace->underline_thickness) * FROM_266);
1270 const float fixedWidth = static_cast<float>(ftFace->available_sizes[fixedSizeIndex].width);
1271 const float fixedHeight = static_cast<float>(ftFace->available_sizes[fixedSizeIndex].height);
1273 // Create the FreeType font face item to cache.
1274 FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, mCacheHandler->GetGlyphCacheManager(), path, requestedPointSize, faceIndex, metrics, fixedSizeIndex, fixedWidth, fixedHeight, hasColorTables);
1276 fontId = mCacheHandler->CacheFontFaceCacheItem(std::move(fontFaceCacheItem));
1281 if(mIsAtlasLimitationEnabled)
1283 //There is limitation on block size to fit in predefined atlas size.
1284 //If the block size cannot fit into atlas size, then the system cannot draw block.
1285 //This is workaround to avoid issue in advance
1286 //Decrementing point-size until arriving to maximum allowed block size.
1287 auto requestedPointSizeBackup = requestedPointSize;
1288 const Size& maxSizeFitInAtlas = GetCurrentMaximumBlockSizeFitInAtlas();
1289 error = SearchOnProperPointSize(ftFace, mDpiHorizontal, mDpiVertical, maxSizeFitInAtlas, requestedPointSize);
1291 if(requestedPointSize != requestedPointSizeBackup)
1293 DALI_LOG_WARNING(" The requested-point-size : %d, is reduced to point-size : %d\n", requestedPointSizeBackup, requestedPointSize);
1298 error = FT_Set_Char_Size(ftFace,
1300 FT_F26Dot6(requestedPointSize),
1305 if(FT_Err_Ok == error)
1307 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1309 FontMetrics metrics(static_cast<float>(ftMetrics.ascender) * FROM_266,
1310 static_cast<float>(ftMetrics.descender) * FROM_266,
1311 static_cast<float>(ftMetrics.height) * FROM_266,
1312 static_cast<float>(ftFace->underline_position) * FROM_266,
1313 static_cast<float>(ftFace->underline_thickness) * FROM_266);
1315 // Create the FreeType font face item to cache.
1316 FontFaceCacheItem fontFaceCacheItem(mFreeTypeLibrary, ftFace, mCacheHandler->GetGlyphCacheManager(), path, requestedPointSize, faceIndex, metrics);
1318 fontId = mCacheHandler->CacheFontFaceCacheItem(std::move(fontFaceCacheItem));
1322 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " FreeType Set_Char_Size error: %d for pointSize %d\n", error, requestedPointSize);
1328 if(cacheDescription)
1330 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " Cache Font Path at font id : %d [%s]\n", fontId, path.c_str());
1331 mCacheHandler->CacheFontPath(ftFace, fontId, requestedPointSize, path);
1337 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " FreeType New_Face error: %d for [%s]\n", error, path.c_str());
1340 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " font id : %d\n", fontId);
1344 bool FontClient::Plugin::IsScalable(const FontPath& path) const
1346 bool isScalable = false;
1348 FT_Face ftFace = nullptr;
1349 int error = FT_New_Face(mFreeTypeLibrary,
1353 if(FT_Err_Ok != error)
1355 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: %s\n", path.c_str());
1359 isScalable = ftFace->face_flags & FT_FACE_FLAG_SCALABLE;
1364 FT_Done_Face(ftFace);
1370 bool FontClient::Plugin::IsScalable(const FontDescription& fontDescription) const
1372 // Create a font pattern.
1373 FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1375 FcResult result = FcResultMatch;
1377 // match the pattern
1378 FcPattern* match = FcFontMatch(nullptr /* use default configure */, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1379 bool isScalable = false;
1383 // Get the path to the font file name.
1385 GetFcString(match, FC_FILE, path);
1386 isScalable = IsScalable(path);
1390 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str());
1393 // Destroys the created patterns.
1394 FcPatternDestroy(match);
1395 FcPatternDestroy(fontFamilyPattern);
1400 void FontClient::Plugin::GetFixedSizes(const FontPath& path, Vector<PointSize26Dot6>& sizes) const
1402 // Empty the caller container
1405 FT_Face ftFace = nullptr;
1406 int error = FT_New_Face(mFreeTypeLibrary,
1410 if(FT_Err_Ok != error)
1412 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font path : [%s]\n", path.c_str());
1417 // Fetch the number of fixed sizes available
1418 if(ftFace->num_fixed_sizes && ftFace->available_sizes)
1420 for(int i = 0; i < ftFace->num_fixed_sizes; ++i)
1422 sizes.PushBack(ftFace->available_sizes[i].size);
1426 FT_Done_Face(ftFace);
1430 void FontClient::Plugin::GetFixedSizes(const FontDescription& fontDescription,
1431 Vector<PointSize26Dot6>& sizes) const
1433 // Create a font pattern.
1434 FcPattern* fontFamilyPattern = CreateFontFamilyPattern(fontDescription); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1436 FcResult result = FcResultMatch;
1438 // match the pattern
1439 FcPattern* match = FcFontMatch(nullptr /* use default configure */, fontFamilyPattern, &result); // Creates a font pattern that needs to be destroyed by calling FcPatternDestroy.
1443 // Get the path to the font file name.
1445 GetFcString(match, FC_FILE, path);
1446 GetFixedSizes(path, sizes);
1450 DALI_LOG_INFO(gFontClientLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str());
1453 // Destroys the created patterns.
1454 FcPatternDestroy(match);
1455 FcPatternDestroy(fontFamilyPattern);
1458 bool FontClient::Plugin::HasItalicStyle(FontId fontId) const
1460 const FontCacheItemInterface* fontCacheItem = GetCachedFontItem(fontId);
1461 if(fontCacheItem != nullptr)
1463 return fontCacheItem->HasItalicStyle();
1468 } // namespace Dali::TextAbstraction::Internal