Simplify code.
This commit is contained in:
parent
48290546d9
commit
503c1862ba
8 changed files with 38 additions and 31 deletions
|
@ -96,7 +96,7 @@ public:
|
|||
box2d_type& operator*=(T);
|
||||
box2d_type& operator/=(T);
|
||||
T operator[](int index) const;
|
||||
box2d_type operator +(T other); //enlarge box by given amount
|
||||
box2d_type operator +(T other) const; //enlarge box by given amount
|
||||
box2d_type& operator +=(T other); //enlarge box by given amount
|
||||
|
||||
// compute the bounding box of this one transformed
|
||||
|
|
|
@ -61,6 +61,12 @@ struct pixel_position
|
|||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
pixel_position rotate(double sina_, double cosa_) const;
|
||||
pixel_position operator~()
|
||||
{
|
||||
return pixel_position(x, -y);
|
||||
}
|
||||
};
|
||||
|
||||
inline pixel_position operator* (double factor, pixel_position const& pos)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
//mapnik
|
||||
#include <mapnik/text/char_properties_ptr.hpp>
|
||||
#include <mapnik/pixel_position.hpp>
|
||||
|
||||
//boost
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
@ -52,8 +53,7 @@ struct glyph_info
|
|||
double ymax;
|
||||
double line_height; //Line height returned by freetype, includes normal font line spacing, but not additional user defined spacing
|
||||
|
||||
double offset_x;
|
||||
double offset_y;
|
||||
pixel_position offset;
|
||||
|
||||
char_properties_ptr format;
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ private:
|
|||
void path_move_dx(vertex_cache &pp);
|
||||
static double normalize_angle(double angle);
|
||||
double get_spacing(double path_length, double layout_width) const;
|
||||
bool collision(box2d<double> const& box) const;
|
||||
Feature const& feature_;
|
||||
DetectorType &detector_;
|
||||
box2d<double> const& extent_;
|
||||
|
|
|
@ -404,7 +404,7 @@ box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
box2d<T> box2d<T>::operator+ (T other)
|
||||
box2d<T> box2d<T>::operator+ (T other) const
|
||||
{
|
||||
return box2d<T>(minx_ - other, miny_ - other, maxx_ + other, maxy_ + other);
|
||||
}
|
||||
|
|
|
@ -181,8 +181,7 @@ void text_layout::shape_text(text_line_ptr line)
|
|||
tmp.char_index = glyphs[i].cluster;
|
||||
tmp.glyph_index = glyphs[i].codepoint;
|
||||
tmp.width = positions[i].x_advance / 64.0;
|
||||
tmp.offset_x = positions[i].x_offset / 64.0;
|
||||
tmp.offset_y = positions[i].y_offset / 64.0;
|
||||
tmp.offset.set(positions[i].x_offset / 64.0, positions[i].y_offset / 64.0);
|
||||
tmp.face = face;
|
||||
tmp.format = itr->format;
|
||||
face->glyph_dimensions(tmp);
|
||||
|
|
|
@ -163,12 +163,9 @@ static void rotated_box2d(box2d<double> &box, double sina, double cosa, double w
|
|||
box.init(-new_width/2., -new_height/2., new_width/2., new_height/2.);
|
||||
}
|
||||
|
||||
static pixel_position rotate(pixel_position pos, double sina, double cosa)
|
||||
pixel_position pixel_position::rotate(double sina, double cosa) const
|
||||
{
|
||||
double tmp_x = pos.x * cosa + pos.y * sina;
|
||||
pos.y = - pos.x * sina + pos.y * cosa;
|
||||
pos.x = tmp_x;
|
||||
return pos;
|
||||
return pixel_position(x * cosa - y * sina, x * sina + y * cosa);
|
||||
}
|
||||
|
||||
|
||||
|
@ -178,26 +175,13 @@ bool placement_finder_ng::find_point_placement(pixel_position pos)
|
|||
glyph_positions_ptr glyphs = boost::make_shared<glyph_positions>();
|
||||
|
||||
pixel_position displacement = scale_factor_ * info_->properties.displacement + alignment_offset();
|
||||
if (info_->properties.rotate_displacement) displacement = rotate(displacement, sina_, cosa_);
|
||||
if (info_->properties.rotate_displacement) displacement = displacement.rotate(-sina_, cosa_);
|
||||
|
||||
glyphs->set_base_point(pos + displacement);
|
||||
box2d<double> bbox;
|
||||
rotated_box2d(bbox, sina_, cosa_, layout_.width(), layout_.height());
|
||||
bbox.re_center(glyphs->get_base_point().x, glyphs->get_base_point().y);
|
||||
|
||||
if (!detector_.extent().intersects(bbox)
|
||||
||
|
||||
(info_->properties.avoid_edges && !extent_.contains(bbox))
|
||||
||
|
||||
(info_->properties.minimum_padding > 0 &&
|
||||
!extent_.contains(bbox + (scale_factor_ * info_->properties.minimum_padding)))
|
||||
||
|
||||
(!info_->properties.allow_overlap &&
|
||||
!detector_.has_point_placement(bbox, info_->properties.minimum_distance * scale_factor_))
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (collision(bbox)) return false;
|
||||
|
||||
detector_.insert(bbox, layout_.get_text());
|
||||
|
||||
|
@ -228,9 +212,7 @@ bool placement_finder_ng::find_point_placement(pixel_position pos)
|
|||
for (; glyph_itr != glyph_end; glyph_itr++)
|
||||
{
|
||||
// place the character relative to the center of the string envelope
|
||||
double dx = x * cosa_ - y * sina_;
|
||||
double dy = x * sina_ + y * cosa_;
|
||||
glyphs->push_back(*glyph_itr, pixel_position(dx, dy), angle_); //TODO: Store cosa, sina instead
|
||||
glyphs->push_back(*glyph_itr, pixel_position(x, y).rotate(sina_, cosa_), angle_); //TODO: Store cosa, sina instead
|
||||
if (glyph_itr->width)
|
||||
{
|
||||
//Only advance if glyph is not part of a multiple glyph sequence
|
||||
|
@ -405,6 +387,24 @@ double placement_finder_ng::get_spacing(double path_length, double layout_width)
|
|||
return path_length / num_labels;
|
||||
}
|
||||
|
||||
bool placement_finder_ng::collision(const box2d<double> &box) const
|
||||
{
|
||||
if (!detector_.extent().intersects(box)
|
||||
||
|
||||
(info_->properties.avoid_edges && !extent_.contains(box))
|
||||
||
|
||||
(info_->properties.minimum_padding > 0 &&
|
||||
!extent_.contains(box + (scale_factor_ * info_->properties.minimum_padding)))
|
||||
||
|
||||
(!info_->properties.allow_overlap &&
|
||||
!detector_.has_point_placement(box, info_->properties.minimum_distance * scale_factor_))
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
|
|
|
@ -55,8 +55,9 @@ void text_renderer<T>::prepare_glyphs(glyph_positions_ptr pos)
|
|||
matrix.yy = (FT_Fixed)( cosa * 0x10000L);
|
||||
}
|
||||
|
||||
pen.x = int((itr->pos.x + glyph.offset_x * cosa - glyph.offset_y * sina) * 64);
|
||||
pen.y = int((itr->pos.y + glyph.offset_y * cosa + glyph.offset_x * sina) * 64);
|
||||
pixel_position pos = itr->pos + glyph.offset.rotate(sina, cosa);
|
||||
pen.x = int(pos.x * 64);
|
||||
pen.y = int(pos.y * 64);
|
||||
|
||||
FT_Face face = glyph.face->get_face();
|
||||
FT_Set_Transform(face, &matrix, &pen);
|
||||
|
|
Loading…
Add table
Reference in a new issue