From d8691f784563e4dfac0c46635b82f3ef92eaee73 Mon Sep 17 00:00:00 2001 From: Xiphoseer Date: Sat, 18 Jan 2025 09:38:56 +0100 Subject: [PATCH] feat: add SDO filename as title --- crates/sdo-web/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/sdo-web/src/lib.rs b/crates/sdo-web/src/lib.rs index 0bd6db07..4369954f 100644 --- a/crates/sdo-web/src/lib.rs +++ b/crates/sdo-web/src/lib.rs @@ -109,6 +109,7 @@ pub struct ActiveDocument { sdoc: SDoc<'static>, di: DocumentInfo, pd: FontKind, + name: String, } impl GenerationContext for ActiveDocument { @@ -422,7 +423,10 @@ impl Handle { xoffset: 0, yoffset: 0, }; - let meta = MetaInfo::default(); + let meta = MetaInfo { + title: Some(active_doc.name.clone()), + ..MetaInfo::default() + }; let pk = match active_doc.pd { FontKind::Editor => Err(JsError::new("editor font not supported")), FontKind::Printer(printer_kind) => Ok(printer_kind), @@ -439,7 +443,7 @@ impl Handle { #[wasm_bindgen] pub async fn render(&mut self, requested_index: usize) -> Result { - if let Some(ActiveDocument { sdoc, di, pd }) = &self.active { + if let Some(ActiveDocument { sdoc, di, pd, .. }) = &self.active { if let Some(page_text) = sdoc.tebu.pages.get(requested_index) { let index = page_text.index as usize; log::info!("Rendering page {} ({})", requested_index, index); @@ -479,12 +483,12 @@ impl Handle { .map(|active| active.sdoc.tebu.pages.len()) } - async fn show_staged(&mut self, rest: &str) -> Result<(), JsValue> { + async fn show_staged(&mut self, name: &str) -> Result<(), JsValue> { let heading = self.document.create_element("h2")?; - heading.set_text_content(Some(rest)); + heading.set_text_content(Some(name)); self.output.append_child(&heading)?; - let file = self.input_file(rest)?; + let file = self.input_file(name)?; let data = js_file_data(&file).await?.to_vec(); if let Ok((_, four_cc)) = four_cc(&data) { @@ -513,6 +517,7 @@ impl Handle { sdoc: sdoc.into_owned(), di: DocumentInfo::new(dfci, images), pd, + name: name.to_owned(), }); } _ => warn!("Unknown format: {}", four_cc),