diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-01-28 12:01:05 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-01-28 12:14:03 +0100 |
| commit | 28c554ec2185a15e22f0408ce485ed4afe035e03 (patch) | |
| tree | 622d2d281133c4e6b92633e44bfc1e1301250fb4 /src/model/symbol.rs | |
| parent | 23238d4d44881a5b466ab23a32e2a7447f460127 (diff) | |
Rework math attachments and accents
Diffstat (limited to 'src/model/symbol.rs')
| -rw-r--r-- | src/model/symbol.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/model/symbol.rs b/src/model/symbol.rs index 686f1b81..214fea3e 100644 --- a/src/model/symbol.rs +++ b/src/model/symbol.rs @@ -1,6 +1,6 @@ use std::cmp::Reverse; use std::collections::BTreeSet; -use std::fmt::{self, Debug, Formatter, Write}; +use std::fmt::{self, Debug, Display, Formatter, Write}; use crate::diag::StrResult; use crate::util::EcoString; @@ -109,6 +109,12 @@ impl Debug for Symbol { } } +impl Display for Symbol { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_char(self.get()) + } +} + /// Find the best symbol from the list. fn find(list: &[(&str, char)], modifiers: &str) -> Option<char> { let mut best = None; @@ -150,3 +156,30 @@ fn parts(modifiers: &str) -> impl Iterator<Item = &str> { fn contained(modifiers: &str, m: &str) -> bool { parts(modifiers).any(|part| part == m) } + +/// Normalize an accent to a combining one. +/// +/// https://www.w3.org/TR/mathml-core/#combining-character-equivalences +pub fn combining_accent(c: char) -> Option<char> { + Some(match c { + '\u{0300}' | '`' => '\u{0300}', + '\u{0301}' | '´' => '\u{0301}', + '\u{0302}' | '^' | 'ˆ' => '\u{0302}', + '\u{0303}' | '~' | '∼' | '˜' => '\u{0303}', + '\u{0304}' | '¯' => '\u{0304}', + '\u{0305}' | '-' | '‾' | '−' => '\u{0305}', + '\u{0306}' | '˘' => '\u{0306}', + '\u{0307}' | '.' | '˙' | '⋅' => '\u{0307}', + '\u{0308}' | '¨' => '\u{0308}', + '\u{030a}' | '∘' | '○' => '\u{030a}', + '\u{030b}' | '˝' => '\u{030b}', + '\u{030c}' | 'ˇ' => '\u{030c}', + '\u{0327}' | '¸' => '\u{0327}', + '\u{0328}' | '˛' => '\u{0328}', + '\u{0332}' | '_' => '\u{0332}', + '\u{20d6}' | '←' => '\u{20d6}', + '\u{20d7}' | '→' | '⟶' => '\u{20d7}', + '⏞' | '⏟' | '⎴' | '⎵' | '⏜' | '⏝' | '⏠' | '⏡' => c, + _ => return None, + }) +} |
