Skip to content

Commit 02f4bf3

Browse files
ShotaroKataokaShotaro Kataoka
andauthored
fix(textbox): apply lineOpacity to textbox borders (#669)
Closes #667 Co-authored-by: Shotaro Kataoka <sktok@amazon.co.jp>
1 parent ca67220 commit 02f4bf3

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ Under an Upgrading section, the bullets after **Local installs (`sdpm update`).*
5757

5858
### Fixed
5959

60+
- **A textbox border keeps its `lineOpacity`** (#667). The textbox builder ignored
61+
`lineOpacity`, so a translucent border came out fully opaque, and a PPTX → JSON → PPTX
62+
round trip lost the opacity `pptx_to_json` had read. It now writes the border alpha as
63+
shapes do. Local mode and the AWS stack (SdpmRuntime).
64+
6065
- **Charts keep theme styling when `valueAxis` or `categoryAxis` is set.** Setting either
6166
no longer drops theme styling of the axis tick labels, axis lines and title. Only a chart
6267
read back from a PPTX keeps the styling it came with; JSON written by hand or by an agent

‎sdpm/references/guides/slide-json-elements.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Expands an external JSON file's elements array. Draw order is controlled by posi
8383
- `autoWidth`: true → word_wrap disabled (width fits text)
8484
- `line`: border color. Omit or `"none"` for no border
8585
- `lineWidth`: border thickness (pt, default 1)
86+
- `lineOpacity`: border opacity (default 1.0)
8687
- `margin*`: px (same 1920-wide canvas basis as other coordinates)
8788
- `verticalAlign`: `top`, `middle`, `bottom` (default: top for textbox)
8889
- **Line breaks**: `\n` creates a line break (internally split into paragraphs)

‎sdpm/sdpm/engine/builder/elements/textbox.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ def _add_textbox(self, slide, elem):
308308
int(hex_color[4:6], 16)
309309
)
310310
textbox.line.width = Pt(line_width)
311+
line_opacity = elem.get("lineOpacity")
312+
if line_opacity is not None and 0 <= line_opacity < 1:
313+
self._set_line_opacity(textbox, line_opacity)
311314

312315
# Apply text frame margins (px input → EMU)
313316
margin_left = elem.get("marginLeft")

‎tests/test_element_roundtrip.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,15 @@ def test_box_properties_survive(self, tmp_path):
497497
assert (out["verticalAlign"], out["textDirection"]) == ("bottom", "vert270")
498498
assert (out["marginTop"], out["autoWidth"]) == (5, True)
499499

500+
def test_border_opacity_survives(self, tmp_path):
501+
border = {"text": "t", "line": "#FF0000", "lineWidth": 2}
502+
(sp,) = _built_shapes(tmp_path, [_textbox(**border, lineOpacity=0.5)])
503+
assert sp._element.spPr.find(f"{_A}ln/{_A}solidFill/{_A}srgbClr/{_A}alpha").get("val") == "50000"
504+
assert _one(tmp_path / "rt", _textbox(**border, lineOpacity=0.5))["lineOpacity"] == 0.5
505+
for extra in ({}, {"lineOpacity": 1}):
506+
(sp,) = _built_shapes(tmp_path / f"o{len(extra)}", [_textbox(**border, **extra)])
507+
assert sp._element.spPr.find(f".//{_A}alpha") is None
508+
500509
def test_text_gradient_survives(self, tmp_path):
501510
out = _one(tmp_path, _textbox(text="grad", fontSize=40,
502511
textGradient={"angle": 0, "stops": GRADIENT["stops"]}))

0 commit comments

Comments
 (0)