diff --git a/bindings/python/mapnik_text_placement.cpp b/bindings/python/mapnik_text_placement.cpp index 331188668..75b2283e1 100644 --- a/bindings/python/mapnik_text_placement.cpp +++ b/bindings/python/mapnik_text_placement.cpp @@ -432,15 +432,6 @@ void export_text_placement() ; register_ptr_to_python >(); -#if 0 - class_, - boost::noncopyable> - ("ProcessedText", no_init) - .def("push_back", &processed_text::push_back) - .def("clear", &processed_text::clear) - ; -#endif class_, diff --git a/include/mapnik/font_engine_freetype.hpp b/include/mapnik/font_engine_freetype.hpp index fe8a34aec..5aac7fd17 100644 --- a/include/mapnik/font_engine_freetype.hpp +++ b/include/mapnik/font_engine_freetype.hpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -49,7 +48,6 @@ extern "C" #include #include #include -#include #ifdef MAPNIK_THREADSAFE #include #endif @@ -66,97 +64,6 @@ extern "C" namespace mapnik { -class font_face; -class text_path; -class string_info; - -class MAPNIK_DECL font_glyph -{ -public: - font_glyph() : face(), index(0) {} - - font_glyph(face_ptr face, unsigned index) - : face(face), index(index) {} - - face_ptr get_face() const - { - return face; - } - - unsigned get_index() const - { - return index; - } - face_ptr face; - unsigned index; -}; - -typedef boost::shared_ptr glyph_ptr; - -class MAPNIK_DECL font_face_set : private boost::noncopyable -{ -public: - typedef std::vector::iterator iterator; - font_face_set(void) - : faces_(), - dimension_cache_() {} - - void add(face_ptr face) - { - faces_.push_back(face); - dimension_cache_.clear(); //Make sure we don't use old cached data - } - - unsigned size() const - { - return faces_.size(); - } - - glyph_ptr get_glyph(unsigned c) const - { - BOOST_FOREACH ( face_ptr const& face, faces_) - { - FT_UInt g = face->get_char(c); - if (g) return boost::make_shared(face, g); - } - - // Final fallback to empty square if nothing better in any font - return boost::make_shared(*faces_.begin(), 0); - } - - iterator begin() - { - return faces_.begin(); - } - - iterator end() - { - return faces_.end(); - } - - char_info character_dimensions(const unsigned c); - - void get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format); - - void set_pixel_sizes(unsigned size) - { - BOOST_FOREACH ( face_ptr const& face, faces_) - { - face->set_pixel_sizes(size); - } - } - - void set_character_sizes(float size) - { - BOOST_FOREACH ( face_ptr const& face, faces_) - { - face->set_character_sizes(size); - } - } -private: - std::vector faces_; - std::map dimension_cache_; -}; // FT_Stroker wrapper class stroker : boost::noncopyable @@ -164,35 +71,17 @@ class stroker : boost::noncopyable public: explicit stroker(FT_Stroker s) : s_(s) {} + ~stroker(); - void init(double radius) - { - FT_Stroker_Set(s_, (FT_Fixed) (radius * (1<<6)), - FT_STROKER_LINECAP_ROUND, - FT_STROKER_LINEJOIN_ROUND, - 0); - } + void init(double radius); - FT_Stroker const& get() const - { - return s_; - } - - ~stroker() - { - MAPNIK_LOG_DEBUG(font_engine_freetype) << "stroker: Destroy stroker=" << s_; - - FT_Stroker_Done(s_); - } + FT_Stroker const& get() const { return s_; } private: FT_Stroker s_; }; - - - -typedef boost::shared_ptr face_set_ptr; typedef boost::shared_ptr stroker_ptr; + class MAPNIK_DECL freetype_engine { public: @@ -210,7 +99,7 @@ private: #ifdef MAPNIK_THREADSAFE static boost::mutex mutex_; #endif - static std::map > name2file_; + static std::map > name2file_; }; template @@ -316,50 +205,12 @@ struct text_renderer : private boost::noncopyable typedef T pixmap_type; text_renderer (pixmap_type & pixmap, face_manager &font_manager_, stroker & s, composite_mode_e comp_op = src_over); - box2d prepare_glyphs(text_path *path); void render(pixel_position pos); void render_id(int feature_id, pixel_position pos, double min_radius=1.0); private: - - void render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity) - { - int x_max=x+bitmap->width; - int y_max=y+bitmap->rows; - int i,p,j,q; - - for (i=x,p=0;ibuffer[q*bitmap->width+p]; - if (gray) - { - pixmap_.blendPixel2(i, j, rgba, gray, opacity); - } - } - } - } - - void render_bitmap_id(FT_Bitmap *bitmap,int feature_id,int x,int y) - { - int x_max=x+bitmap->width; - int y_max=y+bitmap->rows; - int i,p,j,q; - - for (i=x,p=0;ibuffer[q*bitmap->width+p]; - if (gray) - { - pixmap_.setPixel(i,j,feature_id); - //pixmap_.blendPixel2(i,j,rgba,gray,opacity_); - } - } - } - } + void render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity); + void render_bitmap_id(FT_Bitmap *bitmap,int feature_id,int x,int y); pixmap_type & pixmap_; face_manager &font_manager_; diff --git a/include/mapnik/text/face.hpp b/include/mapnik/text/face.hpp index 0e111cc58..f1629044a 100644 --- a/include/mapnik/text/face.hpp +++ b/include/mapnik/text/face.hpp @@ -24,6 +24,7 @@ //mapnik #include +#include // freetype2 extern "C" @@ -39,6 +40,7 @@ extern "C" //stl #include #include +#include namespace mapnik { @@ -92,6 +94,26 @@ private: std::map dimension_cache_; }; + + +class MAPNIK_DECL font_face_set : private boost::noncopyable +{ +public: + typedef std::vector::iterator iterator; + font_face_set(void) : faces_(){} + + void add(face_ptr face); + void set_character_sizes(float size); + + unsigned size() const { return faces_.size(); } + iterator begin() { return faces_.begin(); } + iterator end() { return faces_.end(); } +private: + std::vector faces_; +}; +typedef boost::shared_ptr face_set_ptr; + + } //ns mapnik #endif // FACE_HPP diff --git a/src/agg/process_shield_symbolizer.cpp b/src/agg/process_shield_symbolizer.cpp index d579ca471..e65b5a0ee 100644 --- a/src/agg/process_shield_symbolizer.cpp +++ b/src/agg/process_shield_symbolizer.cpp @@ -66,7 +66,6 @@ void agg_renderer::process(shield_symbolizer const& sym, sym.get_opacity(), sym.comp_op()); - ren.prepare_glyphs(&(placements[ii])); ren.render(placements[ii].center); } } diff --git a/src/agg/process_text_symbolizer.cpp b/src/agg/process_text_symbolizer.cpp index bb5e9d485..4e6bcee91 100644 --- a/src/agg/process_text_symbolizer.cpp +++ b/src/agg/process_text_symbolizer.cpp @@ -46,7 +46,6 @@ void agg_renderer::process(text_symbolizer const& sym, placements_type &placements = helper.placements(); for (unsigned int ii = 0; ii < placements.size(); ++ii) { - ren.prepare_glyphs(&(placements[ii])); ren.render(placements[ii].center); } } diff --git a/src/build.py b/src/build.py index fd3c70125..a349f3b46 100644 --- a/src/build.py +++ b/src/build.py @@ -166,7 +166,6 @@ source = Split( json/feature_collection_parser.cpp json/geojson_generator.cpp markers_placement.cpp - processed_text.cpp formatting/base.cpp formatting/expression.cpp formatting/list.cpp diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index ef6a209db..3d3e881b3 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -685,11 +685,11 @@ public: context_->glyph_path(glyphs); } - void add_text(text_path & path, cairo_face_manager & manager, face_manager &font_manager) { + #if 0 double sx = path.center.x; double sy = path.center.y; @@ -732,6 +732,9 @@ public: show_glyph(glyph->get_index(), sx + x, sy - y); } } +#else +#warning "Text rendering in Cairo disabled!" +#endif } diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index 4acaa6f26..01496ec80 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -220,54 +220,7 @@ stroker_ptr freetype_engine::create_stroker() return stroker_ptr(); } -char_info font_face_set::character_dimensions(const unsigned c) -{ - //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; - } - - FT_Matrix matrix; - FT_Vector pen; - FT_Error error; - - pen.x = 0; - pen.y = 0; - - FT_BBox glyph_bbox; - FT_Glyph image; - - glyph_ptr glyph = get_glyph(c); - FT_Face face = glyph->get_face()->get_face(); - - matrix.xx = (FT_Fixed)( 1 * 0x10000L ); - matrix.xy = (FT_Fixed)( 0 * 0x10000L ); - matrix.yx = (FT_Fixed)( 0 * 0x10000L ); - matrix.yy = (FT_Fixed)( 1 * 0x10000L ); - - FT_Set_Transform(face, &matrix, &pen); - - error = FT_Load_Glyph (face, glyph->get_index(), FT_LOAD_NO_HINTING); - if ( error ) - return char_info(); - - error = FT_Get_Glyph(face->glyph, &image); - if ( error ) - 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; - - 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; -} - - +#if 0 void font_face_set::get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format) { double avg_height = character_dimensions('X').height(); @@ -313,6 +266,7 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust ubidi_close(bidi); } +#endif template text_renderer::text_renderer (pixmap_type & pixmap, face_manager &font_manager_, stroker & s, composite_mode_e comp_op) @@ -321,6 +275,7 @@ text_renderer::text_renderer (pixmap_type & pixmap, face_manager box2d text_renderer::prepare_glyphs(text_path *path) { @@ -398,6 +353,7 @@ box2d text_renderer::prepare_glyphs(text_path *path) return box2d(bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax); } +#endif template void composite_bitmap(T & pixmap, FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity, composite_mode_e comp_op) @@ -520,16 +476,70 @@ void text_renderer::render_id(int feature_id, pixel_position pos, double min_ } } +template +void text_renderer::render_bitmap_id(FT_Bitmap *bitmap,int feature_id,int x,int y) +{ + int x_max=x+bitmap->width; + int y_max=y+bitmap->rows; + int i,p,j,q; + + for (i=x,p=0;ibuffer[q*bitmap->width+p]; + if (gray) + { + pixmap_.setPixel(i,j,feature_id); + //pixmap_.blendPixel2(i,j,rgba,gray,opacity_); + } + } + } +} + +template +void text_renderer::render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity) +{ + int x_max=x+bitmap->width; + int y_max=y+bitmap->rows; + int i,p,j,q; + + for (i=x,p=0;ibuffer[q*bitmap->width+p]; + if (gray) + { + pixmap_.blendPixel2(i, j, rgba, gray, opacity); + } + } + } +} + #ifdef MAPNIK_THREADSAFE boost::mutex freetype_engine::mutex_; #endif std::map > freetype_engine::name2file_; template void text_renderer::render(pixel_position); template text_renderer::text_renderer(image_32&, face_manager&, stroker&, composite_mode_e); -template box2dtext_renderer::prepare_glyphs(text_path*); template void text_renderer::render_id(int, pixel_position, double ); template text_renderer::text_renderer(grid&, face_manager&, stroker&, composite_mode_e); -template box2dtext_renderer::prepare_glyphs(text_path*); + +void stroker::init(double radius) +{ + FT_Stroker_Set(s_, (FT_Fixed) (radius * (1<<6)), + FT_STROKER_LINECAP_ROUND, + FT_STROKER_LINEJOIN_ROUND, + 0); +} + +stroker::~stroker() +{ + MAPNIK_LOG_DEBUG(font_engine_freetype) << "stroker: Destroy stroker=" << s_; + + FT_Stroker_Done(s_); +} } diff --git a/src/grid/process_shield_symbolizer.cpp b/src/grid/process_shield_symbolizer.cpp index 3a956892f..e91bb8939 100644 --- a/src/grid/process_shield_symbolizer.cpp +++ b/src/grid/process_shield_symbolizer.cpp @@ -64,7 +64,6 @@ void grid_renderer::process(shield_symbolizer const& sym, helper.get_marker(), helper.get_image_transform(), sym.get_opacity()); - ren.prepare_glyphs(&(placements[ii])); ren.render_id(feature.id(), placements[ii].center, 2); } } diff --git a/src/grid/process_text_symbolizer.cpp b/src/grid/process_text_symbolizer.cpp index 2986c4665..039b41a51 100644 --- a/src/grid/process_text_symbolizer.cpp +++ b/src/grid/process_text_symbolizer.cpp @@ -48,7 +48,6 @@ void grid_renderer::process(text_symbolizer const& sym, placements_type &placements = helper.placements(); for (unsigned int ii = 0; ii < placements.size(); ++ii) { - ren.prepare_glyphs(&(placements[ii])); ren.render_id(feature.id(), placements[ii].center, 2); } } diff --git a/src/processed_text.cpp b/src/processed_text.cpp index 921e528c6..0513f1c44 100644 --- a/src/processed_text.cpp +++ b/src/processed_text.cpp @@ -56,6 +56,7 @@ void processed_text::clear() string_info &processed_text::get_string_info() { +#if 0 info_.clear(); //if this function is called twice invalid results are returned, so clear string_info first expression_list::iterator itr = expr_list_.begin(); expression_list::iterator end = expr_list_.end(); @@ -79,6 +80,7 @@ string_info &processed_text::get_string_info() info_.add_text(itr->str); } return info_; +#endif } } //ns mapnik diff --git a/src/text/face.cpp b/src/text/face.cpp index fd323d04a..fe4694ef6 100644 --- a/src/text/face.cpp +++ b/src/text/face.cpp @@ -22,6 +22,8 @@ #include #include +#include + extern "C" { #include FT_GLYPH_H @@ -78,4 +80,19 @@ font_face::~font_face() FT_Done_Face(face_); } +/******************************************************************************/ + +void font_face_set::add(face_ptr face) +{ + faces_.push_back(face); +} + +void font_face_set::set_character_sizes(float size) +{ + BOOST_FOREACH ( face_ptr const& face, faces_) + { + face->set_character_sizes(size); + } +} + }//ns mapnik diff --git a/src/text/layout.cpp b/src/text/layout.cpp index a819449dd..ef834db8d 100644 --- a/src/text/layout.cpp +++ b/src/text/layout.cpp @@ -33,7 +33,6 @@ * string_info * text_path * char_info - * font_glyph */ namespace mapnik