Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ bool parseOptions(int argc, char **argv) {
opts.seed = arg_strn("s", "seed", "<uint>", 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", "<float>", 0, 1, "level of map detail"),
opts.outfile = arg_filen("o", "output", "filename", 0, 1, "output file"),
opts.output = arg_filen(NULL, NULL, "<file>", 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, "<file>", 0, 1, "output file (may end in .png or .svg)"),
opts.eroamount = arg_dbln("e", "erosion-amount", "<float>", 0, 1, "erosion amount"),
opts.erosteps = arg_intn(NULL, "erosion-steps", "<int>", 0, 1, "number of erosion iterations"),
opts.ncities = arg_intn("c", "cities", "<int>", 0, 1, "number of generated cities"),
Expand Down Expand Up @@ -386,4 +386,4 @@ bool _setVerbosity(arg_lit *verbose) {
}

}
}
}
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
15 changes: 12 additions & 3 deletions src/render/rendermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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)