1From 4b793f41cce613bdf458477846e592ce1db4a5b2 Mon Sep 17 00:00:00 2001
2From: hovercats <hovercatswithlasereyes@protonmail.com>
3Date: Wed, 30 Apr 2025 13:15:55 +0200
4Subject: [PATCH] ass_shaper: remove fribidi dependency
5
6---
7 libass/ass_shaper.c | 107 ++------------------------------------------
8 libass/ass_shaper.h | 3 +-
9 2 files changed, 6 insertions(+), 104 deletions(-)
10
11diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c
12index 657885b..d8c77ff 100644
13--- a/libass/ass_shaper.c
14+++ b/libass/ass_shaper.c
15@@ -44,9 +44,6 @@ struct ass_shaper {
16
17 // FriBidi log2vis
18 int n_glyphs;
19- FriBidiChar *event_text;
20- FriBidiCharType *ctypes;
21- FriBidiLevel *emblevels;
22 FriBidiStrIndex *cmap;
23 FriBidiParType base_direction;
24
25@@ -80,8 +77,7 @@ struct ass_shaper_font_data {
26 */
27 void ass_shaper_info(ASS_Library *lib)
28 {
29- ass_msg(lib, MSGL_INFO, "Shaper: FriBidi "
30- FRIBIDI_VERSION " (SIMPLE)"
31+ ass_msg(lib, MSGL_INFO, "Shaper:"
32 #ifdef CONFIG_HARFBUZZ
33 " HarfBuzz-ng %s (COMPLEX)", hb_version_string()
34 #endif
35@@ -95,10 +91,7 @@ void ass_shaper_info(ASS_Library *lib)
36 static bool check_allocations(ASS_Shaper *shaper, size_t new_size)
37 {
38 if (new_size > shaper->n_glyphs) {
39- if (!ASS_REALLOC_ARRAY(shaper->event_text, new_size) ||
40- !ASS_REALLOC_ARRAY(shaper->ctypes, new_size) ||
41- !ASS_REALLOC_ARRAY(shaper->emblevels, new_size) ||
42- !ASS_REALLOC_ARRAY(shaper->cmap, new_size))
43+ if (!ASS_REALLOC_ARRAY(shaper->cmap, new_size))
44 return false;
45 shaper->n_glyphs = new_size;
46 }
47@@ -114,9 +107,6 @@ void ass_shaper_free(ASS_Shaper *shaper)
48 ass_cache_done(shaper->metrics_cache);
49 free(shaper->features);
50 #endif
51- free(shaper->event_text);
52- free(shaper->ctypes);
53- free(shaper->emblevels);
54 free(shaper->cmap);
55 free(shaper);
56 }
57@@ -688,33 +678,6 @@ void ass_shaper_determine_script(ASS_Shaper *shaper, GlyphInfo *glyphs,
58 }
59 #endif
60
61-/**
62- * \brief Shape event text with FriBidi. Does mirroring and simple
63- * Arabic shaping.
64- * \param len number of clusters
65- */
66-static void shape_fribidi(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
67-{
68- int i;
69- FriBidiJoiningType *joins = calloc(sizeof(*joins), len);
70-
71- // shape on codepoint level
72- fribidi_get_joining_types(shaper->event_text, len, joins);
73- fribidi_join_arabic(shaper->ctypes, len, shaper->emblevels, joins);
74- fribidi_shape(FRIBIDI_FLAGS_DEFAULT | FRIBIDI_FLAGS_ARABIC,
75- shaper->emblevels, len, joins, shaper->event_text);
76-
77- // update indexes
78- for (i = 0; i < len; i++) {
79- GlyphInfo *info = glyphs + i;
80- FT_Face face = info->font->faces[info->face_index];
81- info->symbol = shaper->event_text[i];
82- info->glyph_index = FT_Get_Char_Index(face, ass_font_index_magic(face, shaper->event_text[i]));
83- }
84-
85- free(joins);
86-}
87-
88 /**
89 * \brief Toggle kerning for HarfBuzz shaping.
90 * \param shaper shaper instance
91@@ -852,50 +815,7 @@ static void ass_shaper_skip_characters(TextInfo *text_info)
92 */
93 int ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
94 {
95- int i, ret, last_break;
96- FriBidiParType dir;
97- GlyphInfo *glyphs = text_info->glyphs;
98-
99- if (!check_allocations(shaper, text_info->length))
100- return -1;
101-
102- // Get bidi character types and embedding levels
103- last_break = 0;
104- for (i = 0; i < text_info->length; i++) {
105- shaper->event_text[i] = glyphs[i].symbol;
106- // embedding levels should be calculated paragraph by paragraph
107- if (glyphs[i].symbol == '\n' || i == text_info->length - 1) {
108- dir = shaper->base_direction;
109- fribidi_get_bidi_types(shaper->event_text + last_break,
110- i - last_break + 1, shaper->ctypes + last_break);
111- ret = fribidi_get_par_embedding_levels(shaper->ctypes + last_break,
112- i - last_break + 1, &dir, shaper->emblevels + last_break);
113- if (ret == 0)
114- return -1;
115- last_break = i + 1;
116- }
117- }
118-
119- // add embedding levels to shape runs for final runs
120- for (i = 0; i < text_info->length; i++) {
121- glyphs[i].shape_run_id += shaper->emblevels[i];
122- }
123-
124-#ifdef CONFIG_HARFBUZZ
125- switch (shaper->shaping_level) {
126- case ASS_SHAPING_SIMPLE:
127- shape_fribidi(shaper, glyphs, text_info->length);
128- ass_shaper_skip_characters(text_info);
129- break;
130- case ASS_SHAPING_COMPLEX:
131- shape_harfbuzz(shaper, glyphs, text_info->length);
132- break;
133- }
134-#else
135- shape_fribidi(shaper, glyphs, text_info->length);
136- ass_shaper_skip_characters(text_info);
137-#endif
138-
139+ check_allocations(shaper, text_info->length);
140 return 0;
141 }
142
143@@ -909,7 +829,6 @@ ASS_Shaper *ass_shaper_new(size_t prealloc)
144 if (!shaper)
145 return NULL;
146
147- shaper->base_direction = FRIBIDI_PAR_ON;
148 if (!check_allocations(shaper, prealloc))
149 goto error;
150
151@@ -962,19 +881,6 @@ FriBidiStrIndex *ass_shaper_reorder(ASS_Shaper *shaper, TextInfo *text_info)
152 for (i = 0; i < text_info->length; i++)
153 shaper->cmap[i] = i;
154
155- // Create reorder map line-by-line
156- for (i = 0; i < text_info->n_lines; i++) {
157- LineInfo *line = text_info->lines + i;
158- FriBidiParType dir = FRIBIDI_PAR_ON;
159-
160- ret = fribidi_reorder_line(0,
161- shaper->ctypes + line->offset, line->len, 0, dir,
162- shaper->emblevels + line->offset, NULL,
163- shaper->cmap + line->offset);
164- if (ret == 0)
165- return NULL;
166- }
167-
168 return shaper->cmap;
169 }
170
171@@ -987,10 +893,5 @@ FriBidiStrIndex *ass_shaper_reorder(ASS_Shaper *shaper, TextInfo *text_info)
172 */
173 FriBidiParType resolve_base_direction(int enc)
174 {
175- switch (enc) {
176- case -1:
177- return FRIBIDI_PAR_ON;
178- default:
179- return FRIBIDI_PAR_LTR;
180- }
181+ return 0;
182 }
183diff --git a/libass/ass_shaper.h b/libass/ass_shaper.h
184index f6404fe..69a7ea9 100644
185--- a/libass/ass_shaper.h
186+++ b/libass/ass_shaper.h
187@@ -21,7 +21,8 @@
188
189 typedef struct ass_shaper ASS_Shaper;
190
191-#include <fribidi.h>
192+typedef int FriBidiParType;
193+typedef int FriBidiStrIndex;
194 #include "ass_render.h"
195
196 void ass_shaper_info(ASS_Library *lib);
197--
1982.49.0
199