chiark / gitweb /
bundles: base64 the SVGs from bundles
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 22 May 2021 21:21:32 +0000 (22:21 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 22 May 2021 21:42:43 +0000 (22:42 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bundles.rs
templates/script.ts

index e6ae0932915587d57c23f6ef7e516832d02c310a..fdc2482daa401c963fd54896fd9ae2dabdec54a7 100644 (file)
@@ -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")?;
index 4df5d069408f72a9f3e1630807b2dbc50e195487..54a258da5356b79ad3370481d2188c0d4d4d7087 100644 (file)
@@ -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;