Skip to content

Commit

Permalink
Remove class text_processor.
Browse files Browse the repository at this point in the history
  • Loading branch information
herm committed Jan 31, 2012
1 parent e4340c0 commit 1a16e9c
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 217 deletions.
106 changes: 64 additions & 42 deletions include/mapnik/text_placements.hpp
Expand Up @@ -49,57 +49,50 @@ class text_placements;
typedef std::pair<double,double> position; typedef std::pair<double,double> position;
typedef std::pair<double,double> dimension_type; typedef std::pair<double,double> dimension_type;


enum label_placement_enum { struct char_properties
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, char_properties();
J_MIDDLE, /** Construct object from XML. */
J_RIGHT, void from_xml(boost::property_tree::ptree const &sym, std::map<std::string,font_set> const & fontsets);
justify_alignment_MAX /** Write object to XML ptree. */
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, char_properties const &dfl=char_properties()) const;
std::string face_name;
font_set fontset;
float text_size;
double character_spacing;
double line_spacing; //Largest total height (fontsize+line_spacing) per line is chosen
double text_opacity;
bool wrap_before;
unsigned wrap_char;
text_transform_e text_transform; //Per expression
color fill;
color halo_fill;
double halo_radius;
}; };


DEFINE_ENUM( justify_alignment_e, justify_alignment );

/** Contains all text symbolizer properties which are not directly related to text formating. */ /** Contains all text symbolizer properties which are not directly related to text formating. */
struct text_symbolizer_properties struct text_symbolizer_properties
{ {
text_symbolizer_properties(); text_symbolizer_properties();
/** Load all values and also the ```processor``` object from XML ptree. */ /** Load all values from XML ptree. */
void from_xml(boost::property_tree::ptree const &sym, std::map<std::string,font_set> const & fontsets); void from_xml(boost::property_tree::ptree const &sym, std::map<std::string,font_set> const & fontsets);
/** Save all values to XML ptree (but does not create a new parent node!). */ /** Save all values to XML ptree (but does not create a new parent node!). */
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, text_symbolizer_properties const &dfl=text_symbolizer_properties()) const; void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, text_symbolizer_properties const &dfl=text_symbolizer_properties()) const;


/** Takes a feature and produces formated text as output.
* The output object has to be created by the caller and passed in for thread safety.
*/
void process(processed_text &output, Feature const& feature) const;
/** Automatically create processing instructions for a single expression. */
void set_old_style_expression(expression_ptr expr);
/** Sets new format tree. */
void set_format_tree(formating::node_ptr tree);
/** Get format tree. */
formating::node_ptr format_tree() const;
/** Get a list of all expressions used in any placement.
* This function is used to collect attributes. */
std::set<expression_ptr> get_all_expressions() const;

//Per symbolizer options //Per symbolizer options
expression_ptr orientation; expression_ptr orientation;
position displacement; position displacement;
Expand All @@ -121,10 +114,39 @@ struct text_symbolizer_properties
bool allow_overlap; bool allow_overlap;
unsigned text_ratio; unsigned text_ratio;
unsigned wrap_width; unsigned wrap_width;
/** Contains everything related to text formating */ /** Default values for char_properties. */
text_processor processor; char_properties default_format;
private:
formating::node_ptr tree_;
}; };


class processed_text : boost::noncopyable
{
public:
class processed_expression
{
public:
processed_expression(char_properties const& properties, UnicodeString const& text) :
p(properties), str(text) {}
char_properties p;
UnicodeString str;
};
public:
processed_text(face_manager<freetype_engine> & font_manager, double scale_factor);
void push_back(processed_expression const& exp);
unsigned size() const { return expr_list_.size(); }
unsigned empty() const { return expr_list_.empty(); }
void clear();
typedef std::list<processed_expression> expression_list;
expression_list::const_iterator begin() const;
expression_list::const_iterator end() const;
string_info &get_string_info();
private:
expression_list expr_list_;
face_manager<freetype_engine> & font_manager_;
double scale_factor_;
string_info info_;
};


/** Generate a possible placement and store results of placement_finder. /** Generate a possible placement and store results of placement_finder.
* This placement has first to be tested by placement_finder to verify it * This placement has first to be tested by placement_finder to verify it
Expand Down
118 changes: 42 additions & 76 deletions include/mapnik/text_processing.hpp
Expand Up @@ -23,6 +23,8 @@
#define MAPNIK_TEXT_PROCESSING_HPP #define MAPNIK_TEXT_PROCESSING_HPP


#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/optional.hpp>

#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/ctrans.hpp> #include <mapnik/ctrans.hpp>
Expand All @@ -37,68 +39,60 @@
#include <set> #include <set>
namespace mapnik namespace mapnik
{ {
class processed_text;
struct char_properties;

enum label_placement_enum {
POINT_PLACEMENT,
LINE_PLACEMENT,
VERTEX_PLACEMENT,
INTERIOR_PLACEMENT,
label_placement_enum_MAX
};


enum text_transform DEFINE_ENUM( label_placement_e, label_placement_enum );

enum vertical_alignment
{ {
NONE = 0, V_TOP = 0,
UPPERCASE, V_MIDDLE,
LOWERCASE, V_BOTTOM,
CAPITALIZE, V_AUTO,
text_transform_MAX vertical_alignment_MAX
}; };
DEFINE_ENUM( text_transform_e, text_transform );


DEFINE_ENUM( vertical_alignment_e, vertical_alignment );


struct char_properties enum horizontal_alignment
{ {
char_properties(); H_LEFT = 0,
/** Construct object from XML. */ H_MIDDLE,
void from_xml(boost::property_tree::ptree const &sym, std::map<std::string,font_set> const & fontsets); H_RIGHT,
/** Write object to XML ptree. */ H_AUTO,
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, char_properties const &dfl=char_properties()) const; horizontal_alignment_MAX
std::string face_name;
font_set fontset;
float text_size;
double character_spacing;
double line_spacing; //Largest total height (fontsize+line_spacing) per line is chosen
double text_opacity;
bool wrap_before;
unsigned wrap_char;
text_transform_e text_transform; //Per expression
color fill;
color halo_fill;
double halo_radius;
}; };


class processed_expression DEFINE_ENUM( horizontal_alignment_e, horizontal_alignment );

enum justify_alignment
{ {
public: J_LEFT = 0,
processed_expression(char_properties const& properties, UnicodeString const& text) : J_MIDDLE,
p(properties), str(text) {} J_RIGHT,
char_properties p; justify_alignment_MAX
UnicodeString str;
}; };


DEFINE_ENUM( justify_alignment_e, justify_alignment );


class processed_text : boost::noncopyable enum text_transform
{ {
public: NONE = 0,
processed_text(face_manager<freetype_engine> & font_manager, double scale_factor); UPPERCASE,
void push_back(processed_expression const& exp); LOWERCASE,
unsigned size() const { return expr_list_.size(); } CAPITALIZE,
unsigned empty() const { return expr_list_.empty(); } text_transform_MAX
void clear();
typedef std::list<processed_expression> expression_list;
expression_list::const_iterator begin() const;
expression_list::const_iterator end() const;
string_info &get_string_info();
private:
expression_list expr_list_;
face_manager<freetype_engine> & font_manager_;
double scale_factor_;
string_info info_;
}; };

DEFINE_ENUM( text_transform_e, text_transform );


namespace formating { namespace formating {
class node; class node;
Expand Down Expand Up @@ -180,34 +174,6 @@ class format_node: public node {


} //namespace formating } //namespace formating


/** Stores formating information and uses this to produce formated text for a given feature. */
class text_processor
{
public:
text_processor();
/** Construct object from XML. */
void from_xml(boost::property_tree::ptree const& pt, std::map<std::string,font_set> const &fontsets);
/** Write object to XML ptree. */
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, text_processor const& dfl) const;

/** Takes a feature and produces formated text as output.
* The output object has to be created by the caller and passed in for thread safety.
*/
void process(processed_text &output, Feature const& feature) const;
/** Automatically create processing instructions for a single expression. */
void set_old_style_expression(expression_ptr expr);
/** Sets new format tree. */
void set_format_tree(formating::node_ptr tree);
/** Get format tree. */
formating::node_ptr get_format_tree() const;
/** Get a list of all expressions used in any placement. This function is used to collect attributes. */
std::set<expression_ptr> get_all_expressions() const;
/** Default values for char_properties. */
char_properties defaults;
private:
formating::node_ptr tree_;
};

} /* namespace mapnik*/ } /* namespace mapnik*/


#endif #endif
8 changes: 4 additions & 4 deletions src/load_map.cpp
Expand Up @@ -1282,7 +1282,7 @@ void map_parser::parse_text_symbolizer( rule & rule, ptree const & sym )
} }


placement_finder->properties.from_xml(sym, fontsets_); placement_finder->properties.from_xml(sym, fontsets_);
if (strict_) ensure_font_face(placement_finder->properties.processor.defaults.face_name); if (strict_) ensure_font_face(placement_finder->properties.default_format.face_name);
if (list) { if (list) {
ptree::const_iterator symIter = sym.begin(); ptree::const_iterator symIter = sym.begin();
ptree::const_iterator endSym = sym.end(); ptree::const_iterator endSym = sym.end();
Expand All @@ -1296,7 +1296,7 @@ void map_parser::parse_text_symbolizer( rule & rule, ptree const & sym )
ensure_attrs(symIter->second, "TextSymbolizer/Placement", s_common.str()); ensure_attrs(symIter->second, "TextSymbolizer/Placement", s_common.str());
text_symbolizer_properties & p = list->add(); text_symbolizer_properties & p = list->add();
p.from_xml(symIter->second, fontsets_); p.from_xml(symIter->second, fontsets_);
if (strict_) ensure_font_face(p.processor.defaults.face_name); if (strict_) ensure_font_face(p.default_format.face_name);
} }
} }


Expand Down Expand Up @@ -1351,7 +1351,7 @@ void map_parser::parse_shield_symbolizer( rule & rule, ptree const & sym )
} }


placement_finder->properties.from_xml(sym, fontsets_); placement_finder->properties.from_xml(sym, fontsets_);
if (strict_) ensure_font_face(placement_finder->properties.processor.defaults.face_name); if (strict_) ensure_font_face(placement_finder->properties.default_format.face_name);
if (list) { if (list) {
ptree::const_iterator symIter = sym.begin(); ptree::const_iterator symIter = sym.begin();
ptree::const_iterator endSym = sym.end(); ptree::const_iterator endSym = sym.end();
Expand All @@ -1365,7 +1365,7 @@ void map_parser::parse_shield_symbolizer( rule & rule, ptree const & sym )
ensure_attrs(symIter->second, "TextSymbolizer/Placement", s_common); ensure_attrs(symIter->second, "TextSymbolizer/Placement", s_common);
text_symbolizer_properties & p = list->add(); text_symbolizer_properties & p = list->add();
p.from_xml(symIter->second, fontsets_); p.from_xml(symIter->second, fontsets_);
if (strict_) ensure_font_face(p.processor.defaults.face_name); if (strict_) ensure_font_face(p.default_format.face_name);
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion src/symbolizer_helpers.cpp
Expand Up @@ -166,7 +166,7 @@ bool text_symbolizer_helper<FaceManagerT, DetectorT>::next_placement()
placement_valid_ = false; placement_valid_ = false;
return false; return false;
} }
placement_->properties.processor.process(text_, feature_); placement_->properties.process(text_, feature_);
info_ = &(text_.get_string_info()); info_ = &(text_.get_string_info());
if (placement_->properties.orientation) if (placement_->properties.orientation)
{ {
Expand Down

0 comments on commit 1a16e9c

Please sign in to comment.