Skip to content

Commit

Permalink
Fix support for macOS 14 (#668)
Browse files Browse the repository at this point in the history
* core-text: define version variable and dbg!() it

Note that this test already has a number of dbg!() calls, presumably
to aid debugging when it fails in the future (for example due to
OS changes).

* core-text: extract helper function in test

* core-text: improve assertion to make failure easier to diagnose

* core-text: allow variations test to pass on 14.x.y

* CI: test on macOS 14

* CI: only test old Rust on one version
  • Loading branch information
djc authored Apr 16, 2024
1 parent 48d6bdf commit 199badc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-11.0, macos-12, macos-13]
toolchain: [stable, 1.56.1]
os: [macos-11.0, macos-12, macos-13, macos-14]
toolchain: [stable]
include:
- os: macos-14
toolchain: 1.56.1
steps:
- uses: actions/checkout@v4
- name: Install toolchain
Expand Down
38 changes: 28 additions & 10 deletions core-text/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,11 +940,13 @@ fn copy_system_font() {
#[test]
fn out_of_range_variations() {
use crate::*;
use core_foundation::base::ItemRef;

let small = new_ui_font_for_language(kCTFontSystemDetailFontType, 19., None);

let axes = small.get_variation_axes();
if macos_version() < (10, 12, 0) {
let version = dbg!(macos_version());
if version < (10, 12, 0) {
assert!(axes.is_none());
return;
}
Expand Down Expand Up @@ -980,10 +982,25 @@ fn out_of_range_variations() {
let var_desc = variation_font.copy_descriptor();
let var_attrs = var_desc.attributes();
dbg!(&var_attrs);
// attributes greater than max are dropped on macOS <= 11
// on macOS 12 they seem to be preserved as is.

// Handling of attributes greater than max changed between versions
let var_attrs = var_attrs.find(variation_attribute);
if macos_version() >= (12, 0, 0) && macos_version() < (13, 0, 0) {
if version >= (14, 0, 0) {
check_attrs(0., var_attrs, axes);
} else if version >= (12, 0, 0) && version < (13, 0, 0) {
check_attrs(1., var_attrs, axes);
} else if version >= (10, 15, 0) {
assert!(var_attrs.is_none());
} else {
let var_attrs = var_attrs.unwrap().downcast::<CFDictionary>().unwrap();
assert!(var_attrs.is_empty());
}

fn check_attrs(
clamp_diff: f64,
var_attrs: Option<ItemRef<'_, CFType>>,
axes: CFArray<CFDictionary<CFString, CFType>>,
) {
let var_attrs = var_attrs.unwrap().downcast::<CFDictionary>().unwrap();
assert!(!var_attrs.is_empty());
let var_attrs: CFDictionary<CFType, CFType> = unsafe { std::mem::transmute(var_attrs) };
Expand All @@ -1006,13 +1023,14 @@ fn out_of_range_variations() {
.unwrap()
.to_f64()
.unwrap();
assert_eq!(val, max + 1.);

let expected = max + clamp_diff;
assert_eq!(
val, expected,
"axis {:?} = {:?} (expected {:?})",
tag, val, expected
);
}
} else if macos_version() >= (10, 15, 0) {
assert!(var_attrs.is_none());
} else {
let var_attrs = var_attrs.unwrap().downcast::<CFDictionary>().unwrap();
assert!(var_attrs.is_empty());
}
}

Expand Down

0 comments on commit 199badc

Please sign in to comment.