00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __TEXT_PATH_H__
00027 #define __TEXT_PATH_H__
00028
00029 #include <boost/utility.hpp>
00030 #include <unicode/unistr.h>
00031
00032 namespace mapnik
00033 {
00034 struct character_info
00035 {
00036 int character;
00037 double width, height;
00038
00039 character_info() : character(0), width(0), height(0) {}
00040 character_info(int c_, double width_, double height_) : character(c_), width(width_), height(height_) {}
00041 ~character_info() {}
00042
00043 character_info(const character_info &ci)
00044 : character(ci.character), width(ci.width), height(ci.height)
00045 {
00046 }
00047
00048 };
00049
00050 class string_info : private boost::noncopyable
00051 {
00052 protected:
00053 typedef boost::ptr_vector<character_info> characters_t;
00054 characters_t characters_;
00055 UnicodeString const& text_;
00056 double width_;
00057 double height_;
00058 public:
00059 string_info(UnicodeString const& text)
00060 : text_(text),
00061 width_(0),
00062 height_(0) {}
00063
00064 void add_info(int c, double width, double height)
00065 {
00066 characters_.push_back(new character_info(c, width, height));
00067 }
00068
00069 unsigned num_characters() const
00070 {
00071 return characters_.size();
00072 }
00073
00074 character_info at(unsigned i) const
00075 {
00076 return characters_[i];
00077 }
00078
00079 character_info operator[](unsigned i) const
00080 {
00081 return at(i);
00082 }
00083
00084 void set_dimensions(double width, double height)
00085 {
00086 width_ = width;
00087 height_ = height;
00088 }
00089
00090 std::pair<double, double> get_dimensions() const
00091 {
00092 return std::pair<double, double>(width_, height_);
00093 }
00094
00095 UnicodeString const& get_string() const
00096 {
00097 return text_;
00098 }
00099 };
00100
00101 struct text_path : boost::noncopyable
00102 {
00103 struct character_node
00104 {
00105 int c;
00106 double x, y, angle;
00107
00108 character_node(int c_, double x_, double y_, double angle_)
00109 : c(c_), x(x_), y(y_), angle(angle_) {}
00110 ~character_node() {}
00111
00112 void vertex(int *c_, double *x_, double *y_, double *angle_)
00113 {
00114 *c_ = c;
00115 *x_ = x;
00116 *y_ = y;
00117 *angle_ = angle;
00118 }
00119 };
00120
00121 typedef std::vector<character_node> character_nodes_t;
00122 double starting_x;
00123 double starting_y;
00124 character_nodes_t nodes_;
00125 int itr_;
00126
00127 std::pair<unsigned,unsigned> string_dimensions;
00128
00129 text_path()
00130 : starting_x(0),
00131 starting_y(0),
00132 itr_(0) {}
00133
00134
00135
00136
00137
00138
00139
00140 ~text_path() {}
00141
00142 void add_node(int c, double x, double y, double angle)
00143 {
00144 nodes_.push_back(character_node(c, x, y, angle));
00145 }
00146
00147 void vertex(int *c, double *x, double *y, double *angle)
00148 {
00149 nodes_[itr_++].vertex(c, x, y, angle);
00150 }
00151
00152 void rewind()
00153 {
00154 itr_ = 0;
00155 }
00156
00157 int num_nodes() const
00158 {
00159 return nodes_.size();
00160 }
00161
00162 void clear()
00163 {
00164 nodes_.clear();
00165 }
00166 };
00167 }
00168
00169 #endif
00170
00171