diff --git a/ppl2psd.py b/ppl2psd.py index 6b93fe1..649fabd 100644 --- a/ppl2psd.py +++ b/ppl2psd.py @@ -525,6 +525,13 @@ def build_type_layer_tysh(ly: dict, font_ps: str, text_w: Optional[float] = None text_len = len(text) eng["StyleRun"]["RunLengthArray"] = List([Integer(text_len)]) eng["ParagraphRun"]["RunLengthArray"] = List([Integer(text_len)]) + # Left-align (template is justify, which spreads short text across the + # box). ppl rows read left-aligned; user prefers left over spread. + try: + props = eng["ParagraphRun"]["RunArray"][0]["ParagraphSheet"]["Properties"] + props["Justification"] = Integer(0) # left + except Exception: + pass prof = font_profile(_font_path_for(ly)) size_px = float(ly.get("textSize", "12") or 12) * prof["k"] @@ -554,20 +561,16 @@ 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 = center of the ppl rect; boundingBox = the actual - # text box centered on it. This keeps the text centered and the edit box - # small (template bbox / justification would spread text across a huge - # frame or run off canvas). - cx, cy = (l + rr) / 2, (t + bb2) / 2 - tysh.transform = [1.0, 0.0, 0.0, 1.0, float(cx), float(cy)] + # 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). + 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 * 1.2 bbd = td[b"boundingBox"] - bbd[b"Left"].value = -tw / 2 - bbd[b"Top "].value = -th / 2 - bbd[b"Rght"].value = tw / 2 - bbd[b"Btom"].value = th / 2 + 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) return tysh.tobytes()