[MPlayer-dev-eng] Fontconfig support for mplayer

Arwed von Merkatz v.merkatz at gmx.net
Sat Apr 19 13:04:19 CEST 2003


Here's the newest version of my fontconfig patch, i integrated the small
configure fix, so it doesn't use fontconfig if freetype support is
disabled. I also cleaned up the code a bit so variables get freed
correctly, and i added the documentation part to the xml documentation
(hope i got that one right).

-- 
Arwed v. Merkatz
Grimoire Guru for video
Sourcemage GNU/Linux
http://www.sourcemage.org
-------------- next part --------------
Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/Makefile,v
retrieving revision 1.262
diff -u -r1.262 Makefile
--- Makefile	29 Mar 2003 14:37:23 -0000	1.262
+++ Makefile	19 Apr 2003 11:22:09 -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) $(FAAD_LIB) $(LIBLZO_LIB) $(DECORE_LIB) $(XVID_LIB) $(PNG_LIB) $(Z_LIB) $(JPEG_LIB) $(ALSA_LIB) $(XMMS_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) $(STREAMING_LIB) $(WIN32_LIB) $(GIF_LIB) $(MACOSX_FRAMEWORKS) $(SMBSUPPORT_LIB) $(FRIBIDI_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) $(FONTCONFIG_LIB) $(TERMCAP_LIB) $(CDPARANOIA_LIB) $(STREAMING_LIB) $(WIN32_LIB) $(GIF_LIB) $(MACOSX_FRAMEWORKS) $(SMBSUPPORT_LIB) $(FRIBIDI_LIB)
 
-CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(FRIBIDI_INC) # -Wall
+CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(FONTCONFIG_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(FRIBIDI_INC) # -Wall
 
 ifeq ($(TARGET_ALTIVEC),yes)
 ifeq ($(TARGET_OS),Darwin)
Index: configure
===================================================================
RCS file: /cvsroot/mplayer/main/configure,v
retrieving revision 1.694
diff -u -r1.694 configure
--- configure	11 Apr 2003 16:33:29 -0000	1.694
+++ configure	19 Apr 2003 11:22:21 -0000
@@ -162,6 +162,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]
   --disable-new-conf     Disable new experimental config parser code [enabled]
   --enable-menu          Enable osd menu support (needs new config) [disabled]
@@ -1073,6 +1074,7 @@
 _cdparanoia=auto
 _big_endian=auto
 _freetype=auto
+_fontconfig=auto
 _shared_pp=no
 _new_conf=yes
 _menu=no
@@ -1267,6 +1269,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	;;
 
@@ -3870,6 +3874,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
@@ -5200,6 +5238,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
@@ -5603,6 +5643,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.213
diff -u -r1.213 mencoder.c
--- mencoder.c	7 Apr 2003 16:03:37 -0000	1.213
+++ mencoder.c	19 Apr 2003 11:22:25 -0000
@@ -435,6 +435,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.691
diff -u -r1.691 mplayer.c
--- mplayer.c	7 Apr 2003 20:55:32 -0000	1.691
+++ mplayer.c	19 Apr 2003 11:22:33 -0000
@@ -1018,8 +1018,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);
@@ -1029,9 +1036,6 @@
        if(!vo_font)
        vo_font=read_font_desc(DATADIR"/font/font.desc",font_factor,verbose>1);
   }
-#ifdef HAVE_FREETYPE
-  if (!vo_font)
-	init_freetype();
 #endif
 #endif
   vo_init_osd();
Index: DOCS/de/documentation.html
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/de/documentation.html,v
retrieving revision 1.71
diff -u -r1.71 documentation.html
--- DOCS/de/documentation.html	22 Mar 2003 12:01:46 -0000	1.71
+++ DOCS/de/documentation.html	19 Apr 2003 11:22:41 -0000
@@ -1108,6 +1108,11 @@
         ~/.mplayer/subfont.ttf</CODE></LI>
     </UL>
   </LI>
+  <LI>Mit Fontconfig in Kombination mit freetype erwartet der -font parameter
+    den fontconfig Namen der Schriftart:
+    <BR>
+    <CODE>-font 'Bitstream Vera Sans'</CODE>
+  </LI>
 </UL>
 
 <P>Wenn du eine Nicht-TrueType-Schrift benutzt, dann entpacke die Dateien  nach
Index: DOCS/de/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/de/mplayer.1,v
retrieving revision 1.27
diff -u -r1.27 mplayer.1
--- DOCS/de/mplayer.1	22 Mar 2003 12:01:47 -0000	1.27
+++ DOCS/de/mplayer.1	19 Apr 2003 11:22:49 -0000
@@ -909,6 +909,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
@@ -916,6 +918,8 @@
 \-font ~/\:.mplayer/\:arial\-14/\:font.desc
 .br
 \-font ~/\:.mplayer/\:arialuni.ttf
+.br
+\-font 'Bitstream Vera Sans'
 .RE
 .PD 1
 .
Index: DOCS/en/documentation.html
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/en/documentation.html,v
retrieving revision 1.400
diff -u -r1.400 documentation.html
--- DOCS/en/documentation.html	1 Apr 2003 00:33:16 -0000	1.400
+++ DOCS/en/documentation.html	19 Apr 2003 11:22:57 -0000
@@ -1014,6 +1014,11 @@
       <LI>create a symlink: <CODE>ln -s /path/to/arial.ttf ~/.mplayer/subfont.ttf</CODE></LI>
     </UL>
   </LI>
+  <LI>using Fontconfig in combination with freetype, you use the -font
+    parameter with a fontconfig font name:
+    <BR>
+    <CODE>-font 'Bitstream Vera Sans'</CODE>
+  </LI>
 </UL>
 
 <P>If you chose non-TTF fonts, UNZIP the file you downloaded to <CODE>~/.mplayer</CODE> or
Index: DOCS/en/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/en/mplayer.1,v
retrieving revision 1.371
diff -u -r1.371 mplayer.1
--- DOCS/en/mplayer.1	11 Apr 2003 10:27:31 -0000	1.371
+++ DOCS/en/mplayer.1	19 Apr 2003 11:23:06 -0000
@@ -900,6 +900,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
@@ -907,6 +909,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.5
diff -u -r1.5 install.xml
--- DOCS/xml/en/install.xml	30 Mar 2003 13:47:11 -0000	1.5
+++ DOCS/xml/en/install.xml	19 Apr 2003 11:23:09 -0000
@@ -752,6 +752,9 @@
       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>
 
Index: libvo/font_load_ft.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/font_load_ft.c,v
retrieving revision 1.9
diff -u -r1.9 font_load_ft.c
--- libvo/font_load_ft.c	30 Jan 2003 19:58:43 -0000	1.9
+++ libvo/font_load_ft.c	19 Apr 2003 11:23:15 -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
 }
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20030419/6ce4f5a7/attachment.pgp>


More information about the MPlayer-dev-eng mailing list