Use the rounded PDF graphics origin when starting text

This commit is contained in:
gloamxun committed 2026-11-29 10:15:19 +08:00
1 parent 893b46baae
commit ecb0f60960
5 files changed
+120 -12

No files matched your search

+48
View File
@@ -240,6 +240,54 @@ fn saved_pdf_position_is_observed_in_shipout_order() {
fs::remove_dir_all(work).unwrap();
}
#[test]
fn native_pdf_text_uses_the_rounded_origin_after_positioned_literals() {
let work = directory();
let source = work.join("origin.tex");
fs::write(
&source,
r"\catcode123=1 \catcode125=2 \catcode35=6 \catcode37=14
\pdfoutput=1 \pdfdecimaldigits=3 \pdfpagewidth=200pt \pdfpageheight=200pt
\pdfhorigin=0sp \pdfvorigin=0sp
\font\body=cmr10 \body
\def\place#1#2#3{\hbox to0sp{\kern#1sp\lower#2sp\hbox{#3}\hss}}
\shipout\hbox{%
\place{66}{13107134}{\pdfliteral{q Q}}%
\place{330}{13106870}{\pdfliteral{q Q}}%
\place{33}{13107134}{A}}
\end",
)
.unwrap();
let result = native_fonts::command()
.args(["native", "--job", "--initex", "--etex"])
.arg(&source)
.arg("origin.pdf")
.current_dir(&work)
.output()
.unwrap();
assert!(
result.status.success(),
"{}",
String::from_utf8_lossy(&result.stderr)
);
let pdf = lopdf::Document::load(work.join("origin.pdf")).unwrap();
let contents = pdf.get_page_content(pdf.get_pages()[&1]).unwrap();
let stream = lopdf::content::Content::decode(&contents).unwrap();
let mut moves = stream.operations.iter().filter(|op| op.operator == "Td");
let start = moves.next().expect("first glyph position");
// The two literals leave 1 sp of residue on each axis after moving
// back. pdfTeX 1.40.29 emits 0 0 Td for the first glyph.
assert!(matches!(
start.operands.as_slice(),
[x, y] if [x, y].iter().all(|axis| matches!(
axis,
lopdf::Object::Integer(0) | lopdf::Object::Real(0.0)
))
), "{start:?}");
assert!(moves.next().is_none());
fs::remove_dir_all(work).unwrap();
}
#[test]
fn shipped_pdf_spaces_take_a_real_font_slot_in_output_order() {
let work = directory();