🐛 Fix text shapes wrongly converted to path in comp-v2 migration

This commit is contained in:
Andrey Antukh 2024-01-25 11:55:06 +01:00
parent 66c07e1336
commit df4be5106b

View file

@ -33,6 +33,7 @@
[app.common.types.pages-list :as ctpl] [app.common.types.pages-list :as ctpl]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
[app.common.types.shape.text :as ctsx]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.db :as db] [app.db :as db]
[app.db.sql :as sql] [app.db.sql :as sql]
@ -106,6 +107,9 @@
(def valid-stroke? (sm/lazy-validator ::cts/stroke)) (def valid-stroke? (sm/lazy-validator ::cts/stroke))
(def valid-flow? (sm/lazy-validator ::ctp/flow)) (def valid-flow? (sm/lazy-validator ::ctp/flow))
(def valid-text-content?
(sm/lazy-validator ::ctsx/content))
(defn- prepare-file-data (defn- prepare-file-data
"Apply some specific migrations or fixes to things that are allowed in v1 but not in v2, "Apply some specific migrations or fixes to things that are allowed in v1 but not in v2,
or that are the result of old bugs." or that are the result of old bugs."
@ -241,6 +245,32 @@
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(d/update-when :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
;; There are some bugs in the past that allows convert text to
;; path and this fix tries to identify this cases and fix them converting
;; the shape back to text shape
fix-text-shapes-converted-to-path
(fn [file-data]
(letfn [(fix-container [container]
(d/update-when container :objects update-vals fix-shape))
(fix-shape [shape]
(if (and (cfh/path-shape? shape)
(contains? shape :content)
(some? (:selrect shape))
(valid-text-content? (:content shape)))
(let [selrect (:selrect shape)]
(-> shape
(assoc :x (:x selrect))
(assoc :y (:y selrect))
(assoc :width (:width selrect))
(assoc :height (:height selrect))
(assoc :type :text)))
shape))]
(-> file-data
(update :pages-index update-vals fix-container)
(d/update-when :components update-vals fix-container))))
fix-recent-colors fix-recent-colors
(fn [file-data] (fn [file-data]
;; Remove invalid colors in :recent-colors ;; Remove invalid colors in :recent-colors
@ -531,6 +561,7 @@
(fix-misc-shape-issues) (fix-misc-shape-issues)
(fix-recent-colors) (fix-recent-colors)
(fix-missing-image-metadata) (fix-missing-image-metadata)
(fix-text-shapes-converted-to-path)
(delete-big-geometry-shapes) (delete-big-geometry-shapes)
(fix-broken-parents) (fix-broken-parents)
(fix-orphan-shapes) (fix-orphan-shapes)