当前位置: 首页>>代码示例>>Python>>正文


Python Context.set_font_face方法代码示例

本文整理汇总了Python中cairo.Context.set_font_face方法的典型用法代码示例。如果您正苦于以下问题:Python Context.set_font_face方法的具体用法?Python Context.set_font_face怎么用?Python Context.set_font_face使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cairo.Context的用法示例。


在下文中一共展示了Context.set_font_face方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_face [as 别名]

#.........这里部分代码省略.........
        self.stack.append(self.affine.terms())
        self.command('q')

    def restore(self):
        self.affine = Affine(*self.stack.pop())
        self.command('Q')

    def user_to_device(self, x, y):
        user = Point(x, y)
        device = self.affine(user)
        return (device.x, device.y)

    def device_to_user(self, x, y):
        device = Point(x, y)
        user = self.affine.inverse()(device)
        return (user.x, user.y)

    def move_to(self, x, y):
        self.point = Point(x, y)
        self.command('%.3f %.3f m' % (x, y))

    def rel_line_to(self, x, y):
        end = Point(x, y).add(self.point)
        self.point = end
        self.command('%.3f %.3f l' % (end.x, end.y))

    def set_source_rgb(self, r, g, b):
        self.command('%.3f %.3f %.3f rg' % (r, g, b))

    def fill(self):
        self.command('f')

    def set_source_surface(self, surf, x, y):
        """
        """
        dim = surf.get_width(), surf.get_height()
        img = Image.fromstring('RGBA', dim, surf.get_data())
        
        # weird channel order
        blue, green, red, alpha = img.split()
        img = Image.merge('RGB', (red, green, blue))

        png_buf = StringIO()
        img.save(png_buf, 'PNG')
        
        jpg_buf = StringIO()
        img.save(jpg_buf, 'JPEG', quality=75)
        
        if len(jpg_buf.getvalue()) < len(png_buf.getvalue()):
            method, buffer, suffix = 'raw_jpeg', jpg_buf, '.jpg'
        
        else:
            method, buffer, suffix = 'raw_png', png_buf, '.png'
        
        handle, filename = mkstemp(prefix='cairoutils-', suffix=suffix)
        self.command(method, filename)
        self.garbage.append(filename)

        write(handle, buffer.getvalue())
        close(handle)

    def paint(self):
        pass

    def set_line_width(self, w):
        self.command('%.3f w' % w)

    def set_dash(self, a):
        a = ' '.join(['%.3f' % v for v in a])
        self.command('[%s] 0 d' % a)

    def stroke(self):
        self.command('S')

    def rel_curve_to(self, a, b, c, d, e, f):
        p1 = Point(a, b).add(self.point)
        p2 = Point(c, d).add(self.point)
        p3 = Point(e, f).add(self.point)
        self.point = p3
        self.command('%.3f %.3f %.3f %.3f %.3f %.3f c' % (p1.x, p1.y, p2.x, p2.y, p3.x, p3.y))

    def set_font_face(self, font):
        self.context.set_font_face(font)

    def set_font_size(self, size):
        self.context.set_font_size(size)
        
        # SetFont here because only the size gives a clue to the correct weight
        self.command('SetFont', 'Liberation Sans', (size > 14) and 'B' or '')
        self.command('SetFontSize', size)

    def show_text(self, text):
        x, y = self.point.x, self.point.y
        text = text.decode('utf8')
        
        # invert the vertical flip in self.show_page() before showing text.
        self.command('q 1 0 0 -1 0 0 cm BT %.3f %.3f Td (%s) Tj ET Q' % (x, -y, text))

    def text_extents(self, text):
        return self.context.text_extents(text)
开发者ID:migurski,项目名称:paperwalking,代码行数:104,代码来源:cairoutils.py

示例2: __init__

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_font_face [as 别名]

#.........这里部分代码省略.........

    def device_to_user(self, x, y):
        device = Point(x, y)
        user = self.affine.inverse()(device)
        return (user.x, user.y)

    def move_to(self, x, y):
        self.point = Point(x, y)
        self.command("%.3f %.3f m" % (x, y))

    def line_to(self, x, y):
        self.point = Point(x, y)
        self.command("%.3f %.3f l" % (x, y))

    def rel_move_to(self, x, y):
        end = Point(x, y).add(self.point)
        self.point = end
        self.command("%.3f %.3f m" % (end.x, end.y))

    def rel_line_to(self, x, y):
        end = Point(x, y).add(self.point)
        self.point = end
        self.command("%.3f %.3f l" % (end.x, end.y))

    def set_source_rgb(self, r, g, b):
        self.command("%.3f %.3f %.3f rg" % (r, g, b))

    def fill(self):
        self.command("f")

    def set_source_surface(self, surf, x, y):
        """
        """
        dim = surf.get_width(), surf.get_height()
        img = Image.fromstring("RGBA", dim, surf.get_data())

        # weird channel order
        blue, green, red, alpha = img.split()
        img = Image.merge("RGB", (red, green, blue))

        png_buf = StringIO()
        img.save(png_buf, "PNG")

        jpg_buf = StringIO()
        img.save(jpg_buf, "JPEG", quality=75)

        if len(jpg_buf.getvalue()) < len(png_buf.getvalue()):
            method, buffer, suffix = "raw_jpeg", jpg_buf, ".jpg"

        else:
            method, buffer, suffix = "raw_png", png_buf, ".png"

        handle, filename = mkstemp(prefix="cairoutils-", suffix=suffix)
        self.command(method, filename)
        self.garbage.append(filename)

        write(handle, buffer.getvalue())
        close(handle)

    def paint(self):
        pass

    def set_line_width(self, w):
        self.command("%.3f w" % w)

    def set_dash(self, a):
        a = " ".join(["%.3f" % v for v in a])
        self.command("[%s] 0 d" % a)

    def stroke(self):
        self.command("S")

    def rel_curve_to(self, a, b, c, d, e, f):
        p1 = Point(a, b).add(self.point)
        p2 = Point(c, d).add(self.point)
        p3 = Point(e, f).add(self.point)
        self.point = p3
        self.command("%.3f %.3f %.3f %.3f %.3f %.3f c" % (p1.x, p1.y, p2.x, p2.y, p3.x, p3.y))

    def set_font_face(self, font):
        self.context.set_font_face(font)

    def set_font_size(self, size):
        self.context.set_font_size(size)

        # SetFont here because only the size gives a clue to the correct weight
        self.command("SetFont", "Helvetica", (size > 14) and "B" or "")
        self.command("SetFontSize", size)

    def show_text(self, text):
        x, y = self.point.x, self.point.y
        text = text.decode("utf8")

        # invert the vertical flip in self.show_page() before showing text.
        self.command("q 1 0 0 -1 0 0 cm BT %.3f %.3f Td (%s) Tj ET Q" % (x, -y, text))

    def text_extents(self, text):
        """ Width is the third element of the returned array.
        """
        return self.context.text_extents(text)
开发者ID:ndpgroup,项目名称:fp-legacy,代码行数:104,代码来源:cairoutils.py


注:本文中的cairo.Context.set_font_face方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。