mirror of
https://framagit.org/almet/jardiflore.git
synced 2025-04-28 12:02:37 +02:00
Place multiple labels per page
This commit is contained in:
parent
7dd93ab825
commit
e0adb40880
1 changed files with 10 additions and 5 deletions
15
main.rs
15
main.rs
|
@ -18,7 +18,8 @@ const A4_HEIGHT: f32 = 297.0;
|
||||||
// Configuration for the label
|
// Configuration for the label
|
||||||
const DPI: f32 = 300.0;
|
const DPI: f32 = 300.0;
|
||||||
const MM_TO_PX: f32 = DPI / 25.4;
|
const MM_TO_PX: f32 = DPI / 25.4;
|
||||||
const LABEL_WIDTH: f32 = 220.0 * MM_TO_PX;
|
const PX_TO_PT: f32 = 0.75;
|
||||||
|
const LABEL_WIDTH: f32 = 210.0 * MM_TO_PX;
|
||||||
const LABEL_HEIGHT: f32 = 16.0 * MM_TO_PX;
|
const LABEL_HEIGHT: f32 = 16.0 * MM_TO_PX;
|
||||||
|
|
||||||
// Elements positionning
|
// Elements positionning
|
||||||
|
@ -181,7 +182,7 @@ fn combine_labels(
|
||||||
// Group labels by page
|
// Group labels by page
|
||||||
for chunk in labels.chunks(labels_per_page) {
|
for chunk in labels.chunks(labels_per_page) {
|
||||||
let mut page_contents = Vec::new();
|
let mut page_contents = Vec::new();
|
||||||
let mut y_position = A4_HEIGHT - LABEL_HEIGHT;
|
let mut y_position = 0.0;
|
||||||
|
|
||||||
for label in chunk {
|
for label in chunk {
|
||||||
let pixels = label.clone().into_raw();
|
let pixels = label.clone().into_raw();
|
||||||
|
@ -197,13 +198,17 @@ fn combine_labels(
|
||||||
page_contents.push(Op::UseXobject {
|
page_contents.push(Op::UseXobject {
|
||||||
id: image_id,
|
id: image_id,
|
||||||
transform: XObjectTransform {
|
transform: XObjectTransform {
|
||||||
translate_y: Some(printpdf::Pt(y_position)),
|
translate_x: None,
|
||||||
..Default::default()
|
translate_y: Some(printpdf::Px(y_position as usize).into_pt(DPI)),
|
||||||
|
rotate: None,
|
||||||
|
scale_x: None,
|
||||||
|
scale_y: None,
|
||||||
|
dpi: None,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Move y position up for next label
|
// Move y position up for next label
|
||||||
y_position -= LABEL_HEIGHT;
|
y_position += LABEL_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create page and add to pages list
|
// Create page and add to pages list
|
||||||
|
|
Loading…
Reference in a new issue