💄 Unify source code style of repair functions

This commit is contained in:
Andrés Moya 2024-01-23 14:30:06 +01:00 committed by Andrey Antukh
parent c679b04ad5
commit 02cb75209c

View file

@ -138,33 +138,38 @@
fix-missing-image-metadata fix-missing-image-metadata
(fn [file-data] (fn [file-data]
(let [update-object ;; Delete broken image shapes with no metadata.
(fn [objects id shape] (letfn [(fix-container
[container]
(d/update-when container :objects #(reduce-kv fix-shape % %)))
(fix-shape
[objects id shape]
(if (and (cfh/image-shape? shape) (if (and (cfh/image-shape? shape)
(nil? (:metadata shape))) (nil? (:metadata shape)))
(-> objects (-> objects
(dissoc id) (dissoc id)
(d/update-in-when [(:parent-id shape) :shapes] (d/update-in-when [(:parent-id shape) :shapes]
(fn [shapes] (filterv #(not= id %) shapes)))) (fn [shapes] (filterv #(not= id %) shapes))))
objects)) objects))]
update-page
(fn [page]
(d/update-when page :objects #(reduce-kv update-object % %)))]
(-> file-data (-> file-data
(update :pages-index update-vals update-page) (update :pages-index update-vals fix-container)
(d/update-when :components update-vals update-page)))) (d/update-when :components update-vals fix-container))))
delete-big-geometry-shapes
(fn [file-data]
;; At some point in time, we had a bug that generated shapes ;; At some point in time, we had a bug that generated shapes
;; with huge geometries that did not validate the ;; with huge geometries that did not validate the
;; schema. Since we don't have a way to fix those shapes, we ;; schema. Since we don't have a way to fix those shapes, we
;; simply proceed to delete it. We ignore path type shapes ;; simply proceed to delete it. We ignore path type shapes
;; because they have not been affected by the bug. ;; because they have not been affected by the bug.
fix-big-invalid-shapes (letfn [(fix-container
(fn [file-data] [container]
(let [update-object (d/update-when container :objects #(reduce-kv fix-shape % %)))
(fn [objects id shape]
(fix-shape
[objects id shape]
(cond (cond
(or (cfh/path-shape? shape) (or (cfh/path-shape? shape)
(cfh/bool-shape? shape)) (cfh/bool-shape? shape))
@ -180,24 +185,22 @@
(fn [shapes] (filterv #(not= id %) shapes)))) (fn [shapes] (filterv #(not= id %) shapes))))
:else :else
objects)) objects))]
update-page
(fn [page]
(d/update-when page :objects #(reduce-kv update-object % %)))]
(-> file-data (-> file-data
(update :pages-index update-vals update-page) (update :pages-index update-vals fix-container)
(d/update-when :components update-vals update-page)))) (d/update-when :components update-vals fix-container))))
fix-misc-shape-issues fix-misc-shape-issues
(fn [file-data] (fn [file-data]
;; Find shapes that are not listed in their parent's children list. (letfn [(fix-container
;; Remove them, and also their children [container]
(let [update-shape (d/update-when container :objects update-vals fix-shape))
(fn [shape]
(fix-shape
[shape]
(cond-> shape (cond-> shape
;; Some shapes has invalid value there ;; Some shapes has invalid gap value
(contains? shape :layout-gap) (contains? shape :layout-gap)
(d/update-in-when [:layout-gap :column-gap] (d/update-in-when [:layout-gap :column-gap]
(fn [gap] (fn [gap]
@ -221,18 +224,15 @@
(number? (:layout-gap shape)) (number? (:layout-gap shape))
(as-> shape (let [n (:layout-gap shape)] (as-> shape (let [n (:layout-gap shape)]
(assoc shape :layout-gap {:row-gap n :column-gap n}))))) (assoc shape :layout-gap {:row-gap n :column-gap n})))))]
update-container
(fn [container]
(d/update-when container :objects update-vals update-shape))]
(-> file-data (-> file-data
(update :pages-index update-vals update-container) (update :pages-index update-vals fix-container)
(d/update-when :components update-vals update-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
(d/update-when file-data :recent-colors (d/update-when file-data :recent-colors
(fn [colors] (fn [colors]
(filterv valid-color? colors)))) (filterv valid-color? colors))))
@ -489,7 +489,7 @@
(fix-misc-shape-issues) (fix-misc-shape-issues)
(fix-recent-colors) (fix-recent-colors)
(fix-missing-image-metadata) (fix-missing-image-metadata)
(fix-big-invalid-shapes) (delete-big-geometry-shapes)
(fix-orphan-shapes) (fix-orphan-shapes)
(fix-orphan-copies) (fix-orphan-copies)
(remove-nested-roots) (remove-nested-roots)