Shift the route-D page body by TeX page origin offsets
This commit is contained in:
1 parent
fb33ac6327
commit
5db7acaff2
7 files changed
+148
-17
No files matched your search
@@ -615,6 +615,12 @@ pub struct Document {
|
||||
/// TeX `\parskip`: vertical glue inserted between paragraphs.
|
||||
#[serde(default)]
|
||||
pub par_skip: i64,
|
||||
/// Extra horizontal displacement of the page origin (`\hoffset`).
|
||||
#[serde(default)]
|
||||
pub h_offset: i64,
|
||||
/// Extra vertical displacement of the page origin (`\voffset`).
|
||||
#[serde(default)]
|
||||
pub v_offset: i64,
|
||||
}
|
||||
|
||||
fn default_text_fraction() -> u8 {
|
||||
@@ -673,6 +679,8 @@ impl Document {
|
||||
text_float_sep: default_text_float_sep(),
|
||||
in_text_sep: default_in_text_sep(),
|
||||
par_skip: 0,
|
||||
h_offset: 0,
|
||||
v_offset: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user