[vlc-devel] [PATCH] freetype: render Arabic diacritics properly

Salah Shaaban salshaaban at gmail.com
Tue Jan 6 12:44:29 CET 2015


To clarify this issue, here are 2 screenshots.

https://docs.google.com/file/d/0B36ioujDBJZsNmZHcHdidlBfRFE/edit?pli=1
https://docs.google.com/file/d/0B36ioujDBJZsR29ONEpVWUtGREk/edit?pli=1


The first shows the current rendering of VLC, with some diacritics marked
with arrows. Here diacritics are treated as separate characters and each is
given its own horizontal space which is incorrect, and causes gaps to
appear in the words. This makes reading the text rather difficult,
especially with fast-changing subtitles.

The second shows diacritics displayed correctly over their corresponding
base glyphs. So now Arabic text is handled flawlessly in VLC as far as I
can see.



On Tue, Jan 6, 2015 at 1:42 PM, Salah-Eddin Shaban <salshaaban at gmail.com>
wrote:

> ---
>  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;
> --
> 1.9.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20150106/794cf4fc/attachment.html>


More information about the vlc-devel mailing list