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(
24
24
indent0 : str = "" ,
25
25
indent1 : str = "" ,
26
26
) -> 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
28
28
29
29
"""wrap_text_to_pixels function
30
30
A helper that will return a list of lines with word-break wrapping.
@@ -62,23 +62,38 @@ def measure(text):
62
62
swidth = measure (" " )
63
63
firstword = True
64
64
for line_in_input in string .split ("\n " ):
65
+ newline = True
65
66
for index , word in enumerate (line_in_input .split (" " )):
66
67
wwidth = measure (word )
67
68
word_parts = []
68
69
cur_part = ""
69
70
70
71
if wwidth > max_width :
71
72
for char in word :
73
+ if newline :
74
+ extraspace = 0
75
+ leadchar = ""
76
+ else :
77
+ extraspace = swidth
78
+ leadchar = " "
72
79
if (
73
80
measure ("" .join (partial ))
74
81
+ measure (cur_part )
75
82
+ measure (char )
76
83
+ measure ("-" )
84
+ + extraspace
77
85
> max_width
78
86
):
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 ))
80
94
cur_part = char
81
95
partial = [indent1 ]
96
+ newline = True
82
97
else :
83
98
cur_part += char
84
99
if cur_part :
@@ -103,6 +118,8 @@ def measure(text):
103
118
lines .append ("" .join (partial ))
104
119
partial = [indent1 , word ]
105
120
width = measure (indent1 ) + wwidth
121
+ if newline :
122
+ newline = False
106
123
107
124
lines .append ("" .join (partial ))
108
125
partial = [indent1 ]
You can’t perform that action at this time.
0 commit comments