Shift the route-D page body by TeX page origin offsets

This commit is contained in:
gloamxun committed 2026-10-23 01:55:28 +08:00
1 parent fb33ac6327
commit 5db7acaff2
7 files changed
+148 -17

No files matched your search

+27 -2
View File
@@ -235,13 +235,28 @@ fn font_resource(font: FontFace) -> &'static str {
}
}
/// TeX page origin offsets (`\hoffset`, `\voffset`) in scaled points.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct PageOrigin {
pub h_offset: i64,
pub v_offset: i64,
}
fn page_content(
list: &DisplayList,
height: i64,
image_names: &BTreeMap<usize, String>,
faces: &'static [PdfFace; 6],
origin: PageOrigin,
) -> String {
let mut content = String::from("q\n0 0 0 rg\n");
if origin != PageOrigin::default() {
content.push_str(&format!(
"1 0 0 1 {} {} cm\n",
pt(origin.h_offset),
pt(-origin.v_offset)
));
}
for item in &list.items {
match item {
DisplayItem::Text {
@@ -318,8 +333,18 @@ fn page_content(
content
}
/// Write several display lists as a multi-page PDF.
/// Write several display lists as a multi-page PDF at the default page origin.
pub fn display_lists_to_pdf(pages: &[DisplayList], page_height: i64) -> Vec<u8> {
display_lists_to_pdf_with_origin(pages, page_height, PageOrigin::default())
}
/// Write several display lists as a multi-page PDF, translating the page body
/// by TeX page origin offsets.
pub fn display_lists_to_pdf_with_origin(
pages: &[DisplayList],
page_height: i64,
origin: PageOrigin,
) -> Vec<u8> {
let height = page_height.max(792 * 65_536);
let width = pages
.iter()
@@ -473,7 +498,7 @@ pub fn display_lists_to_pdf(pages: &[DisplayList], page_height: i64) -> Vec<u8>
for (index, slot) in &used {
names.insert(*index, format!("Im{slot}"));
}
let content = page_content(list, height, &names, faces);
let content = page_content(list, height, &names, faces, origin);
objects.push(
format!(
"<< /Length {} >>\nstream\n{}endstream",