Skip to content

Commit 44f9b8f

Browse files
mTvare6Keavon
authored andcommitted
works finally
1 parent 0d18146 commit 44f9b8f

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

frontend/wasm/src/editor_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ fn render_image_data_to_canvases(image_data: &[(u64, Image<Color>, TransformImag
7777
.dyn_into::<HtmlCanvasElement>()
7878
.expect("Failed to cast element to HtmlCanvasElement");
7979

80-
canvas.set_width(1);
81-
canvas.set_height(1);
80+
canvas.set_width(image.width);
81+
canvas.set_height(image.height);
8282
let context: CanvasRenderingContext2d = canvas
8383
.get_context("2d")
8484
.expect("Failed to get 2d context")

node-graph/gsvg-renderer/src/renderer.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,17 +949,24 @@ impl GraphicElementRendered for RasterDataTable<CPU> {
949949

950950
if render_params.to_canvas() {
951951
let id = generate_uuid();
952+
let scale = DVec2::new(transform.x_axis.x, transform.y_axis.y);
952953
render.image_data.push((id, image.data().clone(), TransformImage(transform)));
954+
log::debug!("{transform} {} {}", image.width, image.height);
953955
render.parent_tag(
954956
"foreignObject",
955957
|attributes| {
956-
attributes.push("width", "1");
957-
attributes.push("height", "1");
958-
959-
let matrix = format_transform_matrix(transform);
958+
let size = DVec2::new(image.width as f64, image.height as f64);
959+
let scale = scale / size;
960+
let scale = DAffine2::from_scale(scale);
961+
let matrix = format_transform_matrix(scale);
960962
if !matrix.is_empty() {
961963
attributes.push("transform", matrix);
964+
attributes.push("transform-origin", "top-left");
962965
}
966+
attributes.push("width", transform.matrix2.x_axis.x.to_string());
967+
attributes.push("height", transform.matrix2.y_axis.y.to_string());
968+
attributes.push("x", transform.translation.x.to_string());
969+
attributes.push("y", transform.translation.y.to_string());
963970

964971
let factor = if render_params.for_mask { 1. } else { instance.alpha_blending.fill };
965972
let opacity = instance.alpha_blending.opacity * factor;
@@ -973,7 +980,6 @@ impl GraphicElementRendered for RasterDataTable<CPU> {
973980
|render| {
974981
render.leaf_tag("div", |attributes| {
975982
attributes.push("data-canvas-placeholder", format!("canvas{}", id));
976-
attributes.push("style", "width: 100%; height: 100%;".to_string());
977983
})
978984
},
979985
);

0 commit comments

Comments
 (0)