Hyphenate native XeTeX OpenType words during line breaking
This commit is contained in:
1 parent
20986b2fd5
commit
c97e0e7279
8 files changed
+321
-16
No files matched your search
@@ -19,6 +19,10 @@ impl Executor {
|
||||
) {
|
||||
return self.fail("patterns requires a begin-group token");
|
||||
}
|
||||
if self.state.input_profile() == InputProfile::XeTeX {
|
||||
self.reads.insert(Dependency::Parameter(Parameter::XeTeXhyphenatablelength));
|
||||
}
|
||||
let max_length = super::super::hyphenation::max_word_length(&self.state);
|
||||
let (mut letters, mut weights, mut digit) = (Vec::new(), vec![0], false);
|
||||
loop {
|
||||
let t = self.required_expanded(files)?.token;
|
||||
@@ -50,7 +54,7 @@ impl Executor {
|
||||
}
|
||||
Meaning::Character(TokenKind::Character(c, CatCode::Letter | CatCode::Other)) => {
|
||||
if !digit && c.is_ascii_digit() {
|
||||
if letters.len() < 63 {
|
||||
if letters.len() < max_length {
|
||||
*weights.last_mut().unwrap() = c as u8 - b'0';
|
||||
digit = true;
|
||||
}
|
||||
@@ -65,7 +69,7 @@ impl Executor {
|
||||
}
|
||||
n
|
||||
};
|
||||
if letters.len() < 63 {
|
||||
if letters.len() < max_length {
|
||||
letters.push(c);
|
||||
weights.push(0);
|
||||
digit = false;
|
||||
|
||||
@@ -447,10 +447,15 @@ impl Executor {
|
||||
self.reads.insert(Dependency::ParagraphShape);
|
||||
self.reads.insert(Dependency::Hyphenation);
|
||||
for n in &b.nodes {
|
||||
if let super::super::paragraph::TextNode::Glyph { original, .. } = n {
|
||||
for c in original.chars() {
|
||||
self.reads.insert(Dependency::CaseCode(CaseCode::Lower, c));
|
||||
let text = match n {
|
||||
TextNode::Glyph { original, .. } => original,
|
||||
TextNode::OpenType(run) if self.state.input_profile() == InputProfile::XeTeX => {
|
||||
&run.text
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
for c in text.chars() {
|
||||
self.reads.insert(Dependency::CaseCode(CaseCode::Lower, c));
|
||||
}
|
||||
}
|
||||
self.reads.insert(Dependency::FontResources);
|
||||
@@ -727,7 +732,12 @@ impl Executor {
|
||||
);
|
||||
self.reads
|
||||
.insert(Dependency::Parameter(Parameter::Language));
|
||||
let (mut word, mut points, mut count) = (String::new(), Vec::new(), 0);
|
||||
let xetex = self.state.input_profile() == InputProfile::XeTeX;
|
||||
if xetex {
|
||||
self.reads.insert(Dependency::Parameter(Parameter::XeTeXhyphenatablelength));
|
||||
}
|
||||
let max_length = super::super::hyphenation::max_word_length(&self.state);
|
||||
let (mut word, mut points, mut count, mut units) = (String::new(), Vec::new(), 0, 0);
|
||||
loop {
|
||||
let t = self.required_expanded(files)?.token;
|
||||
let meaning = self.meaning(&t);
|
||||
@@ -750,20 +760,20 @@ impl Executor {
|
||||
word.clear();
|
||||
points.clear();
|
||||
count = 0;
|
||||
units = 0;
|
||||
continue;
|
||||
}
|
||||
Meaning::Character(TokenKind::Character(c, CatCode::Letter | CatCode::Other)) => c,
|
||||
Meaning::CharGiven(c) => self.scalar_character(c, t.span)?,
|
||||
Meaning::Primitive(Primitive::Char) => {
|
||||
let n = self.integer(files)?;
|
||||
char::from(u8::try_from(n).map_err(|_| {
|
||||
self.error("hyphenation character must be in 0..255", self.current)
|
||||
})?)
|
||||
let maximum = if xetex { 0x10FFFF } else { 255 };
|
||||
let n = self.character_number("hyphenation character", maximum, files)?;
|
||||
self.scalar_character(n, t.span)?
|
||||
}
|
||||
_ => return self.fail("improper token in hyphenation exceptions"),
|
||||
};
|
||||
if c == '-' {
|
||||
if count < 63 {
|
||||
if units < max_length {
|
||||
points.push(count);
|
||||
}
|
||||
continue;
|
||||
@@ -773,9 +783,12 @@ impl Executor {
|
||||
if lower == 0 {
|
||||
return self.fail("hyphenation character must have nonzero lccode");
|
||||
}
|
||||
if count < 63 {
|
||||
word.push(char::from_u32(lower).expect("validated case code"));
|
||||
let lower = char::from_u32(lower).expect("validated case code");
|
||||
let size = if xetex { lower.len_utf16() } else { 1 };
|
||||
if units + size <= max_length {
|
||||
word.push(lower);
|
||||
count += 1;
|
||||
units += size;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user