TypeLayer: small edit box (boundingBox = text size at bbox top-left)

boundingBox was the whole boundingRect making the edit box huge. Use the
actual rendered text size (0,0,tw,th) with transform origin at the rect
top-left: box is small and positioned at the text.
This commit is contained in:
AskaEth committed 2026-08-27 17:09:27 +08:00
1 parent 1c2a9912f5
commit c9c1b6d238
1 file changed
+6 -5
+6 -5
View File
@@ -561,16 +561,17 @@ def build_type_layer_tysh(ly: dict, font_ps: str, text_w: Optional[float] = None
pass
l, t, rr, bb2 = bounding_rect(ly)
# transform origin = boundingRect top-left; boundingBox from the origin.
# This keeps the text edit box aligned with the text (the previous
# center-origin version shifted the box down-right).
# transform origin = boundingRect top-left; boundingBox = the ACTUAL
# text box (0,0,tw,th) so the edit box is small and sits at the text.
tysh.transform = [1.0, 0.0, 0.0, 1.0, float(l), float(t)]
tysh.left, tysh.top, tysh.right, tysh.bottom = int(l), int(t), int(rr), int(bb2)
tw = text_w if text_w else (rr - l)
th = size_px * 0.9 # ~glyph height
bbd = td[b"boundingBox"]
bbd[b"Left"].value = 0.0
bbd[b"Top "].value = 0.0
bbd[b"Rght"].value = float(rr - l)
bbd[b"Btom"].value = float(bb2 - t)
bbd[b"Rght"].value = float(tw)
bbd[b"Btom"].value = float(th)
return tysh.tobytes()