Start work on new placement finder.

This commit is contained in:
Hermann Kraus 2012-07-06 02:09:48 +02:00
parent 959ff260dd
commit ddb1fa995f
4 changed files with 142 additions and 4 deletions

View file

@ -38,18 +38,21 @@
namespace mapnik
{
/** This class stores all glyphs in a format run (i.e. conscutive glyphs with the same format). */
class format_run
{
char_properties_ptr properties;
std::vector<glyph_info> glyphs;
// double
std::vector<glyph_info> const& glyphs() const { return glyphs_; }
void add_glyph(glyph_info const& info);
private:
std::vector<glyph_info> glyphs_;
};
typedef boost::shared_ptr<format_run> format_run_ptr;
/* This class stores all glyphs in a line in left to right order.
/** This class stores all format_runs in a line in left to right order.
*
* It can be used for rendering but no text processing (like line breaking)
* should be done!
@ -60,7 +63,7 @@ class text_line
public:
double max_text_height; //Height of the largest format run in this run.
double max_line_height; //Includes line spacing
std::vector<format_run_ptr> const& get_runs() const { return runs_; }
std::vector<format_run_ptr> const& runs() const { return runs_; }
void add_run(format_run_ptr);
private:

View file

@ -0,0 +1,75 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_PLACEMENT_FINDER_NG_HPP
#define MAPNIK_PLACEMENT_FINDER_NG_HPP
//mapnik
#include <mapnik/box2d.hpp>
//boost
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
namespace mapnik
{
class label_collision_detector4;
typedef label_collision_detector4 DetectorType;
class feature_impl;
typedef feature_impl Feature;
class text_layout;
typedef boost::shared_ptr<text_layout> text_layout_ptr;
class placement_positions
{
public:
placement_positions(text_layout_ptr layout);
void point_placement(double x, double y);
private:
double x_;
double y_;
bool point_;
text_layout_ptr layout_;
};
typedef boost::shared_ptr<placement_positions> placement_positions_ptr;
class placement_finder_ng : boost::noncopyable
{
public:
placement_finder_ng(Feature const& feature,
DetectorType & detector,
box2d<double> const& extent);
/** Try to place a single label at the given point. */
placement_positions_ptr find_point_placement(text_layout_ptr layout, double pos_x, double pos_y, double angle=0.0);
private:
Feature const& feature_;
DetectorType const& detector_;
box2d<double> const& extent_;
};
}//ns mapnik
#endif // PLACEMENT_FINDER_NG_HPP

View file

@ -185,6 +185,7 @@ source = Split(
text/itemizer.cpp
text/scrptrun.cpp
text/face.cpp
text/placement_finder_ng.cpp
"""
)

View file

@ -0,0 +1,59 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//mapnik
#include <mapnik/text/placement_finder_ng.hpp>
//boost
#include <boost/make_shared.hpp>
namespace mapnik
{
placement_finder_ng::placement_finder_ng( Feature const& feature, DetectorType &detector, box2d<double> const& extent)
: feature_(feature), detector_(detector), extent_(extent)
{
}
placement_positions_ptr placement_finder_ng::find_point_placement(text_layout_ptr layout, double pos_x, double pos_y, double angle)
{
placement_positions_ptr ptr = boost::make_shared<placement_positions>(layout);
ptr->point_placement(pos_x, pos_y);
//TODO: angle
//TODO: Check for placement
return ptr;
}
placement_positions::placement_positions(text_layout_ptr layout)
: x_(0), y_(0), point_(true), layout_(layout)
{
}
void placement_positions::point_placement(double x, double y)
{
x_ = x;
y_ = y;
point_ = true;
}
}// ns mapnik