Mac OS X fixes.
[swftools.git] / m4 / freetype.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_FREETYPE,
19 [
20 AC_CHECK_PROGS(FREETYPE_CONFIG, freetype-config,)
21 OLDCPPFLAGS="${CPPFLAGS}"
22 OLDLIBS="${LIBS}"
23 if test "x${FREETYPE_CONFIG}" '!=' "x"; then
24     CPPFLAGS="$CPPFLAGS "`freetype-config --cflags`
25 else if test -d /usr/include/freetype2; then
26     CPPFLAGS="$CPPFLAGS -I/usr/include/freetype2"
27 else if test -d /usr/local/include/freetype2; then
28     CPPFLAGS="$CPPFLAGS -I/usr/local/include/freetype2"
29 fi 
30 fi
31 fi
32
33 if test "x${FREETYPE_CONFIG}" '=' "x";then
34     # if we didn't find the freetype-config program, we won't
35     # know where the libs are expected to be. So just blindly
36     # try to link against them.
37     AC_CHECK_LIB(freetype, FT_Init_FreeType,HAVE_LIB_FREETYPE=1,)
38 fi
39
40 AC_CHECK_HEADERS(ft2build.h,HAVE_FT2BUILD_H=1)
41 if test "x${HAVE_FT2BUILD_H}" '=' "x";then
42     AC_CHECK_HEADERS(freetype/freetype.h,HAVE_FREETYPE_FREETYPE_H=1)
43 fi
44
45 if test "x${HAVE_LIB_FREETYPE}" '!=' "x" -o \
46         "x${FREETYPE_CONFIG}" '!=' "x";then
47     if test "x${HAVE_FREETYPE_FREETYPE_H}" '!=' "x";then
48         HAVE_FREETYPE=1
49     fi
50     if test "x${HAVE_FT2BUILD_H}" '!=' "x";then
51         HAVE_FREETYPE=1
52     fi
53 fi
54
55 if test "x${HAVE_FREETYPE}" = "x1"; then 
56     if test "x${FREETYPE_CONFIG}" '!=' "x"; then
57         LIBS="$LIBS "`freetype-config --libs`
58     else
59         LIBS="$LIBS -lfreetype"
60     fi
61
62     if test "x${HAVE_FT2BUILD_H}" = "x1"; then
63         HAVE_FT2BUILD_H_DEFINE='#define HAVE_FT2BUILD_H'
64     fi
65
66     AC_MSG_CHECKING([whether we can compile the freetype test program])
67
68     cat > conftest.c << EOF
69 $HAVE_FT2BUILD_H_DEFINE
70
71 #ifdef HAVE_FT2BUILD_H
72 #include <ft2build.h>
73 #include FT_FREETYPE_H
74 #include FT_GLYPH_H
75 #include FT_SIZES_H
76 #include FT_SFNT_NAMES_H
77 #include FT_TRUETYPE_IDS_H
78 #include FT_OUTLINE_H
79 #else
80 #include <freetype/freetype.h>
81 #include <freetype/ftglyph.h>
82 #include <freetype/ftsizes.h>
83 #include <freetype/ftsnames.h>
84 #include <freetype/ttnameid.h>
85 #include <freetype/ftoutln.h>
86 #endif
87
88 int main()
89 {
90     FT_Library ftlibrary;
91     FT_Face face;
92     FT_Error error;
93     FT_ULong charcode;
94     FT_UInt gindex;
95     FT_Glyph glyph;
96     FT_BBox bbox;
97     FT_Matrix matrix;
98     FT_UInt i;
99     char* name = 0;
100     char italic, bold;
101    
102     FT_Init_FreeType(&ftlibrary);
103     FT_New_Face(ftlibrary, "filename", 0, &face);
104     i = face->num_glyphs - 1;
105     italic = face->style_flags&FT_STYLE_FLAG_ITALIC;
106     bold = face->style_flags&FT_STYLE_FLAG_BOLD;
107     FT_Get_Postscript_Name(face);
108     FT_Get_Char_Index(face, 33);
109     FT_Get_First_Char(face, &i);
110     FT_Get_Next_Char(face, 33, &i);
111     if(FT_HAS_GLYPH_NAMES(face)) {
112         FT_Get_Glyph_Name(face, 33, name, 127);
113     }
114     FT_Load_Glyph(face, 33, FT_LOAD_NO_BITMAP|FT_LOAD_NO_SCALE);
115     FT_Get_Glyph(face->glyph, &glyph);
116     FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_unscaled, &bbox);
117     FT_Done_Glyph(glyph);
118     FT_Done_Face(face);
119     FT_Done_FreeType(ftlibrary);
120     return 0;
121 }
122 EOF
123
124     ac_link='$CC $CPPFLAGS $CFLAGS conftest.c $LDFLAGS $LIBS -o conftest${ac_exeext}'
125     if { (eval echo freetype.m4:71: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
126         AC_MSG_RESULT(yes)
127         AC_DEFINE_UNQUOTED(HAVE_FREETYPE, 1)
128         AC_DEFINE_UNQUOTED(USE_FREETYPE, 1)  # for ttf2tp1
129     else
130         echo "configure: failed program was:" >&5
131         cat conftest.c >&5
132         HAVE_FREETYPE=0
133         AC_MSG_RESULT(no)
134     fi
135     rm -f conftest*
136 fi
137
138 # if the above didn't work out, reset all changes to the compiler variables.
139 if test "x${HAVE_FREETYPE}" '!=' "x1"; then 
140     CPPFLAGS=$OLDCPPFLAGS
141     LIBS=$OLDLIBS
142 fi 
143 ])
144