diff --git a/include/llmr/map/tile_parser.hpp b/include/llmr/map/tile_parser.hpp index b4bccb67a..5785c29b3 100644 --- a/include/llmr/map/tile_parser.hpp +++ b/include/llmr/map/tile_parser.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace llmr { @@ -25,7 +26,7 @@ private: bool obsolete() const; void parseGlyphs(); void parseStyleLayers(const std::vector& layers); - void addGlyph(uint64_t tileid, const std::string stackname, const std::string &string, const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face); + void addGlyph(uint64_t tileid, const std::string stackname, const std::u32string &string, const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face); std::unique_ptr createBucket(const BucketDescription& bucket_desc); std::unique_ptr createFillBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); std::unique_ptr createLineBucket(const VectorTileLayer& layer, const BucketDescription& bucket_desc); diff --git a/include/llmr/text/glyph_store.hpp b/include/llmr/text/glyph_store.hpp index ea7c96dc4..eb5d6038f 100644 --- a/include/llmr/text/glyph_store.hpp +++ b/include/llmr/text/glyph_store.hpp @@ -30,7 +30,7 @@ public: void insert(uint32_t id, const SDFGlyph &glyph); const std::map &getMetrics() const; const std::map &getSDFs() const; - const Shaping getShaping(const std::string &string) const; + const Shaping getShaping(const std::u32string &string) const; private: std::map bitmaps; diff --git a/include/llmr/util/utf.hpp b/include/llmr/util/utf.hpp new file mode 100644 index 000000000..8aa85a90a --- /dev/null +++ b/include/llmr/util/utf.hpp @@ -0,0 +1,44 @@ +#ifndef LLMR_UTIL_UTF +#define LLMR_UTIL_UTF + +#include + +// g++/libstdc++ is missing c++11 codecvt support +#ifdef __linux__ +#include +#else +#include +#endif + +namespace llmr { + +namespace util { + +#ifdef __linux__ + +class utf8_to_utf32 { + public: + explicit utf8_to_utf32() {} + std::u32string convert(std::string const& utf8) { + return boost::locale::conv::utf_to_utf(utf8); + } +}; + +#else + +class utf8_to_utf32 { + public: + explicit utf8_to_utf32() + : utf32conv_() {} + std::u32string convert(std::string const& utf8) { + return utf32conv_.from_bytes(utf8); + } + private: + std::wstring_convert, char32_t> utf32conv_; +}; + +#endif + +}} + +#endif diff --git a/setup-libraries.sh b/setup-libraries.sh index d43461111..fca19fd9c 100755 --- a/setup-libraries.sh +++ b/setup-libraries.sh @@ -71,7 +71,7 @@ source MacOSX.sh if [ ! -f out/build-cpp11-libcpp-x86_64/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi if [ ! -f out/build-cpp11-libcpp-x86_64/lib/libssl.a ] ; then ./scripts/build_openssl.sh ; fi if [ ! -f out/build-cpp11-libcpp-x86_64/lib/libcurl.a ] ; then ./scripts/build_curl.sh ; fi - if [ ! -d out/build-cpp11-libcpp-x86_64/include/boost ] ; then ./scripts/build_boost.sh `pwd`/../../src/ `pwd`/../../linux/ `pwd`/../../common/ ; fi + if [ ! -d out/build-cpp11-libcpp-x86_64/include/boost ] ; then ./scripts/build_boost.sh `pwd`/../../src/ `pwd`/../../include/ `pwd`/../../linux/ `pwd`/../../common/ ; fi echo ' ...done' rm -rf out/packages @@ -91,7 +91,7 @@ source Linux.sh if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64/lib/libuv.a ] ; then ./scripts/build_libuv.sh ; fi if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64/lib/libssl.a ] ; then ./scripts/build_openssl.sh ; fi if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64/lib/libcurl.a ] ; then ./scripts/build_curl.sh ; fi - if [ ! -d out/build-cpp11-libstdcpp-gcc-x86_64/include/boost ] ; then ./scripts/build_boost.sh `pwd`/../../src/ `pwd`/../../linux/ `pwd`/../../common/ ; fi + if [ ! -d out/build-cpp11-libstdcpp-gcc-x86_64/include/boost ] ; then ./scripts/build_boost.sh `pwd`/../../src/ `pwd`/../../include/ `pwd`/../../linux/ `pwd`/../../common/ ; fi rm -rf out/packages diff --git a/src/map/tile_parser.cpp b/src/map/tile_parser.cpp index 2cd10049a..ff5d61a5e 100644 --- a/src/map/tile_parser.cpp +++ b/src/map/tile_parser.cpp @@ -11,7 +11,9 @@ #include #include #include + #include +#include using namespace llmr; @@ -30,7 +32,7 @@ bool TileParser::obsolete() const { return tile.state == TileData::State::obsolete; } -void TileParser::addGlyph(uint64_t tileid, const std::string stackname, const std::string &string, const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face) { +void TileParser::addGlyph(uint64_t tileid, const std::string stackname, const std::u32string &string, const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face) { std::map sdfs = fontStack.getSDFs(); // Loop through all characters and add glyph to atlas, positions. for (uint32_t chr : string) { @@ -164,6 +166,7 @@ std::unique_ptr TileParser::createTextBucket(const VectorTileLayer& laye std::unique_ptr bucket = std::make_unique( tile.textVertexBuffer, tile.triangleElementsBuffer, bucket_desc, placement); + util::utf8_to_utf32 ucs4conv; // Determine and load glyph ranges { @@ -183,7 +186,7 @@ std::unique_ptr TileParser::createTextBucket(const VectorTileLayer& laye continue; } - const std::string string = toString(it_prop->second); + const std::u32string string = ucs4conv.convert(toString(it_prop->second)); // Loop through all characters of this text and collect unique codepoints. for (uint32_t chr : string) { @@ -215,11 +218,11 @@ std::unique_ptr TileParser::createTextBucket(const VectorTileLayer& laye continue; } - const std::string string = toString(it_prop->second); + const std::u32string string = ucs4conv.convert(toString(it_prop->second)); // Shape labels. const Shaping shaped = fontStack.getShaping(string); - shaping.emplace(string, shaped); + shaping.emplace(toString(it_prop->second), shaped); // Place labels. addGlyph(tile.id.to_uint64(), bucket_desc.geometry.font, string, fontStack, glyphAtlas, face); diff --git a/src/text/glyph_store.cpp b/src/text/glyph_store.cpp index 3e6c2bc74..dc77d18c0 100644 --- a/src/text/glyph_store.cpp +++ b/src/text/glyph_store.cpp @@ -2,10 +2,11 @@ #include #include +#include #include #include #include -#include +#include namespace llmr { @@ -27,7 +28,7 @@ const std::map &FontStack::getSDFs() const { return sdfs; } -const Shaping FontStack::getShaping(const std::string &string) const { +const Shaping FontStack::getShaping(const std::u32string &string) const { std::lock_guard lock(mtx); uint32_t i = 0; uint32_t x = 0;