From 9c669985302b483892912aa345aaab1c057e1bfa Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Fri, 20 Jan 2023 07:35:21 +0100 Subject: [PATCH 1/3] :bug: Fix svg import --- frontend/src/app/main/data/workspace/svg_upload.cljs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index 096bd0464..00e314a0b 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -516,12 +516,12 @@ ;; In penpot groups have the size of their children. To respect the imported svg size and empty space let's create a transparent shape as background to respect the imported size base-background-shape {:tag :rect - :attrs {:x "0" - :y "0" - :width (str (:width root-shape)) - :height (str (:height root-shape)) - :fill "none" - :id "base-background"} + :attrs {:x (str vb-x) + :y (str vb-y) + :width (str vb-width) + :height (str vb-height) + :fill "none" + :id "base-background"} :hidden true :content []} From be74cd2c7bfdff04f65b81199f007b78d94458a8 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Fri, 20 Jan 2023 09:17:04 +0100 Subject: [PATCH 2/3] :bug: Fix import svgs with currentColor as stroke fill --- .../app/main/data/workspace/svg_upload.cljs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index 00e314a0b..07b510349 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -81,13 +81,13 @@ color-style (str/trim (get-in shape [:svg-attrs :style :fill])) color-style (if (= color-style "currentColor") clr/black color-style)] (cond-> shape - ;; Color present as attribute + ;; Color present as attribute (uc/color? color-attr) (-> (update :svg-attrs dissoc :fill) (update-in [:svg-attrs :style] dissoc :fill) (assoc-in [:fills 0 :fill-color] (uc/parse-color color-attr))) - ;; Color present as style + ;; Color present as style (uc/color? color-style) (-> (update-in [:svg-attrs :style] dissoc :fill) (update :svg-attrs dissoc :fill) @@ -110,20 +110,22 @@ (get-in shape [:svg-attrs :style :stroke-linecap])) ((d/nilf str/trim)) ((d/nilf keyword))) + color-attr (str/trim (get-in shape [:svg-attrs :stroke])) + color-attr (if (= color-attr "currentColor") clr/black color-attr) + color-style (str/trim (get-in shape [:svg-attrs :style :stroke])) + color-style (if (= color-style "currentColor") clr/black color-style) shape (cond-> shape - (uc/color? (str/trim (get-in shape [:svg-attrs :stroke]))) + ;; Color present as attribute + (uc/color? color-attr) (-> (update :svg-attrs dissoc :stroke) - (assoc-in [:strokes 0 :stroke-color] (-> (get-in shape [:svg-attrs :stroke]) - (str/trim) - (uc/parse-color)))) + (assoc-in [:strokes 0 :stroke-color] (uc/parse-color color-attr))) - (uc/color? (str/trim (get-in shape [:svg-attrs :style :stroke]))) + ;; Color present as style + (uc/color? color-style) (-> (update-in [:svg-attrs :style] dissoc :stroke) - (assoc-in [:strokes 0 :stroke-color] (-> (get-in shape [:svg-attrs :style :stroke]) - (str/trim) - (uc/parse-color)))) + (assoc-in [:strokes 0 :stroke-color] (uc/parse-color color-style))) (get-in shape [:svg-attrs :stroke-opacity]) (-> (update :svg-attrs dissoc :stroke-opacity) @@ -133,7 +135,7 @@ (get-in shape [:svg-attrs :style :stroke-opacity]) (-> (update-in [:svg-attrs :style] dissoc :stroke-opacity) (assoc-in [:strokes 0 :stroke-opacity] (-> (get-in shape [:svg-attrs :style :stroke-opacity]) - (d/parse-double)))) + (d/parse-double)))) (get-in shape [:svg-attrs :stroke-width]) (-> (update :svg-attrs dissoc :stroke-width) From 2f188e7fb40f2d5630716a06263b36bd252c16f5 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Fri, 20 Jan 2023 11:01:22 +0100 Subject: [PATCH 3/3] :bug: Fix regression with library svgs --- frontend/src/app/main/ui/shapes/attrs.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/shapes/attrs.cljs b/frontend/src/app/main/ui/shapes/attrs.cljs index 7b9275ba7..acaad65e9 100644 --- a/frontend/src/app/main/ui/shapes/attrs.cljs +++ b/frontend/src/app/main/ui/shapes/attrs.cljs @@ -147,7 +147,7 @@ (defn extract-svg-attrs [render-id svg-defs svg-attrs] (if (and (empty? svg-defs) (empty? svg-attrs)) - [nil nil] + [{} {}] (let [replace-id (fn [id] (if (contains? svg-defs id) (str render-id "-" id)