new parameter -s textonly
[swftools.git] / m4 / fontconfig.m4
1 # ----------- freetype.m4 ----------------
2 #
3 # Checks for:
4 #    * freetype library (-lfreetype)
5 #    * freetype headers (freetype2/freetype/freetype.h)
6 #    * whether a freetype test program can be compiled
7
8 # Environment set:
9 #    * HAVE_FREETYPE
10 #
11 # Defines:
12 #    * HAVE_FREETYPE
13 #    * USE_FREETYPE
14 #
15 # Substitutes:
16 #
17
18 AC_DEFUN([RFX_CHECK_FONTCONFIG],
19 [
20 OLDCPPFLAGS="${CPPFLAGS}"
21 OLDLIBS="${LIBS}"
22         
23 if test -d /usr/include/fontconfig; then
24     CPPFLAGS="$CPPFLAGS -I/usr/include/fontconfig"
25 fi
26
27 AC_CHECK_LIB(fontconfig, FcInit, [HAVE_LIB_FONTCONFIG=1],)
28 AC_CHECK_HEADERS(fontconfig.h,[HAVE_FONTCONFIG_H=1])
29
30 if test "x${HAVE_LIB_FONTCONFIG}" != "x";then
31 if test "x${HAVE_FONTCONFIG_H}" != "x";then
32     HAVE_FONTCONFIG=1
33 fi
34 fi
35
36 if test "x${HAVE_FONTCONFIG}" = "x1"; then 
37     LIBS="$LIBS -lfontconfig"
38 AC_MSG_CHECKING([whether we can compile the fontconfig test program])
39
40 if (echo $LIBS | grep lfreetype >/dev/null 2>&1); then
41     #move freetype library to the end of libraries, otherwise fontconfig
42     #won't compile.
43     LIBS=`echo $LIBS | sed -e 's/-lfreetype//g' -e 's/$/ -lfreetype/'`
44 fi
45
46 cat > conftest.c << EOF
47 #include <string.h>
48 #include <fontconfig.h>
49
50 int main()
51 {
52     FcPattern *pattern, *match;
53     FcResult result;
54     FcChar8 *v;
55     char*s1="abc",*s2="ABC";
56     strcasecmp(s1,s2);
57     FcInit();
58     pattern = FcPatternBuild(0, FC_FAMILY, FcTypeString, "", 0);
59     FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
60     FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
61
62     FcConfig*c = FcConfigCreate();
63     FcConfigParseAndLoad(c, (FcChar8*)"", 1);
64     FcConfigBuildFonts(c);
65     FcConfigSetCurrent(c);
66         
67     FcFontSet * set =  FcConfigGetFonts(c, FcSetSystem);
68     FcFontSetDestroy(set);
69
70     FcConfigSubstitute(0, pattern, FcMatchPattern); 
71     FcDefaultSubstitute(pattern);
72     match = FcFontMatch(0, pattern, &result);
73     FcPatternGetString(match, "family", 0, &v) == FcResultMatch;
74     FcPatternGetBool(match, "family", 0, &v) == FcResultMatch;
75     FcPatternPrint(pattern);
76     FcPatternDestroy(pattern);
77     FcPatternDestroy(match);
78     FcFini();
79     return 0;
80 }
81 EOF
82
83     ac_link='$CC $CPPFLAGS $CFLAGS conftest.c $LDFLAGS $LIBS -o conftest${ac_exeext}'
84     if { (eval echo freetype.m4:71: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
85         AC_MSG_RESULT(yes)
86         AC_DEFINE([HAVE_FONTCONFIG], [1], [Define if fontconfig is available])
87     else
88         echo "configure: failed program was:" >&5
89         cat conftest.c >&5
90         HAVE_FONTCONFIG=0
91         AC_MSG_RESULT(no)
92     fi
93     rm -f conftest*
94 fi
95
96 # if the above didn't work out, reset all changes to the compiler variables.
97 if test "x${HAVE_FONTCONFIG}" "!=" "x1"; then 
98     CPPFLAGS=$OLDCPPFLAGS
99     LIBS=$OLDLIBS
100 fi 
101 ])
102