Skip to content

Commit 32efba5

Browse files
author
Steve Canny
committed
acpt: add scenarios for XxxStyle.font
1 parent b50dc0e commit 32efba5

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

docx/text/run.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from __future__ import absolute_import, print_function, unicode_literals
88

99
from ..enum.text import WD_BREAK
10-
from ..shared import Parented
10+
from ..shared import ElementProxy, Parented
1111

1212

1313
def boolproperty(f):
@@ -372,6 +372,16 @@ def web_hidden(self):
372372
return 'webHidden'
373373

374374

375+
class Font(ElementProxy):
376+
"""
377+
Proxy object wrapping the parent of a ``<w:rPr>`` element and providing
378+
access to character properties such as font name, font size, bold, and
379+
subscript.
380+
"""
381+
382+
__slots__ = ()
383+
384+
375385
class _Text(object):
376386
"""
377387
Proxy object wrapping ``<w:t>`` element.

features/steps/styles.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from docx.enum.style import WD_STYLE_TYPE
1111
from docx.styles.styles import Styles
1212
from docx.styles.style import BaseStyle
13+
from docx.text.run import Font
1314

1415
from helpers import test_docx
1516

@@ -67,6 +68,18 @@ def given_a_style_having_a_known_attr_name(context, attr_name):
6768
context.style = document.styles['Normal']
6869

6970

71+
@given('a style of type {style_type}')
72+
def given_a_style_of_type(context, style_type):
73+
document = Document(test_docx('sty-known-styles'))
74+
name = {
75+
'WD_STYLE_TYPE.CHARACTER': 'Default Paragraph Font',
76+
'WD_STYLE_TYPE.LIST': 'No List',
77+
'WD_STYLE_TYPE.PARAGRAPH': 'Normal',
78+
'WD_STYLE_TYPE.TABLE': 'Normal Table',
79+
}[style_type]
80+
context.style = document.styles[name]
81+
82+
7083
# when =====================================================
7184

7285
@when('I assign a new name to the style')
@@ -155,6 +168,14 @@ def then_style_builtin_is_builtin(context, builtin_str):
155168
assert style.builtin == builtin
156169

157170

171+
@then('style.font is the Font object for the style')
172+
def then_style_font_is_the_Font_object_for_the_style(context):
173+
style = context.style
174+
font = style.font
175+
assert isinstance(font, Font)
176+
assert font.element is style.element
177+
178+
158179
@then('style.name is the {which} name')
159180
def then_style_name_is_the_which_name(context, which):
160181
expected_name = {

features/sty-access-font.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Feature: Access style font
2+
In order to discover or change the character formatting of a style
3+
As a developer using python-docx
4+
I need access to the font of a style
5+
6+
7+
@wip
8+
Scenario Outline: Get style font
9+
Given a style of type <style-type>
10+
Then style.font is the Font object for the style
11+
12+
Examples: Style types
13+
| style-type |
14+
| WD_STYLE_TYPE.CHARACTER |
15+
| WD_STYLE_TYPE.PARAGRAPH |
16+
| WD_STYLE_TYPE.TABLE |

0 commit comments

Comments
 (0)