summaryrefslogtreecommitdiff
path: root/platform/macos
diff options
context:
space:
mode:
Diffstat (limited to 'platform/macos')
-rw-r--r--platform/macos/display_server_macos.mm18
-rw-r--r--platform/macos/export/export_plugin.cpp2
-rw-r--r--platform/macos/export/plist.cpp2
-rw-r--r--platform/macos/os_macos.h7
-rw-r--r--platform/macos/os_macos.mm140
5 files changed, 151 insertions, 18 deletions
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index 3aff5b8b7e..ad6143e16e 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -2348,9 +2348,6 @@ void DisplayServerMacOS::reparent_check(WindowID p_window) {
if (parent_screen == screen) {
if (![[wd_parent.window_object childWindows] containsObject:wd.window_object]) {
- if (wd.exclusive) {
- ERR_FAIL_COND_MSG([[wd_parent.window_object childWindows] count] > 0, "Transient parent has another exclusive child.");
- }
[wd.window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
[wd_parent.window_object addChildWindow:wd.window_object ordered:NSWindowAbove];
}
@@ -2369,9 +2366,6 @@ void DisplayServerMacOS::reparent_check(WindowID p_window) {
if (child_screen == screen) {
if (![[wd.window_object childWindows] containsObject:wd_child.window_object]) {
- if (wd_child.exclusive) {
- ERR_FAIL_COND_MSG([[wd.window_object childWindows] count] > 0, "Transient parent has another exclusive child.");
- }
if (wd_child.fullscreen) {
[wd_child.window_object toggleFullScreen:nil];
}
@@ -2426,7 +2420,7 @@ void DisplayServerMacOS::window_set_position(const Point2i &p_position, WindowID
ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];
- if ([wd.window_object isZoomed]) {
+ if (NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame])) {
return;
}
@@ -2549,7 +2543,7 @@ void DisplayServerMacOS::window_set_size(const Size2i p_size, WindowID p_window)
ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];
- if ([wd.window_object isZoomed]) {
+ if (NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame])) {
return;
}
@@ -2631,7 +2625,7 @@ void DisplayServerMacOS::window_set_mode(WindowMode p_mode, WindowID p_window) {
wd.exclusive_fullscreen = false;
} break;
case WINDOW_MODE_MAXIMIZED: {
- if ([wd.window_object isZoomed]) {
+ if (NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame])) {
[wd.window_object zoom:nil];
}
} break;
@@ -2664,7 +2658,7 @@ void DisplayServerMacOS::window_set_mode(WindowMode p_mode, WindowID p_window) {
}
} break;
case WINDOW_MODE_MAXIMIZED: {
- if (![wd.window_object isZoomed]) {
+ if (!NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame])) {
[wd.window_object zoom:nil];
}
} break;
@@ -2684,7 +2678,7 @@ DisplayServer::WindowMode DisplayServerMacOS::window_get_mode(WindowID p_window)
return WINDOW_MODE_FULLSCREEN;
}
}
- if ([wd.window_object isZoomed] && !wd.resize_disabled) {
+ if (NSEqualRects([wd.window_object frame], [[wd.window_object screen] visibleFrame])) {
return WINDOW_MODE_MAXIMIZED;
}
if ([wd.window_object respondsToSelector:@selector(isMiniaturized)]) {
@@ -2794,8 +2788,10 @@ void DisplayServerMacOS::window_set_flag(WindowFlags p_flag, bool p_enabled, Win
}
if (p_enabled) {
[wd.window_object setStyleMask:[wd.window_object styleMask] & ~NSWindowStyleMaskResizable];
+ [[wd.window_object standardWindowButton:NSWindowZoomButton] setEnabled:NO];
} else {
[wd.window_object setStyleMask:[wd.window_object styleMask] | NSWindowStyleMaskResizable];
+ [[wd.window_object standardWindowButton:NSWindowZoomButton] setEnabled:YES];
}
} break;
case WINDOW_FLAG_EXTEND_TO_TITLE: {
diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp
index 5860a4f0ae..5e71d10a3f 100644
--- a/platform/macos/export/export_plugin.cpp
+++ b/platform/macos/export/export_plugin.cpp
@@ -1834,8 +1834,8 @@ bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<Editor
if (p_preset->get("notarization/apple_id_name") != "") {
if (p_preset->get("notarization/apple_id_password") == "") {
err += TTR("Notarization: Apple ID password not specified.") + "\n";
+ valid = false;
}
- valid = false;
}
if (p_preset->get("notarization/api_uuid") != "") {
if (p_preset->get("notarization/api_key") == "") {
diff --git a/platform/macos/export/plist.cpp b/platform/macos/export/plist.cpp
index cad014e65b..82ecd41d9c 100644
--- a/platform/macos/export/plist.cpp
+++ b/platform/macos/export/plist.cpp
@@ -353,7 +353,7 @@ bool PList::load_file(const String &p_filename) {
} else {
// Load text plist.
Error err;
- Vector<uint8_t> array = FileAccess::get_file_as_array(p_filename, &err);
+ Vector<uint8_t> array = FileAccess::get_file_as_bytes(p_filename, &err);
ERR_FAIL_COND_V(err != OK, false);
String ret;
diff --git a/platform/macos/os_macos.h b/platform/macos/os_macos.h
index 46e7c17ebe..b2734e57cc 100644
--- a/platform/macos/os_macos.h
+++ b/platform/macos/os_macos.h
@@ -57,6 +57,10 @@ class OS_MacOS : public OS_Unix {
List<String> launch_service_args;
+ CGFloat _weight_to_ct(int p_weight) const;
+ CGFloat _stretch_to_ct(int p_stretch) const;
+ String _get_default_fontname(const String &p_font_name) const;
+
static _FORCE_INLINE_ String get_framework_executable(const String &p_path);
static void pre_wait_observer_cb(CFRunLoopObserverRef p_observer, CFRunLoopActivity p_activiy, void *p_context);
@@ -98,7 +102,8 @@ public:
virtual String get_locale() const override;
virtual Vector<String> get_system_fonts() const override;
- virtual String get_system_font_path(const String &p_font_name, bool p_bold = false, bool p_italic = false) const override;
+ virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
+ virtual Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override;
virtual String get_executable_path() const override;
virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
virtual Error create_instance(const List<String> &p_arguments, ProcessID *r_child_id = nullptr) override;
diff --git a/platform/macos/os_macos.mm b/platform/macos/os_macos.mm
index e620b058d3..ebba96ceb1 100644
--- a/platform/macos/os_macos.mm
+++ b/platform/macos/os_macos.mm
@@ -336,9 +336,7 @@ Vector<String> OS_MacOS::get_system_fonts() const {
return ret;
}
-String OS_MacOS::get_system_font_path(const String &p_font_name, bool p_bold, bool p_italic) const {
- String ret;
-
+String OS_MacOS::_get_default_fontname(const String &p_font_name) const {
String font_name = p_font_name;
if (font_name.to_lower() == "sans-serif") {
font_name = "Helvetica";
@@ -351,21 +349,153 @@ String OS_MacOS::get_system_font_path(const String &p_font_name, bool p_bold, bo
} else if (font_name.to_lower() == "cursive") {
font_name = "Apple Chancery";
};
+ return font_name;
+}
+
+CGFloat OS_MacOS::_weight_to_ct(int p_weight) const {
+ if (p_weight < 150) {
+ return -0.80;
+ } else if (p_weight < 250) {
+ return -0.60;
+ } else if (p_weight < 350) {
+ return -0.40;
+ } else if (p_weight < 450) {
+ return 0.0;
+ } else if (p_weight < 550) {
+ return 0.23;
+ } else if (p_weight < 650) {
+ return 0.30;
+ } else if (p_weight < 750) {
+ return 0.40;
+ } else if (p_weight < 850) {
+ return 0.56;
+ } else if (p_weight < 925) {
+ return 0.62;
+ } else {
+ return 1.00;
+ }
+}
+
+CGFloat OS_MacOS::_stretch_to_ct(int p_stretch) const {
+ if (p_stretch < 56) {
+ return -0.5;
+ } else if (p_stretch < 69) {
+ return -0.37;
+ } else if (p_stretch < 81) {
+ return -0.25;
+ } else if (p_stretch < 93) {
+ return -0.13;
+ } else if (p_stretch < 106) {
+ return 0.0;
+ } else if (p_stretch < 137) {
+ return 0.13;
+ } else if (p_stretch < 144) {
+ return 0.25;
+ } else if (p_stretch < 162) {
+ return 0.37;
+ } else {
+ return 0.5;
+ }
+}
+
+Vector<String> OS_MacOS::get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale, const String &p_script, int p_weight, int p_stretch, bool p_italic) const {
+ Vector<String> ret;
+ String font_name = _get_default_fontname(p_font_name);
+
+ CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, font_name.utf8().get_data(), kCFStringEncodingUTF8);
+ CTFontSymbolicTraits traits = 0;
+ if (p_weight >= 700) {
+ traits |= kCTFontBoldTrait;
+ }
+ if (p_italic) {
+ traits |= kCTFontItalicTrait;
+ }
+ if (p_stretch < 100) {
+ traits |= kCTFontCondensedTrait;
+ } else if (p_stretch > 100) {
+ traits |= kCTFontExpandedTrait;
+ }
+
+ CFNumberRef sym_traits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &traits);
+ CFMutableDictionaryRef traits_dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
+ CFDictionaryAddValue(traits_dict, kCTFontSymbolicTrait, sym_traits);
+
+ CGFloat weight = _weight_to_ct(p_weight);
+ CFNumberRef font_weight = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &weight);
+ CFDictionaryAddValue(traits_dict, kCTFontWeightTrait, font_weight);
+
+ CGFloat stretch = _stretch_to_ct(p_stretch);
+ CFNumberRef font_stretch = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &stretch);
+ CFDictionaryAddValue(traits_dict, kCTFontWidthTrait, font_stretch);
+
+ CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
+ CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, name);
+ CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits_dict);
+
+ CTFontDescriptorRef font = CTFontDescriptorCreateWithAttributes(attributes);
+ if (font) {
+ CTFontRef family = CTFontCreateWithFontDescriptor(font, 0, nullptr);
+ CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, p_text.utf8().get_data(), kCFStringEncodingUTF8);
+ CFRange range = CFRangeMake(0, CFStringGetLength(string));
+ CTFontRef fallback_family = CTFontCreateForString(family, string, range);
+ if (fallback_family) {
+ CTFontDescriptorRef fallback_font = CTFontCopyFontDescriptor(fallback_family);
+ if (fallback_font) {
+ CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(fallback_font, kCTFontURLAttribute);
+ if (url) {
+ NSString *font_path = [NSString stringWithString:[(__bridge NSURL *)url path]];
+ ret.push_back(String::utf8([font_path UTF8String]));
+ CFRelease(url);
+ }
+ CFRelease(fallback_font);
+ }
+ CFRelease(fallback_family);
+ }
+ CFRelease(string);
+ CFRelease(font);
+ }
+
+ CFRelease(attributes);
+ CFRelease(traits_dict);
+ CFRelease(sym_traits);
+ CFRelease(font_stretch);
+ CFRelease(font_weight);
+ CFRelease(name);
+
+ return ret;
+}
+
+String OS_MacOS::get_system_font_path(const String &p_font_name, int p_weight, int p_stretch, bool p_italic) const {
+ String ret;
+ String font_name = _get_default_fontname(p_font_name);
CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, font_name.utf8().get_data(), kCFStringEncodingUTF8);
CTFontSymbolicTraits traits = 0;
- if (p_bold) {
+ if (p_weight > 700) {
traits |= kCTFontBoldTrait;
}
if (p_italic) {
traits |= kCTFontItalicTrait;
}
+ if (p_stretch < 100) {
+ traits |= kCTFontCondensedTrait;
+ } else if (p_stretch > 100) {
+ traits |= kCTFontExpandedTrait;
+ }
CFNumberRef sym_traits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &traits);
CFMutableDictionaryRef traits_dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
CFDictionaryAddValue(traits_dict, kCTFontSymbolicTrait, sym_traits);
+ CGFloat weight = _weight_to_ct(p_weight);
+ CFNumberRef font_weight = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &weight);
+ CFDictionaryAddValue(traits_dict, kCTFontWeightTrait, font_weight);
+
+ CGFloat stretch = _stretch_to_ct(p_stretch);
+ CFNumberRef font_stretch = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &stretch);
+ CFDictionaryAddValue(traits_dict, kCTFontWidthTrait, font_stretch);
+
CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, name);
CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits_dict);
@@ -384,6 +514,8 @@ String OS_MacOS::get_system_font_path(const String &p_font_name, bool p_bold, bo
CFRelease(attributes);
CFRelease(traits_dict);
CFRelease(sym_traits);
+ CFRelease(font_stretch);
+ CFRelease(font_weight);
CFRelease(name);
return ret;