# HG changeset patch # User reimar # Date 1150358751 0 # Node ID 0f99a5fe9c7f7acdb895d0648ee2ceab84c6c291 # Parent e75ab7767078ef04c269ec9bc19b00162d70079a Support UTF8 in OSD text diff -r e75ab7767078 -r 0f99a5fe9c7f libvo/sub.c --- a/libvo/sub.c Thu Jun 15 08:04:40 2006 +0000 +++ b/libvo/sub.c Thu Jun 15 08:05:51 2006 +0000 @@ -140,6 +140,35 @@ } } +static unsigned utf8_get_char(char **str) { + uint8_t *strp = (uint8_t *)*str; + unsigned c = *strp++; + unsigned mask = 0x80; + int len = -1; + while (c & mask) { + mask >>= 1; + len++; + } + if (len <= 0 || len > 4) + goto no_utf8; + c &= mask - 1; + while ((*strp & 0xc0) == 0x80) { + if (len-- <= 0) + goto no_utf8; + c = (c << 6) | (*strp++ & 0x3f); + } + if (len) + goto no_utf8; + *str = (char *)strp; + return c; + +no_utf8: + strp = (uint8_t *)*str; + c = *strp++; + *str = (char *)strp; + return c; +} + inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){ unsigned char *cp=vo_osd_text; int x=20; @@ -150,7 +179,7 @@ obj->bbox.y1=obj->y=10; while (*cp){ - int c=*cp++; + uint16_t c=utf8_get_char(&cp); render_one_glyph(vo_font, c); x+=vo_font->width[c]+vo_font->charspace; h=get_height(c,h); @@ -165,7 +194,7 @@ cp=vo_osd_text; x = obj->x; while (*cp){ - int c=*cp++; + uint16_t c=utf8_get_char(&cp); if ((font=vo_font->font[c])>=0) draw_alpha_buf(obj,x,obj->y, vo_font->width[c],