diff --git a/include/mapnik/skia/skia_font_manager.hpp b/include/mapnik/skia/skia_font_manager.hpp index d979421cc..56b0f8226 100644 --- a/include/mapnik/skia/skia_font_manager.hpp +++ b/include/mapnik/skia/skia_font_manager.hpp @@ -30,7 +30,6 @@ namespace mapnik { - class skia_font_manager { public: diff --git a/include/mapnik/skia/skia_typeface_cache.hpp b/include/mapnik/skia/skia_typeface_cache.hpp new file mode 100644 index 000000000..0c2caa8b1 --- /dev/null +++ b/include/mapnik/skia/skia_typeface_cache.hpp @@ -0,0 +1,54 @@ +/***************************************************************************** + * + * 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 + * + *****************************************************************************/ + + +#if defined(HAVE_SKIA) + +#ifndef MAPNIK_SKIA_TYPEFACE_CACHE_HPP +#define MAPNIK_SKIA_TYPEFACE_CACHE_HPP + +#include + +class SkTypeface; + +namespace mapnik +{ + +class skia_typeface_cache +{ +public: + skia_typeface_cache(); + ~skia_typeface_cache(); + static bool register_font(std::string const& file_name); + static bool register_fonts(std::string const& dir, bool recurse = false); + +private: +#ifdef MAPNIK_THREADSAFE + static boost::mutex mutex_; +#endif + static std::map typefaces_; +}; + +} + +#endif // MAPNIK_SKIA_TYPEFACE_CACHE_HPP +#endif // #if defined(HAVE_SKIA) diff --git a/src/build.py b/src/build.py index 1dddfdbd6..c9532dab6 100644 --- a/src/build.py +++ b/src/build.py @@ -259,6 +259,7 @@ if env['HAS_SKIA']: lib_env.Append(CPPDEFINES = '-DHAVE_SKIA') libmapnik_defines.append('-DHAVE_SKIA') source.insert(0,'skia/skia_renderer.cpp') + source.insert(0,'skia/skia_typeface_cache.cpp') if env['JPEG']: diff --git a/src/skia/skia_typeface_cache.cpp b/src/skia/skia_typeface_cache.cpp new file mode 100644 index 000000000..05f53130f --- /dev/null +++ b/src/skia/skia_typeface_cache.cpp @@ -0,0 +1,119 @@ +/***************************************************************************** + * + * 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 + * + *****************************************************************************/ + +#include +#include +#include +#ifdef MAPNIK_THREADSAFE +#include +#endif + +#include +#include + +#include +#include + +namespace mapnik +{ + +skia_typeface_cache::skia_typeface_cache() +{ +} + +skia_typeface_cache::~skia_typeface_cache() +{ +} + +bool skia_typeface_cache::register_font(std::string const& file_name) +{ +#ifdef MAPNIK_THREADSAFE + boost::mutex::scoped_lock lock(mutex_); +#endif + SkTypeface * typeface = SkTypeface::CreateFromFile(file_name.c_str()); + if (typeface) + { + SkAdvancedTypefaceMetrics * metrics = typeface->getAdvancedTypefaceMetrics(SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo); + std::cerr << metrics->fFontName.writable_str() << std::endl; + //typefaces_.insert(std::make_pair( + } +} + +bool skia_typeface_cache::register_fonts(std::string const& dir, bool recurse) +{ + if (!mapnik::util::exists(dir)) + { + return false; + } + if (!mapnik::util::is_directory(dir)) + { + return register_font(dir); + } + bool success = false; + try + { + boost::filesystem::directory_iterator end_itr; + for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr) + { +#if (BOOST_FILESYSTEM_VERSION == 3) + std::string file_name = itr->path().string(); +#else // v2 + std::string file_name = itr->string(); +#endif + if (boost::filesystem::is_directory(*itr) && recurse) + { + if (register_fonts(file_name, true)) + { + success = true; + } + } + else + { +#if (BOOST_FILESYSTEM_VERSION == 3) + std::string base_name = itr->path().filename().string(); +#else // v2 + std::string base_name = itr->filename(); +#endif + if (!boost::algorithm::starts_with(base_name,".") && + boost::filesystem::is_regular_file(file_name)) + { + if (register_font(file_name)) + { + success = true; + } + } + } + } + } + catch (std::exception const& ex) + { + MAPNIK_LOG_ERROR(skia_typeface_cache) << "register_fonts: " << ex.what(); + } + return success; +} + +#ifdef MAPNIK_THREADSAFE +boost::mutex skia_typeface_cache::mutex_; +#endif +std::map skia_typeface_cache::typefaces_; + +}