diff --git a/include/mapnik/text_path.hpp b/include/mapnik/text_path.hpp index e06e4b9bb..cd9a4c275 100644 --- a/include/mapnik/text_path.hpp +++ b/include/mapnik/text_path.hpp @@ -56,11 +56,13 @@ protected: UnicodeString const& text_; double width_; double height_; + bool is_rtl; public: string_info(UnicodeString const& text) : text_(text), width_(0), - height_(0) {} + height_(0), + is_rtl(false) {} void add_info(int c, double width, double height) { @@ -71,6 +73,9 @@ public: { return characters_.size(); } + + void set_rtl(bool value) {is_rtl = value;} + bool get_rtl() const {return is_rtl;} character_info at(unsigned i) const { diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index 7b84c5d0b..d5ab39c2e 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -262,6 +262,11 @@ void font_face_set::get_string_info(string_info & info) } } + if (ubidi_getBaseDirection(ustr.getBuffer(), length) == UBIDI_RTL) + { + info.set_rtl(true); + } + ubidi_close(bidi); info.set_dimensions(width, height); } diff --git a/src/placement_finder.cpp b/src/placement_finder.cpp index 3a4e33275..a57da1222 100644 --- a/src/placement_finder.cpp +++ b/src/placement_finder.cpp @@ -379,7 +379,14 @@ void placement_finder::find_point_placement(placement & p, // set for upper left corner of text envelope for the first line, bottom left of first character x = -(line_width / 2.0); - y = (0.5 * (string_height + (line_spacing * (total_lines-1)))) - max_character_height; + if (p.info.get_rtl()==false) + { + y = (0.5 * (string_height + (line_spacing * (total_lines-1)))) - max_character_height; + } + else + { + y = -(0.5 * (string_height + (line_spacing * (total_lines-1)))) + max_character_height; + } // if needed, adjust for desired justification (J_MIDDLE is the default) if( po->jalign == J_LEFT ) @@ -404,7 +411,14 @@ void placement_finder::find_point_placement(placement & p, index_to_wrap_at = line_breaks[++line_number]; line_width = line_widths[line_number]; - y -= (max_character_height + line_spacing); // move position down to line start + if (p.info.get_rtl()==false) + { + y -= (max_character_height + line_spacing); // move position down to line start + } + else + { + y += (max_character_height + line_spacing); // move position up to line start + } // reset to begining of line position x = ((po->jalign == J_LEFT)? -(string_width / 2.0): ((po->jalign == J_RIGHT)? ((string_width /2.0) - line_width): -(line_width / 2.0)));