Add alignment to text_placement_info.
This commit is contained in:
parent
8322a96575
commit
de089f0d68
5 changed files with 140 additions and 116 deletions
|
@ -22,6 +22,9 @@
|
|||
#ifndef TEXT_PLACEMENTS_HPP
|
||||
#define TEXT_PLACEMENTS_HPP
|
||||
|
||||
//mapnik
|
||||
#include <mapnik/enumeration.hpp>
|
||||
|
||||
//stl
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -34,9 +37,65 @@ namespace mapnik {
|
|||
|
||||
typedef boost::tuple<double,double> position;
|
||||
|
||||
enum label_placement_enum {
|
||||
POINT_PLACEMENT,
|
||||
LINE_PLACEMENT,
|
||||
VERTEX_PLACEMENT,
|
||||
INTERIOR_PLACEMENT,
|
||||
label_placement_enum_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( label_placement_e, label_placement_enum );
|
||||
|
||||
enum vertical_alignment
|
||||
{
|
||||
V_TOP = 0,
|
||||
V_MIDDLE,
|
||||
V_BOTTOM,
|
||||
V_AUTO,
|
||||
vertical_alignment_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( vertical_alignment_e, vertical_alignment );
|
||||
|
||||
enum horizontal_alignment
|
||||
{
|
||||
H_LEFT = 0,
|
||||
H_MIDDLE,
|
||||
H_RIGHT,
|
||||
H_AUTO,
|
||||
horizontal_alignment_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( horizontal_alignment_e, horizontal_alignment );
|
||||
|
||||
enum justify_alignment
|
||||
{
|
||||
J_LEFT = 0,
|
||||
J_MIDDLE,
|
||||
J_RIGHT,
|
||||
justify_alignment_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( justify_alignment_e, justify_alignment );
|
||||
|
||||
enum text_transform
|
||||
{
|
||||
NONE = 0,
|
||||
UPPERCASE,
|
||||
LOWERCASE,
|
||||
CAPITALIZE,
|
||||
text_transform_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( text_transform_e, text_transform );
|
||||
|
||||
class text_placements;
|
||||
|
||||
class text_placement_info
|
||||
{
|
||||
public:
|
||||
text_placement_info(text_placements const* parent);
|
||||
/** Get next placement.
|
||||
* This function is also called before the first placement is tried. */
|
||||
virtual bool next()=0;
|
||||
|
@ -51,6 +110,9 @@ public:
|
|||
/* NOTE: Values are public and non-virtual to avoid any performance problems. */
|
||||
position displacement;
|
||||
unsigned text_size;
|
||||
horizontal_alignment_e halign;
|
||||
justify_alignment_e jalign;
|
||||
vertical_alignment_e valign;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<text_placement_info> text_placement_info_ptr;
|
||||
|
@ -58,32 +120,38 @@ typedef boost::shared_ptr<text_placement_info> text_placement_info_ptr;
|
|||
class text_placements
|
||||
{
|
||||
public:
|
||||
text_placements() : text_size_(10) {}
|
||||
text_placements() :
|
||||
text_size_(10), halign_(H_MIDDLE), jalign_(J_MIDDLE), valign_(V_MIDDLE) {}
|
||||
virtual text_placement_info_ptr get_placement_info() const =0;
|
||||
|
||||
virtual void set_default_text_size(unsigned size) { text_size_ = size; }
|
||||
unsigned get_default_text_size() const { return text_size_; }
|
||||
|
||||
virtual void set_default_displacement(position const& displacement) { displacement_ = displacement;}
|
||||
position const& get_default_displacement() { return displacement_; }
|
||||
|
||||
virtual void set_default_halign(horizontal_alignment_e const& align) { halign_ = align;}
|
||||
horizontal_alignment_e const& get_default_halign() { return halign_; }
|
||||
|
||||
virtual void set_default_jalign(justify_alignment_e const& align) { jalign_ = align;}
|
||||
justify_alignment_e const& get_default_jalign() { return jalign_; }
|
||||
|
||||
virtual void set_default_valign(vertical_alignment_e const& align) { valign_ = align;}
|
||||
vertical_alignment_e const& get_default_valign() { return valign_; }
|
||||
|
||||
virtual ~text_placements() {}
|
||||
protected:
|
||||
unsigned text_size_;
|
||||
position displacement_;
|
||||
horizontal_alignment_e halign_;
|
||||
justify_alignment_e jalign_;
|
||||
vertical_alignment_e valign_;
|
||||
friend class text_placement_info;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<text_placements> text_placements_ptr;
|
||||
|
||||
class text_placements_dummy;
|
||||
class text_placement_info_dummy : public text_placement_info
|
||||
{
|
||||
public:
|
||||
text_placement_info_dummy(text_placements_dummy const* parent) : state(0), position_state(0), parent_(parent) {}
|
||||
bool next();
|
||||
bool next_position_only();
|
||||
private:
|
||||
unsigned state;
|
||||
unsigned position_state;
|
||||
text_placements_dummy const* parent_;
|
||||
};
|
||||
class text_placements_info_dummy;
|
||||
|
||||
class text_placements_dummy: public text_placements
|
||||
{
|
||||
|
@ -92,6 +160,21 @@ public:
|
|||
friend class text_placement_info_dummy;
|
||||
};
|
||||
|
||||
class text_placement_info_dummy : public text_placement_info
|
||||
{
|
||||
public:
|
||||
text_placement_info_dummy(text_placements_dummy const* parent) : text_placement_info(parent),
|
||||
state(0), position_state(0), parent_(parent) {}
|
||||
bool next();
|
||||
bool next_position_only();
|
||||
private:
|
||||
unsigned state;
|
||||
unsigned position_state;
|
||||
text_placements_dummy const* parent_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif // TEXT_PLACEMENTS_HPP
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
namespace mapnik {
|
||||
|
||||
class text_placements_simple;
|
||||
class text_placement_info_simple;
|
||||
|
||||
typedef enum {
|
||||
NORTH,
|
||||
|
@ -39,20 +39,6 @@ typedef enum {
|
|||
EXACT_POSITION
|
||||
} directions_t;
|
||||
|
||||
/** Simple placement strategy.
|
||||
* See parent class for documentation of each function. */
|
||||
class text_placement_info_simple : public text_placement_info
|
||||
{
|
||||
public:
|
||||
text_placement_info_simple(text_placements_simple const* parent) : state(0), position_state(0), parent_(parent) {}
|
||||
bool next();
|
||||
bool next_position_only();
|
||||
private:
|
||||
unsigned state;
|
||||
unsigned position_state;
|
||||
text_placements_simple const* parent_;
|
||||
};
|
||||
|
||||
|
||||
/** Automatically generates placement options from a user selected list of directions and text sizes. */
|
||||
class text_placements_simple: public text_placements
|
||||
|
@ -69,5 +55,21 @@ private:
|
|||
friend class text_placement_info_simple;
|
||||
};
|
||||
|
||||
/** Simple placement strategy.
|
||||
* See parent class for documentation of each function. */
|
||||
class text_placement_info_simple : public text_placement_info
|
||||
{
|
||||
public:
|
||||
text_placement_info_simple(text_placements_simple const* parent) :
|
||||
text_placement_info(parent), state(0), position_state(0), parent_(parent) {}
|
||||
bool next();
|
||||
bool next_position_only();
|
||||
private:
|
||||
unsigned state;
|
||||
unsigned position_state;
|
||||
text_placements_simple const* parent_;
|
||||
};
|
||||
|
||||
|
||||
} //namespace
|
||||
#endif
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#define MAPNIK_TEXT_SYMBOLIZER_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/enumeration.hpp>
|
||||
#include <mapnik/color.hpp>
|
||||
#include <mapnik/font_set.hpp>
|
||||
#include <mapnik/graphics.hpp>
|
||||
|
@ -43,59 +42,6 @@
|
|||
|
||||
namespace mapnik
|
||||
{
|
||||
enum label_placement_enum {
|
||||
POINT_PLACEMENT,
|
||||
LINE_PLACEMENT,
|
||||
VERTEX_PLACEMENT,
|
||||
INTERIOR_PLACEMENT,
|
||||
label_placement_enum_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( label_placement_e, label_placement_enum );
|
||||
|
||||
enum vertical_alignment
|
||||
{
|
||||
V_TOP = 0,
|
||||
V_MIDDLE,
|
||||
V_BOTTOM,
|
||||
V_AUTO,
|
||||
vertical_alignment_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( vertical_alignment_e, vertical_alignment );
|
||||
|
||||
enum horizontal_alignment
|
||||
{
|
||||
H_LEFT = 0,
|
||||
H_MIDDLE,
|
||||
H_RIGHT,
|
||||
H_AUTO,
|
||||
horizontal_alignment_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( horizontal_alignment_e, horizontal_alignment );
|
||||
|
||||
enum justify_alignment
|
||||
{
|
||||
J_LEFT = 0,
|
||||
J_MIDDLE,
|
||||
J_RIGHT,
|
||||
justify_alignment_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( justify_alignment_e, justify_alignment );
|
||||
|
||||
enum text_transform
|
||||
{
|
||||
NONE = 0,
|
||||
UPPERCASE,
|
||||
LOWERCASE,
|
||||
CAPITALIZE,
|
||||
text_transform_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( text_transform_e, text_transform );
|
||||
|
||||
|
||||
struct MAPNIK_DECL text_symbolizer : public symbolizer_base
|
||||
{
|
||||
|
@ -196,7 +142,6 @@ private:
|
|||
color halo_fill_;
|
||||
double halo_radius_;
|
||||
label_placement_e label_p_;
|
||||
vertical_alignment_e valign_;
|
||||
position anchor_;
|
||||
bool avoid_edges_;
|
||||
double minimum_distance_;
|
||||
|
@ -204,8 +149,6 @@ private:
|
|||
bool overlap_;
|
||||
double text_opacity_;
|
||||
bool wrap_before_;
|
||||
horizontal_alignment_e halign_;
|
||||
justify_alignment_e jalign_;
|
||||
text_placements_ptr placement_options_;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -37,10 +37,19 @@ using phoenix::push_back;
|
|||
using phoenix::ref;
|
||||
using qi::_1;
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
text_placement_info::text_placement_info(text_placements const* parent):
|
||||
displacement(parent->displacement_),
|
||||
text_size(parent->text_size_), halign(parent->halign_), jalign(parent->jalign_),
|
||||
valign(parent->valign_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool text_placement_info_dummy::next()
|
||||
{
|
||||
displacement = parent_->displacement_;
|
||||
text_size = parent_->text_size_;
|
||||
if (state) return false;
|
||||
state++;
|
||||
return true;
|
||||
|
@ -70,7 +79,6 @@ bool text_placement_info_simple::next()
|
|||
if (state > parent_->text_sizes_.size()) return false;
|
||||
text_size = parent_->text_sizes_[state-1];
|
||||
}
|
||||
std::cerr << "Trying text_size=" << text_size << "\n";
|
||||
state++;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,6 @@ text_symbolizer::text_symbolizer(expression_ptr name, std::string const& face_na
|
|||
halo_fill_(color(255,255,255)),
|
||||
halo_radius_(0),
|
||||
label_p_(POINT_PLACEMENT),
|
||||
valign_(V_MIDDLE),
|
||||
anchor_(0.0,0.5),
|
||||
avoid_edges_(false),
|
||||
minimum_distance_(0.0),
|
||||
|
@ -115,8 +114,6 @@ text_symbolizer::text_symbolizer(expression_ptr name, std::string const& face_na
|
|||
overlap_(false),
|
||||
text_opacity_(1.0),
|
||||
wrap_before_(false),
|
||||
halign_(H_MIDDLE),
|
||||
jalign_(J_MIDDLE),
|
||||
placement_options_(placements)
|
||||
{
|
||||
set_text_size(size);
|
||||
|
@ -142,7 +139,6 @@ text_symbolizer::text_symbolizer(expression_ptr name, unsigned size, color const
|
|||
halo_fill_(color(255,255,255)),
|
||||
halo_radius_(0),
|
||||
label_p_(POINT_PLACEMENT),
|
||||
valign_(V_MIDDLE),
|
||||
anchor_(0.0,0.5),
|
||||
avoid_edges_(false),
|
||||
minimum_distance_(0.0),
|
||||
|
@ -150,8 +146,6 @@ text_symbolizer::text_symbolizer(expression_ptr name, unsigned size, color const
|
|||
overlap_(false),
|
||||
text_opacity_(1.0),
|
||||
wrap_before_(false),
|
||||
halign_(H_MIDDLE),
|
||||
jalign_(J_MIDDLE),
|
||||
placement_options_(placements)
|
||||
{
|
||||
set_text_size(size);
|
||||
|
@ -177,7 +171,6 @@ text_symbolizer::text_symbolizer(text_symbolizer const& rhs)
|
|||
halo_fill_(rhs.halo_fill_),
|
||||
halo_radius_(rhs.halo_radius_),
|
||||
label_p_(rhs.label_p_),
|
||||
valign_(rhs.valign_),
|
||||
anchor_(rhs.anchor_),
|
||||
avoid_edges_(rhs.avoid_edges_),
|
||||
minimum_distance_(rhs.minimum_distance_),
|
||||
|
@ -185,9 +178,7 @@ text_symbolizer::text_symbolizer(text_symbolizer const& rhs)
|
|||
overlap_(rhs.overlap_),
|
||||
text_opacity_(rhs.text_opacity_),
|
||||
wrap_before_(rhs.wrap_before_),
|
||||
halign_(rhs.halign_),
|
||||
jalign_(rhs.jalign_),
|
||||
placement_options_(rhs.placement_options_) {}
|
||||
placement_options_(rhs.placement_options_) /*TODO: Copy options! */ {}
|
||||
|
||||
text_symbolizer& text_symbolizer::operator=(text_symbolizer const& other)
|
||||
{
|
||||
|
@ -211,7 +202,6 @@ text_symbolizer& text_symbolizer::operator=(text_symbolizer const& other)
|
|||
halo_fill_ = other.halo_fill_;
|
||||
halo_radius_ = other.halo_radius_;
|
||||
label_p_ = other.label_p_;
|
||||
valign_ = other.valign_;
|
||||
anchor_ = other.anchor_;
|
||||
avoid_edges_ = other.avoid_edges_;
|
||||
minimum_distance_ = other.minimum_distance_;
|
||||
|
@ -219,9 +209,7 @@ text_symbolizer& text_symbolizer::operator=(text_symbolizer const& other)
|
|||
overlap_ = other.overlap_;
|
||||
text_opacity_ = other.text_opacity_;
|
||||
wrap_before_ = other.wrap_before_;
|
||||
halign_ = other.halign_;
|
||||
jalign_ = other.jalign_;
|
||||
placement_options_ = other.placement_options_;
|
||||
placement_options_ = other.placement_options_; /*TODO?*/
|
||||
std::cout << "TODO: Metawriter (text_symbolizer::operator=)\n";
|
||||
return *this;
|
||||
}
|
||||
|
@ -436,16 +424,6 @@ label_placement_e text_symbolizer::get_label_placement() const
|
|||
return label_p_;
|
||||
}
|
||||
|
||||
void text_symbolizer::set_vertical_alignment(vertical_alignment_e valign)
|
||||
{
|
||||
valign_ = valign;
|
||||
}
|
||||
|
||||
vertical_alignment_e text_symbolizer::get_vertical_alignment() const
|
||||
{
|
||||
return valign_;
|
||||
}
|
||||
|
||||
void text_symbolizer::set_anchor(double x, double y)
|
||||
{
|
||||
anchor_ = boost::make_tuple(x,y);
|
||||
|
@ -516,24 +494,34 @@ double text_symbolizer::get_text_opacity() const
|
|||
return text_opacity_;
|
||||
}
|
||||
|
||||
void text_symbolizer::set_vertical_alignment(vertical_alignment_e valign)
|
||||
{
|
||||
placement_options_->set_default_valign(valign);
|
||||
}
|
||||
|
||||
vertical_alignment_e text_symbolizer::get_vertical_alignment() const
|
||||
{
|
||||
return placement_options_->get_default_valign();
|
||||
}
|
||||
|
||||
void text_symbolizer::set_horizontal_alignment(horizontal_alignment_e halign)
|
||||
{
|
||||
halign_ = halign;
|
||||
placement_options_->set_default_halign(halign);
|
||||
}
|
||||
|
||||
horizontal_alignment_e text_symbolizer::get_horizontal_alignment() const
|
||||
{
|
||||
return halign_;
|
||||
return placement_options_->get_default_halign();
|
||||
}
|
||||
|
||||
void text_symbolizer::set_justify_alignment(justify_alignment_e jalign)
|
||||
{
|
||||
jalign_ = jalign;
|
||||
placement_options_->set_default_jalign(jalign);
|
||||
}
|
||||
|
||||
justify_alignment_e text_symbolizer::get_justify_alignment() const
|
||||
{
|
||||
return jalign_;
|
||||
return placement_options_->get_default_jalign();
|
||||
}
|
||||
|
||||
text_placements_ptr text_symbolizer::get_placement_options() const
|
||||
|
|
Loading…
Reference in a new issue