From a11c2af54263e77981f4b5c25bd470a23c814037 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 10 Oct 2024 14:23:32 +0200 Subject: [PATCH] Playing with image export and svg generation --- frontend/render_v2/rs/src/main.rs | 16 ++++++++-------- frontend/src/app/render_v2/rs.js | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/frontend/render_v2/rs/src/main.rs b/frontend/render_v2/rs/src/main.rs index 8bc8d1627..215a602c2 100644 --- a/frontend/render_v2/rs/src/main.rs +++ b/frontend/render_v2/rs/src/main.rs @@ -266,16 +266,16 @@ pub unsafe extern "C" fn draw_shapes(state: *mut State, ptr: *mut Rect, len: usi } // base64 image of the canvas - // let image = state.surface.image_snapshot(); - // let mut context = state.surface.direct_context(); - // let encoded_image = image.encode(context.as_mut(), EncodedImageFormat::PNG, None).unwrap(); - // let base64_image = base64::encode(&encoded_image.as_bytes()); - // println!("data:image/png;base64,{}", base64_image); + let image = state.surface.image_snapshot(); + let mut context = state.surface.direct_context(); + let encoded_image = image.encode(context.as_mut(), EncodedImageFormat::PNG, None).unwrap(); + let base64_image = base64::encode(&encoded_image.as_bytes()); + println!("data:image/png;base64,{}", base64_image); // SVG representation - // let svg_data = svg_canvas.end(); - // let svg = String::from_utf8_lossy(svg_data.as_bytes()); - // println!("svg: {}", svg); + let svg_data = svg_canvas.end(); + let svg = String::from_utf8_lossy(svg_data.as_bytes()); + println!("svg: {}", svg.replace('\n', "")); flush(state); std::mem::forget(buf); diff --git a/frontend/src/app/render_v2/rs.js b/frontend/src/app/render_v2/rs.js index 339c18a46..a8d0fc988 100644 --- a/frontend/src/app/render_v2/rs.js +++ b/frontend/src/app/render_v2/rs.js @@ -9192,6 +9192,17 @@ function invoke_iif(index,a1,a2) { } } +function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6) { + var sp = stackSave(); + try { + getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6); + } catch(e) { + stackRestore(sp); + if (!(e instanceof EmscriptenEH)) throw e; + _setThrew(1, 0); + } +} + function invoke_iiiiffii(index,a1,a2,a3,a4,a5,a6,a7) { var sp = stackSave(); try { @@ -9225,17 +9236,6 @@ function invoke_viiff(index,a1,a2,a3,a4) { } } -function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6) { - var sp = stackSave(); - try { - getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6); - } catch(e) { - stackRestore(sp); - if (!(e instanceof EmscriptenEH)) throw e; - _setThrew(1, 0); - } -} - function invoke_viiiiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8,a9) { var sp = stackSave(); try {