Use char_properties_ptr in more files.

This commit is contained in:
Hermann Kraus 2012-07-01 23:14:35 +02:00
parent 993395c510
commit 47dea8ed52
16 changed files with 72 additions and 23 deletions

View file

@ -24,9 +24,9 @@
#define CHAR_INFO_HPP
#include <boost/shared_ptr.hpp>
#include <mapnik/text/char_properties_ptr.hpp>
namespace mapnik {
struct char_properties;
class char_info {
public:
@ -58,7 +58,7 @@ public:
double ymin;
double ymax;
double avg_height;
char_properties *format;
char_properties_ptr format;
double height() const { return ymax-ymin; }
};
}

View file

@ -33,6 +33,7 @@
#include <mapnik/pixel_position.hpp>
#include <mapnik/image_compositing.hpp>
#include <mapnik/text/face.hpp>
#include <mapnik/text/char_properties_ptr.hpp>
// freetype2
extern "C"
@ -195,8 +196,8 @@ struct text_renderer : private boost::noncopyable
struct glyph_t : boost::noncopyable
{
FT_Glyph image;
char_properties *properties;
glyph_t(FT_Glyph image_, char_properties *properties_)
char_properties_ptr properties;
glyph_t(FT_Glyph image_, char_properties_ptr properties_)
: image(image_), properties(properties_) {}
~glyph_t () { FT_Done_Glyph(image);}
};

View file

@ -25,6 +25,7 @@
// mapnik
#include <mapnik/feature.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/text/char_properties_ptr.hpp>
// stl
#include <set>
@ -37,7 +38,6 @@ namespace mapnik {
typedef std::set<expression_ptr> expression_set;
class text_layout;
class xml_node;
struct char_properties;
namespace formatting {

View file

@ -32,7 +32,7 @@ class expression_format: public node {
public:
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 const& feature, text_layout &output) const;
virtual void apply(char_properties_ptr p, Feature const& feature, text_layout &output) const;
virtual void add_expressions(expression_set &output) const;
void set_child(node_ptr child);

View file

@ -32,7 +32,7 @@ class format_node: public node {
public:
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 const& feature, text_layout &output) const;
virtual void apply(char_properties_ptr p, Feature const& feature, text_layout &output) const;
virtual void add_expressions(expression_set &output) const;
void set_child(node_ptr child);

View file

@ -30,7 +30,7 @@ class list_node: public node {
public:
list_node() : node(), children_() {}
virtual void to_xml(boost::property_tree::ptree &xml) const;
virtual void apply(char_properties const& p, Feature const& feature, text_layout &output) const;
virtual void apply(char_properties_ptr p, Feature const& feature, text_layout &output) const;
virtual void add_expressions(expression_set &output) const;
void push_back(node_ptr n);

View file

@ -0,0 +1,10 @@
#ifndef CHAR_PROPERTIES_PTR_HPP
#define CHAR_PROPERTIES_PTR_HPP
#include <boost/shared_ptr.hpp>
namespace mapnik
{
struct char_properties;
typedef boost::shared_ptr<char_properties> char_properties_ptr;
}
#endif // CHAR_PROPERTIES_PTR_HPP

View file

@ -29,14 +29,13 @@ namespace mapnik
{
class font_face;
struct char_properties;
typedef boost::shared_ptr<font_face> face_ptr;
typedef unsigned glyph_index_t;
struct glyph_info
{
glyph_info()
: glyph_index(0), face(), char_index(0), format(0),
: glyph_index(0), face(), char_index(0),
width(0), ymin(0), ymax(0), line_height(0), valid(false) {}
glyph_index_t glyph_index;
face_ptr face;

View file

@ -24,7 +24,7 @@
#define MAPNIK_TEXT_ITEMIZER_HPP
//mapnik
#include <mapnik/text_properties.hpp> //TODO: Move to text/properties.hpp
#include <mapnik/text/char_properties_ptr.hpp>
// stl
#include <string>

View file

@ -26,18 +26,53 @@
#include <mapnik/text/itemizer.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/text/glyph_info.hpp>
#include <mapnik/text/char_properties_ptr.hpp>
//stl
#include <vector>
#include <list>
//boost
#include <boost/shared_ptr.hpp>
namespace mapnik
{
class format_run
{
char_properties_ptr properties;
std::vector<glyph_info> glyphs;
// double
};
typedef boost::shared_ptr<format_run> format_run_ptr;
/* This class stores all glyphs in a line in left to right order.
*
* It can be used for rendering but no text processing (like line breaking)
* should be done!
* Glyphs are stored in runs with the same format.
*/
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_; }
void add_run(format_run_ptr);
private:
std::vector<format_run_ptr> runs_;
};
class text_layout
{
public:
text_layout(face_manager_freetype & font_manager);
inline void add_text(UnicodeString const& str, char_properties const& format)
inline void add_text(UnicodeString const& str, char_properties_ptr format)
{
itemizer.add_text(str, format);
}
@ -48,6 +83,7 @@ public:
private:
text_itemizer itemizer;
std::list<text_line> lines_;
std::vector<glyph_info> glyphs_;
face_manager_freetype &font_manager_;
};

View file

@ -44,7 +44,7 @@ public:
text_shaping(FT_Face face);
~text_shaping();
uint32_t process_text(UnicodeString const& text, bool rtl, UScriptCode script);
uint32_t process_text(UnicodeString const& text, unsigned start, unsigned end, bool rtl, UScriptCode script);
hb_buffer_t *get_buffer() { return buffer_; }
protected:

View file

@ -23,6 +23,7 @@
#define TEXT_PROPERTIES_HPP
// mapnik
#include <mapnik/text/char_properties_ptr.hpp>
#include <mapnik/color.hpp>
#include <mapnik/font_set.hpp>
#include <mapnik/enumeration.hpp>
@ -71,8 +72,6 @@ struct char_properties
color halo_fill;
double halo_radius;
};
typedef boost::shared_ptr<char_properties> char_properties_ptr;
enum label_placement_enum
{

View file

@ -23,10 +23,11 @@
// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/text/char_properties_ptr.hpp>
#include <mapnik/graphics.hpp>
#include <mapnik/grid/grid.hpp>
#include <mapnik/text_path.hpp>
#include <mapnik/text_properties.hpp>
// boost
#include <boost/algorithm/string.hpp>

View file

@ -67,6 +67,7 @@ void font_face::glyph_dimensions(glyph_info &glyph)
glyph.ymin = glyph_bbox.yMin; //TODO: Which data format? 26.6, integer?
glyph.ymax = glyph_bbox.yMax; //TODO: Which data format? 26.6, integer?
glyph.line_height = face_->size->metrics.height/64.0;
glyph.valid = true;
//TODO: dimension_cache_.insert(std::pair<unsigned, char_info>(c, dim));
}

View file

@ -21,6 +21,7 @@
*****************************************************************************/
#include <mapnik/text/layout.hpp>
#include <mapnik/text/shaping.hpp>
#include <mapnik/text_properties.hpp>
//stl
#include <iostream>
@ -48,18 +49,19 @@ void text_layout::break_lines()
void text_layout::shape_text()
{
glyphs_.reserve(itemizer.get_text().length()); //Preallocate memory
UnicodeString const& text = itemizer.get_text();
glyphs_.reserve(text.length()); //Preallocate memory
uint32_t offset = 0; //in utf16 code points
std::list<text_item> const& list = itemizer.itemize();
std::list<text_item>::const_iterator itr = list.begin(), end = list.end();
for (;itr!=end; itr++)
{
face_set_ptr face_set = font_manager_.get_face_set(itr->format.face_name, itr->format.fontset);
face_set->set_character_sizes(itr->format.text_size);
face_set_ptr face_set = font_manager_.get_face_set(itr->format->face_name, itr->format->fontset);
face_set->set_character_sizes(itr->format->text_size);
face_ptr face = *(face_set->begin()); //TODO: Implement font sets correctly
text_shaping shaper(face->get_face()); //TODO: Make this more efficient by caching this object in font_face
uint32_t chars = shaper.process_text(itr->str, itr->rtl == UBIDI_DEFAULT_RTL, itr->script);
uint32_t chars = shaper.process_text(text, itr->start, itr->end, itr->rtl == UBIDI_DEFAULT_RTL, itr->script);
hb_buffer_t *buffer = shaper.get_buffer();
unsigned num_glyphs = hb_buffer_get_length(buffer);
@ -68,7 +70,7 @@ void text_layout::shape_text()
hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, NULL);
std::string s;
std::cout << "Processing item '" << itr->str.toUTF8String(s) << "' (" << uscript_getName(itr->script) << "," << itr->str.length() << "," << num_glyphs << "," << itr->rtl << ")\n";
std::cout << "Processing item '" << text.tempSubStringBetween(itr->start, itr->end).toUTF8String(s) << "' (" << uscript_getName(itr->script) << "," << itr->end - itr->start << "," << num_glyphs << "," << itr->rtl << ")\n";
for (unsigned i=0; i<num_glyphs; i++)
{

View file

@ -52,14 +52,14 @@ text_shaping::~text_shaping()
hb_font_destroy(font_);
}
uint32_t text_shaping::process_text(UnicodeString const& text, bool rtl, UScriptCode script)
uint32_t text_shaping::process_text(UnicodeString const& text, unsigned start, unsigned end, bool rtl, UScriptCode script)
{
if (!font_) return 0;
hb_buffer_reset(buffer_);
uint32_t length = text.length();
hb_buffer_add_utf16(buffer_, text.getBuffer(), length, 0, -1);
hb_buffer_add_utf16(buffer_, text.getBuffer(), length, start, end-start);
hb_buffer_set_direction(buffer_, rtl?HB_DIRECTION_RTL:HB_DIRECTION_LTR);
hb_buffer_set_script(buffer_, hb_icu_script_to_script(script));
#if 0