mirror of
https://github.com/penpot/penpot.git
synced 2025-06-08 14:01:38 +02:00
🐛 Fix problem with flipped shapes
This commit is contained in:
parent
5f77df1996
commit
32d39c35e4
5 changed files with 25 additions and 28 deletions
|
@ -111,10 +111,10 @@
|
||||||
(cond-> (some? transform)
|
(cond-> (some? transform)
|
||||||
(gmt/multiply transform))
|
(gmt/multiply transform))
|
||||||
|
|
||||||
(cond-> (and flip-x (not no-flip))
|
(cond-> (and flip-x no-flip)
|
||||||
(gmt/scale (gpt/point -1 1)))
|
(gmt/scale (gpt/point -1 1)))
|
||||||
|
|
||||||
(cond-> (and flip-y (not no-flip))
|
(cond-> (and flip-y no-flip)
|
||||||
(gmt/scale (gpt/point 1 -1)))
|
(gmt/scale (gpt/point 1 -1)))
|
||||||
|
|
||||||
(gmt/translate (gpt/negate shape-center)))))
|
(gmt/translate (gpt/negate shape-center)))))
|
||||||
|
@ -126,8 +126,8 @@
|
||||||
([{:keys [transform flip-x flip-y] :as shape} {:keys [no-flip] :as params}]
|
([{:keys [transform flip-x flip-y] :as shape} {:keys [no-flip] :as params}]
|
||||||
(if (and (some? shape)
|
(if (and (some? shape)
|
||||||
(or (some? transform)
|
(or (some? transform)
|
||||||
(and (not no-flip) flip-x)
|
(and no-flip flip-x)
|
||||||
(and (not no-flip) flip-y)))
|
(and no-flip flip-y)))
|
||||||
(dm/str (transform-matrix shape params))
|
(dm/str (transform-matrix shape params))
|
||||||
"")))
|
"")))
|
||||||
|
|
||||||
|
|
|
@ -32,23 +32,6 @@
|
||||||
(d/update-when :position-data #(mapv update-color %))
|
(d/update-when :position-data #(mapv update-color %))
|
||||||
(assoc :stroke-color "#FFFFFF" :stroke-opacity 1))))
|
(assoc :stroke-color "#FFFFFF" :stroke-opacity 1))))
|
||||||
|
|
||||||
(defn position-data-transform
|
|
||||||
[shape {:keys [x y width height]}]
|
|
||||||
(let [rect (gsh/make-rect x (- y height) width height)
|
|
||||||
center (gsh/center-rect rect)]
|
|
||||||
(when (or (:flip-x shape) (:flip-y shape))
|
|
||||||
(-> (gmt/matrix)
|
|
||||||
(gmt/translate center)
|
|
||||||
|
|
||||||
(cond-> (:flip-x shape)
|
|
||||||
(gmt/scale (gpt/point -1 1))
|
|
||||||
|
|
||||||
(:flip-y shape)
|
|
||||||
(gmt/scale (gpt/point 1 -1)))
|
|
||||||
|
|
||||||
(gmt/translate (gpt/negate center))
|
|
||||||
(dm/str)))))
|
|
||||||
|
|
||||||
(mf/defc text-shape
|
(mf/defc text-shape
|
||||||
{::mf/wrap-props false
|
{::mf/wrap-props false
|
||||||
::mf/wrap [mf/memo]}
|
::mf/wrap [mf/memo]}
|
||||||
|
@ -60,7 +43,7 @@
|
||||||
|
|
||||||
{:keys [x y width height position-data]} shape
|
{:keys [x y width height position-data]} shape
|
||||||
|
|
||||||
transform (gsh/transform-str shape {:no-flip true})
|
transform (gsh/transform-str shape)
|
||||||
|
|
||||||
;; These position attributes are not really necessary but they are convenient for for the export
|
;; These position attributes are not really necessary but they are convenient for for the export
|
||||||
group-props (-> #js {:transform transform
|
group-props (-> #js {:transform transform
|
||||||
|
@ -96,7 +79,6 @@
|
||||||
:y (- (:y data) (:height data))
|
:y (- (:y data) (:height data))
|
||||||
:textLength (:width data)
|
:textLength (:width data)
|
||||||
:lengthAdjust "spacingAndGlyphs"
|
:lengthAdjust "spacingAndGlyphs"
|
||||||
:transform (position-data-transform shape data)
|
|
||||||
:alignmentBaseline alignment-bl
|
:alignmentBaseline alignment-bl
|
||||||
:dominantBaseline dominant-bl
|
:dominantBaseline dominant-bl
|
||||||
:style (-> #js {:fontFamily (:font-family data)
|
:style (-> #js {:fontFamily (:font-family data)
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
[:& text/text-shape {:shape shape}]]
|
[:& text/text-shape {:shape shape}]]
|
||||||
|
|
||||||
(when (and (debug? :text-outline) (d/not-empty? (:position-data shape)))
|
(when (and (debug? :text-outline) (d/not-empty? (:position-data shape)))
|
||||||
[:g {:transform (gsh/transform-str shape {:no-flip true})}
|
[:g {:transform (gsh/transform-str shape)}
|
||||||
(let [bounding-box (gsht/position-data-selrect shape)]
|
(let [bounding-box (gsht/position-data-selrect shape)]
|
||||||
[:rect {
|
[:rect {
|
||||||
:x (:x bounding-box)
|
:x (:x bounding-box)
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
(some? text-modifier)
|
(some? text-modifier)
|
||||||
(dwt/apply-text-modifier text-modifier))
|
(dwt/apply-text-modifier text-modifier))
|
||||||
|
|
||||||
transform (gsh/transform-str shape {:no-flip true})
|
transform (gsh/transform-str shape)
|
||||||
{:keys [x y width height]} shape]
|
{:keys [x y width height]} shape]
|
||||||
|
|
||||||
[:rect.main.viewport-selrect
|
[:rect.main.viewport-selrect
|
||||||
|
|
|
@ -272,7 +272,7 @@
|
||||||
current-transform (mf/deref refs/current-transform)
|
current-transform (mf/deref refs/current-transform)
|
||||||
|
|
||||||
selrect (:selrect shape)
|
selrect (:selrect shape)
|
||||||
transform (gsh/transform-str shape {:no-flip true})]
|
transform (gsh/transform-str shape)]
|
||||||
|
|
||||||
(when (not (#{:move :rotate} current-transform))
|
(when (not (#{:move :rotate} current-transform))
|
||||||
[:g.controls {:pointer-events (if disable-handlers "none" "visible")}
|
[:g.controls {:pointer-events (if disable-handlers "none" "visible")}
|
||||||
|
@ -297,7 +297,7 @@
|
||||||
workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)
|
workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)
|
||||||
|
|
||||||
selrect (:selrect shape)
|
selrect (:selrect shape)
|
||||||
transform (gsh/transform-matrix shape {:no-flip true})
|
transform (gsh/transform-matrix shape)
|
||||||
|
|
||||||
rotation (-> (gpt/point 1 0)
|
rotation (-> (gpt/point 1 0)
|
||||||
(gpt/transform (:transform shape))
|
(gpt/transform (:transform shape))
|
||||||
|
@ -309,7 +309,22 @@
|
||||||
[:g.controls {:pointer-events (if disable-handlers "none" "visible")}
|
[:g.controls {:pointer-events (if disable-handlers "none" "visible")}
|
||||||
;; Handlers
|
;; Handlers
|
||||||
(for [{:keys [type position props]} (handlers-for-selection selrect shape zoom)]
|
(for [{:keys [type position props]} (handlers-for-selection selrect shape zoom)]
|
||||||
(let [common-props {:key (dm/str (name type) "-" (name position))
|
(let [rotation
|
||||||
|
(cond
|
||||||
|
(and (#{:top-left :bottom-right} position)
|
||||||
|
(or (and (:flip-x shape) (not (:flip-y shape)))
|
||||||
|
(and (:flip-y shape) (not (:flip-x shape)))))
|
||||||
|
(- rotation 90)
|
||||||
|
|
||||||
|
(and (#{:top-right :bottom-left} position)
|
||||||
|
(or (and (:flip-x shape) (not (:flip-y shape)))
|
||||||
|
(and (:flip-y shape) (not (:flip-x shape)))))
|
||||||
|
(+ rotation 90)
|
||||||
|
|
||||||
|
:else
|
||||||
|
rotation)
|
||||||
|
|
||||||
|
common-props {:key (dm/str (name type) "-" (name position))
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:position position
|
:position position
|
||||||
:on-rotate on-rotate
|
:on-rotate on-rotate
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue