From 94405ab72d97c38eee2d629595d71a52dd45ffd0 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 16 Feb 2021 11:46:39 +0100 Subject: [PATCH 1/5] :bug: Fixed problem with transform matrices --- common/app/common/geom/point.cljc | 5 ++++ common/app/common/geom/shapes/transforms.cljc | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/common/app/common/geom/point.cljc b/common/app/common/geom/point.cljc index 1217260c3..f55c2e37c 100644 --- a/common/app/common/geom/point.cljc +++ b/common/app/common/geom/point.cljc @@ -246,6 +246,11 @@ dist (distance line-point2 line-point1)] (/ num dist))) +(defn almost-zero? [{:keys [x y] :as p}] + (assert (point? p)) + (and (mth/almost-zero? x) + (mth/almost-zero? y))) + ;; --- Debug diff --git a/common/app/common/geom/shapes/transforms.cljc b/common/app/common/geom/shapes/transforms.cljc index 09f021d1e..269f781bb 100644 --- a/common/app/common/geom/shapes/transforms.cljc +++ b/common/app/common/geom/shapes/transforms.cljc @@ -130,7 +130,12 @@ [[p1 _ p3 p4]] (let [v1 (gpt/to-vec p3 p4) v2 (gpt/to-vec p4 p1)] - (- 90 (gpt/angle-with-other v1 v2)))) + ;; If one of the vectors is zero it's a rectangle with 0 height or width + ;; We don't skew these + (if (or (gpt/almost-zero? v1) + (gpt/almost-zero? v2)) + 0 + (- 90 (gpt/angle-with-other v1 v2))))) (defn- calculate-height "Calculates the height of a paralelogram given by the points" @@ -142,7 +147,7 @@ (defn- calculate-rotation "Calculates the rotation between two shapes given the resize vector direction" - [points-shape1 points-shape2 flip-x flip-y] + [center points-shape1 points-shape2 flip-x flip-y] (let [idx-1 0 idx-2 (cond (and flip-x (not flip-y)) 1 @@ -151,8 +156,8 @@ :else 0) p1 (nth points-shape1 idx-1) p2 (nth points-shape2 idx-2) - v1 (gpt/to-vec (gco/center-points points-shape1) p1) - v2 (gpt/to-vec (gco/center-points points-shape2) p2) + v1 (gpt/to-vec center p1) + v2 (gpt/to-vec center p2) rot-angle (gpt/angle-with-other v1 v2) rot-sign (if (> (* (:y v1) (:x v2)) (* (:x v1) (:y v2))) -1 1)] @@ -183,14 +188,15 @@ stretch-matrix (gmt/multiply stretch-matrix (gmt/skew-matrix skew-angle 0)) - h1 (calculate-height points-temp) - h2 (calculate-height (transform-points points-rec center stretch-matrix)) + h1 (max 1 (calculate-height points-temp)) + h2 (max 1 (calculate-height (transform-points points-rec center stretch-matrix))) h3 (if-not (mth/almost-zero? h2) (/ h1 h2) 1) h3 (if (mth/nan? h3) 1 h3) stretch-matrix (gmt/multiply stretch-matrix (gmt/scale-matrix (gpt/point 1 h3))) rotation-angle (calculate-rotation + center (transform-points points-rec (gco/center-points points-rec) stretch-matrix) points-temp flip-x @@ -222,9 +228,13 @@ ;; This rectangle is the new data for the current rectangle. We want to change our rectangle ;; to have this width, height, x, y - rect-shape (gco/make-centered-rect center - (:width points-temp-dim) - (:height points-temp-dim)) + rect-shape (-> (gco/make-centered-rect + center + (:width points-temp-dim) + (:height points-temp-dim)) + (update :width max 1) + (update :height max 1)) + rect-points (gpr/rect->points rect-shape) [matrix matrix-inverse] (calculate-adjust-matrix points-temp rect-points (:flip-x shape) (:flip-y shape)) From 043c038dae53cedfb2abf7dfaa72558ee124c961 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 17 Feb 2021 09:45:19 +0100 Subject: [PATCH 2/5] :bug: Fix radial gradients --- frontend/src/app/main/ui/shapes/gradients.cljs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/shapes/gradients.cljs b/frontend/src/app/main/ui/shapes/gradients.cljs index cd8ab02e0..c9df9e474 100644 --- a/frontend/src/app/main/ui/shapes/gradients.cljs +++ b/frontend/src/app/main/ui/shapes/gradients.cljs @@ -36,7 +36,9 @@ (mf/defc radial-gradient [{:keys [id gradient shape]}] (let [{:keys [x y width height]} (:selrect shape) center (gsh/center-shape shape) - transform (when (= :path (:type shape)) (gsh/transform-matrix shape))] + transform (if (= :path (:type shape)) + (gsh/transform-matrix shape) + (gmt/matrix))] (let [[x y] (if (= (:type shape) :frame) [0 0] [x y]) translate-vec (gpt/point (+ x (* width (:start-x gradient))) (+ y (* height (:start-y gradient)))) From 803caf65312ec62ebad211c6cfea5859184cdf90 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 17 Feb 2021 13:37:53 +0100 Subject: [PATCH 3/5] :bug: Fixes problem with chinese inputs --- frontend/src/app/main/ui/workspace/shapes/text/editor.cljs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs index d279c16fa..c62865146 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs @@ -222,6 +222,11 @@ (fn [event] (dwt/editor-select-all! editor)) + on-composition-start + (mf/use-callback + (fn [] + (.insertText slate/Editor editor ""))) + on-change (mf/use-callback (fn [val] @@ -263,6 +268,7 @@ (dom/stop-propagation event) ;; WARN: monky patch (obj/set! slate/Transforms "deselect" (constantly nil))) + :on-composition-start on-composition-start :placeholder (when (= :fixed grow-type) "Type some text here...")}]]])) (mf/defc text-shape-edit From 471cad3ae95681c5b0ebdaa467e6474d5d07c63c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 19 Feb 2021 10:53:41 +0100 Subject: [PATCH 4/5] :bug: Disable placeholders on text editor. Causes crash on use IME. --- frontend/src/app/main/ui/workspace/shapes/text/editor.cljs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs index c62865146..961d800e2 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs @@ -224,7 +224,7 @@ on-composition-start (mf/use-callback - (fn [] + (fn [event] (.insertText slate/Editor editor ""))) on-change @@ -269,7 +269,8 @@ ;; WARN: monky patch (obj/set! slate/Transforms "deselect" (constantly nil))) :on-composition-start on-composition-start - :placeholder (when (= :fixed grow-type) "Type some text here...")}]]])) + ;; :placeholder (when (= :fixed grow-type) "Type some text here...") + }]]])) (mf/defc text-shape-edit {::mf/wrap [mf/memo] From 55b1417df8ca6b79b8d432998493f42c24c5ec56 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 19 Feb 2021 11:33:43 +0100 Subject: [PATCH 5/5] :bug: Fixes problems with new paths --- frontend/src/app/main/data/workspace/drawing/path.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/data/workspace/drawing/path.cljs b/frontend/src/app/main/data/workspace/drawing/path.cljs index c73014f1e..a1f2a4a29 100644 --- a/frontend/src/app/main/data/workspace/drawing/path.cljs +++ b/frontend/src/app/main/data/workspace/drawing/path.cljs @@ -90,8 +90,8 @@ path))) (defn- points->components [shape content] - (let [transform (:transform shape) - transform-inverse (:transform-inverse shape) + (let [transform (:transform shape (gmt/matrix)) + transform-inverse (:transform-inverse shape (gmt/matrix)) center (gsh/center-shape shape) base-content (gsh/transform-content content