Hyphenate native XeTeX OpenType words during line breaking

This commit is contained in:
gloamxun committed 2026-11-25 21:37:05 +08:00
1 parent 20986b2fd5
commit c97e0e7279
8 files changed
+321 -16

No files matched your search

@@ -6,6 +6,7 @@ use crate::opentype::{OpenTypeFont, OpenTypeRun};
mod break_cache;
mod expansion;
mod native_hyphenation;
mod protrusion;
pub(super) use protrusion::stored_margin_kern;
use break_cache::BreakNode;
@@ -1262,6 +1263,11 @@ pub(super) fn finish(
steps,
step_limit,
)?;
if state.input_profile() == InputProfile::XeTeX {
native_hyphenation::add_hyphens(
&mut b.nodes, state, b.initial_language, steps, step_limit,
)?;
}
}
trace.pass(pass, parameters[&Parameter::Pretolerance].width() >= 0)?;
if let Some(path) = break_cache::solve(
@@ -1425,6 +1431,7 @@ fn add_hyphens(
steps: &mut usize,
step_limit: usize,
) -> Result<(), String> {
let max_length = super::hyphenation::max_word_length(state);
let (mut start, mut i) = (0, 0);
let mut edits = Vec::new();
let mut word_font = None;
@@ -1454,7 +1461,7 @@ fn add_hyphens(
})
.take_while(|s| {
let n = s.chars().count();
if letters + n > 63 {
if letters + n > max_length {
false
} else {
letters += n;
@@ -1551,7 +1558,7 @@ fn add_hyphens(
component_sources,
..
} => {
if components.len() + original.chars().count() > 63 {
if components.len() + original.chars().count() > max_length {
break;
}
components.extend(original.chars().enumerate().map(|(k, c)| {