commit f07dd54

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