diff --git a/src/config.cpp b/src/config.cpp index 69fc670..a9f96ec 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -38,8 +38,8 @@ bool parseOptions(int argc, char **argv) { opts.seed = arg_strn("s", "seed", "", 0, 1, "set random generator seed"), opts.timeseed = arg_litn(NULL, "timeseed", 0, 1, "set seed from system time"), opts.resolution = arg_dbln("r", "resolution", "", 0, 1, "level of map detail"), - opts.outfile = arg_filen("o", "output", "filename", 0, 1, "output file"), - opts.output = arg_filen(NULL, NULL, "", 0, 1, "output file"), + opts.outfile = arg_filen("o", "output", "filename", 0, 1, "output file (may end in .png or .svg)"), + opts.output = arg_filen(NULL, NULL, "", 0, 1, "output file (may end in .png or .svg)"), opts.eroamount = arg_dbln("e", "erosion-amount", "", 0, 1, "erosion amount"), opts.erosteps = arg_intn(NULL, "erosion-steps", "", 0, 1, "number of erosion iterations"), opts.ncities = arg_intn("c", "cities", "", 0, 1, "number of generated cities"), @@ -386,4 +386,4 @@ bool _setVerbosity(arg_lit *verbose) { } } -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 37edde3..1c22784 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ void outputMap(gen::MapGenerator &map) { std::string outfile = gen::config::outfile; std::string outfileExt = gen::config::outfileExt; #ifdef PYTHON_RENDERING_SUPPORTED - if (outfileExt != std::string(".png")) { + if (outfileExt != std::string(".png") && outfileExt != std::string(".svg")) { outfile += ".png"; } diff --git a/src/render/rendermap.py b/src/render/rendermap.py index 5715d19..3cc541f 100644 --- a/src/render/rendermap.py +++ b/src/render/rendermap.py @@ -115,7 +115,13 @@ def draw_map(jsonstring, output_filename): imgwidth = data["image_width"] imgheight = data["image_height"] - surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, imgwidth, imgheight) + + surface = None + if (output_filename.endswith(".svg")): + surface = cairo.SVGSurface(output_filename, imgwidth, imgheight) + else: + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, imgwidth, imgheight) + ctx = cairo.Context(surface) update_draw_scale(data["draw_scale"]) @@ -153,5 +159,8 @@ def draw_map(jsonstring, output_filename): draw_cities(data["city"], ctx, imgwidth, imgheight) draw_towns(data["town"], ctx, imgwidth, imgheight) draw_labels(data["label"], ctx, imgwidth, imgheight); - - surface.write_to_png(output_filename) + + if isinstance(surface, cairo.SVGSurface): + surface.finish() + else: + surface.write_to_png(output_filename)