]> granicus.if.org Git - libass/commitdiff
Provide slightly more fine-grained control over style overrides
authorwm4 <wm4@nowhere>
Thu, 16 Oct 2014 23:55:16 +0000 (01:55 +0200)
committerwm4 <wm4@nowhere>
Fri, 17 Oct 2014 00:05:40 +0000 (02:05 +0200)
libass/ass.h
libass/ass_render.c
libass/ass_render.h
libass/ass_render_api.c

index 408bdeb4bfc83ea33c5781222d242afe2501c642..c8c6452324ab30aa2da23d6c1ad728f5a0d38b58 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdarg.h>
 #include "ass_types.h"
 
-#define LIBASS_VERSION 0x01103000
+#define LIBASS_VERSION 0x01103001
 
 /*
  * A linked list of images produced by an ass renderer.
@@ -87,6 +87,15 @@ typedef enum {
     ASS_SHAPING_COMPLEX
 } ASS_ShapingLevel;
 
+/**
+ * \brief Style override options. See
+ * ass_set_selective_style_override_enabled() for details.
+ */
+typedef enum {
+    ASS_OVERRIDE_BIT_STYLE = 1,
+    ASS_OVERRIDE_BIT_FONT_SIZE = 2,
+} ASS_OverrideBits;
+
 /**
  * \brief Return the version of library. This returns the value LIBASS_VERSION
  * was set to when the library was compiled.
@@ -332,9 +341,21 @@ void ass_set_fonts(ASS_Renderer *priv, const char *default_font,
  *          only be implemented on "best effort" basis, and has to rely on
  *          heuristics that can easily break.
  * \param priv renderer handle
- * \param enable enable selective styling if the value is not 0
- */
-void ass_set_selective_style_override_enabled(ASS_Renderer *priv, int enable);
+ * \param bits bit mask comprised of ASS_OverrideBits values. If the value is
+ *  0, all override features are disabled, and libass will behave like libass
+ *  versions before this feature was introduced. Possible values:
+ *      ASS_OVERRIDE_BIT_STYLE: apply the style as set with
+ *          ass_set_selective_style_override() on events which look like
+ *          dialogue. Other style overrides are also applied this way, except
+ *          ass_set_font_scale(). How ass_set_font_scale() is applied depends
+ *          on the ASS_OVERRIDE_BIT_FONT_SIZE flag.
+ *      ASS_OVERRIDE_BIT_FONT_SIZE: apply ass_set_font_scale() only on events
+ *          which look like dialogue. If not set, it is applied to all
+ *          events.
+ *      0: ignore ass_set_selective_style_override(), but apply all other
+ *          overrides (traditional behavior).
+ */
+void ass_set_selective_style_override_enabled(ASS_Renderer *priv, int bits);
 
 /**
  * \brief Set style for selective style override.
index 0cec41244340ec41fe045158b296f50f2a9a3211..8d942f6a0ed164189e85d57f187673e81e96cdf5 100644 (file)
@@ -773,15 +773,23 @@ static ASS_Style *handle_selective_style_overrides(ASS_Renderer *render_priv,
     ASS_Style *script = render_priv->track->styles +
                         render_priv->state.event->Style;
     ASS_Style *new = &render_priv->state.override_style_temp_storage;
-    int override = !event_is_positioned(render_priv->state.event->Text);
+    int explicit = event_is_positioned(render_priv->state.event->Text);
+    int requested = render_priv->settings.selective_style_overrides;
     double scale;
 
     if (!rstyle)
         rstyle = script;
 
     render_priv->state.style = script;
+    render_priv->state.overrides = ASS_OVERRIDE_BIT_FONT_SIZE; // odd default
 
-    if (!override || !render_priv->settings.selective_style_overrides)
+    if (explicit && (requested & ASS_OVERRIDE_BIT_FONT_SIZE))
+        render_priv->state.overrides &= ~(unsigned)ASS_OVERRIDE_BIT_FONT_SIZE;
+
+    if (!explicit && (requested & ASS_OVERRIDE_BIT_STYLE))
+        render_priv->state.overrides |= ASS_OVERRIDE_BIT_STYLE;
+
+    if (!(render_priv->state.overrides & ASS_OVERRIDE_BIT_STYLE))
         return rstyle;
 
     // Create a new style that contains a mix of the original style and
@@ -834,9 +842,11 @@ static void init_font_scale(ASS_Renderer *render_priv)
     if (!settings_priv->storage_height)
         render_priv->blur_scale = render_priv->border_scale;
 
-    render_priv->font_scale *= settings_priv->font_size_coeff;
-    render_priv->border_scale *= settings_priv->font_size_coeff;
-    render_priv->blur_scale *= settings_priv->font_size_coeff;
+    if (render_priv->state.overrides & ASS_OVERRIDE_BIT_FONT_SIZE) {
+        render_priv->font_scale *= settings_priv->font_size_coeff;
+        render_priv->border_scale *= settings_priv->font_size_coeff;
+        render_priv->blur_scale *= settings_priv->font_size_coeff;
+    }
 }
 
 /**
index e1b42b24435758e843276bd24d34486c4bb05d22..ea630aa44144e3ee1b1f520a7a837bba2ad64393 100644 (file)
@@ -296,6 +296,9 @@ typedef struct {
     int wrap_style;
     int font_encoding;
 
+    // combination of ASS_OVERRIDE_BIT_* flags that apply right now
+    unsigned overrides;
+
     // used to store RenderContext.style when doing selective style overrides
     ASS_Style override_style_temp_storage;
 } RenderContext;
index 072b693fdb675164adce7c7544a81a2b978ad36c..8802629e59760142b0699ac72fa52746705aa1c4 100644 (file)
@@ -151,11 +151,10 @@ void ass_set_fonts(ASS_Renderer *priv, const char *default_font,
                         default_font, fc, config, update);
 }
 
-void ass_set_selective_style_override_enabled(ASS_Renderer *priv, int enable)
+void ass_set_selective_style_override_enabled(ASS_Renderer *priv, int bits)
 {
-    enable = !!enable;
-    if (priv->settings.selective_style_overrides != enable) {
-        priv->settings.selective_style_overrides = enable;
+    if (priv->settings.selective_style_overrides != bits) {
+        priv->settings.selective_style_overrides = bits;
         ass_reconfigure(priv);
     }
 }