]> git.armaanb.net Git - asd-repo.git/blob - junk/libass/patches/no-fribidi.patch
mpv: move to junk
[asd-repo.git] / junk / libass / patches / no-fribidi.patch
1 diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c
2 index ffcb36b..849b55f 100644
3 --- a/libass/ass_shaper.c
4 +++ b/libass/ass_shaper.c
5 @@ -81,8 +81,7 @@ struct ass_shaper_font_data {
6   */
7  void ass_shaper_info(ASS_Library *lib)
8  {
9 -    ass_msg(lib, MSGL_INFO, "Shaper: FriBidi "
10 -            FRIBIDI_VERSION " (SIMPLE)"
11 +    ass_msg(lib, MSGL_INFO, "Shaper: "
12              " HarfBuzz-ng %s (COMPLEX)", hb_version_string()
13             );
14  }
15 @@ -686,8 +685,7 @@ static bool shape_harfbuzz(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
16          hb_buffer_add_utf32(buf, shaper->event_text + offset, i - offset + 1,
17                  0, i - offset + 1);
18  
19 -        props.direction = FRIBIDI_LEVEL_IS_RTL(level) ?
20 -            HB_DIRECTION_RTL : HB_DIRECTION_LTR;
21 +        props.direction = HB_DIRECTION_LTR;
22          props.script = glyphs[offset].script;
23          props.language  = hb_shaper_get_run_language(shaper, props.script);
24          hb_buffer_set_segment_properties(buf, &props);
25 @@ -754,33 +752,6 @@ void ass_shaper_determine_script(ASS_Shaper *shaper, GlyphInfo *glyphs,
26      }
27  }
28  
29 -/**
30 - * \brief Shape event text with FriBidi. Does mirroring and simple
31 - * Arabic shaping.
32 - * \param len number of clusters
33 - */
34 -static void shape_fribidi(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
35 -{
36 -    int i;
37 -    FriBidiJoiningType *joins = calloc(sizeof(*joins), len);
38 -
39 -    // shape on codepoint level
40 -    fribidi_get_joining_types(shaper->event_text, len, joins);
41 -    fribidi_join_arabic(shaper->ctypes, len, shaper->emblevels, joins);
42 -    fribidi_shape(FRIBIDI_FLAGS_DEFAULT | FRIBIDI_FLAGS_ARABIC,
43 -            shaper->emblevels, len, joins, shaper->event_text);
44 -
45 -    // update indexes
46 -    for (i = 0; i < len; i++) {
47 -        GlyphInfo *info = glyphs + i;
48 -        FT_Face face = info->font->faces[info->face_index];
49 -        info->symbol = shaper->event_text[i];
50 -        info->glyph_index = FT_Get_Char_Index(face, ass_font_index_magic(face, shaper->event_text[i]));
51 -    }
52 -
53 -    free(joins);
54 -}
55 -
56  /**
57   * \brief Toggle kerning for HarfBuzz shaping.
58   * \param shaper shaper instance
59 @@ -864,33 +835,6 @@ void ass_shaper_set_bidi_brackets(ASS_Shaper *shaper, bool match_brackets)
60  }
61  #endif
62  
63 -/**
64 -  * \brief Remove all zero-width invisible characters from the text.
65 -  * \param text_info text
66 -  */
67 -static void ass_shaper_skip_characters(TextInfo *text_info)
68 -{
69 -    int i;
70 -    GlyphInfo *glyphs = text_info->glyphs;
71 -
72 -    for (i = 0; i < text_info->length; i++) {
73 -        // Skip direction override control characters
74 -        if ((glyphs[i].symbol <= 0x202e && glyphs[i].symbol >= 0x202a)
75 -                || (glyphs[i].symbol <= 0x200f && glyphs[i].symbol >= 0x200b)
76 -                || (glyphs[i].symbol <= 0x206f && glyphs[i].symbol >= 0x2060)
77 -                || (glyphs[i].symbol <= 0xfe0f && glyphs[i].symbol >= 0xfe00)
78 -                || (glyphs[i].symbol <= 0xe01ef && glyphs[i].symbol >= 0xe0100)
79 -                || (glyphs[i].symbol <= 0x180f && glyphs[i].symbol >= 0x180b)
80 -                || glyphs[i].symbol == 0x061c
81 -                || glyphs[i].symbol == 0xfeff
82 -                || glyphs[i].symbol == 0x00ad
83 -                || glyphs[i].symbol == 0x034f) {
84 -            glyphs[i].symbol = 0;
85 -            glyphs[i].skip = true;
86 -        }
87 -    }
88 -}
89 -
90  /**
91   * \brief Shape an event's text. Calculates directional runs and shapes them.
92   * \param text_info event's text
93 @@ -898,52 +842,18 @@ static void ass_shaper_skip_characters(TextInfo *text_info)
94   */
95  bool ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
96  {
97 -    int i, ret, last_break;
98 -    FriBidiParType dir;
99 +    int i;
100      GlyphInfo *glyphs = text_info->glyphs;
101  
102      if (!check_allocations(shaper, text_info->length))
103          return false;
104  
105      // Get bidi character types and embedding levels
106 -    last_break = 0;
107      for (i = 0; i < text_info->length; i++) {
108          shaper->event_text[i] = glyphs[i].symbol;
109 -        // embedding levels should be calculated paragraph by paragraph
110 -        if (glyphs[i].symbol == '\n' || i == text_info->length - 1) {
111 -            dir = shaper->base_direction;
112 -            fribidi_get_bidi_types(shaper->event_text + last_break,
113 -                    i - last_break + 1, shaper->ctypes + last_break);
114 -#ifdef USE_FRIBIDI_EX_API
115 -            FriBidiBracketType *btypes = NULL;
116 -            if (shaper->bidi_brackets) {
117 -                btypes = shaper->btypes + last_break;
118 -                fribidi_get_bracket_types(shaper->event_text + last_break,
119 -                        i - last_break + 1, shaper->ctypes + last_break,
120 -                        btypes);
121 -            }
122 -            ret = fribidi_get_par_embedding_levels_ex(
123 -                    shaper->ctypes + last_break, btypes,
124 -                    i - last_break + 1, &dir, shaper->emblevels + last_break);
125 -#else
126 -            ret = fribidi_get_par_embedding_levels(shaper->ctypes + last_break,
127 -                    i - last_break + 1, &dir, shaper->emblevels + last_break);
128 -#endif
129 -            if (ret == 0)
130 -                return false;
131 -            last_break = i + 1;
132 -        }
133      }
134  
135 -    switch (shaper->shaping_level) {
136 -    case ASS_SHAPING_SIMPLE:
137 -        shape_fribidi(shaper, glyphs, text_info->length);
138 -        ass_shaper_skip_characters(text_info);
139 -        return true;
140 -    case ASS_SHAPING_COMPLEX:
141 -    default:
142 -        return shape_harfbuzz(shaper, glyphs, text_info->length);
143 -    }
144 +    return shape_harfbuzz(shaper, glyphs, text_info->length);
145  }
146  
147  /**
148 @@ -955,7 +865,7 @@ ASS_Shaper *ass_shaper_new(void)
149      if (!shaper)
150          return NULL;
151  
152 -    shaper->base_direction = FRIBIDI_PAR_ON;
153 +    shaper->base_direction = 0;
154  
155      if (!init_features(shaper))
156          goto error;
157 @@ -998,25 +908,12 @@ void ass_shaper_cleanup(ASS_Shaper *shaper, TextInfo *text_info)
158   */
159  FriBidiStrIndex *ass_shaper_reorder(ASS_Shaper *shaper, TextInfo *text_info)
160  {
161 -    int i, ret;
162 +    int i;
163  
164      // Initialize reorder map
165      for (i = 0; i < text_info->length; i++)
166          shaper->cmap[i] = i;
167  
168 -    // Create reorder map line-by-line
169 -    for (i = 0; i < text_info->n_lines; i++) {
170 -        LineInfo *line = text_info->lines + i;
171 -        FriBidiParType dir = FRIBIDI_PAR_ON;
172 -
173 -        ret = fribidi_reorder_line(0,
174 -                shaper->ctypes + line->offset, line->len, 0, dir,
175 -                shaper->emblevels + line->offset, NULL,
176 -                shaper->cmap + line->offset);
177 -        if (ret == 0)
178 -            return NULL;
179 -    }
180 -
181      return shaper->cmap;
182  }
183  
184 @@ -1034,10 +931,5 @@ FriBidiStrIndex *ass_shaper_get_reorder_map(ASS_Shaper *shaper)
185   */
186  FriBidiParType resolve_base_direction(int enc)
187  {
188 -    switch (enc) {
189 -        case -1:
190 -            return FRIBIDI_PAR_ON;
191 -        default:
192 -            return FRIBIDI_PAR_LTR;
193 -    }
194 +    return 0;
195  }
196 diff --git a/libass/ass_shaper.h b/libass/ass_shaper.h
197 index 70bec9a..c0ff055 100644
198 --- a/libass/ass_shaper.h
199 +++ b/libass/ass_shaper.h
200 @@ -21,13 +21,14 @@
201  
202  typedef struct ass_shaper ASS_Shaper;
203  
204 -#include <fribidi.h>
205  #include <stdbool.h>
206  #include "ass_render.h"
207  
208 -#if FRIBIDI_MAJOR_VERSION >= 1
209 -#define USE_FRIBIDI_EX_API
210 -#endif
211 +typedef uint32_t FriBidiChar;
212 +typedef uint32_t FriBidiCharType;
213 +typedef int FriBidiStrIndex;
214 +typedef int FriBidiParType;
215 +typedef signed char FriBidiLevel;
216  
217  void ass_shaper_info(ASS_Library *lib);
218  ASS_Shaper *ass_shaper_new(void);