From 80e9b3c0f277824c4223b2f3dac91e86b2333f77 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 16 Feb 2013 22:51:10 +0100 Subject: cleanup: remove duplicated function, move escape parsing function --- sub/osd_libass.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'sub') diff --git a/sub/osd_libass.c b/sub/osd_libass.c index 051383f78e..bbd925f135 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -20,12 +20,14 @@ #include #include +#include + #include "config.h" #include "talloc.h" +#include "core/mp_common.h" #include "core/mp_msg.h" #include "sub.h" -#include "libavutil/common.h" static const char osd_font_pfb[] = #include "sub/osd_font.h" @@ -102,15 +104,6 @@ static void clear_obj(struct osd_object *obj) ass_flush_events(obj->osd_track); } -static char *append_utf8_buffer(char *buffer, uint32_t codepoint) -{ - char data[8]; - uint8_t tmp; - char *output = data; - PUT_UTF8(codepoint, tmp, *output++ = tmp;); - return talloc_strndup_append_buffer(buffer, data, output - data); -} - void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function) { // 0xFF is never valid UTF-8, so we can use it to escape OSD symbols. @@ -124,7 +117,7 @@ static char *mangle_ass(const char *in) // As used by osd_get_function_sym(). if (in[0] == '\xFF' && in[1]) { res = talloc_strdup_append_buffer(res, ASS_USE_OSD_FONT); - res = append_utf8_buffer(res, OSD_CODEPOINTS + in[1]); + res = mp_append_utf8_buffer(res, OSD_CODEPOINTS + in[1]); res = talloc_strdup_append_buffer(res, "{\\r}"); in += 2; continue; @@ -134,7 +127,7 @@ static char *mangle_ass(const char *in) res = talloc_strndup_append_buffer(res, in, 1); // Break ASS escapes with U+2060 WORD JOINER if (*in == '\\') - res = append_utf8_buffer(res, 0x2060); + res = mp_append_utf8_buffer(res, 0x2060); in++; } return res; @@ -207,10 +200,10 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj) if (osd->progbar_type == 0 || osd->progbar_type >= 256) { // no sym } else if (osd->progbar_type >= 32) { - text = append_utf8_buffer(text, osd->progbar_type); + text = mp_append_utf8_buffer(text, osd->progbar_type); } else { text = talloc_strdup_append_buffer(text, ASS_USE_OSD_FONT); - text = append_utf8_buffer(text, OSD_CODEPOINTS + osd->progbar_type); + text = mp_append_utf8_buffer(text, OSD_CODEPOINTS + osd->progbar_type); text = talloc_strdup_append_buffer(text, "{\\r}"); } @@ -218,12 +211,12 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj) text = talloc_strdup_append_buffer(text, "\\h"); text = talloc_strdup_append_buffer(text, ASS_USE_OSD_FONT); - text = append_utf8_buffer(text, OSD_CODEPOINTS + OSD_PB_START); + text = mp_append_utf8_buffer(text, OSD_CODEPOINTS + OSD_PB_START); for (int n = 0; n < active; n++) - text = append_utf8_buffer(text, OSD_CODEPOINTS + OSD_PB_0); + text = mp_append_utf8_buffer(text, OSD_CODEPOINTS + OSD_PB_0); for (int n = 0; n < OSDBAR_ELEMS - active; n++) - text = append_utf8_buffer(text, OSD_CODEPOINTS + OSD_PB_1); - text = append_utf8_buffer(text, OSD_CODEPOINTS + OSD_PB_END); + text = mp_append_utf8_buffer(text, OSD_CODEPOINTS + OSD_PB_1); + text = mp_append_utf8_buffer(text, OSD_CODEPOINTS + OSD_PB_END); ASS_Event *event = get_osd_ass_event(obj->osd_track); event->Text = strdup(text); -- cgit v1.2.3