+ make width,height and type optinal in following

symbolizers: 
    * point_symbolizer
    * shield_symbolizer
    * line_pattern_symbolizer
    * polygon_pattern_symbolizer
This commit is contained in:
Artem Pavlenko 2010-01-11 13:27:38 +00:00
parent cf4c94a44b
commit 8cd7645561

View file

@ -24,6 +24,7 @@
#include <mapnik/version.hpp>
#include <mapnik/image_reader.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/color.hpp>
#include <mapnik/color_factory.hpp>
#include <mapnik/filter_factory.hpp>
@ -483,11 +484,11 @@ namespace mapnik
params["file"] = ensure_relative_to_xml(file_param);
}
}
#ifdef MAPNIK_DEBUG
#ifdef MAPNIK_DEBUG
else {
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
}
#endif
#endif
//now we are ready to create datasource
try
@ -652,6 +653,7 @@ namespace mapnik
optional<std::string> file = get_opt_attr<string>(sym, "file");
optional<std::string> base = get_opt_attr<string>(sym, "base");
optional<std::string> type = get_opt_attr<string>(sym, "type");
optional<boolean> allow_overlap =
get_opt_attr<boolean>(sym, "allow_overlap");
optional<float> opacity =
@ -660,8 +662,32 @@ namespace mapnik
optional<unsigned> width = get_opt_attr<unsigned>(sym, "width");
optional<unsigned> height = get_opt_attr<unsigned>(sym, "height");
if (file && type && width && height)
//
if (file)
{
if (!type)
{
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 )
@ -677,11 +703,12 @@ namespace mapnik
{
*file = ensure_relative_to_xml(file);
}
#ifdef MAPNIK_DEBUG
else {
#ifdef MAPNIK_DEBUG
else
{
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
}
#endif
#endif
point_symbolizer symbol(*file,*type,*width,*height);
if (allow_overlap)
@ -709,16 +736,16 @@ namespace mapnik
}
}
else if (file || type || width || height)
{
std::ostringstream os;
os << "Missing required attributes: ";
if ( ! file ) os << "file ";
if ( ! type ) os << "type ";
if ( ! width ) os << "width ";
if ( ! height ) os << "height ";
throw config_error( os.str() );
}
//else if (file || type || width || height)
//{
// std::ostringstream os;
// os << "Missing required attributes: ";
// if ( ! file ) os << "file ";
// if ( ! type ) os << "type ";
// if ( ! width ) os << "width ";
// if ( ! height ) os << "height ";
// throw config_error( os.str() );
//}
else
{
rule.append(point_symbolizer());
@ -737,9 +764,32 @@ namespace mapnik
{
std::string file = get_attr<string>(sym, "file");
optional<std::string> base = get_opt_attr<string>(sym, "base");
std::string type = get_attr<string>(sym, "type");
unsigned width = get_attr<unsigned>(sym, "width");
unsigned height = get_attr<unsigned>(sym, "height");
optional<std::string> type = get_attr<string>(sym, "type");
optional<unsigned> width = get_attr<unsigned>(sym, "width");
optional<unsigned> height = get_attr<unsigned>(sym, "height");
if (!type)
{
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
{
@ -755,14 +805,14 @@ namespace mapnik
{
file = ensure_relative_to_xml(file);
}
#ifdef MAPNIK_DEBUG
#ifdef MAPNIK_DEBUG
else {
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
}
#endif
#endif
line_pattern_symbolizer symbol(file,type,width,height);
line_pattern_symbolizer symbol(file,*type,*width,*height);
rule.append(symbol);
}
catch (ImageReaderException const & ex )
@ -793,9 +843,32 @@ namespace mapnik
{
std::string file = get_attr<string>(sym, "file");
optional<std::string> base = get_opt_attr<string>(sym, "base");
std::string type = get_attr<string>(sym, "type");
unsigned width = get_attr<unsigned>(sym, "width");
unsigned height = get_attr<unsigned>(sym, "height");
optional<std::string> type = get_attr<string>(sym, "type");
optional<unsigned> width = get_attr<unsigned>(sym, "width");
optional<unsigned> height = get_attr<unsigned>(sym, "height");
if (!type)
{
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
{
@ -811,13 +884,13 @@ namespace mapnik
{
file = ensure_relative_to_xml(file);
}
#ifdef MAPNIK_DEBUG
#ifdef MAPNIK_DEBUG
else {
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
}
#endif
#endif
polygon_pattern_symbolizer symbol(file,type,width,height);
polygon_pattern_symbolizer symbol(file,*type,*width,*height);
rule.append(symbol);
}
catch (ImageReaderException const & ex )
@ -1053,9 +1126,32 @@ namespace mapnik
std::string image_file = get_attr<string>(sym, "file");
optional<std::string> base = get_opt_attr<string>(sym, "base");
std::string type = get_attr<string>(sym, "type");
unsigned width = get_attr<unsigned>(sym, "width");
unsigned height = get_attr<unsigned>(sym, "height");
optional<std::string> type = get_opt_attr<string>(sym, "type");
optional<unsigned> width = get_opt_attr<unsigned>(sym, "width");
optional<unsigned> height = get_opt_attr<unsigned>(sym, "height");
if (!type)
{
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
{
@ -1072,14 +1168,14 @@ namespace mapnik
{
image_file = ensure_relative_to_xml(image_file);
}
#ifdef MAPNIK_DEBUG
#ifdef MAPNIK_DEBUG
else {
std::clog << "\nFound relative paths in xml, leaving unchanged...\n";
}
#endif
#endif
shield_symbolizer shield_symbol(name,size,fill,
image_file,type,width,height);
image_file,*type,*width,*height);
if (fontset_name && face_name)
{
@ -1536,11 +1632,11 @@ namespace mapnik
boost::filesystem::path rel_path = *opt_path;
if ( !rel_path.has_root_path() ) {
boost::filesystem::path full = boost::filesystem::complete(xml_path.branch_path()/rel_path).normalize();
#ifdef MAPNIK_DEBUG
#ifdef MAPNIK_DEBUG
std::clog << "\nModifying relative paths to be relative to xml...\n";
std::clog << "original base path: " << *opt_path << "\n";
std::clog << "relative base path: " << full.string() << "\n";
#endif
#endif
return full.string();
}
return *opt_path;