Debian Codegraph @

examples/cairo_snippets/snippets/text_align_center.py

raw symbols SCIP
1 from math import pi
2 import cairo
3
4
5 def draw(cr, width, height):
6 cr.scale(width, height)
7 cr.set_line_width(0.04)
8
9 utf8 = "cairo"
10
11 cr.select_font_face("Sans",
12 cairo.FONT_SLANT_NORMAL,
13 cairo.FONT_WEIGHT_NORMAL)
14
15 cr.set_font_size(0.2)
16 x_bearing, y_bearing, width, height, x_advance, y_advance = \
17 cr.text_extents(utf8)
18 x = 0.5 - (width / 2 + x_bearing)
19 y = 0.5 - (height / 2 + y_bearing)
20
21 cr.move_to(x, y)
22 cr.show_text(utf8)
23
24 # draw helping lines
25 cr.set_source_rgba(1, 0.2, 0.2, 0.6)
26 cr.arc(x, y, 0.05, 0, 2 * pi)
27 cr.fill()
28 cr.move_to(0.5, 0)
29 cr.rel_line_to(0, 1)
30 cr.move_to(0, 0.5)
31 cr.rel_line_to(1, 0)
32 cr.stroke()