Get the UI font from CoreText on OS X

This commit is contained in:
Thomas Goyne 2013-12-10 09:08:30 -08:00
parent 1935e77261
commit 85148002bc
6 changed files with 34 additions and 6 deletions

View File

@ -97,7 +97,7 @@ AudioKaraoke::AudioKaraoke(wxWindow *parent, agi::Context *c)
SetSizerAndFit(main_sizer);
/// @todo subscribe
split_font.SetFaceName(to_wx(OPT_GET("Audio/Karaoke/Font Face")->GetString()));
split_font.SetFaceName(FontFace("Audio/Karaoke"));
split_font.SetPointSize(OPT_GET("Audio/Karaoke/Font Size")->GetInt());
split_area->Bind(wxEVT_SIZE, &AudioKaraoke::OnSize, this);

View File

@ -225,7 +225,7 @@ void BaseGrid::OnHighlightVisibleChange(agi::OptionValue const& opt) {
}
void BaseGrid::UpdateStyle() {
wxString fontname = to_wx(OPT_GET("Subtitle/Grid/Font Face")->GetString());
wxString fontname = FontFace("Subtitle/Grid");
if (fontname.empty()) fontname = "Tahoma";
font.SetFaceName(fontname);
font.SetPointSize(OPT_GET("Subtitle/Grid/Font Size")->GetInt());

View File

@ -53,7 +53,7 @@
"Drag Timing" : true,
"Inactive Lines Display Mode" : 1,
"Karaoke" : {
"Font Face" : "Lucida Grande",
"Font Face" : "",
"Font Size" : 9
},
"Lead" : {
@ -361,7 +361,7 @@
"Width" : 1280
},
"Edit Box" : {
"Font Face" : "Lucida Grande",
"Font Face" : "",
"Font Size" : 13
},
"Grid" : {
@ -378,7 +378,7 @@
{"bool" : true}
],
"Focus Allow" : true,
"Font Face" : "Lucida Grande",
"Font Face" : "",
"Font Size" : 12,
"Hide Overrides" : 1,
"Hide Overrides Char" : "☀",

View File

@ -207,7 +207,7 @@ void SubsTextEditCtrl::SetSyntaxStyle(int id, wxFont &font, std::string const& n
void SubsTextEditCtrl::SetStyles() {
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
font.SetEncoding(wxFONTENCODING_DEFAULT); // this solves problems with some fonts not working properly
wxString fontname = to_wx(OPT_GET("Subtitle/Edit Box/Font Face")->GetString());
wxString fontname = FontFace("Subtitle/Edit Box");
if (!fontname.empty()) font.SetFaceName(fontname);
font.SetPointSize(OPT_GET("Subtitle/Edit Box/Font Size")->GetInt());

View File

@ -64,6 +64,7 @@
#ifdef __APPLE__
#include <libaegisub/util_osx.h>
#include <CoreText/CTFont.h>
#endif
/// @brief There shall be no kiB, MiB stuff here Pretty reading of size
@ -272,6 +273,31 @@ void AddFullScreenButton(wxWindow *) { }
void SetFloatOnParent(wxWindow *) { }
#endif
wxString FontFace(std::string opt_prefix) {
opt_prefix += "/Font Face";
auto value = OPT_GET(opt_prefix)->GetString();
#ifdef __WXOSX_COCOA__
if (value.empty()) {
auto default_font = CTFontCreateUIFontForLanguage(kCTFontUserFontType, 0, nullptr);
auto default_font_name = CTFontCopyPostScriptName(default_font);
CFRelease(default_font);
auto utf8_str = CFStringGetCStringPtr(default_font_name, kCFStringEncodingUTF8);
if (utf8_str)
value = utf8_str;
else {
char buffer[1024];
CFStringGetCString(default_font_name, buffer, sizeof(buffer), kCFStringEncodingUTF8);
buffer[1023] = '\0';
value = buffer;
}
CFRelease(default_font_name);
}
#endif
return to_wx(value);
}
agi::fs::path FileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, wxString const& wildcard, int flags, wxWindow *parent) {
wxString path;
if (!option_name.empty())

View File

@ -127,5 +127,7 @@ struct cast {
}
};
wxString FontFace(std::string opt_prefix);
agi::fs::path OpenFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, wxString const& wildcard, wxWindow *parent);
agi::fs::path SaveFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, wxString const& wildcard, wxWindow *parent);