mirror of
https://github.com/penpot/penpot.git
synced 2026-11-25 12:22:29 +00:00
On the WebGL renderer, a sync re-measure of copies shared a 40 ms batch with user resizes of the main text. The batch skipped the component sync when any request asked for that. So a resize of the main (grow type, font size, paste, search and replace) often never reached copies on other pages or in other files, and the viewer and exports showed the old size. A batch now skips the sync only when every request asks for it, the same rule as :save-undo?. Such an edit costs one extra short sync round. That round holds only skip requests, so it stops after one pass. A copy that the sync switched from fixed to auto-grow was never re-measured, because the check read the grow type before the sync. The check now reads the grow type that the change sets. A copy that the sync makes fixed is not re-measured. A sync started without an undo group (library update dialog, color and typography sync) committed with a fresh group, and its re-measure and layout pass took other ones. Ctrl+Z first undid only the re-measure and left the copies in the old box. The sync now picks its group when it runs: inside an undo transaction (color, typography and asset deletes) it takes the transaction's, otherwise a fresh one. The re-measure and layout pass share it, so one undo reverts the edit, the sync and its follow-ups, and a failed save rolls them back together. On the SVG renderer, opening a page resized a copy with no position data even when its size had not drifted. Measured sizes round up, so 17.4 became 18. The measurement from that resize then landed on the user's last undo entry. The heal now reports whether it resized, and the check phase resizes only when the size drifted. The SVG page-open check covered only texts with overridden content. A copy loses its touched flags, so a label overridden inside a main (a Button label in a Card main) was never checked in the main's copies, and its heal skips the component sync. The check now covers every auto-grow text inside a copy, as the WebGL check does. The heal's reflow now skips the component sync too: without undo it touched the main component on every page open. A page-open check measured with a font that failed to load wrote the fallback font size. It now writes no size then; a copy without position data still gets it. The WebGL and SVG renderers can measure a text differently; a gap over 1 px makes each page open by a user of the other renderer write the size back. Two browsers on the SVG renderer can do the same: a long auto-width line can differ by more than 1 px, and an auto-height text can wrap a line differently. This is a known limit, noted in the text-heal docstring. The drift check moves to text-size-drifted? in app.common.geom.shapes.text, and takes a tolerance. Both renderers use it: 1 px for the SVG check and the WebGL page-open check, 0.1 px for the WebGL font-load check. The WebGL check did not skip axes that fill their layout parent, so those texts looked stale on every page open and were resized for nothing. It now reads the stored width and height and skips fill axes. The sync docstring and a test message gave the wrong reason for :skip-component-sync?. :ignore-touched stops the resize from marking :geometry-group. :skip-component-sync? stops the re-measure commit from starting another sync. "Remasure" is now "re-measure" in identifiers, test names and comments. The sync docstring now states that an auto-grow copy takes the main's size on each geometry sync, also with overridden content, until the re-measure or the page-open check corrects it. The sync's undo comment no longer says the layout pass gets the sync's undo group: the layout buffer drops it, and the pass joins the same undo entry through :stack-undo?. Tests: heal undo tests cover mixed user and sync batches in both orders, and undo for both renderers. A heal leaves the undo stack unchanged, and undo reverts the user edit. A heal reflow skips the component sync. Sync tests cover a copy that becomes auto-grow (re-measured) and one that becomes fixed (not), and a sync with no undo group that shares one with its re-measure, also inside an undo transaction, with and without a group of the edit. Viewport tests cover no resize without drift, a drifted copy that resizes and settles, the check of every auto-grow text in a copy, and no size write from a failed font. Component tests mount the SVG renderer: a drifted copy is measured once to check and once to settle, with no undo step, and a matching copy is measured once. Stale-selrect tests cover skipped fill axes. The drift tests move to common-tests.geom-shapes-text-test, with tolerance and grow-type cases. Relates to #12721 AI-assisted-by: claude-opus-5-5
115 lines
5.3 KiB
Clojure
115 lines
5.3 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns common-tests.geom-shapes-text-test
|
|
(:require
|
|
[app.common.geom.matrix :as gmt]
|
|
[app.common.geom.point :as gpt]
|
|
[app.common.geom.rect :as grc]
|
|
[app.common.geom.shapes.text :as gte]
|
|
[app.common.math :as mth]
|
|
[clojure.test :as t]))
|
|
|
|
(t/deftest position-data->rect-test
|
|
(t/testing "Converts position data to a rect"
|
|
(let [pd {:x 100 :y 200 :width 80 :height 20}
|
|
result (gte/position-data->rect pd)]
|
|
(t/is (grc/rect? result))
|
|
(t/is (mth/close? 100.0 (:x result)))
|
|
(t/is (mth/close? 180.0 (:y result)))
|
|
(t/is (mth/close? 80.0 (:width result)))
|
|
(t/is (mth/close? 20.0 (:height result)))))
|
|
|
|
(t/testing "Negative y still works"
|
|
(let [pd {:x 10 :y 5 :width 20 :height 10}
|
|
result (gte/position-data->rect pd)]
|
|
(t/is (mth/close? 10.0 (:x result)))
|
|
(t/is (mth/close? -5.0 (:y result))))))
|
|
|
|
(t/deftest shape->rect-test
|
|
(t/testing "Shape with position data returns bounding rect"
|
|
(let [shape {:position-data [{:x 10 :y 50 :width 40 :height 10}
|
|
{:x 10 :y 60 :width 30 :height 10}]}
|
|
result (gte/shape->rect shape)]
|
|
(t/is (grc/rect? result))
|
|
(t/is (pos? (:width result)))
|
|
(t/is (pos? (:height result)))))
|
|
|
|
(t/testing "Shape without position data returns selrect"
|
|
(let [selrect (grc/make-rect 10 20 100 50)
|
|
shape {:position-data nil :selrect selrect}
|
|
result (gte/shape->rect shape)]
|
|
(t/is (= selrect result))))
|
|
|
|
(t/testing "Shape with empty position data returns selrect"
|
|
(let [selrect (grc/make-rect 10 20 100 50)
|
|
shape {:position-data [] :selrect selrect}
|
|
result (gte/shape->rect shape)]
|
|
(t/is (= selrect result)))))
|
|
|
|
(t/deftest shape->bounds-test
|
|
(t/testing "Shape with position data and identity transform"
|
|
(let [shape {:position-data [{:x 10 :y 50 :width 40 :height 10}]
|
|
:selrect (grc/make-rect 10 40 40 10)
|
|
:transform (gmt/matrix)
|
|
:flip-x false :flip-y false}
|
|
result (gte/shape->bounds shape)]
|
|
(t/is (grc/rect? result))
|
|
(t/is (pos? (:width result))))))
|
|
|
|
(t/deftest overlaps-position-data?-test
|
|
(t/testing "Overlapping position data"
|
|
(let [shape-points [(gpt/point 0 0) (gpt/point 100 0)
|
|
(gpt/point 100 100) (gpt/point 0 100)]
|
|
shape {:points shape-points}
|
|
pd [{:x 10 :y 30 :width 20 :height 10}]]
|
|
(t/is (true? (gte/overlaps-position-data? shape pd)))))
|
|
|
|
(t/testing "Non-overlapping position data"
|
|
(let [shape-points [(gpt/point 0 0) (gpt/point 10 0)
|
|
(gpt/point 10 10) (gpt/point 0 10)]
|
|
shape {:points shape-points}
|
|
pd [{:x 200 :y 200 :width 20 :height 10}]]
|
|
(t/is (false? (gte/overlaps-position-data? shape pd))))))
|
|
|
|
(t/deftest text-size-drifted-ignores-sub-pixel-gaps
|
|
(t/is (not (gte/text-size-drifted? {:grow-type :auto-width :width 100 :height 17} 100.5 17.5 1)))
|
|
(t/is (not (gte/text-size-drifted? {:grow-type :auto-height :width 100 :height 17} 100 17.5 1))))
|
|
|
|
(t/deftest text-size-drifted-checks-only-the-growing-axis
|
|
(t/is (not (gte/text-size-drifted? {:grow-type :auto-height :width 100 :height 17} 140 17 1))
|
|
"auto-height width comes from the box, not the text")
|
|
(t/is (gte/text-size-drifted? {:grow-type :auto-height :width 100 :height 17} 100 34 1))
|
|
(t/is (gte/text-size-drifted? {:grow-type :auto-width :width 44 :height 17} 67 17 1))
|
|
(t/is (gte/text-size-drifted? {:grow-type :auto-width :width 44 :height 17} 44 34 1)
|
|
"auto-width grows in height too"))
|
|
|
|
(t/deftest text-size-drifted-treats-exactly-the-tolerance-as-rounding
|
|
(t/is (not (gte/text-size-drifted? {:grow-type :auto-height :width 100 :height 17} 100 18 1))
|
|
"a 1px height gap is rounding at a 1px tolerance")
|
|
(t/is (not (gte/text-size-drifted? {:grow-type :auto-width :width 44 :height 17} 45 17 1))
|
|
"a 1px width gap is rounding at a 1px tolerance")
|
|
(t/is (gte/text-size-drifted? {:grow-type :auto-height :width 100 :height 17} 100 17.5 0.1)
|
|
"a finer tolerance catches a sub-pixel gap"))
|
|
|
|
(t/deftest text-size-drifted-ignores-an-axis-that-fills-its-parent
|
|
(t/is (not (gte/text-size-drifted? {:grow-type :auto-height :width 100 :height 40
|
|
:layout-item-v-sizing :fill}
|
|
100 17 1))
|
|
"a height set by the layout is not drift")
|
|
(t/is (not (gte/text-size-drifted? {:grow-type :auto-width :width 200 :height 17
|
|
:layout-item-h-sizing :fill}
|
|
44 17 1))
|
|
"a width set by the layout is not drift")
|
|
(t/is (gte/text-size-drifted? {:grow-type :auto-width :width 200 :height 17
|
|
:layout-item-h-sizing :fill}
|
|
44 34 1)
|
|
"the axis that does not fill is still checked"))
|
|
|
|
(t/deftest text-size-drifted-ignores-other-grow-types
|
|
(t/is (not (gte/text-size-drifted? {:grow-type :fixed :width 100 :height 17} 300 90 1)))
|
|
(t/is (not (gte/text-size-drifted? {:width 100 :height 17} 300 90 1))))
|