Honour declared paper size in route-D output
This commit is contained in:
1 parent
043ae7f072
commit
7b9d543e49
7 files changed
+142
-33
No files matched your search
@@ -566,6 +566,12 @@ fn default_insertion_multiplier() -> u32 {
|
||||
pub struct Document {
|
||||
pub units: Vec<Unit>,
|
||||
pub page_goal: i64,
|
||||
/// TeX `\paperwidth`: width of the output page.
|
||||
#[serde(default = "default_paper_width")]
|
||||
pub paper_width: i64,
|
||||
/// TeX `\paperheight`: height of the output page.
|
||||
#[serde(default = "default_paper_height")]
|
||||
pub paper_height: i64,
|
||||
/// TeX-like `\topskip`: distance from the page top to the first baseline.
|
||||
#[serde(default)]
|
||||
pub top_skip: i64,
|
||||
@@ -630,6 +636,14 @@ pub struct Document {
|
||||
pub output_routine: Option<String>,
|
||||
}
|
||||
|
||||
fn default_paper_width() -> i64 {
|
||||
612 * 65_536
|
||||
}
|
||||
|
||||
fn default_paper_height() -> i64 {
|
||||
792 * 65_536
|
||||
}
|
||||
|
||||
fn default_text_fraction() -> u8 {
|
||||
50
|
||||
}
|
||||
@@ -671,6 +685,8 @@ impl Document {
|
||||
Self {
|
||||
units,
|
||||
page_goal,
|
||||
paper_width: default_paper_width(),
|
||||
paper_height: default_paper_height(),
|
||||
top_skip: 0,
|
||||
max_depth: 0,
|
||||
text_fraction_percent: default_text_fraction(),
|
||||
@@ -2401,6 +2417,13 @@ impl Engine {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn documents_default_to_letter_paper() {
|
||||
let document = Document::new(100, Vec::new());
|
||||
assert_eq!(document.paper_width, 612 * 65_536);
|
||||
assert_eq!(document.paper_height, 792 * 65_536);
|
||||
}
|
||||
|
||||
fn document() -> Document {
|
||||
Document::new(
|
||||
50,
|
||||
|
||||
@@ -345,13 +345,29 @@ pub fn display_lists_to_pdf_with_origin(
|
||||
page_height: i64,
|
||||
origin: PageOrigin,
|
||||
) -> Vec<u8> {
|
||||
let height = page_height.max(792 * 65_536);
|
||||
let width = pages
|
||||
.iter()
|
||||
.map(|page| page.width)
|
||||
.max()
|
||||
.unwrap_or(612 * 65_536)
|
||||
.max(612 * 65_536);
|
||||
display_lists_to_pdf_with_paper(
|
||||
pages,
|
||||
pages
|
||||
.iter()
|
||||
.map(|page| page.width)
|
||||
.max()
|
||||
.unwrap_or(612 * 65_536)
|
||||
.max(612 * 65_536),
|
||||
page_height.max(792 * 65_536),
|
||||
origin,
|
||||
)
|
||||
}
|
||||
|
||||
/// Write several display lists as a multi-page PDF with an explicit paper
|
||||
/// size (TeX `\paperwidth`/`\paperheight`) and page origin offsets.
|
||||
pub fn display_lists_to_pdf_with_paper(
|
||||
pages: &[DisplayList],
|
||||
page_width: i64,
|
||||
page_height: i64,
|
||||
origin: PageOrigin,
|
||||
) -> Vec<u8> {
|
||||
let width = page_width;
|
||||
let height = page_height;
|
||||
|
||||
let mut objects: Vec<Vec<u8>> = Vec::new();
|
||||
objects.push(b"<< /Type /Catalog /Pages 2 0 R >>".to_vec());
|
||||
|
||||
Reference in new issue
Block a user