🐛 Fix problem with lines and inside/outside stroke

This commit is contained in:
alonso.torres 2021-10-07 15:53:19 +02:00
parent 65894bf582
commit 0ca7d074ac
4 changed files with 36 additions and 18 deletions

View file

@ -27,6 +27,7 @@
- Fix stroke caps adjustments in relation with stroke size [Taiga #2123](https://tree.taiga.io/project/penpot/issue/2123) - 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 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 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 ### :arrow_up: Deps updates
### :boom: Breaking changes ### :boom: Breaking changes

View file

@ -160,6 +160,7 @@
;; PATHS ;; PATHS
(d/export gsp/content->selrect) (d/export gsp/content->selrect)
(d/export gsp/transform-content) (d/export gsp/transform-content)
(d/export gsp/open-path?)
;; Intersection ;; Intersection
(d/export gin/overlaps?) (d/export gin/overlaps?)

View file

@ -948,3 +948,14 @@
(gsc/transform-points points-center transform-inverse) (gsc/transform-points points-center transform-inverse)
(gpr/points->selrect))] (gpr/points->selrect))]
[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?)))))

View file

@ -7,6 +7,7 @@
(ns app.main.ui.shapes.custom-stroke (ns app.main.ui.shapes.custom-stroke
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh]
[app.main.ui.context :as muc] [app.main.ui.context :as muc]
[app.util.object :as obj] [app.util.object :as obj]
[cuerdas.core :as str] [cuerdas.core :as str]
@ -145,22 +146,24 @@
(mf/defc stroke-defs (mf/defc stroke-defs
[{:keys [shape render-id]}] [{:keys [shape render-id]}]
(cond (when (and (= (:type shape) :path)
(and (= :inner (:stroke-alignment shape :center)) (gsh/open-path? shape))
(> (:stroke-width shape 0) 0)) (cond
[:& inner-stroke-clip-path {:shape shape (and (= :inner (:stroke-alignment shape :center))
:render-id render-id}] (> (:stroke-width shape 0) 0))
[:& inner-stroke-clip-path {:shape shape
:render-id render-id}]
(and (= :outer (:stroke-alignment shape :center)) (and (= :outer (:stroke-alignment shape :center))
(> (:stroke-width shape 0) 0)) (> (:stroke-width shape 0) 0))
[:& outer-stroke-mask {:shape shape [:& outer-stroke-mask {:shape shape
:render-id render-id}] :render-id render-id}]
(and (or (some? (:stroke-cap-start shape)) (and (or (some? (:stroke-cap-start shape))
(some? (:stroke-cap-end shape))) (some? (:stroke-cap-end shape)))
(= (:stroke-alignment shape) :center)) (= (:stroke-alignment shape) :center))
[:& cap-markers {:shape shape [:& cap-markers {:shape shape
:render-id render-id}])) :render-id render-id}])))
;; Outer alingmnent: display the shape in two layers. One ;; Outer alingmnent: display the shape in two layers. One
;; without stroke (only fill), and another one only with stroke ;; without stroke (only fill), and another one only with stroke
@ -253,15 +256,17 @@
stroke-position (:stroke-alignment shape :center) stroke-position (:stroke-alignment shape :center)
has-stroke? (and (> stroke-width 0) has-stroke? (and (> stroke-width 0)
(not= stroke-style :none)) (not= stroke-style :none))
inner? (= :inner stroke-position) closed? (or (not= :path (:type shape))
outer? (= :outer stroke-position)] (not (gsh/open-path? shape)))
inner? (= :inner stroke-position)
outer? (= :outer stroke-position)]
(cond (cond
(and has-stroke? inner?) (and has-stroke? inner? closed?)
[:& inner-stroke {:shape shape} [:& inner-stroke {:shape shape}
child] child]
(and has-stroke? outer?) (and has-stroke? outer? closed?)
[:& outer-stroke {:shape shape} [:& outer-stroke {:shape shape}
child] child]