0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-02 12:28:54 -05:00

🐛 Fix problem with strokes exporting images

This commit is contained in:
alonso.torres 2024-02-16 09:43:38 +01:00
parent 74e57c00af
commit 4c81ac4386
3 changed files with 45 additions and 43 deletions

View file

@ -15,8 +15,8 @@
(defn shape-stroke-margin (defn shape-stroke-margin
[shape stroke-width] [shape stroke-width]
(if (cfh/path-shape? shape) (if (cfh/path-shape? shape)
;; TODO: Calculate with the stroke offset (not implemented yet ;; TODO: Calculate with the stroke offset (not implemented yet)
(mth/sqrt (* 2 stroke-width stroke-width)) (+ stroke-width (mth/sqrt (* 2 stroke-width stroke-width)))
(- (mth/sqrt (* 2 stroke-width stroke-width)) stroke-width))) (- (mth/sqrt (* 2 stroke-width stroke-width)) stroke-width)))
(defn- apply-filters (defn- apply-filters
@ -104,7 +104,7 @@
0)) 0))
(reduce d/max 0)) (reduce d/max 0))
margin stroke-margin
(if ignore-margin? (if ignore-margin?
0 0
(shape-stroke-margin shape stroke-width)) (shape-stroke-margin shape stroke-width))
@ -124,9 +124,8 @@
:drop-shadow (+ (mth/abs (:offset-y %)) (* (:spread %) 2) (* (:blur %) 2) 10) :drop-shadow (+ (mth/abs (:offset-y %)) (* (:spread %) 2) (* (:blur %) 2) 10)
0)) 0))
(reduce d/max 0))] (reduce d/max 0))]
{:horizontal (mth/ceil (+ stroke-margin shadow-width))
{:horizontal (mth/ceil (+ stroke-width margin shadow-width)) :vertical (mth/ceil (+ stroke-margin shadow-height))})))
:vertical (mth/ceil (+ stroke-width margin shadow-height))})))
(defn- add-padding (defn- add-padding
[bounds padding] [bounds padding]
@ -143,13 +142,17 @@
(update :height + (* 2 v-padding))))) (update :height + (* 2 v-padding)))))
(defn calculate-base-bounds (defn calculate-base-bounds
[shape] ([shape]
(calculate-base-bounds shape true))
([shape ignore-margin?]
(-> (get-shape-filter-bounds shape) (-> (get-shape-filter-bounds shape)
(add-padding (calculate-padding shape true)))) (add-padding (calculate-padding shape ignore-margin?)))))
(defn get-object-bounds (defn get-object-bounds
[objects shape] ([objects shape]
(let [base-bounds (calculate-base-bounds shape) (get-object-bounds objects shape nil))
([objects shape {:keys [ignore-margin?] :or {ignore-margin? true}}]
(let [base-bounds (calculate-base-bounds shape ignore-margin?)
bounds bounds
(cond (cond
(or (empty? (:shapes shape)) (or (empty? (:shapes shape))
@ -185,5 +188,5 @@
filters (shape->filters shape) filters (shape->filters shape)
blur-value (or (-> shape :blur :value) 0)] blur-value (or (-> shape :blur :value) 0)]
(get-rect-filter-bounds children-bounds filters blur-value))) (get-rect-filter-bounds children-bounds filters blur-value))))

View file

@ -449,7 +449,7 @@
(assoc :fills [])) (assoc :fills []))
{:keys [width height] :as bounds} (gsb/get-object-bounds objects object) {:keys [width height] :as bounds} (gsb/get-object-bounds objects object {:ignore-margin? false})
vbox (format-viewbox bounds) vbox (format-viewbox bounds)
fonts (ff/shape->fonts object objects) fonts (ff/shape->fonts object objects)

View file

@ -13,6 +13,7 @@
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.bounds :as gsb] [app.common.geom.shapes.bounds :as gsb]
[app.common.geom.shapes.text :as gst] [app.common.geom.shapes.text :as gst]
[app.common.math :as mth]
[app.config :as cf] [app.config :as cf]
[app.main.ui.context :as muc] [app.main.ui.context :as muc]
[app.main.ui.shapes.attrs :as attrs] [app.main.ui.shapes.attrs :as attrs]
@ -47,7 +48,7 @@
:center (/ (:stroke-width stroke 0) 2) :center (/ (:stroke-width stroke 0) 2)
:outer (:stroke-width stroke 0) :outer (:stroke-width stroke 0)
0) 0)
margin (gsb/shape-stroke-margin stroke stroke-width) stroke-margin (gsb/shape-stroke-margin shape stroke-width)
;; NOTE: for performance reasons we may can delimit a bit the ;; NOTE: for performance reasons we may can delimit a bit the
;; dependencies to really useful shape attrs instead of using ;; dependencies to really useful shape attrs instead of using
@ -57,8 +58,6 @@
(gst/shape->rect shape) (gst/shape->rect shape)
(grc/points->rect (:points shape)))) (grc/points->rect (:points shape))))
stroke-margin (+ stroke-width margin)
x (- (dm/get-prop selrect :x) stroke-margin) x (- (dm/get-prop selrect :x) stroke-margin)
y (- (dm/get-prop selrect :y) stroke-margin) y (- (dm/get-prop selrect :y) stroke-margin)
w (+ (dm/get-prop selrect :width) (* 2 stroke-margin)) w (+ (dm/get-prop selrect :width) (* 2 stroke-margin))