Skip to content

Commit 22fcae2

Browse files
committed
feat: update table cell style to support new font size types and adjust related tests
1 parent c462cc0 commit 22fcae2

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/pptxr/_pptx/shape/table.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
from pptx.enum.text import MSO_VERTICAL_ANCHOR, PP_ALIGN
66
from pptx.shapes.graphfrm import GraphicFrame
7-
from pptx.util import Pt
87

9-
from pptxr.types._length import Length, LiteralLength
8+
from pptxr.types._length import Length, LiteralLength, LiteralPoint, Point
109

10+
from ..converter import to_pptx_length
1111
from . import Shape
1212

1313
DataFrame: TypeAlias = list[list[str]]
@@ -20,7 +20,7 @@ class TableCellStyle(TypedDict):
2020
vertical_align: NotRequired[Literal["top", "middle", "bottom"]]
2121
bold: NotRequired[bool]
2222
italic: NotRequired[bool]
23-
font_size: NotRequired[int] # ポイントサイズで指定
23+
font_size: NotRequired[Point | LiteralPoint]
2424
font_name: NotRequired[str]
2525

2626

@@ -122,7 +122,9 @@ def __init__(
122122
run.font.italic = cell_style["italic"]
123123

124124
if "font_size" in cell_style:
125-
run.font.size = Pt(cell_style["font_size"])
125+
run.font.size = to_pptx_length(
126+
cell_style["font_size"]
127+
)
126128

127129
if "font_name" in cell_style:
128130
run.font.name = cell_style["font_name"]

src/pptxr/types/_length.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
POINTS_PER_INCH = 72 # 1 inch = 72 points
88
CM_PER_INCH = 2.54 # 1 inch = 2.54 cm
99

10+
LiteralPoint = tuple[int, Literal["pt"]]
11+
LiteralInch = tuple[float, Literal["in"]]
12+
LiteralCentimeter = tuple[float, Literal["cm"]]
1013

11-
LiteralLength = (
12-
tuple[int, Literal["pt"]]
13-
| tuple[float, Literal["in"]]
14-
| tuple[float, Literal["cm"]]
15-
)
14+
LiteralLength = LiteralPoint | LiteralInch | LiteralCentimeter
1615

1716

1817
class Inch:

tests/test_presentation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def test_create_presentation_with_styled_table(output: pathlib.Path) -> None:
6262

6363
cell_styles: list[list[TableCellStyle]] = [
6464
[
65-
{"bold": True, "font_size": 14, "text_align": "center"},
66-
{"bold": True, "font_size": 14, "text_align": "center"},
67-
{"bold": True, "font_size": 14, "text_align": "center"},
65+
{"bold": True, "font_size": (14, "pt"), "text_align": "center"},
66+
{"bold": True, "font_size": (14, "pt"), "text_align": "center"},
67+
{"bold": True, "font_size": (14, "pt"), "text_align": "center"},
6868
],
6969
[
7070
{"text_align": "left", "vertical_align": "middle"},

0 commit comments

Comments
 (0)