Debian Codegraph @

examples/cairo_snippets/snippets/text_extents.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.4)
16 x_bearing, y_bearing, width, height, x_advance, y_advance = \
17 cr.text_extents(utf8)
18
19 x = 0.1
20 y = 0.6
21
22 cr.move_to(x, y)
23 cr.show_text(utf8)
24
25 # draw helping lines
26 cr.set_source_rgba(1, 0.2, 0.2, 0.6)
27 cr.arc(x, y, 0.05, 0, 2 * pi)
28 cr.fill()
29 cr.move_to(x, y)
30 cr.rel_line_to(0, -height)
31 cr.rel_line_to(width, 0)
32 cr.rel_line_to(x_bearing, -y_bearing)
33 cr.stroke()