diff --git a/src/main.rs b/src/main.rs index fabf94d..e07fc41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,7 @@ mod faces; mod hand_pose; mod palm; mod printer; +mod quotes; struct PreviewFrame { buffer: SharedPixelBuffer, diff --git a/src/printer.rs b/src/printer.rs index 0ad3fb8..6e7bf15 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -52,6 +52,8 @@ use opencv::{ prelude::*, }; +use crate::quotes::QUOTES; + const DEFAULT_PRINTER: &str = "/dev/usb/lp0"; const DEFAULT_DOTS: usize = 576; const DEFAULT_GAMMA: f32 = 2.0; @@ -74,42 +76,6 @@ const KEEPSAKE_DE: &str = "Ich war dabei!"; const KEEPSAKE_EN: &str = "I was there!"; /// Capture time, written the German way and the same in both languages. const STAMP_FORMAT: &str = "%d.%m.%Y, %H:%M"; -/// One is printed per slip. Each line is short enough for a single 80 mm line; -/// on 58 mm paper the longer ones wrap. -const QUOTES: [[&str; 2]; 8] = [ - [ - "Analysis bestanden. Wunder gibt es doch.", - "Passed Analysis. Miracles do happen.", - ], - [ - "Im Freihaus gibt es Kaffee und Hoffnung.", - "The Freihaus serves coffee and hope.", - ], - [ - "TISS sagt nein. Mein Herz sagt auch nein.", - "TISS says no. So does my heart.", - ], - [ - "WINF: zwei Fächer, eine Deadline.", - "WINF: two subjects, one deadline.", - ], - [ - "Karlsplatz: der schönste Umweg zur Uni.", - "Karlsplatz: the prettiest detour to class.", - ], - [ - "Prüfungswoche: Schlafen ist optional.", - "Exam week: sleeping is optional.", - ], - [ - "Die Bibliothek kennt alle meine Ausreden.", - "The library has heard all my excuses.", - ], - [ - "Mathe ist einfach, sagt die Mathematik.", - "Maths is easy, says maths.", - ], -]; /// Pause between writes, leaving the head time to drain a band (8 mm of paper) /// before the next one arrives. const PACE: Duration = Duration::from_millis(100); @@ -402,9 +368,10 @@ fn encode( job } -/// The German letters in the captions as single PC437 bytes, the code page the -/// booth's printer starts in. Anything else non-ASCII would need a wider table -/// or `ESC t`, so a test keeps the printed text within this set. +/// The German letters and the middle dot in the captions as single PC437 bytes, +/// the code page the booth's printer starts in. Anything else non-ASCII would +/// need a wider table or `ESC t`, so a test keeps the printed text within this +/// set. fn code_page(character: char) -> Option { Some(match character { 'ä' => 0x84, @@ -414,6 +381,7 @@ fn code_page(character: char) -> Option { 'Ö' => 0x99, 'Ü' => 0x9A, 'ß' => 0xE1, + '·' => 0xFA, ascii if ascii.is_ascii() => ascii as u8, _ => return None, }) @@ -456,7 +424,7 @@ fn first_quote() -> usize { % QUOTES.len() } -fn footer(head: &Head, stamp: &str, quote: &[&str; 2]) -> Vec { +fn footer(head: &Head, stamp: &str, quote: &[&str]) -> Vec { let mut write = centered(head); write.extend([0x1B, b'd', 1]); write.extend(LARGE); @@ -466,8 +434,9 @@ fn footer(head: &Head, stamp: &str, quote: &[&str; 2]) -> Vec { write.extend([0x1B, b'd', 1]); text_line(&mut write, stamp); write.extend([0x1B, b'd', 1]); - text_line(&mut write, quote[0]); - text_line(&mut write, quote[1]); + for line in quote { + text_line(&mut write, line); + } write.extend([0x1B, b'd', FEED_LINES]); // ESC d n: feed n lines write.extend([0x1D, b'V', 66, 3]); // GS V 66 n: feed and partial cut write @@ -483,7 +452,7 @@ mod tests { fn printed_lines() -> impl Iterator { [EVENT_TITLE, EVENT_PLACE, KEEPSAKE_DE, KEEPSAKE_EN, STAMP] .into_iter() - .chain(QUOTES.iter().flatten().copied()) + .chain(QUOTES.iter().flat_map(|quote| quote.iter().copied())) } fn contains_line(write: &[u8], line: &str) -> bool { @@ -523,7 +492,7 @@ mod tests { let picked: std::collections::BTreeSet = (0..1000).map(|_| first_quote()).collect(); assert!(picked.last().is_some_and(|last| *last < QUOTES.len())); - // Not all eight on a coarse clock, but a slip must not be predictable. + // Not all of them on a coarse clock, but a slip must not be predictable. assert!(picked.len() > 1, "{picked:?}"); } diff --git a/src/quotes.rs b/src/quotes.rs new file mode 100644 index 0000000..58b60c1 --- /dev/null +++ b/src/quotes.rs @@ -0,0 +1,122 @@ +//! Quotes printed under each photo, one per slip. + +/// One is printed per slip, one printed line per entry. The first eight are +/// German with the English underneath; the rest are English only. Each line is +/// short enough for a single 80 mm line (longer quotes are split by hand); on +/// 58 mm paper the longer ones wrap. +pub const QUOTES: &[&[&str]] = &[ + &[ + "Analysis bestanden. Wunder gibt es doch.", + "Passed Analysis. Miracles do happen.", + ], + &[ + "Im Freihaus gibt es Kaffee und Hoffnung.", + "The Freihaus serves coffee and hope.", + ], + &[ + "TISS sagt nein. Mein Herz sagt auch nein.", + "TISS says no. So does my heart.", + ], + &[ + "WINF: zwei Fächer, eine Deadline.", + "WINF: two subjects, one deadline.", + ], + &[ + "Karlsplatz: der schönste Umweg zur Uni.", + "Karlsplatz: the prettiest detour to class.", + ], + &[ + "Prüfungswoche: Schlafen ist optional.", + "Exam week: sleeping is optional.", + ], + &[ + "Die Bibliothek kennt alle meine Ausreden.", + "The library has heard all my excuses.", + ], + &[ + "Mathe ist einfach, sagt die Mathematik.", + "Maths is easy, says maths.", + ], + // The good times. + &["Good times, good people."], + &["Glad you came."], + &["A night to remember."], + &["Here for the good times."], + &["Made it out tonight."], + &["Look at us go."], + &["This one's a keeper."], + &["Smile, you earned it."], + &["Friends first, deadlines later."], + &["Great company, as always."], + &["Not bad for a weeknight."], + &["Still better than studying."], + &["Zero regrets."], + &["Camera loves us."], + &["Nailed it."], + &["The good old days, right now."], + &["Best seats in the house."], + &["Proof that we have a social life."], + &["Group project, actually fun."], + &["Exams can wait."], + &["We clean up nicely."], + &["Told you it would be fun."], + &["Save the date, we're doing this again."], + &["You had to be there. Luckily, we were."], + &["Photo or it didn't happen."], + &["Passed with distinction."], + &["Attendance: voluntary. Mood: excellent."], + &["See you at the next one."], + // Winfnachten. + &["Merry Winfnachten!"], + &["Winfnachten: the most wonderful night", "of the semester."], + &["All I want for Winfnachten is to pass my exams."], + &["Winfnachten spirit: confirmed."], + &["On the nice list. Mostly."], + &["Dear Santa, I studied. Sort of."], + &["Have yourself a merry little Winfnachten."], + &["See you next Winfnachten."], + // winf.at. + &["Check out what's next at winf.at"], + &["More events, more photos: winf.at"], + &["Liked tonight? There's more at winf.at"], + &["Find your next event at winf.at"], + &["Brought to you by FSWinf · winf.at"], + &["Your student body at TU Wien: winf.at"], + &["Stay in the loop: winf.at"], + &["This photo was made by volunteers.", "Meet them at winf.at"], + // Studying at TU Wien. + &["Questions about your studies? Ask us: winf.at"], + &["Stuck on your study plan? We can help: winf.at"], + &["Need a place to study?", "Visit our study room: winf.at"], + &["New at TU Wien? Start here: winf.at"], + &["First semester? Join our E-Tuts: winf.at"], + &[ + "Business Informatics or Data Science?", + "We've got you: winf.at", + ], + // Getting involved. + &["Want to help run the next one? Join us: winf.at"], + &[ + "Come to a Fachschaft meeting.", + "Everyone's welcome: winf.at", + ], + &["We're students, just like you. Say hi: winf.at"], + &["Got ideas for the next event? Tell us: winf.at"], + // The receipt. + &["Receipt for one great night."], + &["Proof of attendance."], + &["Keep this receipt. No returns on good memories."], + &["Thank you for celebrating with us."], + &["Paid in full: one great evening."], + &["Total: priceless."], + &["Memories: 1x. Regrets: 0x."], + &["Items: good friends, good times.", "Total: worth it."], + &["No refunds. No regrets."], + &["Valid forever."], + &[ + "This receipt is not tax deductible.", + "Sorry, business students.", + ], + &["Customer copy. The memories are yours."], + &["Thank you, come again!"], +];