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


Python cairocffi.PDFSurface方法代码示例

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


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

示例1: setupCairo

# 需要导入模块: import cairocffi [as 别名]
# 或者: from cairocffi import PDFSurface [as 别名]
def setupCairo(self, outputFormat='png'):
        self.outputFormat = outputFormat
        if outputFormat == 'png':
            self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                                              self.width, self.height)
        elif outputFormat == 'svg':
            self.surfaceData = BytesIO()
            self.surface = cairo.SVGSurface(self.surfaceData,
                                            self.width, self.height)
        elif outputFormat == 'pdf':
            self.surfaceData = BytesIO()
            self.surface = cairo.PDFSurface(self.surfaceData,
                                            self.width, self.height)
            res_x, res_y = self.surface.get_fallback_resolution()
            self.width = float(self.width / res_x) * 72
            self.height = float(self.height / res_y) * 72
            self.surface.set_size(self.width, self.height)
        self.ctx = cairo.Context(self.surface) 
开发者ID:brutasse,项目名称:graphite-api,代码行数:20,代码来源:glyph.py

示例2: _save

# 需要导入模块: import cairocffi [as 别名]
# 或者: from cairocffi import PDFSurface [as 别名]
def _save(self, fo, fmt, **kwargs):
        # save PDF/PS/SVG
        orientation = kwargs.get('orientation', 'portrait')

        dpi = 72
        self.figure.dpi = dpi
        w_in, h_in = self.figure.get_size_inches()
        width_in_points, height_in_points = w_in * dpi, h_in * dpi

        if orientation == 'landscape':
            width_in_points, height_in_points = (
                height_in_points, width_in_points)

        if fmt == 'ps':
            if not hasattr(cairo, 'PSSurface'):
                raise RuntimeError('cairo has not been compiled with PS '
                                   'support enabled')
            surface = cairo.PSSurface(fo, width_in_points, height_in_points)
        elif fmt == 'pdf':
            if not hasattr(cairo, 'PDFSurface'):
                raise RuntimeError('cairo has not been compiled with PDF '
                                   'support enabled')
            surface = cairo.PDFSurface(fo, width_in_points, height_in_points)
        elif fmt in ('svg', 'svgz'):
            if not hasattr(cairo, 'SVGSurface'):
                raise RuntimeError('cairo has not been compiled with SVG '
                                   'support enabled')
            if fmt == 'svgz':
                if isinstance(fo, str):
                    fo = gzip.GzipFile(fo, 'wb')
                else:
                    fo = gzip.GzipFile(None, 'wb', fileobj=fo)
            surface = cairo.SVGSurface(fo, width_in_points, height_in_points)
        else:
            raise ValueError("Unknown format: {!r}".format(fmt))

        # surface.set_dpi() can be used
        renderer = RendererCairo(self.figure.dpi)
        renderer.set_width_height(width_in_points, height_in_points)
        renderer.set_ctx_from_surface(surface)
        ctx = renderer.gc.ctx

        if orientation == 'landscape':
            ctx.rotate(np.pi / 2)
            ctx.translate(0, -height_in_points)
            # Perhaps add an '%%Orientation: Landscape' comment?

        self.figure.draw(renderer)

        ctx.show_page()
        surface.finish()
        if fmt == 'svgz':
            fo.close() 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:55,代码来源:backend_cairo.py

示例3: _save

# 需要导入模块: import cairocffi [as 别名]
# 或者: from cairocffi import PDFSurface [as 别名]
def _save(self, fo, fmt, **kwargs):
        # save PDF/PS/SVG
        orientation = kwargs.get('orientation', 'portrait')

        dpi = 72
        self.figure.dpi = dpi
        w_in, h_in = self.figure.get_size_inches()
        width_in_points, height_in_points = w_in * dpi, h_in * dpi

        if orientation == 'landscape':
            width_in_points, height_in_points = (
                height_in_points, width_in_points)

        if fmt == 'ps':
            if not hasattr(cairo, 'PSSurface'):
                raise RuntimeError('cairo has not been compiled with PS '
                                   'support enabled')
            surface = cairo.PSSurface(fo, width_in_points, height_in_points)
        elif fmt == 'pdf':
            if not hasattr(cairo, 'PDFSurface'):
                raise RuntimeError('cairo has not been compiled with PDF '
                                   'support enabled')
            surface = cairo.PDFSurface(fo, width_in_points, height_in_points)
        elif fmt in ('svg', 'svgz'):
            if not hasattr(cairo, 'SVGSurface'):
                raise RuntimeError('cairo has not been compiled with SVG '
                                   'support enabled')
            if fmt == 'svgz':
                if isinstance(fo, str):
                    fo = gzip.GzipFile(fo, 'wb')
                else:
                    fo = gzip.GzipFile(None, 'wb', fileobj=fo)
            surface = cairo.SVGSurface(fo, width_in_points, height_in_points)
        else:
            warnings.warn("unknown format: %s" % fmt, stacklevel=2)
            return

        # surface.set_dpi() can be used
        renderer = RendererCairo(self.figure.dpi)
        renderer.set_width_height(width_in_points, height_in_points)
        renderer.set_ctx_from_surface(surface)
        ctx = renderer.gc.ctx

        if orientation == 'landscape':
            ctx.rotate(np.pi / 2)
            ctx.translate(0, -height_in_points)
            # Perhaps add an '%%Orientation: Landscape' comment?

        self.figure.draw(renderer)

        ctx.show_page()
        surface.finish()
        if fmt == 'svgz':
            fo.close() 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:56,代码来源:backend_cairo.py

示例4: __init__

# 需要导入模块: import cairocffi [as 别名]
# 或者: from cairocffi import PDFSurface [as 别名]
def __init__(self,
                 img_format="png",
                 output="page",
                 width=0.15,
                 height=0.15,
                 dots_per_inch=dots_per_inch):
        """
        A thin wrapper to produce vector graphics using cairo. This class represents a page / image file we are going
        to draw onto.

        :param img_format:
            The image format we are to produce.
        :type img_format:
            str
        :param output:
            The filename of the image file we are to produce, without a file type suffix
        :type output:
            str
        :param width:
            The width of the page, metres
        :type width:
            float
        :param height:
            The height of the page, metres
        :type height:
            float
        :param dots_per_inch:
            The dots per inch resolution to render this page
        :type dots_per_inch:
            float
        """

        # PDF surfaces are always measured in points
        if img_format in ("pdf", "svg"):
            dots_per_inch = 72.

        self.format = img_format
        self.output = "{}.{}".format(output, img_format)
        self.dots_per_metre = dots_per_inch * 39.370079
        self.width = int(width * self.dots_per_metre)
        self.height = int(height * self.dots_per_metre)

        if self.format == "pdf":
            self.surface = cairo.PDFSurface(self.output, self.width, self.height)
        elif self.format == "png":
            self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.width, self.height)
        elif self.format == "svg":
            self.surface = cairo.SVGSurface(self.output, self.width, self.height)
        else:
            assert False, "Unknown image output format {}".format(self.format) 
开发者ID:dcf21,项目名称:planisphere,代码行数:52,代码来源:graphics_context.py

示例5: _save

# 需要导入模块: import cairocffi [as 别名]
# 或者: from cairocffi import PDFSurface [as 别名]
def _save(self, fo, fmt, **kwargs):
        # save PDF/PS/SVG
        orientation = kwargs.get('orientation', 'portrait')

        dpi = 72
        self.figure.dpi = dpi
        w_in, h_in = self.figure.get_size_inches()
        width_in_points, height_in_points = w_in * dpi, h_in * dpi

        if orientation == 'landscape':
            width_in_points, height_in_points = (
                height_in_points, width_in_points)

        if fmt == 'ps':
            if not hasattr(cairo, 'PSSurface'):
                raise RuntimeError('cairo has not been compiled with PS '
                                   'support enabled')
            surface = cairo.PSSurface(fo, width_in_points, height_in_points)
        elif fmt == 'pdf':
            if not hasattr(cairo, 'PDFSurface'):
                raise RuntimeError('cairo has not been compiled with PDF '
                                   'support enabled')
            surface = cairo.PDFSurface(fo, width_in_points, height_in_points)
        elif fmt in ('svg', 'svgz'):
            if not hasattr(cairo, 'SVGSurface'):
                raise RuntimeError('cairo has not been compiled with SVG '
                                   'support enabled')
            if fmt == 'svgz':
                if isinstance(fo, six.string_types):
                    fo = gzip.GzipFile(fo, 'wb')
                else:
                    fo = gzip.GzipFile(None, 'wb', fileobj=fo)
            surface = cairo.SVGSurface(fo, width_in_points, height_in_points)
        else:
            warnings.warn("unknown format: %s" % fmt)
            return

        # surface.set_dpi() can be used
        renderer = RendererCairo(self.figure.dpi)
        renderer.set_width_height(width_in_points, height_in_points)
        renderer.set_ctx_from_surface(surface)
        ctx = renderer.gc.ctx

        if orientation == 'landscape':
            ctx.rotate(np.pi / 2)
            ctx.translate(0, -height_in_points)
            # Perhaps add an '%%Orientation: Landscape' comment?

        self.figure.draw(renderer)

        ctx.show_page()
        surface.finish()
        if fmt == 'svgz':
            fo.close() 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:56,代码来源:backend_cairo.py


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