Use shared pointers for text_layout.

This commit is contained in:
Hermann Kraus 2012-07-02 01:06:30 +02:00
parent aecd6820c2
commit 6e4915ef83
5 changed files with 15 additions and 7 deletions

View file

@ -29,7 +29,6 @@
#include <mapnik/feature.hpp> #include <mapnik/feature.hpp>
#include <mapnik/marker.hpp> #include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp> #include <mapnik/marker_cache.hpp>
#include <mapnik/text/layout.hpp>
#include <mapnik/text_path.hpp> #include <mapnik/text_path.hpp>
//boost //boost
@ -41,6 +40,9 @@ namespace mapnik {
typedef boost::ptr_vector<text_path> placements_type; typedef boost::ptr_vector<text_path> placements_type;
template <typename DetectorT> class placement_finder; template <typename DetectorT> class placement_finder;
class text_layout;
typedef boost::shared_ptr<text_layout> text_layout_ptr;
/** Helper object that does all the TextSymbolizer placment finding /** Helper object that does all the TextSymbolizer placment finding
* work except actually rendering the object. */ * work except actually rendering the object. */
template <typename FaceManagerT, typename DetectorT> template <typename FaceManagerT, typename DetectorT>
@ -83,7 +85,7 @@ protected:
box2d<double> dims_; box2d<double> dims_;
box2d<double> const& query_extent_; box2d<double> const& query_extent_;
//Processing //Processing
text_layout layout_; text_layout_ptr layout_;
/* Using list instead of vector, because we delete random elements and need iterators to stay valid. */ /* Using list instead of vector, because we delete random elements and need iterators to stay valid. */
/** Remaining geometries to be processed. */ /** Remaining geometries to be processed. */
std::list<geometry_type*> geometries_to_process_; std::list<geometry_type*> geometries_to_process_;

View file

@ -67,6 +67,8 @@ private:
std::vector<format_run_ptr> runs_; std::vector<format_run_ptr> runs_;
}; };
typedef boost::shared_ptr<text_line> text_line_ptr;
class text_layout class text_layout
{ {
@ -83,7 +85,7 @@ public:
private: private:
text_itemizer itemizer; text_itemizer itemizer;
std::list<text_line> lines_; std::vector<text_line_ptr> lines_;
std::vector<glyph_info> glyphs_; std::vector<glyph_info> glyphs_;
face_manager_freetype &font_manager_; face_manager_freetype &font_manager_;
}; };

View file

@ -25,6 +25,7 @@
#include <mapnik/label_collision_detector.hpp> #include <mapnik/label_collision_detector.hpp>
#include <mapnik/placement_finder.hpp> #include <mapnik/placement_finder.hpp>
#include <mapnik/font_engine_freetype.hpp> #include <mapnik/font_engine_freetype.hpp>
#include <mapnik/text/layout.hpp>
#include "agg_conv_clip_polyline.h" #include "agg_conv_clip_polyline.h"
namespace mapnik { namespace mapnik {
@ -40,7 +41,7 @@ text_symbolizer_helper<FaceManagerT, DetectorT>::text_symbolizer_helper(const te
writer_(sym.get_metawriter()), writer_(sym.get_metawriter()),
dims_(0, 0, width, height), dims_(0, 0, width, height),
query_extent_(query_extent), query_extent_(query_extent),
layout_(font_manager), layout_(new text_layout(font_manager)),
angle_(0.0), angle_(0.0),
placement_valid_(false), placement_valid_(false),
points_on_line_(false), points_on_line_(false),
@ -251,8 +252,8 @@ bool text_symbolizer_helper<FaceManagerT, DetectorT>::next_placement()
placement_valid_ = false; placement_valid_ = false;
return false; return false;
} }
placement_->properties.process(layout_, feature_); placement_->properties.process(*layout_, feature_);
layout_.shape_text(); layout_->shape_text();
//TODO //TODO
// info_ = &(text_.get_string_info()); // info_ = &(text_.get_string_info());
if (placement_->properties.orientation) if (placement_->properties.orientation)

View file

@ -50,8 +50,10 @@ void text_layout::break_lines()
void text_layout::shape_text() void text_layout::shape_text()
{ {
UnicodeString const& text = itemizer.get_text(); UnicodeString const& text = itemizer.get_text();
glyphs_.reserve(text.length()); //Preallocate memory
uint32_t offset = 0; //in utf16 code points uint32_t offset = 0; //in utf16 code points
glyphs_.reserve(text.length()); //Preallocate memory
std::list<text_item> const& list = itemizer.itemize(); std::list<text_item> const& list = itemizer.itemize();
std::list<text_item>::const_iterator itr = list.begin(), end = list.end(); std::list<text_item>::const_iterator itr = list.begin(), end = list.end();
for (;itr!=end; itr++) for (;itr!=end; itr++)

View file

@ -58,6 +58,7 @@ uint32_t text_shaping::process_text(UnicodeString const& text, unsigned start, u
hb_buffer_reset(buffer_); hb_buffer_reset(buffer_);
uint32_t length = text.length(); 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_add_utf16(buffer_, text.getBuffer(), length, start, end-start);
hb_buffer_set_direction(buffer_, rtl?HB_DIRECTION_RTL:HB_DIRECTION_LTR); hb_buffer_set_direction(buffer_, rtl?HB_DIRECTION_RTL:HB_DIRECTION_LTR);