mirror of
https://github.com/penpot/penpot.git
synced 2026-11-23 19:00:36 +00:00
🐛 Measure a text in the element its renderer mounted
In the SVG renderer, a text inside a component kept drawing its old font weight after a font weight token changed: the Design panel showed the new weight, the canvas the old one, also after a reload. A changed text is measured in a hidden HTML element, looked up in the document by `#html-text-node-<id>`. While a layout reflows, the text modifiers renderer mounts an element with the same id for the same text, ahead of the changes renderer's one. The measurement found that transient element; when a font variant had to load first, it was gone by the time the measurement ran, so the position data came out empty and was dropped, and nothing measured the text again. Texts in boards with layout, as component mains usually are, take that path; others did not. `calc-position-data` now measures the element the renderer passes, never one looked up by id. Found by the components Qase run (PENPOT-2562). Checked in the browser: cycling the font weight token of a main and its copy through weights not loaded yet (300, 700, 200, 900, 600 italic, 300) redraws both with each new weight; before, the first use of each weight kept the old one. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
8ed11dcf26
commit
c5c60e466b
@ -121,7 +121,7 @@
|
||||
"Measure the text and commit its position-data and auto-grow size as
|
||||
`text-heal` decides for `phase`. Resolves to the next heal phase, if any."
|
||||
[{:keys [id] :as shape} node phase]
|
||||
(->> (tsp/calc-position-data id)
|
||||
(->> (tsp/calc-position-data node)
|
||||
(p/fmap (fn [position-data]
|
||||
(let [;; A page-open check never writes a size laid out
|
||||
;; with a fallback font
|
||||
@ -151,7 +151,7 @@
|
||||
|
||||
(defn- update-text-modifier
|
||||
[{:keys [grow-type id] :as shape} node]
|
||||
(->> (tsp/calc-position-data id)
|
||||
(->> (tsp/calc-position-data node)
|
||||
(p/fmap (fn [position-data]
|
||||
(let [props {:position-data position-data}]
|
||||
(if (contains? #{:auto-height :auto-width} grow-type)
|
||||
|
||||
@ -82,9 +82,8 @@
|
||||
(seq (.-childNodes parent-node)))))
|
||||
|
||||
(defn- calc-text-node-positions
|
||||
[shape-id]
|
||||
(let [text-nodes (-> (dom/query (dm/fmt "#html-text-node-%" shape-id))
|
||||
(dom/query-all ".text-node"))]
|
||||
[root-node]
|
||||
(let [text-nodes (dom/query-all root-node ".text-node")]
|
||||
(->> (p/all (map resolve-font text-nodes))
|
||||
(p/fmap (fn [fonts]
|
||||
(cond-> (into [] (mapcat process-text-node) text-nodes)
|
||||
@ -97,7 +96,10 @@
|
||||
(true? (::font-failed (meta position-data))))
|
||||
|
||||
(defn calc-position-data
|
||||
[shape-id]
|
||||
"Measure the position data of the text rendered in `root-node`, the
|
||||
`.text-node-html` element of a text shape. Several renderers can hold an
|
||||
element for the same shape at once, so it is never looked up by id."
|
||||
[root-node]
|
||||
(letfn [(get-prop [styles prop]
|
||||
(let [value (.getPropertyValue styles prop)]
|
||||
(when (and (some? value) (not= value ""))
|
||||
@ -120,8 +122,8 @@
|
||||
txt/default-text-fills)
|
||||
:text text})))]
|
||||
|
||||
(when (some? shape-id)
|
||||
(->> (calc-text-node-positions shape-id)
|
||||
(when (some? root-node)
|
||||
(->> (calc-text-node-positions root-node)
|
||||
(p/fmap (fn [text-data]
|
||||
(with-meta (mapv transform-data text-data)
|
||||
(meta text-data))))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user