There was an error while loading. Please reload this page.
1 parent ff5e5c2 commit 5b7edf9Copy full SHA for 5b7edf9
5 files changed
docx/oxml/__init__.py
@@ -181,7 +181,9 @@ def OxmlElement(nsptag_str, attrs=None, nsdecls=None):
181
from .text.paragraph import CT_P
182
register_element_cls('w:p', CT_P)
183
184
-from .text.parfmt import CT_Ind, CT_Jc, CT_PPr, CT_Spacing, CT_TabStops
+from .text.parfmt import (
185
+ CT_Ind, CT_Jc, CT_PPr, CT_Spacing, CT_TabStop, CT_TabStops
186
+)
187
register_element_cls('w:ind', CT_Ind)
188
register_element_cls('w:jc', CT_Jc)
189
register_element_cls('w:keepLines', CT_OnOff)
@@ -190,6 +192,7 @@ def OxmlElement(nsptag_str, attrs=None, nsdecls=None):
190
192
register_element_cls('w:pPr', CT_PPr)
191
193
register_element_cls('w:pStyle', CT_String)
194
register_element_cls('w:spacing', CT_Spacing)
195
+register_element_cls('w:tab', CT_TabStop)
196
register_element_cls('w:tabs', CT_TabStops)
197
register_element_cls('w:widowControl', CT_OnOff)
198
docx/oxml/text/parfmt.py
@@ -315,6 +315,13 @@ class CT_Spacing(BaseOxmlElement):
315
lineRule = OptionalAttribute('w:lineRule', WD_LINE_SPACING)
316
317
318
+class CT_TabStop(BaseOxmlElement):
319
+ """
320
+ ``<w:tab>`` element, representing an individual tab stop.
321
322
+ pos = RequiredAttribute('w:pos', ST_SignedTwipsMeasure)
323
+
324
325
class CT_TabStops(BaseOxmlElement):
326
"""
327
``<w:tabs>`` element, container for a sorted sequence of tab stops.
docx/text/tabstops.py
@@ -63,3 +63,11 @@ class TabStop(ElementProxy):
63
def __init__(self, element):
64
super(TabStop, self).__init__(element, None)
65
self._tab = element
66
67
+ @property
68
+ def position(self):
69
70
+ The distance (in EMU) of this tab stop from the inside edge of the
71
+ paragraph. May be positive or negative.
72
73
+ return self._tab.pos
features/tab-tabstop-props.feature
@@ -4,7 +4,6 @@ Feature: Tab stop properties
4
I need a set of read/write properties on TabStop
5
6
7
- @wip
8
Scenario Outline: Get TabStop.position
9
Given a tab stop 0.5 inches <in-or-out> from the paragraph left edge
10
Then tab_stop.position is <position>
tests/text/test_tabstops.py
@@ -9,6 +9,7 @@
absolute_import, division, print_function, unicode_literals
)
11
12
+from docx.shared import Twips
13
from docx.text.tabstops import TabStop, TabStops
14
15
import pytest
@@ -17,6 +18,20 @@
17
18
from ..unitutil.mock import call, class_mock, instance_mock
19
20
21
+class DescribeTabStop(object):
22
23
+ def it_knows_its_position(self, position_get_fixture):
24
+ tab_stop, expected_value = position_get_fixture
25
+ assert tab_stop.position == expected_value
26
27
+ # fixture --------------------------------------------------------
28
29
+ @pytest.fixture
30
+ def position_get_fixture(self, request):
31
+ tab_stop = TabStop(element('w:tab{w:pos=720}'))
32
+ return tab_stop, Twips(720)
33
34
35
class DescribeTabStops(object):
36
37
def it_knows_its_length(self, len_fixture):
0 commit comments