Use shared pointer to track char_properties.

Store positions instead of strings in text_item.
This commit is contained in:
Hermann Kraus 2012-07-01 22:35:20 +02:00
parent e537b0e8dd
commit 7d241c5353
4 changed files with 13 additions and 9 deletions

View file

@ -41,7 +41,6 @@ struct glyph_info
glyph_index_t glyph_index;
face_ptr face;
unsigned char_index; //Position in the string of all characters i.e. before itemizing
char_properties *format;
double width;
double ymin;

View file

@ -39,12 +39,13 @@ namespace mapnik
struct text_item
{
UnicodeString str;
unsigned start; //First char
unsigned end; //First char after this item
UScriptCode script;
char_properties format;
char_properties_ptr format;
UBiDiDirection rtl;
text_item(UnicodeString const& str) :
str(str), script(), format(), rtl(UBIDI_LTR)
text_item() :
start(0), end(0), script(), format(), rtl(UBIDI_LTR)
{
}
@ -59,7 +60,7 @@ class text_itemizer
{
public:
text_itemizer();
void add_text(UnicodeString str, char_properties const& format);
void add_text(UnicodeString str, char_properties_ptr format);
std::list<text_item> const& itemize();
void clear();
UnicodeString const& get_text() { return text; }
@ -70,7 +71,7 @@ private:
unsigned limit;
T data;
};
typedef run<char_properties> format_run_t;
typedef run<char_properties_ptr> format_run_t;
typedef run<UBiDiDirection> direction_run_t;
typedef run<UScriptCode> script_run_t;
UnicodeString text;

View file

@ -34,6 +34,7 @@
// boost
#include <boost/property_tree/ptree.hpp>
#include <boost/shared_ptr.hpp>
namespace mapnik
{
@ -70,6 +71,7 @@ struct char_properties
color halo_fill;
double halo_radius;
};
typedef boost::shared_ptr<char_properties> char_properties_ptr;
enum label_placement_enum

View file

@ -35,7 +35,7 @@ text_itemizer::text_itemizer() : text(), format_runs(), direction_runs(), script
}
void text_itemizer::add_text(UnicodeString str, char_properties const& format)
void text_itemizer::add_text(UnicodeString str, char_properties_ptr format)
{
text += str;
format_runs.push_back(format_run_t(format, text.length()));
@ -112,7 +112,9 @@ void text_itemizer::create_item_list()
while (position < text.length())
{
unsigned next_position = std::min(script_itr->limit, std::min(dir_itr->limit, format_itr->limit));
text_item item(text.tempSubStringBetween(position, next_position));
text_item item;
item.start = position;
item.end = next_position;
item.format = format_itr->data;
item.script = script_itr->data;
item.rtl = dir_itr->data;