+ take into account <base> when reading
width/height - fixed
This commit is contained in:
parent
4483564b5e
commit
090fdb3974
1 changed files with 1026 additions and 1034 deletions
268
src/load_map.cpp
268
src/load_map.cpp
|
@ -59,10 +59,10 @@ using std::endl;
|
|||
|
||||
namespace mapnik
|
||||
{
|
||||
using boost::optional;
|
||||
using boost::optional;
|
||||
|
||||
class map_parser : boost::noncopyable {
|
||||
public:
|
||||
class map_parser : boost::noncopyable {
|
||||
public:
|
||||
map_parser( bool strict, std::string const& filename = "" ) :
|
||||
strict_( strict ),
|
||||
filename_( filename ),
|
||||
|
@ -70,7 +70,7 @@ namespace mapnik
|
|||
font_manager_(font_engine_) {}
|
||||
|
||||
void parse_map( Map & map, ptree const & sty);
|
||||
private:
|
||||
private:
|
||||
void parse_style( Map & map, ptree const & sty);
|
||||
void parse_layer( Map & map, ptree const & lay);
|
||||
|
||||
|
@ -102,10 +102,10 @@ namespace mapnik
|
|||
face_manager<freetype_engine> font_manager_;
|
||||
std::map<std::string,std::string> file_sources_;
|
||||
std::map<std::string,FontSet> fontsets_;
|
||||
};
|
||||
};
|
||||
|
||||
void load_map(Map & map, std::string const& filename, bool strict)
|
||||
{
|
||||
void load_map(Map & map, std::string const& filename, bool strict)
|
||||
{
|
||||
ptree pt;
|
||||
#ifdef HAVE_LIBXML2
|
||||
read_xml2(filename, pt);
|
||||
|
@ -121,10 +121,10 @@ namespace mapnik
|
|||
#endif
|
||||
map_parser parser( strict, filename);
|
||||
parser.parse_map(map, pt);
|
||||
}
|
||||
}
|
||||
|
||||
void load_map_string(Map & map, std::string const& str, bool strict, std::string const& base_url)
|
||||
{
|
||||
void load_map_string(Map & map, std::string const& str, bool strict, std::string const& base_url)
|
||||
{
|
||||
ptree pt;
|
||||
#ifdef HAVE_LIBXML2
|
||||
read_xml2_string(str, pt, base_url);
|
||||
|
@ -142,10 +142,10 @@ namespace mapnik
|
|||
|
||||
map_parser parser( strict, base_url);
|
||||
parser.parse_map(map, pt);
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_map( Map & map, ptree const & pt )
|
||||
{
|
||||
void map_parser::parse_map( Map & map, ptree const & pt )
|
||||
{
|
||||
try
|
||||
{
|
||||
ptree const & map_node = pt.get_child("Map");
|
||||
|
@ -281,10 +281,10 @@ namespace mapnik
|
|||
{
|
||||
throw config_error("Not a map file. Node 'Map' not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_style( Map & map, ptree const & sty )
|
||||
{
|
||||
void map_parser::parse_style( Map & map, ptree const & sty )
|
||||
{
|
||||
string name("<missing name>");
|
||||
try
|
||||
{
|
||||
|
@ -317,10 +317,10 @@ namespace mapnik
|
|||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_fontset( Map & map, ptree const & fset )
|
||||
{
|
||||
void map_parser::parse_fontset( Map & map, ptree const & fset )
|
||||
{
|
||||
string name("<missing name>");
|
||||
try
|
||||
{
|
||||
|
@ -357,10 +357,10 @@ namespace mapnik
|
|||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_font(FontSet & fset, ptree const & f)
|
||||
{
|
||||
void map_parser::parse_font(FontSet & fset, ptree const & f)
|
||||
{
|
||||
std::string face_name = get_attr(f, "face_name", string());
|
||||
|
||||
if ( strict_ )
|
||||
|
@ -369,10 +369,10 @@ namespace mapnik
|
|||
}
|
||||
|
||||
fset.add_face_name(face_name);
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_layer( Map & map, ptree const & lay )
|
||||
{
|
||||
void map_parser::parse_layer( Map & map, ptree const & lay )
|
||||
{
|
||||
std::string name;
|
||||
try
|
||||
{
|
||||
|
@ -532,10 +532,10 @@ namespace mapnik
|
|||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_rule( feature_type_style & style, ptree const & r )
|
||||
{
|
||||
void map_parser::parse_rule( feature_type_style & style, ptree const & r )
|
||||
{
|
||||
std::string name;
|
||||
try
|
||||
{
|
||||
|
@ -644,10 +644,10 @@ namespace mapnik
|
|||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_point_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
void map_parser::parse_point_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
try
|
||||
{
|
||||
optional<std::string> file = get_opt_attr<string>(sym, "file");
|
||||
|
@ -669,25 +669,6 @@ namespace mapnik
|
|||
{
|
||||
type = type_from_filename(*file);
|
||||
}
|
||||
|
||||
if (!width || !height)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(*file));
|
||||
if (reader.get())
|
||||
{
|
||||
if (!width) width = reader->width();
|
||||
if (!height) height = reader->height();
|
||||
BOOST_ASSERT(*width > 0 && *height > 0);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught while loading image:" << *file << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( base )
|
||||
|
@ -709,7 +690,23 @@ namespace mapnik
|
|||
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!width || !height)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(*file,*type));
|
||||
if (reader.get())
|
||||
{
|
||||
if (!width) width = reader->width();
|
||||
if (!height) height = reader->height();
|
||||
BOOST_ASSERT(*width > 0 && *height > 0);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught while loading image:" << *file << std::endl;
|
||||
}
|
||||
}
|
||||
point_symbolizer symbol(*file,*type,*width,*height);
|
||||
if (allow_overlap)
|
||||
{
|
||||
|
@ -756,10 +753,10 @@ namespace mapnik
|
|||
ex.append_context("in PointSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_line_pattern_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
void map_parser::parse_line_pattern_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string file = get_attr<string>(sym, "file");
|
||||
|
@ -773,24 +770,6 @@ namespace mapnik
|
|||
type = type_from_filename(file);
|
||||
}
|
||||
|
||||
if (!width || !height)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(file));
|
||||
if (reader.get())
|
||||
{
|
||||
if (!width) width = reader->width();
|
||||
if (!height) height = reader->height();
|
||||
BOOST_ASSERT(*width > 0 && *height > 0);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught while loading image:" << file << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( base )
|
||||
|
@ -810,7 +789,23 @@ namespace mapnik
|
|||
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!width || !height)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(file,*type));
|
||||
if (reader.get())
|
||||
{
|
||||
if (!width) width = reader->width();
|
||||
if (!height) height = reader->height();
|
||||
BOOST_ASSERT(*width > 0 && *height > 0);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught while loading image:" << file << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
line_pattern_symbolizer symbol(file,*type,*width,*height);
|
||||
rule.append(symbol);
|
||||
|
@ -834,11 +829,11 @@ namespace mapnik
|
|||
ex.append_context("in LinePatternSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_polygon_pattern_symbolizer( rule_type & rule,
|
||||
void map_parser::parse_polygon_pattern_symbolizer( rule_type & rule,
|
||||
ptree const & sym )
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string file = get_attr<string>(sym, "file");
|
||||
|
@ -852,24 +847,6 @@ namespace mapnik
|
|||
type = type_from_filename(file);
|
||||
}
|
||||
|
||||
if (!width || !height)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(file));
|
||||
if (reader.get())
|
||||
{
|
||||
if (!width) width = reader->width();
|
||||
if (!height) height = reader->height();
|
||||
BOOST_ASSERT(*width > 0 && *height > 0);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught while loading image:" << file << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( base )
|
||||
|
@ -889,7 +866,23 @@ namespace mapnik
|
|||
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!width || !height)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(file,*type));
|
||||
if (reader.get())
|
||||
{
|
||||
if (!width) width = reader->width();
|
||||
if (!height) height = reader->height();
|
||||
BOOST_ASSERT(*width > 0 && *height > 0);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught while loading image:" << file << std::endl;
|
||||
}
|
||||
}
|
||||
polygon_pattern_symbolizer symbol(file,*type,*width,*height);
|
||||
rule.append(symbol);
|
||||
}
|
||||
|
@ -912,10 +905,10 @@ namespace mapnik
|
|||
ex.append_context("in PolygonPatternSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_text_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
void map_parser::parse_text_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string name = get_attr<string>(sym, "name");
|
||||
|
@ -1107,10 +1100,10 @@ namespace mapnik
|
|||
ex.append_context("in TextSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_shield_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
void map_parser::parse_shield_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string name = get_attr<string>(sym, "name");
|
||||
|
@ -1135,24 +1128,6 @@ namespace mapnik
|
|||
type = type_from_filename(image_file);
|
||||
}
|
||||
|
||||
if (!width || !height)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(image_file));
|
||||
if (reader.get())
|
||||
{
|
||||
if (!width) width = reader->width();
|
||||
if (!height) height = reader->height();
|
||||
BOOST_ASSERT(*width > 0 && *height > 0);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught while loading image:" << image_file << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( base )
|
||||
|
@ -1173,6 +1148,23 @@ namespace mapnik
|
|||
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
|
||||
}
|
||||
#endif
|
||||
if (!width || !height)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::auto_ptr<ImageReader> reader(get_image_reader(image_file,*type));
|
||||
if (reader.get())
|
||||
{
|
||||
if (!width) width = reader->width();
|
||||
if (!height) height = reader->height();
|
||||
BOOST_ASSERT(*width > 0 && *height > 0);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "Exception caught while loading image:" << image_file << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
shield_symbolizer shield_symbol(name,size,fill,
|
||||
image_file,*type,*width,*height);
|
||||
|
@ -1357,10 +1349,10 @@ namespace mapnik
|
|||
ex.append_context("in ShieldSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_line_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
void map_parser::parse_line_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
try
|
||||
{
|
||||
stroke strk;
|
||||
|
@ -1457,11 +1449,11 @@ namespace mapnik
|
|||
ex.append_context("in LineSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void map_parser::parse_polygon_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
void map_parser::parse_polygon_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
try
|
||||
{
|
||||
polygon_symbolizer poly_sym;
|
||||
|
@ -1513,11 +1505,11 @@ namespace mapnik
|
|||
ex.append_context("in PolygonSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void map_parser::parse_building_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
void map_parser::parse_building_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
try {
|
||||
building_symbolizer building_sym;
|
||||
|
||||
|
@ -1568,10 +1560,10 @@ namespace mapnik
|
|||
ex.append_context("in BuildingSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::parse_raster_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
void map_parser::parse_raster_symbolizer( rule_type & rule, ptree const & sym )
|
||||
{
|
||||
try
|
||||
{
|
||||
raster_symbolizer raster_sym;
|
||||
|
@ -1620,19 +1612,19 @@ namespace mapnik
|
|||
ex.append_context("in RasterSymbolizer");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_parser::ensure_font_face( const std::string & face_name )
|
||||
{
|
||||
void map_parser::ensure_font_face( const std::string & face_name )
|
||||
{
|
||||
if ( ! font_manager_.get_face( face_name ) )
|
||||
{
|
||||
throw config_error("Failed to find font face '" +
|
||||
face_name + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string map_parser::ensure_relative_to_xml( boost::optional<std::string> opt_path )
|
||||
{
|
||||
std::string map_parser::ensure_relative_to_xml( boost::optional<std::string> opt_path )
|
||||
{
|
||||
boost::filesystem::path xml_path = filename_;
|
||||
boost::filesystem::path rel_path = *opt_path;
|
||||
if ( !rel_path.has_root_path() ) {
|
||||
|
@ -1645,6 +1637,6 @@ namespace mapnik
|
|||
return full.string();
|
||||
}
|
||||
return *opt_path;
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace mapnik
|
||||
|
|
Loading…
Reference in a new issue