first commit

main
Admin1312 2025-06-25 11:49:04 +02:00
commit d80952ac92
9 changed files with 2066 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

1981
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "printstick"
version = "0.1.0"
edition = "2024"
[dependencies]
printpdf = "0.8.2"

17
src/config.rs Normal file
View File

@ -0,0 +1,17 @@
pub struct Config {
pub bleed_mm: f64,
pub page_width_mm: f64,
pub page_height_mm: f64,
pub spacing_mm: f64
}
impl Config {
pub fn load_a4() -> Config {
Config {
bleed_mm: 5.0,
page_width_mm: 297.0,
page_height_mm: 420.0,
spacing_mm: 5.0
}
}
}

38
src/layout.rs Normal file
View File

@ -0,0 +1,38 @@
use crate::config::Config;
use crate::stickers::Sticker;
pub fn stickers_placement() -> Vec<Sticker> {
let config = Config::load_a4();
let mut positions: Vec<Sticker> = vec![];
let sticker_width = 50.0;
let sticker_height = 50.0;
let usable_width: f64 = config.page_width_mm - 2.0 * config.bleed_mm;
let usable_height: f64 = config.page_height_mm - 2.0 * config.bleed_mm;
let total_width = sticker_width + config.spacing_mm;
let total_height = sticker_height + config.spacing_mm;
let row = (usable_width / total_width).floor() as usize;
let col = (usable_height / total_height).floor() as usize;
for i in 0..col {
for j in 0..row {
let x = config.bleed_mm + (j as f64) * total_width;
let y = config.bleed_mm + (i as f64) * total_height;
positions.push(
Sticker {
path: String::from("Bonjour"),
position: (x, y),
width: sticker_width,
height: sticker_height
}
);
}
}
positions
}

4
src/lib.rs Normal file
View File

@ -0,0 +1,4 @@
pub mod layout;
pub mod config;
pub mod stickers;
pub mod pdf;

8
src/main.rs Normal file
View File

@ -0,0 +1,8 @@
use printstick::layout::stickers_placement;
use printstick::stickers::Sticker;
fn main() {
let positions: Vec<Sticker> = stickers_placement();
println!("Generated positions: {:?}", positions);
}

3
src/pdf.rs Normal file
View File

@ -0,0 +1,3 @@
// pub fn generate_pdf(output_path: &str, positions: Vec<(Mm, Mm)>, stickers: &[Sticker]) {
// }

7
src/stickers.rs Normal file
View File

@ -0,0 +1,7 @@
#[derive(Debug)]
pub struct Sticker {
pub path: String,
pub position: (f64, f64), // (x, y)
pub width: f64,
pub height: f64
}