[vlc-devel] Re: [PATCH] italic tag support fo MPL2 subtitles
Roman Bednarek
roman at mikronika.com.pl
Wed Feb 21 21:57:08 CET 2007
On Wed, 21 Feb 2007, Remi Denis-Courmont wrote:
>> I just postponed adding a de-escaping function, where should I place
>> it?
>
> Depends how complicated it is. Trivial functions can be inlined in include/
> More complex ones can go in src/text/ if code duplication is to be avoided.
>
Second version of the MPL2 italic patch.
I have changed the escape code to ESC=27, and added StripControlCodes
function to not supported renderers (win32text and svg). I have copied the
function twice, I do know know how to add new file properly.
I do not see more problems with it, if you generally accept the idea of
embedding control codes into text.
I thought about proposed ANSI escape codes and pango markup language,
but I wanted something very simple and rich enough for subtitle needs.
Regards
Roman Bednarek
-------------- next part --------------
Index: modules/demux/subtitle.c
===================================================================
--- modules/demux/subtitle.c (revision 18935)
+++ modules/demux/subtitle.c (working copy)
@@ -1311,8 +1311,12 @@
char buffer_text[MAX_LINE + 1];
int i_start;
int i_stop;
- unsigned int i;
+ unsigned int i,j;
+ char output_text[MAX_LINE + 1];
+ int output_italic;
+ int output_start_line;
+
p_subtitle->i_start = 0;
p_subtitle->i_stop = 0;
p_subtitle->psz_text = NULL;
@@ -1334,16 +1338,45 @@
}
}
- /* replace | by \n */
- for( i = 0; i < strlen( buffer_text ); i++ )
+ memset( output_text, '\0', MAX_LINE );
+ output_start_line = VLC_TRUE;
+ output_italic = VLC_FALSE;
+ for( i = 0,j=0; i < strlen( buffer_text ) && j<MAX_LINE-2; i++ )
{
+ if( output_start_line )
+ {
+ output_start_line = VLC_FALSE;
+ if( buffer_text[i] == '/' )
+ {
+ if( !output_italic )
+ {
+ output_text[j++] = 27;
+ output_text[j++] = 'I';
+ output_italic = VLC_TRUE;
+ }
+ continue;
+ }
+ else if( buffer_text[i] != '/' && output_italic )
+ {
+ output_text[j++] = 27;
+ output_text[j++] = 'i';
+ output_italic = VLC_FALSE;
+ }
+ }
if( buffer_text[i] == '|' )
{
- buffer_text[i] = '\n';
+ output_text[j++] = '\n';
+ output_start_line=VLC_TRUE;
}
+ else
+ {
+ output_text[j++] = buffer_text[i];
+ }
}
+ output_text[j]=0;
+
p_subtitle->i_start = (int64_t)i_start * 100000;
p_subtitle->i_stop = (int64_t)i_stop * 100000;
- p_subtitle->psz_text = strndup( buffer_text, MAX_LINE );
+ p_subtitle->psz_text = strndup( output_text, MAX_LINE );
return( 0 );
}
Index: modules/misc/svg.c
===================================================================
--- modules/misc/svg.c (revision 18935)
+++ modules/misc/svg.c (working copy)
@@ -58,7 +58,29 @@
static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
subpicture_region_t *p_region_in );
+static void StripControlCodes( char *psz_text )
+{
+ int i_left_moves = 0;
+ int i = 0;
+
+ if( !psz_text ) return;
+ while( psz_text[ i ] )
+ {
+ if( psz_text[ i ] == 27 )
+ {
+ i++;
+ i_left_moves+=2;
+ }
+ else
+ {
+ psz_text[ i - i_left_moves ] = psz_text[ i ];
+ }
+ i++;
+ }
+ psz_text[ i - i_left_moves ] = '\0';
+}
+
/*****************************************************************************
* Module descriptor
*****************************************************************************/
@@ -445,6 +467,8 @@
psz_string = p_region_in->psz_text;
if( !psz_string || !*psz_string ) return VLC_EGENERIC;
+ StripControlCodes(psz_string);
+
p_svg = ( svg_rendition_t * )malloc( sizeof( svg_rendition_t ) );
if( !p_svg )
{
Index: modules/misc/win32text.c
===================================================================
--- modules/misc/win32text.c (revision 18935)
+++ modules/misc/win32text.c (working copy)
@@ -48,6 +48,29 @@
static int Render( filter_t *, subpicture_region_t *, uint8_t *, int, int);
static int SetFont( filter_t *, int );
+static void StripControlCodes( char *psz_text )
+{
+ int i_left_moves = 0;
+ int i = 0;
+
+ if( !psz_text ) return;
+
+ while( psz_text[ i ] )
+ {
+ if( psz_text[ i ] == 27 )
+ {
+ i++;
+ i_left_moves+=2;
+ }
+ else
+ {
+ psz_text[ i - i_left_moves ] = psz_text[ i ];
+ }
+ i++;
+ }
+ psz_text[ i - i_left_moves ] = '\0';
+}
+
/*****************************************************************************
* Module descriptor
*****************************************************************************/
@@ -307,6 +330,9 @@
/* Sanity check */
if( !p_region_in || !p_region_out ) return VLC_EGENERIC;
+
+ StripControlCodes( p_region_in->psz_text );
+
#ifdef UNICODE
psz_string = malloc( (strlen( p_region_in->psz_text )+1) * sizeof(TCHAR) );
if( mbstowcs( psz_string, p_region_in->psz_text,
Index: modules/misc/freetype.c
===================================================================
--- modules/misc/freetype.c (revision 18935)
+++ modules/misc/freetype.c (working copy)
@@ -829,6 +829,9 @@
#define face p_sys->p_face
#define glyph face->glyph
+ // reset transform
+ FT_Set_Transform( face, NULL, NULL );
+
while( *psz_unicode )
{
i_char = *psz_unicode++;
@@ -837,6 +840,28 @@
continue;
}
+ if( i_char == 27 ) // control code
+ {
+ i_char = *psz_unicode++;
+ if( !i_char ) break;
+
+ if( i_char == 'I' )
+ {
+ FT_Matrix slantMat;
+ slantMat.xx = (1 << 16);
+ slantMat.xy = ((1 << 16) >> 2);
+ slantMat.yx = 0;
+ slantMat.yy = (1 << 16);
+ FT_Set_Transform( face, &slantMat, NULL );
+ continue;
+ }
+ else if( i_char == 'i' )
+ {
+ FT_Set_Transform( face, NULL, NULL );
+ continue;
+ }
+ }
+
if( i_char == '\n' )
{
psz_line_start = psz_unicode;
More information about the vlc-devel
mailing list