diff --git a/include/mapnik/text/shaping.hpp b/include/mapnik/text/shaping.hpp index 28cbaccdf..4694c0d4a 100644 --- a/include/mapnik/text/shaping.hpp +++ b/include/mapnik/text/shaping.hpp @@ -3,9 +3,8 @@ //ICU #include -class hb_font_t; -class hb_buffer_t; -class hb_glyph_info_t; +#include +#include // freetype2 extern "C" @@ -24,7 +23,7 @@ public: text_shaping(FT_Face face); ~text_shaping(); - uint32_t process_text(UnicodeString const& text); + uint32_t process_text(UnicodeString const& text, bool rtl, UScriptCode script); hb_buffer_t *get_buffer() { return buffer_; } protected: diff --git a/src/text/layout.cpp b/src/text/layout.cpp index 9df7b3a34..3f555421a 100644 --- a/src/text/layout.cpp +++ b/src/text/layout.cpp @@ -32,7 +32,7 @@ void text_layout::shape_text() face_ptr face = *(face_set->begin()); //TODO: Implement font sets correctly text_shaping shaper(face->get_face()); //TODO: Make this more efficient by caching this object in font_face - uint32_t bytes = shaper.process_text(itr->str); + uint32_t bytes = shaper.process_text(itr->str, itr->rtl == UBIDI_DEFAULT_RTL, itr->script); hb_buffer_t *buffer = shaper.get_buffer(); unsigned num_glyphs = hb_buffer_get_length(buffer); diff --git a/src/text/shaping.cpp b/src/text/shaping.cpp index b25e93777..c25ffca4f 100644 --- a/src/text/shaping.cpp +++ b/src/text/shaping.cpp @@ -9,6 +9,7 @@ #define HAVE_FREETYPE #include #include +#include namespace mapnik @@ -20,6 +21,7 @@ text_shaping::text_shaping(FT_Face face) buffer_ (hb_buffer_create()), face_(face) { + hb_buffer_set_unicode_funcs(buffer_, hb_icu_get_unicode_funcs()); load_font(); } @@ -29,7 +31,7 @@ text_shaping::~text_shaping() hb_font_destroy(font_); } -uint32_t text_shaping::process_text(const UnicodeString &text) +uint32_t text_shaping::process_text(UnicodeString const& text, bool rtl, UScriptCode script) { if (!font_) return 0; hb_buffer_reset(buffer_); @@ -37,9 +39,9 @@ uint32_t text_shaping::process_text(const UnicodeString &text) std::string s; text.toUTF8String(s); hb_buffer_add_utf8(buffer_, s.c_str(), s.length(), 0, -1); + hb_buffer_set_direction(buffer_, rtl?HB_DIRECTION_RTL:HB_DIRECTION_LTR); + hb_buffer_set_script(buffer_, hb_icu_script_to_script(script)); #if 0 - hb_buffer_set_direction(buffer, hb_direction_from_string (direction, -1)); - hb_buffer_set_script(buffer, hb_script_from_string (script, -1)); hb_buffer_set_language(buffer, hb_language_from_string (language, -1)); #endif hb_shape(font_, buffer_, 0 /*features*/, 0 /*num_features*/);