Keep CMMI/CMSY Type1 math in Times PDFs
The TrueType Times backend also sent math glyphs through Liberation fallbacks, which changed their size and spacing. Allow the math face slots (6..10) to use their Computer Modern Type1 programs even when the text backend is TrueType, and add a PDF test asserting CMMI10 plus LiberationSerif in the same file. Test count is 1082.
This commit is contained in:
1 parent
0f23eb4a83
commit
e41492b2a0
5 files changed
+45
-7
No files matched your search
@@ -872,7 +872,11 @@ fn write_pdf(
|
||||
}
|
||||
let cm_faces: Vec<Option<(&'static Type1Font, BTreeMap<char, u8>)>> = (0..FACE_COUNT)
|
||||
.map(|slot| {
|
||||
if backend != FontBackend::ComputerModern || !used_faces[slot] {
|
||||
// A Times/TrueType document still wants the real Computer Modern
|
||||
// math faces: the Liberation fallback has different glyph sizes,
|
||||
// so formulas would be narrower and shorter than TeX.
|
||||
let type1_math = backend == FontBackend::TrueType && (6..=10).contains(&slot);
|
||||
if (backend != FontBackend::ComputerModern && !type1_math) || !used_faces[slot] {
|
||||
return None;
|
||||
}
|
||||
let font = type1_fonts()[slot].as_ref()?;
|
||||
@@ -1297,6 +1301,40 @@ mod tests {
|
||||
assert!(widths.contains(&format!("{id} [500]")), "{widths}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn truetype_pdf_keeps_cmmi_for_math() {
|
||||
let mut list = crate::render::DisplayList::default();
|
||||
list.width = 612 * 65_536;
|
||||
list.height = 792 * 65_536;
|
||||
list.push(crate::render::DisplayItem::Text {
|
||||
font: crate::render::FontFace::MathItalic,
|
||||
x: 72 * 65_536,
|
||||
y: 100 * 65_536,
|
||||
size: 10 * 65_536,
|
||||
text: "α".to_string(),
|
||||
});
|
||||
list.push(crate::render::DisplayItem::Text {
|
||||
font: crate::render::FontFace::Roman,
|
||||
x: 72 * 65_536,
|
||||
y: 120 * 65_536,
|
||||
size: 10 * 65_536,
|
||||
text: "Body".to_string(),
|
||||
});
|
||||
let pdf = super::display_lists_to_pdf_with_truetype_and_metadata(
|
||||
&[list],
|
||||
612 * 65_536,
|
||||
792 * 65_536,
|
||||
super::PageOrigin::default(),
|
||||
&super::PdfMetadata::default(),
|
||||
);
|
||||
let text = String::from_utf8_lossy(&pdf);
|
||||
assert!(text.contains("/BaseFont /CMMI10"), "missing CMMI10");
|
||||
assert!(
|
||||
text.contains("/BaseFont /LiberationSerif"),
|
||||
"missing body face"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latin1_text_is_octal_escaped_in_the_content_stream() {
|
||||
assert_eq!(escape("café"), "caf\\351");
|
||||
|
||||
Reference in new issue
Block a user