🐛 Parse rx and ry SVG values correctly (#7176)

This commit is contained in:
Elena Torró
2025-08-25 10:44:11 +02:00
committed by GitHub
parent c3b326d95e
commit 3bb547fc45
2 changed files with 25 additions and 7 deletions

View File

@@ -9,6 +9,7 @@
### :heart: Community contributions (Thank you!)
### :sparkles: New features & Enhancements
- Add defaults for artboard drawing [Taiga #494](https://tree.taiga.io/project/penpot/us/494?milestone=465047)
- Continuous display of distances between elements when moving a layer with the keyboard [Taiga #1780](https://tree.taiga.io/project/penpot/us/1780)
- New Number token - unitless values [Taiga #10936](https://tree.taiga.io/project/penpot/us/10936)
@@ -28,6 +29,7 @@
- Fix font size/variant not updated when editing a text [Taiga #11552](https://tree.taiga.io/project/penpot/issue/11552)
- Fix issue where Alt + arrow keys shortcut interferes with letter-spacing when moving text layers [Taiga #11552](https://tree.taiga.io/project/penpot/issue/11771)
- Fix consistency issues on how font variants are visualized [Taiga #11499](https://tree.taiga.io/project/penpot/us/11499)
- Fix parsing rx and ry SVG values for rect radius [Taiga #11861](https://tree.taiga.io/project/penpot/issue/11861)
## 2.9.0 (Unreleased)

View File

@@ -269,6 +269,22 @@
(d/parse-double width 1)
(d/parse-double height 1)))
(defn- parse-radius-attrs
[attrs]
(if (or (contains? attrs :rx) (contains? attrs :ry))
(let [rx-val (d/parse-double (:rx attrs) 0)
ry-val (d/parse-double (:ry attrs) 0)
radius (cond
(and (contains? attrs :rx) (contains? attrs :ry))
(min rx-val ry-val)
(contains? attrs :rx)
rx-val
(contains? attrs :ry)
ry-val
:else 0)]
{:r1 radius :r2 radius :r3 radius :r4 radius})
{}))
(defn create-rect-shape [name frame-id svg-data {:keys [attrs] :as data}]
(let [transform (->> (csvg/parse-transform (:transform attrs))
(gmt/transform-in (gpt/point svg-data)))
@@ -280,7 +296,9 @@
(update :y - (:y origin)))
props (-> (dissoc attrs :x :y :width :height :rx :ry :transform)
(csvg/attrs->props))]
(csvg/attrs->props))
radius-attrs (parse-radius-attrs attrs)]
(cts/setup-shape
(-> (calculate-rect-metadata rect transform)
(assoc :type :rect)
@@ -288,13 +306,10 @@
(assoc :frame-id frame-id)
(assoc :svg-viewbox vbox)
(assoc :svg-attrs props)
;; We need to ensure fills are empty on import process
;; because setup-shape assings one by default.
;; We need to ensure fills are empty on import process
;; because setup-shape assings one by default.
(assoc :fills [])
(cond-> (contains? attrs :rx)
(assoc :rx (d/parse-double (:rx attrs) 0)))
(cond-> (contains? attrs :ry)
(assoc :ry (d/parse-double (:ry attrs) 0)))))))
(merge radius-attrs)))))
(defn- parse-circle-attrs
[attrs]
@@ -508,6 +523,7 @@
:else (dm/str tag))]
(dm/str "svg-" suffix)))
(defn parse-svg-element
[frame-id svg-data {:keys [tag attrs hidden] :as element} unames]