本文整理汇总了Python中cairo.Context.select_font_face方法的典型用法代码示例。如果您正苦于以下问题:Python Context.select_font_face方法的具体用法?Python Context.select_font_face怎么用?Python Context.select_font_face使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.select_font_face方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import select_font_face [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
for b in self._buttons:
b.set_shape_from_context(context)
shapes = [b.shape for b in self._buttons]
context.save()
context.select_font_face("", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
xb, yb, w, h, xa, ya = context.text_extents(self.title)
width = max(shape.width for shape in shapes)
width = max(width, xa)
container_width = self.container_size[0]
translation = Point(0, self.distance)
if container_width > width:
translation += Point((container_width)/2, 0)
else:
translation += Point(width/2, 0)
context.move_to(translation.x - xa/2, h + 2 * self.distance)
context.show_text(self.title)
context.restore()
height = h + self.distance * 3
for b in self._buttons:
height += b.shape.height + self.distance
self.min_size = width + 2 * self.distance, height + self.distance
start_point = context.get_current_point()
translation += Point(0, h + self.distance * 3)
context.translate(translation.x, translation.y)
distance_offset = Point(0, self.distance)
for b in self._buttons:
context.move_to(*start_point)
b.set_translate(translation.x, translation.y)
context.save()
b.on_draw(widget, context)
context.restore()
to_translate = Point(distance_offset.x,
distance_offset.y + b.shape.height)
context.translate(to_translate.x, to_translate.y)
translation += to_translate
示例2: _set_font
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import select_font_face [as 别名]
def _set_font(self, context: cairo.Context):
context.set_font_size(self.font_size)
slant = cairo.FONT_SLANT_NORMAL if not self.italic else cairo.FONT_SLANT_ITALIC
weight = cairo.FONT_WEIGHT_NORMAL if not self.bold else cairo.FONT_WEIGHT_BOLD
context.select_font_face("", slant, weight)