[MPlayer-dev-eng] [PATCH] fontconfig font lookup support

Arwed von Merkatz v.merkatz at gmx.net
Sat Nov 8 13:55:33 CET 2003


Hi,

trying again to get some feedback on my fontconfig support patch.
This patch enables mplayer/mencoder to use fontconfig to get a
truetype/type1 font for rendering the osd and subtitles. It defaults to
the 'sans-serif' font, and makes it possible to use -font <fontconfig
font name> to choose a different font. This makes it a lot easier to
switch the font, e.g. i use the Vera Sans font (which sans-serif maps to
on my system) most of the time, but i have some files with UTF-8
subtitles that include characters that aren't included in Vera, so i
just start those files with mplayer -font "Bitstream Cyberbit" and have
it use a font with a better unicode coverage.

-- 
Arwed v. Merkatz
Grimoire Guru for video
Grimoire Guru for xfce
Sourcemage GNU/Linux
http://www.sourcemage.org
-------------- next part --------------
Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/Makefile,v
retrieving revision 1.277
diff -u -r1.277 Makefile
--- Makefile	19 Oct 2003 20:20:45 -0000	1.277
+++ Makefile	8 Nov 2003 12:43:08 -0000
@@ -40,6 +40,8 @@
 
 CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(X11_INC) $(FRIBIDI_INC) $(DVB_INC) # -Wall
 
+COMMON_LIBS += $(FONTCONFIG_LIB)
+CFLAGS += $(FONTCONFIG_INC)
 PARTS = libmpdemux libmpcodecs mp3lib liba52 libmpeg2 libavcodec libao2 drivers osdep postproc input libvo libaf
 ifeq ($(INTERNAL_FAAD),yes)
 COMMON_LIBS += libfaad2/libfaad2.a 
Index: configure
===================================================================
RCS file: /cvsroot/mplayer/main/configure,v
retrieving revision 1.807
diff -u -r1.807 configure
--- configure	7 Nov 2003 22:14:51 -0000	1.807
+++ configure	8 Nov 2003 12:43:19 -0000
@@ -172,6 +172,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]
@@ -1180,6 +1181,7 @@
 _cdparanoia=auto
 _big_endian=auto
 _freetype=auto
+_fontconfig=auto
 _shared_pp=no
 _menu=no
 _qtx=auto
@@ -1395,6 +1397,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        ;;
@@ -4214,6 +4218,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
@@ -5814,6 +5852,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
@@ -6261,6 +6301,9 @@
 
 /* enable FreeType support */
 $_def_freetype
+
+/* enable Fontconfig support */
+$_def_fontconfig
 
 /* enable FriBiDi usage */
 $_def_fribidi
Index: mencoder.c
===================================================================
RCS file: /cvsroot/mplayer/main/mencoder.c,v
retrieving revision 1.221
diff -u -r1.221 mencoder.c
--- mencoder.c	7 Nov 2003 23:32:38 -0000	1.221
+++ mencoder.c	8 Nov 2003 12:43:23 -0000
@@ -440,6 +440,10 @@
 #ifdef USE_OSD
 #ifdef HAVE_FREETYPE
   init_freetype();
+#ifdef HAVE_FONTCONFIG
+  if(!font_name)
+    font_name = "sans-serif";
+#endif
 #else
   if(font_name){
        vo_font=read_font_desc(font_name,font_factor,verbose>1);
Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.736
diff -u -r1.736 mplayer.c
--- mplayer.c	1 Nov 2003 15:16:19 -0000	1.736
+++ mplayer.c	8 Nov 2003 12:43:31 -0000
@@ -1057,8 +1057,15 @@
 
 //------ load global data first ------
 
-#ifdef USE_OSD
 // check font
+#ifdef USE_OSD
+#ifdef HAVE_FREETYPE
+  init_freetype();
+#ifdef HAVE_FONTCONFIG
+  if(!font_name)
+    font_name = "sans-serif";
+#endif
+#else
   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);
@@ -1068,9 +1075,6 @@
        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();
 #endif
 #endif
   vo_init_osd();
Index: DOCS/man/de/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/man/de/mplayer.1,v
retrieving revision 1.33
diff -u -r1.33 mplayer.1
--- DOCS/man/de/mplayer.1	4 Nov 2003 21:51:39 -0000	1.33
+++ DOCS/man/de/mplayer.1	8 Nov 2003 12:43:39 -0000
@@ -912,6 +912,8 @@
 Die \-subfont-*-Optionen sind nur verf?gbar, wenn FreeType eincompieliert
 wurde. Wenn die FreeType-Unterst?tzung aktiviert wurde, dann kann die
 alte Schriftunterst?tzung nicht mehr benutzt werden.
+.br
+Bei Fontconfig gibt diese Option den fontconfig Namen der Schriftart an.
 
 .I BEISPIELE:
 .PD 0
@@ -919,6 +921,8 @@
 \-font ~/\:.mplayer/\:arial\-14/\:font.desc
 .br
 \-font ~/\:.mplayer/\:arialuni.ttf
+.br
+\-font 'Bitstream Vera Sans'
 .RE
 .PD 1
 .
Index: DOCS/man/en/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/man/en/mplayer.1,v
retrieving revision 1.483
diff -u -r1.483 mplayer.1
--- DOCS/man/en/mplayer.1	8 Nov 2003 00:09:15 -0000	1.483
+++ DOCS/man/en/mplayer.1	8 Nov 2003 12:43:47 -0000
@@ -1165,6 +1165,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
@@ -1172,6 +1174,8 @@
 \-font ~/\:.mplayer/\:arial-14/\:font.desc
 .br
 \-font ~/\:.mplayer/\:arialuni.ttf
+.br
+\-font 'Bitstream Vera Sans'
 .RE
 .PD 1
 .
Index: DOCS/xml/en/install.xml
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/xml/en/install.xml,v
retrieving revision 1.15
diff -u -r1.15 install.xml
--- DOCS/xml/en/install.xml	5 Nov 2003 15:59:07 -0000	1.15
+++ DOCS/xml/en/install.xml	8 Nov 2003 12:43:50 -0000
@@ -777,6 +777,22 @@
   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>
Index: libvo/font_load_ft.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/font_load_ft.c,v
retrieving revision 1.10
diff -u -r1.10 font_load_ft.c
--- libvo/font_load_ft.c	9 Jun 2003 12:15:47 -0000	1.10
+++ libvo/font_load_ft.c	8 Nov 2003 12:43:56 -0000
@@ -23,6 +23,10 @@
 #include <freetype/freetype.h>
 #include <freetype/ftglyph.h>
 
+#ifdef HAVE_FONTCONFIG
+#include <fontconfig/fontconfig.h>
+#endif
+
 #include "../bswap.h"
 #include "font_load.h"
 #include "mp_msg.h"
@@ -1112,6 +1116,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;
 
@@ -1120,8 +1129,28 @@
 
     if (vo_font) free_font_desc(vo_font);
 
+    
 #ifdef USE_OSD
+#ifdef HAVE_FONTCONFIG
+    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
     vo_font=read_font_desc_ft(font_name, width, height);
+#endif
 #endif
 }
 


More information about the MPlayer-dev-eng mailing list