diff --git a/Cargo.lock b/Cargo.lock index 6a602ed891..01e7d2ebfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6901,6 +6901,7 @@ dependencies = [ "cfb", "chrono", "craft-cdr", + "craft-codepage", "craft-docpath", "craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba25ccd233934d1b2f74e3c0f235168bf5f13ef3)", "craft-jxl", @@ -7060,6 +7061,7 @@ dependencies = [ name = "vectorcraft-metafile" version = "0.24.1" dependencies = [ + "craft-codepage", "craft-image-codecs 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ba25ccd233934d1b2f74e3c0f235168bf5f13ef3)", "craft-metafile", "image", diff --git a/Cargo.toml b/Cargo.toml index 6056916d75..29b7c94503 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "d7c9632bfb craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "d7c9632bfb3040cf45db394e7500cc93c81c49e0" } craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "d7c9632bfb3040cf45db394e7500cc93c81c49e0" } craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "d7c9632bfb3040cf45db394e7500cc93c81c49e0", features = ["egui"] } +craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "d7c9632bfb3040cf45db394e7500cc93c81c49e0" } # internal vectorcraft-geom = { path = "crates/geom" } vectorcraft-color = { path = "crates/color" } diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 075211dc1a..cf21c25e46 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -19,6 +19,7 @@ bundled-fonts = ["vectorcraft-text/bundled-fonts"] heif = ["dep:heic-rs", "dep:rayon"] [dependencies] +craft-codepage = { workspace = true } # Which paths stored in documents may be opened. craft-docpath = { workspace = true } craft-proof = { workspace = true } diff --git a/crates/engine/src/cmd/fileio/tests_psdlayers.rs b/crates/engine/src/cmd/fileio/tests_psdlayers.rs index 09acabbfa0..8660eee992 100644 --- a/crates/engine/src/cmd/fileio/tests_psdlayers.rs +++ b/crates/engine/src/cmd/fileio/tests_psdlayers.rs @@ -405,9 +405,9 @@ fn zipped_and_32_bit_layers_read() { /// A layer without a Unicode name takes the name its Pascal string holds, read as Mac Roman. #[test] fn names_without_a_unicode_name_read_as_mac_roman() { - let l = L { legacy: Some(b"Caf\x8E \xD2Old\xD3"), ..layer("", [0, 0, 1, 1], [0, 0, 0, 255]) }; + let l = L { legacy: Some(b"Caf\x8E\xCA\xD2Old\xD3\xDB"), ..layer("", [0, 0, 1, 1], [0, 0, 0, 255]) }; let (s, r) = open(&file(1, 1, &[l], 8, false, false), json!({})); - assert_eq!(name(&s.doc().unwrap().doc.layers[0]), "Café “Old”", "{r}"); + assert_eq!(name(&s.doc().unwrap().doc.layers[0]), "Café\u{a0}“Old”€", "{r}"); } #[test] diff --git a/crates/engine/src/cmd/place/rtf.rs b/crates/engine/src/cmd/place/rtf.rs index 5af9519521..f9282abd5d 100644 --- a/crates/engine/src/cmd/place/rtf.rs +++ b/crates/engine/src/cmd/place/rtf.rs @@ -651,8 +651,8 @@ mod tests { let s = read(concat!(r"{\rtf1\ansi\uc1 caf\u233?\uc2 \u", "8364", r"\'80\'80 \uc1\u-10179?\u-8704? end\'93q\'94}")); assert_eq!(text_of(&s), "café€ 😀 end“q”"); assert_eq!(text_of(&read(r"{\rtf1\uc1\u233\bin1 ?X}")), "éX", "binary data is one fallback character"); - let mac = read(r"{\rtf1\mac \'8e\'a5}"); - assert_eq!(text_of(&mac), "é•", "Mac Roman"); + let mac = read(r"{\rtf1\mac \'8e\'ca\'a5\'db\'de}"); + assert_eq!(text_of(&mac), "é\u{a0}•€fi", "Mac Roman"); } #[test] diff --git a/crates/engine/src/cmd/place/text.rs b/crates/engine/src/cmd/place/text.rs index 78261a8804..06ab1af83f 100644 --- a/crates/engine/src/cmd/place/text.rs +++ b/crates/engine/src/cmd/place/text.rs @@ -185,20 +185,7 @@ pub(in crate::cmd) fn windows_1252(b: u8) -> char { /// Byte `b` of Mac Roman. pub(in crate::cmd) fn mac_roman(b: u8) -> char { - const HIGH: [char; 128] = [ - 'Ä', 'Å', 'Ç', 'É', 'Ñ', 'Ö', 'Ü', 'á', 'à', 'â', 'ä', 'ã', 'å', 'ç', 'é', 'è', // - 'ê', 'ë', 'í', 'ì', 'î', 'ï', 'ñ', 'ó', 'ò', 'ô', 'ö', 'õ', 'ú', 'ù', 'û', 'ü', // - '†', '°', '¢', '£', '§', '•', '¶', 'ß', '®', '©', '™', '´', '¨', '≠', 'Æ', 'Ø', // - '∞', '±', '≤', '≥', '¥', 'µ', '∂', '∑', '∏', 'π', '∫', 'ª', 'º', 'Ω', 'æ', 'ø', // - '¿', '¡', '¬', '√', 'ƒ', '≈', '∆', '«', '»', '…', '\u{A0}', 'À', 'Ã', 'Õ', 'Œ', 'œ', // - '–', '—', '“', '”', '‘', '’', '÷', '◊', 'ÿ', 'Ÿ', '⁄', '€', '‹', '›', 'fi', 'fl', // - '‡', '·', '‚', '„', '‰', 'Â', 'Ê', 'Á', 'Ë', 'È', 'Í', 'Î', 'Ï', 'Ì', 'Ó', 'Ô', // - '\u{F8FF}', 'Ò', 'Ú', 'Û', 'Ù', 'ı', 'ˆ', '˜', '¯', '˘', '˙', '˚', '¸', '˝', '˛', 'ˇ', - ]; - match b { - 0x80.. => HIGH.get(usize::from(b - 0x80)).copied().unwrap_or(char::REPLACEMENT_CHARACTER), - _ => char::from(b), - } + craft_codepage::windows_byte(craft_codepage::MAC_ROMAN_CODE_PAGE, b) } /// `text` with its line breaks (CR LF, CR or LF) as paragraph breaks, cleaned up as `o` says: @@ -344,7 +331,7 @@ mod tests { let ansi = TextOptions { character_set: CharacterSet::Ansi, ..TextOptions::default() }; assert_eq!(decode(&[0x93, b'q', 0x94, 0xE9], ansi), "“q”é"); let mac = TextOptions { character_set: CharacterSet::Ansi, mac: true, ..TextOptions::default() }; - assert_eq!(decode(&[0xD2, b'q', 0xD3, 0x8E, 0xA5, 0xDB], mac), "“q”é•€"); + assert_eq!(decode(&[0xD2, b'q', 0xD3, 0x8E, 0xCA, 0xA5, 0xDB, 0xDE, 0xF0], mac), "“q”é\u{a0}•€fi\u{f8ff}"); } /// The other character sets decode by their Encoding Standard decoders: the platform matters diff --git a/crates/metafile/Cargo.toml b/crates/metafile/Cargo.toml index d8047c039a..1026a54c4b 100644 --- a/crates/metafile/Cargo.toml +++ b/crates/metafile/Cargo.toml @@ -9,6 +9,7 @@ description = "VectorCraft metafiles: EMF and WMF export and EMF, EMF+ and WMF i workspace = true [dependencies] +craft-codepage = { workspace = true } vectorcraft-geom = { workspace = true } vectorcraft-color = { workspace = true } vectorcraft-doc = { workspace = true } diff --git a/crates/metafile/src/import/pict.rs b/crates/metafile/src/import/pict.rs index a1e5a674e0..a5ef46316f 100644 --- a/crates/metafile/src/import/pict.rs +++ b/crates/metafile/src/import/pict.rs @@ -206,20 +206,7 @@ fn mix(a: [u8; 3], b: [u8; 3], t: f64) -> [u8; 3] { /// Byte `b` of Mac Roman. fn mac_roman(b: u8) -> char { - const HIGH: [char; 128] = [ - 'Ä', 'Å', 'Ç', 'É', 'Ñ', 'Ö', 'Ü', 'á', 'à', 'â', 'ä', 'ã', 'å', 'ç', 'é', 'è', // - 'ê', 'ë', 'í', 'ì', 'î', 'ï', 'ñ', 'ó', 'ò', 'ô', 'ö', 'õ', 'ú', 'ù', 'û', 'ü', // - '†', '°', '¢', '£', '§', '•', '¶', 'ß', '®', '©', '™', '´', '¨', '≠', 'Æ', 'Ø', // - '∞', '±', '≤', '≥', '¥', 'µ', '∂', '∑', '∏', 'π', '∫', 'ª', 'º', 'Ω', 'æ', 'ø', // - '¿', '¡', '¬', '√', 'ƒ', '≈', '∆', '«', '»', '…', '\u{A0}', 'À', 'Ã', 'Õ', 'Œ', 'œ', // - '–', '—', '“', '”', '‘', '’', '÷', '◊', 'ÿ', 'Ÿ', '⁄', '€', '‹', '›', 'fi', 'fl', // - '‡', '·', '‚', '„', '‰', 'Â', 'Ê', 'Á', 'Ë', 'È', 'Í', 'Î', 'Ï', 'Ì', 'Ó', 'Ô', // - '\u{F8FF}', 'Ò', 'Ú', 'Û', 'Ù', 'ı', 'ˆ', '˜', '¯', '˘', '˙', '˚', '¸', '˝', '˛', 'ˇ', - ]; - match b { - 0x80.. => HIGH.get(usize::from(b - 0x80)).copied().unwrap_or(char::REPLACEMENT_CHARACTER), - _ => char::from(b), - } + craft_codepage::windows_byte(craft_codepage::MAC_ROMAN_CODE_PAGE, b) } /// The family name of a classic Macintosh font number. diff --git a/crates/metafile/src/tests/pict.rs b/crates/metafile/src/tests/pict.rs index 0d8b48c939..54ca33de89 100644 --- a/crates/metafile/src/tests/pict.rs +++ b/crates/metafile/src/tests/pict.rs @@ -236,17 +236,23 @@ fn patterns_fill_with_their_average_color() { #[test] fn text_comes_in_as_point_type_in_the_named_font() { - let name = [be(&[9, 300]), vec![6], b"Geneva".to_vec()].concat(); + let name = [be(&[9, 300]), vec![6], b"Gen\x8Eva".to_vec()].concat(); let bytes = v2( [0, 0, 100, 200], - &[(0x2C, name), (0x03, be(&[300])), (0x0D, be(&[18])), (0x04, vec![1]), (0x28, [be(&[50, 10]), vec![4], b"Caf\x8E".to_vec()].concat())], + &[ + (0x2C, name), + (0x03, be(&[300])), + (0x0D, be(&[18])), + (0x04, vec![1]), + (0x28, [be(&[50, 10]), vec![8], b"Caf\x8E\xCA\xDB\xDE\xF0".to_vec()].concat()), + ], ); let p = import_pict(&bytes).unwrap(); let texts: Vec<_> = all(&p.document).into_iter().filter(|n| matches!(n.kind, NodeKind::Text(_))).collect(); let NodeKind::Text(t) = &texts[0].kind else { panic!("text") }; - assert_eq!(t.plain_text(), "Café"); + assert_eq!(t.plain_text(), "Café\u{a0}€fi\u{f8ff}"); let st = &t.runs[0].style; - assert_eq!((st.font_family.as_str(), st.font_style.as_str(), st.size), ("Geneva", "Bold", 18.0)); + assert_eq!((st.font_family.as_str(), st.font_style.as_str(), st.size), ("Genéva", "Bold", 18.0)); // The text location is the baseline's start. assert_eq!(t.xf.translation(), Point::new(10.0, 50.0).to_vec2()); }