[MPlayer-dev-eng] [PATCH] UTF-8 osd messages

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Apr 23 00:09:10 CEST 2006


Hi,
the attached patch adds support for OSD messages in UTF-8.
Though this probably should only be active when MSG_CHARSET actually is
UTF-8.
Also, the utf8_get_char function is a bit overkill for this, since it will
always encouter valid UTF-8 in this case, but I made it more flexible in
the hope in will be used in other place as well in the future.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libvo/sub.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/sub.c,v
retrieving revision 1.83
diff -u -r1.83 sub.c
--- libvo/sub.c	9 Feb 2006 14:07:58 -0000	1.83
+++ libvo/sub.c	22 Apr 2006 21:38:37 -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],


More information about the MPlayer-dev-eng mailing list