Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Last active March 31, 2024 14:00
Show Gist options
  • Save pointofpresence/c3e873afb04a14d9d1624ef78d1bb2de to your computer and use it in GitHub Desktop.
Save pointofpresence/c3e873afb04a14d9d1624ef78d1bb2de to your computer and use it in GitHub Desktop.
Python: Текст по центру холста (Cairo)
context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
context.set_font_size(52.0)
(x, y, width, height, dx, dy) = context.text_extents("Hello")
context.move_to(WIDTH/2. - width/2., HEIGHT/2. + height/2.)
context.show_text("Hello")
"""
Указанный код рисует текст "Hello" по центру холста, выравнивая его горизонтально и вертикально
с использованием информации о геометрии текста (width, height, dx, dy), полученной из text_extents.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment