From f393ce927359e7117c4479c276bb1d8b2f99b5fc Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 26 Jun 2024 19:46:29 +0200 Subject: [PATCH] :bug: Add migration for fix path shapes with invalid curve segment params --- common/src/app/common/files/defaults.cljc | 2 +- common/src/app/common/files/migrations.cljc | 51 ++++++++++++++++++++- common/src/app/common/svg.cljc | 1 - frontend/src/app/util/path/format.cljs | 2 + 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/files/defaults.cljc b/common/src/app/common/files/defaults.cljc index 91acf6539..0a2d031db 100644 --- a/common/src/app/common/files/defaults.cljc +++ b/common/src/app/common/files/defaults.cljc @@ -6,4 +6,4 @@ (ns app.common.files.defaults) -(def version 49) +(def version 50) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 434630977..528345a6c 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -957,6 +957,54 @@ (update data :pages-index update-vals update-page))) +(defn migrate-up-50 + "This migration mainly fixes paths with curve-to segments + without :c1x :c1y :c2x :c2y properties. Additionally, we found a + case where the params instead to be plain hash-map, is a points + instance. This migration normalizes all params to plain map." + + [data] + (let [update-segment + (fn [{:keys [command params] :as segment}] + (let [params (into {} params) + params (cond + (= :curve-to command) + (let [x (get params :x) + y (get params :y)] + + (cond-> params + (nil? (:c1x params)) + (assoc :c1x x) + + (nil? (:c1y params)) + (assoc :c1y y) + + (nil? (:c2x params)) + (assoc :c2x x) + + (nil? (:c2y params)) + (assoc :c2y y))) + + :else + params)] + + (assoc segment :params params))) + + update-shape + (fn [shape] + (if (cfh/path-shape? shape) + (d/update-when shape :content (fn [content] (mapv update-segment content))) + shape)) + + update-container + (fn [page] + (d/update-when page :objects update-vals update-shape))] + + (-> data + (update :pages-index update-vals update-container) + (update :components update-vals update-container)))) + + (def migrations "A vector of all applicable migrations" [{:id 2 :migrate-up migrate-up-2} @@ -997,4 +1045,5 @@ {:id 46 :migrate-up migrate-up-46} {:id 47 :migrate-up migrate-up-47} {:id 48 :migrate-up migrate-up-48} - {:id 49 :migrate-up migrate-up-49}]) + {:id 49 :migrate-up migrate-up-49} + {:id 50 :migrate-up migrate-up-50}]) diff --git a/common/src/app/common/svg.cljc b/common/src/app/common/svg.cljc index 1b50a9dde..4b9f71572 100644 --- a/common/src/app/common/svg.cljc +++ b/common/src/app/common/svg.cljc @@ -1046,7 +1046,6 @@ (str/includes? data "]*>" ""))) - (defn parse [text] #?(:cljs (tubax/xml->clj text) diff --git a/frontend/src/app/util/path/format.cljs b/frontend/src/app/util/path/format.cljs index 5a5860341..b120ff4d3 100644 --- a/frontend/src/app/util/path/format.cljs +++ b/frontend/src/app/util/path/format.cljs @@ -10,6 +10,8 @@ [app.common.svg.path.subpath :refer [pt=]] [app.util.array :as arr])) +;; TODO: move to common + (def path-precision 3) (defn- join-params