feat/more-print-quotes #3
@@ -27,6 +27,7 @@ mod faces;
|
||||
mod hand_pose;
|
||||
mod palm;
|
||||
mod printer;
|
||||
mod quotes;
|
||||
|
||||
struct PreviewFrame {
|
||||
buffer: SharedPixelBuffer<Rgb8Pixel>,
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
//! band and are not stored by the printer (no memory switch writes).
|
||||
//!
|
||||
//! Each photo is captioned with the event name and place above it, and a
|
||||
//! keepsake line, the capture date and time and one of `QUOTES` below it, in
|
||||
//! German with the English directly underneath. The timestamp is the system
|
||||
//! keepsake line, the capture date and time and one of `QUOTES` below it. The
|
||||
//! captions are in German with the English directly underneath, the quotes in
|
||||
//! English only. The timestamp is the system
|
||||
//! clock in local time, so the booth's clock has to be right for it to mean
|
||||
//! anything. Text goes out in the printer's own code page (PC437), since it
|
||||
//! prints UTF-8 bytes as separate glyphs; see `code_page`.
|
||||
@@ -52,6 +53,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 +77,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 +369,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<u8> {
|
||||
Some(match character {
|
||||
'ä' => 0x84,
|
||||
@@ -414,6 +382,7 @@ fn code_page(character: char) -> Option<u8> {
|
||||
'Ö' => 0x99,
|
||||
'Ü' => 0x9A,
|
||||
'ß' => 0xE1,
|
||||
'·' => 0xFA,
|
||||
ascii if ascii.is_ascii() => ascii as u8,
|
||||
_ => return None,
|
||||
})
|
||||
@@ -456,7 +425,7 @@ fn first_quote() -> usize {
|
||||
% QUOTES.len()
|
||||
}
|
||||
|
||||
fn footer(head: &Head, stamp: &str, quote: &[&str; 2]) -> Vec<u8> {
|
||||
fn footer(head: &Head, stamp: &str, quote: &[&str]) -> Vec<u8> {
|
||||
let mut write = centered(head);
|
||||
write.extend([0x1B, b'd', 1]);
|
||||
write.extend(LARGE);
|
||||
@@ -466,8 +435,9 @@ fn footer(head: &Head, stamp: &str, quote: &[&str; 2]) -> Vec<u8> {
|
||||
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 +453,7 @@ mod tests {
|
||||
fn printed_lines() -> impl Iterator<Item = &'static str> {
|
||||
[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 +493,7 @@ mod tests {
|
||||
let picked: std::collections::BTreeSet<usize> =
|
||||
(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:?}");
|
||||
}
|
||||
|
||||
@@ -650,16 +620,16 @@ mod tests {
|
||||
width_bytes: 1,
|
||||
data: vec![0; 1],
|
||||
};
|
||||
let job = encode(&bitmap, &Head::default(), 2, STAMP, 6);
|
||||
let last = QUOTES.len() - 1;
|
||||
let job = encode(&bitmap, &Head::default(), 2, STAMP, last);
|
||||
assert!(contains_line(&job[0], EVENT_TITLE) && contains_line(&job[0], EVENT_PLACE));
|
||||
assert!(contains_line(&job[2], KEEPSAKE_DE) && contains_line(&job[2], KEEPSAKE_EN));
|
||||
assert!(contains_line(&job[2], STAMP));
|
||||
// Consecutive copies get consecutive quotes, wrapping round the list.
|
||||
assert!(contains_line(&job[2], QUOTES[6][0]) && contains_line(&job[2], QUOTES[6][1]));
|
||||
assert!(contains_line(&job[5], QUOTES[7][0]) && contains_line(&job[5], QUOTES[7][1]));
|
||||
assert!(QUOTES[last].iter().all(|line| contains_line(&job[2], line)));
|
||||
assert!(QUOTES[0].iter().all(|line| contains_line(&job[5], line)));
|
||||
assert!(
|
||||
encode(&bitmap, &Head::default(), 1, STAMP, QUOTES.len() - 1)[2]
|
||||
.ends_with(&footer(&Head::default(), STAMP, "ES[QUOTES.len() - 1])[1..])
|
||||
job[2].ends_with(&footer(&Head::default(), STAMP, QUOTES[last])[1..])
|
||||
);
|
||||
// The real stamp is as wide as the one used here.
|
||||
let now = Local::now().format(STAMP_FORMAT).to_string();
|
||||
|
||||
89
src/quotes.rs
Normal file
89
src/quotes.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
//! Quotes printed under each photo, one per slip.
|
||||
|
||||
/// One is printed per slip, one printed line per entry, in English. 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]] = &[
|
||||
// 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!"],
|
||||
];
|
||||
Reference in New Issue
Block a user