[MPlayer-dev-eng] [PATCH] fontconfig font lookup support
Arwed von Merkatz
v.merkatz at gmx.net
Sun Dec 7 17:04:37 CET 2003
On Sun, Dec 07, 2003 at 04:09:57PM +0100, Alex Beregszaszi wrote:
> 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.
> Could you send a new patch for current CVS?
Here it is.
--
Arwed v. Merkatz
Grimoire Guru for video
Grimoire Guru for xfce
Sourcemage GNU/Linux
http://www.sourcemage.org
-------------- next part --------------
? TOOLS/divx2pass.log
Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/Makefile,v
retrieving revision 1.278
diff -u -r1.278 Makefile
--- Makefile 18 Nov 2003 02:32:42 -0000 1.278
+++ Makefile 7 Dec 2003 16:05:37 -0000
@@ -40,6 +40,8 @@
CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(X11_INC) $(FRIBIDI_INC) $(DVB_INC) $(XVID_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.818
diff -u -r1.818 configure
--- configure 7 Dec 2003 15:26:12 -0000 1.818
+++ configure 7 Dec 2003 16:05:52 -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
@@ -6340,6 +6380,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.223
diff -u -r1.223 mencoder.c
--- mencoder.c 2 Dec 2003 23:40:05 -0000 1.223
+++ mencoder.c 7 Dec 2003 16:05:57 -0000
@@ -442,6 +442,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.737
diff -u -r1.737 mplayer.c
--- mplayer.c 30 Nov 2003 16:35:38 -0000 1.737
+++ mplayer.c 7 Dec 2003 16:06:07 -0000
@@ -1058,8 +1058,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);
@@ -1069,9 +1076,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 7 Dec 2003 16:06:17 -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.496
diff -u -r1.496 mplayer.1
--- DOCS/man/en/mplayer.1 7 Dec 2003 00:45:38 -0000 1.496
+++ DOCS/man/en/mplayer.1 7 Dec 2003 16:06:27 -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
.
Index: DOCS/xml/en/install.xml
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/xml/en/install.xml,v
retrieving revision 1.20
diff -u -r1.20 install.xml
--- DOCS/xml/en/install.xml 30 Nov 2003 13:07:40 -0000 1.20
+++ DOCS/xml/en/install.xml 7 Dec 2003 16:06:31 -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>
Index: libvo/font_load_ft.c
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/font_load_ft.c,v
retrieving revision 1.11
diff -u -r1.11 font_load_ft.c
--- libvo/font_load_ft.c 20 Nov 2003 16:25:40 -0000 1.11
+++ libvo/font_load_ft.c 7 Dec 2003 16:06:38 -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;
@@ -1121,8 +1130,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