]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcfreetype.c
Add some example usages.
[fontconfig.git] / src / fcfreetype.c
index df13ad369932f89f87582cda548a8dce1419819a..054e208ae191a4ed534971867b353b0b8cf1c33b 100644 (file)
 #include <freetype/ttnameid.h>
 #include <freetype/t1tables.h>
 
-#if (FREETYPE_MINOR > 1 || (FREETYPE_MINOR == 1 && FREETYPE_PATCH >= 4))
+#if HAVE_FT_GET_BDF_PROPERTY
 #include <freetype/ftbdf.h>
 #include <freetype/ftmodule.h>
-#define USE_FTBDF
 #define HAS_BDF_PROPERTY(f) ((f) && (f)->driver && \
                             (f)->driver->root.clazz->get_interface)
 #define MY_Get_BDF_Property(f,n,p) (HAS_BDF_PROPERTY(f) ? \
                                    FT_Err_Invalid_Argument)
 #endif
 
+#if !HAVE_FT_GET_BDF_PROPERTY
+#warning "No FT_Get_BDF_Property"
+#endif
+
+#if !HAVE_FT_GET_PS_FONT_INFO
+#warning "No FT_Get_Font_Info"
+#endif
 
 /*
  * Keep Han languages separated by eliminating languages
@@ -357,8 +363,10 @@ FcFreeTypeQuery (const FcChar8     *file,
     const FcChar8   *foundry = 0;
     int                    spacing;
     TT_OS2         *os2;
+#if HAVE_FT_GET_PS_FONT_INFO
     PS_FontInfoRec  psfontinfo;
-#ifdef USE_FTBDF
+#endif
+#if HAVE_FT_GET_BDF_PROPERTY
     BDF_PropertyRec prop;
 #endif
     TT_Header      *head;
@@ -793,6 +801,7 @@ FcFreeTypeQuery (const FcChar8      *file,
      * Code from g2@magestudios.net (Gerard Escalante)
      */
     
+#if HAVE_FT_GET_PS_FONT_INFO
     if (FT_Get_PS_Font_Info(face, &psfontinfo) == 0)
     {
        if (weight == -1 && psfontinfo.weight)
@@ -817,8 +826,9 @@ FcFreeTypeQuery (const FcChar8      *file,
         if(!foundry)
             foundry = FcNoticeFoundry(psfontinfo.notice);
     }
+#endif /* HAVE_FT_GET_PS_FONT_INFO */
     
-#ifdef USE_FTBDF
+#if HAVE_FT_GET_BDF_PROPERTY
     /*
      * Finally, look for a FOUNDRY BDF property if no other
      * mechanism has managed to locate a foundry
@@ -866,7 +876,6 @@ FcFreeTypeQuery (const FcChar8      *file,
                printf ("\tsetwidth %s maps to %d\n", prop.u.atom, width);
        }
     }
-
 #endif
 
     /*
@@ -934,7 +943,7 @@ FcFreeTypeQuery (const FcChar8      *file,
     if (!cs)
        goto bail1;
 
-#ifdef USE_FTBDF
+#if HAVE_FT_GET_BDF_PROPERTY
     /* For PCF fonts, override the computed spacing with the one from
        the property */
     if(MY_Get_BDF_Property(face, "SPACING", &prop) == 0 &&
@@ -985,7 +994,7 @@ FcFreeTypeQuery (const FcChar8      *file,
                goto bail1;
        if (!FcPatternAddBool (pat, FC_ANTIALIAS, FcFalse))
            goto bail1;
-#ifdef USE_FTBDF
+#if HAVE_FT_GET_BDF_PROPERTY
         if(face->num_fixed_sizes == 1) {
             int rc;
             int value;
@@ -1062,31 +1071,10 @@ bail:
 }
 
 
-/*
- * Figure out whether the available freetype has FT_Get_Next_Char
- */
-
-#if FREETYPE_MAJOR > 2
-# define HAS_NEXT_CHAR
-#else
-# if FREETYPE_MAJOR == 2
-#  if FREETYPE_MINOR > 0
-#   define HAS_NEXT_CHAR
-#  else
-#   if FREETYPE_MINOR == 0
-#    if FREETYPE_PATCH >= 9
-#     define HAS_NEXT_CHAR
-#    endif
-#   endif
-#  endif
-# endif
-#endif
-
 /*
  * For our purposes, this approximation is sufficient
  */
-#ifndef HAS_NEXT_CHAR
-#define FT_Get_First_Char(face, gi) ((*(gi) = 1), 1)
+#if !HAVE_FT_GET_NEXT_CHAR
 #define FT_Get_Next_Char(face, ucs4, gi) ((ucs4) >= 0xffffff ? \
                                          (*(gi) = 0), 0 : \
                                          (*(gi) = 1), (ucs4) + 1)
@@ -1611,6 +1599,7 @@ FcHashGlyphName (const FcChar8 *name)
     return h;
 }
 
+#if HAVE_FT_HAS_PS_GLYPH_NAMES
 /*
  * Use Type1 glyph names for fonts which have reliable names
  * and which export an Adobe Custom mapping
@@ -1696,6 +1685,7 @@ FcFreeTypeGlyphNameIndex (FT_Face face, FcChar8 *name)
     }
     return 0;
 }
+#endif
 
 /*
  * Map a UCS4 glyph to a glyph index.  Use all available encoding
@@ -1743,6 +1733,7 @@ FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4)
        if (glyphindex)
            return glyphindex;
     }
+#if HAVE_FT_HAS_PS_GLYPH_NAMES
     /*
      * Check postscript name table if present
      */
@@ -1756,6 +1747,7 @@ FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4)
                return glyphindex;
        }
     }
+#endif
     return 0;
 }
 
@@ -1815,6 +1807,8 @@ FcFreeTypeCheckGlyph (FT_Face face, FcChar32 ucs4,
     return FcFalse;
 }
 
+#define APPROXIMATELY_EQUAL(x,y) (ABS ((x) - (y)) <= MAX (ABS (x), ABS (y)) / 33)
+
 FcCharSet *
 FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
 {
@@ -1828,8 +1822,8 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
     int                    o;
     int                    i;
     FT_UInt        glyph;
-    FT_Pos         advance, all_advance = 0;
-    FcBool         has_advance = FcFalse, fixed_advance = FcTrue;
+    FT_Pos         advance, advance_one = 0, advance_two = 0;
+    FcBool         has_advance = FcFalse, fixed_advance = FcTrue, dual_advance = FcFalse;
 
     fcs = FcCharSetCreate ();
     if (!fcs)
@@ -1859,10 +1853,20 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
                    if (!has_advance)
                    {
                        has_advance = FcTrue;
-                       all_advance = advance;
+                       advance_one = advance;
                    }
-                   else if (advance != all_advance)
-                       fixed_advance = FcFalse;
+                   else if (!APPROXIMATELY_EQUAL (advance, advance_one))
+                    {
+                        if (fixed_advance)
+                        {
+                            dual_advance = FcTrue;
+                            fixed_advance = FcFalse;
+                            advance_two = advance;
+                        }
+                        else if (!APPROXIMATELY_EQUAL (advance, advance_two))
+                            dual_advance = FcFalse;
+                    }
+
                    leaf = FcCharSetFindLeafCreate (fcs, ucs4);
                    if (!leaf)
                        goto bail1;
@@ -1907,10 +1911,20 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
                        if (!has_advance)
                        {
                            has_advance = FcTrue;
-                           all_advance = advance;
+                           advance_one = advance;
                        }
-                       else if (advance != all_advance)
-                           fixed_advance = FcFalse;
+                       else if (!APPROXIMATELY_EQUAL (advance, advance_one))
+                        {
+                            if (fixed_advance)
+                            {
+                                dual_advance = FcTrue;
+                                fixed_advance = FcFalse;
+                                advance_two = advance;
+                            }
+                            else if (!APPROXIMATELY_EQUAL (advance, advance_two))
+                                dual_advance = FcFalse;
+                        }
+
                        if (!leaf)
                        {
                            leaf = FcCharSetFindLeafCreate (fcs, ucs4);
@@ -1945,6 +1959,7 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
 #endif
        }
     }
+#if HAVE_FT_HAS_PS_GLYPH_NAMES
     /*
      * Add mapping from PS glyph names if available
      */
@@ -1963,10 +1978,19 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
                    if (!has_advance)
                    {
                        has_advance = FcTrue;
-                       all_advance = advance;
+                       advance_one = advance;
                    }
-                   else if (advance != all_advance)
-                       fixed_advance = FcFalse;
+                   else if (!APPROXIMATELY_EQUAL (advance, advance_one))
+                    {
+                        if (fixed_advance)
+                        {
+                            dual_advance = FcTrue;
+                            fixed_advance = FcFalse;
+                            advance_two = advance;
+                        }
+                        else if (!APPROXIMATELY_EQUAL (advance, advance_two))
+                            dual_advance = FcFalse;
+                    }
                    leaf = FcCharSetFindLeafCreate (fcs, ucs4);
                    if (!leaf)
                        goto bail1;
@@ -1979,6 +2003,7 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
            }
        }
     }
+#endif
 #ifdef CHECK
     printf ("%d glyphs %d encoded\n", (int) face->num_glyphs, FcCharSetCount (fcs));
     for (ucs4 = 0; ucs4 <= font_max; ucs4++)
@@ -1999,6 +2024,8 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
 #endif
     if (fixed_advance)
        *spacing = FC_MONO;
+    else if (dual_advance && APPROXIMATELY_EQUAL (2 * MIN (advance_one, advance_two), MAX (advance_one, advance_two)))
+        *spacing = FC_DUAL;
     else
        *spacing = FC_PROPORTIONAL;
     return fcs;