0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-13 07:21:40 -05:00

🐛 Fix problem with flipped shapes

This commit is contained in:
alonso.torres 2022-12-30 13:50:37 +01:00
parent 5f77df1996
commit 32d39c35e4
5 changed files with 25 additions and 28 deletions

View file

@ -111,10 +111,10 @@
(cond-> (some? transform)
(gmt/multiply transform))
(cond-> (and flip-x (not no-flip))
(cond-> (and flip-x no-flip)
(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/translate (gpt/negate shape-center)))))
@ -126,8 +126,8 @@
([{:keys [transform flip-x flip-y] :as shape} {:keys [no-flip] :as params}]
(if (and (some? shape)
(or (some? transform)
(and (not no-flip) flip-x)
(and (not no-flip) flip-y)))
(and no-flip flip-x)
(and no-flip flip-y)))
(dm/str (transform-matrix shape params))
"")))

View file

@ -32,23 +32,6 @@
(d/update-when :position-data #(mapv update-color %))
(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/wrap-props false
::mf/wrap [mf/memo]}
@ -60,7 +43,7 @@
{: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
group-props (-> #js {:transform transform
@ -96,7 +79,6 @@
:y (- (:y data) (:height data))
:textLength (:width data)
:lengthAdjust "spacingAndGlyphs"
:transform (position-data-transform shape data)
:alignmentBaseline alignment-bl
:dominantBaseline dominant-bl
:style (-> #js {:fontFamily (:font-family data)

View file

@ -39,7 +39,7 @@
[:& text/text-shape {:shape 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)]
[:rect {
:x (:x bounding-box)

View file

@ -28,7 +28,7 @@
(some? 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]
[:rect.main.viewport-selrect

View file

@ -272,7 +272,7 @@
current-transform (mf/deref refs/current-transform)
selrect (:selrect shape)
transform (gsh/transform-str shape {:no-flip true})]
transform (gsh/transform-str shape)]
(when (not (#{:move :rotate} current-transform))
[:g.controls {:pointer-events (if disable-handlers "none" "visible")}
@ -297,7 +297,7 @@
workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)
selrect (:selrect shape)
transform (gsh/transform-matrix shape {:no-flip true})
transform (gsh/transform-matrix shape)
rotation (-> (gpt/point 1 0)
(gpt/transform (:transform shape))
@ -309,7 +309,22 @@
[:g.controls {:pointer-events (if disable-handlers "none" "visible")}
;; Handlers
(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
:position position
:on-rotate on-rotate