diff --git a/include/mapnik/cairo_context.hpp b/include/mapnik/cairo_context.hpp index 3d35fea64..5858cf501 100644 --- a/include/mapnik/cairo_context.hpp +++ b/include/mapnik/cairo_context.hpp @@ -72,23 +72,9 @@ void check_object_status_and_throw_exception(const T& object) class cairo_face : private mapnik::noncopyable { public: - cairo_face(boost::shared_ptr const& engine, face_ptr const& face) - : face_(face) - { - static cairo_user_data_key_t key; - c_face_ = cairo_ft_font_face_create_for_ft_face(face->get_face(), FT_LOAD_NO_HINTING); - cairo_font_face_set_user_data(c_face_, &key, new handle(engine, face), destroy); - } - ~cairo_face() - { - if (c_face_) cairo_font_face_destroy(c_face_); - } - - cairo_font_face_t * face() const - { - return c_face_; - } - + cairo_face(boost::shared_ptr const& engine, face_ptr const& face); + ~cairo_face(); + cairo_font_face_t * face() const; private: class handle { diff --git a/include/mapnik/font_engine_freetype.hpp b/include/mapnik/font_engine_freetype.hpp index 8fa4a62d7..5667dce83 100644 --- a/include/mapnik/font_engine_freetype.hpp +++ b/include/mapnik/font_engine_freetype.hpp @@ -38,15 +38,6 @@ #include #include -// freetype2 -extern "C" -{ -#include -#include FT_FREETYPE_H -#include FT_GLYPH_H -#include FT_STROKER_H -} - // boost #include #include @@ -64,12 +55,16 @@ extern "C" // uci #include +struct FT_LibraryRec_; + namespace mapnik { class font_face; class text_path; class string_info; struct char_properties; +class stroker; +struct glyph_t; typedef boost::shared_ptr face_ptr; @@ -95,59 +90,7 @@ private: typedef boost::shared_ptr glyph_ptr; -class font_face : mapnik::noncopyable -{ -public: - font_face(FT_Face face) - : face_(face) {} - std::string family_name() const - { - return std::string(face_->family_name); - } - - std::string style_name() const - { - return std::string(face_->style_name); - } - - FT_GlyphSlot glyph() const - { - return face_->glyph; - } - - FT_Face get_face() const - { - return face_; - } - - unsigned get_char(unsigned c) const - { - return FT_Get_Char_Index(face_, c); - } - - bool set_pixel_sizes(unsigned size) - { - if (! FT_Set_Pixel_Sizes( face_, 0, size )) - return true; - return false; - } - - bool set_character_sizes(double size) - { - if ( !FT_Set_Char_Size(face_,0,(FT_F26Dot6)(size * (1<<6)),0,0)) - return true; - return false; - } - - ~font_face() - { - FT_Done_Face(face_); - } - -private: - FT_Face face_; -}; class MAPNIK_DECL font_face_set : private mapnik::noncopyable { @@ -159,83 +102,18 @@ public: : faces_(), dimension_cache_() {} - void add(face_ptr face) - { - faces_.push_back(face); - dimension_cache_.clear(); //Make sure we don't use old cached data - } - - size_type 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(face, g); - } - - // Final fallback to empty square if nothing better in any font - return boost::make_shared(*faces_.begin(), 0); - } - + void add(face_ptr face); + size_type size() const; + glyph_ptr get_glyph(unsigned c) const; char_info character_dimensions(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(double size) - { - BOOST_FOREACH ( face_ptr const& face, faces_) - { - face->set_character_sizes(size); - } - } + void set_pixel_sizes(unsigned size); + void set_character_sizes(double size); private: container_type faces_; std::map dimension_cache_; }; -// FT_Stroker wrapper -class stroker : mapnik::noncopyable -{ -public: - explicit stroker(FT_Stroker s) - : s_(s) {} - - void init(double radius) - { - FT_Stroker_Set(s_, (FT_Fixed) (radius * (1<<6)), - FT_STROKER_LINECAP_ROUND, - FT_STROKER_LINEJOIN_ROUND, - 0); - } - - FT_Stroker const& get() const - { - return s_; - } - - ~stroker() - { - FT_Stroker_Done(s_); - } -private: - FT_Stroker s_; -}; - - - typedef boost::shared_ptr face_set_ptr; typedef boost::shared_ptr stroker_ptr; @@ -263,7 +141,7 @@ public: virtual ~freetype_engine(); freetype_engine(); private: - FT_Library library_; + FT_LibraryRec_ * library_; #ifdef MAPNIK_THREADSAFE static boost::mutex mutex_; #endif @@ -360,18 +238,6 @@ private: template struct text_renderer : private mapnik::noncopyable { - struct glyph_t : mapnik::noncopyable - { - FT_Glyph image; - char_properties *properties; - glyph_t(FT_Glyph image_, char_properties *properties_) - : image(image_), - properties(properties_) {} - ~glyph_t() - { - FT_Done_Glyph(image); - } - }; typedef boost::ptr_vector glyphs_t; typedef T pixmap_type; diff --git a/include/mapnik/font_util.hpp b/include/mapnik/font_util.hpp new file mode 100644 index 000000000..6e04988a2 --- /dev/null +++ b/include/mapnik/font_util.hpp @@ -0,0 +1,145 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2013 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + + +#ifndef MAPNIK_FONT_UTIL_HPP +#define MAPNIK_FONT_UTIL_HPP + +// mapnik +#include + +#include + +// freetype2 +extern "C" +{ +#include +#include FT_FREETYPE_H +#include FT_GLYPH_H +#include FT_STROKER_H +} + +namespace mapnik +{ +struct char_properties; + +struct glyph_t : mapnik::noncopyable +{ + FT_Glyph image; + char_properties *properties; + glyph_t(FT_Glyph image_, char_properties *properties_) + : image(image_), + properties(properties_) {} + ~glyph_t() + { + FT_Done_Glyph(image); + } +}; + + +// FT_Stroker wrapper +class stroker : mapnik::noncopyable +{ +public: + explicit stroker(FT_Stroker s) + : s_(s) {} + + void init(double radius) + { + FT_Stroker_Set(s_, (FT_Fixed) (radius * (1<<6)), + FT_STROKER_LINECAP_ROUND, + FT_STROKER_LINEJOIN_ROUND, + 0); + } + + FT_Stroker const& get() const + { + return s_; + } + + ~stroker() + { + FT_Stroker_Done(s_); + } +private: + FT_Stroker s_; +}; + + +class font_face : mapnik::noncopyable +{ +public: + font_face(FT_Face face) + : face_(face) {} + + std::string family_name() const + { + return std::string(face_->family_name); + } + + std::string style_name() const + { + return std::string(face_->style_name); + } + + FT_GlyphSlot glyph() const + { + return face_->glyph; + } + + FT_Face get_face() const + { + return face_; + } + + unsigned get_char(unsigned c) const + { + return FT_Get_Char_Index(face_, c); + } + + bool set_pixel_sizes(unsigned size) + { + if (! FT_Set_Pixel_Sizes( face_, 0, size )) + return true; + return false; + } + + bool set_character_sizes(double size) + { + if ( !FT_Set_Char_Size(face_,0,(FT_F26Dot6)(size * (1<<6)),0,0)) + return true; + return false; + } + + ~font_face() + { + FT_Done_Face(face_); + } + +private: + FT_Face face_; +}; + +} + + +#endif // MAPNIK_FONT_UTIL_HPP diff --git a/src/agg/process_shield_symbolizer.cpp b/src/agg/process_shield_symbolizer.cpp index d522e9be0..753dccd14 100644 --- a/src/agg/process_shield_symbolizer.cpp +++ b/src/agg/process_shield_symbolizer.cpp @@ -27,6 +27,7 @@ #include #include #include +#include // boost #include diff --git a/src/agg/process_text_symbolizer.cpp b/src/agg/process_text_symbolizer.cpp index 287bb18b6..0ee0e9559 100644 --- a/src/agg/process_text_symbolizer.cpp +++ b/src/agg/process_text_symbolizer.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace mapnik { diff --git a/src/cairo_context.cpp b/src/cairo_context.cpp index 598a47592..83aea2783 100644 --- a/src/cairo_context.cpp +++ b/src/cairo_context.cpp @@ -21,9 +21,28 @@ *****************************************************************************/ #include +#include namespace mapnik { +cairo_face::cairo_face(boost::shared_ptr const& engine, face_ptr const& face) + : face_(face) +{ + static cairo_user_data_key_t key; + c_face_ = cairo_ft_font_face_create_for_ft_face(face->get_face(), FT_LOAD_NO_HINTING); + cairo_font_face_set_user_data(c_face_, &key, new handle(engine, face), destroy); +} + +cairo_face::~cairo_face() +{ + if (c_face_) cairo_font_face_destroy(c_face_); +} + +cairo_font_face_t * cairo_face::face() const +{ + return c_face_; +} + cairo_context::cairo_context(cairo_ptr const& cairo) : cairo_(cairo) {} diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index a6af3137b..48222fd67 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -28,6 +28,7 @@ #include #include #include +#include // boost @@ -48,7 +49,10 @@ namespace mapnik { -freetype_engine::freetype_engine() + +freetype_engine::freetype_engine() : + library_(NULL) + { FT_Error error = FT_Init_FreeType( &library_ ); if (error) @@ -234,6 +238,29 @@ stroker_ptr freetype_engine::create_stroker() return stroker_ptr(); } +void font_face_set::add(face_ptr face) +{ + faces_.push_back(face); + dimension_cache_.clear(); //Make sure we don't use old cached data +} + +font_face_set::size_type font_face_set::size() const +{ + return faces_.size(); +} + +glyph_ptr font_face_set::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(face, g); + } + + // Final fallback to empty square if nothing better in any font + return boost::make_shared(*faces_.begin(), 0); +} + char_info font_face_set::character_dimensions(unsigned int c) { //Check if char is already in cache @@ -329,6 +356,22 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust ubidi_close(bidi); } +void font_face_set::set_pixel_sizes(unsigned size) +{ + BOOST_FOREACH ( face_ptr const& face, faces_) + { + face->set_pixel_sizes(size); + } +} + +void font_face_set::set_character_sizes(double size) +{ + BOOST_FOREACH ( face_ptr const& face, faces_) + { + face->set_character_sizes(size); + } +} + template void composite_bitmap(T & pixmap, diff --git a/src/grid/process_shield_symbolizer.cpp b/src/grid/process_shield_symbolizer.cpp index 5d80ed1ac..0fab6d5e1 100644 --- a/src/grid/process_shield_symbolizer.cpp +++ b/src/grid/process_shield_symbolizer.cpp @@ -29,6 +29,7 @@ #include #include #include +#include // agg #include "agg_trans_affine.h" diff --git a/src/grid/process_text_symbolizer.cpp b/src/grid/process_text_symbolizer.cpp index 2c6322062..40e6ed5a3 100644 --- a/src/grid/process_text_symbolizer.cpp +++ b/src/grid/process_text_symbolizer.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace mapnik {