Continue XeTeX text layout on missing legacy glyphs

This commit is contained in:
gloamxun committed 2026-11-29 00:28:09 +08:00
1 parent cb6525ffca
commit 90f174283e
5 files changed
+114 -15

No files matched your search

@@ -385,6 +385,7 @@ impl Executor {
files: &mut impl SourceProvider,
) -> Result<(), Error> {
let slot = slot.into();
let xetex = self.state.input_profile() == InputProfile::XeTeX;
let tracing = self.read_parameter(Parameter::Tracinglostchars).width();
let online = self.read_parameter(Parameter::Tracingonline).width();
let destination = if tracing <= 0 {
@@ -403,7 +404,8 @@ impl Executor {
match slot {
0..=31 => format!("^^{}", char::from(slot as u8 + 64)),
127 => "^^?".into(),
128..=255 => format!("^^{slot:02x}"),
128..=159 => format!("^^{slot:02x}"),
160..=255 if !xetex => format!("^^{slot:02x}"),
_ => char::from_u32(slot)
.map(|c| c.to_string())
.unwrap_or_else(|| format!("U+{slot:04X}")),
@@ -423,17 +425,14 @@ impl Executor {
} else {
"Missing character: There is no "
});
let tail = literal(&if tracing > 2 {
format!(
" (\"{slot:X}) in font {}.",
self.state.fonts.font(font).expect("loaded font").name()
)
let code = if xetex || tracing > 2 {
format!(" (\"{slot:X})")
} else {
format!(
" in font {}!",
self.state.fonts.font(font).expect("loaded font").name()
)
});
String::new()
};
let font = self.state.fonts.font(font).expect("loaded font").name();
let end = if tracing > 2 { '.' } else { '!' };
let tail = literal(&format!("{code} in font {font}{end}"));
format!("{head}{printed}{tail}")
});
self.events.push(Event::MissingGlyph(MissingGlyph {
@@ -442,19 +442,20 @@ impl Executor {
return Ok(());
}
let font = self.state.text_font();
let opentype = if self.state.input_profile() != super::super::InputProfile::TeX8Bit {
let profile = self.state.input_profile();
let opentype = if profile != InputProfile::TeX8Bit {
self.state.fonts.font(font).map_err(|e| self.error(e, token.span))?.opentype().cloned()
} else {
None
};
let slot = u8::try_from(c as u32).ok();
if slot.is_none() && opentype.is_none() {
if profile != InputProfile::XeTeX && slot.is_none() && opentype.is_none() {
return Err(self.error("native TFM text font requires an 8-bit character slot", token.span));
}
if self.paragraph.is_none() {
self.begin_paragraph(token.invocation.unwrap_or(token.span), true)?;
}
let space_factor = if slot.is_some() || self.state.input_profile() == InputProfile::XeTeX {
let space_factor = if slot.is_some() || profile == InputProfile::XeTeX {
self.read_space_factor_code(u32::from(c))
} else {
1000
@@ -478,7 +479,7 @@ impl Executor {
self.reads.insert(Dependency::FontResources);
self.reads.insert(Dependency::TextFont);
if let Some(font) = opentype {
if self.state.input_profile() == InputProfile::XeTeX {
if profile == InputProfile::XeTeX {
self.reads.insert(Dependency::Parameter(Parameter::XeTeXuseglyphmetrics));
self.reads.insert(Dependency::Parameter(Parameter::XeTeXgenerateactualtext));
self.reads.insert(Dependency::Parameter(Parameter::XeTeXinterwordspaceshaping));
@@ -495,6 +496,15 @@ impl Executor {
.opentype_character(c, TokenOrigin::from(token), &self.state, font)
.map_err(|e| self.error(e, token.invocation.unwrap_or(token.span)));
}
if slot.is_none() {
// The pending character saw this scalar as lookahead, so there
// is no right-boundary ligature and no new legacy character node.
let paragraph = self.paragraph.as_mut().unwrap();
paragraph.finish_text(false, &self.state)
.map_err(|e| self.error(e, token.invocation.unwrap_or(token.span)))?;
self.paragraph.as_mut().unwrap().cancel_boundary = false;
return self.missing_glyph(font, u32::from(c), token.invocation.unwrap_or(token.span), files);
}
let missing = self
.paragraph
.as_mut()