summaryrefslogtreecommitdiff
path: root/src/util/mac.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-25 13:24:30 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-25 13:24:30 +0200
commitf2882bf85476cd55eaad0594d983fbcf8a1ef778 (patch)
tree8235ec36788e919c8a1ebbcc878231b415636a7f /src/util/mac.rs
parent821536b253bed0753eb031d4cc7fbd407dce9f39 (diff)
Support decoding of mac roman names
This allows discovery of Apple fonts without unicode name entries.
Diffstat (limited to 'src/util/mac.rs')
-rw-r--r--src/util/mac.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util/mac.rs b/src/util/mac.rs
new file mode 100644
index 00000000..95e8fcd6
--- /dev/null
+++ b/src/util/mac.rs
@@ -0,0 +1,25 @@
+/// Decode mac roman encoded bytes into a string.
+pub fn decode_mac_roman(coded: &[u8]) -> String {
+ coded.iter().copied().map(char_from_mac_roman).collect()
+}
+
+/// Convert a mac roman coded character to a unicode char.
+fn char_from_mac_roman(code: u8) -> char {
+ #[rustfmt::skip]
+ const TABLE: [char; 128] = [
+ 'Ä', 'Å', 'Ç', 'É', 'Ñ', 'Ö', 'Ü', 'á', 'à', 'â', 'ä', 'ã', 'å', 'ç', 'é', 'è',
+ 'ê', 'ë', 'í', 'ì', 'î', 'ï', 'ñ', 'ó', 'ò', 'ô', 'ö', 'õ', 'ú', 'ù', 'û', 'ü',
+ '†', '°', '¢', '£', '§', '•', '¶', 'ß', '®', '©', '™', '´', '¨', '≠', 'Æ', 'Ø',
+ '∞', '±', '≤', '≥', '¥', 'µ', '∂', '∑', '∏', 'π', '∫', 'ª', 'º', 'Ω', 'æ', 'ø',
+ '¿', '¡', '¬', '√', 'ƒ', '≈', '∆', '«', '»', '…', '\u{a0}', 'À', 'Ã', 'Õ', 'Œ', 'œ',
+ '–', '—', '“', '”', '‘', '’', '÷', '◊', 'ÿ', 'Ÿ', '⁄', '€', '‹', '›', 'fi', 'fl',
+ '‡', '·', '‚', '„', '‰', 'Â', 'Ê', 'Á', 'Ë', 'È', 'Í', 'Î', 'Ï', 'Ì', 'Ó', 'Ô',
+ '\u{f8ff}', 'Ò', 'Ú', 'Û', 'Ù', 'ı', 'ˆ', '˜', '¯', '˘', '˙', '˚', '¸', '˝', '˛', 'ˇ',
+ ];
+
+ if code < 128 {
+ code as char
+ } else {
+ TABLE[(code - 128) as usize]
+ }
+}