- int i_char, i_line; /* character and line indexes */
- int i_file; /* 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 );
- if( i_file == -1 )
- {
- intf_ErrMsg("error: can't open file '%s' (%s)\n", 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 );
- close( i_file );
- return( NULL );
- }
-
- /* Allocate font descriptor */
- p_font = malloc( sizeof( vout_font_t ) );
- if( p_font == NULL )
- {
- intf_ErrMsg("error: %s\n", strerror(ENOMEM));
- close( i_file );
- return( NULL );
- }
-
- /* Read file */
- switch( ((u16)pi_buffer[0] << 8) | pi_buffer[1] )
- {
- 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.
- */
-
- /* 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 );
- free( p_font );
- close( i_file );
- return( NULL );
- }
-
- /* Copy font properties */
- p_font->i_type = VOUT_FIXED_FONT;
- p_font->i_width = 8;
- p_font->i_height = pi_buffer[1];
- p_font->i_interspacing = 8;
- p_font->i_bytes_per_line = 1;
- p_font->i_bytes_per_char = pi_buffer[1];
- 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] ? 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 );
+ subpicture_updater_sys_t *sys = subpic->updater.p_sys;
+ VLC_UNUSED(fmt_src); VLC_UNUSED(ts);
+
+ if( fmt_dst->i_sar_num <= 0 || fmt_dst->i_sar_den <= 0 )
+ return;
+
+ subpic->b_absolute = false;
+ subpic->i_original_picture_width = fmt_dst->i_width * fmt_dst->i_sar_num / fmt_dst->i_sar_den;
+ subpic->i_original_picture_height = fmt_dst->i_height;
+
+ video_format_t fmt;
+ video_format_Init( &fmt, VLC_CODEC_TEXT);
+ fmt.i_sar_num = 1;
+ fmt.i_sar_den = 1;
+
+ subpicture_region_t *r = subpic->p_region = subpicture_region_New(&fmt);
+ if (!r)
+ return;
+
+ r->psz_text = strdup(sys->text);
+
+ const float margin_ratio = 0.04;
+ const int margin_h = margin_ratio * fmt_dst->i_visible_width;
+ const int margin_v = margin_ratio * fmt_dst->i_visible_height;
+
+ r->i_align = sys->position;
+ r->i_x = 0;
+ if (r->i_align & SUBPICTURE_ALIGN_LEFT)
+ r->i_x += margin_h + fmt_dst->i_x_offset;
+ else if (r->i_align & SUBPICTURE_ALIGN_RIGHT)
+ r->i_x += margin_h + fmt_dst->i_width - (fmt_dst->i_visible_width + fmt_dst->i_x_offset);
+
+ r->i_y = 0;
+ if (r->i_align & SUBPICTURE_ALIGN_TOP )
+ r->i_y += margin_v + fmt_dst->i_y_offset;
+ else if (r->i_align & SUBPICTURE_ALIGN_BOTTOM )
+ r->i_y += margin_v + fmt_dst->i_height - (fmt_dst->i_visible_height + fmt_dst->i_y_offset);