From 0b2ffbe1fa4eefb51961a6d9af5292621af4f21b Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 29 Dec 2022 14:39:26 +0100 Subject: [PATCH] :bug: Fix "currentColor" is not converted when importing SVG --- CHANGES.md | 1 + .../app/main/data/workspace/svg_upload.cljs | 47 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 847d2686e..774ad0a2b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -33,6 +33,7 @@ - Fix missing loading icon on shared libraries [Taiga #4148](https://tree.taiga.io/project/penpot/issue/4148) - Fix selection stroke missing in properties of multiple texts [Taiga #4048](https://tree.taiga.io/project/penpot/issue/4048) - Fix missing create component menu for frames [Github #2670](https://github.com/penpot/penpot/issues/2670) +- Fix "currentColor" is not converted when importing SVG [Github 2276](https://github.com/penpot/penpot/issues/2276) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index b0b483f5d..4f34e2d20 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -6,6 +6,7 @@ (ns app.main.data.workspace.svg-upload (:require + [app.common.colors :as clr] [app.common.data :as d] [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] @@ -73,34 +74,34 @@ :else (str tag)))) (defn setup-fill [shape] - (cond-> shape + (let [color-attr (str/trim (get-in shape [:svg-attrs :fill])) + color-attr (if (= color-attr "currentColor") clr/black color-attr) + 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 - (uc/color? (str/trim (get-in shape [:svg-attrs :fill]))) - (-> (update :svg-attrs dissoc :fill) - (update-in [:svg-attrs :style] dissoc :fill) - (assoc-in [:fills 0 :fill-color] (-> (get-in shape [:svg-attrs :fill]) - (str/trim) - (uc/parse-color)))) + (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 - (uc/color? (str/trim (get-in shape [:svg-attrs :style :fill]))) - (-> (update-in [:svg-attrs :style] dissoc :fill) - (update :svg-attrs dissoc :fill) - (assoc-in [:fills 0 :fill-color] (-> (get-in shape [:svg-attrs :style :fill]) - (str/trim) - (uc/parse-color)))) + (uc/color? color-style) + (-> (update-in [:svg-attrs :style] dissoc :fill) + (update :svg-attrs dissoc :fill) + (assoc-in [:fills 0 :fill-color] (uc/parse-color color-style))) - (get-in shape [:svg-attrs :fill-opacity]) - (-> (update :svg-attrs dissoc :fill-opacity) - (update-in [:svg-attrs :style] dissoc :fill-opacity) - (assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :fill-opacity]) - (d/parse-double)))) + (get-in shape [:svg-attrs :fill-opacity]) + (-> (update :svg-attrs dissoc :fill-opacity) + (update-in [:svg-attrs :style] dissoc :fill-opacity) + (assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :fill-opacity]) + (d/parse-double)))) - (get-in shape [:svg-attrs :style :fill-opacity]) - (-> (update-in [:svg-attrs :style] dissoc :fill-opacity) - (update :svg-attrs dissoc :fill-opacity) - (assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :style :fill-opacity]) - (d/parse-double)))))) + (get-in shape [:svg-attrs :style :fill-opacity]) + (-> (update-in [:svg-attrs :style] dissoc :fill-opacity) + (update :svg-attrs dissoc :fill-opacity) + (assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :style :fill-opacity]) + (d/parse-double))))))) (defn setup-stroke [shape] (let [stroke-linecap (-> (or (get-in shape [:svg-attrs :stroke-linecap])