master chld/ports-heresy / lib / libass / no-fribidi.patch
  1diff --git a/libass/ass_render.h b/libass/ass_render.h
  2index 7a157ab..c8adf1d 100644
  3--- a/libass/ass_render.h
  4+++ b/libass/ass_render.h
  5@@ -22,7 +22,6 @@
  6 
  7 #include <inttypes.h>
  8 #include <stdbool.h>
  9-#include <fribidi.h>
 10 #include <ft2build.h>
 11 #include FT_FREETYPE_H
 12 #include FT_GLYPH_H
 13@@ -49,6 +48,8 @@
 14 #define PARSED_FADE (1<<0)
 15 #define PARSED_A    (1<<1)
 16 
 17+typedef uint32_t FriBidiChar;
 18+
 19 typedef struct {
 20     ASS_Image result;
 21     CompositeHashValue *source;
 22diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c
 23index 86f2c66..e72a7d5 100644
 24--- a/libass/ass_shaper.c
 25+++ b/libass/ass_shaper.c
 26@@ -87,8 +87,7 @@ struct ass_shaper_metrics_data {
 27  */
 28 void ass_shaper_info(ASS_Library *lib)
 29 {
 30-    ass_msg(lib, MSGL_INFO, "Shaper: FriBidi "
 31-            FRIBIDI_VERSION " (SIMPLE)"
 32+    ass_msg(lib, MSGL_INFO, "Shaper: "
 33             " HarfBuzz-ng %s (COMPLEX)", hb_version_string()
 34            );
 35 }
 36@@ -705,8 +704,7 @@ static bool shape_harfbuzz(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
 37                     lead_context, i - offset + 1);
 38         }
 39 
 40-        props.direction = FRIBIDI_LEVEL_IS_RTL(level) ?
 41-            HB_DIRECTION_RTL : HB_DIRECTION_LTR;
 42+        props.direction = HB_DIRECTION_LTR;
 43         props.script = glyphs[offset].script;
 44         props.language  = hb_shaper_get_run_language(shaper, props.script);
 45         hb_buffer_set_segment_properties(buf, &props);
 46@@ -774,35 +772,6 @@ void ass_shaper_determine_script(ASS_Shaper *shaper, GlyphInfo *glyphs,
 47     }
 48 }
 49 
 50-/**
 51- * \brief Shape event text with FriBidi. Does mirroring and simple
 52- * Arabic shaping.
 53- * \param len number of clusters
 54- */
 55-static void shape_fribidi(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
 56-{
 57-    int i;
 58-    FriBidiJoiningType *joins = calloc(len, sizeof(*joins));
 59-
 60-    // shape on codepoint level
 61-    fribidi_get_joining_types(shaper->event_text, len, joins);
 62-    fribidi_join_arabic(shaper->ctypes, len, shaper->emblevels, joins);
 63-    fribidi_shape(FRIBIDI_FLAGS_DEFAULT | FRIBIDI_FLAGS_ARABIC,
 64-            shaper->emblevels, len, joins, shaper->event_text);
 65-
 66-    // update indexes
 67-    for (i = 0; i < len; i++) {
 68-        GlyphInfo *info = glyphs + i;
 69-        FT_Face face = info->font->faces[info->face_index];
 70-        info->symbol = shaper->event_text[i];
 71-        info->glyph_index = ass_font_index_magic(face, shaper->event_text[i]);
 72-        if (info->glyph_index)
 73-            info->glyph_index = FT_Get_Char_Index(face, info->glyph_index);
 74-    }
 75-
 76-    free(joins);
 77-}
 78-
 79 /**
 80  * \brief Toggle kerning for HarfBuzz shaping.
 81  * \param shaper shaper instance
 82@@ -895,7 +864,7 @@ void ass_shaper_set_base_direction(ASS_Shaper *shaper, FriBidiParType dir)
 83     shaper->base_direction = dir;
 84 
 85     if (shaper->whole_text_layout != WHOLE_TEXT_LAYOUT_EXPLICIT)
 86-        shaper->whole_text_layout = dir == FRIBIDI_PAR_ON ?
 87+        shaper->whole_text_layout = dir == 0 ?
 88             WHOLE_TEXT_LAYOUT_IMPLICIT : WHOLE_TEXT_LAYOUT_OFF;
 89 }
 90 
 91@@ -935,7 +904,7 @@ void ass_shaper_set_whole_text_layout(ASS_Shaper *shaper, bool enable)
 92 {
 93     shaper->whole_text_layout = enable ?
 94         WHOLE_TEXT_LAYOUT_EXPLICIT :
 95-        shaper->base_direction == FRIBIDI_PAR_ON ?
 96+        shaper->base_direction == 0 ?
 97             WHOLE_TEXT_LAYOUT_IMPLICIT : WHOLE_TEXT_LAYOUT_OFF;
 98 }
 99 
100@@ -946,8 +915,7 @@ void ass_shaper_set_whole_text_layout(ASS_Shaper *shaper, bool enable)
101  */
102 bool ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
103 {
104-    int i, ret, last_break;
105-    FriBidiParType dir, *pdir;
106+    int i;
107     GlyphInfo *glyphs = text_info->glyphs;
108     shaper->event_text = text_info->event_text;
109 
110@@ -957,61 +925,7 @@ bool ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
111     for (i = 0; i < text_info->length; i++)
112         shaper->event_text[i] = glyphs[i].symbol;
113 
114-    fribidi_get_bidi_types(shaper->event_text,
115-            text_info->length, shaper->ctypes);
116-
117-    int n_pars = 1;
118-    for (i = 0; i < text_info->length - 1; i++)
119-        if (shaper->ctypes[i] == FRIBIDI_TYPE_BS)
120-            n_pars++;
121-
122-    if (!check_par_allocations(shaper, n_pars))
123-        return false;
124-
125-#ifdef USE_FRIBIDI_EX_API
126-    if (shaper->bidi_brackets) {
127-        fribidi_get_bracket_types(shaper->event_text,
128-                text_info->length, shaper->ctypes, shaper->btypes);
129-    }
130-#endif
131-
132-    // Get bidi embedding levels
133-    last_break = 0;
134-    pdir = shaper->pbase_dir;
135-    for (i = 0; i < text_info->length; i++) {
136-        // Embedding levels must be calculated one bidi "paragraph" at a time
137-        if (i == text_info->length - 1 ||
138-                shaper->ctypes[i] == FRIBIDI_TYPE_BS ||
139-                (!shaper->whole_text_layout &&
140-                    (glyphs[i + 1].starts_new_run || glyphs[i].hspacing))) {
141-            dir = shaper->base_direction;
142-#ifdef USE_FRIBIDI_EX_API
143-            FriBidiBracketType *btypes = NULL;
144-            if (shaper->bidi_brackets)
145-                btypes = shaper->btypes + last_break;
146-            ret = fribidi_get_par_embedding_levels_ex(
147-                    shaper->ctypes + last_break, btypes,
148-                    i - last_break + 1, &dir, shaper->emblevels + last_break);
149-#else
150-            ret = fribidi_get_par_embedding_levels(shaper->ctypes + last_break,
151-                    i - last_break + 1, &dir, shaper->emblevels + last_break);
152-#endif
153-            if (ret == 0)
154-                return false;
155-            last_break = i + 1;
156-            if (shaper->whole_text_layout)
157-                *pdir++ = dir;
158-        }
159-    }
160-
161-    switch (shaper->shaping_level) {
162-    case ASS_SHAPING_SIMPLE:
163-        shape_fribidi(shaper, glyphs, text_info->length);
164-        return true;
165-    case ASS_SHAPING_COMPLEX:
166-    default:
167-        return shape_harfbuzz(shaper, glyphs, text_info->length);
168-    }
169+    return shape_harfbuzz(shaper, glyphs, text_info->length);
170 }
171 
172 /**
173@@ -1025,7 +939,7 @@ ASS_Shaper *ass_shaper_new(Cache *metrics_cache, Cache *face_size_metrics_cache)
174     if (!shaper)
175         return NULL;
176 
177-    shaper->base_direction = FRIBIDI_PAR_ON;
178+    shaper->base_direction = 0;
179 
180     if (!init_features(shaper))
181         goto error;
182@@ -1087,38 +1001,12 @@ void ass_shaper_cleanup(ASS_Shaper *shaper, TextInfo *text_info)
183  */
184 FriBidiStrIndex *ass_shaper_reorder(ASS_Shaper *shaper, TextInfo *text_info)
185 {
186-    int i, ret;
187+    int i;
188 
189     // Initialize reorder map
190     for (i = 0; i < text_info->length; i++)
191         shaper->cmap[i] = i;
192 
193-    // Create reorder map line-by-line or run-by-run
194-    int last_break = 0;
195-    FriBidiParType *pdir = shaper->whole_text_layout ?
196-        shaper->pbase_dir : &shaper->base_direction;
197-    GlyphInfo *glyphs = text_info->glyphs;
198-    for (i = 0; i < text_info->length; i++) {
199-        // Bidi "paragraph separators" may occur between line breaks:
200-        // U+001C..1E even with ASS_FEATURE_WRAP_UNICODE,
201-        // or U+000D, U+0085, U+2029 only without it
202-        if (i == text_info->length - 1 || glyphs[i + 1].linebreak ||
203-                shaper->ctypes[i] == FRIBIDI_TYPE_BS ||
204-                (!shaper->whole_text_layout &&
205-                    (glyphs[i + 1].starts_new_run || glyphs[i].hspacing))) {
206-            ret = fribidi_reorder_line(0,
207-                    shaper->ctypes, i - last_break + 1, last_break, *pdir,
208-                    shaper->emblevels, NULL,
209-                    shaper->cmap);
210-            if (ret == 0)
211-                return NULL;
212-
213-            last_break = i + 1;
214-            if (shaper->whole_text_layout && shaper->ctypes[i] == FRIBIDI_TYPE_BS)
215-                pdir++;
216-        }
217-    }
218-
219     return shaper->cmap;
220 }
221 
222@@ -1136,10 +1024,5 @@ FriBidiStrIndex *ass_shaper_get_reorder_map(ASS_Shaper *shaper)
223  */
224 FriBidiParType ass_resolve_base_direction(int enc)
225 {
226-    switch (enc) {
227-        case -1:
228-            return FRIBIDI_PAR_ON;
229-        default:
230-            return FRIBIDI_PAR_LTR;
231-    }
232+    return 0;
233 }
234diff --git a/libass/ass_shaper.h b/libass/ass_shaper.h
235index 06f868d..333252b 100644
236--- a/libass/ass_shaper.h
237+++ b/libass/ass_shaper.h
238@@ -21,14 +21,15 @@
239 
240 typedef struct ass_shaper ASS_Shaper;
241 
242-#include <fribidi.h>
243 #include <stdbool.h>
244 #include "ass_render.h"
245 #include "ass_cache.h"
246 
247-#if FRIBIDI_MAJOR_VERSION >= 1
248-#define USE_FRIBIDI_EX_API
249-#endif
250+typedef uint32_t FriBidiChar;
251+typedef uint32_t FriBidiCharType;
252+typedef int FriBidiStrIndex;
253+typedef int FriBidiParType;
254+typedef signed char FriBidiLevel;
255 
256 void ass_shaper_info(ASS_Library *lib);
257 ASS_Shaper *ass_shaper_new(Cache *metrics_cache, Cache *face_size_metrics_cache);
258diff --git a/meson.build b/meson.build
259index 9eb7969..bc40a57 100644
260--- a/meson.build
261+++ b/meson.build
262@@ -87,12 +87,6 @@ deps += dependency(
263     default_options: ['harfbuzz=disabled'],
264 )
265 
266-deps += dependency(
267-    'fribidi',
268-    version: '>= 0.19.1',
269-    default_options: ['docs=false', 'tests=false'],
270-)
271-
272 harfbuzz_options = [
273     'tests=disabled',
274     'cairo=disabled',
275