mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Integration: don't count symbols on Mac Roman letters as windows-1252 (#8327)
The previous fix-up counted § ® ¾ ¿ (and ¹ » ¼ ½) as common windows-1252
text, but those bytes are Mac Roman ß Æ æ ø (π ª º Ω). Mac names with no
Unicode copy such as "Weiß", "Gaußscher Weichzeichner", "Størrelse",
"Lærredstørrelse" and "Æble" then tied and read as windows-1252 ("Wei§",
"St¿rrelse"), where the PR read them right.
Keep only the 12 symbols whose byte is not a letter in Mac Roman
(¡ ¢ £ ¥ © « ° ± ² ³ ¶ ·). Windows "Größe »", "50 °" and "« auto »" still
read as windows-1252; a name whose only non-ASCII character is ® ("Logo
®") reads as Mac Roman "Logo Æ" again, as on the PR head (tested as a
known limitation).
Co-authored-by: regexer <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
af59f65b82
commit
1d0bc23c3e
3 files changed
+69
-24
No files matched your search
@@ -3214,10 +3214,10 @@ fn load_decodes_legacy_step_names() {
|
||||
|
||||
#[test]
|
||||
fn load_keeps_windows_1252_symbols() {
|
||||
// Windows Photoshop step names with no Unicode copy: ® and » are letters in Mac Roman, which
|
||||
// must not win ("Logo Æ", "Grˆfle ª"). Save Actions writes the names back as that text.
|
||||
// Windows Photoshop step names with no Unicode copy: Mac Roman reads ° and » as ∞ and ª,
|
||||
// which must not win ("50 ∞", "Grˆfle ª"). Save Actions writes the names back as that text.
|
||||
let steps = vec![
|
||||
AtnItem { dictionary: b"Logo \xae".to_vec(), ..item("syntheticFill", "", None) },
|
||||
AtnItem { dictionary: b"50 \xb0".to_vec(), ..item("syntheticFill", "", None) },
|
||||
AtnItem { dictionary: b"Gr\xf6\xdfe \xbb".to_vec(), ..item("syntheticFill", "", None) },
|
||||
];
|
||||
let file = AtnFile {
|
||||
@@ -3228,12 +3228,12 @@ fn load_keeps_windows_1252_symbols() {
|
||||
let mut s = Session::new();
|
||||
let r = s.execute("actions.load", json!({"data": b64(&atn::write(&file).unwrap())})).unwrap();
|
||||
assert_eq!(r["encoding"], "windows-1252", "{r}");
|
||||
assert_eq!(r["unsupported"][0]["name"], "Logo ®", "{r}");
|
||||
assert_eq!(r["unsupported"][0]["name"], "50 °", "{r}");
|
||||
assert_eq!(r["unsupported"][1]["name"], "Größe »", "{r}");
|
||||
let saved = s.execute("actions.save", json!({"set": "Größe ändern"})).unwrap();
|
||||
let saved = atn::parse(&photocraft_paint::tile::b64_decode(saved["data"].as_str().unwrap()).unwrap()).unwrap();
|
||||
let names: Vec<String> = saved.actions[0].items.iter().map(|i| saved.item_label(i)).collect();
|
||||
assert_eq!(names, ["Logo ®", "Größe »"]);
|
||||
assert_eq!(names, ["50 °", "Größe »"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+27
-5
@@ -644,15 +644,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn latin1_symbol_names_read_as_windows_1252() {
|
||||
// Windows Photoshop "Logo ®" and "Größe »" with no Unicode copy: Mac Roman reads these
|
||||
// bytes as letters ("Logo Æ", "Grˆfle ª"), but they are windows-1252, as before #6743.
|
||||
let f = parse(&one_action("Set 1", "Action 1", vec![bare(AtnEvent::name("x"), b"Logo \xae")])).unwrap();
|
||||
assert_eq!(f.encoding.as_deref(), Some("windows-1252"));
|
||||
assert_eq!(labels(&f), ["Logo ®"]);
|
||||
// Windows Photoshop "Größe »" and "50 °" with no Unicode copy: Mac Roman reads these
|
||||
// bytes as letters and symbols ("Grˆfle ª", "50 ∞"), but they are windows-1252, as before
|
||||
// #6743.
|
||||
let f = parse(&one_action("Größe ändern", "Aktion", vec![bare(AtnEvent::name("x"), b"Gr\xf6\xdfe \xbb")])).unwrap();
|
||||
assert_eq!(f.encoding.as_deref(), Some("windows-1252"));
|
||||
assert_eq!(labels(&f), ["Größe »"]);
|
||||
assert!(f.warnings.is_empty(), "{:?}", f.warnings);
|
||||
let f = parse(&one_action("Größe ändern", "Aktion", vec![bare(AtnEvent::name("x"), b"50 \xb0")])).unwrap();
|
||||
assert_eq!(labels(&f), ["50 °"]);
|
||||
// Known limitation: "Logo ®" alone reads as Mac Roman "Logo Æ", as Mac "Æble" needs that
|
||||
// byte (codepage's symbols_on_mac_roman_letters_stay_ambiguous).
|
||||
let f = parse(&one_action("Set 1", "Action 1", vec![bare(AtnEvent::name("x"), b"Logo \xae")])).unwrap();
|
||||
assert_eq!(f.encoding.as_deref(), Some("macintosh"));
|
||||
assert_eq!(labels(&f), ["Logo Æ"]);
|
||||
// Mac Roman bytes that windows-1252 reads as controls or rare letters stay Mac Roman.
|
||||
let f =
|
||||
parse(&one_action("Définir", "Action 1", vec![bare(AtnEvent::name("x"), b"Gr\x9a\xa7e"), bare(AtnEvent::name("y"), b"Arri\x8fre-plan")])).unwrap();
|
||||
@@ -660,6 +665,23 @@ mod tests {
|
||||
assert_eq!(labels(&f), ["Größe", "Arrière-plan"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mac_roman_sharp_s_and_slashed_o_stay_mac_roman() {
|
||||
// Mac Roman ß ø æ Æ are the bytes of windows-1252 § ¿ ¾ ®: German and Danish Mac names
|
||||
// with no Unicode copy still read as Mac Roman, each alone and as a set.
|
||||
let words: [&[u8]; 5] = [b"Wei\xa7", b"Gau\xa7scher Weichzeichner", b"St\xbfrrelse", b"L\xberredst\xbfrrelse", b"\xaeble"];
|
||||
let text = ["Weiß", "Gaußscher Weichzeichner", "Størrelse", "Lærredstørrelse", "Æble"];
|
||||
for (bytes, text) in words.iter().zip(text) {
|
||||
let f = parse(&one_action("Größe ändern", "Aktion 1", vec![bare(AtnEvent::name("x"), bytes)])).unwrap();
|
||||
assert_eq!((f.encoding.as_deref(), labels(&f)), (Some("macintosh"), vec![text.to_string()]));
|
||||
assert!(f.warnings.is_empty(), "{:?}", f.warnings);
|
||||
}
|
||||
let items = words.iter().map(|w| bare(AtnEvent::name("x"), w)).collect();
|
||||
let f = parse(&one_action("Größe ändern", "Aktion 1", items)).unwrap();
|
||||
assert_eq!(f.encoding.as_deref(), Some("macintosh"));
|
||||
assert_eq!(labels(&f), text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn known_names_alone_never_warn() {
|
||||
// Nothing decodes to the Unicode name, but nothing is shown from the bytes either.
|
||||
|
||||
+37
-14
@@ -16,9 +16,9 @@
|
||||
//! fine): kana → Shift_JIS; Hangul → EUC-KR; Cyrillic → windows-1251; Han → GBK, then
|
||||
//! Big5, then Shift_JIS; Latin letters → windows-1252, then Mac Roman.
|
||||
//! 4. Still tied: windows-1252, flagged [`Guess::uncertain`].
|
||||
//! 5. Mac Roman must also beat windows-1252 when Latin-1's symbols (© ® ° § « » ± ½…) count
|
||||
//! as common text, as Mac Roman's letters sit on those bytes (1252 "Logo ®" is Mac Roman
|
||||
//! "Logo Æ"). Otherwise the names are windows-1252, with step 3's hint and step 4's warning.
|
||||
//! 5. Mac Roman must also beat windows-1252 when the Latin-1 symbols that are no letter in
|
||||
//! Mac Roman (© ° « ± …) count as common text (1252 "Größe »" is Mac Roman "Grˆfle ª").
|
||||
//! Otherwise the names are windows-1252, with step 3's hint and step 4's warning.
|
||||
//!
|
||||
//! Only the first [`GUESS_SAMPLE`] bytes of names are examined.
|
||||
|
||||
@@ -241,9 +241,12 @@ fn is_latin_common(ch: char) -> bool {
|
||||
(ch.is_alphabetic() && !['Š', 'š', 'Ž', 'ž', 'Œ', 'œ', 'Ÿ', 'ƒ', 'ˆ'].contains(&ch)) || TYPOGRAPHIC.contains(&ch) || LATIN_SYMBOLS.contains(&ch)
|
||||
}
|
||||
|
||||
/// Latin-1 symbols people type in names (windows-1252 0xA1–0xF7). Not € or ™: windows-1252 has
|
||||
/// them at 0x80 and 0x99, Mac Roman's Ä and ô.
|
||||
const LATIN_SYMBOLS: [char; 20] = ['¡', '¢', '£', '¥', '§', '©', '«', '®', '°', '±', '²', '³', '¶', '·', '¹', '»', '¼', '½', '¾', '¿'];
|
||||
/// Latin-1 symbols people type in names (windows-1252 0xA1–0xB7) whose byte is not a letter in
|
||||
/// Mac Roman. Left out because Mac Roman has a letter there: § ® ¹ » ¼ ½ ¾ ¿ (ß Æ π ª º Ω æ ø,
|
||||
/// as in Mac "Weiß", "Størrelse", "Æble"), € and ™ (0x80, 0x99: Ä, ô). So a windows-1252 name
|
||||
/// whose only non-ASCII character is one of those ("Logo ®") still reads as Mac Roman ("Logo
|
||||
/// Æ").
|
||||
const LATIN_SYMBOLS: [char; 12] = ['¡', '¢', '£', '¥', '©', '«', '°', '±', '²', '³', '¶', '·'];
|
||||
|
||||
/// Quotes, dashes, ellipsis and bullet: windows-1252 and windows-1251 share them at 0x82–0x97;
|
||||
/// Mac Roman has them too.
|
||||
@@ -398,24 +401,44 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn latin1_symbols_read_as_1252_not_mac_roman() {
|
||||
// Mac Roman has letters where windows-1252 has © ® « » §: 1252 "Logo ®" is Mac Roman
|
||||
// "Logo Æ", "Größe »" is "Grˆfle ª". Latin-1 (what a code-page-blind reader shows) wins.
|
||||
let logo: &[&[u8]] = &[b"Logo \xae"];
|
||||
assert_eq!(guess(logo, "Set 1"), Guess { encoding: WINDOWS_1252, uncertain: true });
|
||||
assert_eq!(guess(logo, "Größe ändern"), Guess { encoding: WINDOWS_1252, uncertain: false });
|
||||
assert_eq!(decode(logo[0], WINDOWS_1252), "Logo ®");
|
||||
for words in [&["Größe »"][..], &["Contraste « auto »", "§ 3 Größe", "½ Größe", "Teinte ¾ ©"]] {
|
||||
// Mac Roman has letters where windows-1252 has some symbols: 1252 "Größe »" is Mac Roman
|
||||
// "Grˆfle ª", "50 °" is "50 ∞". Latin-1 (what a code-page-blind reader shows) wins.
|
||||
for words in [&["Größe »"][..], &["50 °"], &["Contraste « auto »", "© Größe", "± 5"]] {
|
||||
let g = guess_words(WINDOWS_1252, words, "Größe ändern");
|
||||
assert_eq!(g, Guess { encoding: WINDOWS_1252, uncertain: false }, "{words:?}");
|
||||
assert_eq!(guess_words(WINDOWS_1252, words, "Set 1").encoding, WINDOWS_1252, "{words:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn symbols_on_mac_roman_letters_stay_ambiguous() {
|
||||
// Known limitation: 1252 "Logo ®" is Mac Roman "Logo Æ", and ® is not counted for
|
||||
// windows-1252 because Mac "Æble" and "Weiß" use those bytes, so the name reads as Mac
|
||||
// Roman whatever the hint, as it did before the symbols counted at all.
|
||||
let logo: &[&[u8]] = &[b"Logo \xae"];
|
||||
assert_eq!(guess(logo, "Größe ändern"), Guess { encoding: MACINTOSH, uncertain: false });
|
||||
assert_eq!(guess(logo, "Set 1"), Guess { encoding: MACINTOSH, uncertain: false });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mac_roman_letters_still_read_as_mac_roman() {
|
||||
// Mac Roman "Größe" is 1252 "Grš§e", "Ändern" "€ndern", "Contrôle" "Contr™le": Mac Roman
|
||||
// still wins once § counts as common text in windows-1252.
|
||||
for word in ["Größe", "Ändern", "Contrôle"] {
|
||||
// Mac Roman ß ø æ Æ are 1252 § ¿ ¾ ®, which windows-1252 must not count as common.
|
||||
let words = [
|
||||
"Größe",
|
||||
"Ändern",
|
||||
"Contrôle",
|
||||
"Weiß",
|
||||
"Schwarzweiß",
|
||||
"Gaußscher Weichzeichner",
|
||||
"Schließen",
|
||||
"Størrelse",
|
||||
"Lærredstørrelse",
|
||||
"Fjern støy",
|
||||
"Æble",
|
||||
];
|
||||
for word in words {
|
||||
let g = guess_words(MACINTOSH, &[word], "Définir l’arrière-plan");
|
||||
assert_eq!(g, Guess { encoding: MACINTOSH, uncertain: false }, "{word}");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user