drawing.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:zellij 作者: nedbat 项目源码 文件源码
def __init__(self, width=None, height=None, name=None, bounds=None, bg=(1, 1, 1), format=None):
        """Create a new Cairo drawing.

        If `bounds` is provided, it's a Bounds describing the extend of the
        drawing.  Otherwise, provide `width` and `height` to specify a size
        explicitly.

        `bg` is the background color to paint initially.

        """
        if bounds is None:
            assert width is not None
            assert height is not None
            bounds = Bounds(0, 0, width, height)
        self.bounds = bounds

        self.width = int(self.bounds.width)
        self.height = int(self.bounds.height)

        self.name, self.format = name_and_format(name, format)

        if self.format == 'png':
            self.surface = cairo.ImageSurface(cairo.Format.ARGB32, self.width, self.height)
        elif self.format == 'svg':
            self.surface = cairo.SVGSurface(self.name, self.width, self.height)
        self.ctx = cairo.Context(self.surface)
        self.ctx.set_antialias(cairo.Antialias.BEST)
        self.ctx.set_line_cap(cairo.LineCap.ROUND)
        self.ctx.set_line_join(cairo.LineJoin.MITER)

        self.translate(-self.bounds.llx, -self.bounds.lly)

        # Start with a solid-color canvas.
        if bg:
            with self.style(rgb=bg):
                self.rectangle(self.bounds.llx, self.bounds.lly, self.width, self.height)
                self.fill()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号