]> granicus.if.org Git - libass/commitdiff
Add ass_set_line_position() API function for subtitle position
authorwm4 <wm4@nowhere>
Sat, 29 Sep 2012 20:24:01 +0000 (22:24 +0200)
committerGrigori Goronzy <greg@blackbox>
Mon, 1 Oct 2012 13:41:13 +0000 (15:41 +0200)
This allows users to change the vertical position of normal subtitles.
MPlayer has such a feature as -sub-pos option using its internal
subtitle renderer.

Bump LIBASS_VERSION to indicate the API addition.

configure.ac
libass/ass.h
libass/ass_render.c
libass/ass_render.h
libass/ass_render_api.c
libass/libass.sym

index 35548c6291cf2744a6b094c58bc167420f5b7bff..a9f9071ed611830a55dab7bf1f531b0f87bbf3e0 100644 (file)
@@ -1,4 +1,4 @@
-AC_INIT(libass, 0.10.0)
+AC_INIT(libass, 0.10.1)
 AM_INIT_AUTOMAKE
 AC_CONFIG_MACRO_DIR([m4])
 # Disable C++/Fortran checks
index 5aef92e3e581090bdd7e495e4456f31567d91739..2d767f727f1cf8fb504e6c2c7f1d39bc62d2ebde 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdarg.h>
 #include "ass_types.h"
 
-#define LIBASS_VERSION 0x01000000
+#define LIBASS_VERSION 0x01010000
 
 /*
  * A linked list of images produced by an ass renderer.
@@ -213,6 +213,14 @@ void ass_set_hinting(ASS_Renderer *priv, ASS_Hinting ht);
  */
 void ass_set_line_spacing(ASS_Renderer *priv, double line_spacing);
 
+/**
+ * \brief Set vertical line position.
+ * \param priv renderer handle
+ * \param line_position vertical line position of subtitles in percent
+ * (0-100: 0 = on the bottom (default), 100 = on top)
+ */
+void ass_set_line_position(ASS_Renderer *priv, double line_position);
+
 /**
  * \brief Set font lookup defaults.
  * \param default_font path to default font to use. Must be supplied if
index c7ebef59f14ae49a000e02b2fa53b0f0e8f02a8f..f8b7987df06a77b26e51f3479a892cc27381baa2 100644 (file)
@@ -2032,16 +2032,25 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event,
                 y2scr(render_priv, render_priv->track->PlayResY / 2.0);
             device_y = scr_y - (bbox.yMax + bbox.yMin) / 2.0;
         } else {                // subtitle
-            double scr_y;
+            double scr_top, scr_bottom, scr_y0;
             if (valign != VALIGN_SUB)
                 ass_msg(render_priv->library, MSGL_V,
                        "Invalid valign, assuming 0 (subtitle)");
-            scr_y =
+            scr_bottom =
                 y2scr_sub(render_priv,
                           render_priv->track->PlayResY - MarginV);
-            device_y = scr_y;
+            scr_top = y2scr_top(render_priv, 0); //xxx not always 0?
+            device_y = scr_bottom + (scr_top - scr_bottom) *
+                       render_priv->settings.line_position / 100.0;
             device_y -= text_info->height;
             device_y += text_info->lines[0].asc;
+            // clip to top to avoid confusion if line_position is very high,
+            // turning the subtitle into a toptitle
+            // also, don't change behavior if line_position is not used
+            scr_y0 = scr_top + text_info->lines[0].asc;
+            if (device_y < scr_y0 && render_priv->settings.line_position > 0) {
+                device_y = scr_y0;
+            }
         }
     } else if (render_priv->state.evt_type == EVENT_VSCROLL) {
         if (render_priv->state.scroll_direction == SCROLL_TB)
index ad72a740094bf5cf27f5ce1f0559ca02a99122d5..d0d9aa388e6999522607a00fc7c600ee901a5c89 100644 (file)
@@ -67,6 +67,7 @@ typedef struct {
     int frame_height;
     double font_size_coeff;     // font size multiplier
     double line_spacing;        // additional line spacing (in frame pixels)
+    double line_position;       // vertical position for subtitles, 0-100 (0 = no change)
     int top_margin;             // height of top margin. Everything except toptitles is shifted down by top_margin.
     int bottom_margin;          // height of bottom margin. (frame_height - top_margin - bottom_margin) is original video height.
     int left_margin;
index 8bf9e5db6fa8a3b749253f58bab91152153deca5..e70e5ed1b1487b683fbf40edd78028a27122d817 100644 (file)
@@ -116,6 +116,14 @@ void ass_set_line_spacing(ASS_Renderer *priv, double line_spacing)
     priv->settings.line_spacing = line_spacing;
 }
 
+void ass_set_line_position(ASS_Renderer *priv, double line_position)
+{
+    if (priv->settings.line_position != line_position) {
+        priv->settings.line_position = line_position;
+        ass_reconfigure(priv);
+    }
+}
+
 void ass_set_fonts(ASS_Renderer *priv, const char *default_font,
                    const char *default_family, int fc, const char *config,
                    int update)
index f8fa1458a15e8d8340c89da185fcd1d8c9a44260..32fd94fd321be5238e20d27cfc1e9c26393a9d0c 100644 (file)
@@ -35,3 +35,4 @@ ass_fonts_update
 ass_set_cache_limits
 ass_flush_events
 ass_set_shaper
+ass_set_line_position