From 1b6e6ec2e4f36d4a8c06e002bf2077b9996a48a5 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 30 Aug 2021 16:47:57 +0200 Subject: [PATCH] :bug: Fix problem with borders on shape export --- CHANGES.md | 1 + frontend/src/app/main/ui/render.cljs | 11 ++++++--- frontend/src/app/main/ui/shapes/filters.cljs | 25 ++++++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ec9e3403a..75cffe960 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,7 @@ - Prevent adding numeric suffix to layer names when not needed [Taiga #1929](https://tree.taiga.io/project/penpot/us/1929). - Prevent deleting or moving the drafts project [Taiga #1935](https://tree.taiga.io/project/penpot/issue/1935). - Fix problem with zoom and selection [Taiga #1919](https://tree.taiga.io/project/penpot/issue/1919) +- Fix problem with borders on shape export [#1092](https://github.com/penpot/penpot/issues/1092) ### :arrow_up: Deps updates ### :boom: Breaking changes diff --git a/frontend/src/app/main/ui/render.cljs b/frontend/src/app/main/ui/render.cljs index 62b70f079..a8db5400e 100644 --- a/frontend/src/app/main/ui/render.cljs +++ b/frontend/src/app/main/ui/render.cljs @@ -55,7 +55,12 @@ width (* width zoom) height (* height zoom) - vbox (str/join " " [x y width height]) + padding (* (filters/calculate-padding object) zoom) + + vbox (str/join " " [(- x padding) + (- y padding) + (+ width padding padding) + (+ height padding padding)]) frame-wrapper (mf/use-memo @@ -81,8 +86,8 @@ [:& (mf/provider embed/context) {:value true} [:svg {:id "screenshot" :view-box vbox - :width width - :height height + :width (+ width padding padding) + :height (+ height padding padding) :version "1.1" :xmlns "http://www.w3.org/2000/svg" :xmlnsXlink "http://www.w3.org/1999/xlink" diff --git a/frontend/src/app/main/ui/shapes/filters.cljs b/frontend/src/app/main/ui/shapes/filters.cljs index c2664d695..25af34796 100644 --- a/frontend/src/app/main/ui/shapes/filters.cljs +++ b/frontend/src/app/main/ui/shapes/filters.cljs @@ -201,6 +201,19 @@ :width (- x2 x1) :height (- y2 y1)}))))) +(defn calculate-padding [shape] + (let [{:keys [stroke-style stroke-alignment stroke-width]} shape] + (cond + (and (not= stroke-style :none) + (= stroke-alignment :outer)) + stroke-width + + (and (not= stroke-style :none) + (= stroke-alignment :center)) + (mth/ceil (/ stroke-width 2)) + + :else 0))) + (mf/defc filters [{:keys [filter-id shape]}] @@ -209,15 +222,17 @@ ;; Adds the previous filter as `filter-in` parameter filters (map #(assoc %1 :filter-in %2) filters (cons nil (map :id filters))) - bounds (get-filters-bounds shape filters (or (-> shape :blur :value) 0))] + bounds (get-filters-bounds shape filters (or (-> shape :blur :value) 0)) + + padding (calculate-padding shape)] [:* (when (> (count filters) 2) [:filter {:id filter-id - :x (:x bounds) - :y (:y bounds) - :width (:width bounds) - :height (:height bounds) + :x (- (:x bounds) padding) + :y (- (:y bounds) padding) + :width (+ (:width bounds) (* 2 padding)) + :height (+ (:height bounds) (* 2 padding)) :filterUnits "userSpaceOnUse" :color-interpolation-filters "sRGB"}