예제 #1
0
bool freetype_engine::register_fonts_impl(std::string const& dir,
                                          font_library & library,
                                          freetype_engine::font_file_mapping_type & font_file_mapping,
                                          bool recurse)
{
    if (!mapnik::util::exists(dir))
    {
        return false;
    }
    if (!mapnik::util::is_directory(dir))
    {
        return register_font_impl(dir, library, font_file_mapping);
    }
    bool success = false;
    try
    {
        boost::filesystem::directory_iterator end_itr;
#ifdef _WINDOWS
        std::wstring wide_dir(mapnik::utf8_to_utf16(dir));
        for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr)
        {
            std::string file_name = mapnik::utf16_to_utf8(itr->path().wstring());
#else
        for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr)
        {
            std::string file_name = itr->path().string();
#endif
            if (boost::filesystem::is_directory(*itr) && recurse)
            {
                if (register_fonts_impl(file_name, library, font_file_mapping, true))
                {
                    success = true;
                }
            }
            else
            {
                std::string base_name = itr->path().filename().string();
                if (!boost::algorithm::starts_with(base_name,".") &&
                    mapnik::util::is_regular_file(file_name) &&
                    is_font_file(file_name))
                {
                    if (register_font_impl(file_name, library, font_file_mapping))
                    {
                        success = true;
                    }
                }
            }
        }
    }
    catch (std::exception const& ex)
    {
        MAPNIK_LOG_ERROR(font_engine_freetype) << "register_fonts: " << ex.what();
    }
    return success;
}
예제 #2
0
bool freetype_engine::register_font(std::string const& file_name)
{
#ifdef MAPNIK_THREADSAFE
    std::lock_guard<std::mutex> lock(mutex_);
#endif
    font_library library;
    return register_font_impl(file_name, library, global_font_file_mapping_);
}
예제 #3
0
bool freetype_engine::register_fonts_impl(std::string const& dir,
                                          font_library & library,
                                          freetype_engine::font_file_mapping_type & font_file_mapping,
                                          bool recurse)
{
    if (!mapnik::util::exists(dir))
    {
        return false;
    }
    if (!mapnik::util::is_directory(dir))
    {
        return register_font_impl(dir, library, font_file_mapping);
    }
    bool success = false;
    try
    {
        for (std::string const& file_name : mapnik::util::list_directory(dir))
        {
            if (mapnik::util::is_directory(file_name) && recurse)
            {
                if (register_fonts_impl(file_name, library, font_file_mapping, true))
                {
                    success = true;
                }
            }
            else
            {
                std::string base_name = mapnik::util::basename(file_name);
                if (!boost::algorithm::starts_with(base_name,".") &&
                    mapnik::util::is_regular_file(file_name) &&
                    is_font_file(file_name))
                {
                    if (register_font_impl(file_name, library, font_file_mapping))
                    {
                        success = true;
                    }
                }
            }
        }
    }
    catch (std::exception const& ex)
    {
        MAPNIK_LOG_ERROR(font_engine_freetype) << "register_fonts: " << ex.what();
    }
    return success;
}
예제 #4
0
bool freetype_engine::register_font(std::string const& file_name)
{
#ifdef MAPNIK_THREADSAFE
    mapnik::scoped_lock lock(mutex_);
#endif

    FT_Library library = 0;
    std::unique_ptr<FT_MemoryRec_> memory(new FT_MemoryRec_);
    init_freetype(&*memory, library);
    bool result = register_font_impl(file_name, library);
    FT_Done_Library(library);
    return result;
}