GeezerVison is showing github.com — acpt: add scenarios for Font.highlight_color · python-openxml/python-docx@c25b7f3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +60Lines changed: 60 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 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. |
Collapse file Copy file name to clipboardExpand all lines: docs/api/enum/index.rst +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ can be found here: | 12 | 12 | MsoThemeColorIndex | 13 | 13 | WdAlignParagraph | 14 | 14 | WdBuiltinStyle | | 15 | + WdColorIndex | 15 | 16 | WdLineSpacing | 16 | 17 | WdOrientation | 17 | 18 | WdSectionStart | |
Collapse file Copy file name to clipboardExpand all lines: docx/enum/text.py +68Lines changed: 68 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,6 +84,74 @@ class WD_BREAK_TYPE(object): | 84 | 84 | WD_BREAK = WD_BREAK_TYPE | 85 | 85 |
| 86 | 86 |
| | 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 | + | 87 | 155 | class WD_LINE_SPACING(XmlEnumeration): | 88 | 156 | """ | 89 | 157 | Specifies a line spacing format to be applied to a paragraph. | |
Collapse file Copy file name to clipboardExpand all lines: features/steps/font.py +30-1Lines changed: 30 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | from docx import Document | 14 | 14 | from docx.dml.color import ColorFormat | 15 | 15 | 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 | 17 | 17 | from docx.shared import RGBColor | 18 | 18 |
| 19 | 19 | from helpers import test_docx | @@ -27,6 +27,17 @@ def given_a_font(context): | 27 | 27 | context.font = document.paragraphs[0].runs[0].font | 28 | 28 |
| 29 | 29 |
| | 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 | + | 30 | 41 | @given('a font having {type} color') | 31 | 42 | def given_a_font_having_type_color(context, type): | 32 | 43 | 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): | 94 | 105 | font.color.theme_color = new_value | 95 | 106 |
| 96 | 107 |
| | 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 | + | 97 | 117 | @when('I assign {value} to font.name') | 98 | 118 | def when_I_assign_value_to_font_name(context, value): | 99 | 119 | font = context.font | @@ -170,6 +190,15 @@ def then_font_color_type_is_value(context, value): | 170 | 190 | assert font.color.type == expected_value | 171 | 191 |
| 172 | 192 |
| | 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 | + | 173 | 202 | @then('font.name is {value}') | 174 | 203 | def then_font_name_is_value(context, value): | 175 | 204 | font = context.font | |
Collapse file Copy file name to clipboard Collapse file Copy file name to clipboardExpand all lines: features/txt-font-props.feature +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,31 @@ Feature: Get or set font properties | 4 | 4 | I need a set of read/write properties on the Font object | 5 | 5 |
| 6 | 6 |
| | 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 | + | 7 | 32 | Scenario Outline: Get typeface name | 8 | 33 | Given a font having typeface name <name> | 9 | 34 | Then font.name is <value> | |
|