Normalize native XeTeX physical input before tokenization
This commit is contained in:
1 parent
048478c346
commit
76df2d6832
10 files changed
+214
-63
No files matched your search
@@ -483,9 +483,7 @@ fn push(output: &mut Vec<Entry>, value: u32, source: &PaintSource) -> Result<(),
|
||||
}
|
||||
|
||||
fn normalize(input: Vec<Entry>, composed: bool) -> Result<Vec<Entry>, &'static str> {
|
||||
use unicode_normalization::char::{
|
||||
canonical_combining_class as ccc, compose, decompose_canonical,
|
||||
};
|
||||
use unicode_normalization::char::decompose_canonical;
|
||||
|
||||
let mut decomposed = Vec::with_capacity(input.len());
|
||||
for entry in input {
|
||||
@@ -498,35 +496,15 @@ fn normalize(input: Vec<Entry>, composed: bool) -> Result<Vec<Entry>, &'static s
|
||||
return Err("mapped OpenType word capacity exceeded");
|
||||
}
|
||||
}
|
||||
let mut marks = 0;
|
||||
for i in 0..decomposed.len() {
|
||||
if ccc(decomposed[i].0) == 0 {
|
||||
decomposed[marks..i].sort_by_key(|(c, _)| ccc(*c));
|
||||
marks = i + 1;
|
||||
}
|
||||
}
|
||||
decomposed[marks..].sort_by_key(|(c, _)| ccc(*c));
|
||||
let mut output: Vec<Entry> = Vec::with_capacity(decomposed.len());
|
||||
let mut starter: Option<usize> = None;
|
||||
let mut last_class = 0;
|
||||
for (character, source) in decomposed {
|
||||
let class = ccc(character);
|
||||
if composed
|
||||
&& (last_class == 0 || last_class < class)
|
||||
&& let Some(index) = starter
|
||||
&& let Some(joined) = compose(char::from_u32(output[index].value).unwrap(), character)
|
||||
{
|
||||
output[index].value = joined.into();
|
||||
output[index].source.merge(&source);
|
||||
output[index].source =
|
||||
std::mem::take(&mut output[index].source).derived(Derivation::FontMapping);
|
||||
continue;
|
||||
}
|
||||
if class == 0 {
|
||||
starter = Some(output.len());
|
||||
}
|
||||
last_class = class;
|
||||
push(&mut output, character.into(), &source)?;
|
||||
}
|
||||
Ok(output)
|
||||
let normalized = crate::normalization::order_and_compose(decomposed, composed, |starter, mark| {
|
||||
starter.merge(&mark);
|
||||
*starter = std::mem::take(starter).derived(Derivation::FontMapping);
|
||||
});
|
||||
Ok(normalized
|
||||
.into_iter()
|
||||
.map(|(character, source)| Entry {
|
||||
value: character.into(),
|
||||
source,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
Reference in new issue
Block a user