[cairo] Text Antialiasing
Tim Flink
tim at mail.mew.co.jp
Fri Feb 23 00:45:02 PST 2007
Thanks for the tip. I changed my code so that I use set_font_options()
before rendering the text.
However, I still don't think that the output text is anti-aliased even
though running get_antialias() on the font confirms that it has been set
to cairo.ANTIALIAS_GRAY.
Is there something else that I am missing?
Thanks,
Tim
Behdad Esfahbod wrote:
> On Thu, 2007-02-22 at 20:37 -0500, Tim Flink wrote:
>
>> fo.set_hint_style(5)
>> fo.set_antialias(cairo.ANTIALIAS_DEFAULT)
>> xbearing, ybearing, width, height, xadvance, yadvance =
>> cr.text_extents(text)
>>
>
> You've got to do cr.set_font_options(fo) before measuring text.
>
>
-------------- next part --------------
#! /usr/bin/env python
# -*- coding: shift-jis -*-
import cairo
surface = cairo.SVGSurface('cairoAliasing.svg', 137, 60)
cr = cairo.Context(surface)
fo = cairo.FontOptions()
#set antialiasing
fo.set_antialias(cairo.ANTIALIAS_GRAY)
cr.set_font_options(fo)
#test with japanese characters
#text = '³CÈn'.decode('shift-jis')
#cr.select_font_face('IPA Mona Gothic', cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
#test with roman characters
text = 'penny'
cr.select_font_face('Arial', cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
cr.set_font_size(24)
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)
#get information about writing text
options = cr.get_font_options()
print "antialising: %d" % (options.get_antialias(),)
cr.show_text(text)
surface.write_to_png('cairoAliasing.png')
cr.show_page()
surface.finish()
More information about the cairo
mailing list