[MPlayer-dev-eng] [PATCH] Remove font attributes from subtitles

Robert Ramiega jedi at plukwa.net
Tue Sep 20 12:54:23 CEST 2005


On Tue, Sep 20, 2005 at 01:23:42AM +0200, Guillaume POIRIER wrote:
> Hi,
> 
> On 9/6/05, Robert Ramiega <jedi at plukwa.net> wrote:
> >   Hi!
> > Sometimes subtitles files (i've seen this in mdvd and mpl2 only) contain
> > information on attributes of the following subtitle (like italics or color).
> > As of now mplayer just displays this information as part of subtitle. So far
> > i couldn't make head or tails out of subtitle rendering in mplayer so i made
> > small patch that removes this extranous information.
> >  If someone would be so nice and get me started on subtitle rendering i'm
> > willing to try to make mplayer actually recognize and use this attributes.

> how come there has been no replies to this patch? is it ok/bad?

 It's bad. Because it hides things instead of solving them.

 I have a better one (should be attached) that makes mplayer capable of
displaying italics in subtitles. It's a bit better but still needs some work
 About the patch:
1. only italics ({y:i}, '/') are supported atm (and only if tag is at the
begining of subtitle line)
2. only "v2" font.desc fonts allow italics to actually be displayed. Whole
code should be backward compatible with currently used "v1" font.desc. This
"v2" fonts have additional [files] [characters] section that define
italic bitmaps of glyphs. At this moment it's waiting for improvements (as
of now code relays on italics beeing in second [file][character] pair).
 Those "v2" fonts are available at http://rebels.plukwa.net/~jedi/mplayer

 I know nothing about libfreetype/libfontconfig so can't make it to support
italics.
 next few days i intend to create better v2 font.desc implementation. After
that i'll try to 'rewrite' subreader.c and libvo/sub.c: vo_update_text_sub
currently does things that might as well be done while reading subtitle file
(like splitting subtitle line into words). This could help in getting in
more subtitle tags support.

 Comments are very very welcome (just don't beat me after 10 years of beeing
sysadm only i'm starting to re-learning how to write some code =o))


ps:
Gamester17 please do not post this patch on the XBMC tracker. Thank You =o)

ps2:
I've just noticed that cvs diff -uN seemed to ignore newely created file
(TOOLS/subfont-c/fontgen-v2) and i don't know how to include it in patch.
fontgen-v2 is simple bash script that generates font.desc in "v2" format

-- 
Just a friendly Jedi Knight     | I find your lack of faith
Robert Ramiega jedi at plukwa.net  | disturbing
-------------- next part --------------
? TOOLS/subfont-c/fontgen-v2
Index: subreader.c
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.c,v
retrieving revision 1.144
diff -u -r1.144 subreader.c
--- subreader.c	1 Jun 2005 09:01:41 -0000	1.144
+++ subreader.c	20 Sep 2005 10:09:19 -0000
@@ -257,6 +257,29 @@
     else return NULL;  // last text field
 }
 
+void sub_clean(char *source)
+{
+    char temp_line[LINE_LEN+1]="";
+    char *ptr, *ptr2;
+
+    ptr = source;
+    ptr2 = temp_line;
+    while(*ptr != '\0') {
+	if(strncasecmp(ptr, "{s:", 3) == 0 || strncasecmp(ptr, "{c:", 3) == 0) {
+	    while(*ptr != '}' && *ptr != '\0') ptr++;
+	    if(*ptr == '}') ptr++;
+	}
+	if(strncasecmp(ptr,"{y:i}",5) == 0) {
+	   *ptr2 = '/';
+	   ptr +=5;
+	   ptr2++;
+	} else
+	  *ptr2++ = *ptr++;
+    }
+    strcpy(source, temp_line);
+}
+
+
 subtitle *sub_read_line_microdvd(FILE *fd,subtitle *current) {
     char line[LINE_LEN+1];
     char line2[LINE_LEN+1];
@@ -271,7 +294,7 @@
 	     (sscanf (line,
 		      "{%ld}{%ld}%[^\r\n]",
 		      &(current->start), &(current->end), line2) < 3));
-	
+    sub_clean(line2);	
     p=line2;
 
     next=p, i=0;
@@ -298,6 +321,7 @@
 		      &(current->start), &(current->end), line2) < 3));
     current->start *= 10;
     current->end *= 10;
+    sub_clean(line2);
     p=line2;
 
     next=p, i=0;
Index: libvo/font_load.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/font_load.c,v
retrieving revision 1.31
diff -u -r1.31 font_load.c
--- libvo/font_load.c	30 Nov 2004 02:36:05 -0000	1.31
+++ libvo/font_load.c	20 Sep 2005 10:09:20 -0000
@@ -51,10 +51,10 @@
 char *dn;
 struct stat fstate;
 char section[64];
-int i,j;
+int i,j,k;
 int chardb=0;
 int fontdb=-1;
-int version=0;
+
 int first=1;
 
 desc=malloc(sizeof(font_desc_t));if(!desc) goto fail_out;
@@ -80,7 +80,10 @@
 desc->charspace=2;
 desc->spacewidth=12;
 desc->height=0;
-for(i=0;i<65536;i++) desc->start[i]=desc->width[i]=desc->font[i]=-1;
+
+desc->italic=0;
+for(i=0;i<65536;i++) 
+   desc->start[i][0]=desc->start[i][1]=desc->width[i][0]=desc->width[i][1]=desc->font[i][0]=desc->font[i][1]=-1;
 
 section[0]=0;
 
@@ -198,6 +201,10 @@
 	  free(cp);
           continue;
       }
+      if(desc->version==2 && pdb==2 && strcmp(p[0],"italic")==0){
+         desc->italic=1;
+	 continue;
+      }
   } else
 
   if(strcmp(section,"[info]")==0){
@@ -206,7 +213,7 @@
           continue;
       }
       if(pdb==2 && strcmp(p[0],"descversion")==0){
-          version=atoi(p[1]);
+          desc->version=atoi(p[1]);
           continue;
       }
       if(pdb==2 && strcmp(p[0],"spacewidth")==0){
@@ -233,9 +240,9 @@
           if(end<start) {
               mp_msg(MSGT_OSD, MSGL_WARN, "error in font desc: end<start for char '%c'\n",chr);
           } else {
-              desc->start[chr]=start;
-              desc->width[chr]=end-start+1;
-              desc->font[chr]=fontdb;
+              desc->start[chr][desc->italic]=start;
+              desc->width[chr][desc->italic]=end-start+1;
+              desc->font[chr][desc->italic]=fontdb;
 //              printf("char %d '%c'  start=%d width=%d\n",chr,chr,desc->start[chr],desc->width[chr]);
               ++chardb;
           }
@@ -298,17 +305,18 @@
     }
     if(!desc->height) desc->height=desc->pic_a[i]->h;
 }
-
-j='_';if(desc->font[j]<0) j='?';
-for(i=0;i<65536;i++)
-  if(desc->font[i]<0){
-      desc->start[i]=desc->start[j];
-      desc->width[i]=desc->width[j];
-      desc->font[i]=desc->font[j];
+j='_';if(desc->font[j][0]<0) j='?';
+j='_';if(desc->font[j][1]<0) j='?';
+for(k=0;k<2;k++){
+  for(i=0;i<65536;i++)
+  if(desc->font[i][k]<0){
+      desc->start[i][k]=desc->start[j][k];
+      desc->width[i][k]=desc->width[j][k];
+      desc->font[i][k]=desc->font[j][k];
   }
-desc->font[' ']=-1;
-desc->width[' ']=desc->spacewidth;
-
+  desc->font[' '][k]=-1;
+  desc->width[' '][k]=desc->spacewidth;
+}
 mp_msg(MSGT_OSD, MSGL_V, "Font %s loaded successfully! (%d chars)\n",fname,chardb);
 
 return desc;
@@ -332,4 +340,3 @@
 
 }
 #endif
-
Index: libvo/font_load.h
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/font_load.h,v
retrieving revision 1.13
diff -u -r1.13 font_load.h
--- libvo/font_load.h	20 Nov 2003 16:25:40 -0000	1.13
+++ libvo/font_load.h	20 Sep 2005 10:09:20 -0000
@@ -1,6 +1,7 @@
 #ifndef __MPLAYER_FONT_LOAD_H
 #define __MPLAYER_FONT_LOAD_H
 
+
 #ifdef HAVE_FREETYPE
 #include <ft2build.h>
 #include FT_FREETYPE_H
@@ -17,6 +18,11 @@
 } raw_file;
 
 typedef struct {
+    short version;
+    /* 0 - means FreeType
+     * 1 - no support for subtitle styles (italic, bold, etc)
+     * 2 - support for italics in subs
+     */
 #ifdef HAVE_FREETYPE
     int dynamic;
 #endif
@@ -29,11 +35,13 @@
 //    char *fname_b;
     raw_file* pic_a[16];
     raw_file* pic_b[16];
-    short font[65536];
-    int start[65536];   // short is not enough for unicode fonts
-    short width[65536];
+    short font[65536][2];
+    int start[65536][2];   // short is not enough for unicode fonts
+    short width[65536][2];
+    short italic;
     int freetype;
 
+
 #ifdef HAVE_FREETYPE
     int face_cnt;
     
Index: libvo/font_load_ft.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/font_load_ft.c,v
retrieving revision 1.16
diff -u -r1.16 font_load_ft.c
--- libvo/font_load_ft.c	13 May 2005 19:47:50 -0000	1.16
+++ libvo/font_load_ft.c	20 Sep 2005 10:09:20 -0000
@@ -172,7 +172,7 @@
 
 	character = charset[i];
 	code = charcodes[i];
-	desc->font[unicode?character:code] = pic_idx;
+	desc->font[unicode?character:code][0] = pic_idx;
 	// get glyph index
 	if (character==0)
 	    glyph_index = 0;
@@ -181,7 +181,7 @@
 	    if (glyph_index==0) {
 		WARNING("Glyph for char 0x%02x|U+%04X|%c not found.", code, character,
 			code<' '||code>255 ? '.':code);
-		desc->font[unicode?character:code] = -1;
+		desc->font[unicode?character:code][0] = -1;
 		continue;
 	    }
 	}
@@ -498,14 +498,14 @@
     
     int	const	load_flags = FT_LOAD_DEFAULT;
     int		pen_xa;
-    int font = desc->font[c];
+    int font = desc->font[c][0];
     int error;
     
 //    fprintf(stderr, "render_one_glyph %d\n", c);
 
     if (!desc->dynamic) return;
-    if (desc->width[c] != -1) return;
-    if (desc->font[c] == -1) return;
+    if (desc->width[c][0] != -1) return;
+    if (desc->font[c][0] == -1) return;
 
     glyph_index = desc->glyph_index[c];
     
@@ -513,7 +513,7 @@
     error = FT_Load_Glyph(desc->faces[font], glyph_index, load_flags);
     if (error) {
 	WARNING("FT_Load_Glyph 0x%02x (char 0x%04x) failed.", glyph_index, c);
-	desc->font[c] = -1;
+	desc->font[c][0] = -1;
 	return;
     }
     slot = desc->faces[font]->glyph;
@@ -523,7 +523,7 @@
 	error = FT_Render_Glyph(slot, ft_render_mode_normal);
 	if (error) {
 	    WARNING("FT_Render_Glyph 0x%04x (char 0x%04x) failed.", glyph_index, c);
-	    desc->font[c] = -1;
+	    desc->font[c][0] = -1;
 	    return;
 	}
     }
@@ -532,7 +532,7 @@
     error = FT_Get_Glyph(slot, (FT_Glyph*)&glyph);
     if (error) {
 	WARNING("FT_Get_Glyph 0x%04x (char 0x%04x) failed.", glyph_index, c);
-	desc->font[c] = -1;
+	desc->font[c][0] = -1;
 	return;
     }
 
@@ -580,8 +580,8 @@
     pen_xa = f266ToInt(slot->advance.x) + 2*desc->pic_b[font]->padding;
     if (pen_xa > maxw) pen_xa = maxw;
 
-    desc->start[c] = off;
-    width = desc->width[c] = pen_xa;
+    desc->start[c][0] = off;
+    width = desc->width[c][0] = pen_xa;
     height = desc->pic_b[font]->charheight;
     stride = desc->pic_b[font]->w;
 
@@ -859,8 +859,10 @@
     desc->tables.omt = NULL;
     desc->tables.tmp = NULL;
 
-    for(i = 0; i < 65536; i++)
-	desc->start[i] = desc->width[i] = desc->font[i] = -1;
+    for(i = 0; i < 65536; i++) {
+	desc->start[i][0] = desc->width[i][0] = desc->font[i][0] = -1;
+	desc->start[i][1] = desc->width[i][0] = desc->font[i][0] = -1;
+    }
     for(i = 0; i < 16; i++)
 	desc->pic_a[i] = desc->pic_b[i] = NULL;
     
@@ -940,9 +942,9 @@
     
     if (!vo_font->dynamic) return 0;
     if (prevc < 0 || c < 0) return 0;
-    if (desc->font[prevc] != desc->font[c]) return 0;
-    if (desc->font[prevc] == -1 || desc->font[c] == -1) return 0;
-    FT_Get_Kerning(desc->faces[desc->font[c]], 
+    if (desc->font[prevc][0] != desc->font[c][0]) return 0;
+    if (desc->font[prevc][0] == -1 || desc->font[c][0] == -1) return 0;
+    FT_Get_Kerning(desc->faces[desc->font[c][0]], 
 		   desc->glyph_index[prevc], desc->glyph_index[c],
 		   ft_kerning_default, &kern);
 
@@ -1072,18 +1074,18 @@
     }
 
     // final cleanup
-    desc->font[' ']=-1;
-    desc->width[' ']=desc->spacewidth;
+    desc->font[' '][0]=-1;
+    desc->width[' '][0]=desc->spacewidth;
 
     j = '_';
-    if (desc->font[j] < 0) j = '?';
-    if (desc->font[j] < 0) j = ' ';
+    if (desc->font[j][0] < 0) j = '?';
+    if (desc->font[j][0] < 0) j = ' ';
     render_one_glyph(desc, j);
     for(i = 0; i < 65536; i++) {
-	if (desc->font[i] < 0 && i != ' ') {
-	    desc->start[i] = desc->start[j];
-	    desc->width[i] = desc->width[j];
-	    desc->font[i] = desc->font[j];
+	if (desc->font[i][0] < 0 && i != ' ') {
+	    desc->start[i][0] = desc->start[j][0];
+	    desc->width[i][0] = desc->width[j][0];
+	    desc->font[i][0] = desc->font[j][0];
 	}
     }
     return desc;
Index: libvo/sub.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/sub.c,v
retrieving revision 1.78
diff -u -r1.78 sub.c
--- libvo/sub.c	10 Apr 2005 11:54:31 -0000	1.78
+++ libvo/sub.c	20 Sep 2005 10:09:20 -0000
@@ -70,7 +70,7 @@
 // return the real height of a char:
 static inline int get_height(int c,int h){
     int font;
-    if ((font=vo_font->font[c])>=0)
+    if ((font=vo_font->font[c][0])>=0)
 	if(h<vo_font->pic_a[font]->h) h=vo_font->pic_a[font]->h;
     return h;
 }
@@ -151,7 +151,7 @@
         while (*cp){
           int c=*cp++;
 	  render_one_glyph(vo_font, c);
-	  x+=vo_font->width[c]+vo_font->charspace;
+	  x+=vo_font->width[c][0]+vo_font->charspace;
 	  h=get_height(c,h);
         }
 	
@@ -165,14 +165,14 @@
 	x = obj->x;
         while (*cp){
           int c=*cp++;
-          if ((font=vo_font->font[c])>=0)
+          if ((font=vo_font->font[c][0])>=0)
             draw_alpha_buf(obj,x,obj->y,
-			   vo_font->width[c],
-			   vo_font->pic_a[font]->h,
-			   vo_font->pic_b[font]->bmp+vo_font->start[c],
-			   vo_font->pic_a[font]->bmp+vo_font->start[c],
+         vo_font->width[c][0],
+         vo_font->pic_a[font]->h,
+			   vo_font->pic_b[font]->bmp+vo_font->start[c][0],
+			   vo_font->pic_a[font]->bmp+vo_font->start[c][0],
 			   vo_font->pic_a[font]->w);
-          x+=vo_font->width[c]+vo_font->charspace;
+         x+=vo_font->width[c][0]+vo_font->charspace;
         }
 }
 
@@ -205,11 +205,11 @@
     // calculate bbox corners:    
     {	int h=0;
         int y=(dys-vo_font->height)/2;
-        int delimw=vo_font->width[OSD_PB_START]
-     		  +vo_font->width[OSD_PB_END]
+        int delimw=vo_font->width[OSD_PB_START][0]
+     		  +vo_font->width[OSD_PB_END][0]
      		  +vo_font->charspace;
         int width=(2*dxs-3*delimw)/3;
-   	int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
+   	int charw=vo_font->width[OSD_PB_0][0]+vo_font->charspace;
         int elems=width/charw;
    	int x=(dxs-elems*charw-delimw)/2;
 	int delta = 0;
@@ -217,8 +217,8 @@
 	h=get_height(OSD_PB_END,h);
 	h=get_height(OSD_PB_0,h);
 	h=get_height(OSD_PB_1,h);
-	if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
-	    delta = vo_font->width[vo_osd_progbar_type]+vo_font->spacewidth;
+	if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type][0]>=0){
+	    delta = vo_font->width[vo_osd_progbar_type][0]+vo_font->spacewidth;
 	    delta = (x-delta > 0) ? delta : x;
 	    h=get_height(vo_osd_progbar_type,h);
 	}
@@ -234,9 +234,9 @@
     alloc_buf(obj);
     
     {
-	int minw = vo_font->width[OSD_PB_START]+vo_font->width[OSD_PB_END]+vo_font->width[OSD_PB_0];
-	if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){
-	    minw += vo_font->width[vo_osd_progbar_type]+vo_font->charspace+vo_font->spacewidth;
+	int minw = vo_font->width[OSD_PB_START][0]+vo_font->width[OSD_PB_END][0]+vo_font->width[OSD_PB_0][0];
+	if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type][0]>=0){
+	    minw += vo_font->width[vo_osd_progbar_type][0]+vo_font->charspace+vo_font->spacewidth;
 	}
 	if (obj->bbox.x2 - obj->bbox.x1 < minw) return; // space too small, don't render anything
     }
@@ -248,7 +248,7 @@
    	int x=obj->x;
         int y=obj->y;
         int c,font;
-   	int charw=vo_font->width[OSD_PB_0]+vo_font->charspace;
+	int charw=vo_font->width[OSD_PB_0][0]+vo_font->charspace;
         int elems=obj->params.progbar.elems;
 
 	if (vo_osd_progbar_value<=0)
@@ -264,32 +264,33 @@
 //        printf("osd.progbar  width=%d  xpos=%d\n",width,x);
 
         c=vo_osd_progbar_type;
-        if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) {
-	    int xp=x-vo_font->width[c]-vo_font->spacewidth;
+
+	if(vo_osd_progbar_type>0 && (font=vo_font->font[c][0])>=0) {
+	    int xp=x-vo_font->width[c][0]-vo_font->spacewidth;
 	   draw_alpha_buf(obj,(xp<0?0:xp),y,
-              vo_font->width[c],
-              vo_font->pic_a[font]->h,
-              vo_font->pic_b[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->w);
+	      vo_font->width[c][0],
+	      vo_font->pic_a[font]->h,
+	      vo_font->pic_b[font]->bmp+vo_font->start[c][0],
+	      vo_font->pic_a[font]->bmp+vo_font->start[c][0],
+	      vo_font->pic_a[font]->w);
 	}
    
         c=OSD_PB_START;
-        if ((font=vo_font->font[c])>=0)
+        if ((font=vo_font->font[c][0])>=0)
             draw_alpha_buf(obj,x,y,
-              vo_font->width[c],
+              vo_font->width[c][0],
               vo_font->pic_a[font]->h,
-              vo_font->pic_b[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->bmp+vo_font->start[c],
+              vo_font->pic_b[font]->bmp+vo_font->start[c][0],
+              vo_font->pic_a[font]->bmp+vo_font->start[c][0],
               vo_font->pic_a[font]->w);
-        x+=vo_font->width[c]+vo_font->charspace;
+        x+=vo_font->width[c][0]+vo_font->charspace;
 
    	c=OSD_PB_0;
-   	if ((font=vo_font->font[c])>=0){
-	   w=vo_font->width[c];
+   	if ((font=vo_font->font[c][0])>=0){
+	   w=vo_font->width[c][0];
 	   h=vo_font->pic_a[font]->h;
-	   s=vo_font->pic_b[font]->bmp+vo_font->start[c];
-	   sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
+	   s=vo_font->pic_b[font]->bmp+vo_font->start[c][0];
+	   sa=vo_font->pic_a[font]->bmp+vo_font->start[c][0];
 	   st=vo_font->pic_a[font]->w;
 	   if ((i=mark)) do {
 	       draw_alpha_buf(obj,x,y,w,h,s,sa,st);
@@ -298,11 +299,11 @@
 	}
 
    	c=OSD_PB_1;
-	if ((font=vo_font->font[c])>=0){
-	   w=vo_font->width[c];
+	if ((font=vo_font->font[c][0])>=0){
+	   w=vo_font->width[c][0];
 	   h=vo_font->pic_a[font]->h;
-	   s =vo_font->pic_b[font]->bmp+vo_font->start[c];
-	   sa=vo_font->pic_a[font]->bmp+vo_font->start[c];
+	   s =vo_font->pic_b[font]->bmp+vo_font->start[c][0];
+	   sa=vo_font->pic_a[font]->bmp+vo_font->start[c][0];
 	   st=vo_font->pic_a[font]->w;
 	   if ((i=elems-mark)) do {
 	       draw_alpha_buf(obj,x,y,w,h,s,sa,st);
@@ -311,12 +312,12 @@
 	}
 
         c=OSD_PB_END;
-        if ((font=vo_font->font[c])>=0)
+        if ((font=vo_font->font[c][0])>=0)
             draw_alpha_buf(obj,x,y,
-              vo_font->width[c],
+              vo_font->width[c][0],
               vo_font->pic_a[font]->h,
-              vo_font->pic_b[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->bmp+vo_font->start[c],
+              vo_font->pic_b[font]->bmp+vo_font->start[c][0],
+              vo_font->pic_a[font]->bmp+vo_font->start[c][0],
               vo_font->pic_a[font]->w);
 //        x+=vo_font->width[c]+vo_font->charspace;
 
@@ -329,9 +330,9 @@
 
 // vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
 
-inline static void vo_update_text_sub(mp_osd_obj_t* obj,int dxs,int dys){
+inline  static void vo_update_text_sub(mp_osd_obj_t* obj,int dxs,int dys){
    unsigned char *t;
-   int c,i,j,l,x,y,font,prevc,counter;
+   int c,i,j,l,x,y,font,prevc;
    int len;
    int k;
    int lastStripPosition;
@@ -339,10 +340,15 @@
    int xmin=dxs,xmax=0;
    int h,lasth;
    int xtblc, utblc;
+	struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
+	struct osd_text_p *otp_sub = NULL, *otp_sub_tmp,	// these are used to store the whole sub text osd
+	                  *otp, *tmp_otp, *pmt;	// these are used to manage sub text osd coming from a single sub line
+	int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
+   short italic;
    
    obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
 
-   if(!vo_sub || !vo_font || !sub_visibility || (vo_font->font[40]<0)){
+   if(!vo_sub || !vo_font || !sub_visibility || (vo_font->font[40][0]<0)){
        obj->flags&=~OSDFLAG_VISIBLE;
        return;
    }
@@ -351,20 +357,19 @@
    obj->params.subtitle.lines=0;
 
       // too long lines divide into a smaller ones
-      i=k=lasth=0;
+      i=k=lasth=italic=0;
       h=vo_font->height;
       lastStripPosition=-1;
       l=vo_sub->lines;
 
-    {
-	struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp;
-	struct osd_text_p *otp_sub = NULL, *otp_sub_tmp,	// these are used to store the whole sub text osd
-	                  *otp, *tmp_otp, *pmt;	// these are used to manage sub text osd coming from a single sub line
-	int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
+    //{
 
       while (l) {
 	    xsize = -vo_font->charspace;
 	  l--;
+	  if(vo_font->version > 1 ) 
+	       italic= vo_sub->text[i][0]=='/'?1:0;
+	  else italic = 0;
 	  t=vo_sub->text[i++];	  
 	  len=strlen(t)-1;
 	    char_position = 0;
@@ -378,6 +383,7 @@
 
 	    // reading the subtitle words from vo_sub->text[]
 	  for (j=0;j<=len;j++){
+	     
 	      if ((c=t[j])>=0x80){
 		 if (sub_utf8){
 		    if ((c & 0xe0) == 0xc0)    /* 2 bytes U+00080..U+0007FF*/
@@ -405,7 +411,7 @@
 			tmp_ott->prev = cp_ott;
 			cp_ott->next = tmp_ott;
 			tmp_ott->osd_kerning =
-			    vo_font->charspace + vo_font->width[' '];
+			    vo_font->charspace + vo_font->width[' '][italic];
 			cp_ott = tmp_ott;
 		    }
 		    tmp_ott->osd_length = xsize;
@@ -417,14 +423,14 @@
 		    xsize = 0;
 		    prevc = c;
 		} else {
-		    int delta_xsize = vo_font->width[c] + vo_font->charspace + kerning(vo_font, prevc, c);
+		    int delta_xsize = vo_font->width[c][italic] + vo_font->charspace + kerning(vo_font, prevc, c);
 		    
 		    if (xsize + delta_xsize <= dxs) {
 			if (!x) x = 1;
 			prevc = c;
 			char_seq[char_position++] = c;
 			xsize += delta_xsize;
-			if ((!suboverlap_enabled) && ((font = vo_font->font[c]) >= 0)) {
+			if ((!suboverlap_enabled) && ((font = vo_font->font[c][italic]) >= 0)) {
 			    if (vo_font->pic_a[font]->h > h) {
 				h = vo_font->pic_a[font]->h;
 			    }
@@ -448,7 +454,7 @@
 		    tmp_ott->prev = cp_ott;
 		    cp_ott->next = tmp_ott;
 		    tmp_ott->osd_kerning =
-			vo_font->charspace + vo_font->width[' '];
+			vo_font->charspace + vo_font->width[' '][0];
 		    cp_ott = tmp_ott;
 		}
 		tmp_ott->osd_length = xsize;
@@ -479,7 +485,7 @@
 			tmp->prev = tmp_otp;
 			tmp_otp = tmp;
 			tmp_otp->ott = tmp_ott;
-			value = -2 * vo_font->charspace - vo_font->width[' '];
+			value = -2 * vo_font->charspace - vo_font->width[' '][0];
 		    } else {
 			tmp_otp->value = value;
 			exit = 1;
@@ -607,7 +613,7 @@
 	    obj->y -= vo_font->height;
 	}
 	if(obj->params.subtitle.lines)
-	    obj->y = dys - ((obj->params.subtitle.lines - 1) * vo_font->height + vo_font->pic_a[vo_font->font[40]]->h);
+	    obj->y = dys - ((obj->params.subtitle.lines - 1) * vo_font->height + vo_font->pic_a[vo_font->font[40][0]]->h);
 	
 	// free memory
 	if (otp_sub != NULL) {
@@ -624,7 +630,7 @@
 	    free(pmt);
 	}
 	
-    }
+    //}
     /// vertical alignment
     h = dys - obj->y;
     if (sub_alignment == 2)
@@ -691,16 +697,22 @@
 		    x = obj->params.subtitle.xtbl[i];
 	    }
 	 prevc = -1;
+
+	 italic = obj->params.subtitle.utbl[j]=='/'?1:0;
+	 j += italic;
+	 if(vo_font->version < 2)  /*  needed for backward compatibilty to descversion 1 */
+	      italic = 0;
+
 	 while ((c=obj->params.subtitle.utbl[j++])){
 	       x += kerning(vo_font,prevc,c);
-	       if ((font=vo_font->font[c])>=0)
+	       if ((font=vo_font->font[c][italic])>=0)
 		  draw_alpha_buf(obj,x,y,
-			     vo_font->width[c],
+			     vo_font->width[c][italic],
 			     vo_font->pic_a[font]->h+y<obj->dys ? vo_font->pic_a[font]->h : obj->dys-y,
-			     vo_font->pic_b[font]->bmp+vo_font->start[c],
-			     vo_font->pic_a[font]->bmp+vo_font->start[c],
+			     vo_font->pic_b[font]->bmp+vo_font->start[c][italic],
+			     vo_font->pic_a[font]->bmp+vo_font->start[c][italic],
 			     vo_font->pic_a[font]->w);
-	       x+=vo_font->width[c]+vo_font->charspace;
+	       x+=vo_font->width[c][italic]+vo_font->charspace;
                prevc = c;
 	    }
          y+=vo_font->height;
-------------- next part --------------
#!/bin/bash

# font.desc v2 generator

# $1 - encoding
# $2 - size
# $3 - symbolsize
# $4 - regular font
# $5 - italic font

blur=2
outline=1.5


./subfont --blur $blur --outline $outline "$1" $2 $4
mv $1-a.raw $1-r-a.raw
mv $1-b.raw $1-r-b.raw
sed -i "s/descversion 1/descversion 2/" font.desc
sed -i "s/$1-a.raw/$1-r-a.raw/" font.desc
sed -i "s/$1-b.raw/$1-r-b.raw/" font.desc
./subfont --append --blur $blur --outline $outline "$1" $2 $5
mv $1-a.raw $1-i-a.raw
mv $1-b.raw $1-i-b.raw
sed -i "s/$1-a.raw/$1-i-a.raw/" font.desc
sed -i "s/$1-b.raw/$1-i-b.raw\nitalic yes/" font.desc
./subfont --append --blur $blur --outline $outline encodings/osd-mplayer $3 osd/osd.pfb


More information about the MPlayer-dev-eng mailing list