diff --git a/include/mapnik/text/harfbuzz_shaper.hpp b/include/mapnik/text/harfbuzz_shaper.hpp index c84a36240..b96e98519 100644 --- a/include/mapnik/text/harfbuzz_shaper.hpp +++ b/include/mapnik/text/harfbuzz_shaper.hpp @@ -128,6 +128,9 @@ static void shape_text(text_line & line, double ymin = 0.0; double ymax = 0.0; + double units_per_EM = face->get_face()->units_per_EM; + double scale_multiplier = (units_per_EM > 0) ? (size / units_per_EM) : 1.0 ; + for (unsigned i = 0; i < num_glyphs; ++i) { auto const& gpos = positions[i]; @@ -138,7 +141,7 @@ static void shape_text(text_line & line, if (face->glyph_dimensions(g)) { g.face = face; - g.scale_multiplier = size / face->get_face()->units_per_EM; + g.scale_multiplier = scale_multiplier;//size / face->get_face()->units_per_EM; //Overwrite default advance with better value provided by HarfBuzz g.unscaled_advance = gpos.x_advance; g.offset.set(gpos.x_offset * g.scale_multiplier, gpos.y_offset * g.scale_multiplier); @@ -148,7 +151,7 @@ static void shape_text(text_line & line, ymax = std::max(g.ymax(), ymax); } } - std::cerr << "update y min/max " << ymin << "," << ymax << std::endl; + std::cerr << "Harfbuzz shaper: update y min/max " << ymin << "," << ymax << std::endl; line.set_y_minmax(ymin, ymax); break; //When we reach this point the current font had all glyphs. } diff --git a/include/mapnik/text/icu_shaper.hpp b/include/mapnik/text/icu_shaper.hpp index bcd822b27..3d1b923a3 100644 --- a/include/mapnik/text/icu_shaper.hpp +++ b/include/mapnik/text/icu_shaper.hpp @@ -90,7 +90,9 @@ static void shape_text(text_line & line, std::size_t num_chars = static_cast(num_char); shaped.releaseBuffer(length); bool shaped_status = true; - double max_glyph_height = 0; + double ymin = 0.0; + double ymax = 0.0; + double scale_multiplier = size / face->get_face()->units_per_EM; if (U_SUCCESS(err) && (num_chars == length)) { unsigned char_index = 0; @@ -109,16 +111,17 @@ static void shape_text(text_line & line, if (face->glyph_dimensions(g)) { g.face = face; - g.scale_multiplier = size / face->get_face()->units_per_EM; - double tmp_height = g.height(); - if (tmp_height > max_glyph_height) max_glyph_height = tmp_height; + g.scale_multiplier = scale_multiplier; width_map[char_index++] += g.advance(); line.add_glyph(std::move(g), scale_factor); + ymin = std::min(g.ymin(), ymin); + ymax = std::max(g.ymax(), ymax); } } } if (!shaped_status) continue; - line.update_max_char_height(max_glyph_height); + std::cerr << "ICU shaper: update y min/max " << ymin << "," << ymax << std::endl; + line.set_y_minmax(ymin, ymax); return; } } diff --git a/src/agg/process_debug_symbolizer.cpp b/src/agg/process_debug_symbolizer.cpp index 4c1a029d5..aa0b4ec49 100644 --- a/src/agg/process_debug_symbolizer.cpp +++ b/src/agg/process_debug_symbolizer.cpp @@ -268,6 +268,7 @@ void agg_renderer::process(debug_symbolizer const& sym, for (auto const& n : *common_.detector_) { auto const& label = n.get(); + std::cerr << "label.box=>" << label.box << std::endl; draw_rotated_rect(pixmap_, *ras_ptr, label.box, label.angle); } } diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index 8a2378769..6224c8486 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -118,7 +118,7 @@ text_upright_e placement_finder::simplify_upright(text_upright_e upright, double bool placement_finder::find_point_placement(pixel_position const& pos) { - glyph_positions_ptr glyphs = std::make_shared(); + glyph_positions_ptr glyphs = std::make_unique(); std::vector,double> > labels; glyphs->reserve(layouts_.glyphs_count()); @@ -140,7 +140,9 @@ bool placement_finder::find_point_placement(pixel_position const& pos) } box2d bbox = layout.bounds(); - bbox.re_center(layout_center.x, layout_center.y); + std::cerr << "before recenter -->" << bbox << std::endl; + auto box_center_y = bbox.center().y; + bbox.re_center(layout_center.x, layout_center.y + box_center_y); // TODO double margin = (text_props_->margin != 0 ? text_props_->margin : text_props_->minimum_distance) * scale_factor_; @@ -197,6 +199,7 @@ bool placement_finder::find_point_placement(pixel_position const& pos) { label_box.expand_to_include(box); } + std::cerr << box << std::endl; detector_.insert(box, layouts_.text(), std::get<1>(label)); } // do not render text off the canvas @@ -305,7 +308,7 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or pixel_position pos = off_pp.current_position() + cluster_offset; // Center the text on the line - double char_height = line.ymax() - line.ymin();//line.max_char_height(); + double char_height = line.ymax() - line.ymin(); //line.max_char_height(); pos.y = -pos.y - char_height/2.0*rot.cos; pos.x = pos.x + char_height/2.0*rot.sin; diff --git a/src/text/text_layout.cpp b/src/text/text_layout.cpp index 8caba4628..0844a8ad3 100644 --- a/src/text/text_layout.cpp +++ b/src/text/text_layout.cpp @@ -37,12 +37,15 @@ namespace mapnik { // Output is centered around (0,0) -static void rotated_box2d(box2d & box, rotation const& rot, pixel_position const& center, double width, double ymin, double ymax) +void rotated_box2d(box2d & box, rotation const& rot, pixel_position const& center, double width, double height, double vertical_displacement) { double half_width, half_height; - half_width = width / 2.; - half_height = (ymax - ymin) / 2.; - box.init(center.x - half_width, center.y - half_height + ymin, center.x + half_width, center.y + half_height + ymin); + half_width = 0.5 * width ; + half_height = 0.5 * height; + box.init(center.x - half_width, + center.y - half_height - vertical_displacement, + center.x + half_width, + center.y + half_height - vertical_displacement); } pixel_position evaluate_displacement(double dx, double dy, directions_e dir) @@ -192,11 +195,10 @@ void text_layout::layout() init_auto_alignment(); // Find text origin. - std::cerr << "ymin=" << ymin_ << " ymax=" << ymax_ << std::endl; displacement_ = scale_factor_ * displacement_ + alignment_offset(); if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_); // Find layout bounds, expanded for rotation - rotated_box2d(bounds_, orientation_, displacement_, width_, ymin_, ymax_); + rotated_box2d(bounds_, orientation_, displacement_, width_, height_, ymin_); } // In the Unicode string characters are always stored in logical order. @@ -409,8 +411,8 @@ void text_layout::add_line(text_line && line) line.set_first_line(true); } height_ += line.height(); - ymin_ += line.ymin(); - ymax_ += line.ymax(); + ymin_ = std::min(ymin_, line.ymin()); + ymax_ = std::max(ymax_, line.ymax()); glyphs_count_ += line.size(); width_ = std::max(width_, line.width()); lines_.emplace_back(std::move(line));