Created
December 21, 2012 20:45
-
-
Save springmeyer/4355690 to your computer and use it in GitHub Desktop.
enable native svg renderer over cairo in mapnik python bindings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bindings/python/build.py b/bindings/python/build.py | |
index 2a83607..df6dd9d 100644 | |
--- a/bindings/python/build.py | |
+++ b/bindings/python/build.py | |
@@ -182,6 +182,9 @@ if 'uninstall' not in COMMAND_LINE_TARGETS: | |
py_env.ParseConfig('pkg-config --cflags pycairo') | |
py_env.Append(CXXFLAGS = '-DHAVE_PYCAIRO') | |
+ if env['SVG_RENDERER']: | |
+ py_env.Append(CXXFLAGS = '-DSVG_RENDERER') | |
+ | |
libraries.append('boost_thread%s' % env['BOOST_APPEND']) | |
_mapnik = py_env.LoadableModule('mapnik/_mapnik', sources, LIBS=libraries, LDMODULEPREFIX='', LDMODULESUFFIX='.so',LINKFLAGS=linkflags) | |
diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp | |
index 3f6e76d..d7b870c 100644 | |
--- a/bindings/python/mapnik_python.cpp | |
+++ b/bindings/python/mapnik_python.cpp | |
@@ -78,6 +78,9 @@ void export_logger(); | |
#ifdef HAVE_CAIRO | |
#include <mapnik/cairo_renderer.hpp> | |
#endif | |
+#ifdef SVG_RENDERER | |
+#include <mapnik/svg/output/svg_renderer.hpp> | |
+#endif | |
#include <mapnik/graphics.hpp> | |
#include <mapnik/image_util.hpp> | |
#include <mapnik/load_map.hpp> | |
@@ -269,6 +272,18 @@ void render_to_file1(const mapnik::Map& map, | |
{ | |
if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24") | |
{ | |
+#if defined(SVG_RENDERER) | |
+ if (format == "svg") { | |
+ std::ofstream svg_stream(filename.c_str()); | |
+ typedef mapnik::svg_renderer<std::ostream_iterator<char> > svg_ren; | |
+ std::ostream_iterator<char> output_stream_iterator(svg_stream); | |
+ svg_ren renderer(map, output_stream_iterator); | |
+ renderer.apply(); | |
+ svg_stream.close(); | |
+ return; | |
+ } | |
+#endif | |
+ | |
#if defined(HAVE_CAIRO) | |
mapnik::save_to_cairo_file(map,filename,format,1.0); | |
#else | |
@@ -288,6 +303,18 @@ void render_to_file2(const mapnik::Map& map,std::string const& filename) | |
std::string format = mapnik::guess_type(filename); | |
if (format == "pdf" || format == "svg" || format =="ps") | |
{ | |
+#if defined(SVG_RENDERER) | |
+ if (format == "svg") { | |
+ std::ofstream svg_stream(filename.c_str()); | |
+ typedef mapnik::svg_renderer<std::ostream_iterator<char> > svg_ren; | |
+ std::ostream_iterator<char> output_stream_iterator(svg_stream); | |
+ svg_ren renderer(map, output_stream_iterator); | |
+ renderer.apply(); | |
+ svg_stream.close(); | |
+ return; | |
+ } | |
+#endif | |
+ | |
#if defined(HAVE_CAIRO) | |
mapnik::save_to_cairo_file(map,filename,format,1.0); | |
#else | |
@@ -310,6 +337,19 @@ void render_to_file3(const mapnik::Map& map, | |
{ | |
if (format == "pdf" || format == "svg" || format =="ps" || format == "ARGB32" || format == "RGB24") | |
{ | |
+ | |
+#if defined(SVG_RENDERER) | |
+ if (format == "svg") { | |
+ // TODO - support scale_factor | |
+ std::ofstream svg_stream(filename.c_str()); | |
+ typedef mapnik::svg_renderer<std::ostream_iterator<char> > svg_ren; | |
+ std::ostream_iterator<char> output_stream_iterator(svg_stream); | |
+ svg_ren renderer(map, output_stream_iterator); | |
+ renderer.apply(); | |
+ svg_stream.close(); | |
+ return; | |
+ } | |
+#endif | |
#if defined(HAVE_CAIRO) | |
mapnik::save_to_cairo_file(map,filename,format,scale_factor); | |
#else |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. So
scale_factor
is not supported with the native SVG renderer?