From e5f7b3b3fd980b5ea9ed623bba9aff670e5bd5f3 Mon Sep 17 00:00:00 2001 From: Slic3rPE Date: Thu, 23 Sep 2021 19:32:08 +0200 Subject: [PATCH] FIX on MAC (made by Filip) --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 025b18bd4b..160979160d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -15,10 +15,13 @@ #include "nanosvg/nanosvg.h" // load SVG file #include +#include #include #ifdef __APPLE__ +#include #include +#include #endif // apple namespace Slic3r { @@ -322,7 +325,10 @@ void GLGizmoEmboss::draw_window() draw_font_list(); - if (ImGui::Button(_L("choose font").c_str())) choose_font_by_wxdialog(); + if (ImGui::Button(_L("choose font").c_str())) + choose_font_by_wxdialog(); + //wxGetApp().plater()->CallAfter([this]{choose_font_by_wxdialog();}); + //ImGui::SameLine(); //if (ImGui::Button(_L("use system font").c_str())) { @@ -455,7 +461,7 @@ bool GLGizmoEmboss::choose_font_by_wxdialog() { data.SetInitialFont(data.GetChosenFont()); wxFontDialog font_dialog(wxGetApp().mainframe, data); //static wxFontDialog font_dialog(nullptr); - font_dialog.SetTitle(_L("Select font for Emboss")); + //font_dialog.SetTitle(_L("Select font for Emboss")); if (font_dialog.ShowModal() != wxID_OK) return false; data = font_dialog.GetFontData(); wxFont font = data.GetChosenFont(); @@ -623,11 +629,17 @@ std::optional WxFontUtils::load_font(const wxFont &font) return {}; #elif __APPLE__ const wxNativeFontInfo *info = font.GetNativeFontInfo(); + if(info == nullptr) return {}; CTFontDescriptorRef descriptor = info->GetCTFontDescriptor(); - CFDictionaryRef attribs = CTFontDescriptorCopyAttributes(descriptor); - CFStringRef url = (CFStringRef)CTFontDescriptorCopyAttribute(descriptor, kCTFontURLAttribute); - std::string str(CFStringGetCStringPtr(CFURLGetString(anUrl),kCFStringEncodingUTF8)); - return Emboss::load_font(str); + CFURLRef typeref = (CFURLRef)CTFontDescriptorCopyAttribute(descriptor, kCTFontURLAttribute); + CFStringRef url = CFURLGetString(typeref); + if(url == NULL) return {}; + wxString file_uri; + wxCFTypeRef(url).GetValue(file_uri); + std::string file_path(wxURI::Unescape(file_uri).c_str()); + size_t start = std::string("file://").size(); + file_path = file_path.substr(start, file_path.size()-start); + return Emboss::load_font(file_path.c_str()); #endif }