[cairo] Text Antialiasing

Tim Flink tim at mail.mew.co.jp
Thu Feb 22 17:37:41 PST 2007


I'm new to cairo and I have some questions about pycairo 1.2.6

I would like to use antialiased text, but I haven't been able to get it
to work yet. At the moment I am creating a new cairo.FontOptions object
and using the FontObjects.set_antialias() method in an attempt to get
antialiased text but it doesn't seem to be working.

What is the correct way to get cairo to write anti-aliased text using
pycairo?

Any help would be greatly appreciated.

Thanks,

Tim

Code was written for Python 2.5 and pycairo1.2.6 (binary forWin32 and
Python2.5) under Windows XP SP2, Japanese Language Edition
-------------- next part --------------
#! /usr/bin/env python
import cairo

surface = cairo.SVGSurface('cairoAliasing.svg', 137, 60)
cr = cairo.Context(surface)
fo = cairo.FontOptions()


text = 'penny thoughts'
cr.select_font_face('Arial', cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
cr.set_font_size(16)
fo.set_hint_style(5)
fo.set_antialias(cairo.ANTIALIAS_DEFAULT)
xbearing, ybearing, width, height, xadvance, yadvance = cr.text_extents(text)

text_x = ( 137/2 ) - ( width/2 )
text_y = ( 60/2 ) + ( height/2 )	

cr.move_to(text_x, text_y)
cr.set_source_rgb(0, 0, 0)
cr.show_text(text)

surface.write_to_png('cairoAliasing.png')
cr.show_page()
surface.finish()


More information about the cairo mailing list