2022-11-30 18:28:58 -07:00
|
|
|
diff --git a/libass/ass_render.h b/libass/ass_render.h
|
|
|
|
index 581c131..0cb5458 100644
|
|
|
|
--- a/libass/ass_render.h
|
|
|
|
+++ b/libass/ass_render.h
|
|
|
|
@@ -22,7 +22,6 @@
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
-#include <fribidi.h>
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include FT_GLYPH_H
|
|
|
|
@@ -49,6 +48,8 @@
|
|
|
|
#define PARSED_FADE (1<<0)
|
|
|
|
#define PARSED_A (1<<1)
|
|
|
|
|
|
|
|
+typedef uint32_t FriBidiChar;
|
|
|
|
+
|
|
|
|
typedef struct {
|
|
|
|
ASS_Image result;
|
|
|
|
CompositeHashValue *source;
|
2021-07-07 05:02:09 -06:00
|
|
|
diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c
|
2022-11-30 18:28:58 -07:00
|
|
|
index db61963..014b318 100644
|
2021-07-07 05:02:09 -06:00
|
|
|
--- a/libass/ass_shaper.c
|
|
|
|
+++ b/libass/ass_shaper.c
|
2022-05-12 09:51:32 -06:00
|
|
|
@@ -90,8 +90,7 @@ struct ass_shaper_font_data {
|
2021-07-07 05:02:09 -06:00
|
|
|
*/
|
|
|
|
void ass_shaper_info(ASS_Library *lib)
|
|
|
|
{
|
|
|
|
- ass_msg(lib, MSGL_INFO, "Shaper: FriBidi "
|
|
|
|
- FRIBIDI_VERSION " (SIMPLE)"
|
|
|
|
+ ass_msg(lib, MSGL_INFO, "Shaper: "
|
|
|
|
" HarfBuzz-ng %s (COMPLEX)", hb_version_string()
|
|
|
|
);
|
|
|
|
}
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -722,8 +721,7 @@ static bool shape_harfbuzz(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
|
2022-05-12 09:51:32 -06:00
|
|
|
lead_context, i - offset + 1);
|
|
|
|
}
|
2021-07-07 05:02:09 -06:00
|
|
|
|
|
|
|
- props.direction = FRIBIDI_LEVEL_IS_RTL(level) ?
|
|
|
|
- HB_DIRECTION_RTL : HB_DIRECTION_LTR;
|
|
|
|
+ props.direction = HB_DIRECTION_LTR;
|
|
|
|
props.script = glyphs[offset].script;
|
|
|
|
props.language = hb_shaper_get_run_language(shaper, props.script);
|
|
|
|
hb_buffer_set_segment_properties(buf, &props);
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -791,35 +789,6 @@ void ass_shaper_determine_script(ASS_Shaper *shaper, GlyphInfo *glyphs,
|
2022-05-12 09:51:32 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
- * \brief Shape event text with FriBidi. Does mirroring and simple
|
|
|
|
- * Arabic shaping.
|
|
|
|
- * \param len number of clusters
|
|
|
|
- */
|
2021-07-07 05:02:09 -06:00
|
|
|
-static void shape_fribidi(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
|
|
|
|
-{
|
|
|
|
- int i;
|
|
|
|
- FriBidiJoiningType *joins = calloc(sizeof(*joins), len);
|
|
|
|
-
|
|
|
|
- // shape on codepoint level
|
|
|
|
- fribidi_get_joining_types(shaper->event_text, len, joins);
|
|
|
|
- fribidi_join_arabic(shaper->ctypes, len, shaper->emblevels, joins);
|
|
|
|
- fribidi_shape(FRIBIDI_FLAGS_DEFAULT | FRIBIDI_FLAGS_ARABIC,
|
|
|
|
- shaper->emblevels, len, joins, shaper->event_text);
|
|
|
|
-
|
|
|
|
- // update indexes
|
|
|
|
- for (i = 0; i < len; i++) {
|
|
|
|
- GlyphInfo *info = glyphs + i;
|
|
|
|
- FT_Face face = info->font->faces[info->face_index];
|
|
|
|
- info->symbol = shaper->event_text[i];
|
2022-05-12 09:51:32 -06:00
|
|
|
- info->glyph_index = ass_font_index_magic(face, shaper->event_text[i]);
|
|
|
|
- if (info->glyph_index)
|
|
|
|
- info->glyph_index = FT_Get_Char_Index(face, info->glyph_index);
|
2021-07-07 05:02:09 -06:00
|
|
|
- }
|
|
|
|
-
|
|
|
|
- free(joins);
|
|
|
|
-}
|
2022-05-12 09:51:32 -06:00
|
|
|
-
|
2021-07-07 05:02:09 -06:00
|
|
|
/**
|
2021-09-12 21:43:09 -06:00
|
|
|
* \brief Toggle kerning for HarfBuzz shaping.
|
2022-05-12 09:51:32 -06:00
|
|
|
* \param shaper shaper instance
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -912,7 +881,7 @@ void ass_shaper_set_base_direction(ASS_Shaper *shaper, FriBidiParType dir)
|
2022-05-12 09:51:32 -06:00
|
|
|
shaper->base_direction = dir;
|
|
|
|
|
|
|
|
if (shaper->whole_text_layout != WHOLE_TEXT_LAYOUT_EXPLICIT)
|
|
|
|
- shaper->whole_text_layout = dir == FRIBIDI_PAR_ON ?
|
|
|
|
+ shaper->whole_text_layout = dir == 0 ?
|
|
|
|
WHOLE_TEXT_LAYOUT_IMPLICIT : WHOLE_TEXT_LAYOUT_OFF;
|
|
|
|
}
|
|
|
|
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -952,7 +921,7 @@ void ass_shaper_set_whole_text_layout(ASS_Shaper *shaper, bool enable)
|
2022-05-12 09:51:32 -06:00
|
|
|
{
|
|
|
|
shaper->whole_text_layout = enable ?
|
|
|
|
WHOLE_TEXT_LAYOUT_EXPLICIT :
|
|
|
|
- shaper->base_direction == FRIBIDI_PAR_ON ?
|
|
|
|
+ shaper->base_direction == 0 ?
|
|
|
|
WHOLE_TEXT_LAYOUT_IMPLICIT : WHOLE_TEXT_LAYOUT_OFF;
|
|
|
|
}
|
|
|
|
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -963,8 +932,7 @@ void ass_shaper_set_whole_text_layout(ASS_Shaper *shaper, bool enable)
|
2021-07-07 05:02:09 -06:00
|
|
|
*/
|
|
|
|
bool ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
|
|
|
|
{
|
|
|
|
- int i, ret, last_break;
|
2022-05-12 09:51:32 -06:00
|
|
|
- FriBidiParType dir, *pdir;
|
2021-07-07 05:02:09 -06:00
|
|
|
+ int i;
|
|
|
|
GlyphInfo *glyphs = text_info->glyphs;
|
2022-11-30 18:28:58 -07:00
|
|
|
shaper->event_text = text_info->event_text;
|
2021-07-07 05:02:09 -06:00
|
|
|
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -979,52 +947,7 @@ bool ass_shaper_shape(ASS_Shaper *shaper, TextInfo *text_info)
|
2022-05-12 09:51:32 -06:00
|
|
|
for (i = 0; i < text_info->length; i++)
|
|
|
|
shaper->event_text[i] = glyphs[i].symbol;
|
2021-07-07 05:02:09 -06:00
|
|
|
|
2022-05-12 09:51:32 -06:00
|
|
|
- fribidi_get_bidi_types(shaper->event_text,
|
|
|
|
- text_info->length, shaper->ctypes);
|
|
|
|
-
|
|
|
|
-#ifdef USE_FRIBIDI_EX_API
|
|
|
|
- if (shaper->bidi_brackets) {
|
|
|
|
- fribidi_get_bracket_types(shaper->event_text,
|
|
|
|
- text_info->length, shaper->ctypes, shaper->btypes);
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
- // Get bidi embedding levels
|
2021-07-07 05:02:09 -06:00
|
|
|
- last_break = 0;
|
2022-05-12 09:51:32 -06:00
|
|
|
- pdir = shaper->pbase_dir;
|
|
|
|
- for (i = 0; i < text_info->length; i++) {
|
2021-07-07 05:02:09 -06:00
|
|
|
- // embedding levels should be calculated paragraph by paragraph
|
2022-05-12 09:51:32 -06:00
|
|
|
- if (glyphs[i].symbol == '\n' || i == text_info->length - 1 ||
|
|
|
|
- (!shaper->whole_text_layout &&
|
|
|
|
- (glyphs[i + 1].starts_new_run || glyphs[i].hspacing))) {
|
2021-07-07 05:02:09 -06:00
|
|
|
- dir = shaper->base_direction;
|
|
|
|
-#ifdef USE_FRIBIDI_EX_API
|
|
|
|
- FriBidiBracketType *btypes = NULL;
|
2022-05-12 09:51:32 -06:00
|
|
|
- if (shaper->bidi_brackets)
|
2021-07-07 05:02:09 -06:00
|
|
|
- btypes = shaper->btypes + last_break;
|
|
|
|
- ret = fribidi_get_par_embedding_levels_ex(
|
|
|
|
- shaper->ctypes + last_break, btypes,
|
|
|
|
- i - last_break + 1, &dir, shaper->emblevels + last_break);
|
|
|
|
-#else
|
|
|
|
- ret = fribidi_get_par_embedding_levels(shaper->ctypes + last_break,
|
|
|
|
- i - last_break + 1, &dir, shaper->emblevels + last_break);
|
|
|
|
-#endif
|
|
|
|
- if (ret == 0)
|
|
|
|
- return false;
|
|
|
|
- last_break = i + 1;
|
2022-05-12 09:51:32 -06:00
|
|
|
- if (shaper->whole_text_layout)
|
|
|
|
- *pdir++ = dir;
|
2021-07-07 05:02:09 -06:00
|
|
|
- }
|
2022-05-12 09:51:32 -06:00
|
|
|
- }
|
|
|
|
-
|
2021-07-07 05:02:09 -06:00
|
|
|
- switch (shaper->shaping_level) {
|
|
|
|
- case ASS_SHAPING_SIMPLE:
|
|
|
|
- shape_fribidi(shaper, glyphs, text_info->length);
|
|
|
|
- return true;
|
|
|
|
- case ASS_SHAPING_COMPLEX:
|
|
|
|
- default:
|
|
|
|
- return shape_harfbuzz(shaper, glyphs, text_info->length);
|
|
|
|
- }
|
|
|
|
+ return shape_harfbuzz(shaper, glyphs, text_info->length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -1038,7 +961,7 @@ ASS_Shaper *ass_shaper_new(Cache *metrics_cache)
|
2021-07-07 05:02:09 -06:00
|
|
|
if (!shaper)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
- shaper->base_direction = FRIBIDI_PAR_ON;
|
|
|
|
+ shaper->base_direction = 0;
|
|
|
|
|
|
|
|
if (!init_features(shaper))
|
|
|
|
goto error;
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -1079,34 +1002,12 @@ void ass_shaper_cleanup(ASS_Shaper *shaper, TextInfo *text_info)
|
2021-07-07 05:02:09 -06:00
|
|
|
*/
|
|
|
|
FriBidiStrIndex *ass_shaper_reorder(ASS_Shaper *shaper, TextInfo *text_info)
|
|
|
|
{
|
|
|
|
- int i, ret;
|
|
|
|
+ int i;
|
|
|
|
|
|
|
|
// Initialize reorder map
|
|
|
|
for (i = 0; i < text_info->length; i++)
|
|
|
|
shaper->cmap[i] = i;
|
|
|
|
|
2022-05-12 09:51:32 -06:00
|
|
|
- // Create reorder map line-by-line or run-by-run
|
|
|
|
- int last_break = 0;
|
|
|
|
- FriBidiParType *pdir = shaper->whole_text_layout ?
|
|
|
|
- shaper->pbase_dir : &shaper->base_direction;
|
|
|
|
- GlyphInfo *glyphs = text_info->glyphs;
|
|
|
|
- for (i = 0; i < text_info->length; i++) {
|
|
|
|
- if (i == text_info->length - 1 || glyphs[i + 1].linebreak ||
|
|
|
|
- (!shaper->whole_text_layout &&
|
|
|
|
- (glyphs[i + 1].starts_new_run || glyphs[i].hspacing))) {
|
|
|
|
- ret = fribidi_reorder_line(0,
|
|
|
|
- shaper->ctypes, i - last_break + 1, last_break, *pdir,
|
|
|
|
- shaper->emblevels, NULL,
|
|
|
|
- shaper->cmap);
|
|
|
|
- if (ret == 0)
|
|
|
|
- return NULL;
|
2021-07-07 05:02:09 -06:00
|
|
|
-
|
2022-05-12 09:51:32 -06:00
|
|
|
- last_break = i + 1;
|
|
|
|
- if (shaper->whole_text_layout)
|
|
|
|
- pdir++;
|
|
|
|
- }
|
2021-07-07 05:02:09 -06:00
|
|
|
- }
|
|
|
|
-
|
|
|
|
return shaper->cmap;
|
|
|
|
}
|
|
|
|
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -1124,10 +1025,5 @@ FriBidiStrIndex *ass_shaper_get_reorder_map(ASS_Shaper *shaper)
|
2021-07-07 05:02:09 -06:00
|
|
|
*/
|
2022-11-30 18:28:58 -07:00
|
|
|
FriBidiParType ass_resolve_base_direction(int enc)
|
2021-07-07 05:02:09 -06:00
|
|
|
{
|
|
|
|
- switch (enc) {
|
|
|
|
- case -1:
|
|
|
|
- return FRIBIDI_PAR_ON;
|
|
|
|
- default:
|
|
|
|
- return FRIBIDI_PAR_LTR;
|
|
|
|
- }
|
|
|
|
+ return 0;
|
|
|
|
}
|
|
|
|
diff --git a/libass/ass_shaper.h b/libass/ass_shaper.h
|
2022-11-30 18:28:58 -07:00
|
|
|
index 819a3fd..3eef8d7 100644
|
2021-07-07 05:02:09 -06:00
|
|
|
--- a/libass/ass_shaper.h
|
|
|
|
+++ b/libass/ass_shaper.h
|
2022-11-30 18:28:58 -07:00
|
|
|
@@ -21,14 +21,15 @@
|
2021-07-07 05:02:09 -06:00
|
|
|
|
|
|
|
typedef struct ass_shaper ASS_Shaper;
|
|
|
|
|
|
|
|
-#include <fribidi.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "ass_render.h"
|
2022-11-30 18:28:58 -07:00
|
|
|
#include "ass_cache.h"
|
2021-07-07 05:02:09 -06:00
|
|
|
|
|
|
|
-#if FRIBIDI_MAJOR_VERSION >= 1
|
|
|
|
-#define USE_FRIBIDI_EX_API
|
|
|
|
-#endif
|
|
|
|
+typedef uint32_t FriBidiChar;
|
|
|
|
+typedef uint32_t FriBidiCharType;
|
|
|
|
+typedef int FriBidiStrIndex;
|
|
|
|
+typedef int FriBidiParType;
|
|
|
|
+typedef signed char FriBidiLevel;
|
|
|
|
|
|
|
|
void ass_shaper_info(ASS_Library *lib);
|
2022-11-30 18:28:58 -07:00
|
|
|
ASS_Shaper *ass_shaper_new(Cache *metrics_cache);
|