📄 video_text.c
字号:
p_font->i_first = 0; p_font->i_last = 255; /* Allocate font space */ p_font->p_data = malloc( 2 * 256 * pi_buffer[1] ); if( p_font->p_data == NULL ) { intf_ErrMsg("error: %s\n", strerror(ENOMEM)); free( p_font ); close( i_file ); return( NULL ); } /* 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 ); free( p_font->p_data ); free( p_font ); close( i_file ); return( NULL ); } /* 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. */ for( i_char = 0; i_char <= 255; i_char++ ) { for( i_line = 0; i_line < pi_buffer[1]; i_line++ ) { p_font->p_data[ (i_char + 256) * pi_buffer[1] + i_line ] = ((p_font->p_data[ i_char * pi_buffer[1] + i_line ] << 1) | (p_font->p_data[ i_char * pi_buffer[1] + i_line ] >> 1) | (i_line > 0 ? p_font->p_data[ i_char * pi_buffer[1] + i_line - 1]: 0) | (i_line < pi_buffer[1] - 1 ? p_font->p_data[ i_char * pi_buffer[1] + i_line + 1]: 0)) & ~p_font->p_data[ i_char * pi_buffer[1] + i_line ]; } } break; default: intf_ErrMsg("error: file '%s' has an unknown format\n", psz_name ); free( p_font ); close( i_file ); return( NULL ); break; } 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 );}/***************************************************************************** * vout_UnloadFont: unload a font ***************************************************************************** * This function free the resources allocated by vout_LoadFont *****************************************************************************/void vout_UnloadFont( vout_font_t *p_font ){ intf_DbgMsg( "font %p\n", p_font ); free( p_font->p_data ); free( p_font );}/***************************************************************************** * vout_TextSize: return the dimensions of a text ***************************************************************************** * This function is used to align text. It returns the width and height of a * given text. *****************************************************************************/void vout_TextSize( vout_font_t *p_font, int i_style, const char *psz_text, int *pi_width, int *pi_height ){ switch( p_font->i_type ) { case VOUT_FIXED_FONT: *pi_width = ((i_style & WIDE_TEXT) ? p_font->i_interspacing * 2 : p_font->i_interspacing) * (strlen( psz_text ) - 1) + p_font->i_width; *pi_height = p_font->i_height; if( i_style & ITALIC_TEXT ) { *pi_width = *pi_height / 3; } break;#ifdef DEBUG default: intf_DbgMsg("error: unknown font type %d\n", p_font->i_type ); break;#endif }}/***************************************************************************** * vout_Print: low level printing function ***************************************************************************** * This function prints a text, without clipping, in a buffer using a * 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 ){ 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 */ vout_put_byte_t *p_PutByte; /* PutByte function */ /* FIXME: background: can be something else that whole byte ?? */ /* Select output function */ switch( i_bytes_per_pixel ) { case 1: p_PutByte = (vout_put_byte_t *) PutByte8; break; case 2: p_PutByte = (vout_put_byte_t *) PutByte16; break; case 3: p_PutByte = (vout_put_byte_t *) PutByte24; break; case 4: default: p_PutByte = (vout_put_byte_t *) PutByte32; break; } /* Choose masks and copy font data to local variables */ i_char_mask = (i_style & VOID_TEXT) ? 0 : 0xff; i_border_mask = (i_style & OUTLINED_TEXT) ? 0xff : 0; i_bg_mask = (i_style & OPAQUE_TEXT) ? 0xff : 0; i_font_bytes_per_line = p_font->i_bytes_per_line; i_font_height = p_font->i_height; i_interspacing = i_bytes_per_pixel * ((i_style & WIDE_TEXT) ? p_font->i_interspacing * 2 : p_font->i_interspacing); /* Print text */ for( ; *psz_text != '\0'; psz_text++ ) { /* Check that the character is valid */ if( (*psz_text >= p_font->i_first) && (*psz_text <= p_font->i_last) ) { /* Select character - bytes per char is always valid, event for * non fixed fonts */ p_char = p_font->p_data + (*psz_text - p_font->i_first) * p_font->i_bytes_per_char; p_border = p_char + (p_font->i_last - p_font->i_first + 1) * p_font->i_bytes_per_char; /* Select base address for output */ switch( p_font->i_type ) { case VOUT_FIXED_FONT: /* * Simple fixed width font */ /* Italic text: shift picture start right */ if( i_style & ITALIC_TEXT ) { p_pic += i_bytes_per_pixel * (p_font->i_height / 3); } /* Print character */ for( i_line = 0; i_line < i_font_height; i_line ++ ) { for( i_byte = 0; i_byte < i_font_bytes_per_line; i_byte++, p_char++, p_border++) { /* Put pixels */ p_PutByte( p_pic + i_bytes_per_line * i_line, i_byte, *p_char & i_char_mask, *p_border & i_border_mask, i_bg_mask, i_char_color, i_border_color, i_bg_color ); } /* Italic text: shift picture start left */ if( (i_style & ITALIC_TEXT) && !(i_line % 3) ) { p_pic -= i_bytes_per_pixel; } } /* 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 } } }}/* following functions are local *//***************************************************************************** * PutByte8: print a fixed width font character byte in 1 Bpp *****************************************************************************/static void PutByte8( u8 *p_pic, int i_byte, int i_char, int i_border, int i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color ){ /* Computes position offset and background mask */ p_pic += 8 * i_byte; i_bg &= ~(i_char | i_border); /* Put character bits */ PUT_BYTE_MASK(i_char, i_char_color); PUT_BYTE_MASK(i_border, i_border_color); PUT_BYTE_MASK(i_bg, i_bg_color);}/***************************************************************************** * PutByte16: print a fixed width font character byte in 2 Bpp *****************************************************************************/static void PutByte16( u16 *p_pic, int i_byte, int i_char, int i_border, int i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color ){ /* Computes position offset and background mask */ p_pic += 8 * i_byte; i_bg &= ~(i_char | i_border); /* Put character bits */ PUT_BYTE_MASK(i_char, i_char_color); PUT_BYTE_MASK(i_border, i_border_color); PUT_BYTE_MASK(i_bg, i_bg_color);}/***************************************************************************** * PutByte24: print a fixed width font character byte in 3 Bpp *****************************************************************************/static void PutByte24( void *p_pic, int i_byte, byte_t i_char, byte_t i_border, byte_t i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color ){ /* XXX?? */}/***************************************************************************** * PutByte32: print a fixed width font character byte in 4 Bpp *****************************************************************************/static void PutByte32( u32 *p_pic, int i_byte, byte_t i_char, byte_t i_border, byte_t i_bg, u32 i_char_color, u32 i_border_color, u32 i_bg_color ){ /* Computes position offset and background mask */ p_pic += 8 * i_byte; i_bg &= ~(i_char | i_border); /* Put character bits */ PUT_BYTE_MASK(i_char, i_char_color); PUT_BYTE_MASK(i_border, i_border_color); PUT_BYTE_MASK(i_bg, i_bg_color);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -