File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def wrap_text_to_pixels(
2424 indent0 : str = "" ,
2525 indent1 : str = "" ,
2626) -> List [str ]:
27- # pylint: disable=too-many-branches, too-many-locals
27+ # pylint: disable=too-many-branches, too-many-locals, too-many-nested-blocks, too-many-statements
2828
2929 """wrap_text_to_pixels function
3030 A helper that will return a list of lines with word-break wrapping.
@@ -62,23 +62,38 @@ def measure(text):
6262 swidth = measure (" " )
6363 firstword = True
6464 for line_in_input in string .split ("\n " ):
65+ newline = True
6566 for index , word in enumerate (line_in_input .split (" " )):
6667 wwidth = measure (word )
6768 word_parts = []
6869 cur_part = ""
6970
7071 if wwidth > max_width :
7172 for char in word :
73+ if newline :
74+ extraspace = 0
75+ leadchar = ""
76+ else :
77+ extraspace = swidth
78+ leadchar = " "
7279 if (
7380 measure ("" .join (partial ))
7481 + measure (cur_part )
7582 + measure (char )
7683 + measure ("-" )
84+ + extraspace
7785 > max_width
7886 ):
79- word_parts .append ("" .join (partial ) + cur_part + "-" )
87+ if cur_part :
88+ word_parts .append (
89+ "" .join (partial ) + leadchar + cur_part + "-"
90+ )
91+
92+ else :
93+ word_parts .append ("" .join (partial ))
8094 cur_part = char
8195 partial = [indent1 ]
96+ newline = True
8297 else :
8398 cur_part += char
8499 if cur_part :
@@ -103,6 +118,8 @@ def measure(text):
103118 lines .append ("" .join (partial ))
104119 partial = [indent1 , word ]
105120 width = measure (indent1 ) + wwidth
121+ if newline :
122+ newline = False
106123
107124 lines .append ("" .join (partial ))
108125 partial = [indent1 ]
You can’t perform that action at this time.
0 commit comments