#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
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,
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;
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
*/
family = 0;
style = 0;
+ foundry = 0;
snamec = FT_Get_Sfnt_Name_Count (face);
for (snamei = 0; snamei < snamec; snamei++)
{
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;
}
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);
free (style);
}
+ if(foundry) {
+ if(!FcPatternAddString (pat, FC_FOUNDRY, foundry))
+ goto bail;
+ }
+
if (!FcPatternAddString (pat, FC_FILE, file))
goto bail1;
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++)
exclusiveLang = FcCodePageRange[i].lang;
}
}
+
+ foundry = vendor_foundry(os2->achVendID);
+
}
if (os2 && os2->version != 0xffff)
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;