+ trying to fix text rendering ... sigh

This commit is contained in:
artemp 2013-07-17 13:33:16 +01:00
parent c1a9b60b50
commit ec570d8a7e
8 changed files with 134 additions and 44 deletions

View file

@ -210,7 +210,7 @@ public:
return face_set;
}
face_set_ptr get_face_set(std::string const& name, boost::optional<font_set> fset)
face_set_ptr get_face_set(std::string const& name, boost::optional<font_set> fset) // FIXME : bad style !!
{
if (fset && fset->size() > 0)
{

View file

@ -30,10 +30,13 @@
namespace mapnik {
namespace formatting {
class MAPNIK_DECL text_node: public node {
class MAPNIK_DECL text_node: public node
{
public:
text_node(expression_ptr text): node(), text_(text) {}
text_node(std::string text): node(), text_(parse_expression(text)) {}
text_node(expression_ptr text)
: node(), text_(text) {}
text_node(std::string const& text)
: node(), text_(parse_expression(text)) {}
void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(xml_node const& xml);
virtual void apply(char_properties const& p, feature_impl const& feature, processed_text &output) const;

View file

@ -26,16 +26,16 @@
#include <mapnik/text_properties.hpp>
#include <mapnik/text_path.hpp>
#include <mapnik/noncopyable.hpp>
#include <mapnik/font_engine_freetype.hpp> //!!
#include <mapnik/skia/skia_font_manager.hpp>
// stl
#include <list>
namespace mapnik
{
namespace mapnik {
// fwd declares
class freetype_engine;
template <typename T> class face_manager;
//class freetype_engine;
//template <typename T> class face_manager;
class MAPNIK_DECL processed_text : mapnik::noncopyable
{
@ -48,7 +48,7 @@ public:
UnicodeString str;
};
public:
processed_text(face_manager<freetype_engine> & font_manager, double scale_factor);
processed_text(double scale_factor);
void push_back(char_properties const& properties, UnicodeString const& text);
unsigned size() const { return expr_list_.size(); }
unsigned empty() const { return expr_list_.empty(); }
@ -56,10 +56,53 @@ public:
typedef std::list<processed_expression> expression_list;
expression_list::const_iterator begin() const;
expression_list::const_iterator end() const;
string_info const& get_string_info();
template <typename T>
string_info const& get_string_info(T & font_manager)
{
info_.clear(); //if this function is called twice invalid results are returned, so clear string_info first
expression_list::iterator itr = expr_list_.begin();
expression_list::iterator end = expr_list_.end();
for (; itr != end; ++itr)
{
char_properties const& p = itr->p;
std::cerr << p.face_name << " : " << p.fontset << std::endl;
face_set_ptr faces = font_manager.get_face_set(p.face_name, p.fontset);
if (faces->size() > 0)
{
faces->set_character_sizes(p.text_size * scale_factor_); // ???
faces->get_string_info(info_, itr->str, &(itr->p));
info_.add_text(itr->str);
}
}
return info_;
}
#if defined(HAVE_SKIA)
string_info const& get_string_info(skia_font_manager & manager)
{
info_.clear(); //if this function is called twice invalid results are returned, so clear string_info first
expression_list::iterator itr = expr_list_.begin();
expression_list::iterator end = expr_list_.end();
for (; itr != end; ++itr)
{
char_properties const& p = itr->p;
std::cerr << p.face_name << " : " << p.fontset << std::endl;
//face_set_ptr faces = font_manager.get_face_set(p.face_name, p.fontset);
//if (faces->size() > 0)
//{
//faces->set_character_sizes(p.text_size * scale_factor_); // ???
// faces->get_string_info(info_, itr->str, &(itr->p));
// info_.add_text(itr->str);
//}
}
return info_;
}
#endif
//string_info const& get_string_info();
private:
expression_list expr_list_;
face_manager<freetype_engine> &font_manager_;
double scale_factor_;
string_info info_;
};

View file

@ -33,7 +33,8 @@
#include <mapnik/ctrans.hpp>
#include <mapnik/rule.hpp>
#include <mapnik/feature_style_processor.hpp>
#include <mapnik/skia/skia_font_manager.hpp>
#include <mapnik/label_collision_detector.hpp>
// skia fwd decl
class SkCanvas;
@ -64,6 +65,10 @@ public:
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void process(text_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans);
void painted(bool painted) {};
inline bool process(rule::symbolizers const& /*syms*/,
@ -85,6 +90,8 @@ private:
CoordTransform t_;
double scale_factor_;
box2d<double> query_extent_;
skia_font_manager font_manager_;
boost::shared_ptr<label_collision_detector4> detector_;
};
}

View file

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef TEXT_PROPERTIES_HPP
#define TEXT_PROPERTIES_HPP
@ -57,9 +58,9 @@ typedef std::map<std::string, font_set> fontset_map;
struct MAPNIK_DECL char_properties
{
char_properties();
/** Construct object from XML. */
// Construct object from XML.
void from_xml(xml_node const &sym, fontset_map const & fontsets);
/** Write object to XML ptree. */
// Write object to XML ptree.
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, char_properties const& dfl=char_properties()) const;
std::string face_name;
boost::optional<font_set> fontset;
@ -124,27 +125,27 @@ typedef std::pair<double, double> position;
class processed_text;
/** Contains all text symbolizer properties which are not directly related to text formatting. */
// Contains all text symbolizer properties which are not directly related to text formatting.
struct MAPNIK_DECL text_symbolizer_properties
{
text_symbolizer_properties();
/** Load all values from XML ptree. */
// Load all values from XML ptree.
void from_xml(xml_node const &sym, fontset_map const & fontsets);
/** Save all values to XML ptree (but does not create a new parent node!). */
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, text_symbolizer_properties const &dfl=text_symbolizer_properties()) const;
// Save all values to XML ptree (but does not create a new parent node!).
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults,
text_symbolizer_properties const &dfl=text_symbolizer_properties()) const;
/** Takes a feature and produces formated text as output.
* The output object has to be created by the caller and passed in for thread safety.
*/
// Takes a feature and produces formated text as output.
// The output object has to be created by the caller and passed in for thread safety.
void process(processed_text &output, feature_impl const& feature) const;
/** Automatically create processing instructions for a single expression. */
// Automatically create processing instructions for a single expression.
void set_old_style_expression(expression_ptr expr);
/** Sets new format tree. */
// Sets new format tree.
void set_format_tree(formatting::node_ptr tree);
/** Get format tree. */
// Get format tree.
formatting::node_ptr format_tree() const;
/** Get a list of all expressions used in any placement.
* This function is used to collect attributes. */
// Get a list of all expressions used in any placement.
// This function is used to collect attributes.
void add_expressions(expression_set &output) const;
//Per symbolizer options
@ -154,26 +155,26 @@ struct MAPNIK_DECL text_symbolizer_properties
horizontal_alignment_e halign;
justify_alignment_e jalign;
vertical_alignment_e valign;
/** distance between repeated labels on a single geometry */
// distance between repeated labels on a single geometry
double label_spacing;
/** distance the label can be moved on the line to fit, if 0 the default is used */
// distance the label can be moved on the line to fit, if 0 the default is used
unsigned label_position_tolerance;
bool avoid_edges;
double minimum_distance;
double minimum_padding;
double minimum_path_length;
double max_char_angle_delta;
/** Always try render an odd amount of labels */
// Always try render an odd amount of labels
bool force_odd_labels;
bool allow_overlap;
/** Only consider geometry with largest bbox (polygons) */
// Only consider geometry with largest bbox (polygons)
bool largest_bbox_only;
double text_ratio;
double wrap_width;
/** Default values for char_properties. */
// Default values for char_properties.
char_properties format;
private:
/** A tree of formatting::nodes which contain text and formatting information. */
// A tree of formatting::nodes which contain text and formatting information.
formatting::node_ptr tree_;
};

View file

@ -42,11 +42,8 @@ processed_text::expression_list::const_iterator processed_text::end() const
return expr_list_.end();
}
processed_text::processed_text(face_manager<freetype_engine> & font_manager, double scale_factor)
: font_manager_(font_manager), scale_factor_(scale_factor)
{
}
processed_text::processed_text( double scale_factor)
: scale_factor_(scale_factor) {}
void processed_text::clear()
{
@ -54,7 +51,7 @@ void processed_text::clear()
expr_list_.clear();
}
/*
string_info const& processed_text::get_string_info()
{
info_.clear(); //if this function is called twice invalid results are returned, so clear string_info first
@ -100,5 +97,5 @@ string_info const& processed_text::get_string_info()
}
return info_;
}
*/
} //ns mapnik

View file

@ -24,7 +24,7 @@
#include <mapnik/skia/skia_renderer.hpp>
#include <mapnik/vertex_converters.hpp>
#include <mapnik/symbolizer_helpers.hpp>
// skia
#include <SkCanvas.h>
#include <SkPath.h>
@ -74,7 +74,11 @@ skia_renderer::skia_renderer(Map const& map, SkCanvas & canvas, double scale_fac
width_(map.width()),
height_(map.height()),
t_(map.width(), map.height(), map.get_current_extent()),
scale_factor_(scale_factor) {}
scale_factor_(scale_factor),
font_manager_(),
detector_(boost::make_shared<label_collision_detector4>(
box2d<double>(-map.buffer_size(), -map.buffer_size(),
map.width() + map.buffer_size(), map.height() + map.buffer_size()))) {}
skia_renderer::~skia_renderer() {}
@ -239,6 +243,40 @@ void skia_renderer::process(polygon_symbolizer const& sym,
canvas_.drawPath(path, paint);
}
void skia_renderer::process(text_symbolizer const& sym,
mapnik::feature_impl & feature,
proj_transform const& prj_trans)
{
text_symbolizer_helper<skia_font_manager,label_collision_detector4>
helper(sym, feature, prj_trans,
width_, height_,
scale_factor_,
t_, font_manager_, *detector_, query_extent_);
while (helper.next())
{
placements_type const& placements = helper.placements();
for (unsigned i = 0; i < placements.size(); ++i)
{
//std::cerr << placements[i].x << "," << placements[i].y << std::endl;
double sx = placements[i].center.x;
double sy = placements[i].center.y;
placements[i].rewind();
for (int j = 0; j < placements[i].num_nodes(); ++j)
{
char_info_ptr c;
double x, y, angle;
placements[i].vertex(c, x, y, angle);
std::cerr << c << " " << x << "," << y << " angle=" << angle << std::endl;
//context_.add_text(placements[ii], face_manager_, font_manager_, scale_factor_);
}
}
}
}
}
#endif // HAVE_SKIA

View file

@ -58,7 +58,7 @@ text_symbolizer_helper<FaceManagerT, DetectorT>::text_symbolizer_helper(text_sym
detector_(detector),
dims_(0, 0, width, height),
query_extent_(query_extent),
text_(font_manager, scale_factor),
text_(scale_factor),
angle_(0.0),
placement_valid_(false),
points_on_line_(false),
@ -331,7 +331,7 @@ bool text_symbolizer_helper<FaceManagerT, DetectorT>::next_placement()
}
finder_.reset(new placement_finder<DetectorT>(feature_, *placement_,
text_.get_string_info(),
text_.get_string_info(font_manager_),
detector_, dims_));
placement_valid_ = true;
return true;
@ -503,6 +503,7 @@ agg::trans_affine const& shield_symbolizer_helper<FaceManagerT, DetectorT>::get_
}
template class text_symbolizer_helper<face_manager<freetype_engine>, label_collision_detector4>;
template class text_symbolizer_helper<skia_font_manager, label_collision_detector4>;
template class shield_symbolizer_helper<face_manager<freetype_engine>, label_collision_detector4>;
template class mapnik::placement_finder<mapnik::label_collision_detector4>;
} //namespace