Esempio n. 1
0
 def render_fill(cls, text, font_info, surface):
     font = SysFont(font_info.name, font_info.size)        
     font.set_bold(font_info.bold)
     font.set_italic(font_info.italic)
     words = text.split()
     word_surfaces = []
     whitespace = font.render(" ", True, font_info.fcolor, font_info.bcolor)
     for word in words:
         word_surfaces.append(font.render(word, True, font_info.fcolor,
                                          font_info.bcolor))
     
     sf_width = surface.get_width()
     line = []
     line.free = sf_width
     lines = [line]
     max_height = max([surface.get_height() for surface in word_surfaces])
     cur_height = max_height
     for sf in word_surfaces:
         if lines[-1].free == sf_width:
             assert(sf_width < sf.get_width())
             lines[-1].append(sf)
             lines[-1].free -= sf.get_width()
         else:
             if sf.get_width() + whitespace.get_width() > lines[-1].free:
                 lines[-1].append(sf)
                 lines[-1].free -= sf.get_width() + whitespace.get_width() 
             else:
                 if (cur_height + (1 + font_info.spacing) * max_height < 
                     surface.get_width()):
                     assert(sf_width < sf.get_width())
                     line = []
     pass
Esempio n. 2
0
 def render_column(cls, lines, font_info, surface):
     font = SysFont(font_info.name, font_info.size)        
     font.set_bold(font_info.bold)
     font.set_italic(font_info.italic)
     line_surfaces = []
     for line in lines:
         line_surfaces.append(font.render(line, True, font_info.fcolor,
                                          font_info.bcolor))
     max_height = max([sf.get_height() for sf in line_surfaces])
     spacing = ((surface.get_height() - max_height * len(lines))
                 / (len(lines) + 1))
     for sf, y in zip(line_surfaces,
             range(spacing, surface.get_height(), spacing + max_height)):
         surface.blit(sf, (0, y))