Example #1
0
    def render(self, text, antialias=True, color=(0,0,0), background=None, surface=None):      #optional surface for text rendering
        """
        Render text onto surface.
        Arguments are text to render, and optional antialias, RGB color of text, RGB color of background, and surface for text rendering.
        """
        if not surface:
            w,h = self.size(text)
            surf = Surface((w,h))
        else:
            surf = surface
            w,h = surface.width, surface.height
        if background:
            surf.setFillStyle(Color(background))
            surf.fillRect(0,0,w,h)
        surf.setFont('%s %dpx %s' % (self.fontstyle, self.fontsize, self.fontname))
#        if antialias: pass
        surf.setFillStyle(Color(color))
        surf.setTextAlign('center')
        surf.setTextBaseline('middle')
        surf.fillText(text,w/2,h/2)
        if self.underline:
            surf.setLineWidth(self.fontsize/20)
            surf.setStrokeStyle(Color(color))
            surf.beginPath()
            surf.moveTo(0, h*0.85)
            surf.lineTo(w, h*0.85)
            surf.stroke()
        return surf
Example #2
0
 def render(self,
            text,
            antialias=True,
            color=(0, 0, 0),
            background=None,
            surface=None):  #optional surface for text rendering
     """
     Render text onto surface.
     Arguments are text to render, and optional antialias, RGB color of text, RGB color of background, and surface for text rendering.
     """
     if not surface:
         w, h = self.size(text)
         surf = Surface((w, h))
     else:
         surf = surface
         w, h = surface.width, surface.height
     if background:
         surf.setFillStyle(Color(background))
         surf.fillRect(0, 0, w, h)
     surf.setFont('%s %dpx %s' %
                  (self.fontstyle, self.fontsize, self.fontname))
     #        if antialias: pass
     surf.setFillStyle(Color(color))
     surf.setTextAlign('center')
     surf.setTextBaseline('middle')
     surf.fillText(text, w / 2, h / 2)
     if self.underline:
         surf.setLineWidth(self.fontsize / 20)
         surf.setStrokeStyle(Color(color))
         surf.beginPath()
         surf.moveTo(0, h * 0.85)
         surf.lineTo(w, h * 0.85)
         surf.stroke()
     return surf