Advertisement
svenhoefer

Untitled

Apr 2nd, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.36 KB | None | 0 0
  1. diff --git a/src/driver/fontrenderer.cpp b/src/driver/fontrenderer.cpp
  2. index 9c50d01..739f7a6 100644
  3. --- a/src/driver/fontrenderer.cpp
  4. +++ b/src/driver/fontrenderer.cpp
  5. @@ -393,7 +393,7 @@ int UTF8ToUnicode(const char * &text, const bool utf8_encoded) // returns -1 on
  6.  }
  7.  
  8.  #ifdef ENABLE_FRIBIDI
  9. -static std::string fribidi_shape_char(const char * text)
  10. +static std::string fribidi_shape_char(const char * text, bool &is_rtl)
  11.  {
  12.     if(text && *text)
  13.     {
  14. @@ -408,7 +408,7 @@ static std::string fribidi_shape_char(const char * text)
  15.         FriBidiCharSet fribidi_charset = FRIBIDI_CHAR_SET_UTF8;
  16.  
  17.         // tell bidi that we need bidirectional
  18. -       FriBidiCharType fribidi_chartype = FRIBIDI_TYPE_L;
  19. +       FriBidiCharType fribidi_chartype = FRIBIDI_TYPE_ON;
  20.  
  21.         // our buffer
  22.         FriBidiChar *logical = (FriBidiChar *)alloca(sizeof(FriBidiChar)*(len + 1));
  23. @@ -427,6 +427,9 @@ static std::string fribidi_shape_char(const char * text)
  24.             rtl_text = (char *)alloca(sizeof(char)*(rtl_len * 4 + 1));
  25.             fribidi_unicode_to_charset(fribidi_charset, visual, rtl_len, rtl_text);
  26.  
  27. +           is_rtl = ((fribidi_chartype & FRIBIDI_MASK_RTL) || (fribidi_chartype & FRIBIDI_MASK_ARABIC));
  28. +           if (is_rtl)
  29. +               printf("FRIBIDI_MASK_RTL || FRIBIDI_MASK_ARABIC\n");
  30.             return std::string(rtl_text);
  31.         }
  32.     }
  33. @@ -495,8 +498,9 @@ void Font::RenderString(int x, int y, const int width, const char *text, const f
  34.  
  35.     pthread_mutex_lock( &renderer->render_mutex );
  36.  
  37. +   bool is_rtl = false;
  38.  #ifdef ENABLE_FRIBIDI
  39. -   std::string Text = fribidi_shape_char(text);
  40. +   std::string Text = fribidi_shape_char(text, is_rtl);
  41.     text = Text.c_str();
  42.  #endif
  43.  
  44. @@ -512,6 +516,12 @@ void Font::RenderString(int x, int y, const int width, const char *text, const f
  45.     int use_kerning=FT_HAS_KERNING(face);
  46.  
  47.     int left=x;
  48. +   if (is_rtl)
  49. +   {
  50. +       int rtl_left = x + width - getRenderWidth(text);
  51. +       if (rtl_left >= left)
  52. +           left = rtl_left;
  53. +   }
  54.     int step_y=height;
  55.  
  56.     // ----------------------------------- box upper end (this is NOT a font metric, this is our method for y centering)
  57. @@ -690,8 +700,9 @@ int Font::getRenderWidth(const char *text, const bool utf8_encoded)
  58.  {
  59.     pthread_mutex_lock( &renderer->render_mutex );
  60.  
  61. +   bool is_rtl = false;
  62.  #ifdef ENABLE_FRIBIDI
  63. -   std::string Text = fribidi_shape_char(text);
  64. +   std::string Text = fribidi_shape_char(text, is_rtl);
  65.     text = Text.c_str();
  66.  #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement