From c8b0ddfe4e1570b83b815a3c9befced24e4d2875 Mon Sep 17 00:00:00 2001 From: arpi Date: Sun, 29 Dec 2002 14:59:23 +0000 Subject: [PATCH] these patches let ,,oldstyle'' and freetype subtitle renderers live together happily. if an oldstyle subtitle (font.desc) is found, it will be used. otherwise mplayer will choose subfont.ttf, if freetype was detected during ./configure. (also you can use -font /path/to/font.desc and -font /path/to/foobar.ttf too) patch-set by Wojtek Kaniewski git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8636 b3059339-0415-0410-9bf9-f77b7e298cf2 --- DOCS/documentation.html | 3 +-- Gui/interface.c | 2 +- libmenu/vf_menu.c | 2 +- libvo/font_load.c | 19 ++++++++++++++++--- libvo/font_load.h | 16 ++++++++-------- libvo/font_load_ft.c | 12 +++++++++--- libvo/sub.c | 4 ++-- mplayer.c | 6 +++--- 8 files changed, 41 insertions(+), 23 deletions(-) diff --git a/DOCS/documentation.html b/DOCS/documentation.html index 74fce4539d..60af81f301 100644 --- a/DOCS/documentation.html +++ b/DOCS/documentation.html @@ -960,8 +960,7 @@
  • use the font generator GIMP plugin at TOOLS/subfont-GIMP (note: you must have HSI RAW plugin too, see URL below)
  • using a TrueType (TTF) font, by the means of the freetype - library. Version 2.0.9 or greater is mandatory! You have to pass the - --enable-freetype option to ./configure. Then you + library. Version 2.0.9 or greater is mandatory! Then you have two methods:
    • use the -font /path/to/arial.ttf option to specify diff --git a/Gui/interface.c b/Gui/interface.c index f4c93a1d34..9c62c28388 100644 --- a/Gui/interface.c +++ b/Gui/interface.c @@ -305,7 +305,7 @@ extern char ** vo_plugin_args; void guiLoadFont( void ) { #ifdef HAVE_FREETYPE - load_font(vo_image_width, vo_image_height); + load_font_ft(vo_image_width, vo_image_height); #else if ( vo_font ) { diff --git a/libmenu/vf_menu.c b/libmenu/vf_menu.c index a69ba0c397..deba7b9043 100644 --- a/libmenu/vf_menu.c +++ b/libmenu/vf_menu.c @@ -244,7 +244,7 @@ static int config(struct vf_instance_s* vf, int width, int height, int d_width, // here is the right place to get screen dimensions if (force_load_font) { force_load_font = 0; - load_font(width,height); + load_font_ft(width,height); } #endif return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); diff --git a/libvo/font_load.c b/libvo/font_load.c index 646817e0c1..82d8d6a81b 100644 --- a/libvo/font_load.c +++ b/libvo/font_load.c @@ -1,7 +1,5 @@ #include "config.h" -#ifndef HAVE_FREETYPE - #include #include #include @@ -56,6 +54,7 @@ int i,j; int chardb=0; int fontdb=-1; int version=0; +int first=1; desc=malloc(sizeof(font_desc_t));if(!desc) return NULL; memset(desc,0,sizeof(font_desc_t)); @@ -92,6 +91,21 @@ while(fgets(sor,1020,f)){ int ec=' '; int id=0; sor[1020]=0; + + /* skip files that look like: TTF (0x00, 0x01), PFM (0x00, 0x01), PFB + * (0x80, 0x01), PCF (0x01, 0x66), fon ("MZ"), gzipped (0x1f, 0x8b) */ + + if (first) { + if (!sor[0] || sor[1] == 1 || (sor[0] == 'M' && sor[1] == 'Z') || (sor[0] == 0x1f && sor[1] == 0x8b) || (sor[0] == 1 && sor[1] == 0x66)) { + printf("%s doesn't look like a font description, ignoring\n", fname); + fclose(f); + free(desc); + free(dn); + return NULL; + } + first = 0; + } + p[0]=d;++pdb; while(1){ int c=*s++; @@ -303,4 +317,3 @@ read_font_desc("high_arpi.desc",1); } #endif -#endif /* HAVE_FREETYPE */ diff --git a/libvo/font_load.h b/libvo/font_load.h index e4d4e83d2c..98517be1da 100644 --- a/libvo/font_load.h +++ b/libvo/font_load.h @@ -31,6 +31,7 @@ typedef struct { short font[65536]; int start[65536]; // short is not enough for unicode fonts short width[65536]; + int freetype; #ifdef HAVE_FREETYPE int face_cnt; @@ -78,23 +79,22 @@ extern int force_load_font; int init_freetype(); int done_freetype(); -font_desc_t* read_font_desc(char* fname,int movie_width, int movie_height); +font_desc_t* read_font_desc_ft(char* fname,int movie_width, int movie_height); void free_font_desc(font_desc_t *desc); void render_one_glyph(font_desc_t *desc, int c); int kerning(font_desc_t *desc, int prevc, int c); -void load_font(int width, int height); +void load_font_ft(int width, int height); #else +static void render_one_glyph(font_desc_t *desc, int c) {} +static int kerning(font_desc_t *desc, int prevc, int c) { return 0; } + +#endif + raw_file* load_raw(char *name,int verbose); font_desc_t* read_font_desc(char* fname,float factor,int verbose); -static void inline render_one_glyph(font_desc_t *desc, int c) {} -static int inline kerning(font_desc_t *desc, int prevc, int c) { return 0; } -static void inline load_font(int width, int height){} - -#endif - #endif /* ! __MPLAYER_FONT_LOAD_H */ diff --git a/libvo/font_load_ft.c b/libvo/font_load_ft.c index b829f6d00e..398e78b5a7 100644 --- a/libvo/font_load_ft.c +++ b/libvo/font_load_ft.c @@ -50,6 +50,8 @@ int vo_image_width = 0; int vo_image_height = 0; int force_load_font; +int using_freetype = 0; + //// constants static unsigned int const colors = 256; static unsigned int const maxcolor = 255; @@ -937,7 +939,7 @@ int kerning(font_desc_t *desc, int prevc, int c) return f266ToInt(kern.x); } -font_desc_t* read_font_desc(char *fname, int movie_width, int movie_height) +font_desc_t* read_font_desc_ft(char *fname, int movie_width, int movie_height) { font_desc_t *desc; @@ -1086,12 +1088,16 @@ int init_freetype() return -1; } fprintf(stderr, "init_freetype\n"); + using_freetype = 1; return 0; } int done_freetype() { int err; + + if (!using_freetype) + return 0; err = FT_Done_FreeType(library); if (err) { @@ -1102,7 +1108,7 @@ int done_freetype() return 0; } -void load_font(int width, int height) +void load_font_ft(int width, int height) { vo_image_width = width; vo_image_height = height; @@ -1113,7 +1119,7 @@ void load_font(int width, int height) if (vo_font) free_font_desc(vo_font); #ifdef USE_OSD - vo_font=read_font_desc(font_name, width, height); + vo_font=read_font_desc_ft(font_name, width, height); #endif } diff --git a/libvo/sub.c b/libvo/sub.c index fe9385ba93..6bfb0d7d5c 100644 --- a/libvo/sub.c +++ b/libvo/sub.c @@ -526,9 +526,9 @@ int vo_update_osd(int dxs,int dys){ #ifdef HAVE_FREETYPE // here is the right place to get screen dimensions - if (force_load_font) { + if (!vo_font && force_load_font) { force_load_font = 0; - load_font(dxs, dys); + load_font_ft(dxs, dys); } #endif diff --git a/mplayer.c b/mplayer.c index e97f0fbada..56333b181b 100644 --- a/mplayer.c +++ b/mplayer.c @@ -894,7 +894,6 @@ if(!parse_codec_cfg(get_path("codecs.conf"))){ //------ load global data first ------ #ifdef USE_OSD -#ifndef HAVE_FREETYPE // check font if(font_name){ vo_font=read_font_desc(font_name,font_factor,verbose>1); @@ -905,8 +904,9 @@ if(!parse_codec_cfg(get_path("codecs.conf"))){ if(!vo_font) vo_font=read_font_desc(DATADIR"/font/font.desc",font_factor,verbose>1); } -#else - init_freetype(); +#ifdef HAVE_FREETYPE + if (!vo_font) + init_freetype(); #endif #endif vo_init_osd();