예제 #1
0
    def OnPrintPage(self, page):
        page_objs = self.pages[page - 1]
        dc = self.GetDC()
        w, h = dc.GetSizeTuple()
        pw, ph = self.GetPageSizeMM()
        print 'PPI', self.GetPPIPrinter()
        print 'DC', w, h
        print 'Page', pw, ph
        pw *= uc2const.mm_to_pt
        ph *= uc2const.mm_to_pt
        trafo = (w / pw, 0, 0, -h / ph, w / 2.0, h / 2.0)

        canvas_matrix = cairo.Matrix(*trafo)
        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(w), int(h))
        ctx = cairo.Context(surface)
        ctx.set_matrix(canvas_matrix)
        ctx.set_source_rgb(1, 1, 1)
        ctx.paint()

        rend = crenderer.CairoRenderer(self.doc.cms)
        rend.render(ctx, page_objs)

        bmp = wal.copy_surface_to_bitmap(surface)
        #		dc.DrawBitmap(bmp, 0, 0, False)
        return True
예제 #2
0
def render(objs, cms):
    bbox = reduce(lambda a, b: libgeom.sum_bbox(a, b.cache_bbox), objs, [])
    w, h = libgeom.bbox_size(bbox)
    x, y = libgeom.bbox_center(bbox)
    trafo = (1.0, 0, 0, -1.0, w / 2.0 - x, h / 2.0 + y)
    canvas_matrix = cairo.Matrix(*trafo)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h))
    ctx = cairo.Context(surface)
    ctx.set_matrix(canvas_matrix)
    rend = crenderer.CairoRenderer(cms)
    rend.antialias_flag = True
    rend.render(ctx, objs)

    image_stream = StringIO()
    surface.write_to_png(image_stream)
    return image_stream
예제 #3
0
    def render(self, sel_flag=False):
        doc = self.app.current_doc
        if not doc:
            return
        if sel_flag:
            if not doc.selection.objs:
                return None
            w, h = libgeom.bbox_size(doc.selection.bbox)
            x, y = libgeom.bbox_center(doc.selection.bbox)
            trafo = (1.0, 0, 0, -1.0, w / 2.0 - x, h / 2.0 + y)
        else:
            page = doc.active_page
            w, h = page.page_format[1]
            trafo = (1.0, 0, 0, -1.0, w / 2.0, h / 2.0)

        canvas_matrix = cairo.Matrix(*trafo)
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h))
        ctx = cairo.Context(surface)
        ctx.set_matrix(canvas_matrix)

        rend = crenderer.CairoRenderer(doc.cms)

        if sel_flag:
            objs = doc.selection.objs
            for obj in objs:
                layer = doc.methods.get_parent_layer(obj)
                rend.antialias_flag = layer.properties[3] == 1
                rend.render(ctx, [
                    obj,
                ])
        else:
            page = doc.active_page
            layers = doc.methods.get_visible_layers(page)
            for item in layers:
                rend.antialias_flag = item.properties[3] == 1
                rend.render(ctx, item.childs)

        image_stream = StringIO()
        surface.write_to_png(image_stream)
        return image_stream