Changeset 702
- Timestamp:
- 06/29/08 06:56:29 (2 months ago)
- Location:
- trunk
- Files:
-
- 7 modified
-
include/mapnik/font_engine_freetype.hpp (modified) (12 diffs)
-
include/mapnik/image_view.hpp (modified) (2 diffs)
-
include/mapnik/map.hpp (modified) (4 diffs)
-
include/mapnik/octree.hpp (modified) (1 diff)
-
include/mapnik/png_io.hpp (modified) (1 diff)
-
include/mapnik/text_symbolizer.hpp (modified) (4 diffs)
-
src/SConscript (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/mapnik/font_engine_freetype.hpp
r701 r702 31 31 #include <mapnik/geometry.hpp> 32 32 #include <mapnik/text_path.hpp> 33 #include <mapnik/font_set.hpp>34 33 35 34 // freetype2 … … 63 62 { 64 63 public: 65 font_face(FT_Face face) 64 typedef std::pair<unsigned,unsigned> dimension_t; 65 66 font_face(FT_Face face) 66 67 : face_(face) {} 67 68 … … 104 105 } 105 106 106 ~font_face()107 {108 #ifdef MAPNIK_DEBUG109 std::clog << "~font_face: Clean up face \"" << family_name()110 << " " << style_name() << "\"" << std::endl;111 #endif112 FT_Done_Face(face_);113 }114 115 private:116 FT_Face face_;117 };118 119 typedef boost::shared_ptr<font_face> face_ptr;120 121 class MAPNIK_DECL freetype_engine // : public mapnik::singleton<freetype_engine,mapnik::CreateStatic>,122 // private boost::noncopyable123 {124 // friend class mapnik::CreateStatic<freetype_engine>;125 public:126 static bool register_font(std::string const& file_name);127 static std::vector<std::string> face_names ();128 face_ptr create_face(std::string const& family_name);129 virtual ~freetype_engine();130 freetype_engine();131 private:132 FT_Library library_;133 static boost::mutex mutex_;134 static std::map<std::string,std::string> name2file_;135 };136 137 template <typename T>138 class MAPNIK_DECL face_manager : private boost::noncopyable139 {140 typedef T font_engine_type;141 typedef std::map<std::string,face_ptr> faces;142 143 public:144 face_manager(T & engine)145 : engine_(engine) {}146 147 face_ptr get_face(std::string const& name)148 {149 typename faces::iterator itr;150 itr = faces_.find(name);151 if (itr != faces_.end())152 {153 return itr->second;154 }155 else156 {157 face_ptr face = engine_.create_face(name);158 if (face)159 {160 faces_.insert(make_pair(name,face));161 }162 return face;163 }164 }165 private:166 faces faces_;167 font_engine_type & engine_;168 };169 170 template <typename T>171 struct text_renderer : private boost::noncopyable172 {173 typedef std::pair<unsigned,unsigned> dimension_t;174 175 struct glyph_t : boost::noncopyable176 {177 FT_Glyph image;178 glyph_t(FT_Glyph image_) : image(image_) {}179 ~glyph_t () { FT_Done_Glyph(image);}180 };181 182 typedef boost::ptr_vector<glyph_t> glyphs_t;183 typedef T pixmap_type;184 185 text_renderer (pixmap_type & pixmap, std::vector<face_ptr> faces)186 : pixmap_(pixmap),187 faces_(faces),188 fill_(0,0,0),189 halo_fill_(255,255,255),190 halo_radius_(0) {}191 192 107 dimension_t character_dimensions(const unsigned c) 193 108 { … … 196 111 FT_Error error; 197 112 113 FT_GlyphSlot slot = face_->glyph; 114 198 115 pen.x = 0; 199 116 pen.y = 0; … … 201 118 FT_BBox glyph_bbox; 202 119 FT_Glyph image; 203 204 FT_Face face = (*faces_.begin())->get_face(); 205 206 FT_UInt glyph_index = FT_Get_Char_Index(face, c); 207 208 // If there's no glyph_index we loop through the remaining fonts 209 // in the fontset looking for one. 210 if (!glyph_index) { 211 std::vector<face_ptr>::iterator itr = faces_.begin(); 212 std::vector<face_ptr>::iterator end = faces_.end(); 213 214 ++itr; // Skip the first one, we already tried it. 215 216 for (; itr != end; ++itr) 217 { 218 FT_Face f = (*itr)->get_face(); 219 220 glyph_index = FT_Get_Char_Index(f, c); 221 222 if (glyph_index) { 223 face = f; 224 break; 225 } 226 } 227 } 228 120 229 121 matrix.xx = (FT_Fixed)( 1 * 0x10000L ); 230 122 matrix.xy = (FT_Fixed)( 0 * 0x10000L ); 231 123 matrix.yx = (FT_Fixed)( 0 * 0x10000L ); 232 124 matrix.yy = (FT_Fixed)( 1 * 0x10000L ); 233 234 FT_Set_Transform(face, &matrix, &pen); 235 236 error = FT_Load_Glyph (face, glyph_index, FT_LOAD_NO_HINTING); 125 126 FT_Set_Transform (face_,&matrix,&pen); 127 128 FT_UInt glyph_index = FT_Get_Char_Index( face_, c); 129 130 error = FT_Load_Glyph (face_,glyph_index,FT_LOAD_NO_HINTING); 237 131 if ( error ) 238 132 return dimension_t(0, 0); 239 133 240 error = FT_Get_Glyph( face->glyph, &image);134 error = FT_Get_Glyph( face_->glyph, &image); 241 135 if ( error ) 242 136 return dimension_t(0, 0); 243 244 FT_Glyph_Get_CBox(image, ft_glyph_bbox_pixels, &glyph_bbox); 245 FT_Done_Glyph(image); 246 247 unsigned tempx = face->glyph->advance.x >> 6; 248 unsigned tempy = glyph_bbox.yMax - glyph_bbox.yMin; 249 250 //std::clog << "glyph: " << glyph_index << " x: " << tempx << " y: " << tempy << std::endl; 251 252 return dimension_t(tempx, tempy); 137 138 FT_Glyph_Get_CBox(image,ft_glyph_bbox_pixels, &glyph_bbox); 139 FT_Done_Glyph(image); 140 return dimension_t(slot->advance.x >> 6, glyph_bbox.yMax - glyph_bbox.yMin); 253 141 } 254 142 … … 300 188 if ( *arabic.getBuffer() >= 0x0600 && *arabic.getBuffer() <= 0x06ff) 301 189 { 190 302 191 UnicodeString shaped; 303 192 u_shapeArabic(arabic.getBuffer(),arabic.length(),shaped.getBuffer(arabic.length()),arabic.length(), … … 327 216 info.set_dimensions(width, height); 328 217 } 329 218 219 ~font_face() 220 { 221 #ifdef MAPNIK_DEBUG 222 std::clog << "clean up face:" << family_name()<<":" << style_name() << std::endl; 223 #endif 224 FT_Done_Face(face_); 225 } 226 227 private: 228 FT_Face face_; 229 }; 230 231 typedef boost::shared_ptr<font_face> face_ptr; 232 class MAPNIK_DECL freetype_engine // : public mapnik::singleton<freetype_engine,mapnik::CreateStatic>, 233 // private boost::noncopyable 234 { 235 // friend class mapnik::CreateStatic<freetype_engine>; 236 public: 237 static bool register_font(std::string const& file_name); 238 static std::vector<std::string> face_names (); 239 face_ptr create_face(std::string const& family_name); 240 virtual ~freetype_engine(); 241 freetype_engine(); 242 private: 243 FT_Library library_; 244 static boost::mutex mutex_; 245 static std::map<std::string,std::string> name2file_; 246 }; 247 248 template <typename T> 249 class MAPNIK_DECL face_manager : private boost::noncopyable 250 { 251 typedef T font_engine_type; 252 typedef std::map<std::string,face_ptr> faces; 253 254 public: 255 face_manager(T & engine) 256 : engine_(engine) {} 257 258 face_ptr get_face(std::string const& name) 259 { 260 typename faces::iterator itr; 261 itr = faces_.find(name); 262 if (itr != faces_.end()) 263 { 264 return itr->second; 265 } 266 else 267 { 268 face_ptr face = engine_.create_face(name); 269 if (face) 270 { 271 faces_.insert(make_pair(name,face)); 272 } 273 return face; 274 } 275 } 276 private: 277 faces faces_; 278 font_engine_type & engine_; 279 }; 280 281 template <typename T> 282 struct text_renderer : private boost::noncopyable 283 { 284 struct glyph_t : boost::noncopyable 285 { 286 FT_Glyph image; 287 glyph_t(FT_Glyph image_) : image(image_) {} 288 ~glyph_t () { FT_Done_Glyph(image);} 289 }; 290 291 typedef boost::ptr_vector<glyph_t> glyphs_t; 292 typedef T pixmap_type; 293 294 text_renderer (pixmap_type & pixmap, face_ptr face) 295 : pixmap_(pixmap), 296 face_(face), 297 fill_(0,0,0), 298 halo_fill_(255,255,255), 299 halo_radius_(0) {} 300 330 301 void set_pixel_size(unsigned size) 331 302 { 332 std::vector<face_ptr>::iterator itr = faces_.begin(); 333 std::vector<face_ptr>::iterator end = faces_.end(); 334 for (; itr != end; ++itr) 335 { 336 (*itr)->set_pixel_sizes(size); 337 } 303 face_->set_pixel_sizes(size); 338 304 } 339 305 … … 361 327 FT_Vector pen; 362 328 FT_Error error; 363 329 330 FT_Face face = face_->get_face(); 331 // FT_GlyphSlot slot = face->glyph; 332 364 333 FT_BBox bbox; 365 bbox.xMin = bbox.yMin = 32000; // Initialize these so we can tell if we 366 bbox.xMax = bbox.yMax = -32000; // properly grew the bbox later 367 368 std::vector<face_ptr>::iterator end = faces_.end(); 369 334 bbox.xMin = bbox.yMin = 32000; 335 bbox.xMax = bbox.yMax = -32000; //hmm?? 336 370 337 for (int i = 0; i < path->num_nodes(); i++) 371 338 { 372 339 int c; 373 340 double x, y, angle; 374 341 375 342 path->vertex(&c, &x, &y, &angle); 376 377 #ifdef MAPNIK_DEBUG 378 // TODO Enable when we have support for setting verbosity 379 //std::clog << "prepare_glyphs: " << c << "," << x << 380 // "," << y << "," << angle << std::endl; 381 #endif 343 // std::clog << " prepare_glyph: " << (unsigned char)c << "," << x << "," << y << "," << angle << std::endl; 344 382 345 383 346 FT_BBox glyph_bbox; … … 387 350 pen.y = int(y * 64); 388 351 389 FT_Face face = (*faces_.begin())->get_face();390 391 FT_UInt glyph_index = FT_Get_Char_Index(face, unsigned(c));392 393 // If there's no glyph_index we loop through the remaining fonts394 // in the fontset looking for one.395 if (!glyph_index) {396 std::vector<face_ptr>::iterator itr = faces_.begin();397 ++itr; // Skip the first one, we already tried it.398 399 for (; itr != end; ++itr)400 {401 #ifdef MAPNIK_DEBUG402 // TODO Enable when we have support for setting verbosity403 //std::clog << "prepare_glyphs: Falling back to font named \""404 // << (*itr)->family_name() << " " << (*itr)->style_name()405 // << "\"" << std::endl;406 #endif407 408 FT_Face f = (*itr)->get_face();409 410 glyph_index = FT_Get_Char_Index(f, unsigned(c));411 412 if (glyph_index) {413 face = f;414 break;415 }416 }417 418 #ifdef MAPNIK_DEBUG419 // TODO Enable when we have support for setting verbosity420 //if (!glyph_index) {421 // std::clog << "prepare_glyphs: Failed to fall back, glyph "422 // << c << " not found in any font." << std::endl;423 //}424 #endif425 }426 427 352 matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L ); 428 353 matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L ); 429 354 matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L ); 430 355 matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L ); 431 432 FT_Set_Transform(face, &matrix, &pen); 433 434 error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_HINTING); 356 357 FT_Set_Transform (face,&matrix,&pen); 358 359 FT_UInt glyph_index = FT_Get_Char_Index( face, unsigned(c)); 360 361 error = FT_Load_Glyph (face,glyph_index, FT_LOAD_NO_HINTING); 435 362 if ( error ) 436 363 continue; 437 438 error = FT_Get_Glyph( face->glyph, &image);364 365 error = FT_Get_Glyph( face->glyph, &image); 439 366 if ( error ) 440 367 continue; 441 368 442 369 FT_Glyph_Get_CBox(image,ft_glyph_bbox_pixels, &glyph_bbox); 443 370 if (glyph_bbox.xMin < bbox.xMin) … … 449 376 if (glyph_bbox.yMax > bbox.yMax) 450 377 bbox.yMax = glyph_bbox.yMax; 451 452 // Check if we properly grew the bbox 378 453 379 if ( bbox.xMin > bbox.xMax ) 454 380 { … … 559 485 560 486 pixmap_type & pixmap_; 561 std::vector<face_ptr> faces_;487 face_ptr face_; 562 488 mapnik::Color fill_; 563 489 mapnik::Color halo_fill_; … … 569 495 } 570 496 497 571 498 #endif // FONT_ENGINE_FREETYPE_HPP -
trunk/include/mapnik/image_view.hpp
r701 r702 81 81 return width_; 82 82 } 83 84 83 inline unsigned height() const 85 84 { … … 91 90 return data_.getRow(row + y_) + x_; 92 91 } 93 94 92 inline T& data() 95 93 { 96 94 return data_; 97 95 } 98 99 96 inline T const& data() const 100 97 { 101 98 return data_; 102 99 } 103 100 104 101 private: 105 102 unsigned x_; -
trunk/include/mapnik/map.hpp
r701 r702 38 38 class MAPNIK_DECL Map 39 39 { 40 public:41 42 enum aspect_fix_mode43 {44 /* grow the width or height of the specified geo bbox to fill the map size. default behaviour. */45 GROW_BBOX,46 /* grow the width or height of the map to accomodate the specified geo bbox. */47 GROW_CANVAS,48 /* shrink the width or height of the specified geo bbox to fill the map size. */49 SHRINK_BBOX,50 /* shrink the width or height of the map to accomodate the specified geo bbox. */51 SHRINK_CANVAS,52 /* adjust the width of the specified geo bbox, leave height and map size unchanged */53 ADJUST_BBOX_WIDTH,54 /* adjust the height of the specified geo bbox, leave width and map size unchanged */55 ADJUST_BBOX_HEIGHT,56 /* adjust the width of the map, leave height and geo bbox unchanged */57 ADJUST_CANVAS_WIDTH,58 /* adjust the height of the map, leave width and geo bbox unchanged */59 ADJUST_CANVAS_HEIGHT60 };61 private:62 40 static const unsigned MIN_MAPSIZE=16; 63 41 static const unsigned MAX_MAPSIZE=MIN_MAPSIZE<<10; … … 67 45 boost::optional<Color> background_; 68 46 std::map<std::string,feature_type_style> styles_; 69 std::map<std::string,FontSet> fontsets_;70 47 std::vector<Layer> layers_; 71 48 Envelope<double> currentExtent_; 72 aspect_fix_mode aspectFixMode_;73 49 74 50 public: 75 76 51 typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator; 77 52 typedef std::map<std::string,feature_type_style>::iterator style_iterator; … … 155 130 feature_type_style const& find_style(std::string const& name) const; 156 131 157 /*! \brief Insert a fontset into the map.158 * @param name The name of the fontset.159 * @param style The fontset to insert.160 * @return true If success.161 * @return false If failure.162 */163 bool insert_fontset(std::string const& name, FontSet const& fontset);164 165 /*! \brief Find a fontset.166 * @param name The name of the fontset.167 * @return The fontset if found. If not found return the default map fontset.168 */169 FontSet const& find_fontset(std::string const& name) const;170 171 132 /*! \brief Get number of all layers. 172 133 */ … … 283 244 featureset_ptr query_map_point(unsigned index, double x, double y) const; 284 245 ~Map(); 285 286 void setAspectFixMode(aspect_fix_mode afm) { aspectFixMode_ = afm; }287 bool getAspectFixMode() { return aspectFixMode_; }288 289 246 private: 290 247 void fixAspectRatio(); -
trunk/include/mapnik/octree.hpp
r701 r702 25 25 #define _OCTREE_HPP_ 26 26 27 #include <mapnik/global.hpp>28 27 #include <boost/format.hpp> 29 28 #include <boost/utility.hpp> -
trunk/include/mapnik/png_io.hpp
r701 r702 81 81 PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT); 82 82 png_write_info(png_ptr, info_ptr); 83 84 83 for (unsigned i=0;i<image.height();i++) 85 84 { 86 png_write_row(png_ptr,(png_bytep)image.getRow(i));87 } 88 85 png_write_row(png_ptr,(png_bytep)image.getRow(i)); 86 } 87 89 88 png_write_end(png_ptr, info_ptr); 90 89 png_destroy_write_struct(&png_ptr, &info_ptr); -
trunk/include/mapnik/text_symbolizer.hpp
r701 r702 28 28 #include <mapnik/enumeration.hpp> 29 29 #include <mapnik/color.hpp> 30 #include <mapnik/font_set.hpp> 31 #include <mapnik/graphics.hpp> 30 #include <mapnik/graphics.hpp> 32 31 // boost 33 32 #include <boost/tuple/tuple.hpp> … … 51 50 text_symbolizer(std::string const& name,std::string const& face_name, 52 51 unsigned size, Color const& fill); 53 text_symbolizer(std::string const& name, unsigned size, Color const& fill);54 52 text_symbolizer(text_symbolizer const& rhs); 55 53 text_symbolizer& operator=(text_symbolizer const& rhs); … … 69 67 unsigned get_text_size() const; 70 68 std::string const& get_face_name() const; 71 void set_face_name(std::string face_name);72 FontSet const& get_fontset() const;73 void set_fontset(FontSet fontset);74 69 Color const& get_fill() const; 75 70 void set_halo_fill(Color const& fill); … … 92 87 std::string name_; 93 88 std::string face_name_; 94 FontSet fontset_;95 89 unsigned size_; 96 90 unsigned text_ratio_; -
trunk/src/SConscript
r701 r702 48 48 filter_factory.cpp 49 49 font_engine_freetype.cpp 50 font_set.cpp51 50 graphics.cpp 52 51 image_reader.cpp
