Skip to content

Commit 4e5f728

Browse files
author
Steve Canny
committed
parfmt: add ParagraphFormat.right_indent getter
1 parent 0c26810 commit 4e5f728

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

docx/oxml/text/paragraph.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CT_Ind(BaseOxmlElement):
1919
``<w:ind>`` element, specifying paragraph indentation.
2020
"""
2121
left = OptionalAttribute('w:left', ST_SignedTwipsMeasure)
22+
right = OptionalAttribute('w:right', ST_SignedTwipsMeasure)
2223
firstLine = OptionalAttribute('w:firstLine', ST_TwipsMeasure)
2324
hanging = OptionalAttribute('w:hanging', ST_TwipsMeasure)
2425

@@ -151,6 +152,16 @@ def ind_left(self):
151152
return None
152153
return ind.left
153154

155+
@property
156+
def ind_right(self):
157+
"""
158+
The value of `w:ind/@w:right` or |None| if not present.
159+
"""
160+
ind = self.ind
161+
if ind is None:
162+
return None
163+
return ind.right
164+
154165
@property
155166
def jc_val(self):
156167
"""

docx/text/paragraph.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ def line_spacing_rule(self, value):
247247
else:
248248
pPr.spacing_lineRule = value
249249

250+
@property
251+
def right_indent(self):
252+
"""
253+
|Length| value specifying the space between the right margin and the
254+
right side of the paragraph. |None| indicates the right indent value
255+
is inherited from the style hierarchy. Use a |Cm| value object as
256+
a convenient way to apply indentation in units of centimeters.
257+
"""
258+
pPr = self._element.pPr
259+
if pPr is None:
260+
return None
261+
return pPr.ind_right
262+
250263
@property
251264
def space_after(self):
252265
"""

features/txt-parfmt-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Feature: Get or set paragraph formatting properties
9595
| 14 pt | None | 1.1666 | WD_LINE_SPACING.MULTIPLE |
9696

9797

98-
@wip
9998
Scenario Outline: Get paragraph indents
10099
Given a paragraph format having <type> indent of <setting>
101100
Then paragraph_format.<type>_indent is <value>

tests/text/test_paragraph.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ def it_knows_its_left_indent(self, left_indent_get_fixture):
342342
paragraph_format, expected_value = left_indent_get_fixture
343343
assert paragraph_format.left_indent == expected_value
344344

345+
def it_knows_its_right_indent(self, right_indent_get_fixture):
346+
paragraph_format, expected_value = right_indent_get_fixture
347+
assert paragraph_format.right_indent == expected_value
348+
345349
# fixtures -------------------------------------------------------
346350

347351
@pytest.fixture(params=[
@@ -473,6 +477,18 @@ def line_spacing_rule_set_fixture(self, request):
473477
expected_xml = xml(expected_p_cxml)
474478
return paragraph_format, value, expected_xml
475479

480+
@pytest.fixture(params=[
481+
('w:p', None),
482+
('w:p/w:pPr', None),
483+
('w:p/w:pPr/w:ind', None),
484+
('w:p/w:pPr/w:ind{w:right=160}', Pt(8)),
485+
('w:p/w:pPr/w:ind{w:right=-4.2pt}', Pt(-4.2)),
486+
])
487+
def right_indent_get_fixture(self, request):
488+
p_cxml, expected_value = request.param
489+
paragraph_format = ParagraphFormat(element(p_cxml))
490+
return paragraph_format, expected_value
491+
476492
@pytest.fixture(params=[
477493
('w:p', None),
478494
('w:p/w:pPr', None),

0 commit comments

Comments
 (0)