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
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
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
def render_json_data(ctx, json_text, background_image, options): padding = 50 json = decode_json(json_text) layout = prepare_layout(json, options) w, h = layout.get_total_size(ctx) 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) return w+padding*2, h+padding*2