Pack print: A4 upright pages, small pictures at their size, card sides on one sheet
Every page of the pack is now A4 upright, so it prints as one stack. A
PDF page or a whole-page picture that lies wider than tall is turned
onto the page (a small one that fits as it is stays as it is), and a
PDF page is only made smaller, never larger.
A picture never prints larger than its resolution allows (the JFIF or
PNG dpi, else 150 dpi), nor larger than its kind's box: passport pages,
visas and stamps 180 x 128 mm, cards 130 x 90 mm, and a phone's
screenshot (the TDAC, or any picture about twice as tall as wide)
150 x 75 mm. These print at the top of the page.
Cards: a new kind "ID card", and the work permit, take two pictures in
one upload as front and back (migration 0008 documents.back_of). The
Documents tab marks them front/back, lists them together and offers
"Print both sides" (.../documents/{id}/sides.pdf); the pack prints both
on one sheet. The client link takes ID cards too. The demo seeds a TDAC
screenshot and an ID card's two sides.
Checks: fmt, clippy, 108 unit and 57 integration tests (print sizes,
dpi reading, the back following its front, the paired upload, its
audit and the sides PDF); the demo pack's pages checked as images.
The Documents tab's actions stack on a phone, so none is cut off.
This commit is contained in:
1 parent
506221ecd0
commit
1f526f17f9
16 files changed
+724
-73
No files matched your search
+86
-18
@@ -744,6 +744,10 @@ enum Picture {
|
||||
PassportPage,
|
||||
Portrait,
|
||||
Office,
|
||||
/// A phone's screenshot, as a TDAC is often kept.
|
||||
Screenshot,
|
||||
CardFront,
|
||||
CardBack,
|
||||
}
|
||||
|
||||
/// Adds invented documents to the demo people and companies, unless the
|
||||
@@ -798,14 +802,23 @@ pub async fn demo_documents(db: &PgPool, store: &Store, today: NaiveDate) -> Res
|
||||
"tdac",
|
||||
Some(format!("arrivals:{a}")),
|
||||
None,
|
||||
"TDAC.pdf".into(),
|
||||
demo_pdf(
|
||||
"Thailand Digital Arrival Card",
|
||||
&[
|
||||
format!("Traveller: {whose}"),
|
||||
"Arrival card number: TDAC-DEMO".into(),
|
||||
],
|
||||
),
|
||||
// the first person keeps it as a phone's screenshot
|
||||
if n == 0 {
|
||||
"TDAC screenshot.png".into()
|
||||
} else {
|
||||
"TDAC.pdf".into()
|
||||
},
|
||||
if n == 0 {
|
||||
demo_png(Picture::Screenshot)
|
||||
} else {
|
||||
demo_pdf(
|
||||
"Thailand Digital Arrival Card",
|
||||
&[
|
||||
format!("Traveller: {whose}"),
|
||||
"Arrival card number: TDAC-DEMO".into(),
|
||||
],
|
||||
)
|
||||
},
|
||||
));
|
||||
}
|
||||
if let Some(r) = one(latest("ninety_day_reports", "reported_on")).await? {
|
||||
@@ -830,6 +843,13 @@ pub async fn demo_documents(db: &PgPool, store: &Store, today: NaiveDate) -> Res
|
||||
"photo 4x6.png".into(),
|
||||
demo_png(Picture::Portrait),
|
||||
));
|
||||
// an ID card's two sides: they print on one page
|
||||
for (file, picture) in [
|
||||
("ID card front.png", Picture::CardFront),
|
||||
("ID card back.png", Picture::CardBack),
|
||||
] {
|
||||
plan.push((owner, "id-card", None, None, file.into(), demo_png(picture)));
|
||||
}
|
||||
// the copies of the passport's pages and the work permit that
|
||||
// the extension pack asks for
|
||||
let copies = [
|
||||
@@ -1013,6 +1033,11 @@ pub async fn demo_documents(db: &PgPool, store: &Store, today: NaiveDate) -> Res
|
||||
};
|
||||
let id = documents::insert(&mut tx, *owner, &meta, &file, "seed").await?;
|
||||
store.put(id, bytes.clone()).await?;
|
||||
if name.ends_with(" back.png")
|
||||
&& let Some(&front) = written.last()
|
||||
{
|
||||
documents::set_back(&mut tx, id, front).await?;
|
||||
}
|
||||
written.push(id);
|
||||
audit::record(
|
||||
&mut *tx,
|
||||
@@ -1099,21 +1124,18 @@ pub fn demo_pdf(title: &str, lines: &[String]) -> Vec<u8> {
|
||||
}
|
||||
|
||||
/// A picture made of shapes, as a PNG with a palette.
|
||||
/// A plain PNG of `w` x `h` pixels, for tests of how pictures print.
|
||||
pub fn plain_png(w: usize, h: usize) -> Vec<u8> {
|
||||
png(w, h, &vec![0u8; w * h])
|
||||
}
|
||||
|
||||
fn demo_png(picture: Picture) -> Vec<u8> {
|
||||
const PALETTE: [[u8; 3]; 8] = [
|
||||
[0xf3, 0xef, 0xe2], // paper
|
||||
[0x07, 0x13, 0x23], // navy
|
||||
[0xf5, 0xc0, 0x00], // gold
|
||||
[0x9b, 0xa8, 0xba], // grey
|
||||
[0xd8, 0xdd, 0xe5], // light grey
|
||||
[0xff, 0xff, 0xff], // white
|
||||
[0x3a, 0x45, 0x56], // ink
|
||||
[0xa9, 0xc8, 0xe8], // sky
|
||||
];
|
||||
let (w, h) = match picture {
|
||||
Picture::PassportPage => (600usize, 420usize),
|
||||
Picture::Portrait => (240, 360),
|
||||
Picture::Office => (480, 320),
|
||||
Picture::Screenshot => (390, 844),
|
||||
Picture::CardFront | Picture::CardBack => (428, 270),
|
||||
};
|
||||
let mut px = vec![0u8; w * h];
|
||||
let mut fill = |x0: usize, y0: usize, x1: usize, y1: usize, c: u8| {
|
||||
@@ -1148,6 +1170,36 @@ fn demo_png(picture: Picture) -> Vec<u8> {
|
||||
fill(0, 0, w, h, 4);
|
||||
fill(40, 270, 200, h, 1);
|
||||
}
|
||||
Picture::Screenshot => {
|
||||
fill(0, 0, w, h, 5);
|
||||
fill(0, 0, w, 44, 4);
|
||||
fill(0, 44, w, 140, 1);
|
||||
fill(24, 72, 240, 96, 2);
|
||||
for i in 0..9 {
|
||||
let y = 180 + i * 56;
|
||||
fill(24, y, 140, y + 12, 3);
|
||||
fill(24, y + 20, 24 + 120 + (i * 37) % 200, y + 34, 6);
|
||||
}
|
||||
fill(110, 700, 280, 790, 6);
|
||||
}
|
||||
Picture::CardFront => {
|
||||
fill(0, 0, w, h, 4);
|
||||
fill(0, 0, w, 40, 1);
|
||||
fill(20, 60, 120, 200, 3);
|
||||
for (i, len) in [200usize, 150, 230, 120].iter().enumerate() {
|
||||
let y = 70 + i * 34;
|
||||
fill(140, y, 140 + len, y + 12, 6);
|
||||
}
|
||||
fill(0, 240, w, 248, 2);
|
||||
}
|
||||
Picture::CardBack => {
|
||||
fill(0, 0, w, h, 4);
|
||||
fill(0, 30, w, 70, 1);
|
||||
for i in 0..5 {
|
||||
let y = 100 + i * 26;
|
||||
fill(24, y, 24 + 300 - i * 30, y + 10, 6);
|
||||
}
|
||||
}
|
||||
Picture::Office => {
|
||||
fill(0, 0, w, 200, 7);
|
||||
fill(0, 260, w, h, 3);
|
||||
@@ -1185,6 +1237,22 @@ fn demo_png(picture: Picture) -> Vec<u8> {
|
||||
}
|
||||
}
|
||||
}
|
||||
png(w, h, &px)
|
||||
}
|
||||
|
||||
/// A PNG of `w` x `h` pixels in the demo palette, stored without
|
||||
/// compression.
|
||||
fn png(w: usize, h: usize, px: &[u8]) -> Vec<u8> {
|
||||
const PALETTE: [[u8; 3]; 8] = [
|
||||
[0xf3, 0xef, 0xe2], // paper
|
||||
[0x07, 0x13, 0x23], // navy
|
||||
[0xf5, 0xc0, 0x00], // gold
|
||||
[0x9b, 0xa8, 0xba], // grey
|
||||
[0xd8, 0xdd, 0xe5], // light grey
|
||||
[0xff, 0xff, 0xff], // white
|
||||
[0x3a, 0x45, 0x56], // ink
|
||||
[0xa9, 0xc8, 0xe8], // sky
|
||||
];
|
||||
// the image data: each row with filter 0, in stored deflate blocks
|
||||
let mut raw = Vec::with_capacity(h * (w + 1));
|
||||
for row in px.chunks(w) {
|
||||
|
||||
Reference in new issue
Block a user