From 34405a5d9e959e8a2cb4d5fb394e7c2ebef47352 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Sat, 21 Jan 2012 00:35:24 +0100 Subject: [PATCH] Replace dimension_t by char_info. --- include/mapnik/font_engine_freetype.hpp | 11 ++--------- include/mapnik/text_path.hpp | 4 ++++ src/font_engine_freetype.cpp | 23 ++++++++++------------- src/metawriter.cpp | 16 ++++++++-------- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/include/mapnik/font_engine_freetype.hpp b/include/mapnik/font_engine_freetype.hpp index e72dc4538..560e0d404 100644 --- a/include/mapnik/font_engine_freetype.hpp +++ b/include/mapnik/font_engine_freetype.hpp @@ -145,13 +145,6 @@ private: class MAPNIK_DECL font_face_set : private boost::noncopyable { public: - class dimension_t { - public: - dimension_t(unsigned width_, int ymax_, int ymin_) : width(width_), height(ymax_-ymin_), ymin(ymin_) {} - unsigned width, height; - int ymin; - }; - font_face_set(void) : faces_() {} @@ -179,7 +172,7 @@ public: return boost::make_shared(*faces_.begin(), 0); } - dimension_t character_dimensions(const unsigned c); + char_info character_dimensions(const unsigned c); void get_string_info(string_info & info); @@ -200,7 +193,7 @@ public: } private: std::vector faces_; - std::map dimension_cache_; + std::map dimension_cache_; }; // FT_Stroker wrapper diff --git a/include/mapnik/text_path.hpp b/include/mapnik/text_path.hpp index eeebd97c4..0f2628859 100644 --- a/include/mapnik/text_path.hpp +++ b/include/mapnik/text_path.hpp @@ -23,9 +23,13 @@ #ifndef MAPNIK_TEXT_PATH_HPP #define MAPNIK_TEXT_PATH_HPP +// mapnik +#include + // boost #include #include +#include // uci #include diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index 188aaa59d..7b8a76fd9 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -19,7 +19,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ -//$Id$ // mapnik #include @@ -192,9 +191,10 @@ stroker_ptr freetype_engine::create_stroker() return stroker_ptr(); } -font_face_set::dimension_t font_face_set::character_dimensions(const unsigned c) +char_info font_face_set::character_dimensions(const unsigned c) { - std::map::const_iterator itr; + //Check if char is already in cache + std::map::const_iterator itr; itr = dimension_cache_.find(c); if (itr != dimension_cache_.end()) { return itr->second; @@ -222,21 +222,18 @@ font_face_set::dimension_t font_face_set::character_dimensions(const unsigned c) error = FT_Load_Glyph (face, glyph->get_index(), FT_LOAD_NO_HINTING); if ( error ) - return dimension_t(0, 0, 0); + return char_info(); error = FT_Get_Glyph(face->glyph, &image); if ( error ) - return dimension_t(0, 0, 0); + return char_info(); FT_Glyph_Get_CBox(image, ft_glyph_bbox_pixels, &glyph_bbox); FT_Done_Glyph(image); unsigned tempx = face->glyph->advance.x >> 6; - - //std::clog << "glyph: " << glyph_index << " x: " << tempx << " y: " << tempy << std::endl; - dimension_t dim(tempx, glyph_bbox.yMax, glyph_bbox.yMin); - //dimension_cache_[c] = dim; would need an default constructor for dimension_t - dimension_cache_.insert(std::pair(c, dim)); + char_info dim(c, tempx, glyph_bbox.yMax, glyph_bbox.yMin, face->size->metrics.height/64.0 /* >> 6 */); + dimension_cache_.insert(std::pair(c, dim)); return dim; } @@ -270,10 +267,10 @@ void font_face_set::get_string_info(string_info & info) StringCharacterIterator iter(shaped); for (iter.setToStart(); iter.hasNext();) { UChar ch = iter.nextPostInc(); - dimension_t char_dim = character_dimensions(ch); - info.add_info(ch, char_dim.width, char_dim.height); + char_info char_dim = character_dimensions(ch); + info.add_info(ch, char_dim.width, char_dim.height()); width += char_dim.width; - height = (char_dim.height > height) ? char_dim.height : height; + height = (char_dim.height() > height) ? char_dim.height() : height; } } diff --git a/src/metawriter.cpp b/src/metawriter.cpp index 51a56b247..8d1fe5713 100644 --- a/src/metawriter.cpp +++ b/src/metawriter.cpp @@ -218,12 +218,12 @@ void metawriter_json_stream::add_text(placement const& p, double minx = INT_MAX, miny = INT_MAX, maxx = INT_MIN, maxy = INT_MIN; for (int i = 0; i < current_placement.num_nodes(); ++i) { current_placement.vertex(&c, &x, &y, &angle); - font_face_set::dimension_t ci = face->character_dimensions(c); + char_info ci = face->character_dimensions(c); if (x < minx) minx = x; if (x+ci.width > maxx) maxx = x+ci.width; - if (y+ci.height+ci.ymin > maxy) maxy = y+ci.height+ci.ymin; + if (y+ci.height()+ci.ymin > maxy) maxy = y+ci.height()+ci.ymin; if (y+ci.ymin < miny) miny = y+ci.ymin; - // std::cout << (char) c << " height:" << ci.height << " ymin:" << ci.ymin << " y:" << y << " miny:"<< miny << " maxy:"<< maxy <<"\n"; + // std::cout << (char) c << " height:" << ci.height() << " ymin:" << ci.ymin << " y:" << y << " miny:"<< miny << " maxy:"<< maxy <<"\n"; } add_box(box2d(current_placement.starting_x+minx, @@ -242,7 +242,7 @@ void metawriter_json_stream::add_text(placement const& p, } current_placement.vertex(&c, &x, &y, &angle); if (c == ' ') continue; - font_face_set::dimension_t ci = face->character_dimensions(c); + char_info ci = face->character_dimensions(c); double x0, y0, x1, y1, x2, y2, x3, y3; double sina = sin(angle); @@ -251,10 +251,10 @@ void metawriter_json_stream::add_text(placement const& p, y0 = current_placement.starting_y - y - cosa*ci.ymin; x1 = x0 + ci.width * cosa; y1 = y0 - ci.width * sina; - x2 = x0 + (ci.width * cosa - ci.height * sina); - y2 = y0 - (ci.width * sina + ci.height * cosa); - x3 = x0 - ci.height * sina; - y3 = y0 - ci.height * cosa; + x2 = x0 + (ci.width * cosa - ci.height() * sina); + y2 = y0 - (ci.width * sina + ci.height() * cosa); + x3 = x0 - ci.height() * sina; + y3 = y0 - ci.height() * cosa; *f_ << "\n [["; write_point(t, x0, y0);