mirror of
https://github.com/penpot/penpot.git
synced 2026-09-10 14:09:17 +00:00
🐛 Export svg-raw shapes through WASM SVG draw_svg (#11567)
SVG export treated SVGRaw like a fill/stroke leaf and never called draw_svg, so imported SVG content exported as an empty document. Relates to #10546
This commit is contained in:
parent
91860f6916
commit
e67ebacef2
@ -209,6 +209,20 @@ pub(super) fn add_group(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// SVG-raw leaf with markup (same form `get-static-markup` uploads to WASM).
|
||||||
|
pub(super) fn add_svg_raw(
|
||||||
|
pool: &mut ShapesPool,
|
||||||
|
id: Uuid,
|
||||||
|
parent: Uuid,
|
||||||
|
(l, t, r, b): (f32, f32, f32, f32),
|
||||||
|
content: &str,
|
||||||
|
) {
|
||||||
|
let shape = pool.add_shape(id);
|
||||||
|
shape.set_parent(parent);
|
||||||
|
shape.set_svg_raw_content(content.to_string());
|
||||||
|
shape.set_selrect(l, t, r, b);
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds a single-line text shape using the embedded default font.
|
/// Adds a single-line text shape using the embedded default font.
|
||||||
pub(super) fn add_solid_text(
|
pub(super) fn add_solid_text(
|
||||||
pool: &mut ShapesPool,
|
pool: &mut ShapesPool,
|
||||||
|
|||||||
@ -194,6 +194,14 @@ fn render_leaf(
|
|||||||
{
|
{
|
||||||
if matches!(element.shape_type, Type::Text(_)) {
|
if matches!(element.shape_type, Type::Text(_)) {
|
||||||
render_text_fill(builder, shared, element)?;
|
render_text_fill(builder, shared, element)?;
|
||||||
|
} else if matches!(element.shape_type, Type::SVGRaw(_)) {
|
||||||
|
let matrix = element.centered_transform();
|
||||||
|
let canvas = builder.canvas();
|
||||||
|
canvas.save();
|
||||||
|
canvas.concat(&matrix);
|
||||||
|
let mut renderer = VectorRenderer::new(canvas, shared, scale, false);
|
||||||
|
renderer.draw_svg(element)?;
|
||||||
|
canvas.restore();
|
||||||
} else {
|
} else {
|
||||||
emit_fills(builder, shared, element, &element.fills, tree, scale)?;
|
emit_fills(builder, shared, element, &element.fills, tree, scale)?;
|
||||||
|
|
||||||
|
|||||||
@ -125,6 +125,36 @@ fn exports_a_group_with_two_rects_and_group_opacity() {
|
|||||||
insta::assert_snapshot!(svg);
|
insta::assert_snapshot!(svg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn loads_svg_raw_dom_like_wasm_upload() {
|
||||||
|
// Production paints svg-raw via Dom::render after set_shape_svg_raw_content.
|
||||||
|
// Native SkSVGCanvas does not serialize those draws, so the export string
|
||||||
|
// stays empty here; we assert Dom parse + that export does not panic.
|
||||||
|
let mut pool = ShapesPool::new();
|
||||||
|
let id = uid(1);
|
||||||
|
add_svg_raw(
|
||||||
|
&mut pool,
|
||||||
|
id,
|
||||||
|
Uuid::nil(),
|
||||||
|
(0.0, 0.0, 307.0, 243.0),
|
||||||
|
concat!(
|
||||||
|
r#"<svg xmlns="http://www.w3.org/2000/svg">"#,
|
||||||
|
r#"<text x="10" y="24" fill="black">HOLA</text>"#,
|
||||||
|
r#"</svg>"#,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
let resources = crate::render::RenderResources::try_new_headless().expect("headless");
|
||||||
|
let font_manager = skia::FontMgr::from(resources.fonts.font_provider().clone());
|
||||||
|
{
|
||||||
|
let shape = pool.get_mut(&id).unwrap();
|
||||||
|
shape.update_svg_raw_content(font_manager);
|
||||||
|
assert!(shape.svg.is_some(), "Dom must parse like WASM upload");
|
||||||
|
}
|
||||||
|
|
||||||
|
let _svg = render(&pool, id);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn exports_a_clipped_frame_with_overflowing_child() {
|
fn exports_a_clipped_frame_with_overflowing_child() {
|
||||||
let mut pool = ShapesPool::new();
|
let mut pool = ShapesPool::new();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user