Complete symbolizer_helpers.hpp for TextSymbolizer.
This commit is contained in:
parent
469568862b
commit
bdc20f766b
2 changed files with 29 additions and 120 deletions
|
@ -93,10 +93,38 @@ text_placement_info_ptr text_symbolizer_helper<FaceManagerT, DetectorT>::get_pla
|
||||||
if (writer.first)
|
if (writer.first)
|
||||||
placement->collect_extents = true;
|
placement->collect_extents = true;
|
||||||
|
|
||||||
|
unsigned num_geom = feature.num_geometries();
|
||||||
|
if (!num_geom) return text_placement_info_ptr(); //Nothing to do
|
||||||
|
|
||||||
while (placement->next())
|
while (placement->next())
|
||||||
{
|
{
|
||||||
text_processor &processor = placement->properties.processor;
|
text_processor &processor = placement->properties.processor;
|
||||||
|
text_symbolizer_properties const& p = placement->properties;
|
||||||
|
/* TODO: Simplify this. */
|
||||||
|
text_->clear();
|
||||||
|
processor.process(*text_, feature);
|
||||||
|
string_info &info = text_->get_string_info();
|
||||||
|
/* END TODO */
|
||||||
|
double angle = 0.0;
|
||||||
|
if (p.orientation)
|
||||||
|
{
|
||||||
|
angle = boost::apply_visitor(evaluate<Feature,value_type>(feature),*(p.orientation)).to_double();
|
||||||
}
|
}
|
||||||
|
placement_finder<DetectorT> finder(*placement, info, detector_, dims);
|
||||||
|
|
||||||
|
unsigned num_geom = feature.num_geometries();
|
||||||
|
for (unsigned i=0; i<num_geom; ++i)
|
||||||
|
{
|
||||||
|
geometry_type const& geom = feature.get_geometry(i);
|
||||||
|
if (geom.num_points() == 0) continue; // don't bother with empty geometries
|
||||||
|
finder.find_placement(angle, geom, t_, prj_trans);
|
||||||
|
if (!placement->placements.size())
|
||||||
|
continue;
|
||||||
|
if (writer.first) writer.first->add_text(*placement, font_manager_, feature, t_, writer.second);
|
||||||
|
return placement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return text_placement_info_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FaceManagerT, typename DetectorT>
|
template <typename FaceManagerT, typename DetectorT>
|
||||||
|
|
|
@ -37,7 +37,7 @@ void agg_renderer<T>::process(text_symbolizer const& sym,
|
||||||
to check if any of the variables changes and notify the helper.
|
to check if any of the variables changes and notify the helper.
|
||||||
It could be done at a later point, but for now keep the code simple.
|
It could be done at a later point, but for now keep the code simple.
|
||||||
*/
|
*/
|
||||||
text_symbolizer_helper<face_manager<freetype_engine>, boost::shared_ptr<label_collision_detector4> > helper(width_, height_, scale_factor_, t_, font_manager_, detector_);
|
text_symbolizer_helper<face_manager<freetype_engine>, label_collision_detector4> helper(width_, height_, scale_factor_, t_, font_manager_, *detector_);
|
||||||
|
|
||||||
text_placement_info_ptr placement = helper.get_placement(sym, feature, prj_trans);
|
text_placement_info_ptr placement = helper.get_placement(sym, feature, prj_trans);
|
||||||
|
|
||||||
|
@ -51,125 +51,6 @@ void agg_renderer<T>::process(text_symbolizer const& sym,
|
||||||
ren.prepare_glyphs(&(placement->placements[ii]));
|
ren.prepare_glyphs(&(placement->placements[ii]));
|
||||||
ren.render(x, y);
|
ren.render(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
|
|
||||||
bool placement_found = false;
|
|
||||||
text_placement_info_ptr placement_options = sym.get_placement_options()->get_placement_info();
|
|
||||||
while (!placement_found && placement_options->next())
|
|
||||||
{
|
|
||||||
expression_ptr name_expr = sym.get_name();
|
|
||||||
if (!name_expr) return;
|
|
||||||
value_type result = boost::apply_visitor(evaluate<Feature,value_type>(feature),*name_expr);
|
|
||||||
UnicodeString text = result.to_unicode();
|
|
||||||
|
|
||||||
if ( sym.get_text_transform() == UPPERCASE)
|
|
||||||
{
|
|
||||||
text = text.toUpper();
|
|
||||||
}
|
|
||||||
else if ( sym.get_text_transform() == LOWERCASE)
|
|
||||||
{
|
|
||||||
text = text.toLower();
|
|
||||||
}
|
|
||||||
else if ( sym.get_text_transform() == CAPITALIZE)
|
|
||||||
{
|
|
||||||
text = text.toTitle(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( text.length() <= 0 ) continue;
|
|
||||||
color const& fill = sym.get_fill();
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
stroker_ptr strk = font_manager_.get_stroker();
|
|
||||||
if (!(faces->size() > 0 && strk))
|
|
||||||
{
|
|
||||||
throw config_error("Unable to find specified font face '" + sym.get_face_name() + "'");
|
|
||||||
}
|
|
||||||
text_renderer<T> ren(pixmap_, faces, *strk);
|
|
||||||
|
|
||||||
ren.set_character_size(placement_options->text_size * scale_factor_);
|
|
||||||
ren.set_fill(fill);
|
|
||||||
ren.set_halo_fill(sym.get_halo_fill());
|
|
||||||
ren.set_halo_radius(sym.get_halo_radius() * scale_factor_);
|
|
||||||
ren.set_opacity(sym.get_text_opacity());
|
|
||||||
|
|
||||||
box2d<double> dims(0,0,width_,height_);
|
|
||||||
placement_finder<label_collision_detector4> finder(*detector_,dims);
|
|
||||||
|
|
||||||
string_info info(text);
|
|
||||||
|
|
||||||
faces->get_string_info(info, text, 0);
|
|
||||||
metawriter_with_properties writer = sym.get_metawriter();
|
|
||||||
|
|
||||||
BOOST_FOREACH( geometry_type * geom, geometries_to_process )
|
|
||||||
{
|
|
||||||
while (!placement_found && placement_options->next_position_only())
|
|
||||||
{
|
|
||||||
placement text_placement(info, sym, scale_factor_);
|
|
||||||
text_placement.avoid_edges = sym.get_avoid_edges();
|
|
||||||
if (writer.first)
|
|
||||||
text_placement.collect_extents =true; // needed for inmem metawriter
|
|
||||||
|
|
||||||
if (sym.get_label_placement() == POINT_PLACEMENT ||
|
|
||||||
sym.get_label_placement() == INTERIOR_PLACEMENT)
|
|
||||||
{
|
|
||||||
double label_x=0.0;
|
|
||||||
double label_y=0.0;
|
|
||||||
double z=0.0;
|
|
||||||
if (sym.get_label_placement() == POINT_PLACEMENT)
|
|
||||||
geom->label_position(&label_x, &label_y);
|
|
||||||
else
|
|
||||||
geom->label_interior_position(&label_x, &label_y);
|
|
||||||
prj_trans.backward(label_x,label_y, z);
|
|
||||||
t_.forward(&label_x,&label_y);
|
|
||||||
|
|
||||||
double angle = 0.0;
|
|
||||||
expression_ptr angle_expr = sym.get_orientation();
|
|
||||||
if (angle_expr)
|
|
||||||
{
|
|
||||||
// apply rotation
|
|
||||||
value_type result = boost::apply_visitor(evaluate<Feature,value_type>(feature),*angle_expr);
|
|
||||||
angle = result.to_double();
|
|
||||||
}
|
|
||||||
|
|
||||||
finder.find_point_placement(text_placement, placement_options, label_x,label_y,
|
|
||||||
angle, sym.get_line_spacing(),
|
|
||||||
sym.get_character_spacing());
|
|
||||||
finder.update_detector(text_placement);
|
|
||||||
}
|
|
||||||
else if ( geom->num_points() > 1 && sym.get_label_placement() == LINE_PLACEMENT)
|
|
||||||
{
|
|
||||||
path_type path(t_,*geom,prj_trans);
|
|
||||||
finder.find_line_placements<path_type>(text_placement, placement_options, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!text_placement.placements.size()) continue;
|
|
||||||
placement_found = true;
|
|
||||||
|
|
||||||
for (unsigned int ii = 0; ii < text_placement.placements.size(); ++ii)
|
|
||||||
{
|
|
||||||
double x = text_placement.placements[ii].starting_x;
|
|
||||||
double y = text_placement.placements[ii].starting_y;
|
|
||||||
ren.prepare_glyphs(&text_placement.placements[ii]);
|
|
||||||
ren.render(x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (writer.first) writer.first->add_text(text_placement, faces, feature, t_, writer.second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template void agg_renderer<image_32>::process(text_symbolizer const&,
|
template void agg_renderer<image_32>::process(text_symbolizer const&,
|
||||||
|
|
Loading…
Reference in a new issue