def doPaint( self, text, antialias=True, color=( 255, 255, 255), background=None): """Render the __font onto a new Surface and return it. We ignore 'antialias' and use system settings. text -- (unicode) string with the text to doPaint antialias -- attempt to antialias the text or not color -- three or four-tuple of 0-255 values specifying rendering colour for the text background -- three or four-tuple of 0-255 values specifying rendering colour for the background, or None for trasparent background returns a pygame image instance """ log.info( 'doPaint: %r, antialias = %s, color=%s, background=%s', text, antialias, color, background) layout = self._createLayout(text) # determine pixel __size (logical, ink) = layout.get_pixel_extents() ink = pygame.rect.Rect(ink) # Create a new Cairo ImageSurface csrf, cctx = _cairoimage.newContext(ink.w, ink.h) cctx = pangocairo.CairoContext(cctx) # Mangle the colors on little-endian machines. The reason for this # is that Cairo writes native-endian 32-bit ARGB values whereas # Pygame expects endian-independent values in whatever format. So we # tell our users not to expect transparency here (avoiding the A issue) # and we swizzle all the colors around. # doPaint onto it if background is not None: background = _cairoimage.mangle_color(background) cctx.set_source_rgba(*background) cctx.paint() log.debug('incoming color: %s', color) color = _cairoimage.mangle_color(color) log.debug(' translated color: %s', color) cctx.new_path() cctx.layout_path(layout) cctx.set_source_rgba(*color) cctx.fill() # Create and return a new Pygame Image derived from the Cairo Surface return _cairoimage.asImage(csrf)
def render(self, text, antialias=True, color=(255,255,255), background=None ): """Render the font onto a new Surface and return it. We ignore 'antialias' and use system settings. text -- (unicode) string with the text to render antialias -- attempt to antialias the text or not color -- three or four-tuple of 0-255 values specifying rendering colour for the text background -- three or four-tuple of 0-255 values specifying rendering colour for the background, or None for trasparent background returns a pygame image instance """ log.info( 'render: %r, antialias = %s, color=%s, background=%s', text, antialias, color, background ) # create layout layout = pango.Layout(gtk.gdk.pango_context_get()) layout.set_font_description(self.fd) if self.underline: attrs = layout.get_attributes() if not attrs: attrs = pango.AttrList() attrs.insert(pango.AttrUnderline(pango.UNDERLINE_SINGLE, 0, 32767)) layout.set_attributes( attrs ) layout.set_text(text) # determine pixel size (logical, ink) = layout.get_pixel_extents() ink = pygame.rect.Rect(ink) # Create a new Cairo ImageSurface csrf,cctx = _cairoimage.newContext( ink.w, ink.h ) cctx = pangocairo.CairoContext(cctx) # Mangle the colors on little-endian machines. The reason for this # is that Cairo writes native-endian 32-bit ARGB values whereas # Pygame expects endian-independent values in whatever format. So we # tell our users not to expect transparency here (avoiding the A issue) # and we swizzle all the colors around. # render onto it if background is not None: background = _cairoimage.mangle_color( background ) cctx.set_source_rgba(*background) cctx.paint() log.debug( 'incoming color: %s', color ) color = _cairoimage.mangle_color( color ) log.debug( ' translated color: %s', color ) cctx.new_path() cctx.layout_path(layout) cctx.set_source_rgba(*color) cctx.fill() # Create and return a new Pygame Image derived from the Cairo Surface return _cairoimage.asImage( csrf )