/*****************************************************************************
* video_text.c : text manipulation functions
- * (c)1999 VideoLAN
+ *****************************************************************************
+ * 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>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
+/* XXX: unused */
+#if 0
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "config.h"
+#include <stdlib.h> /* free() */
+#include <stdio.h> /* sprintf() */
+#include <string.h> /* strerror() */
+
+#include <vlc/vlc.h>
+
+#ifdef HAVE_ERRNO_H
+# include <errno.h> /* errno */
+#endif
+
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h> /* open() */
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h> /* read(), close() */
+#elif defined( WIN32 ) && !defined( UNDER_CE )
+# include <io.h>
+#endif
+
+#include "video.h"
+#include "video_output.h"
#include "video_text.h"
-#include "intf_msg.h"
/*****************************************************************************
* vout_font_t: bitmap font
* 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 */
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 */
* 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;
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
+ char * psz_vlcpath = p_this->p_libvlc->psz_vlcpath;
+ int i_vlclen = strlen( psz_vlcpath );
+#endif
int i_char, i_line; /* character and line indexes */
- int i_file; /* source file */
+ int i_file = -1; /* source file */
byte_t pi_buffer[2]; /* file buffer */
vout_font_t * p_font; /* the font itself */
- /* Open file */
- i_file = open( psz_name, O_RDONLY );
+ for( ; *ppsz_path != NULL ; ppsz_path++ )
+ {
+#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 ) )
+ {
+ psz_file = malloc( strlen( psz_name ) + strlen( *ppsz_path )
+ + i_vlclen + 3 );
+ if( psz_file == NULL )
+ {
+ continue;
+ }
+ sprintf( psz_file, "%s/%s/%s", psz_vlcpath, *ppsz_path, psz_name );
+ }
+ else
+#endif
+ {
+ psz_file = malloc( strlen( psz_name ) + strlen( *ppsz_path ) + 2 );
+ if( psz_file == NULL )
+ {
+ continue;
+ }
+ sprintf( psz_file, "%s/%s", *ppsz_path, psz_name );
+ }
+
+ /* Open file */
+#ifndef UNDER_CE /* FIXME */
+ i_file = open( psz_file, O_RDONLY );
+#endif
+ free( psz_file );
+
+ if( i_file != -1 )
+ {
+ break;
+ }
+ }
+
if( i_file == -1 )
{
- intf_ErrMsg("error: can't open file '%s' (%s)\n", 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("error: unexpected end of file '%s'\n", 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("error: %s\n", strerror(ENOMEM));
+ msg_Err( p_vout, "out of memory" );
+#ifndef UNDER_CE /* FIXME */
close( i_file );
+#endif
return( NULL );
}
case 0x3604: /* .psf file */
/*
* PSF font: simple fixed font. Only the first 256 characters are read.
- * Those fonts are always 1 byte width, and 256 or 512 characters long.
+ * Those fonts are always 1 byte wide, and 256 or 512 characters long.
*/
/* Read font header - two bytes indicate the font properties */
+#ifndef UNDER_CE /* FIXME */
if( read( i_file, pi_buffer, 2 ) != 2)
{
- intf_ErrMsg("error: unexpected end of file '%s'\n", 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;
p_font->p_data = malloc( 2 * 256 * pi_buffer[1] );
if( p_font->p_data == NULL )
{
- intf_ErrMsg("error: %s\n", 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("error: unexpected end of file '%s'\n", 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++ )
break;
default:
- intf_ErrMsg("error: file '%s' has an unknown format\n", 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\n", psz_name, p_font->i_type,
- p_font->i_width, p_font->i_interspacing, p_font->i_height );
return( p_font );
}
*****************************************************************************/
void vout_UnloadFont( vout_font_t *p_font )
{
- intf_DbgMsg( "font %p\n", p_font );
+ /* If no font was loaded, do nothing */
+ if( p_font == NULL )
+ {
+ return;
+ }
+
free( p_font->p_data );
free( 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:
*pi_width = *pi_height / 3;
}
break;
-#ifdef DEBUG
- default:
- intf_DbgMsg("error: unknown font type %d\n", p_font->i_type );
- break;
-#endif
}
}
* previously loaded bitmap font.
*****************************************************************************/
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 )
+ 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 */
+ 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 */
p_font->i_interspacing * 2 :
p_font->i_interspacing);
+ /* compute where to stop... */
+ i_end = (int) (i_percent * strlen(psz_text) / (s64)100);
+ if(i_end > strlen(psz_text))
+ i_end = strlen(psz_text);
+
+
/* Print text */
- for( ; *psz_text != '\0'; psz_text++ )
+ for( i_position = 0; i_position < i_end; i_position++ ,psz_text++ )
{
/* Check that the character is valid */
if( (*psz_text >= p_font->i_first) && (*psz_text <= p_font->i_last) )
/* Jump to next character */
p_pic += i_interspacing;
break;
-#ifdef DEBUG
- default:
- intf_DbgMsg("error: unknown font type %d\n", p_font->i_type );
- break;
-#endif
}
}
}
PUT_BYTE_MASK(i_border, i_border_color);
PUT_BYTE_MASK(i_bg, i_bg_color);
}
-
+#endif