]> git.sesse.net Git - vlc/blobdiff - modules/misc/quartztext.c
Qt: Profiles Editor for the transcoding.
[vlc] / modules / misc / quartztext.c
index 713efa31018582413efc366574de7cf5811595ef..31d64cb4ba7e2995ce0ab4b3964a918addf7e317 100644 (file)
 #include <vlc_stream.h>
 #include <vlc_xml.h>
 #include <vlc_input.h>
+#include <vlc_strings.h>
 
 #include <math.h>
 
 #include <Carbon/Carbon.h>
 
-#include "text_renderer.h"
-
 #define DEFAULT_FONT           "Arial Black"
 #define DEFAULT_FONT_COLOR     0xffffff
 #define DEFAULT_REL_FONT_SIZE  16
@@ -109,24 +108,24 @@ static const int pi_sizes[] = { 20, 18, 16, 12, 6 };
 static const char *const ppsz_sizes_text[] = {
     N_("Smaller"), N_("Small"), N_("Normal"), N_("Large"), N_("Larger") };
 
-vlc_module_begin();
-    set_shortname( N_("Mac Text renderer"));
-    set_description( N_("Quartz font renderer") );
-    set_category( CAT_VIDEO );
-    set_subcategory( SUBCAT_VIDEO_SUBPIC );
+vlc_module_begin ()
+    set_shortname( N_("Mac Text renderer"))
+    set_description( N_("Quartz font renderer") )
+    set_category( CAT_VIDEO )
+    set_subcategory( SUBCAT_VIDEO_SUBPIC )
 
     add_string( "quartztext-font", DEFAULT_FONT, NULL, FONT_TEXT, FONT_LONGTEXT,
-              false );
+              false )
     add_integer( "quartztext-rel-fontsize", DEFAULT_REL_FONT_SIZE, NULL, FONTSIZER_TEXT,
-                 FONTSIZER_LONGTEXT, false );
+                 FONTSIZER_LONGTEXT, false )
         change_integer_list( pi_sizes, ppsz_sizes_text, NULL );
     add_integer( "quartztext-color", 0x00FFFFFF, NULL, COLOR_TEXT,
-                 COLOR_LONGTEXT, false );
+                 COLOR_LONGTEXT, false )
         change_integer_list( pi_color_values, ppsz_color_descriptions, NULL );
-    set_capability( "text renderer", 150 );
-    add_shortcut( "text" );
-    set_callbacks( Create, Destroy );
-vlc_module_end();
+    set_capability( "text renderer", 150 )
+    add_shortcut( "text" )
+    set_callbacks( Create, Destroy )
+vlc_module_end ()
 
 typedef struct offscreen_bitmap_t offscreen_bitmap_t;
 struct offscreen_bitmap_t
@@ -155,6 +154,12 @@ struct filter_sys_t
     int                     i_fonts;
 };
 
+#define UCHAR UniChar
+#define TR_DEFAULT_FONT p_sys->psz_font_name
+#define TR_FONT_STYLE_PTR ATSUStyle
+
+#include "text_renderer.h"
+
 //////////////////////////////////////////////////////////////////////////////
 // Create: allocates osd-text video thread output method
 //////////////////////////////////////////////////////////////////////////////
@@ -509,9 +514,9 @@ static ATSUStyle GetStyleFromFontStack( filter_sys_t *p_sys,
 }
 
 static void SetupLine( filter_t *p_filter, const char *psz_text_in,
-                       uint32_t **psz_text_out, uint32_t *pi_runs,
-                       uint32_t **ppi_run_lengths, ft_style_t ***ppp_styles,
-                       ft_style_t *p_style )
+                       UniChar **psz_text_out, uint32_t *pi_runs,
+                       uint32_t **ppi_run_lengths, ATSUStyle **ppp_styles,
+                       ATSUStyle p_style )
 {
     uint32_t i_string_length = 0;
 
@@ -527,7 +532,7 @@ static void SetupLine( filter_t *p_filter, const char *psz_text_in,
         else
             *ppp_styles = (ATSUStyle *) malloc( *pi_runs * sizeof( ATSUStyle ) );
 
-        (*ppp_styles)[ *pi_runs - 1 ] = GetStyleFromFontStack( p_sys, &p_fonts, b_bold, b_italic, b_uline );
+        (*ppp_styles)[ *pi_runs - 1 ] = p_style;
 
         if( *ppi_run_lengths )
             *ppi_run_lengths = (uint32_t *) realloc( *ppi_run_lengths, *pi_runs * sizeof( uint32_t ) );
@@ -538,164 +543,6 @@ static void SetupLine( filter_t *p_filter, const char *psz_text_in,
     }
 }
 
-static int ProcessNodes( filter_t *p_filter,
-                         xml_reader_t *p_xml_reader,
-                         text_style_t *p_font_style,
-                         UniChar *psz_text,
-                         int *pi_len,
-
-                         uint32_t *pi_runs,
-                         uint32_t **ppi_run_lengths,
-                         ATSUStyle **ppp_styles )
-{
-    int           rv             = VLC_SUCCESS;
-    filter_sys_t *p_sys          = p_filter->p_sys;
-    UniChar      *psz_text_orig  = psz_text;
-    font_stack_t *p_fonts        = NULL;
-    vlc_value_t   val;
-    int           i_scale        = 1000;
-
-    char *psz_node  = NULL;
-
-    bool b_italic = false;
-    bool b_bold   = false;
-    bool b_uline  = false;
-
-    if( VLC_SUCCESS == var_Get( p_filter, "scale", &val ))
-        i_scale = val.i_int;
-
-    if( p_font_style )
-    {
-        rv = PushFont( &p_fonts,
-               p_font_style->psz_fontname,
-               p_font_style->i_font_size * i_scale / 1000,
-               (p_font_style->i_font_color & 0xffffff) |
-                   ((p_font_style->i_font_alpha & 0xff) << 24),
-                   /* TODO no idea how ATSUStyle works
-               (p_font_style->i_karaoke_background_color & 0xffffff) |
-                   ((p_font_style->i_karaoke_background_alpha & 0xff) << 24)
-                   */
-                   0x00ffffff );
-
-
-        if( p_font_style->i_style_flags & STYLE_BOLD )
-            b_bold = true;
-        if( p_font_style->i_style_flags & STYLE_ITALIC )
-            b_italic = true;
-        if( p_font_style->i_style_flags & STYLE_UNDERLINE )
-            b_uline = true;
-    }
-    else
-    {
-        rv = PushFont( &p_fonts,
-                       p_sys->psz_font_name,
-                       p_sys->i_font_size,
-                       p_sys->i_font_color,
-                       0x00ffffff );
-    }
-    if( rv != VLC_SUCCESS )
-        return rv;
-
-    while ( ( xml_ReaderRead( p_xml_reader ) == 1 ) )
-    {
-        switch ( xml_ReaderNodeType( p_xml_reader ) )
-        {
-            case XML_READER_NONE:
-                break;
-            case XML_READER_ENDELEM:
-                psz_node = xml_ReaderName( p_xml_reader );
-                if( psz_node )
-                {
-                    if( !strcasecmp( "font", psz_node ) )
-                        PopFont( &p_fonts );
-                    else if( !strcasecmp( "b", psz_node ) )
-                        b_bold   = false;
-                    else if( !strcasecmp( "i", psz_node ) )
-                        b_italic = false;
-                    else if( !strcasecmp( "u", psz_node ) )
-                        b_uline  = false;
-
-                    free( psz_node );
-                }
-                break;
-            case XML_READER_STARTELEM:
-                psz_node = xml_ReaderName( p_xml_reader );
-                if( psz_node )
-                {
-                    if( !strcasecmp( "font", psz_node ) )
-                        rv = HandleFontAttributes( p_xml_reader, &p_fonts, i_scale );
-                    else if( !strcasecmp( "b", psz_node ) )
-                        b_bold = true;
-                    else if( !strcasecmp( "i", psz_node ) )
-                        b_italic = true;
-                    else if( !strcasecmp( "u", psz_node ) )
-                        b_uline = true;
-                    else if( !strcasecmp( "br", psz_node ) )
-                    {
-                        SetupLine( p_filter, "\n", &psz_text,
-                                   pi_runs, ppi_run_lengths, ppp_styles,
-                                   GetStyleFromFontStack( p_sys,
-                                                          &p_fonts,
-                                                          b_bold,
-                                                          b_italic,
-                                                          b_uline ) );
-                    }
-                    free( psz_node );
-                }
-                break;
-            case XML_READER_TEXT:
-                psz_node = xml_ReaderValue( p_xml_reader );
-                if( psz_node )
-                {
-                    uint32_t i_string_length;
-
-                    // Turn any multiple-whitespaces into single spaces
-                    char *s = strpbrk( psz_node, "\t\r\n " );
-                    while( s )
-                    {
-                        int i_whitespace = strspn( s, "\t\r\n " );
-
-                        if( i_whitespace > 1 )
-                            memmove( &s[1],
-                                     &s[i_whitespace],
-                                     strlen( s ) - i_whitespace + 1 );
-                        *s++ = ' ';
-
-                        s = strpbrk( s, "\t\r\n " );
-                    }
-
-                    ConvertToUTF16( psz_node, &i_string_length, &psz_text );
-                    psz_text += i_string_length;
-
-                    (*pi_runs)++;
-
-                    if( *ppp_styles )
-                        *ppp_styles = (ATSUStyle *) realloc( *ppp_styles, *pi_runs * sizeof( ATSUStyle ) );
-                    else
-                        *ppp_styles = (ATSUStyle *) malloc( *pi_runs * sizeof( ATSUStyle ) );
-
-                    (*ppp_styles)[ *pi_runs - 1 ] = GetStyleFromFontStack( p_sys, &p_fonts, b_bold, b_italic, b_uline );
-
-                    if( *ppi_run_lengths )
-                        *ppi_run_lengths = (uint32_t *) realloc( *ppi_run_lengths, *pi_runs * sizeof( uint32_t ) );
-                    else
-                        *ppi_run_lengths = (uint32_t *) malloc( *pi_runs * sizeof( uint32_t ) );
-
-                    (*ppi_run_lengths)[ *pi_runs - 1 ] = i_string_length;
-
-                    free( psz_node );
-                }
-                break;
-        }
-    }
-
-    *pi_len = psz_text - psz_text_orig;
-
-    while( VLC_SUCCESS == PopFont( &p_fonts ) );
-
-    return rv;
-}
-
 static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
                        subpicture_region_t *p_region_in )
 {
@@ -758,7 +605,10 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
                 UniChar    *psz_text;
                 int         i_len = 0;
                 uint32_t    i_runs = 0;
+                uint32_t    i_k_runs = 0;
                 uint32_t   *pi_run_lengths = NULL;
+                uint32_t   *pi_k_run_lengths = NULL;
+                uint32_t   *pi_k_durations = NULL;
                 ATSUStyle  *pp_styles = NULL;
 
                 psz_text = (UniChar *) malloc( strlen( p_region_in->psz_html ) *
@@ -769,7 +619,11 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
 
                     rv = ProcessNodes( p_filter, p_xml_reader,
                                   p_region_in->p_style, psz_text, &i_len,
-                                  &i_runs, &pi_run_lengths, &pp_styles );
+                                  &i_runs, &pi_run_lengths, &pp_styles,
+                                  /* No karaoke support */
+                                  false, &i_k_runs, &pi_k_run_lengths, &pi_k_durations );
+
+                    assert( pi_k_run_lengths == NULL && pi_k_durations == NULL );
 
                     p_region_out->i_x = p_region_in->i_x;
                     p_region_out->i_y = p_region_in->i_y;