/home/andreas/src/svn/mapnik/include/mapnik/text_path.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * 
00003  * This file is part of Mapnik (c++ mapping toolkit)
00004  *
00005  * Copyright (C) 2006 Artem Pavlenko
00006  * Copyright (C) 2006 10East Corp.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  *****************************************************************************/
00023 
00024 //$Id$
00025 
00026 #ifndef __TEXT_PATH_H__
00027 #define __TEXT_PATH_H__
00028 
00029 #include <boost/utility.hpp>
00030 
00031 namespace mapnik
00032 {
00033     struct character_info
00034     { 
00035       int character;
00036       double width, height;
00037       
00038       character_info() : character(0), width(0), height(0) {}
00039       character_info(int c_, double width_, double height_) : character(c_), width(width_), height(height_) {}
00040       ~character_info() {}
00041         
00042       character_info(const character_info &ci)
00043         : character(ci.character), width(ci.width), height(ci.height)
00044       {
00045       }
00046           
00047     };
00048     
00049     class string_info : private boost::noncopyable
00050     {
00051     protected:
00052       
00053       
00054       typedef boost::ptr_vector<character_info> characters_t;
00055       
00056       characters_t characters_;
00057       unsigned itr_;
00058 
00059       double width_;
00060       double height_;
00061     public:
00062       string_info() : itr_(0), width_(0), 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()
00070       {
00071         return characters_.size();
00072       }
00073       
00074       character_info at(unsigned i)
00075       {
00076         return characters_[i];
00077       }
00078       
00079       character_info operator[](unsigned i)
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()
00091       {
00092         return std::pair<double, double>(width_, height_);
00093       }
00094     };
00095     
00096     struct text_path 
00097     {
00098         struct character_node
00099         {
00100             int c;
00101             double x, y, angle;
00102             
00103             character_node(int c_, double x_, double y_, double angle_) : c(c_), x(x_), y(y_), angle(angle_) {}
00104             ~character_node() {}
00105 
00106             void vertex(int *c_, double *x_, double *y_, double *angle_)
00107             {
00108                 *c_ = c;
00109                 *x_ = x;
00110                 *y_ = y;
00111                 *angle_ = angle;
00112             }
00113         };
00114 
00115         typedef std::vector<character_node> character_nodes_t;
00116         
00117         character_nodes_t nodes_;
00118         int itr_;
00119         
00120         std::pair<unsigned,unsigned> string_dimensions;
00121         
00122         text_path() :  itr_(0) {} 
00123         text_path(const text_path & other) : itr_(0)
00124         {
00125             nodes_ = other.nodes_;
00126             string_dimensions = other.string_dimensions;
00127         }
00128  
00129         ~text_path() {}
00130           
00131         void add_node(int c, double x, double y, double angle)
00132         {
00133             nodes_.push_back(character_node(c, x, y, angle));
00134         }
00135         
00136         void vertex(int *c, double *x, double *y, double *angle)
00137         {
00138             nodes_[itr_++].vertex(c, x, y, angle);
00139         }
00140         
00141         int num_nodes()
00142         {
00143             return nodes_.size();
00144         }
00145         
00146         void clear()
00147         {
00148           nodes_.clear();
00149         }
00150     };
00151 }
00152 
00153 #endif
00154 
00155 

Generated on Thu Jul 19 17:59:27 2007 for Mapnik by  doxygen 1.4.7