Skip to content

Commit

Permalink
tabs: add TabStop.leader
Browse files Browse the repository at this point in the history
  • Loading branch information
DKWoods authored and Steve Canny committed May 27, 2016
1 parent 48a7e31 commit 321cad1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docx/oxml/text/parfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

from ...enum.text import (
WD_ALIGN_PARAGRAPH, WD_LINE_SPACING, WD_TAB_ALIGNMENT
WD_ALIGN_PARAGRAPH, WD_LINE_SPACING, WD_TAB_ALIGNMENT, WD_TAB_LEADER
)
from ...shared import Length
from ..simpletypes import ST_SignedTwipsMeasure, ST_TwipsMeasure
Expand Down Expand Up @@ -322,6 +322,9 @@ class CT_TabStop(BaseOxmlElement):
``<w:tab>`` element, representing an individual tab stop.
"""
val = RequiredAttribute('w:val', WD_TAB_ALIGNMENT)
leader = OptionalAttribute(
'w:leader', WD_TAB_LEADER, default=WD_TAB_LEADER.SPACES
)
pos = RequiredAttribute('w:pos', ST_SignedTwipsMeasure)


Expand Down
9 changes: 9 additions & 0 deletions docx/text/tabstops.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ def alignment(self):
"""
return self._tab.val

@property
def leader(self):
"""
A member of :ref:`WdTabLeader` specifying a repeating character used
as a "leader", filling in the space spanned by this tab. Assigning
|None| produces the same result as assigning `WD_TAB_LEADER.SPACES`.
"""
return self._tab.leader

@property
def position(self):
"""
Expand Down
1 change: 0 additions & 1 deletion features/tab-tabstop-props.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Feature: Tab stop properties
| RIGHT |


@wip
Scenario Outline: Get TabStop.leader
Given a tab stop having <leader> leader
Then tab_stop.leader is <value>
Expand Down
17 changes: 16 additions & 1 deletion tests/text/test_tabstops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
absolute_import, division, print_function, unicode_literals
)

from docx.enum.text import WD_TAB_ALIGNMENT
from docx.enum.text import WD_TAB_ALIGNMENT, WD_TAB_LEADER
from docx.shared import Twips
from docx.text.tabstops import TabStop, TabStops

Expand All @@ -29,6 +29,10 @@ def it_knows_its_alignment(self, alignment_get_fixture):
tab_stop, expected_value = alignment_get_fixture
assert tab_stop.alignment == expected_value

def it_knows_its_leader(self, leader_get_fixture):
tab_stop, expected_value = leader_get_fixture
assert tab_stop.leader == expected_value

# fixture --------------------------------------------------------

@pytest.fixture(params=[
Expand All @@ -41,6 +45,17 @@ def alignment_get_fixture(self, request):
expected_value = getattr(WD_TAB_ALIGNMENT, member)
return tab_stop, expected_value

@pytest.fixture(params=[
('w:tab', 'SPACES'),
('w:tab{w:leader=none}', 'SPACES'),
('w:tab{w:leader=dot}', 'DOTS'),
])
def leader_get_fixture(self, request):
tab_stop_cxml, member = request.param
tab_stop = TabStop(element(tab_stop_cxml))
expected_value = getattr(WD_TAB_LEADER, member)
return tab_stop, expected_value

@pytest.fixture
def position_get_fixture(self, request):
tab_stop = TabStop(element('w:tab{w:pos=720}'))
Expand Down

0 comments on commit 321cad1

Please sign in to comment.