File: text.py

package info (click to toggle)
py3cairo 1.10.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,308 kB
  • sloc: python: 12,287; ansic: 4,349; makefile: 141; sh: 32
file content (41 lines) | stat: -rwxr-xr-x 875 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python

import cairo
import gtk


def expose_event(widget, event):
    ctx = widget.window.cairo_create()

    ctx.set_line_width(6)
    ctx.set_tolerance(.1)

    ctx.select_font_face('sans-serif')
    ctx.set_font_size(48)
    (x, y, width, height, dx, dy) = ctx.text_extents('Hello World')

    ctx.translate (100, 100)

    ctx.new_path()
    ctx.move_to(x-10,y-10)
    ctx.rel_line_to(width + 20, 0)
    ctx.rel_line_to(0, height + 20)
    ctx.rel_line_to(-(width + 20), 0)
    ctx.close_path()
    ctx.set_source_rgb(0,0,1)
    ctx.stroke()

    ctx.move_to(0, 0)
    ctx.set_source_rgb(0,0,0)
    ctx.show_text('Hello World')

win = gtk.Window()
win.connect('destroy', gtk.main_quit)

drawingarea = gtk.DrawingArea()
win.add(drawingarea)
drawingarea.connect('expose_event', expose_event)
drawingarea.set_size_request(400,150)

win.show_all()
gtk.main()