[vlc-commits] freetype: render Arabic diacritics properly

Salah-Eddin Shaban git at videolan.org
Tue Jan 6 14:22:41 CET 2015


vlc | branch: master | Salah-Eddin Shaban <salshaaban at gmail.com> | Tue Jan  6 13:42:08 2015 +0200| [222671868f7b1b10254e91a0005da4334dbab7e0] | committer: Jean-Baptiste Kempf

freetype: render Arabic diacritics properly

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=222671868f7b1b10254e91a0005da4334dbab7e0
---

 modules/text_renderer/freetype.c |   27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 1670aa7..050ace6 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -1361,6 +1361,10 @@ static int ProcessLines( filter_t *p_filter,
             /* Render the part */
             bool b_break_line = false;
             int i_glyph_last = 0;
+            FT_Vector advance = {
+                .x = 0,
+                .y = 0,
+            };
             while( i_part_length > 0 )
             {
                 const text_style_t *p_glyph_style = pp_styles[i_index];
@@ -1373,6 +1377,16 @@ static int ProcessLines( filter_t *p_filter,
                 if( i_glyph_index == 0 && character == 0xFEFF )
                     goto next;
 
+/* These are the most common Arabic diacritics */
+#define DIACRITIC( a ) ( a >= 0x064B && a <= 0x0653 )
+
+                /* Diacritics should be rendered over the preceding base glyph */
+                if( DIACRITIC( character ) )
+                {
+                    pen.x -= advance.x;
+                    pen.y -= advance.y;
+                }
+
                 /* Get kerning vector */
                 FT_Vector kerning = { .x = 0, .y = 0 };
                 if( FT_HAS_KERNING( p_current_face ) && i_glyph_last != 0 && i_glyph_index != 0 )
@@ -1516,8 +1530,17 @@ static int ProcessLines( filter_t *p_filter,
                     .i_line_thickness = i_line_thickness,
                 };
 
-                pen.x = pen_new.x + p_current_face->glyph->advance.x;
-                pen.y = pen_new.y + p_current_face->glyph->advance.y;
+                /* Diacritics do not determine advance values. We use        */
+                /* the advance values from the last encountered base glyph,  */
+                /* since multiple diacritics may follow a single base glyph. */
+                if( !DIACRITIC( character ) )
+                {
+                    advance.x = p_current_face->glyph->advance.x;
+                    advance.y = p_current_face->glyph->advance.y;
+                }
+
+                pen.x = pen_new.x + advance.x;
+                pen.y = pen_new.y + advance.y;
                 line_bbox = line_bbox_new;
             next:
                 i_glyph_last = i_glyph_index;



More information about the vlc-commits mailing list