-void FontClient::Plugin::InitSystemFonts()
-{
- DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
-
- FcFontSet* fontSet = GetFcFontSet(); // Creates a FcFontSet that needs to be destroyed by calling FcFontSetDestroy.
-
- if(fontSet)
- {
- DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " number of system fonts : %d\n", fontSet->nfont);
-
- // Reserve some space to avoid reallocations.
- mSystemFonts.reserve(fontSet->nfont);
-
- for(int i = 0u; i < fontSet->nfont; ++i)
- {
- FcPattern* fontPattern = fontSet->fonts[i];
-
- FontPath path;
-
- // Skip fonts with no path
- if(GetFcString(fontPattern, FC_FILE, path))
- {
- mSystemFonts.push_back(FontDescription());
- FontDescription& fontDescription = mSystemFonts.back();
-
- fontDescription.path = std::move(path);
-
- int width = 0;
- int weight = 0;
- int slant = 0;
- GetFcString(fontPattern, FC_FAMILY, fontDescription.family);
- GetFcInt(fontPattern, FC_WIDTH, width);
- GetFcInt(fontPattern, FC_WEIGHT, weight);
- GetFcInt(fontPattern, FC_SLANT, slant);
- fontDescription.width = IntToWidthType(width);
- fontDescription.weight = IntToWeightType(weight);
- fontDescription.slant = IntToSlantType(slant);
-
- FONT_LOG_DESCRIPTION(fontDescription, "");
- }
- }
-
- // Destroys the font set created.
- FcFontSetDestroy(fontSet);
- }
-}
-
-bool FontClient::Plugin::MatchFontDescriptionToPattern(FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet)
-{
- DALI_LOG_TRACE_METHOD(gFontClientLogFilter);
-
- FcResult result = FcResultMatch;
- FcPattern* match = FcFontMatch(nullptr /* use default configure */, pattern, &result); // Creates a new font pattern that needs to be destroyed by calling FcPatternDestroy.
-
- const bool matched = nullptr != match;
- DALI_LOG_INFO(gFontClientLogFilter, Debug::General, " pattern matched : %s\n", (matched ? "true" : "false"));
-
- if(matched)
- {
- int width = 0;
- int weight = 0;
- int slant = 0;
- GetFcString(match, FC_FILE, fontDescription.path);
- GetFcString(match, FC_FAMILY, fontDescription.family);
- GetFcInt(match, FC_WIDTH, width);
- GetFcInt(match, FC_WEIGHT, weight);
- GetFcInt(match, FC_SLANT, slant);
- fontDescription.width = IntToWidthType(width);
- fontDescription.weight = IntToWeightType(weight);
- fontDescription.slant = IntToSlantType(slant);
-
- // Retrieve the character set and increase the reference counter.
- FcPatternGetCharSet(match, FC_CHARSET, 0u, characterSet);
- *characterSet = FcCharSetCopy(*characterSet);
-
- // destroyed the matched pattern
- FcPatternDestroy(match);
- FONT_LOG_DESCRIPTION(fontDescription, "");
- }
- return matched;
-}
-
-_FcFontSet* FontClient::Plugin::GetFcFontSet() const
-{
- FcFontSet* fontset = nullptr;
-
- // create a new pattern.
- // a pattern holds a set of names, each name refers to a property of the font
- FcPattern* pattern = FcPatternCreate();
-
- if(nullptr != pattern)
- {
- // create an object set used to define which properties are to be returned in the patterns from FcFontList.
- FcObjectSet* objectSet = FcObjectSetCreate();
-
- if(nullptr != objectSet)
- {
- // build an object set from a list of property names
- FcObjectSetAdd(objectSet, FC_FILE);
- FcObjectSetAdd(objectSet, FC_FAMILY);
- FcObjectSetAdd(objectSet, FC_WIDTH);
- FcObjectSetAdd(objectSet, FC_WEIGHT);
- FcObjectSetAdd(objectSet, FC_SLANT);
-
- // get a list of fonts
- // creates patterns from those fonts containing only the objects in objectSet and returns the set of unique such patterns
- fontset = FcFontList(nullptr /* the default configuration is checked to be up to date, and used */, pattern, objectSet); // Creates a FcFontSet that needs to be destroyed by calling FcFontSetDestroy.
-
- // clear up the object set
- FcObjectSetDestroy(objectSet);
- }
-
- // clear up the pattern
- FcPatternDestroy(pattern);
- }
-
- return fontset;
-}
-
-bool FontClient::Plugin::GetFcString(const FcPattern* const pattern,
- const char* const n,
- std::string& string)
-{
- FcChar8* file = nullptr;
- const FcResult retVal = FcPatternGetString(pattern, n, 0u, &file);
-
- if(FcResultMatch == retVal)
- {
- // Have to use reinterpret_cast because FcChar8 is unsigned char*, not a const char*.
- string.assign(reinterpret_cast<const char*>(file));
-
- return true;
- }
-
- return false;
-}
-
-bool FontClient::Plugin::GetFcInt(const _FcPattern* const pattern, const char* const n, int& intVal)
-{
- const FcResult retVal = FcPatternGetInteger(pattern, n, 0u, &intVal);
-
- if(FcResultMatch == retVal)
- {
- return true;
- }
-
- return false;
-}
-