From 45266074c8c96d8689e2efa1bbf9d6307fd188d4 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 26 Jul 2009 01:08:51 +0000 Subject: [PATCH] scons: fix typo, and ensure all temp output is writeable --- SConstruct | 11 +++--- agg/SConscript | 7 +++- bindings/python/mapnik_python.cpp | 39 +++++++++++++++----- demo/python/rundemo.py | 25 +++++++------ include/mapnik/image_util.hpp | 25 ++++++++++++- src/image_util.cpp | 60 +++++++++++++++++++++++++++++-- 6 files changed, 138 insertions(+), 29 deletions(-) diff --git a/SConstruct b/SConstruct index eef185b6c..6551c5efb 100644 --- a/SConstruct +++ b/SConstruct @@ -387,15 +387,15 @@ def FindBoost(context, prefixes): msg += '\n *libs found: %s' % BOOST_LIB_DIR env['BOOST_LIBS'] = BOOST_LIB_DIR else: - env['BOOST_LIBS'] = '/usr' + LIBDIR_SCHEMA - msg += '\n *using boost lib dir: %s' % env['BOOST_LIBS'] + env['BOOST_LIBS'] = '/usr/' + LIBDIR_SCHEMA + msg += '\n *using default boost lib dir: %s' % env['BOOST_LIBS'] if BOOST_INCLUDE_DIR: msg += '\n *headers found: %s' % BOOST_INCLUDE_DIR env['BOOST_INCLUDES'] = BOOST_INCLUDE_DIR else: env['BOOST_INCLUDES'] = '/usr/include' - msg += '\n *using boost include dir: %s' % env['BOOST_INCLUDES'] + msg += '\n *using default boost include dir: %s' % env['BOOST_INCLUDES'] if not env['BOOST_TOOLKIT'] and not env['BOOST_ABI'] and not env['BOOST_VERSION']: if BOOST_APPEND: @@ -923,10 +923,11 @@ if not preconfigured: os.chmod(SCONS_LOCAL_CONFIG,0666) except: pass try: - os.chmod('.sconsign.dblite',0777) + os.chmod('.sconsign.dblite',0666) except: pass try: - os.chmod(SCONF_TEMP_DIR,0777) + for item in glob('%s/*' % SCONF_TEMP_DIR): + os.chmod(item,0666) except: pass if 'configure' in command_line_args: diff --git a/agg/SConscript b/agg/SConscript index ce9a3321b..9f1eb24a7 100644 --- a/agg/SConscript +++ b/agg/SConscript @@ -24,4 +24,9 @@ Import('env') if env['PLATFORM'] == 'SunOS': env.StaticLibrary('agg', glob.glob('./src/' + '*.cpp'), LIBS=[], CPPPATH='./include', CXXFLAGS='-O -KPIC -DNDEBUG') else: - env.StaticLibrary('agg', glob.glob('./src/' + '*.cpp'), LIBS=[], CPPPATH='./include', CXXFLAGS='-O%s -fPIC -DNDEBUG' % env['OPTIMIZATION']) + link_flags = '' + cxx_flags = '-O%s -fPIC -DNDEBUG' % env['OPTIMIZATION'] + if env['PLATFORM'] == 'Darwin': + cxx_flags += ' -arch ppc -arch i386 -arch ppc64 -arch x86_64 ' + link_flags = ' -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk ' + env.StaticLibrary('agg', glob.glob('./src/' + '*.cpp'), LIBS=[], CPPPATH='./include', CXXFLAGS=cxx_flags,LINKFLAGS=link_flags) diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index a926a385e..42aba76ad 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -194,20 +194,41 @@ void render_to_file1(const mapnik::Map& map, const std::string& filename, const std::string& format) { - mapnik::Image32 image(map.getWidth(),map.getHeight()); - render(map,image,0,0); - mapnik::save_to_file(image,filename,format); + if (format == "pdf" | format == "svg" | format =="ps" | format == "ARGB32" | format == "RGB24") + { +#if defined(HAVE_CAIRO) + mapnik::save_to_cairo_file(map,filename,format); +#else + throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format); +#endif + } + else + { + mapnik::Image32 image(map.getWidth(),map.getHeight()); + render(map,image,0,0); + mapnik::save_to_file(image,filename,format); + } } -void render_to_file2(const mapnik::Map& map, - const std::string& filename) +void render_to_file2(const mapnik::Map& map,const std::string& filename) { - mapnik::Image32 image(map.getWidth(),map.getHeight()); - render(map,image,0,0); - mapnik::save_to_file(image,filename); + std::string format = mapnik::guess_type(filename); + if (format == "pdf" | format == "svg" | format =="ps") + { +#if defined(HAVE_CAIRO) + mapnik::save_to_cairo_file(map,filename,format); +#else + throw mapnik::ImageWriterException("Cairo backend not available, cannot write to format: " + format); +#endif + } + else + { + mapnik::Image32 image(map.getWidth(),map.getHeight()); + render(map,image,0,0); + mapnik::save_to_file(image,filename); + } } - double scale_denominator(mapnik::Map const &map, bool geographic) { return mapnik::scale_denominator(map, geographic); diff --git a/demo/python/rundemo.py b/demo/python/rundemo.py index 32338f7d8..bb47f0a2d 100644 --- a/demo/python/rundemo.py +++ b/demo/python/rundemo.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +##!/usr/bin/env python # -*- coding: utf-8 -*- # # $Id$ @@ -313,21 +313,26 @@ m.layers.append(popplaces_lyr) m.zoom_to_box(Envelope(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855)) # Render two maps, two PNGs, one JPEG. -im = Image(m.width,m.height) -render(m, im) +#im = Image(m.width,m.height) +#render(m, im) # Save image to files images = [] -im.save('demo.png', 'png') # true-colour RGBA -images.append('demo.png') -im.save('demo256.png', 'png256') # save to palette based (max 256 colours) png -images.append('demo256.png') -im.save('demo.jpg', 'jpeg') -images.append('demo.jpg') +#im.save('demo.png', 'png') # true-colour RGBA +#images.append('demo.png') +#im.save('demo256.png', 'png256') # save to palette based (max 256 colours) png +#images.append('demo256.png') +#im.save('demo.jpg', 'jpeg') +#images.append('demo.jpg') + +render_to_file(m,'test_c.pdf','pdf') +render_to_file(m,'test_c.svg','svg') +render_to_file(m,'test_32.png','ARGB32') +render_to_file(m,'test_24.png','RGB24') # Render cairo examples try: - import cairo + import cairo_ surface = cairo.SVGSurface('demo.svg', m.width,m.height) render(m, surface) images.append('demo.svg') diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index 202eb3ce6..a1b3c69fe 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -27,6 +27,7 @@ // mapnik #include +#include #include // boost @@ -53,6 +54,10 @@ namespace mapnik { } }; + MAPNIK_DECL void save_to_cairo_file(mapnik::Map const& map, + std::string const& filename, + std::string const& type); + template MAPNIK_DECL void save_to_file(T const& image, std::string const& filename, @@ -91,12 +96,30 @@ namespace mapnik { return boost::algorithm::iends_with(filename,std::string(".tif")) || boost::algorithm::iends_with(filename,std::string(".tiff")); } - + + inline bool is_pdf (std::string const& filename) + { + return boost::algorithm::iends_with(filename,std::string(".pdf")); + } + + inline bool is_svg (std::string const& filename) + { + return boost::algorithm::iends_with(filename,std::string(".svg")); + } + + inline bool is_ps (std::string const& filename) + { + return boost::algorithm::iends_with(filename,std::string(".ps")); + } + inline std::string type_from_filename(std::string const& filename) { if (is_png(filename)) return "png"; if (is_jpeg(filename)) return "jpeg"; if (is_tiff(filename)) return "tiff"; + if (is_pdf(filename)) return "pdf"; + if (is_svg(filename)) return "svg"; + if (is_ps(filename)) return "ps"; return "unknown"; } diff --git a/src/image_util.cpp b/src/image_util.cpp index c9c2f26c3..576349d28 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -35,6 +35,10 @@ extern "C" #include #include +#ifdef HAVE_CAIRO +#include +#endif + // stl #include #include @@ -103,8 +107,10 @@ namespace mapnik } } else throw ImageWriterException("unknown file type: " + type); - } + } + else throw ImageWriterException("Could not write file to " + filename ); } + template void save_to_file(T const& image,std::string const& filename) @@ -112,12 +118,60 @@ namespace mapnik std::string type = type_from_filename(filename); save_to_file(image,filename,type); } - + + +#if defined(HAVE_CAIRO) + + void save_to_cairo_file(mapnik::Map const& map, std::string const& filename) + { + std::string type = type_from_filename(filename); + save_to_cairo_file(map,filename,type); + } + + void save_to_cairo_file(mapnik::Map const& map, + std::string const& filename, + std::string const& type) + { + std::ofstream file (filename.c_str(), std::ios::out|std::ios::trunc|std::ios::binary); + if (file) + { + Cairo::RefPtr surface; + if (type == "pdf") + surface = Cairo::PdfSurface::create(filename, map.getWidth(),map.getHeight()); + else if (type == "svg") + surface = Cairo::SvgSurface::create(filename, map.getWidth(),map.getHeight()); + else if (type == "ps") + surface = Cairo::PsSurface::create(filename, map.getWidth(),map.getHeight()); + else if (type == "ARGB32") + surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, map.getWidth(),map.getHeight()); + else if (type == "RGB24") + surface = Cairo::ImageSurface::create(Cairo::FORMAT_RGB24, map.getWidth(),map.getHeight()); + else + throw ImageWriterException("unknown file type: " + type); + Cairo::RefPtr context = Cairo::Context::create(surface); + + if (type == "ARGB32" | type == "RGB24") + { + context->set_antialias(Cairo::ANTIALIAS_NONE); + } + + mapnik::cairo_renderer ren(map, context); + ren.apply(); + + if (type == "ARGB32" | type == "RGB24") + { + surface->write_to_png(filename); + } + surface->finish(); + } + } + +#endif template void save_to_file(ImageData32 const&, std::string const&, std::string const&); - + template void save_to_file(ImageData32 const&, std::string const&);