[cairo] trouble with show_text in PyCairo.

Anton Nagorniy anton20vlad at mail.ru
Thu Nov 6 12:07:50 PST 2008


I am new to cairo.

Here is my script

import cairo

WIDTH, HEIGHT = 400, 400

# Setup Cairo
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)

# Set thickness of brush
ctx.set_line_width(15)

# Draw out the triangle using absolute coordinates
ctx.move_to(200, 100)
ctx.line_to(300, 300)
ctx.rel_line_to(-200, 0)

ctx.set_source_rgb(0.0, 0.0, 0.0)
ctx.select_font_face("Georgia", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
ctx.set_font_size(1.2)
x_bearing, y_bearing, width, height = ctx.text_extents("a")[:4]
ctx.move_to(0.5 - width / 2 - x_bearing, 0.5 - height / 2 - y_bearing)
ctx.show_text("a")

ctx.close_path()
# Apply the ink
ctx.stroke()

# Output a PNG file
surface.write_to_png("triangle.png")




It causes an error:
Traceback (most recent call last):
  File "draw_image.py", line 20, in <module>
    x_bearing, y_bearing, width, height = ctx.text_extents("a")[:4]
MemoryError

Please tell me what is wrong with that script and how to fix that error?




More information about the cairo mailing list