mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 22:01:39 +02:00
Merge pull request #2813 from penpot/superalex-fix-svg-import
🐛 Fix svg import
This commit is contained in:
commit
b9b3fcdb6a
2 changed files with 20 additions and 18 deletions
|
@ -81,13 +81,13 @@
|
||||||
color-style (str/trim (get-in shape [:svg-attrs :style :fill]))
|
color-style (str/trim (get-in shape [:svg-attrs :style :fill]))
|
||||||
color-style (if (= color-style "currentColor") clr/black color-style)]
|
color-style (if (= color-style "currentColor") clr/black color-style)]
|
||||||
(cond-> shape
|
(cond-> shape
|
||||||
;; Color present as attribute
|
;; Color present as attribute
|
||||||
(uc/color? color-attr)
|
(uc/color? color-attr)
|
||||||
(-> (update :svg-attrs dissoc :fill)
|
(-> (update :svg-attrs dissoc :fill)
|
||||||
(update-in [:svg-attrs :style] dissoc :fill)
|
(update-in [:svg-attrs :style] dissoc :fill)
|
||||||
(assoc-in [:fills 0 :fill-color] (uc/parse-color color-attr)))
|
(assoc-in [:fills 0 :fill-color] (uc/parse-color color-attr)))
|
||||||
|
|
||||||
;; Color present as style
|
;; Color present as style
|
||||||
(uc/color? color-style)
|
(uc/color? color-style)
|
||||||
(-> (update-in [:svg-attrs :style] dissoc :fill)
|
(-> (update-in [:svg-attrs :style] dissoc :fill)
|
||||||
(update :svg-attrs dissoc :fill)
|
(update :svg-attrs dissoc :fill)
|
||||||
|
@ -110,20 +110,22 @@
|
||||||
(get-in shape [:svg-attrs :style :stroke-linecap]))
|
(get-in shape [:svg-attrs :style :stroke-linecap]))
|
||||||
((d/nilf str/trim))
|
((d/nilf str/trim))
|
||||||
((d/nilf keyword)))
|
((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
|
shape
|
||||||
(cond-> 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)
|
(-> (update :svg-attrs dissoc :stroke)
|
||||||
(assoc-in [:strokes 0 :stroke-color] (-> (get-in shape [:svg-attrs :stroke])
|
(assoc-in [:strokes 0 :stroke-color] (uc/parse-color color-attr)))
|
||||||
(str/trim)
|
|
||||||
(uc/parse-color))))
|
|
||||||
|
|
||||||
(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)
|
(-> (update-in [:svg-attrs :style] dissoc :stroke)
|
||||||
(assoc-in [:strokes 0 :stroke-color] (-> (get-in shape [:svg-attrs :style :stroke])
|
(assoc-in [:strokes 0 :stroke-color] (uc/parse-color color-style)))
|
||||||
(str/trim)
|
|
||||||
(uc/parse-color))))
|
|
||||||
|
|
||||||
(get-in shape [:svg-attrs :stroke-opacity])
|
(get-in shape [:svg-attrs :stroke-opacity])
|
||||||
(-> (update :svg-attrs dissoc :stroke-opacity)
|
(-> (update :svg-attrs dissoc :stroke-opacity)
|
||||||
|
@ -133,7 +135,7 @@
|
||||||
(get-in shape [:svg-attrs :style :stroke-opacity])
|
(get-in shape [:svg-attrs :style :stroke-opacity])
|
||||||
(-> (update-in [:svg-attrs :style] dissoc :stroke-opacity)
|
(-> (update-in [:svg-attrs :style] dissoc :stroke-opacity)
|
||||||
(assoc-in [:strokes 0 :stroke-opacity] (-> (get-in shape [:svg-attrs :style :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])
|
(get-in shape [:svg-attrs :stroke-width])
|
||||||
(-> (update :svg-attrs dissoc :stroke-width)
|
(-> (update :svg-attrs dissoc :stroke-width)
|
||||||
|
@ -516,12 +518,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
|
;; 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
|
base-background-shape {:tag :rect
|
||||||
:attrs {:x "0"
|
:attrs {:x (str vb-x)
|
||||||
:y "0"
|
:y (str vb-y)
|
||||||
:width (str (:width root-shape))
|
:width (str vb-width)
|
||||||
:height (str (:height root-shape))
|
:height (str vb-height)
|
||||||
:fill "none"
|
:fill "none"
|
||||||
:id "base-background"}
|
:id "base-background"}
|
||||||
:hidden true
|
:hidden true
|
||||||
:content []}
|
:content []}
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@
|
||||||
(defn extract-svg-attrs
|
(defn extract-svg-attrs
|
||||||
[render-id svg-defs svg-attrs]
|
[render-id svg-defs svg-attrs]
|
||||||
(if (and (empty? svg-defs) (empty? svg-attrs))
|
(if (and (empty? svg-defs) (empty? svg-attrs))
|
||||||
[nil nil]
|
[{} {}]
|
||||||
(let [replace-id (fn [id]
|
(let [replace-id (fn [id]
|
||||||
(if (contains? svg-defs id)
|
(if (contains? svg-defs id)
|
||||||
(str render-id "-" id)
|
(str render-id "-" id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue