Remove old code.

This commit is contained in:
Hermann Kraus 2012-07-01 02:47:39 +02:00
parent ead99b1411
commit e537b0e8dd
13 changed files with 112 additions and 222 deletions

View file

@ -432,15 +432,6 @@ void export_text_placement()
;
register_ptr_to_python<boost::shared_ptr<text_placement_info> >();
#if 0
class_<processed_text,
boost::shared_ptr<processed_text>,
boost::noncopyable>
("ProcessedText", no_init)
.def("push_back", &processed_text::push_back)
.def("clear", &processed_text::clear)
;
#endif
class_<expression_set,
boost::shared_ptr<expression_set>,

View file

@ -30,7 +30,6 @@
#include <mapnik/ctrans.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/font_set.hpp>
#include <mapnik/char_info.hpp>
#include <mapnik/pixel_position.hpp>
#include <mapnik/image_compositing.hpp>
#include <mapnik/text/face.hpp>
@ -49,7 +48,6 @@ extern "C"
#include <boost/make_shared.hpp>
#include <boost/utility.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/foreach.hpp>
#ifdef MAPNIK_THREADSAFE
#include <boost/thread/mutex.hpp>
#endif
@ -66,97 +64,6 @@ extern "C"
namespace mapnik
{
class font_face;
class text_path;
class string_info;
class MAPNIK_DECL font_glyph
{
public:
font_glyph() : face(), index(0) {}
font_glyph(face_ptr face, unsigned index)
: face(face), index(index) {}
face_ptr get_face() const
{
return face;
}
unsigned get_index() const
{
return index;
}
face_ptr face;
unsigned index;
};
typedef boost::shared_ptr<font_glyph> glyph_ptr;
class MAPNIK_DECL font_face_set : private boost::noncopyable
{
public:
typedef std::vector<face_ptr>::iterator iterator;
font_face_set(void)
: faces_(),
dimension_cache_() {}
void add(face_ptr face)
{
faces_.push_back(face);
dimension_cache_.clear(); //Make sure we don't use old cached data
}
unsigned size() const
{
return faces_.size();
}
glyph_ptr get_glyph(unsigned c) const
{
BOOST_FOREACH ( face_ptr const& face, faces_)
{
FT_UInt g = face->get_char(c);
if (g) return boost::make_shared<font_glyph>(face, g);
}
// Final fallback to empty square if nothing better in any font
return boost::make_shared<font_glyph>(*faces_.begin(), 0);
}
iterator begin()
{
return faces_.begin();
}
iterator end()
{
return faces_.end();
}
char_info character_dimensions(const unsigned c);
void get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format);
void set_pixel_sizes(unsigned size)
{
BOOST_FOREACH ( face_ptr const& face, faces_)
{
face->set_pixel_sizes(size);
}
}
void set_character_sizes(float size)
{
BOOST_FOREACH ( face_ptr const& face, faces_)
{
face->set_character_sizes(size);
}
}
private:
std::vector<face_ptr> faces_;
std::map<unsigned, char_info> dimension_cache_;
};
// FT_Stroker wrapper
class stroker : boost::noncopyable
@ -164,35 +71,17 @@ class stroker : boost::noncopyable
public:
explicit stroker(FT_Stroker s)
: s_(s) {}
~stroker();
void init(double radius)
{
FT_Stroker_Set(s_, (FT_Fixed) (radius * (1<<6)),
FT_STROKER_LINECAP_ROUND,
FT_STROKER_LINEJOIN_ROUND,
0);
}
void init(double radius);
FT_Stroker const& get() const
{
return s_;
}
~stroker()
{
MAPNIK_LOG_DEBUG(font_engine_freetype) << "stroker: Destroy stroker=" << s_;
FT_Stroker_Done(s_);
}
FT_Stroker const& get() const { return s_; }
private:
FT_Stroker s_;
};
typedef boost::shared_ptr<font_face_set> face_set_ptr;
typedef boost::shared_ptr<stroker> stroker_ptr;
class MAPNIK_DECL freetype_engine
{
public:
@ -210,7 +99,7 @@ private:
#ifdef MAPNIK_THREADSAFE
static boost::mutex mutex_;
#endif
static std::map<std::string,std::pair<int,std::string> > name2file_;
static std::map<std::string, std::pair<int,std::string> > name2file_;
};
template <typename T>
@ -316,50 +205,12 @@ struct text_renderer : private boost::noncopyable
typedef T pixmap_type;
text_renderer (pixmap_type & pixmap, face_manager<freetype_engine> &font_manager_, stroker & s, composite_mode_e comp_op = src_over);
box2d<double> prepare_glyphs(text_path *path);
void render(pixel_position pos);
void render_id(int feature_id, pixel_position pos, double min_radius=1.0);
private:
void render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity)
{
int x_max=x+bitmap->width;
int y_max=y+bitmap->rows;
int i,p,j,q;
for (i=x,p=0;i<x_max;++i,++p)
{
for (j=y,q=0;j<y_max;++j,++q)
{
int gray=bitmap->buffer[q*bitmap->width+p];
if (gray)
{
pixmap_.blendPixel2(i, j, rgba, gray, opacity);
}
}
}
}
void render_bitmap_id(FT_Bitmap *bitmap,int feature_id,int x,int y)
{
int x_max=x+bitmap->width;
int y_max=y+bitmap->rows;
int i,p,j,q;
for (i=x,p=0;i<x_max;++i,++p)
{
for (j=y,q=0;j<y_max;++j,++q)
{
int gray=bitmap->buffer[q*bitmap->width+p];
if (gray)
{
pixmap_.setPixel(i,j,feature_id);
//pixmap_.blendPixel2(i,j,rgba,gray,opacity_);
}
}
}
}
void render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity);
void render_bitmap_id(FT_Bitmap *bitmap,int feature_id,int x,int y);
pixmap_type & pixmap_;
face_manager<freetype_engine> &font_manager_;

View file

@ -24,6 +24,7 @@
//mapnik
#include <mapnik/text/glyph_info.hpp>
#include <mapnik/config.hpp>
// freetype2
extern "C"
@ -39,6 +40,7 @@ extern "C"
//stl
#include <map>
#include <string>
#include <vector>
namespace mapnik
{
@ -92,6 +94,26 @@ private:
std::map<glyph_index_t, glyph_info> dimension_cache_;
};
class MAPNIK_DECL font_face_set : private boost::noncopyable
{
public:
typedef std::vector<face_ptr>::iterator iterator;
font_face_set(void) : faces_(){}
void add(face_ptr face);
void set_character_sizes(float size);
unsigned size() const { return faces_.size(); }
iterator begin() { return faces_.begin(); }
iterator end() { return faces_.end(); }
private:
std::vector<face_ptr> faces_;
};
typedef boost::shared_ptr<font_face_set> face_set_ptr;
} //ns mapnik
#endif // FACE_HPP

View file

@ -66,7 +66,6 @@ void agg_renderer<T>::process(shield_symbolizer const& sym,
sym.get_opacity(),
sym.comp_op());
ren.prepare_glyphs(&(placements[ii]));
ren.render(placements[ii].center);
}
}

View file

@ -46,7 +46,6 @@ void agg_renderer<T>::process(text_symbolizer const& sym,
placements_type &placements = helper.placements();
for (unsigned int ii = 0; ii < placements.size(); ++ii)
{
ren.prepare_glyphs(&(placements[ii]));
ren.render(placements[ii].center);
}
}

View file

@ -166,7 +166,6 @@ source = Split(
json/feature_collection_parser.cpp
json/geojson_generator.cpp
markers_placement.cpp
processed_text.cpp
formatting/base.cpp
formatting/expression.cpp
formatting/list.cpp

View file

@ -685,11 +685,11 @@ public:
context_->glyph_path(glyphs);
}
void add_text(text_path & path,
cairo_face_manager & manager,
face_manager<freetype_engine> &font_manager)
{
#if 0
double sx = path.center.x;
double sy = path.center.y;
@ -732,6 +732,9 @@ public:
show_glyph(glyph->get_index(), sx + x, sy - y);
}
}
#else
#warning "Text rendering in Cairo disabled!"
#endif
}

View file

@ -220,54 +220,7 @@ stroker_ptr freetype_engine::create_stroker()
return stroker_ptr();
}
char_info font_face_set::character_dimensions(const unsigned c)
{
//Check if char is already in cache
std::map<unsigned, char_info>::const_iterator itr;
itr = dimension_cache_.find(c);
if (itr != dimension_cache_.end()) {
return itr->second;
}
FT_Matrix matrix;
FT_Vector pen;
FT_Error error;
pen.x = 0;
pen.y = 0;
FT_BBox glyph_bbox;
FT_Glyph image;
glyph_ptr glyph = get_glyph(c);
FT_Face face = glyph->get_face()->get_face();
matrix.xx = (FT_Fixed)( 1 * 0x10000L );
matrix.xy = (FT_Fixed)( 0 * 0x10000L );
matrix.yx = (FT_Fixed)( 0 * 0x10000L );
matrix.yy = (FT_Fixed)( 1 * 0x10000L );
FT_Set_Transform(face, &matrix, &pen);
error = FT_Load_Glyph (face, glyph->get_index(), FT_LOAD_NO_HINTING);
if ( error )
return char_info();
error = FT_Get_Glyph(face->glyph, &image);
if ( error )
return char_info();
FT_Glyph_Get_CBox(image, ft_glyph_bbox_pixels, &glyph_bbox);
FT_Done_Glyph(image);
unsigned tempx = face->glyph->advance.x >> 6;
char_info dim(c, tempx, glyph_bbox.yMax, glyph_bbox.yMin, face->size->metrics.height/64.0 /* >> 6 */);
dimension_cache_.insert(std::pair<unsigned, char_info>(c, dim));
return dim;
}
#if 0
void font_face_set::get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format)
{
double avg_height = character_dimensions('X').height();
@ -313,6 +266,7 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust
ubidi_close(bidi);
}
#endif
template <typename T>
text_renderer<T>::text_renderer (pixmap_type & pixmap, face_manager<freetype_engine> &font_manager_, stroker & s, composite_mode_e comp_op)
@ -321,6 +275,7 @@ text_renderer<T>::text_renderer (pixmap_type & pixmap, face_manager<freetype_eng
stroker_(s),
comp_op_(comp_op) {}
#if 0
template <typename T>
box2d<double> text_renderer<T>::prepare_glyphs(text_path *path)
{
@ -398,6 +353,7 @@ box2d<double> text_renderer<T>::prepare_glyphs(text_path *path)
return box2d<double>(bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax);
}
#endif
template <typename T>
void composite_bitmap(T & pixmap, FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity, composite_mode_e comp_op)
@ -520,16 +476,70 @@ void text_renderer<T>::render_id(int feature_id, pixel_position pos, double min_
}
}
template <typename T>
void text_renderer<T>::render_bitmap_id(FT_Bitmap *bitmap,int feature_id,int x,int y)
{
int x_max=x+bitmap->width;
int y_max=y+bitmap->rows;
int i,p,j,q;
for (i=x,p=0;i<x_max;++i,++p)
{
for (j=y,q=0;j<y_max;++j,++q)
{
int gray=bitmap->buffer[q*bitmap->width+p];
if (gray)
{
pixmap_.setPixel(i,j,feature_id);
//pixmap_.blendPixel2(i,j,rgba,gray,opacity_);
}
}
}
}
template <typename T>
void text_renderer<T>::render_bitmap(FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity)
{
int x_max=x+bitmap->width;
int y_max=y+bitmap->rows;
int i,p,j,q;
for (i=x,p=0;i<x_max;++i,++p)
{
for (j=y,q=0;j<y_max;++j,++q)
{
int gray=bitmap->buffer[q*bitmap->width+p];
if (gray)
{
pixmap_.blendPixel2(i, j, rgba, gray, opacity);
}
}
}
}
#ifdef MAPNIK_THREADSAFE
boost::mutex freetype_engine::mutex_;
#endif
std::map<std::string,std::pair<int,std::string> > freetype_engine::name2file_;
template void text_renderer<image_32>::render(pixel_position);
template text_renderer<image_32>::text_renderer(image_32&, face_manager<freetype_engine>&, stroker&, composite_mode_e);
template box2d<double>text_renderer<image_32>::prepare_glyphs(text_path*);
template void text_renderer<grid>::render_id(int, pixel_position, double );
template text_renderer<grid>::text_renderer(grid&, face_manager<freetype_engine>&, stroker&, composite_mode_e);
template box2d<double>text_renderer<grid>::prepare_glyphs(text_path*);
void stroker::init(double radius)
{
FT_Stroker_Set(s_, (FT_Fixed) (radius * (1<<6)),
FT_STROKER_LINECAP_ROUND,
FT_STROKER_LINEJOIN_ROUND,
0);
}
stroker::~stroker()
{
MAPNIK_LOG_DEBUG(font_engine_freetype) << "stroker: Destroy stroker=" << s_;
FT_Stroker_Done(s_);
}
}

View file

@ -64,7 +64,6 @@ void grid_renderer<T>::process(shield_symbolizer const& sym,
helper.get_marker(), helper.get_image_transform(),
sym.get_opacity());
ren.prepare_glyphs(&(placements[ii]));
ren.render_id(feature.id(), placements[ii].center, 2);
}
}

View file

@ -48,7 +48,6 @@ void grid_renderer<T>::process(text_symbolizer const& sym,
placements_type &placements = helper.placements();
for (unsigned int ii = 0; ii < placements.size(); ++ii)
{
ren.prepare_glyphs(&(placements[ii]));
ren.render_id(feature.id(), placements[ii].center, 2);
}
}

View file

@ -56,6 +56,7 @@ void processed_text::clear()
string_info &processed_text::get_string_info()
{
#if 0
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();
@ -79,6 +80,7 @@ string_info &processed_text::get_string_info()
info_.add_text(itr->str);
}
return info_;
#endif
}
} //ns mapnik

View file

@ -22,6 +22,8 @@
#include <mapnik/text/face.hpp>
#include <mapnik/debug.hpp>
#include <boost/foreach.hpp>
extern "C"
{
#include FT_GLYPH_H
@ -78,4 +80,19 @@ font_face::~font_face()
FT_Done_Face(face_);
}
/******************************************************************************/
void font_face_set::add(face_ptr face)
{
faces_.push_back(face);
}
void font_face_set::set_character_sizes(float size)
{
BOOST_FOREACH ( face_ptr const& face, faces_)
{
face->set_character_sizes(size);
}
}
}//ns mapnik

View file

@ -33,7 +33,6 @@
* string_info
* text_path
* char_info
* font_glyph
*/
namespace mapnik