reverting back to 700

This commit is contained in:
Artem Pavlenko 2008-06-29 10:56:29 +00:00
parent 3275cf9ce6
commit c7cbfa5c82
7 changed files with 147 additions and 275 deletions

View file

@ -30,7 +30,6 @@
#include <mapnik/ctrans.hpp> #include <mapnik/ctrans.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/text_path.hpp> #include <mapnik/text_path.hpp>
#include <mapnik/font_set.hpp>
// freetype2 // freetype2
extern "C" extern "C"
@ -62,7 +61,9 @@ namespace mapnik
class font_face : boost::noncopyable class font_face : boost::noncopyable
{ {
public: public:
font_face(FT_Face face) typedef std::pair<unsigned,unsigned> dimension_t;
font_face(FT_Face face)
: face_(face) {} : face_(face) {}
std::string family_name() const std::string family_name() const
@ -103,11 +104,122 @@ namespace mapnik
return false; return false;
} }
dimension_t character_dimensions(const unsigned c)
{
FT_Matrix matrix;
FT_Vector pen;
FT_Error error;
FT_GlyphSlot slot = face_->glyph;
pen.x = 0;
pen.y = 0;
FT_BBox glyph_bbox;
FT_Glyph image;
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);
FT_UInt glyph_index = FT_Get_Char_Index( face_, c);
error = FT_Load_Glyph (face_,glyph_index,FT_LOAD_NO_HINTING);
if ( error )
return dimension_t(0, 0);
error = FT_Get_Glyph( face_->glyph, &image);
if ( error )
return dimension_t(0, 0);
FT_Glyph_Get_CBox(image,ft_glyph_bbox_pixels, &glyph_bbox);
FT_Done_Glyph(image);
return dimension_t(slot->advance.x >> 6, glyph_bbox.yMax - glyph_bbox.yMin);
}
void get_string_info(string_info & info)
{
unsigned width = 0;
unsigned height = 0;
UErrorCode err = U_ZERO_ERROR;
UnicodeString const& ustr = info.get_string();
const UChar * text = ustr.getBuffer();
UBiDi * bidi = ubidi_openSized(ustr.length(),0,&err);
if (U_SUCCESS(err))
{
ubidi_setPara(bidi,text,ustr.length(), UBIDI_DEFAULT_LTR,0,&err);
if (U_SUCCESS(err))
{
int32_t count = ubidi_countRuns(bidi,&err);
int32_t logicalStart;
int32_t length;
for (int32_t i=0; i< count;++i)
{
if (UBIDI_LTR == ubidi_getVisualRun(bidi,i,&logicalStart,&length))
{
do {
UChar ch = text[logicalStart++];
dimension_t char_dim = character_dimensions(ch);
info.add_info(ch, char_dim.first, char_dim.second);
width += char_dim.first;
height = char_dim.second > height ? char_dim.second : height;
} while (--length > 0);
}
else
{
logicalStart += length;
int32_t j=0,i=length;
UnicodeString arabic;
UChar * buf = arabic.getBuffer(length);
do {
UChar ch = text[--logicalStart];
buf[j++] = ch;
} while (--i > 0);
arabic.releaseBuffer(length);
if ( *arabic.getBuffer() >= 0x0600 && *arabic.getBuffer() <= 0x06ff)
{
UnicodeString shaped;
u_shapeArabic(arabic.getBuffer(),arabic.length(),shaped.getBuffer(arabic.length()),arabic.length(),
U_SHAPE_LETTERS_SHAPE|U_SHAPE_LENGTH_FIXED_SPACES_NEAR|
U_SHAPE_TEXT_DIRECTION_VISUAL_LTR
,&err);
shaped.releaseBuffer(arabic.length());
if (U_SUCCESS(err))
{
for (int j=0;j<shaped.length();++j)
{
dimension_t char_dim = character_dimensions(shaped[j]);
info.add_info(shaped[j], char_dim.first, char_dim.second);
width += char_dim.first;
height = char_dim.second > height ? char_dim.second : height;
}
}
}
}
}
}
ubidi_close(bidi);
}
info.set_dimensions(width, height);
}
~font_face() ~font_face()
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "~font_face: Clean up face \"" << family_name() std::clog << "clean up face:" << family_name()<<":" << style_name() << std::endl;
<< " " << style_name() << "\"" << std::endl;
#endif #endif
FT_Done_Face(face_); FT_Done_Face(face_);
} }
@ -116,9 +228,8 @@ namespace mapnik
FT_Face face_; FT_Face face_;
}; };
typedef boost::shared_ptr<font_face> face_ptr; typedef boost::shared_ptr<font_face> face_ptr;
class MAPNIK_DECL freetype_engine // : public mapnik::singleton<freetype_engine,mapnik::CreateStatic>,
class MAPNIK_DECL freetype_engine // : public mapnik::singleton<freetype_engine,mapnik::CreateStatic>,
// private boost::noncopyable // private boost::noncopyable
{ {
// friend class mapnik::CreateStatic<freetype_engine>; // friend class mapnik::CreateStatic<freetype_engine>;
@ -170,8 +281,6 @@ namespace mapnik
template <typename T> template <typename T>
struct text_renderer : private boost::noncopyable struct text_renderer : private boost::noncopyable
{ {
typedef std::pair<unsigned,unsigned> dimension_t;
struct glyph_t : boost::noncopyable struct glyph_t : boost::noncopyable
{ {
FT_Glyph image; FT_Glyph image;
@ -182,159 +291,16 @@ namespace mapnik
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, std::vector<face_ptr> faces) text_renderer (pixmap_type & pixmap, face_ptr face)
: pixmap_(pixmap), : pixmap_(pixmap),
faces_(faces), face_(face),
fill_(0,0,0), fill_(0,0,0),
halo_fill_(255,255,255), halo_fill_(255,255,255),
halo_radius_(0) {} halo_radius_(0) {}
dimension_t character_dimensions(const unsigned c)
{
FT_Matrix matrix;
FT_Vector pen;
FT_Error error;
pen.x = 0;
pen.y = 0;
FT_BBox glyph_bbox;
FT_Glyph image;
FT_Face face = (*faces_.begin())->get_face();
FT_UInt glyph_index = FT_Get_Char_Index(face, c);
// If there's no glyph_index we loop through the remaining fonts
// in the fontset looking for one.
if (!glyph_index) {
std::vector<face_ptr>::iterator itr = faces_.begin();
std::vector<face_ptr>::iterator end = faces_.end();
++itr; // Skip the first one, we already tried it.
for (; itr != end; ++itr)
{
FT_Face f = (*itr)->get_face();
glyph_index = FT_Get_Char_Index(f, c);
if (glyph_index) {
face = f;
break;
}
}
}
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_index, FT_LOAD_NO_HINTING);
if ( error )
return dimension_t(0, 0);
error = FT_Get_Glyph(face->glyph, &image);
if ( error )
return dimension_t(0, 0);
FT_Glyph_Get_CBox(image, ft_glyph_bbox_pixels, &glyph_bbox);
FT_Done_Glyph(image);
unsigned tempx = face->glyph->advance.x >> 6;
unsigned tempy = glyph_bbox.yMax - glyph_bbox.yMin;
//std::clog << "glyph: " << glyph_index << " x: " << tempx << " y: " << tempy << std::endl;
return dimension_t(tempx, tempy);
}
void get_string_info(string_info & info)
{
unsigned width = 0;
unsigned height = 0;
UErrorCode err = U_ZERO_ERROR;
UnicodeString const& ustr = info.get_string();
const UChar * text = ustr.getBuffer();
UBiDi * bidi = ubidi_openSized(ustr.length(),0,&err);
if (U_SUCCESS(err))
{
ubidi_setPara(bidi,text,ustr.length(), UBIDI_DEFAULT_LTR,0,&err);
if (U_SUCCESS(err))
{
int32_t count = ubidi_countRuns(bidi,&err);
int32_t logicalStart;
int32_t length;
for (int32_t i=0; i< count;++i)
{
if (UBIDI_LTR == ubidi_getVisualRun(bidi,i,&logicalStart,&length))
{
do {
UChar ch = text[logicalStart++];
dimension_t char_dim = character_dimensions(ch);
info.add_info(ch, char_dim.first, char_dim.second);
width += char_dim.first;
height = char_dim.second > height ? char_dim.second : height;
} while (--length > 0);
}
else
{
logicalStart += length;
int32_t j=0,i=length;
UnicodeString arabic;
UChar * buf = arabic.getBuffer(length);
do {
UChar ch = text[--logicalStart];
buf[j++] = ch;
} while (--i > 0);
arabic.releaseBuffer(length);
if ( *arabic.getBuffer() >= 0x0600 && *arabic.getBuffer() <= 0x06ff)
{
UnicodeString shaped;
u_shapeArabic(arabic.getBuffer(),arabic.length(),shaped.getBuffer(arabic.length()),arabic.length(),
U_SHAPE_LETTERS_SHAPE|U_SHAPE_LENGTH_FIXED_SPACES_NEAR|
U_SHAPE_TEXT_DIRECTION_VISUAL_LTR
,&err);
shaped.releaseBuffer(arabic.length());
if (U_SUCCESS(err))
{
for (int j=0;j<shaped.length();++j)
{
dimension_t char_dim = character_dimensions(shaped[j]);
info.add_info(shaped[j], char_dim.first, char_dim.second);
width += char_dim.first;
height = char_dim.second > height ? char_dim.second : height;
}
}
}
}
}
}
ubidi_close(bidi);
}
info.set_dimensions(width, height);
}
void set_pixel_size(unsigned size) void set_pixel_size(unsigned size)
{ {
std::vector<face_ptr>::iterator itr = faces_.begin(); face_->set_pixel_sizes(size);
std::vector<face_ptr>::iterator end = faces_.end();
for (; itr != end; ++itr)
{
(*itr)->set_pixel_sizes(size);
}
} }
void set_fill(mapnik::Color const& fill) void set_fill(mapnik::Color const& fill)
@ -360,25 +326,22 @@ namespace mapnik
FT_Matrix matrix; FT_Matrix matrix;
FT_Vector pen; FT_Vector pen;
FT_Error error; FT_Error error;
FT_BBox bbox;
bbox.xMin = bbox.yMin = 32000; // Initialize these so we can tell if we
bbox.xMax = bbox.yMax = -32000; // properly grew the bbox later
std::vector<face_ptr>::iterator end = faces_.end(); FT_Face face = face_->get_face();
// FT_GlyphSlot slot = face->glyph;
FT_BBox bbox;
bbox.xMin = bbox.yMin = 32000;
bbox.xMax = bbox.yMax = -32000; //hmm??
for (int i = 0; i < path->num_nodes(); i++) for (int i = 0; i < path->num_nodes(); i++)
{ {
int c; int c;
double x, y, angle; double x, y, angle;
path->vertex(&c, &x, &y, &angle); path->vertex(&c, &x, &y, &angle);
// std::clog << " prepare_glyph: " << (unsigned char)c << "," << x << "," << y << "," << angle << std::endl;
#ifdef MAPNIK_DEBUG
// TODO Enable when we have support for setting verbosity
//std::clog << "prepare_glyphs: " << c << "," << x <<
// "," << y << "," << angle << std::endl;
#endif
FT_BBox glyph_bbox; FT_BBox glyph_bbox;
FT_Glyph image; FT_Glyph image;
@ -386,59 +349,23 @@ namespace mapnik
pen.x = int(x * 64); pen.x = int(x * 64);
pen.y = int(y * 64); pen.y = int(y * 64);
FT_Face face = (*faces_.begin())->get_face();
FT_UInt glyph_index = FT_Get_Char_Index(face, unsigned(c));
// If there's no glyph_index we loop through the remaining fonts
// in the fontset looking for one.
if (!glyph_index) {
std::vector<face_ptr>::iterator itr = faces_.begin();
++itr; // Skip the first one, we already tried it.
for (; itr != end; ++itr)
{
#ifdef MAPNIK_DEBUG
// TODO Enable when we have support for setting verbosity
//std::clog << "prepare_glyphs: Falling back to font named \""
// << (*itr)->family_name() << " " << (*itr)->style_name()
// << "\"" << std::endl;
#endif
FT_Face f = (*itr)->get_face();
glyph_index = FT_Get_Char_Index(f, unsigned(c));
if (glyph_index) {
face = f;
break;
}
}
#ifdef MAPNIK_DEBUG
// TODO Enable when we have support for setting verbosity
//if (!glyph_index) {
// std::clog << "prepare_glyphs: Failed to fall back, glyph "
// << c << " not found in any font." << std::endl;
//}
#endif
}
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L ); matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L ); matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L ); matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L ); matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
FT_Set_Transform(face, &matrix, &pen); FT_Set_Transform (face,&matrix,&pen);
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_HINTING); FT_UInt glyph_index = FT_Get_Char_Index( face, unsigned(c));
error = FT_Load_Glyph (face,glyph_index, FT_LOAD_NO_HINTING);
if ( error ) if ( error )
continue; continue;
error = FT_Get_Glyph(face->glyph, &image); error = FT_Get_Glyph( face->glyph, &image);
if ( error ) if ( error )
continue; continue;
FT_Glyph_Get_CBox(image,ft_glyph_bbox_pixels, &glyph_bbox); FT_Glyph_Get_CBox(image,ft_glyph_bbox_pixels, &glyph_bbox);
if (glyph_bbox.xMin < bbox.xMin) if (glyph_bbox.xMin < bbox.xMin)
bbox.xMin = glyph_bbox.xMin; bbox.xMin = glyph_bbox.xMin;
@ -448,8 +375,7 @@ namespace mapnik
bbox.xMax = glyph_bbox.xMax; bbox.xMax = glyph_bbox.xMax;
if (glyph_bbox.yMax > bbox.yMax) if (glyph_bbox.yMax > bbox.yMax)
bbox.yMax = glyph_bbox.yMax; bbox.yMax = glyph_bbox.yMax;
// Check if we properly grew the bbox
if ( bbox.xMin > bbox.xMax ) if ( bbox.xMin > bbox.xMax )
{ {
bbox.xMin = 0; bbox.xMin = 0;
@ -558,7 +484,7 @@ namespace mapnik
} }
pixmap_type & pixmap_; pixmap_type & pixmap_;
std::vector<face_ptr> faces_; face_ptr face_;
mapnik::Color fill_; mapnik::Color fill_;
mapnik::Color halo_fill_; mapnik::Color halo_fill_;
int halo_radius_; int halo_radius_;
@ -568,4 +494,5 @@ namespace mapnik
}; };
} }
#endif // FONT_ENGINE_FREETYPE_HPP #endif // FONT_ENGINE_FREETYPE_HPP

View file

@ -80,7 +80,6 @@ namespace mapnik {
{ {
return width_; return width_;
} }
inline unsigned height() const inline unsigned height() const
{ {
return height_; return height_;
@ -90,17 +89,15 @@ namespace mapnik {
{ {
return data_.getRow(row + y_) + x_; return data_.getRow(row + y_) + x_;
} }
inline T& data() inline T& data()
{ {
return data_; return data_;
} }
inline T const& data() const inline T const& data() const
{ {
return data_; return data_;
} }
private: private:
unsigned x_; unsigned x_;
unsigned y_; unsigned y_;

View file

@ -37,28 +37,6 @@ namespace mapnik
{ {
class MAPNIK_DECL Map class MAPNIK_DECL Map
{ {
public:
enum aspect_fix_mode
{
/* grow the width or height of the specified geo bbox to fill the map size. default behaviour. */
GROW_BBOX,
/* grow the width or height of the map to accomodate the specified geo bbox. */
GROW_CANVAS,
/* shrink the width or height of the specified geo bbox to fill the map size. */
SHRINK_BBOX,
/* shrink the width or height of the map to accomodate the specified geo bbox. */
SHRINK_CANVAS,
/* adjust the width of the specified geo bbox, leave height and map size unchanged */
ADJUST_BBOX_WIDTH,
/* adjust the height of the specified geo bbox, leave width and map size unchanged */
ADJUST_BBOX_HEIGHT,
/* adjust the width of the map, leave height and geo bbox unchanged */
ADJUST_CANVAS_WIDTH,
/* adjust the height of the map, leave width and geo bbox unchanged */
ADJUST_CANVAS_HEIGHT
};
private:
static const unsigned MIN_MAPSIZE=16; static const unsigned MIN_MAPSIZE=16;
static const unsigned MAX_MAPSIZE=MIN_MAPSIZE<<10; static const unsigned MAX_MAPSIZE=MIN_MAPSIZE<<10;
unsigned width_; unsigned width_;
@ -66,13 +44,10 @@ namespace mapnik
std::string srs_; std::string srs_;
boost::optional<Color> background_; boost::optional<Color> background_;
std::map<std::string,feature_type_style> styles_; std::map<std::string,feature_type_style> styles_;
std::map<std::string,FontSet> fontsets_;
std::vector<Layer> layers_; std::vector<Layer> layers_;
Envelope<double> currentExtent_; Envelope<double> currentExtent_;
aspect_fix_mode aspectFixMode_;
public: public:
typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator; typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator;
typedef std::map<std::string,feature_type_style>::iterator style_iterator; typedef std::map<std::string,feature_type_style>::iterator style_iterator;
@ -154,20 +129,6 @@ namespace mapnik
*/ */
feature_type_style const& find_style(std::string const& name) const; feature_type_style const& find_style(std::string const& name) const;
/*! \brief Insert a fontset into the map.
* @param name The name of the fontset.
* @param style The fontset to insert.
* @return true If success.
* @return false If failure.
*/
bool insert_fontset(std::string const& name, FontSet const& fontset);
/*! \brief Find a fontset.
* @param name The name of the fontset.
* @return The fontset if found. If not found return the default map fontset.
*/
FontSet const& find_fontset(std::string const& name) const;
/*! \brief Get number of all layers. /*! \brief Get number of all layers.
*/ */
size_t layerCount() const; size_t layerCount() const;
@ -282,10 +243,6 @@ namespace mapnik
featureset_ptr query_map_point(unsigned index, double x, double y) const; featureset_ptr query_map_point(unsigned index, double x, double y) const;
~Map(); ~Map();
void setAspectFixMode(aspect_fix_mode afm) { aspectFixMode_ = afm; }
bool getAspectFixMode() { return aspectFixMode_; }
private: private:
void fixAspectRatio(); void fixAspectRatio();
}; };

View file

@ -24,7 +24,6 @@
#ifndef _OCTREE_HPP_ #ifndef _OCTREE_HPP_
#define _OCTREE_HPP_ #define _OCTREE_HPP_
#include <mapnik/global.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include <vector> #include <vector>

View file

@ -80,12 +80,11 @@ namespace mapnik {
PNG_COLOR_TYPE_RGB_ALPHA,PNG_INTERLACE_NONE, PNG_COLOR_TYPE_RGB_ALPHA,PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT); PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr); png_write_info(png_ptr, info_ptr);
for (unsigned i=0;i<image.height();i++) for (unsigned i=0;i<image.height();i++)
{ {
png_write_row(png_ptr,(png_bytep)image.getRow(i)); png_write_row(png_ptr,(png_bytep)image.getRow(i));
} }
png_write_end(png_ptr, info_ptr); png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr);
} }

View file

@ -27,8 +27,7 @@
// mapnik // mapnik
#include <mapnik/enumeration.hpp> #include <mapnik/enumeration.hpp>
#include <mapnik/color.hpp> #include <mapnik/color.hpp>
#include <mapnik/font_set.hpp> #include <mapnik/graphics.hpp>
#include <mapnik/graphics.hpp>
// boost // boost
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -50,7 +49,6 @@ namespace mapnik
{ {
text_symbolizer(std::string const& name,std::string const& face_name, text_symbolizer(std::string const& name,std::string const& face_name,
unsigned size, Color const& fill); unsigned size, Color const& fill);
text_symbolizer(std::string const& name, unsigned size, Color const& fill);
text_symbolizer(text_symbolizer const& rhs); text_symbolizer(text_symbolizer const& rhs);
text_symbolizer& operator=(text_symbolizer const& rhs); text_symbolizer& operator=(text_symbolizer const& rhs);
std::string const& get_name() const; std::string const& get_name() const;
@ -68,9 +66,6 @@ namespace mapnik
void set_max_char_angle_delta(double angle); void set_max_char_angle_delta(double angle);
unsigned get_text_size() const; unsigned get_text_size() const;
std::string const& get_face_name() const; std::string const& get_face_name() const;
void set_face_name(std::string face_name);
FontSet const& get_fontset() const;
void set_fontset(FontSet fontset);
Color const& get_fill() const; Color const& get_fill() const;
void set_halo_fill(Color const& fill); void set_halo_fill(Color const& fill);
Color const& get_halo_fill() const; Color const& get_halo_fill() const;
@ -91,7 +86,6 @@ namespace mapnik
private: private:
std::string name_; std::string name_;
std::string face_name_; std::string face_name_;
FontSet fontset_;
unsigned size_; unsigned size_;
unsigned text_ratio_; unsigned text_ratio_;
unsigned wrap_width_; unsigned wrap_width_;

View file

@ -47,7 +47,6 @@ source = Split(
envelope.cpp envelope.cpp
filter_factory.cpp filter_factory.cpp
font_engine_freetype.cpp font_engine_freetype.cpp
font_set.cpp
graphics.cpp graphics.cpp
image_reader.cpp image_reader.cpp
image_util.cpp image_util.cpp