mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:30:05 +00:00
Add check for symbolic font in fontconfig code
This commit is contained in:
parent
6bf3ae833a
commit
f34a3e2145
1 changed files with 42 additions and 19 deletions
|
|
@ -472,6 +472,7 @@ FontManager::Impl::MatchFontFile(const std::string& family,
|
||||||
FcPatternAddString(pattern,
|
FcPatternAddString(pattern,
|
||||||
FC_FONTFORMAT,
|
FC_FONTFORMAT,
|
||||||
reinterpret_cast<const FcChar8*>(kFcTrueType_.c_str()));
|
reinterpret_cast<const FcChar8*>(kFcTrueType_.c_str()));
|
||||||
|
FcPatternAddBool(pattern, FC_SYMBOL, FcFalse);
|
||||||
|
|
||||||
if (!styles.empty())
|
if (!styles.empty())
|
||||||
{
|
{
|
||||||
|
|
@ -485,29 +486,51 @@ FontManager::Impl::MatchFontFile(const std::string& family,
|
||||||
FcDefaultSubstitute(pattern);
|
FcDefaultSubstitute(pattern);
|
||||||
|
|
||||||
// Find matching font
|
// Find matching font
|
||||||
FcResult result;
|
FcResult result {};
|
||||||
FcPattern* match = FcFontMatch(nullptr, pattern, &result);
|
FcFontSet* matches = FcFontSort(nullptr, pattern, FcFalse, nullptr, &result);
|
||||||
FontRecord record {};
|
FontRecord record {};
|
||||||
|
|
||||||
if (match != nullptr)
|
if (matches != nullptr)
|
||||||
{
|
{
|
||||||
FcChar8* fcFamily;
|
for (int i = 0; i < matches->nfont; i++)
|
||||||
FcChar8* fcStyle;
|
|
||||||
FcChar8* fcFile;
|
|
||||||
|
|
||||||
// Match was found, get properties
|
|
||||||
if (FcPatternGetString(match, FC_FAMILY, 0, &fcFamily) == FcResultMatch &&
|
|
||||||
FcPatternGetString(match, FC_STYLE, 0, &fcStyle) == FcResultMatch &&
|
|
||||||
FcPatternGetString(match, FC_FILE, 0, &fcFile) == FcResultMatch)
|
|
||||||
{
|
{
|
||||||
record.family_ = reinterpret_cast<char*>(fcFamily);
|
FcPattern* match =
|
||||||
record.style_ = reinterpret_cast<char*>(fcStyle);
|
// Using C code requires pointer arithmetic
|
||||||
record.filename_ = reinterpret_cast<char*>(fcFile);
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
|
FcFontRenderPrepare(nullptr, pattern, matches->fonts[i]);
|
||||||
|
if (match == nullptr)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
FcChar8* fcFamily = nullptr;
|
||||||
|
FcChar8* fcStyle = nullptr;
|
||||||
|
FcChar8* fcFile = nullptr;
|
||||||
|
FcBool fcSymbol = FcFalse;
|
||||||
|
|
||||||
logger_->debug("Found matching font: {}:{} ({})",
|
// Match was found, get properties
|
||||||
record.family_,
|
if (FcPatternGetString(match, FC_FAMILY, 0, &fcFamily) ==
|
||||||
record.style_,
|
FcResultMatch &&
|
||||||
record.filename_);
|
FcPatternGetString(match, FC_STYLE, 0, &fcStyle) ==
|
||||||
|
FcResultMatch &&
|
||||||
|
FcPatternGetString(match, FC_FILE, 0, &fcFile) == FcResultMatch &&
|
||||||
|
FcPatternGetBool(match, FC_SYMBOL, 0, &fcSymbol) ==
|
||||||
|
FcResultMatch &&
|
||||||
|
fcSymbol == FcFalse /*Must check fcSymbol manually*/)
|
||||||
|
{
|
||||||
|
record.family_ = reinterpret_cast<char*>(fcFamily);
|
||||||
|
record.style_ = reinterpret_cast<char*>(fcStyle);
|
||||||
|
record.filename_ = reinterpret_cast<char*>(fcFile);
|
||||||
|
|
||||||
|
logger_->debug("Found matching font: {}:{} ({}) {}",
|
||||||
|
record.family_,
|
||||||
|
record.style_,
|
||||||
|
record.filename_,
|
||||||
|
fcSymbol);
|
||||||
|
FcPatternDestroy(match);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
FcPatternDestroy(match);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -517,7 +540,7 @@ FontManager::Impl::MatchFontFile(const std::string& family,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
FcPatternDestroy(match);
|
FcFontSetDestroy(matches);
|
||||||
FcPatternDestroy(pattern);
|
FcPatternDestroy(pattern);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue