Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

macOS 15+: resolve PingFang.ttc from AssetsV2 MobileAsset font directory (#552)

鲲侯·星河易道@BigFishMarquis852b4c0cc63d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a97fc5b..09a6ad84 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- macOS 15 and later: Chinese names and text find the PingFang font again, which moved into the system's font assets, with Hiragino Sans GB and STHeiti as fallbacks ([#541](https://github.com/anefzaoui/misterdownloadmanager/issues/541)).
- The video button follows **Options → General → Customize MDM Download panels in browsers** in the pages already open: switched off, or its site listed, it goes within a few seconds, without reloading the page (it stayed until a reload, and on YouTube, which never reloads, for good). A site listed as `example.com` now takes `www.example.com` and its other subdomains too, and a player embedded from another site follows the site in the address bar ([#532](https://github.com/anefzaoui/misterdownloadmanager/issues/532)).
- macOS: file names in Persian, Arabic, Urdu, Hebrew or Armenian show their letters in the download list and windows instead of boxes, whatever the interface language: these scripts now get the font for them that comes with macOS (Arial Unicode), the first time one is needed ([#533](https://github.com/anefzaoui/misterdownloadmanager/issues/533)).
- A download's progress is saved from its first seconds again: since 0.5.2, when the disk was slow to write the resume state as the download started (no data had arrived yet), the first save of its progress waited nine times as long, up to a minute, so a short download cut off by a crash or a power cut in that time started over from the beginning (part of [#518](https://github.com/anefzaoui/misterdownloadmanager/issues/518)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 778b5138..976d7fed 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -522,6 +522,8 @@ These ship in a later version, when they're ready.
### Bugs being looked into
+- 🔄 macOS 15 and later: PingFang moved into the system's font assets, so Chinese text lost its
+ font ([#541](https://github.com/anefzaoui/misterdownloadmanager/issues/541)): fix in review
- 🔄 The video button still showing after it was switched off, or its site listed, in Options
([#532](https://github.com/anefzaoui/misterdownloadmanager/issues/532)): fix in review
- 🔄 macOS: Persian and other Arabic-script file names drawn as boxes in the download list
diff --git a/crates/app/src/theme.rs b/crates/app/src/theme.rs
index faaef77d..884c28e0 100644
--- a/crates/app/src/theme.rs
+++ b/crates/app/src/theme.rs
@@ -295,7 +295,12 @@ const SCRIPT_FONTS: &[(&str, &[&str], &[&str])] = &[
const SCRIPT_FONTS: &[(&str, &[&str], &[&str])] = &[
(
"han",
- &["PingFang.ttc", "Supplemental/Songti.ttc"],
+ &[
+ "PingFang.ttc",
+ "Hiragino Sans GB.ttc",
+ "STHeiti Light.ttc",
+ "Supplemental/Songti.ttc",
+ ],
&["zh-hans", "zh-hant"],
),
("japanese", &["ヒラギノ角ゴシック W3.ttc"], &["ja"]),
@@ -391,6 +396,31 @@ fn font_dir() -> std::path::PathBuf {
return std::path::PathBuf::from("/System/Library/Fonts");
}
+/// Resolves a font file path in `dir`. On macOS 15+ (Sequoia / Tahoe), `PingFang.ttc` moved out
+/// of `/System/Library/Fonts/PingFang.ttc` into `/System/Library/AssetsV2/com_apple_MobileAsset_Font*`.
+#[cfg(any(windows, target_os = "macos"))]
+fn font_path(dir: &std::path::Path, rel: &str) -> std::path::PathBuf {
+ let direct = dir.join(rel);
+ #[cfg(target_os = "macos")]
+ if rel == "PingFang.ttc" && !direct.exists() {
+ for base in [
+ "/System/Library/AssetsV2/com_apple_MobileAsset_Font8",
+ "/System/Library/AssetsV2/com_apple_MobileAsset_Font7",
+ "/System/Library/AssetsV2/com_apple_MobileAsset_Font6",
+ ] {
+ if let Ok(entries) = std::fs::read_dir(base) {
+ for entry in entries.flatten() {
+ let p = entry.path().join("AssetData/PingFang.ttc");
+ if p.is_file() {
+ return p;
+ }
+ }
+ }
+ }
+ }
+ direct
+}
+
/// The fonts for scripts outside the interface language, loaded the first time a character
/// needs one (#405): a file or video named in Bangla, Japanese, Thai... The interface language's
/// own script fonts are loaded up front ([`SCRIPT_FONTS`], kept small for #72); anything else
@@ -509,7 +539,12 @@ const MACOS_FALLBACK_FONTS: &[FallbackFont] = &[
(0xFF00, 0xFFEF),
(0x20000, 0x3FFFF),
],
- files: &["PingFang.ttc", "Supplemental/Songti.ttc"],
+ files: &[
+ "PingFang.ttc",
+ "Hiragino Sans GB.ttc",
+ "STHeiti Light.ttc",
+ "Supplemental/Songti.ttc",
+ ],
},
FallbackFont {
key: "khmer",
@@ -562,7 +597,7 @@ fn fallback_font(c: char) -> Option<(String, egui::FontData)> {
let dir = font_dir();
(
format!("fallback:{}", font.key),
- font.files.iter().map(|f| dir.join(f)).collect(),
+ font.files.iter().map(|f| font_path(&dir, f)).collect(),
)
};
#[cfg(not(any(windows, target_os = "macos")))]
@@ -650,7 +685,9 @@ fn script_fonts(code: &str, all: bool) -> Vec<(String, Vec<u8>)> {
// The first file there is used (older systems name some differently); a .ttc's
// first face is the regular one.
.filter_map(|(key, files, _)| {
- let bytes = files.iter().find_map(|f| std::fs::read(dir.join(f)).ok())?;
+ let bytes = files
+ .iter()
+ .find_map(|f| std::fs::read(font_path(&dir, f)).ok())?;
Some(((*key).to_owned(), bytes))
})
.collect()