]> git.sesse.net Git - vlc/blobdiff - modules/misc/win32text.c
Adjustments to better match VLC coding style.
[vlc] / modules / misc / win32text.c
index b48f856645126b52ca93c5b059d973b36633d14a..e3464674ed26ea50961fd1afe1b8455918d1fc0e 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * win32text.c : Text drawing routines using the TextOut win32 API
  *****************************************************************************
- * Copyright (C) 2002 - 2005 the VideoLAN team
+ * Copyright (C) 2002 - 2009 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
+ *          Pierre Ynard
  *
  * 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
@@ -227,6 +228,9 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
     fmt.i_x_offset = fmt.i_y_offset = 0;
 
     /* Build palette */
+    fmt.p_palette = calloc( 1, sizeof(*fmt.p_palette) );
+    if( !fmt.p_palette )
+        return VLC_EGENERIC;
     fmt.p_palette->i_entries = 16;
     for( i = 0; i < fmt.p_palette->i_entries; i++ )
     {
@@ -236,9 +240,12 @@ static int Render( filter_t *p_filter, subpicture_region_t *p_region,
         fmt.p_palette->palette[i][3] = pi_gamma[i];
     }
 
-    p_region->p_picture = picture_New( fmt.i_chroma, fmt.i_width, fmt.i_height, fmt.i_aspect );
+    p_region->p_picture = picture_NewFromFormat( &fmt );
     if( !p_region->p_picture )
+    {
+        free( fmt.p_palette );
         return VLC_EGENERIC;
+    }
     p_region->fmt = fmt;
 
     p_dst = p_region->p_picture->Y_PIXELS;
@@ -296,11 +303,13 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
     int i, i_width, i_height;
     HBITMAP bitmap, bitmap_bak;
     BITMAPINFO *p_bmi;
-    RECT rect = {0};
-    SIZE size;
+    RECT rect = { 0, 0, 0, 0 };
 
     /* Sanity check */
     if( !p_region_in || !p_region_out ) return VLC_EGENERIC;
+    if( !p_region_in->psz_text || !*p_region_in->psz_text )
+        return VLC_EGENERIC;
+
     psz_string = malloc( (strlen( p_region_in->psz_text )+1) * sizeof(TCHAR) );
     if( !psz_string )
         return VLC_ENOMEM;
@@ -338,9 +347,9 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
     SetTextColor( p_sys->hcdc, RGB( (i_font_color >> 16) & 0xff,
                   (i_font_color >> 8) & 0xff, i_font_color & 0xff) );
 
-    GetTextExtentExPoint( p_sys->hcdc, psz_string, _tcslen(psz_string),
-                          0, 0, 0, &size );
-    i_width = rect.right = size.cx; i_height = rect.bottom = size.cy;
+    DrawText( p_sys->hcdc, psz_string, -1, &rect,
+              DT_CALCRECT | DT_CENTER | DT_NOPREFIX );
+    i_width = rect.right; i_height = rect.bottom;
 
     p_bmi = malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*16);
     memset( p_bmi, 0, sizeof(BITMAPINFOHEADER) );
@@ -364,14 +373,15 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
     if( !bitmap )
     {
         msg_Err( p_filter, "could not create bitmap" );
+        free( psz_string );
         return VLC_EGENERIC;
     }
 
     bitmap_bak = SelectObject( p_sys->hcdc, bitmap );
     FillRect( p_sys->hcdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
 
-    //TextOut( p_sys->hcdc, 0, 0, psz_string, strlen(psz_string) );
-    if( !DrawText( p_sys->hcdc, psz_string, -1, &rect, 0 ) )
+    if( !DrawText( p_sys->hcdc, psz_string, -1, &rect,
+                   DT_CENTER | DT_NOPREFIX ) )
     {
         msg_Err( p_filter, "could not draw text" );
     }
@@ -382,6 +392,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
 
     SelectObject( p_sys->hcdc, bitmap_bak );
     DeleteObject( bitmap );
+    free( psz_string );
     return VLC_SUCCESS;
 }