changeset 23338:2a66d95355f0

add new -subfont option, that allows having a different font for OSD (controls and menu) and subtitles
author ben
date Sun, 20 May 2007 16:10:45 +0000
parents 10a7279b8e56
children 95bc9f4905f8
files cfg-common.h libmenu/vf_menu.c libvo/font_load.h libvo/font_load_ft.c libvo/sub.c mencoder.c mplayer.c mplayer.h
diffstat 8 files changed, 53 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/cfg-common.h	Sun May 20 15:17:56 2007 +0000
+++ b/cfg-common.h	Sun May 20 16:10:45 2007 +0000
@@ -292,6 +292,7 @@
 	{"sub-no-text-pp", &sub_no_text_pp, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"sub-fuzziness", &sub_match_fuzziness, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
 	{"font", &font_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"subfont", &sub_font_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
 	{"ffactor", &font_factor, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 10.0, NULL},
  	{"subpos", &sub_pos, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
 	{"subalign", &sub_alignment, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
--- a/libmenu/vf_menu.c	Sun May 20 15:17:56 2007 +0000
+++ b/libmenu/vf_menu.c	Sun May 20 16:10:45 2007 +0000
@@ -11,6 +11,7 @@
 #include <malloc.h>
 #endif
 
+#include "mplayer.h"
 #include "mp_msg.h"
 
 #include "libmpcodecs/img_format.h"
@@ -267,7 +268,7 @@
   // here is the right place to get screen dimensions
   if (force_load_font) {
     force_load_font = 0;
-    load_font_ft(width,height);
+    load_font_ft(width,height,&vo_font,font_name);
   }
 #endif
   if(outfmt == IMGFMT_MPEGPES)
--- a/libvo/font_load.h	Sun May 20 15:17:56 2007 +0000
+++ b/libvo/font_load.h	Sun May 20 16:10:45 2007 +0000
@@ -62,6 +62,7 @@
 } font_desc_t;
 
 extern font_desc_t* vo_font;
+extern font_desc_t* sub_font;
 
 #ifdef HAVE_FREETYPE
 
@@ -86,7 +87,7 @@
 void render_one_glyph(font_desc_t *desc, int c);
 int kerning(font_desc_t *desc, int prevc, int c);
 
-void load_font_ft(int width, int height);
+void load_font_ft(int width, int height, font_desc_t **desc, const char *name);
 
 void blur(unsigned char *buffer, unsigned short *tmp2, int width, int height,
           int stride, int *m2, int r, int mwidth);
--- a/libvo/font_load_ft.c	Sun May 20 15:17:56 2007 +0000
+++ b/libvo/font_load_ft.c	Sun May 20 16:10:45 2007 +0000
@@ -942,7 +942,7 @@
 {
     FT_Vector kern;
     
-    if (!vo_font->dynamic) return 0;
+    if (!desc->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;
@@ -1137,7 +1137,7 @@
     return 0;
 }
 
-void load_font_ft(int width, int height) 
+void load_font_ft(int width, int height, font_desc_t** fontp, const char *font_name) 
 {
 #ifdef HAVE_FONTCONFIG
     FcPattern *fc_pattern;
@@ -1145,6 +1145,7 @@
     FcChar8 *s;
     FcBool scalable;
 #endif
+    font_desc_t *vo_font = *fontp;
     vo_image_width = width;
     vo_image_height = height;
 
@@ -1177,10 +1178,10 @@
 	}
 	// s doesn't need to be freed according to fontconfig docs
 	FcPatternGetString(fc_pattern, FC_FILE, 0, &s);
-	vo_font=read_font_desc_ft(s, width, height);
+	*fontp=read_font_desc_ft(s, width, height);
 	FcPatternDestroy(fc_pattern);
     }
     else
 #endif
-    vo_font=read_font_desc_ft(font_name, width, height);
+    *fontp=read_font_desc_ft(font_name, width, height);
 }
--- a/libvo/sub.c	Sun May 20 15:17:56 2007 +0000
+++ b/libvo/sub.c	Sun May 20 16:10:45 2007 +0000
@@ -14,6 +14,7 @@
 #define OSD_NAV_BOX_ALPHA 0x7f
 #endif
 
+#include "mplayer.h"
 #include "mp_msg.h"
 #include "help_mp.h"
 #include "video_out.h"
@@ -63,6 +64,7 @@
 
 //static int vo_font_loaded=-1;
 font_desc_t* vo_font=NULL;
+font_desc_t* sub_font=NULL;
 
 unsigned char* vo_osd_text=NULL;
 int sub_unicode=0;
@@ -392,7 +394,7 @@
    
    obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
 
-   if(!vo_sub || !vo_font || !sub_visibility || (vo_font->font[40]<0)){
+   if(!vo_sub || !sub_font || !sub_visibility || (sub_font->font[40]<0)){
        obj->flags&=~OSDFLAG_VISIBLE;
        return;
    }
@@ -402,7 +404,7 @@
 
       // too long lines divide into a smaller ones
       i=k=lasth=0;
-      h=vo_font->height;
+      h=sub_font->height;
       lastStripPosition=-1;
       l=vo_sub->lines;
 
@@ -413,7 +415,7 @@
 	int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter;
 
       while (l) {
-	    xsize = -vo_font->charspace;
+	    xsize = -sub_font->charspace;
 	  l--;
 	  t=vo_sub->text[i++];	  
 	    char_position = 0;
@@ -436,7 +438,7 @@
 		 mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n");
 	      }
 	      if (!c) c++; // avoid UCS 0
-	      render_one_glyph(vo_font, c);
+	      render_one_glyph(sub_font, c);
 
 		if (c == ' ') {
 		    struct osd_text_t *tmp_ott = (struct osd_text_t *) calloc(1, sizeof(struct osd_text_t));
@@ -447,7 +449,7 @@
 			tmp_ott->prev = cp_ott;
 			cp_ott->next = tmp_ott;
 			tmp_ott->osd_kerning =
-			    vo_font->charspace + vo_font->width[' '];
+			    sub_font->charspace + sub_font->width[' '];
 			cp_ott = tmp_ott;
 		    }
 		    tmp_ott->osd_length = xsize;
@@ -459,16 +461,16 @@
 		    xsize = 0;
 		    prevc = c;
 		} else {
-		    int delta_xsize = vo_font->width[c] + vo_font->charspace + kerning(vo_font, prevc, c);
+		    int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_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 (vo_font->pic_a[font]->h > h) {
-				h = vo_font->pic_a[font]->h;
+			if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) {
+			    if (sub_font->pic_a[font]->h > h) {
+				h = sub_font->pic_a[font]->h;
 			    }
 			}
 		    } else {
@@ -490,7 +492,7 @@
 		    tmp_ott->prev = cp_ott;
 		    cp_ott->next = tmp_ott;
 		    tmp_ott->osd_kerning =
-			vo_font->charspace + vo_font->width[' '];
+			sub_font->charspace + sub_font->width[' '];
 		    cp_ott = tmp_ott;
 		}
 		tmp_ott->osd_length = xsize;
@@ -499,7 +501,7 @@
 		for (counter = 0; counter < char_position; ++counter)
 		    tmp_ott->text[counter] = char_seq[counter];
 		char_position = 0;
-		xsize = -vo_font->charspace;
+		xsize = -sub_font->charspace;
 	    }
 	    free(char_seq);
 
@@ -522,7 +524,7 @@
 			tmp->prev = tmp_otp;
 			tmp_otp = tmp;
 			tmp_otp->ott = tmp_ott;
-			value = -2 * vo_font->charspace - vo_font->width[' '];
+			value = -2 * sub_font->charspace - sub_font->width[' '];
 		    } else {
 			tmp_otp->value = value;
 			exit = 1;
@@ -623,7 +625,7 @@
 		break;
 
 	    if (h > obj->y) {	// out of the screen so end parsing
-		obj->y -= lasth - vo_font->height;	// correct the y position
+		obj->y -= lasth - sub_font->height;	// correct the y position
 		break;
 	    }
 	    xsize = tmp_otp->value;
@@ -640,17 +642,17 @@
 			break;
 		    }
 		    c = tmp_ott->text[counter];
-		    render_one_glyph(vo_font, c);
+		    render_one_glyph(sub_font, c);
 		    obj->params.subtitle.utbl[utblc++] = c;
 		    k++;
 		}
 		obj->params.subtitle.utbl[utblc++] = ' ';
 	    }
 	    obj->params.subtitle.utbl[utblc - 1] = 0;
-	    obj->y -= vo_font->height;
+	    obj->y -= sub_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) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h);
 	
 	// free memory
 	if (otp_sub != NULL) {
@@ -689,7 +691,7 @@
     obj->bbox.x1=xmin;
     obj->bbox.x2=xmax;
     obj->bbox.y1=obj->y;
-//    obj->bbox.y2=obj->y+obj->params.subtitle.lines*vo_font->height;
+//    obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height;
     obj->flags|=OSDFLAG_BBOX;
 
     alloc_buf(obj);
@@ -735,18 +737,18 @@
 	    }
 	 prevc = -1;
 	 while ((c=obj->params.subtitle.utbl[j++])){
-	       x += kerning(vo_font,prevc,c);
-	       if ((font=vo_font->font[c])>=0)
+	       x += kerning(sub_font,prevc,c);
+	       if ((font=sub_font->font[c])>=0)
 		  draw_alpha_buf(obj,x,y,
-			     vo_font->width[c],
-			     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_a[font]->w);
-	       x+=vo_font->width[c]+vo_font->charspace;
+			     sub_font->width[c],
+			     sub_font->pic_a[font]->h+y<obj->dys ? sub_font->pic_a[font]->h : obj->dys-y,
+			     sub_font->pic_b[font]->bmp+sub_font->start[c],
+			     sub_font->pic_a[font]->bmp+sub_font->start[c],
+			     sub_font->pic_a[font]->w);
+	       x+=sub_font->width[c]+sub_font->charspace;
                prevc = c;
 	    }
-         y+=vo_font->height;
+         y+=sub_font->height;
 	}
     }
     
@@ -829,12 +831,18 @@
 	if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1;
     }
 
-    if (!vo_font || force_load_font) {
+    if (force_load_font) {
 	force_load_font = 0;
-	load_font_ft(dxs, dys);
+        load_font_ft(dxs, dys, &vo_font, font_name);
+        load_font_ft(dxs, dys, &sub_font, sub_font_name);
 	prev_dxs = dxs;
 	prev_dys = dys;
 	defer_counter = 0;
+    } else {
+       if (!vo_font) 
+           load_font_ft(dxs, dys, &vo_font, font_name);
+       if (!sub_font) 
+           load_font_ft(dxs, dys, &sub_font, sub_font_name);
     }
 #endif
 
--- a/mencoder.c	Sun May 20 15:17:56 2007 +0000
+++ b/mencoder.c	Sun May 20 16:10:45 2007 +0000
@@ -186,6 +186,7 @@
 
 // sub:
 char *font_name=NULL;
+char *sub_font_name=NULL;
 #ifdef HAVE_FONTCONFIG
 extern int font_fontconfig;
 #endif
--- a/mplayer.c	Sun May 20 15:17:56 2007 +0000
+++ b/mplayer.c	Sun May 20 16:10:45 2007 +0000
@@ -322,6 +322,7 @@
 
 // sub:
 char *font_name=NULL;
+char *sub_font_name=NULL;
 #ifdef HAVE_FONTCONFIG
 extern int font_fontconfig;
 #endif
@@ -2533,6 +2534,10 @@
        if(!vo_font)
        vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
   }
+  if (sub_font_name)
+    sub_font = read_font_desc(sub_font_name, font_factor, verbose>1);
+  else
+    sub_font = vo_font;
 #endif
 #ifdef HAVE_FONTCONFIG
   }
--- a/mplayer.h	Sun May 20 15:17:56 2007 +0000
+++ b/mplayer.h	Sun May 20 16:10:45 2007 +0000
@@ -19,6 +19,7 @@
 extern unsigned int osd_visible;
 
 extern char * font_name;
+extern char * sub_font_name;
 extern float  font_factor;
 extern float movie_aspect;
 extern float force_fps;