]> granicus.if.org Git - libass/commitdiff
Reuse numpad2align in parse_tag
authorOleg Oshmyan <chortos@inbox.lv>
Fri, 3 Feb 2017 19:36:23 +0000 (21:36 +0200)
committerOleg Oshmyan <chortos@inbox.lv>
Tue, 14 Feb 2017 17:43:04 +0000 (19:43 +0200)
libass/ass.c
libass/ass_parse.c
libass/ass_utils.c
libass/ass_utils.h

index 3a94290996d30131c5dea957cb3d241d3480d71c..c35f4ae7df8ad963cd89c36a450832bb1231c426 100644 (file)
@@ -24,7 +24,6 @@
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
-#include <limits.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <inttypes.h>
@@ -237,28 +236,6 @@ static long long string2timecode(ASS_Library *library, char *p)
     return tm;
 }
 
-/**
- * \brief converts numpad-style align to align.
- */
-static int numpad2align(int val)
-{
-    if (val < -INT_MAX)
-        // Pick an alignment somewhat arbitrarily. VSFilter handles
-        // INT32_MIN as a mix of 1, 2 and 3, so prefer one of those values.
-        val = 2;
-    else if (val < 0)
-        val = -val;
-
-    int res = ((val - 1) % 3) + 1;  // horizontal alignment
-    if (val <= 3)
-        res |= VALIGN_SUB;
-    else if (val <= 6)
-        res |= VALIGN_CENTER;
-    else
-        res |= VALIGN_TOP;
-    return res;
-}
-
 #define NEXT(str,token) \
        token = next_token(&str); \
        if (!token) break;
index 5cd232f31c42a5ff484b00e233bd2e4e1e942a90..dc27bf5858f0a6530368accc8d443611fb7b5a2d 100644 (file)
@@ -566,14 +566,9 @@ char *parse_tag(ASS_Renderer *render_priv, char *p, char *end, double pwr)
     } else if (tag("an")) {
         int val = argtoi(*args);
         if ((render_priv->state.parsed_tags & PARSED_A) == 0) {
-            if (val >= 1 && val <= 9) {
-                int v = (val - 1) / 3;      // 0, 1 or 2 for vertical alignment
-                if (v != 0)
-                    v = 3 - v;
-                val = ((val - 1) % 3) + 1;  // horizontal alignment
-                val += v * 4;
-                render_priv->state.alignment = val;
-            } else
+            if (val >= 1 && val <= 9)
+                render_priv->state.alignment = numpad2align(val);
+            else
                 render_priv->state.alignment =
                     render_priv->state.style->Alignment;
             render_priv->state.parsed_tags |= PARSED_A;
index 03900f271c396dadcf1ff1d4a6a25b4fa50755c7..8cd639d2cf9c43a53d2abb9322589e1b8bdf9fdf 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <limits.h>
 #include <inttypes.h>
 
 #include "ass_library.h"
@@ -327,6 +328,28 @@ int parse_ycbcr_matrix(char *str)
     return YCBCR_UNKNOWN;
 }
 
+/**
+ * \brief converts numpad-style align to align.
+ */
+int numpad2align(int val)
+{
+    if (val < -INT_MAX)
+        // Pick an alignment somewhat arbitrarily. VSFilter handles
+        // INT32_MIN as a mix of 1, 2 and 3, so prefer one of those values.
+        val = 2;
+    else if (val < 0)
+        val = -val;
+
+    int res = ((val - 1) % 3) + 1;  // horizontal alignment
+    if (val <= 3)
+        res |= VALIGN_SUB;
+    else if (val <= 6)
+        res |= VALIGN_CENTER;
+    else
+        res |= VALIGN_TOP;
+    return res;
+}
+
 void ass_msg(ASS_Library *priv, int lvl, const char *fmt, ...)
 {
     va_list va;
index 6c9f3858e1d9ea310b50febdc7297192b76fdeb6..c2fcf308da70b999336796b3c11bb6d9a6f141f6 100644 (file)
@@ -87,6 +87,7 @@ uint32_t parse_color_tag(char *str);
 uint32_t parse_color_header(char *str);
 char parse_bool(char *str);
 int parse_ycbcr_matrix(char *str);
+int numpad2align(int val);
 unsigned ass_utf8_get_char(char **str);
 unsigned ass_utf8_put_char(char *dest, uint32_t ch);
 void ass_utf16be_to_utf8(char *dst, size_t dst_size, uint8_t *src, size_t src_size);