mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:20:06 +00:00
add support for opentype fonts
This commit is contained in:
parent
c6596b3e7d
commit
a9daf47741
1 changed files with 14 additions and 4 deletions
|
|
@ -29,6 +29,7 @@ static const std::string logPrefix_ = "scwx::qt::manager::font_manager";
|
||||||
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||||
|
|
||||||
static const std::string kFcTrueType_ {"TrueType"};
|
static const std::string kFcTrueType_ {"TrueType"};
|
||||||
|
static const std::string kFcOpenType_ {"CFF"};
|
||||||
|
|
||||||
struct FontRecord
|
struct FontRecord
|
||||||
{
|
{
|
||||||
|
|
@ -70,6 +71,7 @@ public:
|
||||||
|
|
||||||
const std::vector<char>& GetRawFontData(const std::string& filename);
|
const std::vector<char>& GetRawFontData(const std::string& filename);
|
||||||
|
|
||||||
|
static bool CheckFontFormat(const FcChar8* format);
|
||||||
static FontRecord MatchFontFile(const std::string& family,
|
static FontRecord MatchFontFile(const std::string& family,
|
||||||
const std::vector<std::string>& styles);
|
const std::vector<std::string>& styles);
|
||||||
|
|
||||||
|
|
@ -457,6 +459,13 @@ void FontManager::Impl::FinalizeFontconfig()
|
||||||
FcFini();
|
FcFini();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FontManager::Impl::CheckFontFormat(const FcChar8* format)
|
||||||
|
{
|
||||||
|
const std::string stdFormat = reinterpret_cast<const char *>(format);
|
||||||
|
|
||||||
|
return stdFormat == kFcTrueType_ || stdFormat == kFcOpenType_;
|
||||||
|
}
|
||||||
|
|
||||||
FontRecord
|
FontRecord
|
||||||
FontManager::Impl::MatchFontFile(const std::string& family,
|
FontManager::Impl::MatchFontFile(const std::string& family,
|
||||||
const std::vector<std::string>& styles)
|
const std::vector<std::string>& styles)
|
||||||
|
|
@ -469,9 +478,6 @@ FontManager::Impl::MatchFontFile(const std::string& family,
|
||||||
|
|
||||||
FcPatternAddString(
|
FcPatternAddString(
|
||||||
pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(family.c_str()));
|
pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(family.c_str()));
|
||||||
FcPatternAddString(pattern,
|
|
||||||
FC_FONTFORMAT,
|
|
||||||
reinterpret_cast<const FcChar8*>(kFcTrueType_.c_str()));
|
|
||||||
FcPatternAddBool(pattern, FC_SYMBOL, FcFalse);
|
FcPatternAddBool(pattern, FC_SYMBOL, FcFalse);
|
||||||
|
|
||||||
if (!styles.empty())
|
if (!styles.empty())
|
||||||
|
|
@ -505,6 +511,7 @@ FontManager::Impl::MatchFontFile(const std::string& family,
|
||||||
FcChar8* fcFamily = nullptr;
|
FcChar8* fcFamily = nullptr;
|
||||||
FcChar8* fcStyle = nullptr;
|
FcChar8* fcStyle = nullptr;
|
||||||
FcChar8* fcFile = nullptr;
|
FcChar8* fcFile = nullptr;
|
||||||
|
FcChar8* fcFormat = nullptr;
|
||||||
FcBool fcSymbol = FcFalse;
|
FcBool fcSymbol = FcFalse;
|
||||||
|
|
||||||
// Match was found, get properties
|
// Match was found, get properties
|
||||||
|
|
@ -515,7 +522,10 @@ FontManager::Impl::MatchFontFile(const std::string& family,
|
||||||
FcPatternGetString(match, FC_FILE, 0, &fcFile) == FcResultMatch &&
|
FcPatternGetString(match, FC_FILE, 0, &fcFile) == FcResultMatch &&
|
||||||
FcPatternGetBool(match, FC_SYMBOL, 0, &fcSymbol) ==
|
FcPatternGetBool(match, FC_SYMBOL, 0, &fcSymbol) ==
|
||||||
FcResultMatch &&
|
FcResultMatch &&
|
||||||
fcSymbol == FcFalse /*Must check fcSymbol manually*/)
|
FcPatternGetString(match, FC_FONTFORMAT, 0, &fcFormat) ==
|
||||||
|
FcResultMatch &&
|
||||||
|
fcSymbol == FcFalse /*Must check fcSymbol manually*/ &&
|
||||||
|
CheckFontFormat(fcFormat))
|
||||||
{
|
{
|
||||||
record.family_ = reinterpret_cast<char*>(fcFamily);
|
record.family_ = reinterpret_cast<char*>(fcFamily);
|
||||||
record.style_ = reinterpret_cast<char*>(fcStyle);
|
record.style_ = reinterpret_cast<char*>(fcStyle);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue