Fix suggested by Stefan Csomor<csomor@advancedconcepts.ch> for releasing MacOs references.
link: https://groups.google.com/g/wx-users/c/f2nVyT59H6M/m/_BocNmwCAgAJ
This commit is contained in:
parent
ac5633841b
commit
0a3db4525d
@ -1,6 +1,7 @@
|
|||||||
#include "WxFontUtils.hpp"
|
#include "WxFontUtils.hpp"
|
||||||
#include <boost/assign.hpp>
|
#include <boost/assign.hpp>
|
||||||
#include <boost/log/trivial.hpp>
|
#include <boost/log/trivial.hpp>
|
||||||
|
#include "libslic3r/Utils.hpp"
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <CoreText/CTFont.h>
|
#include <CoreText/CTFont.h>
|
||||||
@ -14,10 +15,9 @@
|
|||||||
using namespace Slic3r;
|
using namespace Slic3r;
|
||||||
using namespace Slic3r::GUI;
|
using namespace Slic3r::GUI;
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static bool is_valid_ttf(std::string_view file_path)
|
namespace {
|
||||||
|
bool is_valid_ttf(std::string_view file_path)
|
||||||
{
|
{
|
||||||
if (file_path.empty()) return false;
|
if (file_path.empty()) return false;
|
||||||
auto const pos_point = file_path.find_last_of('.');
|
auto const pos_point = file_path.find_last_of('.');
|
||||||
@ -34,8 +34,7 @@ static bool is_valid_ttf(std::string_view file_path)
|
|||||||
if (extension_size >= 5) return false; // a lot of symbols for extension
|
if (extension_size >= 5) return false; // a lot of symbols for extension
|
||||||
if (extension_size <= 1) return false; // few letters for extension
|
if (extension_size <= 1) return false; // few letters for extension
|
||||||
|
|
||||||
std::string_view extension = file_path.substr(pos_point + 1,
|
std::string_view extension = file_path.substr(pos_point + 1, extension_size);
|
||||||
extension_size);
|
|
||||||
|
|
||||||
// Because of MacOs - Courier, Geneva, Monaco
|
// Because of MacOs - Courier, Geneva, Monaco
|
||||||
if (extension == std::string_view("dfont")) return false;
|
if (extension == std::string_view("dfont")) return false;
|
||||||
@ -44,28 +43,29 @@ static bool is_valid_ttf(std::string_view file_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get filepath from wxFont on Mac OsX
|
// get filepath from wxFont on Mac OsX
|
||||||
static std::string get_file_path(const wxFont& font) {
|
std::string get_file_path(const wxFont& font) {
|
||||||
const wxNativeFontInfo *info = font.GetNativeFontInfo();
|
const wxNativeFontInfo *info = font.GetNativeFontInfo();
|
||||||
if (info == nullptr) return {};
|
if (info == nullptr) return {};
|
||||||
CTFontDescriptorRef descriptor = info->GetCTFontDescriptor();
|
CTFontDescriptorRef descriptor = info->GetCTFontDescriptor();
|
||||||
CFURLRef typeref = (CFURLRef)
|
CFURLRef typeref = (CFURLRef)CTFontDescriptorCopyAttribute(descriptor, kCTFontURLAttribute);
|
||||||
CTFontDescriptorCopyAttribute(descriptor, kCTFontURLAttribute);
|
|
||||||
if (typeref == NULL) return {};
|
if (typeref == NULL) return {};
|
||||||
|
ScopeGuard sg([&typeref]() { CFRelease(typeref); });
|
||||||
CFStringRef url = CFURLGetString(typeref);
|
CFStringRef url = CFURLGetString(typeref);
|
||||||
if (url == NULL) return {};
|
if (url == NULL) return {};
|
||||||
wxString file_uri;
|
wxString file_uri(wxCFStringRef::AsString(url));
|
||||||
wxCFTypeRef(url).GetValue(file_uri);
|
|
||||||
wxURI uri(file_uri);
|
wxURI uri(file_uri);
|
||||||
const wxString &path = uri.GetPath();
|
const wxString &path = uri.GetPath();
|
||||||
std::string path_str(wxURI::Unescape(path).c_str());
|
wxString path_unescaped = wxURI::Unescape(path);
|
||||||
|
std::string path_str = path_unescaped.ToUTF8().data();
|
||||||
BOOST_LOG_TRIVIAL(trace) << "input uri(" << file_uri.c_str() << ") convert to path(" << path.c_str() << ") string(" << path_str << ").";
|
BOOST_LOG_TRIVIAL(trace) << "input uri(" << file_uri.c_str() << ") convert to path(" << path.c_str() << ") string(" << path_str << ").";
|
||||||
return path_str;
|
return path_str;
|
||||||
}
|
}
|
||||||
#endif // __APPLE__
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
bool WxFontUtils::can_load(const wxFont &font)
|
bool WxFontUtils::can_load(const wxFont &font)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!font.IsOk()) return false;
|
if (!font.IsOk()) return false;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return Emboss::can_load(font.GetHFONT()) != nullptr;
|
return Emboss::can_load(font.GetHFONT()) != nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user