From 0ca7d074acbd6d2582dd0bf52351c6c4ead995dc Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 7 Oct 2021 15:53:19 +0200 Subject: [PATCH] :bug: Fix problem with lines and inside/outside stroke --- CHANGES.md | 1 + common/src/app/common/geom/shapes.cljc | 1 + common/src/app/common/geom/shapes/path.cljc | 11 +++++ .../src/app/main/ui/shapes/custom_stroke.cljs | 41 +++++++++++-------- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1da95403b..b894c6154 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,7 @@ - Fix stroke caps adjustments in relation with stroke size [Taiga #2123](https://tree.taiga.io/project/penpot/issue/2123) - Fix problem duplicating paths [Taiga #2147](https://tree.taiga.io/project/penpot/issue/2147) - Fix problem inheriting attributes from SVG root when importing [Taiga #2124](https://tree.taiga.io/project/penpot/issue/2124) +- Fix problem with lines and inside/outside stroke [Taiga #2146](https://tree.taiga.io/project/penpot/issue/2146) ### :arrow_up: Deps updates ### :boom: Breaking changes diff --git a/common/src/app/common/geom/shapes.cljc b/common/src/app/common/geom/shapes.cljc index 30b3cb357..86cd32d81 100644 --- a/common/src/app/common/geom/shapes.cljc +++ b/common/src/app/common/geom/shapes.cljc @@ -160,6 +160,7 @@ ;; PATHS (d/export gsp/content->selrect) (d/export gsp/transform-content) +(d/export gsp/open-path?) ;; Intersection (d/export gin/overlaps?) diff --git a/common/src/app/common/geom/shapes/path.cljc b/common/src/app/common/geom/shapes/path.cljc index b50a4ba76..ed6724904 100644 --- a/common/src/app/common/geom/shapes/path.cljc +++ b/common/src/app/common/geom/shapes/path.cljc @@ -948,3 +948,14 @@ (gsc/transform-points points-center transform-inverse) (gpr/points->selrect))] [points selrect])) + + +(defn open-path? + [shape] + + (and (= :path (:type shape)) + (not (->> shape + :content + (sp/close-subpaths) + (sp/get-subpaths) + (every? sp/is-closed?))))) diff --git a/frontend/src/app/main/ui/shapes/custom_stroke.cljs b/frontend/src/app/main/ui/shapes/custom_stroke.cljs index 1ce51046d..619e9954e 100644 --- a/frontend/src/app/main/ui/shapes/custom_stroke.cljs +++ b/frontend/src/app/main/ui/shapes/custom_stroke.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.shapes.custom-stroke (:require [app.common.data :as d] + [app.common.geom.shapes :as gsh] [app.main.ui.context :as muc] [app.util.object :as obj] [cuerdas.core :as str] @@ -145,22 +146,24 @@ (mf/defc stroke-defs [{:keys [shape render-id]}] - (cond - (and (= :inner (:stroke-alignment shape :center)) - (> (:stroke-width shape 0) 0)) - [:& inner-stroke-clip-path {:shape shape - :render-id render-id}] + (when (and (= (:type shape) :path) + (gsh/open-path? shape)) + (cond + (and (= :inner (:stroke-alignment shape :center)) + (> (:stroke-width shape 0) 0)) + [:& inner-stroke-clip-path {:shape shape + :render-id render-id}] - (and (= :outer (:stroke-alignment shape :center)) - (> (:stroke-width shape 0) 0)) - [:& outer-stroke-mask {:shape shape - :render-id render-id}] + (and (= :outer (:stroke-alignment shape :center)) + (> (:stroke-width shape 0) 0)) + [:& outer-stroke-mask {:shape shape + :render-id render-id}] - (and (or (some? (:stroke-cap-start shape)) - (some? (:stroke-cap-end shape))) - (= (:stroke-alignment shape) :center)) - [:& cap-markers {:shape shape - :render-id render-id}])) + (and (or (some? (:stroke-cap-start shape)) + (some? (:stroke-cap-end shape))) + (= (:stroke-alignment shape) :center)) + [:& cap-markers {:shape shape + :render-id render-id}]))) ;; Outer alingmnent: display the shape in two layers. One ;; without stroke (only fill), and another one only with stroke @@ -253,15 +256,17 @@ stroke-position (:stroke-alignment shape :center) has-stroke? (and (> stroke-width 0) (not= stroke-style :none)) - inner? (= :inner stroke-position) - outer? (= :outer stroke-position)] + closed? (or (not= :path (:type shape)) + (not (gsh/open-path? shape))) + inner? (= :inner stroke-position) + outer? (= :outer stroke-position)] (cond - (and has-stroke? inner?) + (and has-stroke? inner? closed?) [:& inner-stroke {:shape shape} child] - (and has-stroke? outer?) + (and has-stroke? outer? closed?) [:& outer-stroke {:shape shape} child]