X Tutup
Skip to content

Commit 194f77d

Browse files
author
Steve Canny
committed
run: convert CT_Underline.val setter to to_xml()
1 parent c46f822 commit 194f77d

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

docx/oxml/text.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -845,25 +845,13 @@ def val(self):
845845

846846
@val.setter
847847
def val(self, value):
848-
underline_vals = {
849-
True: 'single',
850-
False: 'none',
851-
WD_UNDERLINE.WORDS: 'words',
852-
WD_UNDERLINE.DOUBLE: 'double',
853-
WD_UNDERLINE.DOTTED: 'dotted',
854-
WD_UNDERLINE.THICK: 'thick',
855-
WD_UNDERLINE.DASH: 'dash',
856-
WD_UNDERLINE.DOT_DASH: 'dotDash',
857-
WD_UNDERLINE.DOT_DOT_DASH: 'dotDotDash',
858-
WD_UNDERLINE.WAVY: 'wave',
859-
WD_UNDERLINE.DOTTED_HEAVY: 'dottedHeavy',
860-
WD_UNDERLINE.DASH_HEAVY: 'dashedHeavy',
861-
WD_UNDERLINE.DOT_DASH_HEAVY: 'dashDotHeavy',
862-
WD_UNDERLINE.DOT_DOT_DASH_HEAVY: 'dashDotDotHeavy',
863-
WD_UNDERLINE.WAVY_HEAVY: 'wavyHeavy',
864-
WD_UNDERLINE.DASH_LONG: 'dashLong',
865-
WD_UNDERLINE.WAVY_DOUBLE: 'wavyDouble',
866-
WD_UNDERLINE.DASH_LONG_HEAVY: 'dashLongHeavy',
867-
}
868-
val = underline_vals[value]
848+
# works fine without these two mappings, but only because True == 1
849+
# and False == 0, which happen to match the mapping for WD_UNDERLINE
850+
# .SINGLE and .NONE respectively.
851+
if value is True:
852+
value = WD_UNDERLINE.SINGLE
853+
elif value is False:
854+
value = WD_UNDERLINE.NONE
855+
856+
val = WD_UNDERLINE.to_xml(value)
869857
self.set(qn('w:val'), val)

0 commit comments

Comments
 (0)
X Tutup