Use explicit platform/nameid order when scanning ttf files.
Instead of accepting whatever order names appear in the font file, use an explicit ordering for both platform and nameid. Platforms are high precedence than nameids. The platform order is: microsoft, apple unicode, macintosh, (other) The family nameid order is: preferred family, font family The fullname nameid order is: mac full name, full name The style nameid order is preferred subfamily, font subfamily This will change the names visible to users in various application UIs, but should not change how existing font names are matched as all names remain present in the resulting database. The hope is that family names will, in general, be less ambiguous. Testing here shows that commercial fonts have longer names now while DejaVu has a shorter family name, and moves more of the font description to the style name.
This commit is contained in:
parent
b5803016d7
commit
253ec7609c
|
@ -1043,6 +1043,25 @@ FcStringInPatternElement (FcPattern *pat, const char *elt, FcChar8 *string)
|
|||
return FcFalse;
|
||||
}
|
||||
|
||||
static const FT_UShort platform_order[] = {
|
||||
TT_PLATFORM_MICROSOFT,
|
||||
TT_PLATFORM_APPLE_UNICODE,
|
||||
TT_PLATFORM_MACINTOSH,
|
||||
};
|
||||
#define NUM_PLATFORM_ORDER (sizeof (platform_order) / sizeof (platform_order[0]))
|
||||
|
||||
static const FT_UShort nameid_order[] = {
|
||||
TT_NAME_ID_PREFERRED_FAMILY,
|
||||
TT_NAME_ID_FONT_FAMILY,
|
||||
TT_NAME_ID_MAC_FULL_NAME,
|
||||
TT_NAME_ID_FULL_NAME,
|
||||
TT_NAME_ID_PREFERRED_SUBFAMILY,
|
||||
TT_NAME_ID_FONT_SUBFAMILY,
|
||||
TT_NAME_ID_TRADEMARK,
|
||||
TT_NAME_ID_MANUFACTURER,
|
||||
};
|
||||
|
||||
#define NUM_NAMEID_ORDER (sizeof (nameid_order) / sizeof (nameid_order[0]))
|
||||
FcPattern *
|
||||
FcFreeTypeQuery (const FcChar8 *file,
|
||||
int id,
|
||||
|
@ -1083,6 +1102,8 @@ FcFreeTypeQuery (const FcChar8 *file,
|
|||
int nstyle_lang = 0;
|
||||
int nfullname = 0;
|
||||
int nfullname_lang = 0;
|
||||
int p, platform;
|
||||
int n, nameid;
|
||||
|
||||
FcChar8 *style = 0;
|
||||
int st;
|
||||
|
@ -1132,6 +1153,21 @@ FcFreeTypeQuery (const FcChar8 *file,
|
|||
* of them
|
||||
*/
|
||||
snamec = FT_Get_Sfnt_Name_Count (face);
|
||||
for (p = 0; p <= NUM_PLATFORM_ORDER; p++)
|
||||
{
|
||||
if (p < NUM_PLATFORM_ORDER)
|
||||
platform = platform_order[p];
|
||||
else
|
||||
platform = 0xffff;
|
||||
|
||||
/*
|
||||
* Order nameids so preferred names appear first
|
||||
* in the resulting list
|
||||
*/
|
||||
for (n = 0; n < NUM_NAMEID_ORDER; n++)
|
||||
{
|
||||
nameid = nameid_order[n];
|
||||
|
||||
for (snamei = 0; snamei < snamec; snamei++)
|
||||
{
|
||||
FcChar8 *utf8;
|
||||
|
@ -1141,7 +1177,28 @@ FcFreeTypeQuery (const FcChar8 *file,
|
|||
|
||||
if (FT_Get_Sfnt_Name (face, snamei, &sname) != 0)
|
||||
continue;
|
||||
if (sname.name_id != nameid)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Sort platforms in preference order, accepting
|
||||
* all other platforms last
|
||||
*/
|
||||
if (p < NUM_PLATFORM_ORDER)
|
||||
{
|
||||
if (sname.platform_id != platform)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
int sp;
|
||||
|
||||
for (sp = 0; sp < NUM_PLATFORM_ORDER; sp++)
|
||||
if (sname.platform_id == platform_order[sp])
|
||||
break;
|
||||
if (sp != NUM_PLATFORM_ORDER)
|
||||
continue;
|
||||
}
|
||||
utf8 = FcSfntNameTranscode (&sname);
|
||||
lang = FcSfntNameLanguage (&sname);
|
||||
|
||||
|
@ -1149,6 +1206,7 @@ FcFreeTypeQuery (const FcChar8 *file,
|
|||
continue;
|
||||
|
||||
switch (sname.name_id) {
|
||||
case TT_NAME_ID_PREFERRED_FAMILY:
|
||||
case TT_NAME_ID_FONT_FAMILY:
|
||||
#if 0
|
||||
case TT_NAME_ID_PS_NAME:
|
||||
|
@ -1165,8 +1223,8 @@ FcFreeTypeQuery (const FcChar8 *file,
|
|||
np = &nfamily;
|
||||
nlangp = &nfamily_lang;
|
||||
break;
|
||||
case TT_NAME_ID_FULL_NAME:
|
||||
case TT_NAME_ID_MAC_FULL_NAME:
|
||||
case TT_NAME_ID_FULL_NAME:
|
||||
if (FcDebug () & FC_DBG_SCANV)
|
||||
printf ("found full (n %2d p %d e %d l 0x%04x) %s\n",
|
||||
sname.name_id, sname.platform_id,
|
||||
|
@ -1178,6 +1236,7 @@ FcFreeTypeQuery (const FcChar8 *file,
|
|||
np = &nfullname;
|
||||
nlangp = &nfullname_lang;
|
||||
break;
|
||||
case TT_NAME_ID_PREFERRED_SUBFAMILY:
|
||||
case TT_NAME_ID_FONT_SUBFAMILY:
|
||||
if (FcDebug () & FC_DBG_SCANV)
|
||||
printf ("found style (n %2d p %d e %d l 0x%04x) %s\n",
|
||||
|
@ -1230,6 +1289,8 @@ FcFreeTypeQuery (const FcChar8 *file,
|
|||
else
|
||||
free (utf8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nfamily && face->family_name &&
|
||||
FcStrCmpIgnoreBlanksAndCase ((FcChar8 *) face->family_name, (FcChar8 *) "") != 0)
|
||||
|
|
Loading…
Reference in New Issue