skia_typeface_cache
This commit is contained in:
parent
5d91048534
commit
6a82e617cc
4 changed files with 174 additions and 1 deletions
|
@ -30,7 +30,6 @@
|
|||
namespace mapnik
|
||||
{
|
||||
|
||||
|
||||
class skia_font_manager
|
||||
{
|
||||
public:
|
||||
|
|
54
include/mapnik/skia/skia_typeface_cache.hpp
Normal file
54
include/mapnik/skia/skia_typeface_cache.hpp
Normal file
|
@ -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 <iostream>
|
||||
|
||||
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<std::string, SkTypeface*> typefaces_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MAPNIK_SKIA_TYPEFACE_CACHE_HPP
|
||||
#endif // #if defined(HAVE_SKIA)
|
|
@ -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']:
|
||||
|
|
119
src/skia/skia_typeface_cache.cpp
Normal file
119
src/skia/skia_typeface_cache.cpp
Normal file
|
@ -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 <mapnik/debug.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#endif
|
||||
|
||||
#include <SkTypeface.h>
|
||||
#include <SkAdvancedTypefaceMetrics.h>
|
||||
|
||||
#include <mapnik/skia/skia_typeface_cache.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
|
||||
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<std::string, SkTypeface* > skia_typeface_cache::typefaces_;
|
||||
|
||||
}
|
Loading…
Reference in a new issue