@@ -350,9 +350,12 @@ def __init__(self, text, font, direction, width):
350
350
self .curCharWidth = 0
351
351
self .prevCharWidth = 0
352
352
self .currentTotalWidth = 0
353
+ self .previousTotalWidth = 0
353
354
self .maxSmush = 0
355
+ self .previousSmush = 0
354
356
self .product = FigletProduct ()
355
357
self .buffer = ['' for i in range (self .font .height )]
358
+ self .blank_markers = list ()
356
359
357
360
# constants.. lifted from figlet222
358
361
self .SM_EQUAL = 1 # smush equal chars (not hardblanks)
@@ -428,36 +431,49 @@ def addCurCharRowToBufferRow(self, curChar, row):
428
431
def cutBufferAtLastBlank (self , last_blank ):
429
432
cut_buffer = [row [:last_blank ] for row in self .buffer ]
430
433
self .product .append (cut_buffer )
431
- self .buffer = [self .buffer [row ][last_blank + 1 :] for row in range (self .font .height )]
434
+ self .buffer = [self .buffer [row ][last_blank + self . font . width [ ord ( ' ' )] - 1 :] for row in range (self .font .height )]
432
435
self .currentTotalWidth = len (self .buffer [0 ])
436
+ self .blank_markers = list ()
437
+
438
+
439
+ def cutBufferAtLastChar (self ):
440
+ raise NotImplementedError ()
441
+
433
442
434
443
def blankExist (self , last_blank ):
435
444
return last_blank != - 1
436
445
437
446
def getLastBlank (self ):
438
- last_blank = self .buffer [0 ].rfind (self .font .hardBlank )
439
- while last_blank > self .width :
440
- last_blank = self .buffer [0 ].rfind (self .font .hardBlank , 0 , last_blank )
447
+ try :
448
+ last_blank = self .blank_markers .pop ()
449
+ except IndexError :
450
+ return - 1
441
451
return last_blank
442
452
443
453
def handleNewLine (self ):
444
454
last_blank = self .getLastBlank ()
445
455
if self .blankExist (last_blank ):
446
456
self .cutBufferAtLastBlank (last_blank )
447
457
else :
448
- raise NotImplementedError ()
458
+ self . cutBufferAtLastChar ()
449
459
450
460
def addCharToBuffer (self ):
451
461
curChar = self ._getCurChar ()
452
462
if curChar is None :
453
463
return
454
464
self .curCharWidth = self ._getCurWidth ()
465
+ self .previousSmush = self .maxSmush
466
+ self .previousWidth = self .currentTotalWidth
455
467
self .maxSmush = self .currentSmushAmount (curChar )
456
468
self .currentTotalWidth += self .curCharWidth - self .maxSmush
457
469
458
470
if (self .currentTotalWidth > self .width ):
459
471
self .handleNewLine ()
460
472
473
+ if self .text [self .iterator ] == ord (' ' ):
474
+ self .blank_markers .append (len (self .buffer [0 ]))
475
+
476
+
461
477
for row in range (0 , self .font .height ):
462
478
self .addCurCharRowToBufferRow (curChar , row )
463
479
0 commit comments