mirror of
https://github.com/odrling/Aegisub
synced 2025-04-11 22:56:02 +02:00
Remove OS X and Windows support from the fontconfig file lister
This commit is contained in:
parent
6780373a50
commit
f824d2c56b
@ -19,29 +19,12 @@
|
||||
#include <libaegisub/charset_conv_win.h>
|
||||
#include <libaegisub/log.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <libaegisub/util_osx.h>
|
||||
#endif
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include <wx/intl.h>
|
||||
|
||||
namespace {
|
||||
FcConfig *init_fontconfig() {
|
||||
#ifdef __APPLE__
|
||||
FcConfig *config = FcConfigCreate();
|
||||
std::string conf_path = agi::util::GetBundleResourcesDirectory() + "/etc/fonts/fonts.conf";
|
||||
if (FcConfigParseAndLoad(config, (unsigned char *)conf_path.c_str(), FcTrue))
|
||||
return config;
|
||||
|
||||
LOG_E("font_collector/fontconfig") << "Loading fontconfig configuration file failed";
|
||||
FcConfigDestroy(config);
|
||||
#endif
|
||||
return FcInitLoadConfig();
|
||||
}
|
||||
|
||||
bool pattern_matches(FcPattern *pat, const char *field, std::string const& name) {
|
||||
FcChar8 *str;
|
||||
for (int i = 0; FcPatternGetString(pat, field, i, &str) == FcResultMatch; ++i) {
|
||||
@ -68,7 +51,7 @@ void find_font(FcFontSet *src, FcFontSet *dst, std::string const& family) {
|
||||
}
|
||||
|
||||
FontConfigFontFileLister::FontConfigFontFileLister(FontCollectorStatusCallback &cb)
|
||||
: config(init_fontconfig(), FcConfigDestroy)
|
||||
: config(FcInitLoadConfig(), FcConfigDestroy)
|
||||
{
|
||||
cb(_("Updating font cache\n"), 0);
|
||||
FcConfigBuildFonts(config);
|
||||
@ -114,38 +97,6 @@ CollectionResult FontConfigFontFileLister::GetFontPaths(std::string const& facen
|
||||
|
||||
auto match = matches->fonts[0];
|
||||
|
||||
#ifdef _WIN32
|
||||
wxMemoryDC dc;
|
||||
// Use EnumFontFamiliesEx to verify the match, as fontconfig sometimes gives
|
||||
// us some incorrect matches along with the correct one
|
||||
for (FcPattern *pat : boost::make_iterator_range(&matches->fonts[0], &matches->fonts[matches->nfont])) {
|
||||
FcChar8 *fullname;
|
||||
if (FcPatternGetString(pat, FC_FULLNAME, 0, &fullname) != FcResultMatch)
|
||||
continue;
|
||||
|
||||
LOGFONT lf = {0};
|
||||
lf.lfCharSet = DEFAULT_CHARSET;
|
||||
wcsncpy(lf.lfFaceName, agi::charset::ConvertW((const char *)fullname).c_str(), 31);
|
||||
|
||||
auto cb = [&](const LOGFONT *lf) {
|
||||
auto face = agi::charset::ConvertW(lf->lfFaceName);
|
||||
boost::to_lower(face);
|
||||
return face == family;
|
||||
};
|
||||
|
||||
using type = decltype(cb);
|
||||
bool found = !EnumFontFamiliesEx(dc.GetHDC(), &lf,
|
||||
[](const LOGFONT *lf, const TEXTMETRIC *, DWORD, LPARAM lParam) -> int {
|
||||
return !(*reinterpret_cast<type*>(lParam))(lf);
|
||||
}, (LPARAM)&cb, 0);
|
||||
|
||||
if (found) {
|
||||
match = pat;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
FcChar8 *file;
|
||||
if(FcPatternGetString(match, FC_FILE, 0, &file) != FcResultMatch)
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user