Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c25b7f3

Browse files
DKWoodsSteve Canny
authored andcommitted
acpt: add scenarios for Font.highlight_color
1 parent 46cd9ab commit c25b7f3

File tree

6 files changed

+184
-1
lines changed

6 files changed

+184
-1
lines changed

docs/api/enum/WdColorIndex.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.. _WdColorIndex:
2+
3+
``WD_COLOR_INDEX``
4+
==================
5+
6+
Specifies a standard preset color to apply. Used for font highlighting and
7+
perhaps other applications.
8+
9+
----
10+
11+
AUTO
12+
Automatic color. Default; usually black.
13+
14+
BLACK
15+
Black color.
16+
17+
BLUE
18+
Blue color
19+
20+
BRIGHT_GREEN
21+
Bright green color.
22+
23+
DARK_BLUE
24+
Dark blue color.
25+
26+
DARK_RED
27+
Dark red color.
28+
29+
DARK_YELLOW
30+
Dark yellow color.
31+
32+
GRAY_25
33+
25% shade of gray color.
34+
35+
GRAY_50
36+
50% shade of gray color.
37+
38+
GREEN
39+
Green color.
40+
41+
PINK
42+
Pink color.
43+
44+
RED
45+
Red color.
46+
47+
TEAL
48+
Teal color.
49+
50+
TURQUOISE
51+
Turquoise color.
52+
53+
VIOLET
54+
Violet color.
55+
56+
WHITE
57+
White color.
58+
59+
YELLOW
60+
Yellow color.

docs/api/enum/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ can be found here:
1212
MsoThemeColorIndex
1313
WdAlignParagraph
1414
WdBuiltinStyle
15+
WdColorIndex
1516
WdLineSpacing
1617
WdOrientation
1718
WdSectionStart

docx/enum/text.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,74 @@ class WD_BREAK_TYPE(object):
8484
WD_BREAK = WD_BREAK_TYPE
8585

8686

87+
class WD_COLOR_INDEX(XmlEnumeration):
88+
"""
89+
Specifies a standard preset color to apply. Used for font highlighting and
90+
perhaps other applications.
91+
"""
92+
93+
__ms_name__ = 'WdColorIndex'
94+
95+
__url__ = 'https://msdn.microsoft.com/EN-US/library/office/ff195343.aspx'
96+
97+
__members__ = (
98+
XmlMappedEnumMember(
99+
None, None, None, 'Color is inherited from the style hierarchy.'
100+
),
101+
XmlMappedEnumMember(
102+
'AUTO', 0, 'default', 'Automatic color. Default; usually black.'
103+
),
104+
XmlMappedEnumMember(
105+
'BLACK', 1, 'black', 'Black color.'
106+
),
107+
XmlMappedEnumMember(
108+
'BLUE', 2, 'blue', 'Blue color'
109+
),
110+
XmlMappedEnumMember(
111+
'BRIGHT_GREEN', 4, 'green', 'Bright green color.'
112+
),
113+
XmlMappedEnumMember(
114+
'DARK_BLUE', 9, 'darkBlue', 'Dark blue color.'
115+
),
116+
XmlMappedEnumMember(
117+
'DARK_RED', 13, 'darkRed', 'Dark red color.'
118+
),
119+
XmlMappedEnumMember(
120+
'DARK_YELLOW', 14, 'darkYellow', 'Dark yellow color.'
121+
),
122+
XmlMappedEnumMember(
123+
'GRAY_25', 16, 'lightGray', '25% shade of gray color.'
124+
),
125+
XmlMappedEnumMember(
126+
'GRAY_50', 15, 'darkGray', '50% shade of gray color.'
127+
),
128+
XmlMappedEnumMember(
129+
'GREEN', 11, 'darkGreen', 'Green color.'
130+
),
131+
XmlMappedEnumMember(
132+
'PINK', 5, 'magenta', 'Pink color.'
133+
),
134+
XmlMappedEnumMember(
135+
'RED', 6, 'red', 'Red color.'
136+
),
137+
XmlMappedEnumMember(
138+
'TEAL', 10, 'darkCyan', 'Teal color.'
139+
),
140+
XmlMappedEnumMember(
141+
'TURQUOISE', 3, 'cyan', 'Turquoise color.'
142+
),
143+
XmlMappedEnumMember(
144+
'VIOLET', 12, 'darkMagenta', 'Violet color.'
145+
),
146+
XmlMappedEnumMember(
147+
'WHITE', 8, 'white', 'White color.'
148+
),
149+
XmlMappedEnumMember(
150+
'YELLOW', 7, 'yellow', 'Yellow color.'
151+
),
152+
)
153+
154+
87155
class WD_LINE_SPACING(XmlEnumeration):
88156
"""
89157
Specifies a line spacing format to be applied to a paragraph.

features/steps/font.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from docx import Document
1414
from docx.dml.color import ColorFormat
1515
from docx.enum.dml import MSO_COLOR_TYPE, MSO_THEME_COLOR
16-
from docx.enum.text import WD_UNDERLINE
16+
from docx.enum.text import WD_COLOR_INDEX, WD_UNDERLINE
1717
from docx.shared import RGBColor
1818

1919
from helpers import test_docx
@@ -27,6 +27,17 @@ def given_a_font(context):
2727
context.font = document.paragraphs[0].runs[0].font
2828

2929

30+
@given('a font having {color} highlighting')
31+
def given_a_font_having_color_highlighting(context, color):
32+
paragraph_index = {
33+
'no': 0,
34+
'yellow': 1,
35+
'bright green': 2,
36+
}[color]
37+
document = Document(test_docx('txt-font-highlight-color'))
38+
context.font = document.paragraphs[paragraph_index].runs[0].font
39+
40+
3041
@given('a font having {type} color')
3142
def given_a_font_having_type_color(context, type):
3243
run_idx = ['no', 'auto', 'an RGB', 'a theme'].index(type)
@@ -94,6 +105,15 @@ def when_I_assign_value_to_font_color_theme_color(context, value):
94105
font.color.theme_color = new_value
95106

96107

108+
@when('I assign {value} to font.highlight_color')
109+
def when_I_assign_value_to_font_highlight_color(context, value):
110+
font = context.font
111+
expected_value = (
112+
None if value == 'None' else getattr(WD_COLOR_INDEX, value)
113+
)
114+
font.highlight_color = expected_value
115+
116+
97117
@when('I assign {value} to font.name')
98118
def when_I_assign_value_to_font_name(context, value):
99119
font = context.font
@@ -170,6 +190,15 @@ def then_font_color_type_is_value(context, value):
170190
assert font.color.type == expected_value
171191

172192

193+
@then('font.highlight_color is {value}')
194+
def then_font_highlight_color_is_value(context, value):
195+
font = context.font
196+
expected_value = (
197+
None if value == 'None' else getattr(WD_COLOR_INDEX, value)
198+
)
199+
assert font.highlight_color == expected_value
200+
201+
173202
@then('font.name is {value}')
174203
def then_font_name_is_value(context, value):
175204
font = context.font
Binary file not shown.

features/txt-font-props.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ Feature: Get or set font properties
44
I need a set of read/write properties on the Font object
55

66

7+
@wip
8+
Scenario Outline: Get highlight color
9+
Given a font having <color> highlighting
10+
Then font.highlight_color is <value>
11+
12+
Examples: font.highlight_color values
13+
| color | value |
14+
| no | None |
15+
| yellow | YELLOW |
16+
| bright green | BRIGHT_GREEN |
17+
18+
19+
@wip
20+
Scenario Outline: Set highlight color
21+
Given a font having <color> highlighting
22+
When I assign <value> to font.highlight_color
23+
Then font.highlight_color is <value>
24+
25+
Examples: font.highlight_color values
26+
| color | value |
27+
| no | YELLOW |
28+
| yellow | None |
29+
| bright green | BRIGHT_GREEN |
30+
31+
732
Scenario Outline: Get typeface name
833
Given a font having typeface name <name>
934
Then font.name is <value>

0 commit comments

Comments
 (0)