[cairo] connecting lines
Donn
donn.ingle at gmail.com
Wed Nov 7 11:02:24 PST 2007
Hi, can't reply to my own post since I don't see it courtesy of gmail :(
I reproduced the error, here is some code. I'm sure I'm being thick, which is
par for the course :)
There should be no line between the arc and the text.
/d
#! /usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk, gobject, cairo
import math
# Create a GTK+ widget on which we will draw using Cairo
class Screen(gtk.DrawingArea):
# Draw in response to an expose-event
__gsignals__ = { "expose-event": "override" }
# Handle the expose-event by drawing
def do_expose_event(self, event):
# Create the cairo context
cr = self.window.cairo_create()
# Restrict Cairo to the exposed area; avoid extra work
cr.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
cr.clip()
self.draw(cr, *self.window.get_size())
def draw(self, cr, width, height):
# Fill the background with gray
cr.set_source_rgb(0.5, 0.5, 0.5)
cr.rectangle(0, 0, width, height)
cr.fill()
# GTK mumbo-jumbo to show the widget in a window and quit when it's closed
def run(Widget):
window = gtk.Window()
window.set_size_request(400, 400)
window.connect("delete-event", gtk.main_quit)
widget = Widget()
widget.show()
window.add(widget)
window.present()
gtk.main()
#######################
## Do all your testing in Shapes ##
#######################
class Shapes(Screen):
def draw(self, cr, width, height):
ctx = cr
matrix = cairo.Matrix(1,0,0,1,200, 200)
ctx.transform(matrix)
ctx.save()
print "##Draw Square"
ctx.set_source_rgb(1, 0, 0)
ctx.rectangle(0, 0, 50, 50)
ctx.fill()
ctx.set_source_rgb(0.0, 0.0, 0.0)
ctx.select_font_face("",
cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
ctx.set_font_size(128)
x_bearing, y_bearing, width, height =ctx.text_extents("a")[:4]
ctx.move_to(-120 - x_bearing, -120 - y_bearing)
ctx.show_text("15")
print "##Draw Circle"
ctx.arc(0,0, 25, 0, 2.0 * math.pi)
ctx.set_source_rgb(1, 0, 1)
ctx.fill_preserve()
ctx.set_source_rgb(0, 0, 0)
ctx.stroke()
ctx.set_source_rgb(1, 10, 0)
ctx.rectangle(-10, -10, 10, 10)
ctx.fill()
ctx.restore()
run(Shapes)
More information about the cairo
mailing list