Use font manager and char properties in text engine.
This commit is contained in:
parent
1527fed59c
commit
31fd5647f2
3 changed files with 8 additions and 81 deletions
|
@ -343,43 +343,11 @@ struct text_renderer : private boost::noncopyable
|
||||||
typedef boost::ptr_vector<glyph_t> glyphs_t;
|
typedef boost::ptr_vector<glyph_t> glyphs_t;
|
||||||
typedef T pixmap_type;
|
typedef T pixmap_type;
|
||||||
|
|
||||||
text_renderer (pixmap_type & pixmap, face_set_ptr faces, stroker & s);
|
|
||||||
text_renderer (pixmap_type & pixmap, face_manager<freetype_engine> &font_manager_, stroker & s);
|
text_renderer (pixmap_type & pixmap, face_manager<freetype_engine> &font_manager_, stroker & s);
|
||||||
box2d<double> prepare_glyphs(text_path *path);
|
box2d<double> prepare_glyphs(text_path *path);
|
||||||
void render(double x0, double y0);
|
void render(double x0, double y0);
|
||||||
void render_id(int feature_id,double x0, double y0, double min_radius=1.0);
|
void render_id(int feature_id,double x0, double y0, double min_radius=1.0);
|
||||||
|
|
||||||
|
|
||||||
void set_pixel_size(unsigned size)
|
|
||||||
{
|
|
||||||
faces_->set_pixel_sizes(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_character_size(float size)
|
|
||||||
{
|
|
||||||
faces_->set_character_sizes(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_fill(mapnik::color const& fill)
|
|
||||||
{
|
|
||||||
fill_=fill;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_halo_fill(mapnik::color const& halo)
|
|
||||||
{
|
|
||||||
halo_fill_=halo;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_halo_radius( double radius=1.0)
|
|
||||||
{
|
|
||||||
halo_radius_=radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_opacity( double opacity=1.0)
|
|
||||||
{
|
|
||||||
opacity_=opacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity)
|
void render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity)
|
||||||
{
|
{
|
||||||
|
@ -421,14 +389,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
pixmap_type & pixmap_;
|
pixmap_type & pixmap_;
|
||||||
face_set_ptr faces_;
|
face_manager<freetype_engine> &font_manager_;
|
||||||
// face_manager<freetype_engine> &font_manager_;
|
|
||||||
stroker & stroker_;
|
stroker & stroker_;
|
||||||
color fill_;
|
|
||||||
color halo_fill_;
|
|
||||||
double halo_radius_;
|
|
||||||
glyphs_t glyphs_;
|
glyphs_t glyphs_;
|
||||||
double opacity_;
|
|
||||||
};
|
};
|
||||||
typedef face_manager<freetype_engine> face_manager_freetype;
|
typedef face_manager<freetype_engine> face_manager_freetype;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,11 @@ protected:
|
||||||
typedef std::vector<char_info> characters_t;
|
typedef std::vector<char_info> characters_t;
|
||||||
characters_t characters_;
|
characters_t characters_;
|
||||||
UnicodeString text_;
|
UnicodeString text_;
|
||||||
double width_;
|
|
||||||
double height_;
|
|
||||||
bool is_rtl;
|
bool is_rtl;
|
||||||
public:
|
public:
|
||||||
string_info(UnicodeString const& text)
|
string_info(UnicodeString const& text)
|
||||||
: characters_(),
|
: characters_(),
|
||||||
text_(text),
|
text_(text),
|
||||||
width_(0),
|
|
||||||
height_(0),
|
|
||||||
is_rtl(false)
|
is_rtl(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -77,11 +73,6 @@ public:
|
||||||
text_ += text;
|
text_ += text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_info(int c, double width, double height)
|
|
||||||
{
|
|
||||||
characters_.push_back(char_info(c, width, height, 0, height)); //WARNING: Do not use. Only to keep old code compilable.
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned num_characters() const
|
unsigned num_characters() const
|
||||||
{
|
{
|
||||||
return characters_.size();
|
return characters_.size();
|
||||||
|
@ -107,17 +98,6 @@ public:
|
||||||
return at(i);
|
return at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_dimensions(double width, double height)
|
|
||||||
{
|
|
||||||
width_ = width;
|
|
||||||
height_ = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<double, double> get_dimensions() const
|
|
||||||
{
|
|
||||||
return std::pair<double, double>(width_, height_);
|
|
||||||
}
|
|
||||||
|
|
||||||
UnicodeString const& get_string() const
|
UnicodeString const& get_string() const
|
||||||
{
|
{
|
||||||
return text_;
|
return text_;
|
||||||
|
|
|
@ -241,11 +241,10 @@ char_info font_face_set::character_dimensions(const unsigned c)
|
||||||
return dim;
|
return dim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void font_face_set::get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format)
|
void font_face_set::get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format)
|
||||||
{
|
{
|
||||||
double avg_height = character_dimensions('X').height();
|
double avg_height = character_dimensions('X').height();
|
||||||
unsigned width = 0;
|
|
||||||
unsigned height = 0;
|
|
||||||
UErrorCode err = U_ZERO_ERROR;
|
UErrorCode err = U_ZERO_ERROR;
|
||||||
UnicodeString reordered;
|
UnicodeString reordered;
|
||||||
UnicodeString shaped;
|
UnicodeString shaped;
|
||||||
|
@ -272,8 +271,6 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust
|
||||||
for (iter.setToStart(); iter.hasNext();) {
|
for (iter.setToStart(); iter.hasNext();) {
|
||||||
UChar ch = iter.nextPostInc();
|
UChar ch = iter.nextPostInc();
|
||||||
char_info char_dim = character_dimensions(ch);
|
char_info char_dim = character_dimensions(ch);
|
||||||
width += char_dim.width;
|
|
||||||
height = (char_dim.height() > height) ? char_dim.height() : height;
|
|
||||||
char_dim.format = format;
|
char_dim.format = format;
|
||||||
char_dim.avg_height = avg_height;
|
char_dim.avg_height = avg_height;
|
||||||
info.add_info(char_dim);
|
info.add_info(char_dim);
|
||||||
|
@ -289,23 +286,8 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ubidi_close(bidi);
|
ubidi_close(bidi);
|
||||||
info.set_dimensions(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
text_renderer<T>::text_renderer (pixmap_type & pixmap, face_set_ptr faces, stroker & s)
|
|
||||||
: pixmap_(pixmap),
|
|
||||||
faces_(faces),
|
|
||||||
stroker_(s),
|
|
||||||
fill_(0,0,0),
|
|
||||||
halo_fill_(255,255,255),
|
|
||||||
halo_radius_(0.0),
|
|
||||||
opacity_(1.0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
text_renderer<T>::text_renderer (pixmap_type & pixmap, face_manager<freetype_engine> &font_manager_, stroker & s)
|
text_renderer<T>::text_renderer (pixmap_type & pixmap, face_manager<freetype_engine> &font_manager_, stroker & s)
|
||||||
: pixmap_(pixmap),
|
: pixmap_(pixmap),
|
||||||
|
@ -314,7 +296,6 @@ text_renderer<T>::text_renderer (pixmap_type & pixmap, face_manager<freetype_eng
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<double> text_renderer<T>::prepare_glyphs(text_path *path)
|
box2d<double> text_renderer<T>::prepare_glyphs(text_path *path)
|
||||||
|
@ -350,7 +331,10 @@ box2d<double> text_renderer<T>::prepare_glyphs(text_path *path)
|
||||||
pen.x = int(x * 64);
|
pen.x = int(x * 64);
|
||||||
pen.y = int(y * 64);
|
pen.y = int(y * 64);
|
||||||
|
|
||||||
glyph_ptr glyph = faces_->get_glyph(unsigned(c));
|
face_set_ptr faces = font_manager_.get_face_set(properties->face_name, properties->fontset);
|
||||||
|
faces->set_pixel_sizes(properties->text_size); //TODO: Has to work with floats!
|
||||||
|
|
||||||
|
glyph_ptr glyph = faces->get_glyph(unsigned(c));
|
||||||
FT_Face face = glyph->get_face()->get_face();
|
FT_Face face = glyph->get_face()->get_face();
|
||||||
|
|
||||||
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
|
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
|
||||||
|
@ -490,10 +474,10 @@ boost::mutex freetype_engine::mutex_;
|
||||||
#endif
|
#endif
|
||||||
std::map<std::string,std::pair<int,std::string> > freetype_engine::name2file_;
|
std::map<std::string,std::pair<int,std::string> > freetype_engine::name2file_;
|
||||||
template void text_renderer<image_32>::render(double, double);
|
template void text_renderer<image_32>::render(double, double);
|
||||||
template text_renderer<image_32>::text_renderer(image_32&, face_set_ptr, stroker&);
|
template text_renderer<image_32>::text_renderer(image_32&, face_manager<freetype_engine>&, stroker&);
|
||||||
template box2d<double>text_renderer<image_32>::prepare_glyphs(text_path*);
|
template box2d<double>text_renderer<image_32>::prepare_glyphs(text_path*);
|
||||||
|
|
||||||
template void text_renderer<grid>::render_id(int, double, double, double);
|
template void text_renderer<grid>::render_id(int, double, double, double);
|
||||||
template text_renderer<grid>::text_renderer(grid&, face_set_ptr, stroker&);
|
template text_renderer<grid>::text_renderer(grid&, face_manager<freetype_engine>&, stroker&);
|
||||||
template box2d<double>text_renderer<grid>::prepare_glyphs(text_path*);
|
template box2d<double>text_renderer<grid>::prepare_glyphs(text_path*);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue