+ split agg_renderer impl into different
translation units + add SVG support in point_symbolizer
This commit is contained in:
parent
12b74bc1cc
commit
9beb12b56b
2 changed files with 4 additions and 285 deletions
|
@ -114,9 +114,12 @@ source = Split(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if True :
|
if True : # agg backend
|
||||||
source += Split(
|
source += Split(
|
||||||
"""
|
"""
|
||||||
|
agg/process_point_symbolizer.cpp
|
||||||
|
agg/process_shield_symbolizer.cpp
|
||||||
|
agg/process_markers_symbolizer.cpp
|
||||||
agg_svg_path_renderer.cpp
|
agg_svg_path_renderer.cpp
|
||||||
svg_parser.cpp
|
svg_parser.cpp
|
||||||
svg_path_parser.cpp
|
svg_path_parser.cpp
|
||||||
|
|
|
@ -25,11 +25,8 @@
|
||||||
#include <mapnik/agg_renderer.hpp>
|
#include <mapnik/agg_renderer.hpp>
|
||||||
#include <mapnik/image_util.hpp>
|
#include <mapnik/image_util.hpp>
|
||||||
#include <mapnik/image_cache.hpp>
|
#include <mapnik/image_cache.hpp>
|
||||||
#include <mapnik/svg/marker_cache.hpp>
|
|
||||||
#include <mapnik/unicode.hpp>
|
#include <mapnik/unicode.hpp>
|
||||||
#include <mapnik/placement_finder.hpp>
|
#include <mapnik/placement_finder.hpp>
|
||||||
#include <mapnik/markers_placement.hpp>
|
|
||||||
#include <mapnik/arrow.hpp>
|
|
||||||
#include <mapnik/config_error.hpp>
|
#include <mapnik/config_error.hpp>
|
||||||
#include <mapnik/font_set.hpp>
|
#include <mapnik/font_set.hpp>
|
||||||
#include <mapnik/path_expression_grammar.hpp>
|
#include <mapnik/path_expression_grammar.hpp>
|
||||||
|
@ -425,216 +422,9 @@ void agg_renderer<T>::process(line_symbolizer const& sym,
|
||||||
agg::render_scanlines(*ras_ptr, sl, ren);
|
agg::render_scanlines(*ras_ptr, sl, ren);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void agg_renderer<T>::process(point_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans)
|
|
||||||
{
|
|
||||||
double x;
|
|
||||||
double y;
|
|
||||||
double z=0;
|
|
||||||
|
|
||||||
std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature);
|
|
||||||
boost::optional<mapnik::image_ptr> data;
|
|
||||||
|
|
||||||
if ( filename.empty() )
|
|
||||||
{
|
|
||||||
// default OGC 4x4 black square
|
|
||||||
data = boost::optional<mapnik::image_ptr>(new image_data_32(4,4));
|
|
||||||
(*data)->set(0xff000000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data = mapnik::image_cache::instance()->find(filename,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( data )
|
|
||||||
{
|
|
||||||
for (unsigned i=0;i<feature.num_geometries();++i)
|
|
||||||
{
|
|
||||||
geometry2d const& geom = feature.get_geometry(i);
|
|
||||||
|
|
||||||
geom.label_position(&x,&y);
|
|
||||||
prj_trans.backward(x,y,z);
|
|
||||||
t_.forward(&x,&y);
|
|
||||||
int w = (*data)->width();
|
|
||||||
int h = (*data)->height();
|
|
||||||
int px=int(floor(x - 0.5 * w));
|
|
||||||
int py=int(floor(y - 0.5 * h));
|
|
||||||
box2d<double> label_ext (floor(x - 0.5 * w),
|
|
||||||
floor(y - 0.5 * h),
|
|
||||||
ceil (x + 0.5 * w),
|
|
||||||
ceil (y + 0.5 * h));
|
|
||||||
if (sym.get_allow_overlap() ||
|
|
||||||
detector_.has_placement(label_ext))
|
|
||||||
{
|
|
||||||
pixmap_.set_rectangle_alpha2(*(*data),px,py,sym.get_opacity());
|
|
||||||
detector_.insert(label_ext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void agg_renderer<T>::process(shield_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans)
|
|
||||||
{
|
|
||||||
typedef coord_transform2<CoordTransform,geometry2d> path_type;
|
|
||||||
|
|
||||||
UnicodeString text;
|
|
||||||
if( sym.get_no_text() )
|
|
||||||
text = UnicodeString( " " ); // TODO: fix->use 'space' as the text to render
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expression_ptr name_expr = sym.get_name();
|
|
||||||
if (!name_expr) return;
|
|
||||||
value_type result = boost::apply_visitor(evaluate<Feature,value_type>(feature),*name_expr);
|
|
||||||
text = result.to_unicode();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( sym.get_text_convert() == TOUPPER)
|
|
||||||
{
|
|
||||||
text = text.toUpper();
|
|
||||||
}
|
|
||||||
else if ( sym.get_text_convert() == TOLOWER)
|
|
||||||
{
|
|
||||||
text = text.toLower();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature);
|
|
||||||
boost::optional<mapnik::image_ptr> data = mapnik::image_cache::instance()->find(filename,true);
|
|
||||||
|
|
||||||
if (text.length() > 0 && data)
|
|
||||||
{
|
|
||||||
face_set_ptr faces;
|
|
||||||
|
|
||||||
if (sym.get_fontset().size() > 0)
|
|
||||||
{
|
|
||||||
faces = font_manager_.get_face_set(sym.get_fontset());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
faces = font_manager_.get_face_set(sym.get_face_name());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (faces->size() > 0)
|
|
||||||
{
|
|
||||||
text_renderer<T> ren(pixmap_, faces);
|
|
||||||
|
|
||||||
ren.set_pixel_size(sym.get_text_size());
|
|
||||||
ren.set_fill(sym.get_fill());
|
|
||||||
ren.set_halo_fill(sym.get_halo_fill());
|
|
||||||
ren.set_halo_radius(sym.get_halo_radius());
|
|
||||||
|
|
||||||
placement_finder<label_collision_detector4> finder(detector_);
|
|
||||||
|
|
||||||
string_info info(text);
|
|
||||||
|
|
||||||
faces->get_string_info(info);
|
|
||||||
|
|
||||||
|
|
||||||
int w = (*data)->width();
|
|
||||||
int h = (*data)->height();
|
|
||||||
|
|
||||||
unsigned num_geom = feature.num_geometries();
|
|
||||||
for (unsigned i=0;i<num_geom;++i)
|
|
||||||
{
|
|
||||||
geometry2d const& geom = feature.get_geometry(i);
|
|
||||||
if (geom.num_points() > 0 )
|
|
||||||
{
|
|
||||||
path_type path(t_,geom,prj_trans);
|
|
||||||
|
|
||||||
label_placement_enum how_placed = sym.get_label_placement();
|
|
||||||
if (how_placed == POINT_PLACEMENT || how_placed == VERTEX_PLACEMENT)
|
|
||||||
{
|
|
||||||
// for every vertex, try and place a shield/text
|
|
||||||
geom.rewind(0);
|
|
||||||
for( unsigned jj = 0; jj < geom.num_points(); jj++ )
|
|
||||||
{
|
|
||||||
double label_x;
|
|
||||||
double label_y;
|
|
||||||
double z=0.0;
|
|
||||||
placement text_placement(info, sym, w, h, false);
|
|
||||||
text_placement.avoid_edges = sym.get_avoid_edges();
|
|
||||||
text_placement.allow_overlap = sym.get_allow_overlap();
|
|
||||||
if( how_placed == VERTEX_PLACEMENT )
|
|
||||||
geom.vertex(&label_x,&label_y); // by vertex
|
|
||||||
else
|
|
||||||
geom.label_position(&label_x, &label_y); // by middle of line or by point
|
|
||||||
prj_trans.backward(label_x,label_y, z);
|
|
||||||
t_.forward(&label_x,&label_y);
|
|
||||||
|
|
||||||
finder.find_point_placement( text_placement,label_x,label_y,0.0,sym.get_vertical_alignment(),sym.get_line_spacing(),
|
|
||||||
sym.get_character_spacing(),sym.get_horizontal_alignment(),sym.get_justify_alignment() );
|
|
||||||
|
|
||||||
// check to see if image overlaps anything too, there is only ever 1 placement found for points and verticies
|
|
||||||
if( text_placement.placements.size() > 0)
|
|
||||||
{
|
|
||||||
double x = text_placement.placements[0].starting_x;
|
|
||||||
double y = text_placement.placements[0].starting_y;
|
|
||||||
int px;
|
|
||||||
int py;
|
|
||||||
box2d<double> label_ext;
|
|
||||||
|
|
||||||
if( !sym.get_unlock_image() )
|
|
||||||
{ // center image at text center position
|
|
||||||
// remove displacement from image label
|
|
||||||
position pos = sym.get_displacement();
|
|
||||||
double lx = x - boost::get<0>(pos);
|
|
||||||
double ly = y - boost::get<1>(pos);
|
|
||||||
px=int(floor(lx - (0.5 * w))) ;
|
|
||||||
py=int(floor(ly - (0.5 * h))) ;
|
|
||||||
label_ext.init( floor(lx - 0.5 * w), floor(ly - 0.5 * h), ceil (lx + 0.5 * w), ceil (ly + 0.5 * h) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // center image at reference location
|
|
||||||
px=int(floor(label_x - 0.5 * w));
|
|
||||||
py=int(floor(label_y - 0.5 * h));
|
|
||||||
label_ext.init( floor(label_x - 0.5 * w), floor(label_y - 0.5 * h), ceil (label_x + 0.5 * w), ceil (label_y + 0.5 * h));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( sym.get_allow_overlap() || detector_.has_placement(label_ext) )
|
|
||||||
{
|
|
||||||
//pixmap_.set_rectangle_alpha(px,py,*data);
|
|
||||||
pixmap_.set_rectangle_alpha2(*(*data),px,py,float(sym.get_opacity()));
|
|
||||||
box2d<double> dim = ren.prepare_glyphs(&text_placement.placements[0]);
|
|
||||||
ren.render(x,y);
|
|
||||||
detector_.insert(label_ext);
|
|
||||||
finder.update_detector(text_placement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (geom.num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT)
|
|
||||||
{
|
|
||||||
placement text_placement(info, sym, w, h, true);
|
|
||||||
text_placement.avoid_edges = sym.get_avoid_edges();
|
|
||||||
finder.find_point_placements<path_type>(text_placement,path);
|
|
||||||
|
|
||||||
for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ ii)
|
|
||||||
{
|
|
||||||
int w = (*data)->width();
|
|
||||||
int h = (*data)->height();
|
|
||||||
double x = text_placement.placements[ii].starting_x;
|
|
||||||
double y = text_placement.placements[ii].starting_y;
|
|
||||||
|
|
||||||
int px=int(x - (w/2));
|
|
||||||
int py=int(y - (h/2));
|
|
||||||
|
|
||||||
pixmap_.set_rectangle_alpha(px,py,*(*data));
|
|
||||||
|
|
||||||
box2d<double> dim = ren.prepare_glyphs(&text_placement.placements[ii]);
|
|
||||||
ren.render(x,y);
|
|
||||||
}
|
|
||||||
finder.update_detector(text_placement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void agg_renderer<T>::process(line_pattern_symbolizer const& sym,
|
void agg_renderer<T>::process(line_pattern_symbolizer const& sym,
|
||||||
|
@ -812,80 +602,6 @@ void agg_renderer<T>::process(raster_symbolizer const& sym,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void agg_renderer<T>::process(markers_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans)
|
|
||||||
{
|
|
||||||
typedef coord_transform2<CoordTransform,geometry2d> path_type;
|
|
||||||
typedef agg::pixfmt_rgba32 pixfmt;
|
|
||||||
typedef agg::renderer_base<pixfmt> renderer_base;
|
|
||||||
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
|
|
||||||
|
|
||||||
bool svg_marker;
|
|
||||||
arrow arrow_;
|
|
||||||
box2d<double> extent;
|
|
||||||
boost::optional<path_ptr> marker;
|
|
||||||
|
|
||||||
ras_ptr->reset();
|
|
||||||
ras_ptr->gamma(agg::gamma_linear());
|
|
||||||
agg::scanline_u8 sl;
|
|
||||||
agg::rendering_buffer buf(pixmap_.raw_data(), width_, height_, width_ * 4);
|
|
||||||
pixfmt pixf(buf);
|
|
||||||
renderer_base renb(pixf);
|
|
||||||
renderer_solid ren(renb);
|
|
||||||
|
|
||||||
color const& fill_ = sym.get_fill();
|
|
||||||
unsigned r = fill_.red();
|
|
||||||
unsigned g = fill_.green();
|
|
||||||
unsigned b = fill_.blue();
|
|
||||||
unsigned a = fill_.alpha();
|
|
||||||
|
|
||||||
|
|
||||||
for (unsigned i=0; i<feature.num_geometries(); ++i)
|
|
||||||
{
|
|
||||||
geometry2d const& geom = feature.get_geometry(i);
|
|
||||||
if (geom.num_points() <= 1) continue;
|
|
||||||
|
|
||||||
svg_marker = false;
|
|
||||||
extent = arrow_.extent();
|
|
||||||
|
|
||||||
std::string filename = path_processor_type::evaluate(*sym.get_filename(), feature);
|
|
||||||
|
|
||||||
if (!filename.empty())
|
|
||||||
{
|
|
||||||
marker = mapnik::marker_cache::instance()->find(filename, true);
|
|
||||||
if (marker && *marker)
|
|
||||||
{
|
|
||||||
svg_marker = true;
|
|
||||||
double x1, y1, x2, y2;
|
|
||||||
(*marker)->bounding_rect(&x1, &y1, &x2, &y2);
|
|
||||||
extent.init(x1, y1, x2, y2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
path_type path(t_,geom,prj_trans);
|
|
||||||
markers_placement<path_type, label_collision_detector4> placement(path, extent, detector_, sym.get_spacing(), sym.get_max_error(), sym.get_allow_overlap());
|
|
||||||
|
|
||||||
double x, y, angle;
|
|
||||||
|
|
||||||
while (placement.get_point(&x, &y, &angle))
|
|
||||||
{
|
|
||||||
agg::trans_affine matrix = agg::trans_affine_rotation(angle) * agg::trans_affine_translation(x, y);
|
|
||||||
if (svg_marker)
|
|
||||||
{
|
|
||||||
(*marker)->render(*ras_ptr, sl, ren, matrix, renb.clip_box(), 1.0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
agg::conv_transform<arrow, agg::trans_affine> trans(arrow_, matrix);
|
|
||||||
ras_ptr->add_path(trans);
|
|
||||||
ren.color(agg::rgba8(r, g, b, a));
|
|
||||||
agg::render_scanlines(*ras_ptr, sl, ren);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void agg_renderer<T>::process(text_symbolizer const& sym,
|
void agg_renderer<T>::process(text_symbolizer const& sym,
|
||||||
|
|
Loading…
Reference in a new issue