]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcfreetype.c
bool was misdeclared in DTD
[fontconfig.git] / src / fcfreetype.c
index 7a9e32d2a4dca301be6c48fc2ca60ad1708e29ad..13a6c0c38fc3cd412a949fd591df341056c0294c 100644 (file)
@@ -31,6 +31,9 @@
 #include <freetype/tttables.h>
 #include <freetype/ftsnames.h>
 #include <freetype/ttnameid.h>
+#include <freetype/t1tables.h>
+
+#include "data.h"
 
 /*
  * Keep Han languages separated by eliminating languages
@@ -111,6 +114,41 @@ FcUtf8IsLatin (FcChar8 *str, int len)
     return FcTrue;
 }
 
+static char*
+notice_foundry(char *notice)
+{
+    int i;
+    for(i = 0; i < sizeof(notice_foundries) / sizeof(notice_foundries[0]); i++)
+        if(notice && strstr(notice, notice_foundries[i][0]))
+            return notice_foundries[i][1];
+    return NULL;
+}
+
+static int
+vendor_match(signed char *vendor, char *vendor_string)
+{
+    /* vendor is not necessarily NUL-terminated. */
+    int i, len;
+    len = strlen(vendor_string);
+    if(memcmp(vendor, vendor_string, len) != 0)
+        return 0;
+    for(i = len; i < 4; i++)
+        if(vendor[i] != ' ' && vendor[i] != '\0')
+            return 0;
+    return 1;
+}
+
+static char*
+vendor_foundry(signed char *vendor)
+{
+    int i;
+    for(i = 0; i < sizeof(vendor_foundries) / sizeof(vendor_foundries[0]); i++)
+        if(vendor_match(vendor, vendor_foundries[i][0]))
+            return vendor_foundries[i][1];
+    return NULL;
+}
+
+
 FcPattern *
 FcFreeTypeQuery (const FcChar8 *file,
                 int            id,
@@ -128,8 +166,10 @@ FcFreeTypeQuery (const FcChar8     *file,
     FT_Library     ftLibrary;
     FcChar8        *family;
     FcChar8        *style;
+    FcChar8         *foundry;
     int                    spacing;
     TT_OS2         *os2;
+    PS_FontInfoRec  psfontinfo;
     TT_Header      *head;
     const FcChar8   *exclusiveLang = 0;
     FT_SfntName            sname;
@@ -169,6 +209,16 @@ FcFreeTypeQuery (const FcChar8     *file,
     if (face->style_flags & FT_STYLE_FLAG_BOLD)
        weight = FC_WEIGHT_BOLD;
 
+    /*
+     * Get the OS/2 table
+     */
+    os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
+
+    if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
+        foundry = vendor_foundry(os2->achVendID);
+    else
+        foundry = NULL;
+
     /*
      * Grub through the name table looking for family
      * and style names.  FreeType makes quite a hash
@@ -176,6 +226,7 @@ FcFreeTypeQuery (const FcChar8      *file,
      */
     family = 0;
     style = 0;
+    foundry = 0;
     snamec = FT_Get_Sfnt_Name_Count (face);
     for (snamei = 0; snamei < snamec; snamei++)
     {
@@ -285,7 +336,9 @@ FcFreeTypeQuery (const FcChar8      *file,
            prio |= FC_NAME_PRIO_NAME_PS;
            break;
        case TT_NAME_ID_FONT_SUBFAMILY:
-           break;
+        case TT_NAME_ID_TRADEMARK:
+        case TT_NAME_ID_MANUFACTURER:
+            break;
        default:
            continue;
        }
@@ -398,6 +451,11 @@ FcFreeTypeQuery (const FcChar8     *file,
                style_prio = prio;
            }
            break;
+        case TT_NAME_ID_TRADEMARK:
+        case TT_NAME_ID_MANUFACTURER:
+            if(!foundry)
+                foundry = notice_foundry(utf8);
+            break;
        }
        if (utf8)
            free (utf8);
@@ -455,6 +513,11 @@ FcFreeTypeQuery (const FcChar8     *file,
            free (style);
     }
 
+    if(foundry) {
+        if(!FcPatternAddString (pat, FC_FOUNDRY, foundry))
+            goto bail;
+    }
+
     if (!FcPatternAddString (pat, FC_FILE, file))
        goto bail1;
 
@@ -490,10 +553,6 @@ FcFreeTypeQuery (const FcChar8     *file,
            goto bail1;
     }
 
-    /*
-     * Get the OS/2 table and poke about
-     */
-    os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
     if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
     {
        for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
@@ -525,6 +584,9 @@ FcFreeTypeQuery (const FcChar8      *file,
                exclusiveLang = FcCodePageRange[i].lang;
            }
        }
+
+        foundry = vendor_foundry(os2->achVendID);
+
     }
 
     if (os2 && os2->version != 0xffff)
@@ -564,6 +626,54 @@ FcFreeTypeQuery (const FcChar8     *file,
        case 9: width = FC_WIDTH_ULTRAEXPANDED; break;
        }
     }
+
+    /*
+     * Type 1: Check for FontInfo dictionary information
+     * Code from g2@magestudios.net (Gerard Escalante)
+     */
+    
+    if (FT_Get_PS_Font_Info(face, &psfontinfo) == 0)
+    {
+       if (psfontinfo.weight)
+       {
+           static struct {
+               char    *name;
+               int     value;
+           } ps_weights[] = {
+               { "thin",               FC_WEIGHT_THIN },
+               { "extralight",         FC_WEIGHT_EXTRALIGHT },
+               { "ultralight",         FC_WEIGHT_ULTRALIGHT },
+               { "light",              FC_WEIGHT_LIGHT },
+               { "regular",            FC_WEIGHT_REGULAR },
+               { "normal",             FC_WEIGHT_NORMAL },
+               { "medium",             FC_WEIGHT_MEDIUM },
+               { "demibold",           FC_WEIGHT_DEMIBOLD },
+               { "semibold",           FC_WEIGHT_SEMIBOLD },
+               { "bold",               FC_WEIGHT_BOLD },
+               { "extrabold",          FC_WEIGHT_EXTRABOLD },
+               { "ultrabold",          FC_WEIGHT_ULTRABOLD },
+               { "black",              FC_WEIGHT_BLACK },
+               { "heavy",              FC_WEIGHT_HEAVY },
+           };
+#define NUM_PS_WEIGHTS (sizeof (ps_weights) / sizeof (ps_weights[0]))
+           int w;
+           for (w = 0; w < NUM_PS_WEIGHTS; w++)
+               if (!FcStrCmpIgnoreCase ((FcChar8 *) ps_weights[w].name,
+                                        (FcChar8 *) psfontinfo.weight))
+               {
+                   weight = ps_weights[w].value;
+                   break;
+               }
+       }
+     
+        if (psfontinfo.italic_angle < 0) 
+            slant = FC_SLANT_ITALIC; 
+        else if (psfontinfo.italic_angle >= 0) 
+            slant = FC_SLANT_ROMAN; 
+
+        if(!foundry)
+            foundry = notice_foundry(psfontinfo.notice);
+    }
     
     if (!FcPatternAddInteger (pat, FC_SLANT, slant))
        goto bail1;