changeset 8534:922ce27eb683

This patch adds support for vertical subtitle alignment control. Possible values are top, center, and bottom, with bottom being the default. Alignment is relevant when it comes to positioning subtitles with one line (or fewer lines) of text relative to multi-line subtitles. It is implemented as a new command (sub_alignment) that without an argument cycles the alignment (between top, center, and bottom), or with an argument sets the alignment (0 for top, 1 for center, 2 for bottom). The key 'i' is bound to this command. patch by Oskar Liljeblad (oskar@osk.mine.nu)
author arpi
date Mon, 23 Dec 2002 01:37:43 +0000
parents 9b73b801af55
children bc7bd163fff9
files input/input.c input/input.h libvo/sub.c libvo/sub.h mplayer.c
diffstat 5 files changed, 38 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/input/input.c	Mon Dec 23 01:24:42 2002 +0000
+++ b/input/input.c	Mon Dec 23 01:37:43 2002 +0000
@@ -69,6 +69,7 @@
   { MP_CMD_SATURATION, "saturation",1,  { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} }  },
   { MP_CMD_FRAMEDROPPING, "frame_drop",0, { { MP_CMD_ARG_INT,{-1} }, {-1,{0}} } },
   { MP_CMD_SUB_POS, "sub_pos", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+  { MP_CMD_SUB_ALIGNMENT, "sub_alignment",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
   { MP_CMD_SUB_VISIBILITY, "sub_visibility", 0, { {-1,{0}} } },
   { MP_CMD_VOBSUB_LANG, "vobsub_lang", 0, { {-1,{0}} } },
   { MP_CMD_GET_PERCENT_POS, "get_percent_pos", 0, { {-1,{0}} } },
@@ -247,6 +248,7 @@
   { { 'd', 0 }, "frame_drop" },
   { { 'r', 0 }, "sub_pos -1" },
   { { 't', 0 }, "sub_pos +1" },
+  { { 'i', 0 }, "sub_alignment" },
   { { 'v', 0 }, "sub_visibility" },
   { { 'j', 0 }, "vobsub_lang" },
 #ifdef USE_EDL
--- a/input/input.h	Mon Dec 23 01:24:42 2002 +0000
+++ b/input/input.h	Mon Dec 23 01:37:43 2002 +0000
@@ -41,6 +41,7 @@
 #ifdef USE_EDL
 #define MP_CMD_EDL_MARK 38
 #endif
+#define MP_CMD_SUB_ALIGNMENT 39
 
 #define MP_CMD_GUI_EVENTS       5000
 #define MP_CMD_GUI_LOADFILE     5001
--- a/libvo/sub.c	Mon Dec 23 01:24:42 2002 +0000
+++ b/libvo/sub.c	Mon Dec 23 01:37:43 2002 +0000
@@ -37,6 +37,7 @@
 int sub_unicode=0;
 int sub_utf8=0;
 int sub_pos=100;
+int sub_alignment=2; /* 0=top, 1=center, 2=bottom */
 int sub_visibility=1;
 
 // return the real height of a char:
@@ -418,12 +419,22 @@
        *sfalco*
      */
     if(suboverlap_enabled) obj->y -= vo_font->pic_a[vo_font->font[40]]->h - vo_font->height;
-    if (obj->y >= (dys * sub_pos / 100)){
-	int old=obj->y;
-	obj->y = dys * sub_pos /100;
-	obj->bbox.y2-=old-obj->y;
-    }
-    
+
+    h = dys - obj->y;
+    if (sub_alignment == 2)
+        obj->y = dys * sub_pos / 100 - h;
+    else if (sub_alignment == 1)
+        obj->y = dys * sub_pos / 100 - h / 2;
+    else
+        obj->y = dys * sub_pos / 100;
+
+    if (obj->y < 0)
+        obj->y = 0;
+    if (obj->y > dys - h)
+        obj->y = dys - h;
+
+    obj->bbox.y2 = obj->y + h;
+
     // calculate bbox:
     obj->bbox.x1=xmin;
     obj->bbox.x2=xmax;
--- a/libvo/sub.h	Mon Dec 23 01:24:42 2002 +0000
+++ b/libvo/sub.h	Mon Dec 23 01:37:43 2002 +0000
@@ -97,6 +97,7 @@
 extern char *sub_cp;
 #endif
 extern int sub_pos;
+extern int sub_alignment;
 extern int sub_visibility;
 extern int suboverlap_enabled;
 
--- a/mplayer.c	Mon Dec 23 01:24:42 2002 +0000
+++ b/mplayer.c	Mon Dec 23 01:37:43 2002 +0000
@@ -575,6 +575,7 @@
 int osd_show_sub_delay = 0;
 int osd_show_sub_pos = 0;
 int osd_show_sub_visibility = 0;
+int osd_show_sub_alignment = 0;
 int osd_show_vobsub_changed = 0;
 
 int rtc_fd=-1;
@@ -2485,6 +2486,16 @@
 	vo_osd_changed(OSDTYPE_SUBTITLE);
         osd_show_sub_pos = 9;
     }	break;
+    case MP_CMD_SUB_ALIGNMENT:
+    {
+    	if (cmd->nargs >= 1)
+    	    sub_alignment = cmd->args[0].v.i;
+    	else
+            sub_alignment = (sub_alignment+1) % 3;
+	osd_show_sub_alignment = 9;
+	vo_osd_changed(OSDTYPE_SUBTITLE);
+	break;
+    }
     case MP_CMD_SUB_VISIBILITY:
     {
 	sub_visibility=1-sub_visibility;
@@ -2920,6 +2931,12 @@
          sprintf(osd_text_tmp, "Sub position: %d/100", sub_pos);
          osd_show_sub_pos--;
       } else
+      if (osd_show_sub_alignment) {
+         sprintf(osd_text_tmp, "Sub alignment: %s",
+	    (sub_alignment == 2 ? "bottom" :
+	    (sub_alignment == 1 ? "center" : "top")));
+         osd_show_sub_alignment--;
+      } else
       if (osd_show_av_delay) {
 	  sprintf(osd_text_tmp, "A-V delay: %d ms",(int)(audio_delay*1000));
 	  osd_show_av_delay--;