c++ - make bbox standalone method

This commit is contained in:
artemp 2016-04-22 12:51:20 +02:00
parent 4611d8cad1
commit ed87cd2883
2 changed files with 35 additions and 34 deletions

View file

@ -78,7 +78,6 @@ private:
// Maps upright==auto, left-only and right-only to left,right to simplify processing.
// angle = angle of at start of line (to estimate best option for upright==auto)
text_upright_e simplify_upright(text_upright_e upright, double angle) const;
box2d<double> get_bbox(text_layout const& layout, glyph_info const& glyph, pixel_position const& pos, rotation const& rot);
feature_impl const& feature_;
attributes const& attr_;
DetectorType & detector_;

View file

@ -39,6 +39,41 @@
namespace mapnik
{
namespace {
box2d<double> get_bbox(text_layout const& layout, glyph_info const& glyph, pixel_position const& pos, rotation const& rot)
{
/*
(0/ymax) (width/ymax)
***************
* *
(0/0)* *
* *
***************
(0/ymin) (width/ymin)
Add glyph offset in y direction, but not in x direction (as we use the full cluster width anyways)!
*/
double width = layout.cluster_width(glyph.char_index);
if (glyph.advance() <= 0) width = -width;
pixel_position tmp, tmp2;
tmp.set(0, glyph.ymax());
tmp = tmp.rotate(rot);
tmp2.set(width, glyph.ymax());
tmp2 = tmp2.rotate(rot);
box2d<double> bbox(tmp.x, -tmp.y,
tmp2.x, -tmp2.y);
tmp.set(width, glyph.ymin());
tmp = tmp.rotate(rot);
bbox.expand_to_include(tmp.x, -tmp.y);
tmp.set(0, glyph.ymin());
tmp = tmp.rotate(rot);
bbox.expand_to_include(tmp.x, -tmp.y);
pixel_position pos2 = pos + pixel_position(0, glyph.offset.y).rotate(rot);
bbox.move(pos2.x , -pos2.y);
return bbox;
}
} // anonymous namespace
placement_finder::placement_finder(feature_impl const& feature,
attributes const& attr,
DetectorType &detector,
@ -432,37 +467,4 @@ bool placement_finder::add_marker(glyph_positions_ptr & glyphs, pixel_position c
return true;
}
box2d<double> placement_finder::get_bbox(text_layout const& layout, glyph_info const& glyph, pixel_position const& pos, rotation const& rot)
{
/*
(0/ymax) (width/ymax)
***************
* *
(0/0)* *
* *
***************
(0/ymin) (width/ymin)
Add glyph offset in y direction, but not in x direction (as we use the full cluster width anyways)!
*/
double width = layout.cluster_width(glyph.char_index);
if (glyph.advance() <= 0) width = -width;
pixel_position tmp, tmp2;
tmp.set(0, glyph.ymax());
tmp = tmp.rotate(rot);
tmp2.set(width, glyph.ymax());
tmp2 = tmp2.rotate(rot);
box2d<double> bbox(tmp.x, -tmp.y,
tmp2.x, -tmp2.y);
tmp.set(width, glyph.ymin());
tmp = tmp.rotate(rot);
bbox.expand_to_include(tmp.x, -tmp.y);
tmp.set(0, glyph.ymin());
tmp = tmp.rotate(rot);
bbox.expand_to_include(tmp.x, -tmp.y);
pixel_position pos2 = pos + pixel_position(0, glyph.offset.y).rotate(rot);
bbox.move(pos2.x , -pos2.y);
return bbox;
}
}// ns mapnik