2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2006-03-10 13:08:55 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* Copyright (C) 2006 Artem Pavlenko
|
2006-03-10 13:08:55 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2006-03-10 13:08:55 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-03-10 13:08:55 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
*****************************************************************************/
|
2006-03-10 13:08:55 +01:00
|
|
|
|
|
|
|
//$Id$
|
|
|
|
|
2007-07-02 15:39:08 +02:00
|
|
|
//mapnik
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/text_symbolizer.hpp>
|
2007-10-08 19:42:41 +02:00
|
|
|
// boost
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
//stl
|
|
|
|
#include <iostream>
|
2006-03-10 13:08:55 +01:00
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
static const char * label_placement_strings[] = {
|
|
|
|
"point",
|
|
|
|
"line",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
2008-06-29 12:58:48 +02:00
|
|
|
|
2007-09-25 20:47:12 +02:00
|
|
|
IMPLEMENT_ENUM( mapnik::label_placement_e, label_placement_strings );
|
|
|
|
|
2006-03-10 13:08:55 +01:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2009-01-14 13:10:24 +01:00
|
|
|
text_symbolizer::text_symbolizer(std::string const& name, std::string const& face_name, unsigned size, color const& fill)
|
2007-07-02 15:39:08 +02:00
|
|
|
: name_(name),
|
2006-10-27 19:29:39 +02:00
|
|
|
face_name_(face_name),
|
2008-06-29 12:58:48 +02:00
|
|
|
//fontset_(default_fontset),
|
|
|
|
size_(size),
|
|
|
|
text_ratio_(0),
|
|
|
|
wrap_width_(0),
|
|
|
|
label_spacing_(0),
|
|
|
|
label_position_tolerance_(0),
|
|
|
|
force_odd_labels_(false),
|
|
|
|
max_char_angle_delta_(0),
|
|
|
|
fill_(fill),
|
2009-01-14 13:10:24 +01:00
|
|
|
halo_fill_(color(255,255,255)),
|
2008-06-29 12:58:48 +02:00
|
|
|
halo_radius_(0),
|
|
|
|
label_p_(POINT_PLACEMENT),
|
|
|
|
anchor_(0.0,0.5),
|
|
|
|
displacement_(0.0,0.0),
|
|
|
|
avoid_edges_(false),
|
|
|
|
minimum_distance_(0.0),
|
|
|
|
overlap_(false) {}
|
2009-01-14 13:10:24 +01:00
|
|
|
text_symbolizer::text_symbolizer(std::string const& name, unsigned size, color const& fill)
|
2008-06-29 12:58:48 +02:00
|
|
|
: name_(name),
|
|
|
|
//face_name_(""),
|
|
|
|
//fontset_(default_fontset),
|
2007-07-02 15:39:08 +02:00
|
|
|
size_(size),
|
2006-10-27 19:29:39 +02:00
|
|
|
text_ratio_(0),
|
|
|
|
wrap_width_(0),
|
2006-11-02 00:17:05 +01:00
|
|
|
label_spacing_(0),
|
2006-11-29 11:44:42 +01:00
|
|
|
label_position_tolerance_(0),
|
|
|
|
force_odd_labels_(false),
|
2006-11-04 11:38:24 +01:00
|
|
|
max_char_angle_delta_(0),
|
2007-07-02 15:39:08 +02:00
|
|
|
fill_(fill),
|
2009-01-14 13:10:24 +01:00
|
|
|
halo_fill_(color(255,255,255)),
|
2007-07-02 15:39:08 +02:00
|
|
|
halo_radius_(0),
|
2007-09-25 20:47:12 +02:00
|
|
|
label_p_(POINT_PLACEMENT),
|
2007-07-02 15:39:08 +02:00
|
|
|
anchor_(0.0,0.5),
|
|
|
|
displacement_(0.0,0.0),
|
2007-06-20 23:08:23 +02:00
|
|
|
avoid_edges_(false),
|
2007-07-02 15:39:08 +02:00
|
|
|
minimum_distance_(0.0),
|
2007-06-20 23:08:23 +02:00
|
|
|
overlap_(false) {}
|
2006-03-10 13:08:55 +01:00
|
|
|
text_symbolizer::text_symbolizer(text_symbolizer const& rhs)
|
2006-10-27 19:29:39 +02:00
|
|
|
: name_(rhs.name_),
|
|
|
|
face_name_(rhs.face_name_),
|
2008-06-29 12:58:48 +02:00
|
|
|
fontset_(rhs.fontset_),
|
2006-10-27 19:29:39 +02:00
|
|
|
size_(rhs.size_),
|
|
|
|
text_ratio_(rhs.text_ratio_),
|
|
|
|
wrap_width_(rhs.wrap_width_),
|
2006-11-02 00:17:05 +01:00
|
|
|
label_spacing_(rhs.label_spacing_),
|
2006-11-29 11:44:42 +01:00
|
|
|
label_position_tolerance_(rhs.label_position_tolerance_),
|
|
|
|
force_odd_labels_(rhs.force_odd_labels_),
|
2006-11-04 11:38:24 +01:00
|
|
|
max_char_angle_delta_(rhs.max_char_angle_delta_),
|
2006-10-27 19:29:39 +02:00
|
|
|
fill_(rhs.fill_),
|
|
|
|
halo_fill_(rhs.halo_fill_),
|
|
|
|
halo_radius_(rhs.halo_radius_),
|
|
|
|
label_p_(rhs.label_p_),
|
|
|
|
anchor_(rhs.anchor_),
|
2006-11-17 15:07:41 +01:00
|
|
|
displacement_(rhs.displacement_),
|
2007-06-20 23:08:23 +02:00
|
|
|
avoid_edges_(rhs.avoid_edges_),
|
2007-07-02 15:39:08 +02:00
|
|
|
minimum_distance_(rhs.minimum_distance_),
|
2007-06-20 23:08:23 +02:00
|
|
|
overlap_(rhs.overlap_) {}
|
|
|
|
|
2006-03-10 13:08:55 +01:00
|
|
|
text_symbolizer& text_symbolizer::operator=(text_symbolizer const& other)
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
if (this == &other)
|
|
|
|
return *this;
|
|
|
|
name_ = other.name_;
|
|
|
|
face_name_ = other.face_name_;
|
2008-06-29 12:58:48 +02:00
|
|
|
fontset_ = other.fontset_;
|
2006-10-27 19:29:39 +02:00
|
|
|
size_ = other.size_;
|
|
|
|
text_ratio_ = other.text_ratio_;
|
|
|
|
wrap_width_ = other.wrap_width_;
|
2006-11-02 00:17:05 +01:00
|
|
|
label_spacing_ = other.label_spacing_;
|
2006-11-29 11:44:42 +01:00
|
|
|
label_position_tolerance_ = other.label_position_tolerance_;
|
|
|
|
force_odd_labels_ = other.force_odd_labels_;
|
2006-11-04 11:38:24 +01:00
|
|
|
max_char_angle_delta_ = other.max_char_angle_delta_;
|
2006-10-27 19:29:39 +02:00
|
|
|
fill_ = other.fill_;
|
|
|
|
halo_fill_ = other.halo_fill_;
|
|
|
|
halo_radius_ = other.halo_radius_;
|
|
|
|
label_p_ = other.label_p_;
|
|
|
|
anchor_ = other.anchor_;
|
|
|
|
displacement_ = other.displacement_;
|
2006-11-17 15:07:41 +01:00
|
|
|
avoid_edges_ = other.avoid_edges_;
|
2007-07-02 15:39:08 +02:00
|
|
|
minimum_distance_ = other.minimum_distance_;
|
2007-06-20 23:08:23 +02:00
|
|
|
overlap_ = other.overlap_;
|
2007-07-02 15:39:08 +02:00
|
|
|
|
2006-10-27 19:29:39 +02:00
|
|
|
return *this;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string const& text_symbolizer::get_name() const
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return name_;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
2009-02-05 12:54:07 +01:00
|
|
|
void text_symbolizer::set_name(std::string name)
|
|
|
|
{
|
|
|
|
name_ = name;
|
|
|
|
}
|
|
|
|
|
2006-10-19 19:11:45 +02:00
|
|
|
std::string const& text_symbolizer::get_face_name() const
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return face_name_;
|
2006-10-19 19:11:45 +02:00
|
|
|
}
|
2008-06-29 12:58:48 +02:00
|
|
|
|
|
|
|
void text_symbolizer::set_face_name(std::string face_name)
|
|
|
|
{
|
|
|
|
face_name_ = face_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_fontset(FontSet fontset)
|
|
|
|
{
|
|
|
|
fontset_ = fontset;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontSet const& text_symbolizer::get_fontset() const
|
|
|
|
{
|
|
|
|
return fontset_;
|
|
|
|
}
|
|
|
|
|
2006-10-27 19:29:39 +02:00
|
|
|
unsigned text_symbolizer::get_text_ratio() const
|
|
|
|
{
|
2008-06-29 12:58:48 +02:00
|
|
|
return text_ratio_;
|
2006-10-27 19:29:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_text_ratio(unsigned ratio)
|
|
|
|
{
|
|
|
|
text_ratio_ = ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned text_symbolizer::get_wrap_width() const
|
|
|
|
{
|
2008-06-29 12:58:48 +02:00
|
|
|
return wrap_width_;
|
2006-10-27 19:29:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_wrap_width(unsigned width)
|
|
|
|
{
|
|
|
|
wrap_width_ = width;
|
2006-11-02 00:17:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned text_symbolizer::get_label_spacing() const
|
|
|
|
{
|
2006-11-04 11:38:24 +01:00
|
|
|
return label_spacing_;
|
2006-11-02 00:17:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_label_spacing(unsigned spacing)
|
|
|
|
{
|
|
|
|
label_spacing_ = spacing;
|
2006-10-27 19:29:39 +02:00
|
|
|
}
|
|
|
|
|
2006-11-29 11:44:42 +01:00
|
|
|
unsigned text_symbolizer::get_label_position_tolerance() const
|
|
|
|
{
|
|
|
|
return label_position_tolerance_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_label_position_tolerance(unsigned tolerance)
|
|
|
|
{
|
|
|
|
label_position_tolerance_ = tolerance;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool text_symbolizer::get_force_odd_labels() const
|
|
|
|
{
|
|
|
|
return force_odd_labels_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_force_odd_labels(bool force)
|
|
|
|
{
|
|
|
|
force_odd_labels_ = force;
|
|
|
|
}
|
|
|
|
|
2006-11-04 11:38:24 +01:00
|
|
|
double text_symbolizer::get_max_char_angle_delta() const
|
|
|
|
{
|
|
|
|
return max_char_angle_delta_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_max_char_angle_delta(double angle)
|
|
|
|
{
|
|
|
|
max_char_angle_delta_ = angle;
|
|
|
|
}
|
|
|
|
|
2009-02-05 12:54:07 +01:00
|
|
|
void text_symbolizer::set_text_size(unsigned size)
|
|
|
|
{
|
|
|
|
size_ = size;
|
|
|
|
}
|
|
|
|
|
2006-03-10 13:08:55 +01:00
|
|
|
unsigned text_symbolizer::get_text_size() const
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return size_;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
2009-02-05 12:54:07 +01:00
|
|
|
|
|
|
|
void text_symbolizer::set_fill(color const& fill)
|
|
|
|
{
|
|
|
|
fill_ = fill;
|
|
|
|
}
|
2006-03-10 13:08:55 +01:00
|
|
|
|
2009-01-14 13:10:24 +01:00
|
|
|
color const& text_symbolizer::get_fill() const
|
2006-03-10 13:08:55 +01:00
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return fill_;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
2009-01-14 13:10:24 +01:00
|
|
|
void text_symbolizer::set_halo_fill(color const& fill)
|
2006-03-10 13:08:55 +01:00
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
halo_fill_ = fill;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
2009-01-14 13:10:24 +01:00
|
|
|
color const& text_symbolizer::get_halo_fill() const
|
2006-03-10 13:08:55 +01:00
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return halo_fill_;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_halo_radius(unsigned radius)
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
halo_radius_ = radius;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned text_symbolizer::get_halo_radius() const
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return halo_radius_;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_label_placement(label_placement_e label_p)
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
label_p_ = label_p;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
label_placement_e text_symbolizer::get_label_placement() const
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return label_p_;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_anchor(double x, double y)
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
anchor_ = boost::make_tuple(x,y);
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
position const& text_symbolizer::get_anchor () const
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return anchor_;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
void text_symbolizer::set_displacement(double x, double y)
|
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
displacement_ = boost::make_tuple(x,y);
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
|
|
|
|
2007-02-09 17:32:44 +01:00
|
|
|
position const& text_symbolizer::get_displacement() const
|
2006-03-10 13:08:55 +01:00
|
|
|
{
|
2006-10-27 19:29:39 +02:00
|
|
|
return displacement_;
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|
2006-11-17 15:07:41 +01:00
|
|
|
|
|
|
|
bool text_symbolizer::get_avoid_edges() const
|
|
|
|
{
|
|
|
|
return avoid_edges_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_avoid_edges(bool avoid)
|
|
|
|
{
|
|
|
|
avoid_edges_ = avoid;
|
|
|
|
}
|
2007-06-20 23:08:23 +02:00
|
|
|
|
2007-07-02 15:39:08 +02:00
|
|
|
double text_symbolizer::get_minimum_distance() const
|
|
|
|
{
|
|
|
|
return minimum_distance_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_minimum_distance(double distance)
|
|
|
|
{
|
|
|
|
minimum_distance_ = distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_symbolizer::set_allow_overlap(bool overlap)
|
|
|
|
{
|
|
|
|
overlap_ = overlap;
|
|
|
|
}
|
2007-06-20 23:08:23 +02:00
|
|
|
|
2007-07-02 15:39:08 +02:00
|
|
|
bool text_symbolizer::get_allow_overlap() const
|
|
|
|
{
|
2007-06-20 23:08:23 +02:00
|
|
|
return overlap_;
|
2007-07-02 15:39:08 +02:00
|
|
|
}
|
2006-03-10 13:08:55 +01:00
|
|
|
}
|