Include unboxed inline math in pdfTeX font expansion
This commit is contained in:
1 parent
8cd0263b97
commit
0f10163b5b
4 files changed
+91
-8
No files matched your search
@@ -73,17 +73,21 @@ struct Character<'a> {
|
||||
}
|
||||
|
||||
fn character(node: &TextNode) -> Option<Character<'_>> {
|
||||
let TextNode::Glyph { font: id, glyph, slot, .. } = node else {
|
||||
return None;
|
||||
let (glyph, text_character) = match node {
|
||||
TextNode::Glyph { font, glyph, slot, .. } => (glyph, Some((*font, *slot))),
|
||||
// Inline math contributes its unboxed characters to the paragraph.
|
||||
TextNode::MathChar(glyph) => (glyph, None),
|
||||
_ => return None,
|
||||
};
|
||||
let geometry = glyph.math_geometry.as_ref()?;
|
||||
let MathItem::NativeGlyph { font, .. } = &geometry.items.first()?.item else {
|
||||
let MathItem::NativeGlyph { font, slot, .. } = &geometry.items.first()?.item else {
|
||||
return None;
|
||||
};
|
||||
let (id, slot) = text_character.unwrap_or((font.id, *slot));
|
||||
Some(Character {
|
||||
font,
|
||||
id: *id,
|
||||
slot: *slot,
|
||||
id,
|
||||
slot,
|
||||
width: glyph.width,
|
||||
})
|
||||
}
|
||||
@@ -445,10 +449,14 @@ pub(super) fn pack(
|
||||
let metrics = state.fonts.character(selected, glyph.slot)?
|
||||
.ok_or_else(|| format!("expanded font has no TFM slot {}", glyph.slot))?;
|
||||
let face = state.fonts.glyph_font(selected)?;
|
||||
let TextNode::Glyph { font, glyph, .. } = &mut material[i] else {
|
||||
unreachable!()
|
||||
let glyph = match &mut material[i] {
|
||||
TextNode::Glyph { font, glyph, .. } => {
|
||||
*font = selected;
|
||||
glyph
|
||||
}
|
||||
TextNode::MathChar(glyph) => glyph,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
*font = selected;
|
||||
glyph.width = metrics.width;
|
||||
glyph.height = metrics.height;
|
||||
glyph.depth = metrics.depth;
|
||||
|
||||
@@ -461,6 +461,40 @@ fn font_expansion_codes_invalidate_cached_break_geometry() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn font_expansion_uses_unboxed_inline_math() {
|
||||
let source = r"\catcode123=1 \catcode125=2 \catcode36=3
|
||||
\font\roman=cmr10 \roman
|
||||
\textfont0=\roman \scriptfont0=\roman \scriptscriptfont0=\roman
|
||||
\font\symbol=cmsy10
|
||||
\textfont2=\symbol \scriptfont2=\symbol \scriptscriptfont2=\symbol
|
||||
\font\extension=cmex10
|
||||
\textfont3=\extension \scriptfont3=\extension \scriptscriptfont3=\extension
|
||||
\mathcode65=65
|
||||
\pdfoutput=1 \pdffontexpand\roman 100 100 10 autoexpand
|
||||
\hsize=31pt \parfillskip=0pt plus1fil \rightskip=0pt plus1fil
|
||||
\pretolerance=100 \tolerance=200 \linepenalty=10 \baselineskip=12pt
|
||||
\showboxbreadth=99 \showboxdepth=99
|
||||
\setbox0=\vbox{\pdfadjustspacing=1 \noindent $AA$ $AA$\par}
|
||||
\setbox1=\vbox{\pdfadjustspacing=2 \noindent $AA$ $AA$\par}
|
||||
\setbox2=\vbox{\pdfadjustspacing=2 \noindent \hbox{$AA$} $AA$\par}
|
||||
\showbox0 \showbox1 \showbox2
|
||||
\end
|
||||
";
|
||||
let executed = execute(source, &mut Host::default()).unwrap();
|
||||
let lists = reports(&executed);
|
||||
assert_eq!(lists.len(), 3);
|
||||
for (report, (line_count, expanded_chars)) in lists.iter().zip([(2, 0), (1, 4), (2, 0)]) {
|
||||
assert_eq!(
|
||||
report.text.lines().filter(|line| line.starts_with(r".\hbox(")).count(),
|
||||
line_count,
|
||||
"{}",
|
||||
report.text
|
||||
);
|
||||
assert_eq!(report.text.matches(r"\roman (-80) A").count(), expanded_chars);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn autoexpand_assigns_font_numbers_and_shares_parameters() {
|
||||
let declaration = r"\catcode123=1 \catcode125=2
|
||||
|
||||
Reference in new issue
Block a user