def repaint(self, cr, x, y, w, h):
     c = Context(cr)
     w, h = self.repaint_callback(c)
     if self.size != (w, h):
         self.set_size(w, h)
         self.size = (w, h)
예제 #2
0
def render_json_data(json_text, background_image, png_file):
    padding = 50

    json = decode_json(json_text)
    tree = TreeRootNode(json)
    tree.process()
    layout = TreeLayouter(tree)
    img = ImageSurface(cairo.CAIRO_FORMAT_ARGB32, 10, 100)
    ctx = Context(img)
    w, h = 500, 500
    img = ImageSurface(cairo.CAIRO_FORMAT_ARGB32, w+padding*2, h+padding*2)
    ctx = Context(img)
    ctx.set_font_size(12)
    if background_image:
        bgimage = ImageSurface.from_png(background_image)
    else:
        bgimage = None
    if bgimage and bgimage.status() == cairo.CAIRO_STATUS_SUCCESS:
        ctx.save()
        pat = Pattern(bgimage)
        pat.set_extend(cairo.CAIRO_EXTEND_REPEAT)
        ctx.set_source(pat)
        ctx.paint()
        ctx.restore()
    else:
        ctx.set_source_rgb(1,1,1)
        ctx.paint()
#layout.render(ctx, 0, 0)
    tree.layout(ctx, 0, 0)
    tree.render(ctx)
    img.write_to_png(png_file)

    return w+padding*2, h+padding*2
예제 #3
0
def render_json_data_to_file(json_text, background_image, png_file, options):
    padding = 50

    json = decode_json(json_text)
    tree = tree_from_json(None, "query_block", json["query_block"])
    tree.process()
    tree = strip_useless_nodes(tree)
    layout = TreeLayouter(tree, options)
    img = ImageSurface(cairo.CAIRO_FORMAT_ARGB32, 10, 100)
    ctx = Context(img)
    w, h = layout.get_total_size(ctx)
    img = ImageSurface(cairo.CAIRO_FORMAT_ARGB32, w + padding * 2,
                       h + padding * 2)
    ctx = Context(img)
    ctx.set_font_size(12)
    if background_image:
        bgimage = ImageSurface.from_png(background_image)
    else:
        bgimage = None
    if bgimage and bgimage.status() == cairo.CAIRO_STATUS_SUCCESS:
        ctx.save()
        pat = Pattern(bgimage)
        pat.set_extend(cairo.CAIRO_EXTEND_REPEAT)
        ctx.set_source(pat)
        ctx.paint()
        ctx.restore()
    else:
        ctx.set_source_rgb(1, 1, 1)
        ctx.paint()
    layout.render(ctx, padding, padding)
    img.write_to_png(png_file)

    return w + padding * 2, h + padding * 2
예제 #4
0
def render_json_data_to_file(json_text, background_image, png_file, options):
    padding = 50

    scale = options.get("scale", 1)

    json = decode_json(json_text)
    layout = prepare_layout(json, options)
    img = ImageSurface(cairo.CAIRO_FORMAT_ARGB32, 10, 100)
    ctx = Context(img)
    w, h = layout.get_total_size(ctx)
    img = ImageSurface(cairo.CAIRO_FORMAT_ARGB32, (w+padding*2)*scale, (h+padding*2)*scale)
    ctx = Context(img)
    ctx.scale(scale, scale)
    ctx.set_font_size(12)
    if background_image:
        bgimage = ImageSurface.from_png(background_image)
    else:
        bgimage = None
    if bgimage and bgimage.status() == cairo.CAIRO_STATUS_SUCCESS:
        ctx.save()
        pat = Pattern(bgimage)
        pat.set_extend(cairo.CAIRO_EXTEND_REPEAT)
        ctx.set_source(pat)
        ctx.paint()
        ctx.restore()
    else:
        ctx.set_source_rgb(1,1,1)
        ctx.paint()
    layout.render(ctx, padding, padding)
    img.write_to_png(png_file)

    return w+padding*2, h+padding*2