summaryrefslogtreecommitdiffstats
path: root/libass
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@blackbox>2012-10-01 17:37:00 +0200
committerGrigori Goronzy <greg@blackbox>2012-10-01 17:37:00 +0200
commit840ce4c2d9381e340c3239d104933fea85fff3e5 (patch)
treec113cc481f569a9e6e253db40b94cc7775761c55 /libass
parent146d60f698e9a5ef79e68a27e768d2f4dd40068d (diff)
downloadlibass-840ce4c2d9381e340c3239d104933fea85fff3e5.tar.bz2
libass-840ce4c2d9381e340c3239d104933fea85fff3e5.tar.xz
shaper: add UCDN support
Add explicit support for UCDN, without relying on any HarfBuzz integration. This finally allows easy usage of HarfBuzz without glib, ICU, or some other big bloated library!
Diffstat (limited to 'libass')
-rw-r--r--libass/Makefile.am2
-rw-r--r--libass/ass_shaper.c13
-rw-r--r--libass/hb-ucdn.h198
3 files changed, 212 insertions, 1 deletions
diff --git a/libass/Makefile.am b/libass/Makefile.am
index 142de68..2b7cf55 100644
--- a/libass/Makefile.am
+++ b/libass/Makefile.am
@@ -11,7 +11,7 @@ libass_la_SOURCES = ass.c ass_cache.c ass_font.c ass_fontconfig.c ass_render.c \
ass_library.h ass_types.h ass_utils.h ass_drawing.c \
ass_drawing.h ass_cache_template.h ass_render.h \
ass_parse.c ass_parse.h ass_render_api.c ass_shaper.c \
- ass_shaper.h ass_strtod.c
+ ass_shaper.h ass_strtod.c hb-ucdn.h
libass_la_LDFLAGS = -version-info $(LIBASS_LT_CURRENT):$(LIBASS_LT_REVISION):$(LIBASS_LT_AGE)
libass_la_LDFLAGS += -export-symbols $(srcdir)/libass.sym
diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c
index 89ea97a..16f1c35 100644
--- a/libass/ass_shaper.c
+++ b/libass/ass_shaper.c
@@ -29,6 +29,9 @@
#define MAX_RUNS 50
#ifdef CONFIG_HARFBUZZ
+#ifdef CONFIG_UCDN
+#include "hb-ucdn.h"
+#endif
#include <hb-ft.h>
enum {
VERT = 0,
@@ -57,6 +60,7 @@ struct ass_shaper {
// Glyph metrics cache, to speed up shaping
Cache *metrics_cache;
+ hb_unicode_funcs_t *unicode_funcs;
#endif
};
@@ -108,6 +112,9 @@ void ass_shaper_free(ASS_Shaper *shaper)
{
#ifdef CONFIG_HARFBUZZ
ass_cache_done(shaper->metrics_cache);
+#ifdef CONFIG_UCDN
+ hb_unicode_funcs_destroy(shaper->unicode_funcs);
+#endif
free(shaper->features);
#endif
free(shaper->event_text);
@@ -435,6 +442,9 @@ static void shape_harfbuzz(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len)
runs[run].buf = hb_buffer_create();
runs[run].font = get_hb_font(shaper, glyphs + k);
set_run_features(shaper, glyphs + k);
+#ifdef CONFIG_UCDN
+ hb_buffer_set_unicode_funcs(runs[run].buf, shaper->unicode_funcs);
+#endif
hb_buffer_pre_allocate(runs[run].buf, i - k + 1);
hb_buffer_set_direction(runs[run].buf, direction ? HB_DIRECTION_RTL :
HB_DIRECTION_LTR);
@@ -662,6 +672,9 @@ ASS_Shaper *ass_shaper_new(size_t prealloc)
#ifdef CONFIG_HARFBUZZ
init_features(shaper);
shaper->metrics_cache = ass_glyph_metrics_cache_create();
+#ifdef CONFIG_UCDN
+ shaper->unicode_funcs = hb_ucdn_make_unicode_funcs();
+#endif
#endif
return shaper;
diff --git a/libass/hb-ucdn.h b/libass/hb-ucdn.h
new file mode 100644
index 0000000..3a4abcd
--- /dev/null
+++ b/libass/hb-ucdn.h
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2012 Grigori Goronzy <greg@kinoho.net>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <hb.h>
+#include "ucdn.h"
+
+static const hb_script_t ucdn_script_translate[] = {
+ HB_SCRIPT_COMMON,
+ HB_SCRIPT_LATIN,
+ HB_SCRIPT_GREEK,
+ HB_SCRIPT_CYRILLIC,
+ HB_SCRIPT_ARMENIAN,
+ HB_SCRIPT_HEBREW,
+ HB_SCRIPT_ARABIC,
+ HB_SCRIPT_SYRIAC,
+ HB_SCRIPT_THAANA,
+ HB_SCRIPT_DEVANAGARI,
+ HB_SCRIPT_BENGALI,
+ HB_SCRIPT_GURMUKHI,
+ HB_SCRIPT_GUJARATI,
+ HB_SCRIPT_ORIYA,
+ HB_SCRIPT_TAMIL,
+ HB_SCRIPT_TELUGU,
+ HB_SCRIPT_KANNADA,
+ HB_SCRIPT_MALAYALAM,
+ HB_SCRIPT_SINHALA,
+ HB_SCRIPT_THAI,
+ HB_SCRIPT_LAO,
+ HB_SCRIPT_TIBETAN,
+ HB_SCRIPT_MYANMAR,
+ HB_SCRIPT_GEORGIAN,
+ HB_SCRIPT_HANGUL,
+ HB_SCRIPT_ETHIOPIC,
+ HB_SCRIPT_CHEROKEE,
+ HB_SCRIPT_CANADIAN_ABORIGINAL,
+ HB_SCRIPT_OGHAM,
+ HB_SCRIPT_RUNIC,
+ HB_SCRIPT_KHMER,
+ HB_SCRIPT_MONGOLIAN,
+ HB_SCRIPT_HIRAGANA,
+ HB_SCRIPT_KATAKANA,
+ HB_SCRIPT_BOPOMOFO,
+ HB_SCRIPT_HAN,
+ HB_SCRIPT_YI,
+ HB_SCRIPT_OLD_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ARAMAIC,
+ HB_SCRIPT_OLD_SOUTH_ARABIAN,
+ HB_SCRIPT_INSCRIPTIONAL_PARTHIAN,
+ HB_SCRIPT_INSCRIPTIONAL_PAHLAVI,
+ HB_SCRIPT_OLD_TURKIC,
+ HB_SCRIPT_KAITHI,
+ HB_SCRIPT_BATAK,
+ HB_SCRIPT_BRAHMI,
+ HB_SCRIPT_MANDAIC,
+ HB_SCRIPT_CHAKMA,
+ HB_SCRIPT_MEROITIC_CURSIVE,
+ HB_SCRIPT_MEROITIC_HIEROGLYPHS,
+ HB_SCRIPT_MIAO,
+ HB_SCRIPT_SHARADA,
+ HB_SCRIPT_SORA_SOMPENG,
+ HB_SCRIPT_TAKRI,
+ HB_SCRIPT_UNKNOWN,
+};
+
+static unsigned int
+hb_ucdn_combining_class(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
+ void *user_data)
+{
+ return ucdn_get_combining_class(unicode);
+}
+
+static unsigned int
+hb_ucdn_eastasian_width(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
+ void *user_data)
+{
+ int w = ucdn_get_east_asian_width(unicode);
+ return (w == UCDN_EAST_ASIAN_F || w == UCDN_EAST_ASIAN_W) ? 2 : 1;
+}
+
+static hb_unicode_general_category_t
+hb_ucdn_general_category(hb_unicode_funcs_t *ufuncs,
+ hb_codepoint_t unicode, void *user_data)
+{
+ return (hb_unicode_general_category_t)ucdn_get_general_category(unicode);
+}
+
+static hb_codepoint_t
+hb_ucdn_mirror(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
+ void *user_data)
+{
+ return ucdn_mirror(unicode);
+}
+
+static hb_script_t
+hb_ucdn_script(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
+ void *user_data)
+{
+ return ucdn_script_translate[ucdn_get_script(unicode)];
+}
+
+static hb_bool_t
+hb_ucdn_compose(hb_unicode_funcs_t *ufuncs, hb_codepoint_t a,
+ hb_codepoint_t b, hb_codepoint_t *ab, void *user_data)
+{
+ return ucdn_compose(ab, a, b);
+}
+
+static hb_bool_t
+hb_ucdn_decompose(hb_unicode_funcs_t *ufuncs, hb_codepoint_t ab,
+ hb_codepoint_t *a, hb_codepoint_t *b, void *user_data)
+{
+ return ucdn_decompose(ab, a, b);
+}
+
+static unsigned int
+hb_ucdn_compat_decompose(hb_unicode_funcs_t *ufuncs, hb_codepoint_t u,
+ hb_codepoint_t *decomposed, void *user_data)
+{
+ return ucdn_compat_decompose(u, decomposed);
+}
+
+static hb_unicode_funcs_t *hb_ucdn_make_unicode_funcs(void)
+{
+ hb_unicode_funcs_t *funcs = hb_unicode_funcs_create(NULL);
+ hb_unicode_funcs_set_combining_class_func(funcs, hb_ucdn_combining_class, NULL, NULL);
+ hb_unicode_funcs_set_eastasian_width_func(funcs, hb_ucdn_eastasian_width, NULL, NULL);
+ hb_unicode_funcs_set_general_category_func(funcs, hb_ucdn_general_category, NULL, NULL);
+ hb_unicode_funcs_set_mirroring_func(funcs, hb_ucdn_mirror, NULL, NULL);
+ hb_unicode_funcs_set_script_func(funcs, hb_ucdn_script, NULL, NULL);
+ hb_unicode_funcs_set_compose_func(funcs, hb_ucdn_compose, NULL, NULL);
+ hb_unicode_funcs_set_decompose_func(funcs, hb_ucdn_decompose, NULL, NULL);
+ hb_unicode_funcs_set_decompose_compatibility_func(funcs, hb_ucdn_compat_decompose, NULL, NULL);
+ hb_unicode_funcs_make_immutable(funcs);
+
+ return funcs;
+}