From 32d39c35e4fec74f718926f240182dffb4f02a3a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 30 Dec 2022 13:50:37 +0100 Subject: [PATCH] :bug: Fix problem with flipped shapes --- .../app/common/geom/shapes/transforms.cljc | 8 +++---- .../src/app/main/ui/shapes/text/svg_text.cljs | 20 +----------------- .../app/main/ui/workspace/shapes/text.cljs | 2 +- .../shapes/text/text_edition_outline.cljs | 2 +- .../main/ui/workspace/viewport/selection.cljs | 21 ++++++++++++++++--- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 4383d92bb..3d9852680 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -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)) ""))) diff --git a/frontend/src/app/main/ui/shapes/text/svg_text.cljs b/frontend/src/app/main/ui/shapes/text/svg_text.cljs index 6086efb9d..5e93ce855 100644 --- a/frontend/src/app/main/ui/shapes/text/svg_text.cljs +++ b/frontend/src/app/main/ui/shapes/text/svg_text.cljs @@ -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) diff --git a/frontend/src/app/main/ui/workspace/shapes/text.cljs b/frontend/src/app/main/ui/workspace/shapes/text.cljs index b51432b5b..39ae91b1c 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text.cljs @@ -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) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/text_edition_outline.cljs b/frontend/src/app/main/ui/workspace/shapes/text/text_edition_outline.cljs index aa4e29164..d7766d517 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/text_edition_outline.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/text_edition_outline.cljs @@ -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 diff --git a/frontend/src/app/main/ui/workspace/viewport/selection.cljs b/frontend/src/app/main/ui/workspace/viewport/selection.cljs index f4f829fc7..57fc23d8a 100644 --- a/frontend/src/app/main/ui/workspace/viewport/selection.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/selection.cljs @@ -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