🐛 Ignore export scale in render-wasm PDF export (#12447)

This commit is contained in:
Elena Torró 2026-10-19 18:21:02 +02:00 committed by GitHub
parent 29cd50621d
commit 0801674af2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 15 additions and 23 deletions

View File

@ -287,11 +287,10 @@
(defn render-shape-pdf
"Renders the shape subtree to PDF bytes (Uint8Array)."
[shape-id scale]
[shape-id]
(let [buf (uuid/get-u32 shape-id)]
(-> (h/call wasm/internal-module "_render_shape_pdf"
(aget buf 0) (aget buf 1) (aget buf 2) (aget buf 3)
scale)
(aget buf 0) (aget buf 1) (aget buf 2) (aget buf 3))
(read-render-result LEN-HEADER-BYTES))))
(defn render-shape-svg

View File

@ -418,7 +418,7 @@
(defn- render-object-bytes
[type id scale]
(case type
:pdf (let [bytes (wasm/render-shape-pdf id scale)]
:pdf (let [bytes (wasm/render-shape-pdf id)]
(l/dbg :hint "PDF generated via Skia (render-wasm headless)"
:object-id (str id)
:backend "skia-wasm"

View File

@ -30,8 +30,8 @@
nil))
(defn export-pdf-uri
[{:keys [scale object-id]}]
(let [bytes (wasm.api/render-shape-pdf object-id (or scale 1))
[{:keys [object-id]}]
(let [bytes (wasm.api/render-shape-pdf object-id)
blob (wapi/create-blob bytes "application/pdf")]
(wapi/create-uri blob)))

View File

@ -3010,7 +3010,7 @@
{:x x :y y :width w :height h})))))
(defn render-shape-pdf
[shape-id scale]
[shape-id]
(when (initialized?)
(let [buffer (uuid/get-u32 shape-id)
@ -3019,8 +3019,7 @@
(aget buffer 0)
(aget buffer 1)
(aget buffer 2)
(aget buffer 3)
scale)
(aget buffer 3))
heap (mem/get-heap-u8)
heapu32 (mem/get-heap-u32)

View File

@ -818,11 +818,11 @@ pub fn free_gpu_resources() {
#[no_mangle]
#[wasm_error]
pub extern "C" fn render_shape_pdf(a: u32, b: u32, c: u32, d: u32, scale: f32) -> Result<*mut u8> {
pub extern "C" fn render_shape_pdf(a: u32, b: u32, c: u32, d: u32) -> Result<*mut u8> {
let id = uuid_from_u32_quartet(a, b, c, d);
with_state!(state, {
let data = state.render_shape_pdf(&id, scale)?;
let data = state.render_shape_pdf(&id)?;
let len = data.len() as u32;
let mut buf = Vec::with_capacity(4 + data.len());

View File

@ -19,17 +19,13 @@ pub fn render_to_pdf(
shared: &mut RenderResources,
id: &Uuid,
tree: ShapesPoolRef,
scale: f32,
) -> Result<Vec<u8>> {
let shape = tree
.get(id)
.ok_or_else(|| crate::error::Error::CriticalError("Shape not found for PDF".to_string()))?;
// Boards crop overflowing children (classic board box) but keep their own
// strokes/shadows/blur. Other shapes use full extrect.
let bounds = shape.export_root_bounds(tree, scale);
let page_w = bounds.width() * scale;
let page_h = bounds.height() * scale;
let bounds = shape.export_root_bounds(tree, 1.0);
let mut pdf_bytes: Vec<u8> = Vec::new();
@ -42,13 +38,12 @@ pub fn render_to_pdf(
let document = skia::pdf::new_document(&mut pdf_bytes, Some(&metadata));
let mut on_page = document.begin_page((page_w, page_h), None);
let mut on_page = document.begin_page((bounds.width(), bounds.height()), None);
{
let page_canvas = on_page.canvas();
page_canvas.scale((scale, scale));
page_canvas.translate((-bounds.left(), -bounds.top()));
vector::render_tree_pdf(shared, page_canvas, id, tree, scale, bounds)?;
vector::render_tree_pdf(shared, page_canvas, id, tree, bounds)?;
}
let document = on_page.end_page();

View File

@ -474,10 +474,9 @@ pub(super) fn render_tree_pdf(
canvas: &Canvas,
id: &Uuid,
tree: ShapesPoolRef,
scale: f32,
page: skia::Rect,
) -> Result<()> {
render_tree_dispatch(shared, canvas, id, tree, scale, page, true)
render_tree_dispatch(shared, canvas, id, tree, 1.0, page, true)
}
#[allow(clippy::too_many_arguments)]

View File

@ -101,8 +101,8 @@ impl State {
get_render_state().render_shape_pixels(id, &self.shapes, scale, timestamp, format)
}
pub fn render_shape_pdf(&mut self, id: &Uuid, scale: f32) -> Result<Vec<u8>> {
crate::render::pdf::render_to_pdf(get_resources(), id, &self.shapes, scale)
pub fn render_shape_pdf(&mut self, id: &Uuid) -> Result<Vec<u8>> {
crate::render::pdf::render_to_pdf(get_resources(), id, &self.shapes)
}
pub fn render_shape_svg(&mut self, id: &Uuid, scale: f32) -> Result<Vec<u8>> {