From 6e4915ef8341a18077dc012d191a8aeac56a47a2 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Mon, 2 Jul 2012 01:06:30 +0200 Subject: [PATCH] Use shared pointers for text_layout. --- include/mapnik/symbolizer_helpers.hpp | 6 ++++-- include/mapnik/text/layout.hpp | 4 +++- src/symbolizer_helpers.cpp | 7 ++++--- src/text/layout.cpp | 4 +++- src/text/shaping.cpp | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/mapnik/symbolizer_helpers.hpp b/include/mapnik/symbolizer_helpers.hpp index a97038aed..70dd327e2 100644 --- a/include/mapnik/symbolizer_helpers.hpp +++ b/include/mapnik/symbolizer_helpers.hpp @@ -29,7 +29,6 @@ #include #include #include -#include #include //boost @@ -41,6 +40,9 @@ namespace mapnik { typedef boost::ptr_vector placements_type; template class placement_finder; +class text_layout; +typedef boost::shared_ptr text_layout_ptr; + /** Helper object that does all the TextSymbolizer placment finding * work except actually rendering the object. */ template @@ -83,7 +85,7 @@ protected: box2d dims_; box2d const& query_extent_; //Processing - text_layout layout_; + text_layout_ptr layout_; /* Using list instead of vector, because we delete random elements and need iterators to stay valid. */ /** Remaining geometries to be processed. */ std::list geometries_to_process_; diff --git a/include/mapnik/text/layout.hpp b/include/mapnik/text/layout.hpp index dde9b9580..5add20f6e 100644 --- a/include/mapnik/text/layout.hpp +++ b/include/mapnik/text/layout.hpp @@ -67,6 +67,8 @@ private: std::vector runs_; }; +typedef boost::shared_ptr text_line_ptr; + class text_layout { @@ -83,7 +85,7 @@ public: private: text_itemizer itemizer; - std::list lines_; + std::vector lines_; std::vector glyphs_; face_manager_freetype &font_manager_; }; diff --git a/src/symbolizer_helpers.cpp b/src/symbolizer_helpers.cpp index b04ea6aec..3d60df674 100644 --- a/src/symbolizer_helpers.cpp +++ b/src/symbolizer_helpers.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "agg_conv_clip_polyline.h" namespace mapnik { @@ -40,7 +41,7 @@ text_symbolizer_helper::text_symbolizer_helper(const te writer_(sym.get_metawriter()), dims_(0, 0, width, height), query_extent_(query_extent), - layout_(font_manager), + layout_(new text_layout(font_manager)), angle_(0.0), placement_valid_(false), points_on_line_(false), @@ -251,8 +252,8 @@ bool text_symbolizer_helper::next_placement() placement_valid_ = false; return false; } - placement_->properties.process(layout_, feature_); - layout_.shape_text(); + placement_->properties.process(*layout_, feature_); + layout_->shape_text(); //TODO // info_ = &(text_.get_string_info()); if (placement_->properties.orientation) diff --git a/src/text/layout.cpp b/src/text/layout.cpp index 1bd3011d5..30fa1e190 100644 --- a/src/text/layout.cpp +++ b/src/text/layout.cpp @@ -50,8 +50,10 @@ void text_layout::break_lines() void text_layout::shape_text() { UnicodeString const& text = itemizer.get_text(); - glyphs_.reserve(text.length()); //Preallocate memory uint32_t offset = 0; //in utf16 code points + + glyphs_.reserve(text.length()); //Preallocate memory + std::list const& list = itemizer.itemize(); std::list::const_iterator itr = list.begin(), end = list.end(); for (;itr!=end; itr++) diff --git a/src/text/shaping.cpp b/src/text/shaping.cpp index 5c673c261..7301f8cd2 100644 --- a/src/text/shaping.cpp +++ b/src/text/shaping.cpp @@ -58,6 +58,7 @@ uint32_t text_shaping::process_text(UnicodeString const& text, unsigned start, u hb_buffer_reset(buffer_); uint32_t length = text.length(); + std::cout << "process_text: length: " << length << " start: " << start << " end: " << end << "\n"; hb_buffer_add_utf16(buffer_, text.getBuffer(), length, start, end-start); hb_buffer_set_direction(buffer_, rtl?HB_DIRECTION_RTL:HB_DIRECTION_LTR);