]> git.sesse.net Git - vlc/blobdiff - modules/misc/quartztext.c
xml_ReaderDelete: remove useless parameter
[vlc] / modules / misc / quartztext.c
index 02d84cd189b1f03e78161db32d44f0e0e287e9e3..b7c4da2374319a92eb18c879b30b995c606c96a1 100644 (file)
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_vout.h>
 #include <vlc_osd.h>
-#include <vlc_block.h>
-#include <vlc_filter.h>
 #include <vlc_stream.h>
 #include <vlc_xml.h>
 #include <vlc_input.h>
-#include <vlc_strings.h>
 
-#include <math.h>
-
-#include <Carbon/Carbon.h>
+// Fix ourselves ColorSync headers that gets included in ApplicationServices.
+#define DisposeCMProfileIterateUPP(a) DisposeCMProfileIterateUPP(CMProfileIterateUPP userUPP __attribute__((unused)))
+#define DisposeCMMIterateUPP(a) DisposeCMMIterateUPP(CMProfileIterateUPP userUPP __attribute__((unused)))
+#define __MACHINEEXCEPTIONS__
+#include <ApplicationServices/ApplicationServices.h>
 
 #define DEFAULT_FONT           "Arial Black"
 #define DEFAULT_FONT_COLOR     0xffffff
@@ -106,8 +104,8 @@ 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_shortname( N_("Text renderer for Mac"))
+    set_description( N_("CoreText font renderer") )
     set_category( CAT_VIDEO )
     set_subcategory( SUBCAT_VIDEO_SUBPIC )
 
@@ -234,59 +232,43 @@ static void Destroy( vlc_object_t *p_this )
 static int LoadFontsFromAttachments( filter_t *p_filter )
 {
     filter_sys_t         *p_sys = p_filter->p_sys;
-    input_thread_t       *p_input;
     input_attachment_t  **pp_attachments;
     int                   i_attachments_cnt;
-    int                   k;
-    int                   rv = VLC_SUCCESS;
 
-    p_input = (input_thread_t *)vlc_object_find( p_filter, VLC_OBJECT_INPUT, FIND_PARENT );
-    if( ! p_input )
+    if( filter_GetInputAttachments( p_filter, &pp_attachments, &i_attachments_cnt ) )
         return VLC_EGENERIC;
 
-    if( VLC_SUCCESS != input_Control( p_input, INPUT_GET_ATTACHMENTS, &pp_attachments, &i_attachments_cnt ))
-    {
-        vlc_object_release(p_input);
-        return VLC_EGENERIC;
-    }
-
     p_sys->i_fonts = 0;
     p_sys->p_fonts = malloc( i_attachments_cnt * sizeof( ATSFontContainerRef ) );
     if(! p_sys->p_fonts )
-        rv = VLC_ENOMEM;
+        return VLC_ENOMEM;
 
-    for( k = 0; k < i_attachments_cnt; k++ )
+    for( int k = 0; k < i_attachments_cnt; k++ )
     {
         input_attachment_t *p_attach = pp_attachments[k];
 
-        if( p_sys->p_fonts )
+        if( ( !strcmp( p_attach->psz_mime, "application/x-truetype-font" ) || // TTF
+              !strcmp( p_attach->psz_mime, "application/x-font-otf" ) ) &&    // OTF
+            p_attach->i_data > 0 && p_attach->p_data )
         {
-            if(( !strcmp( p_attach->psz_mime, "application/x-truetype-font" ) || // TTF
-                 !strcmp( p_attach->psz_mime, "application/x-font-otf" ) ) &&    // OTF
-               ( p_attach->i_data > 0 ) &&
-               ( p_attach->p_data != NULL ) )
+            ATSFontContainerRef  container;
+
+            if( noErr == ATSFontActivateFromMemory( p_attach->p_data,
+                                                    p_attach->i_data,
+                                                    kATSFontContextLocal,
+                                                    kATSFontFormatUnspecified,
+                                                    NULL,
+                                                    kATSOptionFlagsDefault,
+                                                    &container ))
             {
-                ATSFontContainerRef  container;
-
-                if( noErr == ATSFontActivateFromMemory( p_attach->p_data,
-                                                        p_attach->i_data,
-                                                        kATSFontContextLocal,
-                                                        kATSFontFormatUnspecified,
-                                                        NULL,
-                                                        kATSOptionFlagsDefault,
-                                                        &container ))
-                {
-                    p_sys->p_fonts[ p_sys->i_fonts++ ] = container;
-                }
+                p_sys->p_fonts[ p_sys->i_fonts++ ] = container;
             }
         }
         vlc_input_attachment_Delete( p_attach );
     }
     free( pp_attachments );
 
-    vlc_object_release(p_input);
-
-    return rv;
+    return VLC_SUCCESS;
 }
 
 static char *EliminateCRLF( char *psz_string )
@@ -316,8 +298,10 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
     char         *psz_string;
     int           i_font_alpha, i_font_size;
     uint32_t      i_font_color;
+    bool          b_bold, b_uline, b_italic;
     vlc_value_t val;
     int i_scale = 1000;
+    b_bold = b_uline = b_italic = FALSE;
 
     p_sys->i_font_size    = GetFontSize( p_filter );
 
@@ -334,6 +318,15 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
         i_font_color = __MAX( __MIN( p_region_in->p_style->i_font_color, 0xFFFFFF ), 0 );
         i_font_alpha = __MAX( __MIN( p_region_in->p_style->i_font_alpha, 255 ), 0 );
         i_font_size  = __MAX( __MIN( p_region_in->p_style->i_font_size, 255 ), 0 ) * i_scale / 1000;
+        if( p_region_in->p_style->i_style_flags )
+        {
+            if( p_region_in->p_style->i_style_flags & STYLE_BOLD )
+                b_bold = TRUE;
+            if( p_region_in->p_style->i_style_flags & STYLE_ITALIC )
+                b_italic = TRUE;
+            if( p_region_in->p_style->i_style_flags & STYLE_UNDERLINE )
+                b_uline = TRUE;
+        }
     }
     else
     {
@@ -369,7 +362,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
         CFRelease( p_cfString );
         len = CFAttributedStringGetLength( p_attrString );
 
-        setFontAttibutes( p_sys->psz_font_name, i_font_size, i_font_color, FALSE, FALSE, FALSE,
+        setFontAttibutes( p_sys->psz_font_name, i_font_size, i_font_color, b_bold, b_italic, b_uline,
                                              CFRangeMake( 0, len ), p_attrString);
 
         RenderYUVA( p_filter, p_region_out, p_attrString );
@@ -497,7 +490,7 @@ static int HandleFontAttributes( xml_reader_t *p_xml_reader,
         {
             if( !strcasecmp( "face", psz_name ) )
             {
-                if( psz_fontname ) free( psz_fontname );
+                free( psz_fontname );
                 psz_fontname = strdup( psz_value );
             }
             else if( !strcasecmp( "size", psz_name ) )
@@ -548,7 +541,7 @@ static void setFontAttibutes( char *psz_fontname, int i_font_size, uint32_t i_fo
 {
     CFStringRef p_cfString;
     CTFontRef   p_font;
-
+    
     // Handle font name and size
     p_cfString = CFStringCreateWithCString( NULL,
                                             psz_fontname,
@@ -834,7 +827,7 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
                     else
                     {
                         /* Only text and karaoke tags are supported */
-                        xml_ReaderDelete( p_xml, p_xml_reader );
+                        xml_ReaderDelete( p_xml_reader );
                         p_xml_reader = NULL;
                         rv = VLC_EGENERIC;
                     }
@@ -862,7 +855,7 @@ static int RenderHtml( filter_t *p_filter, subpicture_region_t *p_region_out,
                 }
                 CFRelease(p_attrString);
 
-                xml_ReaderDelete( p_xml, p_xml_reader );
+                xml_ReaderDelete( p_xml_reader );
             }
             xml_Delete( p_xml );
         }
@@ -911,9 +904,9 @@ static CGContextRef CreateOffScreenContext( int i_width, int i_height,
 
 static offscreen_bitmap_t *Compose( int i_text_align,
                                     CFMutableAttributedStringRef p_attrString,
-                                    int i_width,
-                                    int i_height,
-                                    int *pi_textblock_height )
+                                    unsigned i_width,
+                                    unsigned i_height,
+                                    unsigned *pi_textblock_height )
 {
     offscreen_bitmap_t  *p_offScreen  = NULL;
     CGColorSpaceRef      p_colorSpace = NULL;
@@ -1006,11 +999,11 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region,
                        CFMutableAttributedStringRef p_attrString )
 {
     offscreen_bitmap_t *p_offScreen = NULL;
-    int      i_textblock_height = 0;
+    unsigned      i_textblock_height = 0;
 
-    int i_width = p_filter->fmt_out.video.i_visible_width;
-    int i_height = p_filter->fmt_out.video.i_visible_height;
-    int i_text_align = p_region->i_align & 0x3;
+    unsigned i_width = p_filter->fmt_out.video.i_visible_width;
+    unsigned i_height = p_filter->fmt_out.video.i_visible_height;
+    unsigned i_text_align = p_region->i_align & 0x3;
 
     if( !p_attrString )
     {
@@ -1029,18 +1022,18 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region,
 
     uint8_t *p_dst_y,*p_dst_u,*p_dst_v,*p_dst_a;
     video_format_t fmt;
-    int x, y, i_offset, i_pitch;
+    int i_offset;
+    unsigned x, y, i_pitch;
     uint8_t i_y, i_u, i_v; // YUV values, derived from incoming RGB
 
     // Create a new subpicture region
     memset( &fmt, 0, sizeof(video_format_t) );
     fmt.i_chroma = VLC_CODEC_YUVA;
-    fmt.i_aspect = 0;
     fmt.i_width = fmt.i_visible_width = i_width;
     fmt.i_height = fmt.i_visible_height = __MIN( i_height, i_textblock_height + VERTICAL_MARGIN * 2);
     fmt.i_x_offset = fmt.i_y_offset = 0;
 
-    p_region->p_picture = picture_New( fmt.i_chroma, fmt.i_width, fmt.i_height, fmt.i_aspect );
+    p_region->p_picture = picture_NewFromFormat( &fmt );
     if( !p_region->p_picture )
         return VLC_EGENERIC;
     p_region->fmt = fmt;
@@ -1051,10 +1044,10 @@ static int RenderYUVA( filter_t *p_filter, subpicture_region_t *p_region,
     p_dst_a = p_region->p_picture->A_PIXELS;
     i_pitch = p_region->p_picture->A_PITCH;
 
-    i_offset = (i_height+VERTICAL_MARGIN < fmt.i_height) ? VERTICAL_MARGIN *i_pitch : 0 ;
-    for( y=0; y<fmt.i_height; y++)
+    i_offset = (i_height + VERTICAL_MARGIN < fmt.i_height) ? VERTICAL_MARGIN *i_pitch : 0 ;
+    for( y = 0; y < fmt.i_height; y++)
     {
-        for( x=0; x<fmt.i_width; x++)
+        for( x = 0; x < fmt.i_width; x++)
         {
             int i_alpha = p_offScreen->p_data[ y * p_offScreen->i_bytesPerRow + x * p_offScreen->i_bytesPerPixel     ];
             int i_red   = p_offScreen->p_data[ y * p_offScreen->i_bytesPerRow + x * p_offScreen->i_bytesPerPixel + 1 ];