From: Ian Jackson Date: Sat, 22 May 2021 21:21:32 +0000 (+0100) Subject: bundles: base64 the SVGs from bundles X-Git-Tag: otter-0.6.0~55 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=87fb114de1c61ecc8f0f7f881e4f3deb700fdb56;p=otter.git bundles: base64 the SVGs from bundles Signed-off-by: Ian Jackson --- diff --git a/src/bundles.rs b/src/bundles.rs index e6ae0932..fdc2482d 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -848,8 +848,12 @@ fn make_usvg(za: &mut IndexedZip, progress_count: &mut usize, use image::ImageFormat as IF; match format { PF::Svg => { + let mut usvg1 = tempfile::tempfile_in(&svg_dir) + .context("create temporary usvg").map_err(IE::from)?; + let got = Command::new(&config().usvg_bin).args(&["-c","-"]) - .stdin(input).stdout(output) + .stdin(input) + .stdout(usvg1.try_clone().context("dup usvg1").map_err(IE::from)?) .output().context("run usvg").map_err(IE::from)?; if ! got.status.success() { throw!(LE::BadBundle(format!( @@ -857,9 +861,13 @@ fn make_usvg(za: &mut IndexedZip, progress_count: &mut usize, zf.name(), got.status, String::from_utf8_lossy(&got.stderr) ))); } - let t_f = File::open(&usvg_path).context("reopen").map_err(IE::from)?; - let size = usvg_size(&mut BufReader::new(t_f))?; - dbgc!(size); + + usvg1.rewind().context("rewind temporary usvg").map_err(IE::from)?; + let mut usvg1 = BufReader::new(usvg1); + let [width,height] = usvg_size(&mut usvg1)?; + + let render = Base64Meta { width, height, ctype: "image/svg+xml" }; + base64_usvg(zf.name(),usvg1,output, &render)?; }, PF::Png => { image_usvg(zf.name(),input,output, IF::Png, "image/png")?; diff --git a/templates/script.ts b/templates/script.ts index 4df5d069..54a258da 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -1928,8 +1928,6 @@ function startup() { console.log('STARTUP'); console.log(wasm_bindgen.setup("OK")); - // xxx make there be a function for these singleton elements that - // xxx spots if a loaded svg has introduced the same id var body = document.getElementById("main-body")!; zoom_btn = document.getElementById("zoom-btn") as any; zoom_val = document.getElementById("zoom-val") as any;