@@ -6,6 +6,7 @@ An internal module for laying out text according to options and constraints.
6
6
This is not part of the API and may change at any time.
7
7
'''
8
8
9
+ import string
9
10
10
11
__all__ = (' layout_text' , ' LayoutWord' , ' LayoutLine' )
11
12
@@ -147,7 +148,7 @@ cdef inline void final_strip(LayoutLine line):
147
148
line.w -= last_word.lw # likely 0
148
149
continue
149
150
150
- stripped = last_word.text.rstrip() # ends with space
151
+ stripped = last_word.text.rstrip(string.whitespace ) # ends with space
151
152
# subtract ending space length
152
153
diff = ((len (last_word.text) - len (stripped)) *
153
154
last_word.options[' space_width' ])
@@ -187,10 +188,10 @@ cdef inline layout_text_unrestricted(object text, list lines, int w, int h,
187
188
k = n - 1
188
189
if strip:
189
190
if not _line.w: # no proceeding text: strip leading
190
- line = line.lstrip()
191
+ line = line.lstrip(string.whitespace )
191
192
# ends this line so right strip
192
193
if complete or (dwn and n > 1 or not dwn and pos > 1 ):
193
- line = line.rstrip()
194
+ line = line.rstrip(string.whitespace )
194
195
lw, lh = get_extents(line)
195
196
196
197
old_lh = _line.h
@@ -217,9 +218,9 @@ cdef inline layout_text_unrestricted(object text, list lines, int w, int h,
217
218
# the last line is only stripped from left
218
219
if strip:
219
220
if complete or (dwn and i < n - 1 or not dwn and i > s):
220
- line = line.strip()
221
+ line = line.strip(string.whitespace )
221
222
else :
222
- line = line.lstrip()
223
+ line = line.lstrip(string.whitespace )
223
224
lw, lh = get_extents(line)
224
225
lhh = int (lh * line_height)
225
226
if uh != - 1 and h + lhh > uh and pos: # too high
@@ -424,9 +425,9 @@ def layout_text(object text, list lines, tuple size, tuple text_size,
424
425
line = new_lines[i]
425
426
if strip:
426
427
if not _line.w: # there's no proceeding text, so strip leading
427
- line = line.lstrip()
428
+ line = line.lstrip(string.whitespace )
428
429
if ends_line:
429
- line = line.rstrip()
430
+ line = line.rstrip(string.whitespace )
430
431
k = len (line)
431
432
if not k: # just add empty line if empty
432
433
_line.is_last_line = ends_line # nothing will be appended
@@ -474,7 +475,7 @@ def layout_text(object text, list lines, tuple size, tuple text_size,
474
475
if s != m:
475
476
_do_last_line = 1
476
477
if strip and line[m - 1 ] == ' ' :
477
- ln = line[s:m].rstrip()
478
+ ln = line[s:m].rstrip(string.whitespace )
478
479
lww, lhh = get_extents(ln)
479
480
else :
480
481
ln = line[s:m]
@@ -494,7 +495,7 @@ def layout_text(object text, list lines, tuple size, tuple text_size,
494
495
# try to fit word on new line, if it doesn't fit we'll
495
496
# have to break the word into as many lines needed
496
497
if strip:
497
- s = e - len (line[s:e].lstrip())
498
+ s = e - len (line[s:e].lstrip(string.whitespace ))
498
499
if s == e: # if it was only a stripped space, move on
499
500
m = s
500
501
continue
0 commit comments