def _saveImage_pdf(self, path, **kwargs): stream = skia.FILEWStream(os.fspath(path)) with skia.PDF.MakeDocument(stream) as document: for picture in self._pictures: x, y, width, height = picture.cullRect() assert x == 0 and y == 0 with document.page(width, height) as canvas: canvas.drawPicture(picture)
def _saveImage_svg(self, path, **kwargs): for picture, framePath in _iteratePictures(self._pictures, path): x, y, width, height = picture.cullRect() assert x == 0 and y == 0 stream = skia.FILEWStream(os.fspath(framePath)) canvas = skia.SVGCanvas.Make((width, height), stream) canvas.drawPicture(picture) del canvas stream.flush()
def __init__(self, path): self._stream = skia.FILEWStream(os.fspath(path)) self._document = skia.PDF.MakeDocument(self._stream) self.pageWidth = self.pageHeight = None self._isDrawing = False
def SVG(pens, rect, save_to, scale=1): stream = skia.FILEWStream(str(save_to)) canvas = skia.SVGCanvas.Make((rect.w, rect.h), stream) SkiaPen.CompositeToCanvas(pens, rect, canvas, scale=scale) del canvas stream.flush()
def PDFMultiPage(pages, rect, save_to, scale=1): stream = skia.FILEWStream(str(save_to)) with skia.PDF.MakeDocument(stream) as document: for page in pages: with document.page(rect.w, rect.h) as canvas: SkiaPen.CompositeToCanvas(page, rect, canvas, scale=scale)
def file_wstream(tmp_path): yield skia.FILEWStream(tmp_path.name) try: os.remove(tmp_path.name) except PermissionError: pass