Last active
December 18, 2015 00:19
-
-
Save springmeyer/5696103 to your computer and use it in GitHub Desktop.
loading font from memory stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp | |
index 5f14544..a579989 100644 | |
--- a/src/font_engine_freetype.cpp | |
+++ b/src/font_engine_freetype.cpp | |
@@ -30,6 +30,7 @@ | |
#include <mapnik/pixel_position.hpp> | |
#include <mapnik/font_util.hpp> | |
#include <mapnik/util/fs.hpp> | |
+#include <mapnik/utils.hpp> | |
// boost | |
#include <boost/algorithm/string.hpp> | |
@@ -102,7 +103,24 @@ bool freetype_engine::register_font(std::string const& file_name) | |
// see the FT_FaceRec in freetype.h | |
for ( int i = 0; face == 0 || i < num_faces; i++ ) { | |
// if face is null then this is the first face | |
- error = FT_New_Face (library,file_name.c_str(),i,&face); | |
+ try | |
+ { | |
+#ifdef _WINDOWS | |
+ std::ifstream is(mapnik::utf8_to_utf16(file_name), std::ios::binary); | |
+#else | |
+ std::ifstream is(file_name.c_str() , std::ios::binary); | |
+#endif | |
+ std::string buffer((std::istreambuf_iterator<char>(is)), | |
+ std::istreambuf_iterator<char>()); | |
+ if (buffer.size() <= 0) | |
+ { | |
+ break; | |
+ } | |
+ error = FT_New_Memory_Face (library, | |
+ (FT_Byte const*) buffer.c_str(), | |
+ buffer.size(), | |
+ i, | |
+ &face); | |
if (error) | |
{ | |
break; | |
@@ -135,6 +153,9 @@ bool freetype_engine::register_font(std::string const& file_name) | |
MAPNIK_LOG_DEBUG(font_engine_freetype) << "freetype_engine: " << s.str(); | |
} | |
+ } catch (std::exception const&) { | |
+ break; | |
+ } | |
} | |
if (face) | |
FT_Done_Face(face); | |
@@ -234,7 +255,11 @@ face_ptr freetype_engine::create_face(std::string const& family_name) | |
#ifdef MAPNIK_THREADSAFE | |
mutex::scoped_lock lock(mutex_); | |
#endif | |
+#ifdef _WINDOWS | |
+ std::ifstream is(mapnik::utf8_to_utf16(itr->second.second), std::ios::binary); | |
+#else | |
std::ifstream is(itr->second.second.c_str() , std::ios::binary); | |
+#endif | |
std::string buffer((std::istreambuf_iterator<char>(is)), | |
std::istreambuf_iterator<char>()); | |
std::pair<std::map<std::string,std::string>::iterator,bool> result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment