changeset 11580:90953d955165

Fontconfig support based on patch by Arwed von Merkatz <v.merkatz@gmx.net>, but slightly reworked
author alex
date Mon, 08 Dec 2003 12:14:32 +0000
parents 2f96ed23c71b
children 6ea42c885d60
files DOCS/man/de/mplayer.1 DOCS/man/en/mplayer.1 DOCS/xml/en/install.xml Makefile configure libvo/font_load_ft.c mencoder.c mplayer.c
diffstat 8 files changed, 130 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/de/mplayer.1	Mon Dec 08 12:03:03 2003 +0000
+++ b/DOCS/man/de/mplayer.1	Mon Dec 08 12:14:32 2003 +0000
@@ -919,6 +919,8 @@
 \-font ~/\:.mplayer/\:arial\-14/\:font.desc
 .br
 \-font ~/\:.mplayer/\:arialuni.ttf
+.br
+\-font 'Bitstream Vera Sans'
 .RE
 .PD 1
 .
--- a/DOCS/man/en/mplayer.1	Mon Dec 08 12:03:03 2003 +0000
+++ b/DOCS/man/en/mplayer.1	Mon Dec 08 12:14:32 2003 +0000
@@ -1164,6 +1164,8 @@
 With FreeType, this option determines path to the text font file.
 .br
 The \-subfont-* options are available only with FreeType support compiled in.
+.br
+With Fontconfig, this option determines the fontconfig font name.
 
 .I EXAMPLE:
 .PD 0
@@ -1171,6 +1173,8 @@
 \-font ~/\:.mplayer/\:arial-14/\:font.desc
 .br
 \-font ~/\:.mplayer/\:arialuni.ttf
+.br
+\-font 'Bitstream Vera Sans'
 .RE
 .PD 1
 .
--- a/DOCS/xml/en/install.xml	Mon Dec 08 12:03:03 2003 +0000
+++ b/DOCS/xml/en/install.xml	Mon Dec 08 12:14:32 2003 +0000
@@ -781,6 +781,27 @@
   RAW plugin too, see URL below)
   <!-- FIXME: where's that URL? -->
   </para></listitem>
+<listitem><para>
+  using a TrueType (TTF) font, by the means of the <systemitem class="library">
+  freetype</systemitem> library. Version 2.0.9 or greater is mandatory! Then
+  you have two methods:
+  <itemizedlist>
+    <listitem><para>
+      use the <option>-font /path/to/arial.ttf</option> option to specify a
+      TrueType font file on every occasion
+      </para></listitem>
+    <listitem><para>
+      create a symlink:<screen>ln -s /path/to/arial.ttf ~/.mplayer/subfont.ttf</screen>
+      </para></listitem>
+      </itemizedlist>
+  <para>
+    if compiled with <systemitem class="library">fontconfig</systemitem>
+    support, the above methods won't work, instead the <option>-font</option>
+    expects a fontconfig font name and defaults to the sans-serif font. To get
+    a list of fonts known to fontconfig, use <command>fc-list</command>.
+    Example: <option>-font 'Bitstream Vera Sans'</option>
+    </para>
+  </para></listitem>
 </itemizedlist>
 
 <para>
--- a/Makefile	Mon Dec 08 12:03:03 2003 +0000
+++ b/Makefile	Mon Dec 08 12:14:32 2003 +0000
@@ -36,9 +36,9 @@
 VO_LIBS = $(AA_LIB) $(X_LIB) $(SDL_LIB) $(GGI_LIB) $(MP1E_LIB) $(MLIB_LIB) $(SVGA_LIB) $(DIRECTFB_LIB) 
 AO_LIBS = $(ARTS_LIB) $(ESD_LIB) $(NAS_LIB) $(SGIAUDIO_LIB)
 CODEC_LIBS = $(AV_LIB) $(FAME_LIB) $(MAD_LIB) $(VORBIS_LIB) $(THEORA_LIB) $(FAAD_LIB) $(LIBLZO_LIB) $(DECORE_LIB) $(XVID_LIB) $(PNG_LIB) $(Z_LIB) $(JPEG_LIB) $(ALSA_LIB) $(XMMS_LIB) $(MATROSKA_LIB) 
-COMMON_LIBS = libmpcodecs/libmpcodecs.a mp3lib/libMP3.a liba52/liba52.a libmpeg2/libmpeg2.a $(W32_LIB) $(DS_LIB) libaf/libaf.a libmpdemux/libmpdemux.a input/libinput.a postproc/libswscale.a osdep/libosdep.a $(CSS_LIB) $(CODEC_LIBS) $(FREETYPE_LIB) $(TERMCAP_LIB) $(CDPARANOIA_LIB) $(MPLAYER_NETWORK_LIB) $(WIN32_LIB) $(GIF_LIB) $(MACOSX_FRAMEWORKS) $(SMBSUPPORT_LIB) $(FRIBIDI_LIB) $(FLAC_LIB)
+COMMON_LIBS = libmpcodecs/libmpcodecs.a mp3lib/libMP3.a liba52/liba52.a libmpeg2/libmpeg2.a $(W32_LIB) $(DS_LIB) libaf/libaf.a libmpdemux/libmpdemux.a input/libinput.a postproc/libswscale.a osdep/libosdep.a $(CSS_LIB) $(CODEC_LIBS) $(FREETYPE_LIB) $(TERMCAP_LIB) $(CDPARANOIA_LIB) $(MPLAYER_NETWORK_LIB) $(WIN32_LIB) $(GIF_LIB) $(MACOSX_FRAMEWORKS) $(SMBSUPPORT_LIB) $(FRIBIDI_LIB) $(FLAC_LIB) $(FONTCONFIG_LIB)
 
-CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(X11_INC) $(FRIBIDI_INC) $(DVB_INC) $(XVID_INC) # -Wall
+CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(X11_INC) $(FRIBIDI_INC) $(DVB_INC) $(XVID_INC) $(FONTCONFIG_INC) # -Wall
 
 PARTS = libmpdemux libmpcodecs mp3lib liba52 libmpeg2 libavcodec libao2 drivers osdep postproc input libvo libaf
 ifeq ($(INTERNAL_FAAD),yes)
--- a/configure	Mon Dec 08 12:03:03 2003 +0000
+++ b/configure	Mon Dec 08 12:14:32 2003 +0000
@@ -175,6 +175,7 @@
   --disable-css          Disable old-style libcss DVD support [autodetect]
   --disable-cdparanoia   Disable cdparanoia support [autodetect]
   --disable-freetype     Disable freetype2 font rendering support [autodetect]
+  --disable-fontconfig   Disable fontconfig font lookup support [autodetect]
   --disable-unrarlib     Disable Unique RAR File Library [enabled]
   --enable-menu          Enable OSD menu support (NOT DVD MENU) [disabled]
   --disable-sortsub      Disable subtitles sorting [enabled]
@@ -1185,6 +1186,7 @@
 _cdparanoia=auto
 _big_endian=auto
 _freetype=auto
+_fontconfig=auto
 _shared_pp=no
 _menu=no
 _qtx=auto
@@ -1400,6 +1402,8 @@
   --disable-big-endian) _big_endian=no  ;;
   --enable-freetype)    _freetype=yes   ;;
   --disable-freetype)   _freetype=no    ;;
+  --enable-fontconfig)  _fontconfig=yes ;;
+  --disable-fontconfig) _fontconfig=no  ;;
   --enable-unrarlib)	_unrarlib=yes	;;
   --disable-unrarlib)	_unrarlib=no	;;
   --enable-ftp)         _ftp=yes        ;;
@@ -4274,6 +4278,40 @@
 fi
 echores "$_freetype"
 
+if test "$_freetype" = no ; then
+    _fontconfig=no
+fi
+echocheck "fontconfig"
+if test "$_fontconfig" = auto ; then
+    if ( pkg-config fontconfig --modversion) > /dev/null 2>&1 ; then
+        cat > $TMPC << EOF
+#include <stdio.h>
+#include <fontconfig/fontconfig.h>
+int main()
+{
+    int err = FcInit();
+    if(err == FcFalse){
+        printf("Couldn't initialize fontconfig lib\n");
+        exit(err);
+    }
+    return 0;
+    
+}
+EOF
+        _fontconfig=no
+        cc_check `pkg-config fontconfig --cflags --libs` && ( $TMPO >> "$TMPLOG" ) && _fontconfig=yes
+    else
+        _fontconfig=no
+    fi
+fi
+if test "$_fontconfig" = yes ; then
+    _def_fontconfig='#define HAVE_FONTCONFIG'
+    _inc_fontconfig=`pkg-config fontconfig --cflags`
+    _ld_fontconfig=`pkg-config fontconfig --libs`
+else
+    _def_fontconfig='#undef HAVE_FONTCONFIG'
+fi
+echores "$_fontconfig"
 
 echocheck "fribidi with charsets"
 if test "$_fribidi" = yes ; then
@@ -5887,6 +5925,8 @@
 CDPARANOIA_LIB = $_ld_cdparanoia
 FREETYPE_INC = $_inc_freetype
 FREETYPE_LIB = $_ld_freetype
+FONTCONFIG_INC = $_inc_fontconfig
+FONTCONFIG_LIB = $_ld_fontconfig
 FRIBIDI_INC = $_inc_fribidi
 FRIBIDI_LIB = $_ld_fribidi
 LIBLZO_LIB= $_ld_liblzo
@@ -6341,6 +6381,9 @@
 /* enable FreeType support */
 $_def_freetype
 
+/* enable Fontconfig support */
+$_def_fontconfig
+
 /* enable FriBiDi usage */
 $_def_fribidi
 
--- a/libvo/font_load_ft.c	Mon Dec 08 12:03:03 2003 +0000
+++ b/libvo/font_load_ft.c	Mon Dec 08 12:14:32 2003 +0000
@@ -24,6 +24,10 @@
 #include FT_FREETYPE_H
 #include FT_GLYPH_H
 
+#ifdef HAVE_FONTCONFIG
+#include <fontconfig/fontconfig.h>
+#endif
+
 #include "../bswap.h"
 #include "font_load.h"
 #include "mp_msg.h"
@@ -1113,6 +1117,11 @@
 
 void load_font_ft(int width, int height) 
 {
+#ifdef HAVE_FONTCONFIG
+    FcPattern *fc_pattern;
+    FcChar8 *s;
+    FcBool scalable;
+#endif
     vo_image_width = width;
     vo_image_height = height;
 
@@ -1122,6 +1131,30 @@
     if (vo_font) free_font_desc(vo_font);
 
 #ifdef USE_OSD
+#ifdef HAVE_FONTCONFIG
+    if (font_fontconfig)
+    {
+	if (!font_name)
+	    font_name = "sans-serif";
+	FcInit();
+	fc_pattern = FcNameParse(font_name);
+	FcConfigSubstitute(0, fc_pattern, FcMatchPattern);
+	FcDefaultSubstitute(fc_pattern);
+	fc_pattern = FcFontMatch(0, fc_pattern, 0);
+	FcPatternGetBool(fc_pattern, FC_SCALABLE, 0, &scalable);
+	if (scalable != FcTrue) {
+    	    fc_pattern = FcNameParse("sans-serif");
+    	    FcConfigSubstitute(0, fc_pattern, FcMatchPattern);
+    	    FcDefaultSubstitute(fc_pattern);
+    	    fc_pattern = FcFontMatch(0, fc_pattern, 0);
+	}
+	// s doesn't need to be freed according to fontconfig docs
+	FcPatternGetString(fc_pattern, FC_FILE, 0, &s);
+	vo_font=read_font_desc_ft(s, width, height);
+	free(fc_pattern);
+    }
+    else
+#endif
     vo_font=read_font_desc_ft(font_name, width, height);
 #endif
 }
--- a/mencoder.c	Mon Dec 08 12:03:03 2003 +0000
+++ b/mencoder.c	Mon Dec 08 12:14:32 2003 +0000
@@ -175,6 +175,9 @@
 
 // sub:
 char *font_name=NULL;
+#ifdef HAVE_FONTCONFIG
+int font_fontconfig=0;
+#endif
 float font_factor=0.75;
 char **sub_name=NULL;
 float sub_delay=0;
@@ -443,7 +446,11 @@
 #ifdef USE_OSD
 #ifdef HAVE_FREETYPE
   init_freetype();
-#else
+#endif
+#ifdef HAVE_FONTCONFIG
+  if(!font_fontconfig)
+  {
+#endif
   if(font_name){
        vo_font=read_font_desc(font_name,font_factor,verbose>1);
        if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
@@ -453,6 +460,8 @@
        if(!vo_font)
        vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
   }
+#ifdef HAVE_FONTCONFIG
+  }
 #endif
 #endif
 
--- a/mplayer.c	Mon Dec 08 12:03:03 2003 +0000
+++ b/mplayer.c	Mon Dec 08 12:14:32 2003 +0000
@@ -288,6 +288,9 @@
 
 // sub:
 char *font_name=NULL;
+#ifdef HAVE_FONTCONFIG
+int font_fontconfig=0;
+#endif
 float font_factor=0.75;
 char **sub_name=NULL;
 float sub_delay=0;
@@ -1058,8 +1061,15 @@
 
 //------ load global data first ------
 
+// check font
 #ifdef USE_OSD
-// check font
+#ifdef HAVE_FREETYPE
+  init_freetype();
+#endif
+#ifdef HAVE_FONTCONFIG
+  if(!font_fontconfig)
+  {
+#endif
   if(font_name){
        vo_font=read_font_desc(font_name,font_factor,verbose>1);
        if(!vo_font) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadFont,font_name);
@@ -1069,9 +1079,8 @@
        if(!vo_font)
        vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
   }
-#ifdef HAVE_FREETYPE
-  if (!vo_font)
-	init_freetype();
+#ifdef HAVE_FONTCONFIG
+  }
 #endif
 #endif
   vo_init_osd();
@@ -1373,7 +1382,9 @@
 #endif
 
 // CACHE2: initial prefill: 20%  later: 5%  (should be set by -cacheopts)
+#ifdef HAS_DVBIN_SUPPORT
 goto_enable_cache:
+#endif
 if(stream_cache_size>0){
   current_module="enable_cache";
   if(!stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024/5,stream_cache_size*1024/20))