[vlc-devel] [PATCH] italic tag support fo MPL2 subtitles

Roman Bednarek roman at mikronika.com.pl
Tue Feb 20 18:26:00 CET 2007


    Hi all,
  To complete MPL2 subtitles support I have added parsing italic tag "/" 
and rendering italic subtitle.
  This patch is a little intrusive, it embeds control tags for text 
renderer into the text. It does not use text_style_t struct because there 
is no way (I could find) it can be different for different parts of a 
single subtitle.
  If this patch gets accepted I plan to add suport for some MicroDVD 
formating tags in the same way.

  With Regards,
  Roman Bednarek
-------------- next part --------------
Index: modules/misc/freetype.c

===================================================================

--- modules/misc/freetype.c	(wersja 18907)

+++ modules/misc/freetype.c	(kopia robocza)

@@ -829,6 +829,9 @@

 #define face p_sys->p_face
 #define glyph face->glyph
 
+    // reset transform
+    FT_Set_Transform( face, NULL, NULL );
+
     while( *psz_unicode )
     {
         i_char = *psz_unicode++;
@@ -837,6 +840,28 @@

             continue;
         }
 
+        if( i_char == '\\' ) // control code
+        {
+            i_char = *psz_unicode++;
+            if( !i_char ) break;
+
+            if( i_char == 'I' )
+            {
+                FT_Matrix slantMat;
+                slantMat.xx = (1 << 16);
+                slantMat.xy = ((1 << 16) >> 2);
+                slantMat.yx = 0;
+                slantMat.yy = (1 << 16);
+                FT_Set_Transform( face, &slantMat, NULL );
+                continue;
+            }
+            else if( i_char == 'i' )
+            {
+                FT_Set_Transform( face, NULL, NULL );
+                continue;
+            }
+        }
+
         if( i_char == '\n' )
         {
             psz_line_start = psz_unicode;
Index: modules/demux/subtitle.c

===================================================================

--- modules/demux/subtitle.c	(wersja 18907)

+++ modules/demux/subtitle.c	(kopia robocza)

@@ -1311,8 +1311,12 @@

     char buffer_text[MAX_LINE + 1];
     int    i_start;
     int    i_stop;
-    unsigned int i;
+    unsigned int i,j;
 
+    char output_text[MAX_LINE + 1];
+    int output_italic;
+    int output_start_line;
+
     p_subtitle->i_start = 0;
     p_subtitle->i_stop  = 0;
     p_subtitle->psz_text = NULL;
@@ -1334,16 +1338,50 @@

         }
     }
 
-    /* replace | by \n */
-    for( i = 0; i < strlen( buffer_text ); i++ )
+    memset( output_text, '\0', MAX_LINE );
+    output_start_line = VLC_TRUE;
+    output_italic = VLC_FALSE;
+    for( i = 0,j=0; i < strlen( buffer_text ) && j<MAX_LINE-2; i++ )
     {
+        if( output_start_line )
+        {
+           output_start_line = VLC_FALSE;
+           if( buffer_text[i] == '/' )
+           {
+               if( !output_italic )
+               {
+                   output_text[j++] = '\\';
+                   output_text[j++] = 'I';
+                   output_italic = VLC_TRUE;
+               }
+               continue;
+           }
+           else if( buffer_text[i] != '/' && output_italic )
+           {
+                output_text[j++] = '\\';
+                output_text[j++] = 'i';
+                output_italic = VLC_FALSE;
+           }
+        }
         if( buffer_text[i] == '|' )
         {
-            buffer_text[i] = '\n';
+            output_text[j++] = '\n';
+            output_start_line=VLC_TRUE;
         }
+        else if( buffer_text[i] == '\\' )
+        {
+            output_text[j++] = '\\';
+            output_text[j++] = '\\';
+        }
+        else
+        {
+            output_text[j++] = buffer_text[i];
+        }
     }
+    output_text[j]=0;
+
     p_subtitle->i_start = (int64_t)i_start * 100000;
     p_subtitle->i_stop  = (int64_t)i_stop  * 100000;
-    p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );
+    p_subtitle->psz_text = strndup( output_text, MAX_LINE );
     return( 0 );
 }


More information about the vlc-devel mailing list