diff options
Diffstat (limited to 'scripts/pybootchartgui/pybootchartgui/batch.py')
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/batch.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/scripts/pybootchartgui/pybootchartgui/batch.py b/scripts/pybootchartgui/pybootchartgui/batch.py new file mode 100644 index 0000000000..bd67c9350e --- /dev/null +++ b/scripts/pybootchartgui/pybootchartgui/batch.py | |||
@@ -0,0 +1,23 @@ | |||
1 | import cairo | ||
2 | |||
3 | import draw | ||
4 | |||
5 | def render(res, format, filename): | ||
6 | handlers = { | ||
7 | "png": (lambda w,h: cairo.ImageSurface(cairo.FORMAT_ARGB32,w,h), lambda sfc: sfc.write_to_png(filename)), | ||
8 | "pdf": (lambda w,h: cairo.PDFSurface(filename, w, h), lambda sfc: 0), | ||
9 | "svg": (lambda w,h: cairo.SVGSurface(filename, w, h), lambda sfc: 0) | ||
10 | } | ||
11 | |||
12 | if not(handlers.has_key(format)): | ||
13 | print "Unknown format '%s'." % format | ||
14 | return 10 | ||
15 | |||
16 | make_surface, write_surface = handlers[format] | ||
17 | w,h = draw.extents(*res) | ||
18 | w = max(w, draw.MIN_IMG_W) | ||
19 | surface = make_surface(w,h) | ||
20 | ctx = cairo.Context(surface) | ||
21 | draw.render(ctx, *res) | ||
22 | write_surface(surface) | ||
23 | |||