X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fvideo_output%2Fvideo_text.c;h=b1e3d8a04adbeb9b942e420650439356fb174a3e;hb=583c6553f6761421260d86bbc21b5b3169c04319;hp=d21a5f430bb2c179feb98742090ab981b3da66c3;hpb=44bcfed01477db0b57e6f08048bbee72f032aa7e;p=vlc diff --git a/src/video_output/video_text.c b/src/video_output/video_text.c index d21a5f430b..b1e3d8a04a 100644 --- a/src/video_output/video_text.c +++ b/src/video_output/video_text.c @@ -9,29 +9,31 @@ * 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. + * 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-1307, USA. + * 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. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ +#include "defs.h" + #include /* errno */ #include /* free() */ +#include /* sprintf() */ #include /* strerror() */ #include /* open() */ #include /* read(), close() */ -#include "common.h" #include "config.h" +#include "common.h" #include "video_text.h" #include "intf_msg.h" @@ -202,23 +204,66 @@ 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 }; + + char ** ppsz_path = path; + char * psz_file; +#ifdef SYS_BEOS + char * psz_vlcpath = beos_GetProgramPath(); + 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++ ) + { +#ifdef SYS_BEOS + /* 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 */ + i_file = open( psz_file, O_RDONLY ); + 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)); + intf_DbgMsg( "vout error: can't open file '%s' (%s)", + psz_name, strerror(errno) ); return( NULL ); } /* Read magick number */ if( read( i_file, pi_buffer, 2 ) != 2 ) { - intf_ErrMsg("error: unexpected end of file '%s'\n", psz_name ); + intf_ErrMsg("vout error: unexpected end of file '%s'", psz_name ); close( i_file ); return( NULL ); } @@ -227,7 +272,8 @@ vout_font_t *vout_LoadFont( const char *psz_name ) p_font = malloc( sizeof( vout_font_t ) ); if( p_font == NULL ) { - intf_ErrMsg("error: %s\n", strerror(ENOMEM)); + intf_ErrMsg( "vout error: cannot allocate vout_font_t (%s)", + strerror(ENOMEM) ); close( i_file ); return( NULL ); } @@ -238,13 +284,13 @@ vout_font_t *vout_LoadFont( const char *psz_name ) 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 */ if( read( i_file, pi_buffer, 2 ) != 2) { - intf_ErrMsg("error: unexpected end of file '%s'\n", psz_name ); + intf_ErrMsg( "vout error: unexpected end of file '%s'", psz_name ); free( p_font ); close( i_file ); return( NULL ); @@ -264,7 +310,8 @@ 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("error: %s\n", strerror(ENOMEM)); + intf_ErrMsg( "vout error: cannot allocate font space (%s)", + strerror(ENOMEM) ); free( p_font ); close( i_file ); return( NULL ); @@ -273,7 +320,7 @@ vout_font_t *vout_LoadFont( const char *psz_name ) /* Copy raw data */ 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 ); + intf_ErrMsg("vout error: unexpected end of file '%s'", psz_name ); free( p_font->p_data ); free( p_font ); close( i_file ); @@ -299,7 +346,7 @@ vout_font_t *vout_LoadFont( const char *psz_name ) break; default: - intf_ErrMsg("error: file '%s' has an unknown format\n", psz_name ); + intf_ErrMsg("vout error: file '%s' has an unknown format", psz_name ); free( p_font ); close( i_file ); return( NULL ); @@ -307,7 +354,7 @@ vout_font_t *vout_LoadFont( const char *psz_name ) } - intf_DbgMsg( "loaded %s: type %d, %d-%dx%d\n", psz_name, p_font->i_type, + 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 ); } @@ -319,7 +366,7 @@ vout_font_t *vout_LoadFont( const char *psz_name ) *****************************************************************************/ void vout_UnloadFont( vout_font_t *p_font ) { - intf_DbgMsg( "font %p\n", p_font ); + intf_DbgMsg( "vout: unloading font %p", p_font ); free( p_font->p_data ); free( p_font ); } @@ -345,7 +392,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\n", p_font->i_type ); + intf_DbgMsg("error: unknown font type %d", p_font->i_type ); break; #endif } @@ -358,7 +405,7 @@ void vout_TextSize( vout_font_t *p_font, int i_style, const char *psz_text, int * 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 */ @@ -366,6 +413,7 @@ void vout_Print( vout_font_t *p_font, byte_t *p_pic, int i_bytes_per_pixel, int 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 */ vout_put_byte_t *p_PutByte; /* PutByte function */ /* FIXME: background: can be something else that whole byte ?? */ @@ -399,8 +447,14 @@ void vout_Print( vout_font_t *p_font, byte_t *p_pic, int i_bytes_per_pixel, int p_font->i_interspacing * 2 : p_font->i_interspacing); + /* compute where to stop... */ + i_end = (int) (i_percent * strlen(psz_text) / 100LL); + 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) ) @@ -447,11 +501,12 @@ 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\n", p_font->i_type ); + intf_DbgMsg("error: unknown font type %d", p_font->i_type ); break; #endif } } + } }