]> git.sesse.net Git - vlc/blobdiff - src/video_output/video_text.c
* Win2000 DVD input by Jon Lech Johansen <jon-vl@nanocrew.net>.
[vlc] / src / video_output / video_text.c
index 1dd05f3b8b519bf5b21f109e1572073f7ea933a5..98157994bb51a32a85f4fedb1736a4ac7b911e03 100644 (file)
@@ -2,6 +2,7 @@
  * video_text.c : text manipulation functions
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
+ * $Id: video_text.c,v 1.28 2001/05/31 03:12:49 sam Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                            /* strerror() */
 #include <fcntl.h>                                                 /* open() */
-#include <unistd.h>                                       /* read(), close() */
+
+#ifdef HAVE_UNISTD_H
+#   include <unistd.h>                                    /* read(), close() */
+#elif defined( _MSC_VER ) && defined( _WIN32 )
+#   include <io.h>
+#endif
 
 #ifdef SYS_BEOS
-#include "beos_specific.h"
+#   include "beos_specific.h"
+#endif
+
+#ifdef SYS_DARWIN1_3
+#   include "darwin_specific.h"
+#endif
+
+#if defined( WIN32 )
+#   include <io.h>
 #endif
 
 #include "config.h"
@@ -209,12 +223,12 @@ static void PutByte32( u32 *p_pic, int i_byte, byte_t i_char, byte_t i_border,
  *****************************************************************************/
 vout_font_t *vout_LoadFont( const char *psz_name )
 {
-    static char * path[] = { "share", DATA_PATH, NULL };
+    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_DARWIN1_3 )
+    char *              psz_vlcpath = system_GetProgramPath();
     int                 i_vlclen = strlen( psz_vlcpath );
 #endif
     int                 i_char, i_line;        /* character and line indexes */
@@ -224,7 +238,7 @@ vout_font_t *vout_LoadFont( const char *psz_name )
 
     for( ; *ppsz_path != NULL ; ppsz_path++ )
     {
-#ifdef SYS_BEOS
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
         /* Under BeOS, we need to add beos_GetProgramPath() to access
          * files under the current directory */
         if( strncmp( *ppsz_path, "/", 1 ) )
@@ -249,7 +263,11 @@ vout_font_t *vout_LoadFont( const char *psz_name )
         }
 
         /* Open file */
+#ifndef WIN32
         i_file = open( psz_file, O_RDONLY );
+#else
+        i_file = open( psz_file, O_RDONLY | O_BINARY );
+#endif
         free( psz_file );
 
         if( i_file != -1 )
@@ -371,6 +389,12 @@ vout_font_t *vout_LoadFont( const char *psz_name )
  *****************************************************************************/
 void vout_UnloadFont( vout_font_t *p_font )
 {
+    /* If no font was loaded, do nothing */
+    if( p_font == NULL )
+    {
+        return;
+    }
+
     intf_DbgMsg( "vout: unloading font %p", p_font );
     free( p_font->p_data );
     free( p_font );
@@ -384,6 +408,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:
@@ -397,7 +428,7 @@ void vout_TextSize( vout_font_t *p_font, int i_style, const char *psz_text, int
         break;
 #ifdef DEBUG
     default:
-        intf_DbgMsg("error: unknown font type %d", p_font->i_type );
+        intf_ErrMsg("error: unknown font type %d", p_font->i_type );
         break;
 #endif
     }
@@ -421,6 +452,12 @@ void vout_Print( vout_font_t *p_font, byte_t *p_pic, int i_bytes_per_pixel, int
     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 */
@@ -453,7 +490,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) / I64C(100));
     if(i_end > strlen(psz_text))
         i_end = strlen(psz_text);
     
@@ -506,7 +543,7 @@ void vout_Print( vout_font_t *p_font, byte_t *p_pic, int i_bytes_per_pixel, int
                 break;
 #ifdef DEBUG
             default:
-                intf_DbgMsg("error: unknown font type %d", p_font->i_type );
+                intf_ErrMsg("error: unknown font type %d", p_font->i_type );
                 break;
 #endif
             }