本文整理汇总了Python中variety.Util.Util.compute_trimmed_offsets方法的典型用法代码示例。如果您正苦于以下问题:Python Util.compute_trimmed_offsets方法的具体用法?Python Util.compute_trimmed_offsets怎么用?Python Util.compute_trimmed_offsets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类variety.Util.Util
的用法示例。
在下文中一共展示了Util.compute_trimmed_offsets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_quote_on_surface
# 需要导入模块: from variety.Util import Util [as 别名]
# 或者: from variety.Util.Util import compute_trimmed_offsets [as 别名]
def write_quote_on_surface(surface, quote, author=None, options=None, margin=30):
qcontext = cairo.Context(surface)
acontext = cairo.Context(surface)
iw = surface.get_width()
ih = surface.get_height()
sw = Gdk.Screen.get_default().get_width()
sh = Gdk.Screen.get_default().get_height()
trimw, trimh = Util.compute_trimmed_offsets((iw, ih), (sw, sh))
width = max(200, sw * options.quotes_width // 100) # use quotes_width percent of the visible width
qlayout = PangoCairo.create_layout(qcontext)
qlayout.set_width((width - 4 * margin) * Pango.SCALE)
qlayout.set_alignment(Pango.Alignment.LEFT)
qlayout.set_wrap(Pango.WrapMode.WORD)
font = options.quotes_font if options else "Bitstream Charter 30"
qlayout.set_font_description(Pango.FontDescription(font))
qlayout.set_text(quote, -1)
qheight = qlayout.get_pixel_size()[1]
qwidth = qlayout.get_pixel_size()[0]
if options.quotes_width < 98:
width = qwidth + 4 * margin
else:
width = sw
alayout = PangoCairo.create_layout(acontext)
aheight = 0
if author:
alayout.set_width(qwidth * Pango.SCALE)
alayout.set_alignment(Pango.Alignment.RIGHT)
alayout.set_wrap(Pango.WrapMode.WORD)
alayout.set_font_description(Pango.FontDescription(font))
alayout.set_text(author, -1)
aheight = alayout.get_pixel_size()[1]
height = qheight + aheight + 2.5*margin
bgc = options.quotes_bg_color
qcontext.set_source_rgba(bgc[0]/255.0, bgc[1]/255.0, bgc[2]/255.0, options.quotes_bg_opacity/100.0) # gray semi-transparent background
hpos = trimw + (sw - width) * options.quotes_hpos // 100
vpos = trimh + (sh - height) * options.quotes_vpos // 100
qcontext.rectangle(hpos, vpos, width, height)
qcontext.fill()
qcontext.translate(hpos + (width - qwidth)/2, vpos + margin)
if options.quotes_text_shadow:
qcontext.set_source_rgba(0, 0, 0, 0.2)
PangoCairo.update_layout(qcontext, qlayout)
PangoCairo.show_layout(qcontext, qlayout)
qcontext.translate(-2, -2)
tc = options.quotes_text_color
qcontext.set_source_rgb(tc[0]/255.0, tc[1]/255.0, tc[2]/255.0)
PangoCairo.update_layout(qcontext, qlayout)
PangoCairo.show_layout(qcontext, qlayout)
acontext.translate(hpos + (width - qwidth)/2, vpos + margin + qheight + margin/2)
if options.quotes_text_shadow:
acontext.set_source_rgba(0, 0, 0, 0.2)
PangoCairo.update_layout(acontext, alayout)
PangoCairo.show_layout(acontext, alayout)
acontext.translate(-2, -2)
acontext.set_source_rgb(tc[0]/255.0, tc[1]/255.0, tc[2]/255.0)
PangoCairo.update_layout(acontext, alayout)
PangoCairo.show_layout(acontext, alayout)
qcontext.show_page()
acontext.show_page()