From c9c1b6d238b645dcff7858e79349f1f075259cdf Mon Sep 17 00:00:00 2001 From: AskaEth Date: Thu, 27 Aug 2026 17:09:27 +0800 Subject: [PATCH] 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. --- ppl2psd.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ppl2psd.py b/ppl2psd.py index 649fabd..28078e6 100644 --- a/ppl2psd.py +++ b/ppl2psd.py @@ -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()