本文整理匯總了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)