Store format with each glyph to make code less complex.
This commit is contained in:
parent
8bbceb1a41
commit
9f2ec07cd8
7 changed files with 46 additions and 16 deletions
|
@ -22,21 +22,27 @@
|
|||
#ifndef MAPNIK_GLYPH_INFO_HPP
|
||||
#define MAPNIK_GLYPH_INFO_HPP
|
||||
|
||||
//mapnik
|
||||
#include <mapnik/text/char_properties_ptr.hpp>
|
||||
|
||||
//boost
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
class font_face;
|
||||
typedef boost::shared_ptr<font_face> face_ptr;
|
||||
|
||||
|
||||
typedef unsigned glyph_index_t;
|
||||
|
||||
struct glyph_info
|
||||
{
|
||||
glyph_info()
|
||||
: glyph_index(0), face(), char_index(0),
|
||||
width(0), ymin(0), ymax(0), line_height(0), valid(false) {}
|
||||
width(0), ymin(0), ymax(0), line_height(0) {}
|
||||
glyph_index_t glyph_index;
|
||||
face_ptr face;
|
||||
unsigned char_index; //Position in the string of all characters i.e. before itemizing
|
||||
|
@ -46,7 +52,7 @@ struct glyph_info
|
|||
double ymax;
|
||||
double line_height;
|
||||
|
||||
bool valid; //Are all values valid?
|
||||
char_properties_ptr format;
|
||||
|
||||
double height() const { return ymax-ymin; }
|
||||
};
|
||||
|
|
|
@ -92,6 +92,7 @@ public:
|
|||
void break_lines();
|
||||
void shape_text();
|
||||
void clear();
|
||||
unsigned size() const;
|
||||
|
||||
private:
|
||||
text_itemizer itemizer;
|
||||
|
|
|
@ -64,7 +64,6 @@ public:
|
|||
glyph_info const& get_glyph() const;
|
||||
pixel_position get_position() const;
|
||||
double get_angle() const;
|
||||
char_properties_ptr get_format() const;
|
||||
/** Is each character rotated by the same angle?
|
||||
* This function is used to avoid costly trigonometric function calls when not necessary. */
|
||||
bool is_constant_angle() const;
|
||||
|
@ -73,6 +72,7 @@ private:
|
|||
pixel_position base_point_;
|
||||
bool point_;
|
||||
text_layout_ptr layout_;
|
||||
unsigned current_;
|
||||
};
|
||||
typedef boost::shared_ptr<glyph_positions> glyph_positions_ptr;
|
||||
|
||||
|
|
|
@ -67,7 +67,6 @@ void font_face::glyph_dimensions(glyph_info &glyph)
|
|||
glyph.ymin = glyph_bbox.yMin; //TODO: Which data format? 26.6, integer?
|
||||
glyph.ymax = glyph_bbox.yMax; //TODO: Which data format? 26.6, integer?
|
||||
glyph.line_height = face_->size->metrics.height/64.0;
|
||||
glyph.valid = true;
|
||||
|
||||
//TODO: dimension_cache_.insert(std::pair<unsigned, char_info>(c, dim));
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ void text_layout::shape_text()
|
|||
tmp.glyph_index = glyphs[i].codepoint;
|
||||
tmp.width = positions[i].x_advance / 64.0;
|
||||
tmp.face = face;
|
||||
tmp.format = itr->format;
|
||||
face->glyph_dimensions(tmp);
|
||||
glyphs_.push_back(tmp);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ glyph_positions_ptr placement_finder_ng::find_point_placement(text_layout_ptr la
|
|||
}
|
||||
|
||||
glyph_positions::glyph_positions(text_layout_ptr layout)
|
||||
: base_point_(), point_(true), layout_(layout)
|
||||
: base_point_(), point_(true), layout_(layout), current_(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -54,5 +54,37 @@ void glyph_positions::point_placement(pixel_position base_point)
|
|||
point_ = true;
|
||||
}
|
||||
|
||||
void glyph_positions::rewind()
|
||||
{
|
||||
current_ = 0;
|
||||
}
|
||||
|
||||
glyph_info const& glyph_positions::get_glyph() const
|
||||
{
|
||||
assert(layout_);
|
||||
assert(current_ < layout_->size());
|
||||
|
||||
}
|
||||
|
||||
pixel_position glyph_positions::get_position() const
|
||||
{
|
||||
return pixel_position(0, 0);
|
||||
}
|
||||
|
||||
double glyph_positions::get_angle() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool glyph_positions::is_constant_angle() const
|
||||
{
|
||||
return point_;
|
||||
}
|
||||
|
||||
const pixel_position &glyph_positions::get_base_point() const
|
||||
{
|
||||
return base_point_;
|
||||
}
|
||||
|
||||
|
||||
}// ns mapnik
|
||||
|
|
|
@ -36,23 +36,14 @@ void text_renderer<T>::prepare_glyphs(glyph_positions_ptr pos)
|
|||
matrix.yx = (FT_Fixed)( sina * 0x10000L);
|
||||
matrix.yy = (FT_Fixed)( cosa * 0x10000L);
|
||||
}
|
||||
float text_size = 0;
|
||||
while (pos->next())
|
||||
{
|
||||
char_properties_ptr format = pos->get_format();
|
||||
if (format)
|
||||
{
|
||||
//Only update parameters when format has changed.
|
||||
text_size = format->text_size;
|
||||
}
|
||||
|
||||
|
||||
pixel_position p = pos->get_position();
|
||||
pen.x = int(p.x * 64);
|
||||
pen.y = int(p.y * 64);
|
||||
|
||||
glyph_info const& glyph = pos->get_glyph();
|
||||
glyph.face->set_character_sizes(text_size); //TODO: Optimize this?
|
||||
glyph.face->set_character_sizes(glyph.format->text_size); //TODO: Optimize this?
|
||||
|
||||
if (!constant_angle)
|
||||
{
|
||||
|
@ -76,7 +67,7 @@ void text_renderer<T>::prepare_glyphs(glyph_positions_ptr pos)
|
|||
if (error) continue;
|
||||
|
||||
// take ownership of the glyph
|
||||
glyphs_.push_back(new glyph_t(image, format));
|
||||
glyphs_.push_back(new glyph_t(image, glyph.format));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue