usesuper::*;usecrate::story::layout::{script, SceneIn};/// A story laid out by this app's own page rules and printed the way the/// phones print it: Courier 12 pt from a 1.5 inch margin, ten characters an/// inch, six lines an inch, scene numbers in both margins, page numbers at/// the top right from page two, a title page first.fn printed(scenes: &[SceneIn], names: &[String]) -> Vec<Vec<PrintedLine>> {let laid = script(scenes, names);letmut pages = vec![vec![PrintedLine { y: 300.0, size: 12.0, cells: vec![(250.0, "THE NIGHT BUS".into())] },PrintedLine { y: 336.0, size: 12.0, cells: vec![(270.0, "Written by".into())] },PrintedLine { y: 360.0, size: 12.0, cells: vec![(265.0, "A. Writer".into())] }, ]];for page in &laid.pages {letmut lines = Vec::new();if page.number > 1 { lines.push(PrintedLine { y: 50.0, size: 12.0, cells: vec![(530.0, format!("{}.", page.number))] }); }for (at, row) in page.lines.iter().enumerate() {if row.kind == "blank" {continue; }let x = 108.0 + row.indent as f32 * 7.2;letmut cells = vec![(x, row.text.clone())];ifletSome(scene) = &row.scene { cells.insert(0, (80.0, scene.number.to_string())); cells.push((540.0, scene.number.to_string())); } lines.push(PrintedLine { y: 72.0 + at as f32 * 12.0, size: 12.0, cells }); } pages.push(lines); } pages}/// RULE: A printed screenplay PDF comes in as its scenes, speakers, asides, speech and cuts, read by where each line stands; scene and page numbers, (MORE) and (CONT'D) are left out, a speech over a page break is one speech, the title page gives the title and author, and Telugu and Hindi lines come in as written.#[test]fn a_printed_script_comes_in_by_its_columns() {let long = "Steam off the kettle. Meera counts the coins twice, then a third time, slower, as if the number might change.";let speech = "రవి ఏమీ అనలేదు. పడవ నెమ్మదిగా కదిలింది, నీళ్ల మీద చంద్రుడు ముక్కలయ్యాడు, ఎవరూ మాట్లాడలేదు.";letmut scenes = vec![SceneIn { id: "a".into(), heading: "INT. TEA STALL - MORNING".into(), body: format!("{long}\n\nMEERA\n(not looking up)\nYou took money from him?\n\n@రవి\n{speech}\n\n@रीना\nचलो, देर हो रही है।\n\nCUT TO:") },SceneIn { id: "b".into(), heading: "EXT. JETTY - NIGHT".into(), body: "The boat is gone.".into() }, ];// A long speech, so a page breaks inside it.letmut many = String::from("Nobody speaks.");for _ in0..30 { many.push_str("\n\nRAVI\nOne more crossing, and then no more."); } many.push_str("\n\nOLD MAN\n"); many.push_str(&"I saw nothing, I always see nothing, and tonight I see less than ever. ".repeat(12)); scenes.push(SceneIn { id: "c".into(), heading: "EXT. RIVER - NIGHT".into(), body: many.trim_end().to_string() });let names = vec!["రవి".to_string(), "रीना".to_string(), "MEERA".to_string(), "RAVI".to_string(), "OLD MAN".to_string()];let pages = printed(&scenes, &names); assert!(pages.len() > 3, "the long scene runs over pages");let (elements, title, author) = pdf_elements(&pages); assert_eq!(title.as_deref(), Some("THE NIGHT BUS")); assert_eq!(author.as_deref(), Some("A. Writer"));let doc = doc_of(title.as_deref(), author.as_deref(), &elements); assert_eq!(doc.scenes.len(), 3); assert_eq!(doc.scenes[0].heading, "INT. TEA STALL - MORNING"); assert_eq!(doc.scenes[0].body, format!("{long}\n\nMEERA\n(not looking up)\nYou took money from him?\n\n@రవి\n{speech}\n\n@रीना\nचलो, देर हो रही है।\n\nCUT TO:")); assert_eq!(doc.scenes[1].body, "The boat is gone.");let river = &doc.scenes[2].body; assert!(!river.contains("MORE") && !river.contains("CONT'D"), "{river}"); assert_eq!(river.matches("RAVI\n").count(), 30); assert_eq!(river.matches("OLD MAN\n").count(), 1, "one speech over the page break"); assert!(river.ends_with("tonight I see less than ever."), "{river}");}/// RULE: Elements make scene bodies the writer keeps: a name in lower case or without capitals is marked with `@`, an aside gets its brackets, a cut not ending TO: is forced, and words before the first heading are a scene with no heading.#[test]fn elements_make_fountain_bodies() {let doc = doc_of(Some(" Last Ferry "),None, &[Element::Action("Before.".into()),Element::Heading("INT. BOAT - NIGHT".into()),Element::Summary("They cross".into()),Element::Character("Meera".into()),Element::Parenthetical("softly".into()),Element::Dialogue("Now.".into()),Element::Character("RAVI (V.O.)".into()),Element::Dialogue("Not yet.".into()),Element::Transition("Fade out.".into()),Element::Centered("THE END".into()), ], ); assert_eq!(doc.title, vec![("Title".to_string(), "Last Ferry".to_string())]); assert_eq!(doc.scenes[0].heading, ""); assert_eq!(doc.scenes[0].body, "Before."); assert_eq!(doc.scenes[1].summary.as_deref(), Some("They cross")); assert_eq!(doc.scenes[1].body, "@Meera\n(softly)\nNow.\n\nRAVI (V.O.)\nNot yet.\n\n> Fade out.\n\n> THE END <");}