mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
Merge pull request #7343 from penpot/elenatorro-12118-support-large-svg-files
🐛 Fix parsing large paths with multiple subpaths
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
["react-dom/server" :as rds]
|
||||
[app.common.data :as d :refer [not-empty?]]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.math :as mth]
|
||||
[app.common.types.fills :as types.fills]
|
||||
[app.common.types.fills.impl :as types.fills.impl]
|
||||
[app.common.types.path :as path]
|
||||
@@ -51,6 +52,8 @@
|
||||
(def ^:const GRID-LAYOUT-COLUMN-U8-SIZE 8)
|
||||
(def ^:const GRID-LAYOUT-CELL-U8-SIZE 36)
|
||||
|
||||
(def ^:const MAX_BUFFER_CHUNK_SIZE (* 256 1024))
|
||||
|
||||
(def dpr
|
||||
(if use-dpr? (if (exists? js/window) js/window.devicePixelRatio 1.0) 1.0))
|
||||
|
||||
@@ -317,15 +320,27 @@
|
||||
(h/call wasm/internal-module "stringToUTF8" str offset size)
|
||||
(h/call wasm/internal-module "_set_shape_path_attrs" (count attrs))))
|
||||
|
||||
;; FIXME: revisit on heap refactor is merged to use u32 instead u8
|
||||
(defn set-shape-path-content
|
||||
"Upload path content in chunks to WASM."
|
||||
[content]
|
||||
(let [pdata (path/content content)
|
||||
size (path/get-byte-size content)
|
||||
offset (mem/alloc size)
|
||||
heap (mem/get-heap-u8)]
|
||||
(path/write-to pdata (.-buffer heap) offset)
|
||||
(h/call wasm/internal-module "_set_shape_path_content")))
|
||||
(let [chunk-size (quot MAX_BUFFER_CHUNK_SIZE 4)
|
||||
buffer-size (path/get-byte-size content)
|
||||
padded-size (* 4 (mth/ceil (/ buffer-size 4)))
|
||||
buffer (js/Uint8Array. padded-size)]
|
||||
(path/write-to content (.-buffer buffer) 0)
|
||||
(h/call wasm/internal-module "_start_shape_path_buffer")
|
||||
(let [heapu32 (mem/get-heap-u32)]
|
||||
(loop [offset 0]
|
||||
(when (< offset padded-size)
|
||||
(let [end (min padded-size (+ offset (* chunk-size 4)))
|
||||
chunk (.subarray buffer offset end)
|
||||
chunk-u32 (js/Uint32Array. chunk.buffer chunk.byteOffset (quot (.-length chunk) 4))
|
||||
offset-size (.-length chunk-u32)
|
||||
heap-offset (mem/alloc->offset-32 (* 4 offset-size))]
|
||||
(.set heapu32 chunk-u32 heap-offset)
|
||||
(h/call wasm/internal-module "_set_shape_path_chunk_buffer")
|
||||
(recur end)))))
|
||||
(h/call wasm/internal-module "_set_shape_path_buffer")))
|
||||
|
||||
(defn set-shape-svg-raw-content
|
||||
[content]
|
||||
|
||||
Reference in New Issue
Block a user