]> git.sesse.net Git - vlc/blobdiff - src/video_output/video_text.c
* configure.ac.in, modules/codec/ffmpeg/*: a few direct rendering fixes and got rid...
[vlc] / src / video_output / video_text.c
index bbc552552314cb15d01e5df7403fcab6ba3b6099..62315fed472b2720f26284b5b24cf9ef79ab1607 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * video_text.c : text manipulation functions
  *****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
- * $Id: video_text.c,v 1.21 2001/04/06 18:18:10 massiot Exp $
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: video_text.c,v 1.42 2003/01/19 03:16:24 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+/* XXX: unused */
+#if 0
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "defs.h"
-
-#include <errno.h>                                                  /* errno */
 #include <stdlib.h>                                                /* free() */
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                            /* strerror() */
-#include <fcntl.h>                                                 /* open() */
-#include <unistd.h>                                       /* read(), close() */
 
-#ifdef SYS_BEOS
-#include "beos_specific.h"
+#include <vlc/vlc.h>
+
+#ifdef HAVE_ERRNO_H
+#   include <errno.h>                                               /* errno */
 #endif
 
-#include "config.h"
-#include "common.h"
-#include "video_text.h"
+#ifdef HAVE_FCNTL_H
+#   include <fcntl.h>                                              /* open() */
+#endif
 
-#ifdef SYS_DARWIN1_3
-// #include <CFBundle.h>
-#include <sys/param.h>                                    /* for MAXPATHLEN */
-#include "main.h"
-extern main_t *p_main;
+#ifdef HAVE_UNISTD_H
+#   include <unistd.h>                                    /* read(), close() */
+#elif defined( WIN32 ) && !defined( UNDER_CE )
+#   include <io.h>
 #endif
 
-#include "intf_msg.h"
+#include "video.h"
+#include "video_output.h"
+#include "video_text.h"
 
 /*****************************************************************************
  * vout_font_t: bitmap font
@@ -61,7 +61,7 @@ extern main_t *p_main;
  * Therefore the border masks can't be complete if the font has pixels on the
  * border.
  *****************************************************************************/
-typedef struct vout_font_s
+struct vout_font_t
 {
     int                 i_type;                                 /* font type */
     int                 i_width;                /* character width in pixels */
@@ -72,7 +72,7 @@ typedef struct vout_font_s
     u16                 i_first;                          /* first character */
     u16                 i_last;                            /* last character */
     byte_t *            p_data;                       /* font character data */
-} vout_font_t;
+};
 
 /* Font types */
 #define VOUT_FIXED_FONT       0                         /* simple fixed font */
@@ -215,45 +215,24 @@ static void PutByte32( u32 *p_pic, int i_byte, byte_t i_char, byte_t i_border,
  * This function will try to open a .psf font and load it. It will return
  * NULL on error.
  *****************************************************************************/
-vout_font_t *vout_LoadFont( const char *psz_name )
+vout_font_t *vout_LoadFont( vout_thread_t *p_vout, const char *psz_name )
 {
     static char * path[] = { "share", DATA_PATH, NULL, NULL };
 
     char **             ppsz_path = path;
     char *              psz_file;
-#ifdef SYS_BEOS
-    char *              psz_vlcpath = beos_GetProgramPath();
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
+    char *              psz_vlcpath = p_this->p_libvlc->psz_vlcpath;
     int                 i_vlclen = strlen( psz_vlcpath );
-#elif defined SYS_DARWIN1_3
-    static char         once = 0;
-    static char         app_path[ MAXPATHLEN ];
-    /* HACK TO CUT OUT trailing 'vlc' */
-    int                 i_pathlen = strlen( p_main->ppsz_argv[ 0 ] ) - 3;
-    // CFBundleRef         mainBundle;
 #endif
     int                 i_char, i_line;        /* character and line indexes */
     int                 i_file = -1;                          /* source file */
     byte_t              pi_buffer[2];                         /* file buffer */
     vout_font_t *       p_font;                           /* the font itself */
 
-#ifdef SYS_DARWIN1_3
-    // Get the main bundle for the app
-    // mainBundle = CFBundleGetMainBundle();
-
-    if( !once )
-    {
-       once = 1;
-        strncpy( app_path, p_main->ppsz_argv[ 0 ], i_pathlen );
-        intf_ErrMsg( "%s", p_main->ppsz_argv[ 0 ] );
-        strcat( app_path, "share" );
-        path[ 2 ] = app_path ;
-        intf_ErrMsg( "%s", path[ 2 ] );
-    }
-#endif
-
     for( ; *ppsz_path != NULL ; ppsz_path++ )
     {
-#ifdef SYS_BEOS
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
         /* Under BeOS, we need to add beos_GetProgramPath() to access
          * files under the current directory */
         if( strncmp( *ppsz_path, "/", 1 ) )
@@ -278,7 +257,9 @@ vout_font_t *vout_LoadFont( const char *psz_name )
         }
 
         /* Open file */
+#ifndef UNDER_CE /* FIXME */
         i_file = open( psz_file, O_RDONLY );
+#endif
         free( psz_file );
 
         if( i_file != -1 )
@@ -289,26 +270,32 @@ vout_font_t *vout_LoadFont( const char *psz_name )
 
     if( i_file == -1 )
     {
-        intf_DbgMsg( "vout error: can't open file '%s' (%s)",
-                     psz_name, strerror(errno) );
+#ifdef HAVE_ERRNO_H
+        msg_Err( p_vout, "cannot open '%s' (%s)", psz_name, strerror(errno) );
+#else
+        msg_Err( p_vout, "cannot open '%s'", psz_name );
+#endif
         return( NULL );
     }
 
-    /* Read magick number */
+    /* Read magic number */
+#ifndef UNDER_CE /* FIXME */
     if( read( i_file, pi_buffer, 2 ) != 2 )
     {
-        intf_ErrMsg("vout error: unexpected end of file '%s'", psz_name );
+        msg_Err( p_vout, "unexpected end of file in '%s'", psz_name );
         close( i_file );
         return( NULL );
     }
+#endif
 
     /* Allocate font descriptor */
     p_font = malloc( sizeof( vout_font_t ) );
     if( p_font == NULL )
     {
-        intf_ErrMsg( "vout error: cannot allocate vout_font_t (%s)",
-                     strerror(ENOMEM) );
+        msg_Err( p_vout, "out of memory" );
+#ifndef UNDER_CE /* FIXME */
         close( i_file );
+#endif
         return( NULL );
     }
 
@@ -322,13 +309,15 @@ vout_font_t *vout_LoadFont( const char *psz_name )
          */
 
         /* Read font header - two bytes indicate the font properties */
+#ifndef UNDER_CE /* FIXME */
         if( read( i_file, pi_buffer, 2 ) != 2)
         {
-            intf_ErrMsg( "vout error: unexpected end of file '%s'", psz_name );
+            msg_Err( p_vout, "unexpected end of file in '%s'", psz_name );
             free( p_font );
             close( i_file );
             return( NULL );
         }
+#endif
 
         /* Copy font properties */
         p_font->i_type =                VOUT_FIXED_FONT;
@@ -344,26 +333,29 @@ vout_font_t *vout_LoadFont( const char *psz_name )
         p_font->p_data = malloc( 2 * 256 * pi_buffer[1] );
         if( p_font->p_data == NULL )
         {
-            intf_ErrMsg( "vout error: cannot allocate font space (%s)",
-                         strerror(ENOMEM) );
+            msg_Err( p_vout, "out of memory" );
             free( p_font );
+#ifndef UNDER_CE /* FIXME */
             close( i_file );
+#endif
             return( NULL );
         }
 
         /* Copy raw data */
+#ifndef UNDER_CE /* FIXME */
         if( read( i_file, p_font->p_data, 256 * pi_buffer[1] ) != 256 * pi_buffer[1] )
         {
-            intf_ErrMsg("vout error: unexpected end of file '%s'", psz_name );
+            msg_Err( p_vout, "unexpected end of file in '%s'", psz_name );
             free( p_font->p_data );
             free( p_font );
             close( i_file );
             return( NULL );
         }
+#endif
 
-        /* Computes border masks - remember that masks have the same matrix as
-         * characters, so an empty character border is required to have a complete
-         * border mask. */
+        /* Compute border masks - remember that masks have the same matrix as
+         * characters, so an empty character border is required to have a
+         * complete border mask. */
         for( i_char = 0; i_char <= 255; i_char++ )
         {
             for( i_line = 0; i_line < pi_buffer[1]; i_line++ )
@@ -380,16 +372,18 @@ vout_font_t *vout_LoadFont( const char *psz_name )
 
         break;
     default:
-        intf_ErrMsg("vout error: file '%s' has an unknown format", psz_name );
+        msg_Err( p_vout, "file '%s' has an unknown format", psz_name );
         free( p_font );
+#ifndef UNDER_CE /* FIXME */
         close( i_file );
+#endif
         return( NULL );
         break;
     }
 
+    msg_Err( p_vout, "loaded %s, type %d, %d-%dx%d", psz_name, p_font->i_type,
+             p_font->i_width, p_font->i_interspacing, p_font->i_height );
 
-    intf_DbgMsg( "loaded %s: type %d, %d-%dx%d", psz_name, p_font->i_type,
-                 p_font->i_width, p_font->i_interspacing, p_font->i_height );
     return( p_font );
 }
 
@@ -400,7 +394,12 @@ vout_font_t *vout_LoadFont( const char *psz_name )
  *****************************************************************************/
 void vout_UnloadFont( vout_font_t *p_font )
 {
-    intf_DbgMsg( "vout: unloading font %p", p_font );
+    /* If no font was loaded, do nothing */
+    if( p_font == NULL )
+    {
+        return;
+    }
+
     free( p_font->p_data );
     free( p_font );
 }
@@ -413,6 +412,13 @@ void vout_UnloadFont( vout_font_t *p_font )
  *****************************************************************************/
 void vout_TextSize( vout_font_t *p_font, int i_style, const char *psz_text, int *pi_width, int *pi_height )
 {
+    /* If no font was loaded, do nothing */
+    if( p_font == NULL )
+    {
+        *pi_width = *pi_height = 0;
+        return;
+    }
+
     switch( p_font->i_type )
     {
     case VOUT_FIXED_FONT:
@@ -424,11 +430,6 @@ void vout_TextSize( vout_font_t *p_font, int i_style, const char *psz_text, int
             *pi_width = *pi_height / 3;
         }
         break;
-#ifdef DEBUG
-    default:
-        intf_DbgMsg("error: unknown font type %d", p_font->i_type );
-        break;
-#endif
     }
 }
 
@@ -441,15 +442,21 @@ void vout_TextSize( vout_font_t *p_font, int i_style, const char *psz_text, int
 void vout_Print( vout_font_t *p_font, byte_t *p_pic, int i_bytes_per_pixel, int i_bytes_per_line,
                  u32 i_char_color, u32 i_border_color, u32 i_bg_color, int i_style, const char *psz_text, int i_percent)
 {
-    byte_t      *p_char, *p_border;        /* character and border mask data */
-    int         i_char_mask, i_border_mask, i_bg_mask;              /* masks */
-    int         i_line;                         /* current line in character */
-    int         i_byte;                         /* current byte in character */
-    int         i_interspacing;                  /* offset between two chars */
-    int         i_font_bytes_per_line, i_font_height;     /* font properties */
-    int         i_position, i_end;                      /* current position  */
+    byte_t       *p_char, *p_border;       /* character and border mask data */
+    int          i_char_mask, i_border_mask, i_bg_mask;             /* masks */
+    int          i_line;                        /* current line in character */
+    int          i_byte;                        /* current byte in character */
+    int          i_interspacing;                 /* offset between two chars */
+    int          i_font_bytes_per_line, i_font_height;    /* font properties */
+    unsigned int i_position, i_end;                     /* current position  */
     vout_put_byte_t *p_PutByte;                          /* PutByte function */
 
+    /* If no font was loaded, do nothing */
+    if( p_font == NULL )
+    {
+        return;
+    }
+
     /* FIXME: background: can be something else that whole byte ?? */
 
     /* Select output function */
@@ -482,7 +489,7 @@ void vout_Print( vout_font_t *p_font, byte_t *p_pic, int i_bytes_per_pixel, int
                                                      p_font->i_interspacing);
 
     /* compute where to stop... */
-    i_end = (int) (i_percent * strlen(psz_text) / 100LL);
+    i_end = (int) (i_percent * strlen(psz_text) / (s64)100);
     if(i_end > strlen(psz_text))
         i_end = strlen(psz_text);
     
@@ -533,14 +540,8 @@ void vout_Print( vout_font_t *p_font, byte_t *p_pic, int i_bytes_per_pixel, int
                 /* Jump to next character */
                 p_pic += i_interspacing;
                 break;
-#ifdef DEBUG
-            default:
-                intf_DbgMsg("error: unknown font type %d", p_font->i_type );
-                break;
-#endif
             }
         }
-    
     }
 }
 
@@ -604,4 +605,4 @@ static void PutByte32( u32 *p_pic, int i_byte, byte_t i_char, byte_t i_border, b
     PUT_BYTE_MASK(i_border, i_border_color);
     PUT_BYTE_MASK(i_bg, i_bg_color);
 }
-
+#endif