Preallocate memory for glyphs.

This commit is contained in:
Hermann Kraus 2012-08-19 00:09:45 +02:00
parent 90c2ddcbf1
commit accbc139a5
4 changed files with 28 additions and 3 deletions

View file

@ -68,6 +68,8 @@ public:
unsigned get_first_char() const;
unsigned get_last_char() const;
unsigned size() const;
private:
glyph_vector glyphs_;
double line_height_; //Includes line spacing (returned by freetype)
@ -100,6 +102,7 @@ public:
unsigned size() const;
double cluster_width(unsigned cluster) const;
unsigned glyphs_count() const;
private:
void break_line(text_line_ptr line, double wrap_width, unsigned text_ratio);
@ -115,6 +118,7 @@ private:
std::map<unsigned, double> width_map_;
double width_;
double height_;
unsigned glyphs_count_;
//output

View file

@ -73,17 +73,20 @@ public:
const_iterator end() const;
void push_back(glyph_info const& glyph, pixel_position offset, rotation const& rot);
void reserve(unsigned count);
pixel_position const& get_base_point() const;
void set_base_point(pixel_position base_point);
void set_marker(marker_info_ptr marker, pixel_position const& marker_pos);
marker_info_ptr marker() const;
pixel_position const& marker_pos() const;
box2d<double> const & bbox() const;
private:
std::vector<glyph_position> data_;
pixel_position base_point_;
marker_info_ptr marker_;
pixel_position marker_pos_;
box2d<double> bbox_;
};
typedef boost::shared_ptr<glyph_positions> glyph_positions_ptr;

View file

@ -38,7 +38,8 @@
namespace mapnik
{
text_layout::text_layout(face_manager_freetype &font_manager)
: font_manager_(font_manager), itemizer_(), width_(0), height_(0), lines_()
: font_manager_(font_manager), itemizer_(), width_(0), height_(0), glyphs_count_(0),
lines_()
{
}
@ -205,6 +206,7 @@ void text_layout::add_line(text_line_ptr line)
lines_.push_back(line);
width_ = std::max(width_, line->width());
height_ += line->height();
glyphs_count_ += line->size();
}
void text_layout::clear()
@ -248,6 +250,11 @@ double text_layout::cluster_width(unsigned cluster) const
return 0;
}
unsigned text_layout::glyphs_count() const
{
return glyphs_count_;
}
/*********************************************************************************************/
text_line::text_line(unsigned first_char, unsigned last_char)
@ -311,4 +318,9 @@ unsigned text_line::get_last_char() const
return last_char_;
}
unsigned text_line::size() const
{
glyphs_.size();
}
} //ns mapnik

View file

@ -204,6 +204,7 @@ bool placement_finder_ng::find_point_placement(pixel_position pos)
// set for upper left corner of text envelope for the first line, top left of first character
y = layout_.height() / 2.0;
glyphs->reserve(layout_.glyphs_count());
text_layout::const_iterator line_itr = layout_.begin(), line_end = layout_.end();
for (; line_itr != line_end; line_itr++)
{
@ -316,6 +317,7 @@ bool placement_finder_ng::single_line_placement(vertex_cache &pp, text_upright_e
double sign = (real_orientation == UPRIGHT_LEFT) ? -1 : 1;
double offset = alignment_offset().y + info_->properties.displacement.y + sign * layout_.height()/2.;
glyphs->reserve(layout_.glyphs_count());
text_layout::const_iterator line_itr = layout_.begin(), line_end = layout_.end();
for (; line_itr != line_end; line_itr++)
{
@ -496,7 +498,7 @@ box2d<double> placement_finder_ng::get_bbox(glyph_info const& glyph, pixel_posit
glyph_positions::glyph_positions()
: base_point_()
: data_(), base_point_(), marker_(), marker_pos_(), bbox_()
{
}
@ -513,10 +515,14 @@ glyph_positions::const_iterator glyph_positions::end() const
void glyph_positions::push_back(const glyph_info &glyph, pixel_position offset, rotation const& rot)
{
data_.push_back(glyph_position(glyph, offset, rot));
}
void glyph_positions::reserve(unsigned count)
{
data_.reserve(count);
}
pixel_position const& glyph_positions::get_base_point() const
{
return base_point_;