misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
macOS: a font for Persian, Arabic, Hebrew and Armenian names (#533) (#538)
Ahmed Nefzaouif3ae50349383
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 199a24ca..8e9e90b0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see### Fixed+- 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)).- macOS: **Download File Info** opens in front of the browser that asked for it ([#484](https://github.com/anefzaoui/misterdownloadmanager/issues/484)).- The browser's **video button** over a hover-to-play preview (YouTube's thumbnails) no longer vanishes as the pointer goes to it: it stays where it was while the pointer is on it, a click downloads that video, and it fades once the pointer leaves ([#503](https://github.com/anefzaoui/misterdownloadmanager/issues/503)).diff --git a/ROADMAP.md b/ROADMAP.mdindex 231b1404..ccd76ab5 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -519,6 +519,9 @@ These ship in a later version, when they're ready.### Bugs being looked into+- π macOS: Persian and other Arabic-script file names drawn as boxes in the download list+ ([#533](https://github.com/anefzaoui/misterdownloadmanager/issues/533)): fix in review, to+ confirm on a Mac- π macOS: Download File Info opening behind the browser that asked for it\n ([#484](https://github.com/anefzaoui/misterdownloadmanager/issues/484)): fix in review- π The browser tests: the video button's focus case ran after the one that turns the buttonoff for the test site, and timed out in a full run ([#480](https://github.com/anefzaoui/misterdownloadmanager/issues/480)): fix in reviewdiff --git a/crates/app/src/theme.rs b/crates/app/src/theme.rsindex d19097cc..faaef77d 100644--- a/crates/app/src/theme.rs+++ b/crates/app/src/theme.rs@@ -401,7 +401,7 @@ fn font_dir() -> std::path::PathBuf {struct ScriptFallback;/// One script's fonts on demand: a key, its code points, the files to try (in order).-#[cfg(any(windows, target_os = "macos"))]+#[cfg_attr(not(any(windows, target_os = "macos")), allow(dead_code))]struct FallbackFont {key: &'static str,ranges: &'static [(u32, u32)],@@ -476,9 +476,12 @@ const FALLBACK_FONTS: &[FallbackFont] = &[},];-/// macOS's fonts for the same scripts; Arial Unicode for what isn't listed.+/// macOS's fonts for the same scripts; Arial Unicode for what isn't listed. Compiled everywhere,+/// so the tests check it on every system.#[cfg(target_os = "macos")]-const FALLBACK_FONTS: &[FallbackFont] = &[+const FALLBACK_FONTS: &[FallbackFont] = MACOS_FALLBACK_FONTS;+#[cfg_attr(not(target_os = "macos"), allow(dead_code))]+const MACOS_FALLBACK_FONTS: &[FallbackFont] = &[FallbackFont {key: "japanese",ranges: &[(0x3040, 0x30FF), (0x31F0, 0x31FF), (0xFF66, 0xFF9F)],@@ -523,13 +526,30 @@ const FALLBACK_FONTS: &[FallbackFont] = &[ranges: &[(0x1200, 0x139F), (0x2D80, 0x2DDF), (0xAB00, 0xAB2F)],files: &["Supplemental/Kefa.ttc", "Kefa.ttc"],},+ // Armenian, Hebrew and the Arabic script (Persian, Urdu: #533) too: the system font (SF)+ // has none of them, and Windows' Segoe UI, which has them, isn't there. The same font an+ // Arabic or Persian interface loads ([`SCRIPT_FONTS`]).FallbackFont {key: "unicode",- ranges: &[(0x0900, 0x13FF), (0x1800, 0x1FFF)],+ ranges: &[+ (0x0530, 0x13FF),+ (0x1800, 0x1FFF),+ (0xFB1D, 0xFDFF),+ (0xFE70, 0xFEFF),+ ],files: &["Supplemental/Arial Unicode.ttf"],},];+/// The font in `fonts` for `c`: the first that lists its code point.+#[cfg_attr(not(any(windows, target_os = "macos")), allow(dead_code))]+fn fallback_entry(fonts: &'static [FallbackFont], c: char) -> Option<&'static FallbackFont> {+ let cp = c as u32;+ fonts+ .iter()+ .find(|f| f.ranges.iter().any(|&(a, b)| (a..=b).contains(&cp)))+}+/// The bytes of the font for `c`, loaded once per font, shared by every family that asks.fn fallback_font(c: char) -> Option<(String, egui::FontData)> {use std::collections::HashMap;@@ -538,10 +558,7 @@ fn fallback_font(c: char) -> Option<(String, egui::FontData)> {#[cfg(any(windows, target_os = "macos"))]let (key, files): (String, Vec<std::path::PathBuf>) = {- let cp = c as u32;- let font = FALLBACK_FONTS- .iter()- .find(|f| f.ranges.iter().any(|&(a, b)| (a..=b).contains(&cp)))?;+ let font = fallback_entry(FALLBACK_FONTS, c)?;let dir = font_dir();(format!("fallback:{}", font.key),@@ -990,6 +1007,51 @@ mod glyph_tests {assert!(fonts.has_glyphs(&id, text), "no font for {text}");}}++ /// Names in the Arabic script (a Persian file name, #533), Hebrew and Armenian, under an+ /// English interface on macOS: its system font has none of them, so the fallback must name a+ /// font for every letter. Before, macOS's list started at Devanagari, and they were boxes.+ /// Checked on every system (the table is data); the font itself in the macOS test below.+ const OTHER_SCRIPTS: [&str; 5] = [+ "\u{0641}\u{0627}\u{06CC}\u{0644} \u{067E}\u{0698}\u{0648}\u{0647}\u{0634}\u{06CC} \u{06F1}\u{06F4}\u{06F0}\u{06F3}", // Persian, with Persian digits+ "\u{06AF}\u{0632}\u{0627}\u{0631}\u{0634} \u{0686}\u{06A9}", // Persian+ "\u{0645}\u{0644}\u{0641}", // Arabic+ "\u{05E7}\u{05D5}\u{05D1}\u{05E5}", // Hebrew+ "\u{0586}\u{0561}\u{0575}\u{056C}", // Armenian+ ];++ #[test]+ fn macos_names_a_font_for_the_arabic_script() {+ for text in OTHER_SCRIPTS {+ for c in text.chars().filter(|c| !c.is_whitespace()) {+ let font = super::fallback_entry(super::MACOS_FALLBACK_FONTS, c)+ .unwrap_or_else(|| panic!("no macOS font for U+{:04X} in {text}", c as u32));+ // The file macOS ships (/System/Library/Fonts/Supplemental), which an Arabic or+ // Persian interface already loads.+ assert!(+ font.files.contains(&"Supplemental/Arial Unicode.ttf"),+ "U+{:04X}: {:?}",+ c as u32,+ font.files+ );+ }+ }+ }++ /// The same names drawn with macOS's own fonts: the fallback finds a file that is there and+ /// has the letters.+ #[cfg(target_os = "macos")]+ #[test]+ fn persian_names_get_a_font_on_macos() {+ use egui::epaint::text::{Fonts, TextOptions};+ use egui::{FontFamily, FontId};+ let mut fonts = Fonts::new(TextOptions::default(), egui::FontDefinitions::default())+ .with_font_providers(vec![std::sync::Arc::new(super::ScriptFallback)]);+ let id = FontId::new(13.0, FontFamily::Proportional);+ for text in OTHER_SCRIPTS {+ assert!(fonts.has_glyphs(&id, text), "no font for {text}");+ }+ }use std::collections::{BTreeMap, BTreeSet};use std::path::Path;use unicode_segmentation::UnicodeSegmentation;