1 /*****************************************************************************
2 * freetype.c : Put text on the video, using freetype2
3 *****************************************************************************
4 * Copyright (C) 2002 - 2005 VideoLAN
7 * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
8 * Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
31 #ifdef HAVE_LINUX_LIMITS_H
32 # include <linux/limits.h>
38 #include "vlc_block.h"
39 #include "vlc_filter.h"
48 #include FT_FREETYPE_H
52 #define DEFAULT_FONT "/System/Library/Fonts/LucidaGrande.dfont"
53 #elif defined( SYS_BEOS )
54 #define DEFAULT_FONT "/boot/beos/etc/fonts/ttfonts/Swiss721.ttf"
55 #elif defined( WIN32 )
56 #define DEFAULT_FONT "" /* Default font found at run-time */
58 #define DEFAULT_FONT "/usr/share/fonts/truetype/freefont/FreeSerifBold.ttf"
61 #if defined(HAVE_FRIBIDI)
62 #include <fribidi/fribidi.h>
65 typedef struct line_desc_t line_desc_t;
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Create ( vlc_object_t * );
71 static void Destroy( vlc_object_t * );
73 /* The RenderText call maps to pf_render_string, defined in vlc_filter.h */
74 static int RenderText( filter_t *, subpicture_region_t *,
75 subpicture_region_t * );
76 static line_desc_t *NewLine( byte_t * );
78 /*****************************************************************************
80 *****************************************************************************/
81 #define FONT_TEXT N_("Font")
82 #define FONT_LONGTEXT N_("Font filename")
83 #define FONTSIZE_TEXT N_("Font size in pixels")
84 #define FONTSIZE_LONGTEXT N_("The size of the fonts used by the osd module. " \
85 "If set to something different than 0 this option will override the " \
86 "relative font size " )
87 #define OPACITY_TEXT N_("Opacity, 0..255")
88 #define OPACITY_LONGTEXT N_("The opacity (inverse of transparency) of " \
89 "overlay text. 0 = transparent, 255 = totally opaque. " )
90 #define COLOR_TEXT N_("Text Default Color")
91 #define COLOR_LONGTEXT N_("The color of overlay text. 1 byte for each color, "\
92 "hexadecimal. #000000 = all colors off, 0xFF0000 = just Red, " \
93 "0xFFFFFF = all color on [White]" )
94 #define FONTSIZER_TEXT N_("Font size")
95 #define FONTSIZER_LONGTEXT N_("The size of the fonts used by the osd module" )
97 static int pi_sizes[] = { 20, 18, 16, 12, 6 };
98 static char *ppsz_sizes_text[] = { N_("Smaller"), N_("Small"), N_("Normal"),
99 N_("Large"), N_("Larger") };
100 static int pi_color_values[] = {
101 0x00000000, 0x00808080, 0x00C0C0C0, 0x00FFFFFF, 0x00800000,
102 0x00FF0000, 0x00FF00FF, 0x00FFFF00, 0x00808000, 0x00008000, 0x00008080,
103 0x0000FF00, 0x00800080, 0x00000080, 0x000000FF, 0x0000FFFF };
105 static char *ppsz_color_descriptions[] = {
106 N_("Black"), N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"),
107 N_("Red"), N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"), N_("Teal"),
108 N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"), N_("Aqua") };
111 set_shortname( _("Freetype"));
112 set_description( _("Freetype2 font renderer") );
113 set_category( CAT_VIDEO );
114 set_subcategory( SUBCAT_VIDEO_TEXT );
116 add_file( "freetype-font", DEFAULT_FONT, NULL, FONT_TEXT, FONT_LONGTEXT,
119 add_integer( "freetype-fontsize", 0, NULL, FONTSIZE_TEXT,
120 FONTSIZE_LONGTEXT, VLC_TRUE );
122 /* opacity valid on 0..255, with default 255 = fully opaque */
123 add_integer_with_range( "freetype-opacity", 255, 0, 255, NULL,
124 OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );
126 /* hook to the color values list, with default 0x00ffffff = white */
127 add_integer( "freetype-color", 0x00FFFFFF, NULL, COLOR_TEXT,
128 COLOR_LONGTEXT, VLC_TRUE );
129 change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
131 add_integer( "freetype-rel-fontsize", 16, NULL, FONTSIZER_TEXT,
132 FONTSIZER_LONGTEXT, VLC_FALSE );
133 change_integer_list( pi_sizes, ppsz_sizes_text, 0 );
135 set_capability( "text renderer", 100 );
136 add_shortcut( "text" );
137 set_callbacks( Create, Destroy );
142 /** NULL-terminated list of glyphs making the string */
143 FT_BitmapGlyph *pp_glyphs;
144 /** list of relative positions for the glyphs */
145 FT_Vector *p_glyph_pos;
149 int i_red, i_green, i_blue;
155 static int Render( filter_t *, subpicture_region_t *, line_desc_t *, int, int);
156 static void FreeLines( line_desc_t * );
157 static void FreeLine( line_desc_t * );
159 /*****************************************************************************
160 * filter_sys_t: freetype local data
161 *****************************************************************************
162 * This structure is part of the video output thread descriptor.
163 * It describes the freetype specific properties of an output thread.
164 *****************************************************************************/
167 FT_Library p_library; /* handle to library */
168 FT_Face p_face; /* handle to face object */
169 vlc_bool_t i_use_kerning;
170 uint8_t i_font_opacity;
175 /*****************************************************************************
176 * Create: allocates osd-text video thread output method
177 *****************************************************************************
178 * This function allocates and initializes a Clone vout method.
179 *****************************************************************************/
180 static int Create( vlc_object_t *p_this )
182 filter_t *p_filter = (filter_t *)p_this;
184 char *psz_fontfile = NULL;
188 /* Allocate structure */
189 p_sys = malloc( sizeof( filter_sys_t ) );
192 msg_Err( p_filter, "out of memory" );
196 p_sys->p_library = 0;
197 p_sys->i_font_size = 0;
199 var_Create( p_filter, "freetype-font",
200 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
201 var_Create( p_filter, "freetype-fontsize",
202 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
203 var_Create( p_filter, "freetype-rel-fontsize",
204 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
205 var_Create( p_filter, "freetype-opacity",
206 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
207 var_Get( p_filter, "freetype-opacity", &val );
208 p_sys->i_font_opacity = __MAX( __MIN( val.i_int, 255 ), 0 );
209 var_Create( p_filter, "freetype-color",
210 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
211 var_Get( p_filter, "freetype-color", &val );
212 p_sys->i_font_color = __MIN( val.i_int, 0xFFFFFF );
214 /* Look what method was requested */
215 var_Get( p_filter, "freetype-font", &val );
216 psz_fontfile = val.psz_string;
217 if( !psz_fontfile || !*psz_fontfile )
219 if( psz_fontfile ) free( psz_fontfile );
220 psz_fontfile = (char *)malloc( PATH_MAX + 1 );
222 GetWindowsDirectory( psz_fontfile, PATH_MAX + 1 );
223 strcat( psz_fontfile, "\\fonts\\arial.ttf" );
225 strcpy( psz_fontfile, DEFAULT_FONT );
227 msg_Err( p_filter, "user didn't specify a font" );
232 i_error = FT_Init_FreeType( &p_sys->p_library );
235 msg_Err( p_filter, "couldn't initialize freetype" );
239 i_error = FT_New_Face( p_sys->p_library, psz_fontfile ? psz_fontfile : "",
241 if( i_error == FT_Err_Unknown_File_Format )
243 msg_Err( p_filter, "file %s have unknown format", psz_fontfile );
248 msg_Err( p_filter, "failed to load font file %s", psz_fontfile );
252 i_error = FT_Select_Charmap( p_sys->p_face, ft_encoding_unicode );
255 msg_Err( p_filter, "Font has no unicode translation table" );
259 p_sys->i_use_kerning = FT_HAS_KERNING( p_sys->p_face );
262 var_Get( p_filter, "freetype-fontsize", &val );
265 p_sys->i_font_size = val.i_int;
269 var_Get( p_filter, "freetype-rel-fontsize", &val );
270 p_sys->i_font_size = (int)p_filter->fmt_out.video.i_height / val.i_int;
272 if( p_sys->i_font_size <= 0 )
274 msg_Warn( p_filter, "Invalid fontsize, using 12" );
275 p_sys->i_font_size = 12;
277 msg_Dbg( p_filter, "Using fontsize: %i", p_sys->i_font_size );
279 i_error = FT_Set_Pixel_Sizes( p_sys->p_face, 0, p_sys->i_font_size );
282 msg_Err( p_filter, "couldn't set font size to %d", p_sys->i_font_size );
286 if( psz_fontfile ) free( psz_fontfile );
287 p_filter->pf_render_text = RenderText;
288 p_filter->p_sys = p_sys;
292 if( p_sys->p_face ) FT_Done_Face( p_sys->p_face );
293 if( p_sys->p_library ) FT_Done_FreeType( p_sys->p_library );
294 if( psz_fontfile ) free( psz_fontfile );
299 /*****************************************************************************
300 * Destroy: destroy Clone video thread output method
301 *****************************************************************************
302 * Clean up all data and library connections
303 *****************************************************************************/
304 static void Destroy( vlc_object_t *p_this )
306 filter_t *p_filter = (filter_t *)p_this;
307 filter_sys_t *p_sys = p_filter->p_sys;
309 FT_Done_Face( p_sys->p_face );
310 FT_Done_FreeType( p_sys->p_library );
314 /*****************************************************************************
315 * Render: place string in picture
316 *****************************************************************************
317 * This function merges the previously rendered freetype glyphs into a picture
318 *****************************************************************************/
319 static int Render( filter_t *p_filter, subpicture_region_t *p_region,
320 line_desc_t *p_line, int i_width, int i_height )
324 int i, x, y, i_pitch;
325 uint8_t i_y; /* YUV values, derived from incoming RGB */
327 subpicture_region_t *p_region_tmp;
329 /* Create a new subpicture region */
330 memset( &fmt, 0, sizeof(video_format_t) );
331 fmt.i_chroma = VLC_FOURCC('Y','U','V','P');
332 fmt.i_aspect = VOUT_ASPECT_FACTOR;
333 fmt.i_width = fmt.i_visible_width = i_width + 2;
334 fmt.i_height = fmt.i_visible_height = i_height + 2;
335 fmt.i_x_offset = fmt.i_y_offset = 0;
336 p_region_tmp = spu_CreateRegion( p_filter, &fmt );
339 msg_Err( p_filter, "cannot allocate SPU region" );
343 p_region->fmt = p_region_tmp->fmt;
344 p_region->picture = p_region_tmp->picture;
345 free( p_region_tmp );
347 /* Calculate text color components */
348 i_y = (uint8_t)(( 66 * p_line->i_red + 129 * p_line->i_green +
349 25 * p_line->i_blue + 128) >> 8) + 16;
350 i_u = (int8_t)(( -38 * p_line->i_red - 74 * p_line->i_green +
351 112 * p_line->i_blue + 128) >> 8) + 128;
352 i_v = (int8_t)(( 112 * p_line->i_red - 94 * p_line->i_green -
353 18 * p_line->i_blue + 128) >> 8) + 128;
356 fmt.p_palette->i_entries = 256;
357 for( i = 0; i < fmt.p_palette->i_entries; i++ )
359 fmt.p_palette->palette[i][0] = i * i_y / 256;
360 fmt.p_palette->palette[i][1] = i_u;
361 fmt.p_palette->palette[i][2] = i_v;
362 fmt.p_palette->palette[i][3] =
363 i + (256 - i) * (256 / (255 - p_line->i_alpha)) / 16;
365 fmt.p_palette->palette[0][3] = 0;
367 p_dst = p_region->picture.Y_PIXELS;
368 i_pitch = p_region->picture.Y_PITCH;
370 /* Initialize the region pixels */
371 memset( p_dst, 0, i_pitch * p_region->fmt.i_height );
373 for( ; p_line != NULL; p_line = p_line->p_next )
375 int i_glyph_tmax = 0;
376 int i_bitmap_offset, i_offset;
377 for( i = 0; p_line->pp_glyphs[i] != NULL; i++ )
379 FT_BitmapGlyph p_glyph = p_line->pp_glyphs[ i ];
380 i_glyph_tmax = __MAX( i_glyph_tmax, p_glyph->top );
383 for( i = 0; p_line->pp_glyphs[i] != NULL; i++ )
385 FT_BitmapGlyph p_glyph = p_line->pp_glyphs[ i ];
387 i_offset = ( p_line->p_glyph_pos[ i ].y +
388 i_glyph_tmax - p_glyph->top + 1 ) *
389 i_pitch + p_line->p_glyph_pos[ i ].x + p_glyph->left + 1;
391 for( y = 0, i_bitmap_offset = 0; y < p_glyph->bitmap.rows; y++ )
393 for( x = 0; x < p_glyph->bitmap.width; x++, i_bitmap_offset++ )
395 if( !p_glyph->bitmap.buffer[i_bitmap_offset] )
399 p_dst[i_offset + x] = ((uint16_t)p_dst[i_offset + x]*2 +
400 p_glyph->bitmap.buffer[i_bitmap_offset])/3;
401 i_offset += i_pitch; x--;
402 p_dst[i_offset + x] = ((uint16_t)p_dst[i_offset + x]*2 +
403 p_glyph->bitmap.buffer[i_bitmap_offset])/3;
405 p_dst[i_offset + x] = ((uint16_t)p_dst[i_offset + x]*2 +
406 p_glyph->bitmap.buffer[i_bitmap_offset])/3;
407 i_offset += i_pitch; x--;
408 p_dst[i_offset + x] = ((uint16_t)p_dst[i_offset + x]*2 +
409 p_glyph->bitmap.buffer[i_bitmap_offset])/3;
415 i_offset = ( p_line->p_glyph_pos[ i ].y +
416 i_glyph_tmax - p_glyph->top + 1 ) *
417 i_pitch + p_line->p_glyph_pos[ i ].x + p_glyph->left + 1;
419 for( y = 0, i_bitmap_offset = 0; y < p_glyph->bitmap.rows; y++ )
421 for( x = 0; x < p_glyph->bitmap.width; x++, i_bitmap_offset++ )
423 if( p_glyph->bitmap.buffer[i_bitmap_offset] > 16 )
424 p_dst[i_offset+x] = p_glyph->bitmap.buffer[i_bitmap_offset];
435 * This function renders a text subpicture region into another one.
436 * It also calculates the size needed for this string, and renders the
437 * needed glyphs into memory. It is used as pf_add_string callback in
438 * the vout method by this module
440 static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
441 subpicture_region_t *p_region_in )
443 filter_sys_t *p_sys = p_filter->p_sys;
444 line_desc_t *p_lines = 0, *p_line = 0, *p_next = 0, *p_prev = 0;
445 int i, i_pen_y, i_pen_x, i_error, i_glyph_index, i_previous;
446 uint32_t *psz_unicode, *psz_unicode_orig = 0, i_char, *psz_line_start;
449 vlc_iconv_t iconv_handle = (vlc_iconv_t)(-1);
450 int i_font_color, i_font_alpha, i_font_size, i_red, i_green, i_blue;
458 if( !p_region_in || !p_region_out ) return VLC_EGENERIC;
459 psz_string = p_region_in->psz_text;
460 if( !psz_string || !*psz_string ) return VLC_EGENERIC;
462 i_font_color = 0xFFFFFF;//p_region_in->i_text_color;
463 if( i_font_color == 0xFFFFFF ) i_font_color = p_sys->i_font_color;
465 i_font_alpha = p_region_in->i_text_alpha;
466 if( !i_font_alpha ) i_font_alpha = 255 - p_sys->i_font_opacity;
468 i_font_size = p_region_in->i_text_size;
469 if( !i_font_size ) i_font_size = p_sys->i_font_size;
471 i_red = ( i_font_color & 0x00FF0000 ) >> 16;
472 i_green = ( i_font_color & 0x0000FF00 ) >> 8;
473 i_blue = i_font_color & 0x000000FF;
475 result.x = result.y = 0;
476 line.xMin = line.xMax = line.yMin = line.yMax = 0;
478 psz_unicode = psz_unicode_orig =
479 malloc( ( strlen(psz_string) + 1 ) * sizeof(uint32_t) );
480 if( psz_unicode == NULL )
482 msg_Err( p_filter, "out of memory" );
485 #if defined(WORDS_BIGENDIAN)
486 iconv_handle = vlc_iconv_open( "UCS-4BE", "UTF-8" );
488 iconv_handle = vlc_iconv_open( "UCS-4LE", "UTF-8" );
490 if( iconv_handle == (vlc_iconv_t)-1 )
492 msg_Warn( p_filter, "unable to do conversion" );
496 /* Set up the glyphs for the desired font size. By definition,
497 p_sys->i_font_size is a valid value, else the initial Create would
498 have failed. Using -1 as a flag to use the freetype-fontsize */
499 if ( i_font_size < 0 )
501 FT_Set_Pixel_Sizes( p_sys->p_face, 0, p_sys->i_font_size );
505 i_error = FT_Set_Pixel_Sizes( p_sys->p_face, 0, i_font_size );
508 msg_Warn( p_filter, "Invalid font size to RenderText, using %d",
509 p_sys->i_font_size );
510 FT_Set_Pixel_Sizes( p_sys->p_face, 0, p_sys->i_font_size );
515 char *p_in_buffer, *p_out_buffer;
516 size_t i_in_bytes, i_out_bytes, i_out_bytes_left, i_ret;
517 i_in_bytes = strlen( psz_string );
518 i_out_bytes = i_in_bytes * sizeof( uint32_t );
519 i_out_bytes_left = i_out_bytes;
520 p_in_buffer = psz_string;
521 p_out_buffer = (char *)psz_unicode;
522 i_ret = vlc_iconv( iconv_handle, &p_in_buffer, &i_in_bytes,
523 &p_out_buffer, &i_out_bytes_left );
525 vlc_iconv_close( iconv_handle );
529 msg_Warn( p_filter, "failed to convert string to unicode (%s), "
530 "bytes left %d", strerror(errno), i_in_bytes );
533 *(uint32_t*)p_out_buffer = 0;
534 i_string_length = (i_out_bytes - i_out_bytes_left) / sizeof(uint32_t);
537 #if defined(HAVE_FRIBIDI)
539 uint32_t *p_fribidi_string;
540 FriBidiCharType base_dir = FRIBIDI_TYPE_ON;
541 p_fribidi_string = malloc( (i_string_length + 1) * sizeof(uint32_t) );
542 fribidi_log2vis( (FriBidiChar*)psz_unicode, i_string_length,
543 &base_dir, (FriBidiChar*)p_fribidi_string, 0, 0, 0 );
544 free( psz_unicode_orig );
545 psz_unicode = psz_unicode_orig = p_fribidi_string;
546 p_fribidi_string[ i_string_length ] = 0;
550 /* Calculate relative glyph positions and a bounding box for the
552 if( !(p_line = NewLine( psz_string )) )
554 msg_Err( p_filter, "out of memory" );
558 i_pen_x = i_pen_y = 0;
560 psz_line_start = psz_unicode;
562 #define face p_sys->p_face
563 #define glyph face->glyph
565 while( *psz_unicode )
567 i_char = *psz_unicode++;
568 if( i_char == '\r' ) /* ignore CR chars wherever they may be */
575 psz_line_start = psz_unicode;
576 if( !(p_next = NewLine( psz_string )) )
578 msg_Err( p_filter, "out of memory" );
581 p_line->p_next = p_next;
582 p_line->i_width = line.xMax;
583 p_line->i_height = face->size->metrics.height >> 6;
584 p_line->pp_glyphs[ i ] = NULL;
585 p_line->i_alpha = i_font_alpha;
586 p_line->i_red = i_red;
587 p_line->i_green = i_green;
588 p_line->i_blue = i_blue;
591 result.x = __MAX( result.x, line.xMax );
592 result.y += face->size->metrics.height >> 6;
595 line.xMin = line.xMax = line.yMin = line.yMax = 0;
596 i_pen_y += face->size->metrics.height >> 6;
598 msg_Dbg( p_filter, "Creating new line, i is %d", i );
603 i_glyph_index = FT_Get_Char_Index( face, i_char );
604 if( p_sys->i_use_kerning && i_glyph_index
608 FT_Get_Kerning( face, i_previous, i_glyph_index,
609 ft_kerning_default, &delta );
610 i_pen_x += delta.x >> 6;
613 p_line->p_glyph_pos[ i ].x = i_pen_x;
614 p_line->p_glyph_pos[ i ].y = i_pen_y;
615 i_error = FT_Load_Glyph( face, i_glyph_index, FT_LOAD_DEFAULT );
618 msg_Err( p_filter, "FT_Load_Glyph returned %d", i_error );
621 i_error = FT_Get_Glyph( glyph, &tmp_glyph );
624 msg_Err( p_filter, "FT_Get_Glyph returned %d", i_error );
627 FT_Glyph_Get_CBox( tmp_glyph, ft_glyph_bbox_pixels, &glyph_size );
628 i_error = FT_Glyph_To_Bitmap( &tmp_glyph, ft_render_mode_normal, 0, 1);
629 if( i_error ) continue;
630 p_line->pp_glyphs[ i ] = (FT_BitmapGlyph)tmp_glyph;
633 line.xMax = p_line->p_glyph_pos[i].x + glyph_size.xMax -
634 glyph_size.xMin + ((FT_BitmapGlyph)tmp_glyph)->left;
635 if( line.xMax > (int)p_filter->fmt_out.video.i_visible_width - 20 )
637 p_line->pp_glyphs[ i ] = NULL;
639 p_line = NewLine( psz_string );
640 if( p_prev ) p_prev->p_next = p_line;
641 else p_lines = p_line;
643 while( psz_unicode > psz_line_start && *psz_unicode != ' ' )
647 if( psz_unicode == psz_line_start )
649 msg_Warn( p_filter, "unbreakable string" );
656 psz_unicode = psz_line_start;
659 line.xMin = line.xMax = line.yMin = line.yMax = 0;
662 line.yMax = __MAX( line.yMax, glyph_size.yMax );
663 line.yMin = __MIN( line.yMin, glyph_size.yMin );
665 i_previous = i_glyph_index;
666 i_pen_x += glyph->advance.x >> 6;
670 p_line->i_width = line.xMax;
671 p_line->i_height = face->size->metrics.height >> 6;
672 p_line->pp_glyphs[ i ] = NULL;
673 p_line->i_alpha = i_font_alpha;
674 p_line->i_red = i_red;
675 p_line->i_green = i_green;
676 p_line->i_blue = i_blue;
677 result.x = __MAX( result.x, line.xMax );
678 result.y += line.yMax - line.yMin;
683 p_region_out->i_x = p_region_in->i_x;
684 p_region_out->i_y = p_region_in->i_y;
686 Render( p_filter, p_region_out, p_line, result.x, result.y );
688 if( psz_unicode_orig ) free( psz_unicode_orig );
689 FreeLines( p_lines );
693 if( psz_unicode_orig ) free( psz_unicode_orig );
694 FreeLines( p_lines );
698 static void FreeLine( line_desc_t *p_line )
701 for( i = 0; p_line->pp_glyphs[ i ] != NULL; i++ )
703 FT_Done_Glyph( (FT_Glyph)p_line->pp_glyphs[ i ] );
705 free( p_line->pp_glyphs );
706 free( p_line->p_glyph_pos );
710 static void FreeLines( line_desc_t *p_lines )
712 line_desc_t *p_line, *p_next;
714 if( !p_lines ) return;
716 for( p_line = p_lines; p_line != NULL; p_line = p_next )
718 p_next = p_line->p_next;
723 static line_desc_t *NewLine( byte_t *psz_string )
726 line_desc_t *p_line = malloc( sizeof(line_desc_t) );
728 if( !p_line ) return NULL;
729 p_line->i_height = 0;
731 p_line->p_next = NULL;
733 /* We don't use CountUtf8Characters() here because we are not acutally
734 * sure the string is utf8. Better be safe than sorry. */
735 i_count = strlen( psz_string );
737 p_line->pp_glyphs = malloc( sizeof(FT_BitmapGlyph) * ( i_count + 1 ) );
738 if( p_line->pp_glyphs == NULL )
743 p_line->pp_glyphs[0] = NULL;
745 p_line->p_glyph_pos = malloc( sizeof( FT_Vector ) * i_count + 1 );
746 if( p_line->p_glyph_pos == NULL )
748 free( p_line->pp_glyphs );