mirror of
https://github.com/penpot/penpot.git
synced 2026-06-02 05:30:19 +00:00
Playing with image export and svg generation
This commit is contained in:
parent
445691430b
commit
dfe5d861f2
7
frontend/render_v2/rs/Cargo.lock
generated
7
frontend/render_v2/rs/Cargo.lock
generated
@ -17,6 +17,12 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
version = "0.69.4"
|
version = "0.69.4"
|
||||||
@ -370,6 +376,7 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
|||||||
name = "render"
|
name = "render"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64",
|
||||||
"gl",
|
"gl",
|
||||||
"skia-safe",
|
"skia-safe",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -16,6 +16,7 @@ path = "src/main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
gl = "0.14.0"
|
gl = "0.14.0"
|
||||||
skia-safe = "0.78.2"
|
skia-safe = "0.78.2"
|
||||||
|
base64 = "0.13"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = "s"
|
opt-level = "s"
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use std::boxed::Box;
|
|||||||
use skia_safe::{
|
use skia_safe::{
|
||||||
gpu::{self, gl::FramebufferInfo, DirectContext},
|
gpu::{self, gl::FramebufferInfo, DirectContext},
|
||||||
textlayout::{FontCollection, ParagraphBuilder, ParagraphStyle, TextStyle, TypefaceFontProvider},
|
textlayout::{FontCollection, ParagraphBuilder, ParagraphStyle, TextStyle, TypefaceFontProvider},
|
||||||
FontMgr, Paint, Path, PaintStyle
|
FontMgr, Paint, Path, PaintStyle, EncodedImageFormat, Data, Canvas, SurfaceProps
|
||||||
};
|
};
|
||||||
|
|
||||||
use skia_safe as skia;
|
use skia_safe as skia;
|
||||||
@ -29,7 +29,7 @@ pub struct State {
|
|||||||
gpu_state: GpuState,
|
gpu_state: GpuState,
|
||||||
surface: skia::Surface,
|
surface: skia::Surface,
|
||||||
typeface_font_provider: TypefaceFontProvider,
|
typeface_font_provider: TypefaceFontProvider,
|
||||||
default_font: skia_safe::Font,
|
default_font: skia_safe::Font
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
@ -199,8 +199,11 @@ pub unsafe extern "C" fn scale(state: *mut State, sx: f32, sy: f32) {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn reset_canvas(state: *mut State) {
|
pub unsafe extern "C" fn reset_canvas(state: *mut State) {
|
||||||
(*state).surface.canvas().clear(skia_safe::Color::TRANSPARENT);
|
println!("reset_canvas");
|
||||||
(*state).surface.canvas().reset_matrix();
|
let state = unsafe { state.as_mut() }.expect("got an invalid state pointer");
|
||||||
|
state.surface.canvas().clear(skia_safe::Color::TRANSPARENT);
|
||||||
|
state.surface.canvas().reset_matrix();
|
||||||
|
flush(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@ -223,11 +226,19 @@ pub unsafe extern "C" fn draw_shapes(state: *mut State, ptr: *mut Rect, len: usi
|
|||||||
path_paint.set_stroke_width(1.0);
|
path_paint.set_stroke_width(1.0);
|
||||||
path_paint.set_style(PaintStyle::Stroke);
|
path_paint.set_style(PaintStyle::Stroke);
|
||||||
|
|
||||||
|
let svg_canvas = skia_safe::svg::Canvas::new(skia_safe::Rect::from_size((10000, 10000)), None);
|
||||||
|
|
||||||
for rect in buf.iter() {
|
for rect in buf.iter() {
|
||||||
let r = skia::Rect::new(rect.left, rect.top, rect.right, rect.bottom);
|
let r = skia::Rect::new(rect.left, rect.top, rect.right, rect.bottom);
|
||||||
let color = skia::Color::from_argb((rect.a * 255.0) as u8, rect.r as u8, rect.g as u8, rect.b as u8);
|
let color = skia::Color::from_argb((rect.a * 255.0) as u8, rect.r as u8, rect.g as u8, rect.b as u8);
|
||||||
render_rect(&mut state.surface, r, color);
|
render_rect(&mut state.surface, r, color);
|
||||||
|
|
||||||
|
let mut paint = skia::Paint::default();
|
||||||
|
paint.set_style(skia::PaintStyle::Fill);
|
||||||
|
paint.set_color(color);
|
||||||
|
paint.set_anti_alias(true);
|
||||||
|
svg_canvas.draw_rect(r, &paint);
|
||||||
|
|
||||||
text_paint.set_color(color);
|
text_paint.set_color(color);
|
||||||
state.surface.canvas().draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
state.surface.canvas().draw_str("SKIA TEXT", (rect.left, rect.top), &state.default_font, &text_paint);
|
||||||
|
|
||||||
@ -250,6 +261,19 @@ pub unsafe extern "C" fn draw_shapes(state: *mut State, ptr: *mut Rect, len: usi
|
|||||||
paragraph.layout(256.0);
|
paragraph.layout(256.0);
|
||||||
paragraph.paint(state.surface.canvas(), (rect.left, rect.top));
|
paragraph.paint(state.surface.canvas(), (rect.left, rect.top));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// SVG representation
|
||||||
|
// let svg_data = svg_canvas.end();
|
||||||
|
// let svg = String::from_utf8_lossy(svg_data.as_bytes());
|
||||||
|
// println!("svg: {}", svg);
|
||||||
|
|
||||||
flush(state);
|
flush(state);
|
||||||
std::mem::forget(buf);
|
std::mem::forget(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,9 @@
|
|||||||
;; - 4 F32 for points coordinates
|
;; - 4 F32 for points coordinates
|
||||||
;; - 4 F32 for color
|
;; - 4 F32 for color
|
||||||
;; rect-size (* 8 4)
|
;; rect-size (* 8 4)
|
||||||
rect-size (* 8 4)]
|
rect-size (* 8 4)
|
||||||
|
;; kk (data gpu-state)
|
||||||
|
]
|
||||||
(when shapes-ptr
|
(when shapes-ptr
|
||||||
(free_rects shapes-ptr shapes-size))
|
(free_rects shapes-ptr shapes-size))
|
||||||
|
|
||||||
|
|||||||
@ -8972,6 +8972,17 @@ var dynCall_iiiiij = Module['dynCall_iiiiij'] = createExportWrapper('dynCall_iii
|
|||||||
var dynCall_iiiiijj = Module['dynCall_iiiiijj'] = createExportWrapper('dynCall_iiiiijj', 9);
|
var dynCall_iiiiijj = Module['dynCall_iiiiijj'] = createExportWrapper('dynCall_iiiiijj', 9);
|
||||||
var dynCall_iiiiiijj = Module['dynCall_iiiiiijj'] = createExportWrapper('dynCall_iiiiiijj', 10);
|
var dynCall_iiiiiijj = Module['dynCall_iiiiiijj'] = createExportWrapper('dynCall_iiiiiijj', 10);
|
||||||
|
|
||||||
|
function invoke_iiii(index,a1,a2,a3) {
|
||||||
|
var sp = stackSave();
|
||||||
|
try {
|
||||||
|
return getWasmTableEntry(index)(a1,a2,a3);
|
||||||
|
} catch(e) {
|
||||||
|
stackRestore(sp);
|
||||||
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
|
_setThrew(1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function invoke_ii(index,a1) {
|
function invoke_ii(index,a1) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
@ -8983,17 +8994,6 @@ function invoke_ii(index,a1) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function invoke_viii(index,a1,a2,a3) {
|
|
||||||
var sp = stackSave();
|
|
||||||
try {
|
|
||||||
getWasmTableEntry(index)(a1,a2,a3);
|
|
||||||
} catch(e) {
|
|
||||||
stackRestore(sp);
|
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
|
||||||
_setThrew(1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function invoke_vi(index,a1) {
|
function invoke_vi(index,a1) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
@ -9005,28 +9005,6 @@ function invoke_vi(index,a1) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function invoke_iii(index,a1,a2) {
|
|
||||||
var sp = stackSave();
|
|
||||||
try {
|
|
||||||
return getWasmTableEntry(index)(a1,a2);
|
|
||||||
} catch(e) {
|
|
||||||
stackRestore(sp);
|
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
|
||||||
_setThrew(1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function invoke_vifi(index,a1,a2,a3) {
|
|
||||||
var sp = stackSave();
|
|
||||||
try {
|
|
||||||
getWasmTableEntry(index)(a1,a2,a3);
|
|
||||||
} catch(e) {
|
|
||||||
stackRestore(sp);
|
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
|
||||||
_setThrew(1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function invoke_vii(index,a1,a2) {
|
function invoke_vii(index,a1,a2) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
@ -9049,6 +9027,39 @@ function invoke_viiii(index,a1,a2,a3,a4) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function invoke_viii(index,a1,a2,a3) {
|
||||||
|
var sp = stackSave();
|
||||||
|
try {
|
||||||
|
getWasmTableEntry(index)(a1,a2,a3);
|
||||||
|
} catch(e) {
|
||||||
|
stackRestore(sp);
|
||||||
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
|
_setThrew(1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function invoke_iii(index,a1,a2) {
|
||||||
|
var sp = stackSave();
|
||||||
|
try {
|
||||||
|
return getWasmTableEntry(index)(a1,a2);
|
||||||
|
} catch(e) {
|
||||||
|
stackRestore(sp);
|
||||||
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
|
_setThrew(1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function invoke_vifi(index,a1,a2,a3) {
|
||||||
|
var sp = stackSave();
|
||||||
|
try {
|
||||||
|
getWasmTableEntry(index)(a1,a2,a3);
|
||||||
|
} catch(e) {
|
||||||
|
stackRestore(sp);
|
||||||
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
|
_setThrew(1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function invoke_viiiii(index,a1,a2,a3,a4,a5) {
|
function invoke_viiiii(index,a1,a2,a3,a4,a5) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
@ -9082,10 +9093,21 @@ function invoke_iiiii(index,a1,a2,a3,a4) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function invoke_iiii(index,a1,a2,a3) {
|
function invoke_viffi(index,a1,a2,a3,a4) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
return getWasmTableEntry(index)(a1,a2,a3);
|
getWasmTableEntry(index)(a1,a2,a3,a4);
|
||||||
|
} catch(e) {
|
||||||
|
stackRestore(sp);
|
||||||
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
|
_setThrew(1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function invoke_viiiiffii(index,a1,a2,a3,a4,a5,a6,a7,a8) {
|
||||||
|
var sp = stackSave();
|
||||||
|
try {
|
||||||
|
getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
stackRestore(sp);
|
stackRestore(sp);
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
if (!(e instanceof EmscriptenEH)) throw e;
|
||||||
@ -9203,28 +9225,6 @@ function invoke_viiff(index,a1,a2,a3,a4) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function invoke_viffi(index,a1,a2,a3,a4) {
|
|
||||||
var sp = stackSave();
|
|
||||||
try {
|
|
||||||
getWasmTableEntry(index)(a1,a2,a3,a4);
|
|
||||||
} catch(e) {
|
|
||||||
stackRestore(sp);
|
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
|
||||||
_setThrew(1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function invoke_viiiiffii(index,a1,a2,a3,a4,a5,a6,a7,a8) {
|
|
||||||
var sp = stackSave();
|
|
||||||
try {
|
|
||||||
getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8);
|
|
||||||
} catch(e) {
|
|
||||||
stackRestore(sp);
|
|
||||||
if (!(e instanceof EmscriptenEH)) throw e;
|
|
||||||
_setThrew(1, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6) {
|
function invoke_viiiiii(index,a1,a2,a3,a4,a5,a6) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user