Skip to content

Commit 0c26810

Browse files
author
Steve Canny
committed
parfmt: add ParagraphFormat.left_indent getter
1 parent 931012d commit 0c26810

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

docx/oxml/text/paragraph.py

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

@@ -140,6 +141,16 @@ def first_line_indent(self):
140141
return None
141142
return firstLine
142143

144+
@property
145+
def ind_left(self):
146+
"""
147+
The value of `w:ind/@w:left` or |None| if not present.
148+
"""
149+
ind = self.ind
150+
if ind is None:
151+
return None
152+
return ind.left
153+
143154
@property
144155
def jc_val(self):
145156
"""

docx/text/paragraph.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ def first_line_indent(self):
172172
return None
173173
return pPr.first_line_indent
174174

175+
@property
176+
def left_indent(self):
177+
"""
178+
|Length| value specifying the space between the left margin and the
179+
left side of the paragraph. |None| indicates the left indent value is
180+
inherited from the style hierarchy. Use an |Inches| value object as
181+
a convenient way to apply indentation in units of inches.
182+
"""
183+
pPr = self._element.pPr
184+
if pPr is None:
185+
return None
186+
return pPr.ind_left
187+
175188
@property
176189
def line_spacing(self):
177190
"""

tests/text/test_paragraph.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ def it_knows_its_first_line_indent(self, first_indent_get_fixture):
338338
paragraph_format, expected_value = first_indent_get_fixture
339339
assert paragraph_format.first_line_indent == expected_value
340340

341+
def it_knows_its_left_indent(self, left_indent_get_fixture):
342+
paragraph_format, expected_value = left_indent_get_fixture
343+
assert paragraph_format.left_indent == expected_value
344+
341345
# fixtures -------------------------------------------------------
342346

343347
@pytest.fixture(params=[
@@ -380,6 +384,18 @@ def first_indent_get_fixture(self, request):
380384
paragraph_format = ParagraphFormat(element(p_cxml))
381385
return paragraph_format, expected_value
382386

387+
@pytest.fixture(params=[
388+
('w:p', None),
389+
('w:p/w:pPr', None),
390+
('w:p/w:pPr/w:ind', None),
391+
('w:p/w:pPr/w:ind{w:left=120}', Pt(6)),
392+
('w:p/w:pPr/w:ind{w:left=-06.3pt}', Pt(-6.3)),
393+
])
394+
def left_indent_get_fixture(self, request):
395+
p_cxml, expected_value = request.param
396+
paragraph_format = ParagraphFormat(element(p_cxml))
397+
return paragraph_format, expected_value
398+
383399
@pytest.fixture(params=[
384400
('w:p', None),
385401
('w:p/w:pPr', None),

0 commit comments

Comments
 (0)