summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-06-15 08:05:51 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-06-15 08:05:51 +0000
commit49192fddd6271a5d7bbbf20b1b2a3bef42f4e8bc (patch)
tree15781d01accc7c092fa43332743e5876258b6eef /libvo
parentc95cda1aa8d415ae357337257503372522a5734f (diff)
downloadmpv-49192fddd6271a5d7bbbf20b1b2a3bef42f4e8bc.tar.bz2
mpv-49192fddd6271a5d7bbbf20b1b2a3bef42f4e8bc.tar.xz
Support UTF8 in OSD text
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@18720 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo')
-rw-r--r--libvo/sub.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/libvo/sub.c b/libvo/sub.c
index 05b0901516..580bb5831b 100644
--- a/libvo/sub.c
+++ b/libvo/sub.c
@@ -140,6 +140,35 @@ inline static void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)
}
}
+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 @@ inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){
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 @@ inline static void vo_update_text_osd(mp_osd_obj_t* obj,int dxs,int dys){
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],