Reenable TextSymbolizer in Cairo renderer.

This commit is contained in:
Hermann Kraus 2012-07-30 02:59:06 +02:00
parent a57123f8be
commit 435f716821
2 changed files with 38 additions and 59 deletions

View file

@ -32,17 +32,17 @@ struct pixel_position
double y; double y;
pixel_position(double x, double y) : x(x), y(y) { } pixel_position(double x, double y) : x(x), y(y) { }
pixel_position() : x(0), y(0) { } pixel_position() : x(0), y(0) { }
pixel_position operator+ (pixel_position const& other) pixel_position operator+ (pixel_position const& other) const
{ {
return pixel_position(x + other.x, y + other.y); return pixel_position(x + other.x, y + other.y);
} }
pixel_position operator- (pixel_position const& other) pixel_position operator- (pixel_position const& other) const
{ {
return pixel_position(x - other.x, y - other.y); return pixel_position(x - other.x, y - other.y);
} }
pixel_position operator* (double other) pixel_position operator* (double other) const
{ {
return pixel_position(x * other, y * other); return pixel_position(x * other, y * other);
} }

View file

@ -658,13 +658,13 @@ public:
context_->restore(); context_->restore();
} }
void show_glyph(unsigned long index, double x, double y) void show_glyph(unsigned long index, pixel_position const& pos)
{ {
Cairo::Glyph glyph; Cairo::Glyph glyph;
glyph.index = index; glyph.index = index;
glyph.x = x; glyph.x = pos.x;
glyph.y = y; glyph.y = pos.y;
std::vector<Cairo::Glyph> glyphs; std::vector<Cairo::Glyph> glyphs;
@ -673,13 +673,13 @@ public:
context_->show_glyphs(glyphs); context_->show_glyphs(glyphs);
} }
void glyph_path(unsigned long index, double x, double y) void glyph_path(unsigned long index, pixel_position pos)
{ {
Cairo::Glyph glyph; Cairo::Glyph glyph;
glyph.index = index; glyph.index = index;
glyph.x = x; glyph.x = pos.x;
glyph.y = y; glyph.y = pos.y;
std::vector<Cairo::Glyph> glyphs; std::vector<Cairo::Glyph> glyphs;
@ -688,55 +688,41 @@ public:
context_->glyph_path(glyphs); context_->glyph_path(glyphs);
} }
void add_text(glyph_positions_ptr path, void add_text(glyph_positions_ptr pos,
cairo_face_manager & manager, cairo_face_manager & manager,
face_manager<freetype_engine> &font_manager, face_manager<freetype_engine> &font_manager,
double scale_factor = 1.0) double scale_factor)
{ {
#if 0 pixel_position const& base = pos->get_base_point();
double sx = path.center.x;
double sy = path.center.y;
path.rewind(); glyph_positions::const_iterator itr = pos->begin(), end = pos->end();
for (; itr != end; itr++)
for (int iii = 0; iii < path.num_nodes(); iii++)
{ {
char_info_ptr c; glyph_info const& glyph = *(itr->glyph);
double x, y, angle; double text_size = glyph.format->text_size * scale_factor;
glyph.face->set_character_sizes(text_size);
path.vertex(&c, &x, &y, &angle); Cairo::Matrix matrix;
double sina = sin(itr->angle);
double cosa = cos(itr->angle);
matrix.xx = text_size * cosa;
matrix.xy = text_size * sina;
matrix.yx = text_size * -sina;
matrix.yy = text_size * cosa;
matrix.x0 = 0;
matrix.y0 = 0;
face_set_ptr faces = font_manager.get_face_set(c->format->face_name, c->format->fontset); set_font_matrix(matrix);
float text_size = c->format->text_size * scale_factor; set_font_face(manager, glyph.face);
faces->set_character_sizes(text_size);
glyph_ptr glyph = faces->get_glyph(c->c); glyph_path(glyph.glyph_index, base + itr->pos);
set_line_width(glyph.format->halo_radius * scale_factor);
if (glyph) set_line_join(ROUND_JOIN);
{ set_color(glyph.format->halo_fill);
Cairo::Matrix matrix; stroke();
set_color(glyph.format->fill);
matrix.xx = text_size * cos(angle); show_glyph(glyph.glyph_index, base + itr->pos);
matrix.xy = text_size * sin(angle);
matrix.yx = text_size * -sin(angle);
matrix.yy = text_size * cos(angle);
matrix.x0 = 0;
matrix.y0 = 0;
set_font_matrix(matrix);
set_font_face(manager, glyph->get_face());
glyph_path(glyph->get_index(), sx + x, sy - y);
set_line_width(c->format->halo_radius * scale_factor);
set_line_join(ROUND_JOIN);
set_color(c->format->halo_fill);
stroke();
set_color(c->format->fill);
show_glyph(glyph->get_index(), sx + x, sy - y);
}
} }
#endif
} }
@ -1489,7 +1475,6 @@ void cairo_renderer_base::process(text_symbolizer const& sym,
mapnik::feature_impl & feature, mapnik::feature_impl & feature,
proj_transform const& prj_trans) proj_transform const& prj_trans)
{ {
#if 0
text_symbolizer_helper<face_manager<freetype_engine>, text_symbolizer_helper<face_manager<freetype_engine>,
label_collision_detector4> helper( label_collision_detector4> helper(
sym, feature, prj_trans, sym, feature, prj_trans,
@ -1500,17 +1485,11 @@ void cairo_renderer_base::process(text_symbolizer const& sym,
cairo_context context(context_); cairo_context context(context_);
context.set_operator(sym.comp_op()); context.set_operator(sym.comp_op());
while (helper.next()) glyph_positions_ptr glyphs;
while ((glyphs = helper.next()))
{ {
placements_type const& placements = helper.placements(); context.add_text(glyphs, face_manager_, font_manager_, scale_factor_);
for (unsigned int ii = 0; ii < placements.size(); ++ii)
{
context.add_text(placements[ii], face_manager_, font_manager_, scale_factor_);
}
} }
#else
#warning CAIRO: TextSymbolizer disabled!
#endif
} }
template class cairo_renderer<Cairo::Surface>; template class cairo_renderer<Cairo::Surface>;