Skip to content

Commit

Permalink
feat: add SDO filename as title
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphoseer committed Jan 18, 2025
1 parent ca19c29 commit d8691f7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/sdo-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub struct ActiveDocument {
sdoc: SDoc<'static>,
di: DocumentInfo,
pd: FontKind,
name: String,
}

impl GenerationContext for ActiveDocument {
Expand Down Expand Up @@ -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),
Expand All @@ -439,7 +443,7 @@ impl Handle {

#[wasm_bindgen]
pub async fn render(&mut self, requested_index: usize) -> Result<Blob, JsValue> {
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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d8691f7

Please sign in to comment.