[MPlayer-dev-eng] [HACK/RFC] libass without fribidi
KO Myung-Hun
komh78 at gmail.com
Mon Dec 5 13:02:23 CET 2011
Hi/2.
Reimar Döffinger wrote:
> Hello,
> attached patch seems to work to get a libass that does not depend on
> FriBiDi.
> Does someone know if libass maintainers would be interested in (a
> possibly cleaner version of) this?
>
> Reimar
>
>
> assbidi.diff
>
>
> Index: libass/ass_shaper.c
> ===================================================================
> --- libass/ass_shaper.c (revision 34388)
> +++ libass/ass_shaper.c (working copy)
> @@ -18,7 +18,9 @@
>
> #include "config.h"
>
> +#ifdef CONFIG_FRIBIDI
> #include <fribidi/fribidi.h>
> +#endif
>
> #include "ass_shaper.h"
> #include "ass_render.h"
> @@ -43,9 +45,11 @@
>
> // FriBidi log2vis
> int n_glyphs;
> +#ifdef CONFIG_FRIBIDI
> FriBidiChar *event_text;
> FriBidiCharType *ctypes;
> FriBidiLevel *emblevels;
> +#endif
> FriBidiStrIndex *cmap;
> FriBidiParType base_direction;
>
> @@ -79,8 +83,10 @@
> */
> void ass_shaper_info(ASS_Library *lib)
> {
> - ass_msg(lib, MSGL_V, "Shaper: FriBidi "
> - FRIBIDI_VERSION " (SIMPLE)"
> + ass_msg(lib, MSGL_V, "Shaper:"
> +#ifdef CONFIG_FRIBIDI
> + " FriBidi " FRIBIDI_VERSION " (SIMPLE)"
> +#endif
> #ifdef CONFIG_HARFBUZZ
> " HarfBuzz-ng %s (COMPLEX)", hb_version_string()
> #endif
> @@ -94,9 +100,11 @@
> static void check_allocations(ASS_Shaper *shaper, size_t new_size)
> {
> if (new_size > shaper->n_glyphs) {
> +#ifdef CONFIG_FRIBIDI
> shaper->event_text = realloc(shaper->event_text, sizeof(FriBidiChar) * new_size);
> shaper->ctypes = realloc(shaper->ctypes, sizeof(FriBidiCharType) * new_size);
> shaper->emblevels = realloc(shaper->emblevels, sizeof(FriBidiLevel) * new_size);
> +#endif
> shaper->cmap = realloc(shaper->cmap, sizeof(FriBidiStrIndex) * new_size);
> }
> }
> @@ -110,9 +118,11 @@
> ass_cache_done(shaper->metrics_cache);
> free(shaper->features);
> #endif
> +#ifdef CONFIG_FRIBIDI
> free(shaper->event_text);
> free(shaper->ctypes);
> free(shaper->emblevels);
> +#endif
> free(shaper->cmap);
> free(shaper);
> }
> @@ -493,6 +503,7 @@
> }
> #endif
>
> +#ifdef CONFIG_FRIBIDI
> /**
> * \brief Shape event text with FriBidi. Does mirroring and simple
> * Arabic shaping.
> @@ -519,6 +530,7 @@
>
> free(joins);
> }
> +#endif
>
> /**
> * \brief Toggle kerning for HarfBuzz shaping.
> @@ -595,6 +607,9 @@
> */
> void ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
> {
> +#ifndef CONFIG_FRIBIDI
> + check_allocations(shaper, text_info->length);
> +#else
> int i, last_break;
> FriBidiParType dir;
> GlyphInfo *glyphs = text_info->glyphs;
> @@ -645,6 +660,7 @@
> glyphs[i].skip++;
> }
> }
> +#endif
> }
>
> /**
> @@ -655,7 +671,9 @@
> {
> ASS_Shaper *shaper = calloc(sizeof(*shaper), 1);
>
> +#ifdef CONFIG_FRIBIDI
> shaper->base_direction = FRIBIDI_PAR_ON;
> +#endif
> check_allocations(shaper, prealloc);
>
> #ifdef CONFIG_HARFBUZZ
> @@ -697,6 +715,7 @@
> for (i = 0; i < text_info->length; i++)
> shaper->cmap[i] = i;
>
> +#ifdef CONFIG_FRIBIDI
> // Create reorder map line-by-line
> for (i = 0; i < text_info->n_lines; i++) {
> LineInfo *line = text_info->lines + i;
> @@ -708,6 +727,7 @@
> shaper->emblevels + line->offset, NULL,
> shaper->cmap + line->offset);
> }
> +#endif
>
> return shaper->cmap;
> }
> @@ -721,6 +741,7 @@
> */
> FriBidiParType resolve_base_direction(int enc)
> {
> +#ifdef CONFIG_FRIBIDI
> switch (enc) {
> case 1:
> return FRIBIDI_PAR_ON;
> @@ -730,4 +751,7 @@
> default:
> return FRIBIDI_PAR_LTR;
> }
> +#else
> + return 0;
> +#endif
> }
> Index: libass/ass_shaper.h
> ===================================================================
> --- libass/ass_shaper.h (revision 34388)
> +++ libass/ass_shaper.h (working copy)
> @@ -21,7 +21,12 @@
>
> #include "config.h"
>
> +#ifdef CONFIG_FRIBIDI
> #include <fribidi/fribidi.h>
> +#else
> +typedef int FriBidiParType;
> +typedef int FriBidiStrIndex;
> +#endif
> #include "ass_render.h"
>
Is there a special reason typedefing only these two types ?
Why don't you guard all the FriBidi stuffs with CONFIG_FRIBIDI ?
--
KO Myung-Hun
Using Mozilla SeaMonkey 2.0.14
Under OS/2 Warp 4 for Korean with FixPak #15
On AMD ThunderBird 1GHz with 512 MB RAM
Korean OS/2 User Community : http://www.ecomstation.co.kr
More information about the MPlayer-dev-eng
mailing list