mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #8691 from switch87/fix/text-symbol-fallback
Type: fall back to the symbol and math fonts for signs like ⌖ and ⤒ (#8689)
This commit is contained in:
2 files changed
+57
-1
No files matched your search
@@ -113,11 +113,18 @@ pub const INDIC_FAMILIES: &[&[&str]] = &[
|
||||
MALAYALAM_FAMILIES,
|
||||
SINHALA_FAMILIES,
|
||||
];
|
||||
/// Symbol and math families for signs no text face has, such as ⌖ (U+2316) and ⤒ (U+2912):
|
||||
/// Windows (Segoe UI Symbol), macOS (Apple Symbols) and Linux (Noto, under the name fontconfig
|
||||
/// gives, "Noto Sans Symbols 2", and the "Noto Sans Symbols2" some packages use). They come after
|
||||
/// every other candidate, the emoji fonts included, so they only draw what those lack and an emoji
|
||||
/// keeps its colour face (#8689, as storytold/figcraft#1163).
|
||||
pub const SYMBOL_FAMILIES: &[&str] = &["Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols", "Noto Sans Symbols 2", "Noto Sans Symbols2", "Noto Sans Math"];
|
||||
/// Broad-coverage and emoji fonts, tried after the CJK script fonts so shared Han characters get
|
||||
/// the locale's forms instead of Arial Unicode's.
|
||||
const FALLBACK_LAST: &[&str] = &["Arial Unicode MS", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji"];
|
||||
|
||||
/// Every fallback family candidate, CJK ordered for `order` (see [`crate::cjk::script_order`]).
|
||||
/// Every fallback family candidate, CJK ordered for `order` (see [`crate::cjk::script_order`]),
|
||||
/// with the [`SYMBOL_FAMILIES`] last.
|
||||
pub fn fallback_candidates(order: &[crate::cjk::CjkScript; 4]) -> Vec<&'static str> {
|
||||
let mut v = FALLBACK_CANDIDATES.to_vec();
|
||||
v.extend_from_slice(THAI_FAMILIES);
|
||||
@@ -142,6 +149,7 @@ pub fn fallback_candidates(order: &[crate::cjk::CjkScript; 4]) -> Vec<&'static s
|
||||
v.extend_from_slice(crate::cjk::families(*s));
|
||||
}
|
||||
v.extend_from_slice(FALLBACK_LAST);
|
||||
v.extend_from_slice(SYMBOL_FAMILIES);
|
||||
v
|
||||
}
|
||||
|
||||
|
||||
@@ -2481,6 +2481,54 @@ fn indic_scripts_fall_back_to_installed_fonts() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Signs no text face has: ⌖ (U+2316, Miscellaneous Technical) and ⤒ (U+2912, Supplemental
|
||||
/// Arrows-B). They drew as .notdef boxes because no symbol font was a fallback candidate (#8689).
|
||||
const SYMBOLS: [char; 2] = ['\u{2316}', '\u{2912}'];
|
||||
|
||||
#[test]
|
||||
fn symbols_fall_back_to_installed_symbol_fonts() {
|
||||
let mut e = TextEngine::with_system_fonts();
|
||||
for c in SYMBOLS {
|
||||
// Layer 1: an installed symbol family, asked for by name, draws the sign. A character no
|
||||
// installed symbol family has is skipped, as the script tests skip a missing script font.
|
||||
let sample = c.to_string();
|
||||
let Some(hit) = fonts::SYMBOL_FAMILIES.iter().copied().find(|f| {
|
||||
e.fonts.has_family(f) && {
|
||||
let direct = TextLayer { text: sample.clone(), font_family: (*f).to_string(), size_pt: 24.0, ..Default::default() };
|
||||
let l = e.layout(&direct, 72.0);
|
||||
!l.glyphs.is_empty() && l.glyphs.iter().all(|g| g.id != 0)
|
||||
}
|
||||
}) else {
|
||||
eprintln!("skipped U+{:04X}: no installed symbol font has it", c as u32);
|
||||
continue;
|
||||
};
|
||||
// Layer 2, selection: after a Latin letter in a font without the sign, it falls back
|
||||
// instead of drawing a box, and the Latin keeps the chosen face.
|
||||
let l = e.layout(&point(&format!("A {c}"), 24.0), 72.0);
|
||||
assert!(l.glyphs.iter().all(|g| g.id != 0), "U+{:04X} drawn with .notdef although {hit} is installed", c as u32);
|
||||
let latin = l.glyphs.first().map(|g| g.face);
|
||||
assert!(l.glyphs.iter().any(|g| Some(g.face) != latin), "Latin and U+{:04X} drawn with the same face", c as u32);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn symbol_fallback_candidates_cover_every_platform() {
|
||||
// Logic-level half of #8689 (runs without these fonts): Windows (Segoe UI Symbol), macOS
|
||||
// (Apple Symbols) and Linux (the Noto symbol and math fonts, under the names fontconfig gives
|
||||
// and the "Symbols2" spelling some packages use) each have a symbol font in the candidates,
|
||||
// after the text faces and the emoji fonts, so a symbol font only draws what they lack.
|
||||
for order in [crate::cjk::script_order(None), crate::cjk::script_order(Some("ja"))] {
|
||||
let fb = fonts::fallback_candidates(&order);
|
||||
let earlier = ["Noto Sans", "Segoe UI", "DejaVu Sans", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji"]
|
||||
.map(|f| fb.iter().position(|x| *x == f).unwrap_or_else(|| panic!("{f} missing from {fb:?}")));
|
||||
for fam in ["Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols", "Noto Sans Symbols 2", "Noto Sans Symbols2", "Noto Sans Math"] {
|
||||
assert!(fonts::SYMBOL_FAMILIES.contains(&fam), "{fam} not a symbol family");
|
||||
let i = fb.iter().position(|f| *f == fam).unwrap_or_else(|| panic!("{fam} missing from {fb:?}"));
|
||||
assert!(earlier.iter().all(|t| *t < i), "{fam} ahead of a text or emoji face in {fb:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indic_fallback_candidates_cover_every_platform() {
|
||||
// Logic-level half (runs without these fonts): every script has a Windows, macOS and Linux
|
||||
|
||||
Reference in new issue
Block a user