From 31fd5647f258a0b2a137b0379f7decbb51eaf6c4 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Sun, 22 Jan 2012 20:51:09 +0100 Subject: [PATCH] Use font manager and char properties in text engine. --- include/mapnik/font_engine_freetype.hpp | 39 +------------------------ include/mapnik/text_path.hpp | 20 ------------- src/font_engine_freetype.cpp | 30 +++++-------------- 3 files changed, 8 insertions(+), 81 deletions(-) diff --git a/include/mapnik/font_engine_freetype.hpp b/include/mapnik/font_engine_freetype.hpp index 69307db81..5ded5076d 100644 --- a/include/mapnik/font_engine_freetype.hpp +++ b/include/mapnik/font_engine_freetype.hpp @@ -343,43 +343,11 @@ struct text_renderer : private boost::noncopyable typedef boost::ptr_vector glyphs_t; typedef T pixmap_type; - text_renderer (pixmap_type & pixmap, face_set_ptr faces, stroker & s); text_renderer (pixmap_type & pixmap, face_manager &font_manager_, stroker & s); box2d prepare_glyphs(text_path *path); void render(double x0, double y0); void render_id(int feature_id,double x0, double y0, double min_radius=1.0); - - void set_pixel_size(unsigned size) - { - faces_->set_pixel_sizes(size); - } - - void set_character_size(float size) - { - faces_->set_character_sizes(size); - } - - void set_fill(mapnik::color const& fill) - { - fill_=fill; - } - - void set_halo_fill(mapnik::color const& halo) - { - halo_fill_=halo; - } - - void set_halo_radius( double radius=1.0) - { - halo_radius_=radius; - } - - void set_opacity( double opacity=1.0) - { - opacity_=opacity; - } - private: void render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity) { @@ -421,14 +389,9 @@ private: } pixmap_type & pixmap_; - face_set_ptr faces_; -// face_manager &font_manager_; + face_manager &font_manager_; stroker & stroker_; - color fill_; - color halo_fill_; - double halo_radius_; glyphs_t glyphs_; - double opacity_; }; typedef face_manager face_manager_freetype; } diff --git a/include/mapnik/text_path.hpp b/include/mapnik/text_path.hpp index 31bf69374..a9e232ae2 100644 --- a/include/mapnik/text_path.hpp +++ b/include/mapnik/text_path.hpp @@ -45,15 +45,11 @@ protected: typedef std::vector characters_t; characters_t characters_; UnicodeString text_; - double width_; - double height_; bool is_rtl; public: string_info(UnicodeString const& text) : characters_(), text_(text), - width_(0), - height_(0), is_rtl(false) { @@ -76,11 +72,6 @@ public: { text_ += text; } - - void add_info(int c, double width, double height) - { - characters_.push_back(char_info(c, width, height, 0, height)); //WARNING: Do not use. Only to keep old code compilable. - } unsigned num_characters() const { @@ -106,17 +97,6 @@ public: { return at(i); } - - void set_dimensions(double width, double height) - { - width_ = width; - height_ = height; - } - - std::pair get_dimensions() const - { - return std::pair(width_, height_); - } UnicodeString const& get_string() const { diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index 192ab866e..8ee7ca6ea 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -241,11 +241,10 @@ char_info font_face_set::character_dimensions(const unsigned c) return dim; } + void font_face_set::get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format) { double avg_height = character_dimensions('X').height(); - unsigned width = 0; - unsigned height = 0; UErrorCode err = U_ZERO_ERROR; UnicodeString reordered; UnicodeString shaped; @@ -272,8 +271,6 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust for (iter.setToStart(); iter.hasNext();) { UChar ch = iter.nextPostInc(); char_info char_dim = character_dimensions(ch); - width += char_dim.width; - height = (char_dim.height() > height) ? char_dim.height() : height; char_dim.format = format; char_dim.avg_height = avg_height; info.add_info(char_dim); @@ -289,23 +286,8 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust #endif ubidi_close(bidi); - info.set_dimensions(width, height); } -template -text_renderer::text_renderer (pixmap_type & pixmap, face_set_ptr faces, stroker & s) - : pixmap_(pixmap), - faces_(faces), - stroker_(s), - fill_(0,0,0), - halo_fill_(255,255,255), - halo_radius_(0.0), - opacity_(1.0) -{ - -} - -#if 0 template text_renderer::text_renderer (pixmap_type & pixmap, face_manager &font_manager_, stroker & s) : pixmap_(pixmap), @@ -314,7 +296,6 @@ text_renderer::text_renderer (pixmap_type & pixmap, face_manager box2d text_renderer::prepare_glyphs(text_path *path) @@ -350,7 +331,10 @@ box2d text_renderer::prepare_glyphs(text_path *path) pen.x = int(x * 64); pen.y = int(y * 64); - glyph_ptr glyph = faces_->get_glyph(unsigned(c)); + face_set_ptr faces = font_manager_.get_face_set(properties->face_name, properties->fontset); + faces->set_pixel_sizes(properties->text_size); //TODO: Has to work with floats! + + glyph_ptr glyph = faces->get_glyph(unsigned(c)); FT_Face face = glyph->get_face()->get_face(); matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L ); @@ -490,10 +474,10 @@ boost::mutex freetype_engine::mutex_; #endif std::map > freetype_engine::name2file_; template void text_renderer::render(double, double); -template text_renderer::text_renderer(image_32&, face_set_ptr, stroker&); +template text_renderer::text_renderer(image_32&, face_manager&, stroker&); template box2dtext_renderer::prepare_glyphs(text_path*); template void text_renderer::render_id(int, double, double, double); -template text_renderer::text_renderer(grid&, face_set_ptr, stroker&); +template text_renderer::text_renderer(grid&, face_manager&, stroker&); template box2dtext_renderer::prepare_glyphs(text_path*); }