]> git.sesse.net Git - vlc/blobdiff - modules/codec/subsdec.c
Subtitles: font attributes can use ''
[vlc] / modules / codec / subsdec.c
index 48abf5e1ce80c3c1c9d41f05d7dfb7cb9f0ed103..a69bcf0eb032f6640b2ec6bdaa27afc52f462b4c 100644 (file)
@@ -246,36 +246,36 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->iconv_handle = (vlc_iconv_t)-1;
     p_sys->b_autodetect_utf8 = false;
 
-    char *psz_charset = NULL;
+    const char *encoding;
+    char *var = NULL;
 
     /* First try demux-specified encoding */
     if( p_dec->fmt_in.i_codec == VLC_CODEC_ITU_T140 )
-        psz_charset = strdup( "UTF-8" ); /* IUT T.140 is always using UTF-8 */
+        encoding = "UTF-8"; /* IUT T.140 is always using UTF-8 */
     else
     if( p_dec->fmt_in.subs.psz_encoding && *p_dec->fmt_in.subs.psz_encoding )
     {
-        psz_charset = strdup (p_dec->fmt_in.subs.psz_encoding);
+        encoding = p_dec->fmt_in.subs.psz_encoding;
         msg_Dbg (p_dec, "trying demuxer-specified character encoding: %s",
-                 p_dec->fmt_in.subs.psz_encoding ?
-                 p_dec->fmt_in.subs.psz_encoding : "not specified");
+                 encoding);
     }
-
+    else
     /* Second, try configured encoding */
-    if (psz_charset == NULL)
+    if ((var = var_InheritString (p_dec, "subsdec-encoding")) != NULL)
     {
-        psz_charset = var_InheritString (p_dec, "subsdec-encoding");
-        msg_Dbg (p_dec, "trying configured character encoding: %s",
-                 psz_charset ? psz_charset : "not specified");
-        if (psz_charset != NULL && !strcmp (psz_charset, "system"))
+        msg_Dbg (p_dec, "trying configured character encoding: %s", var);
+        if (!strcmp (var, "system"))
         {
-            free (psz_charset);
-            psz_charset = strdup ("");
+            free (var);
+            var = NULL;
+            encoding = "";
             /* ^ iconv() treats "" as nl_langinfo(CODESET) */
         }
+        else
+            encoding = var;
     }
-
+    else
     /* Third, try "local" encoding with optional UTF-8 autodetection */
-    if (psz_charset == NULL)
     {
         /* xgettext:
            The Windows ANSI code page most commonly used for this language.
@@ -287,12 +287,8 @@ static int OpenDecoder( vlc_object_t *p_this )
 
            This MUST be a valid iconv character set. If unsure, please refer
            the VideoLAN translators mailing list. */
-        const char *acp = vlc_pgettext("GetACP", "CP1252");
-
-        psz_charset = strdup (acp);
-        msg_Dbg (p_dec, "trying default character encoding: %s",
-                 psz_charset ? psz_charset : "not specified");
-
+        encoding = vlc_pgettext("GetACP", "CP1252");
+        msg_Dbg (p_dec, "trying default character encoding: %s", encoding);
         if (var_InheritBool (p_dec, "subsdec-autodetect-utf8"))
         {
             msg_Dbg (p_dec, "using automatic UTF-8 detection");
@@ -300,22 +296,13 @@ static int OpenDecoder( vlc_object_t *p_this )
         }
     }
 
-    /* Forth, don't do character decoding, i.e. assume UTF-8 */
-    if (psz_charset == NULL)
+    if (strcasecmp (encoding, "UTF-8") && strcasecmp (encoding, "utf8"))
     {
-        psz_charset = strdup ("UTF-8");
-        msg_Dbg (p_dec, "using UTF-8 character encoding" );
-    }
-
-    if ((psz_charset != NULL)
-     && strcasecmp (psz_charset, "UTF-8")
-     && strcasecmp (psz_charset, "utf8"))
-    {
-        p_sys->iconv_handle = vlc_iconv_open ("UTF-8", psz_charset);
+        p_sys->iconv_handle = vlc_iconv_open ("UTF-8", encoding);
         if (p_sys->iconv_handle == (vlc_iconv_t)(-1))
-            msg_Err (p_dec, "cannot convert from %s: %m", psz_charset);
+            msg_Err (p_dec, "cannot convert from %s: %m", encoding);
     }
-    free (psz_charset);
+    free (var);
 
     p_sys->i_align = var_InheritInteger( p_dec, "subsdec-align" );
 
@@ -679,18 +666,21 @@ static char *CreateHtmlSubtitle( int *pi_align, char *psz_subtitle )
                                 psz_subtitle++;
                                 i_len = strcspn( psz_subtitle, "\"" );
                             }
+                            else if( *psz_subtitle == '\'' )
+                            {
+                                psz_subtitle++;
+                                i_len = strcspn( psz_subtitle, "'" );
+                            }
                             else
                             {
                                 i_len = strcspn( psz_subtitle, " \t>" );
                             }
                             HtmlPut( &psz_html, "\"" );
-                            if( !strcmp( psz_attribs[ k ], "color=" ) && *psz_subtitle >= '0' && *psz_subtitle <= '9' )
-                                HtmlPut( &psz_html, "#" );
                             HtmlNPut( &psz_html, psz_subtitle, i_len );
                             HtmlPut( &psz_html, "\"" );
 
                             psz_subtitle += i_len;
-                            if( *psz_subtitle == '\"' )
+                            if( *psz_subtitle == '\"' || *psz_subtitle == '\'' )
                                 psz_subtitle++;
                             break;
                         }