Fix name scanning
In 161c738
I switched from linear name scanning to binary searching.
That, however, ignored the fact that there might be more than one
name table entry for each pair we want to query.
To fix that and retain bsearch, I now get all name entries first,
sort them, and use for bsearching.
This fixes https://bugs.freedesktop.org/show_bug.cgi?id=105756
This makes scaning Voto Serif GX twice slower though, since we are
creating and sorting the list for each instance. In the next commit,
I'll share this list across different instances to fix this.
This commit is contained in:
parent
31269e3589
commit
fa13f8835c
|
@ -1136,30 +1136,65 @@ static const FT_UShort nameid_order[] = {
|
||||||
|
|
||||||
#define NUM_NAMEID_ORDER (sizeof (nameid_order) / sizeof (nameid_order[0]))
|
#define NUM_NAMEID_ORDER (sizeof (nameid_order) / sizeof (nameid_order[0]))
|
||||||
|
|
||||||
static FcBool
|
typedef struct
|
||||||
FcFreeTypeGetName (const FT_Face face,
|
{
|
||||||
|
unsigned int platform_id;
|
||||||
|
unsigned int name_id;
|
||||||
|
unsigned int encoding_id;
|
||||||
|
unsigned int language_id;
|
||||||
|
unsigned int idx;
|
||||||
|
} FcNameMapping;
|
||||||
|
|
||||||
|
static int
|
||||||
|
name_mapping_cmp (const void *pa, const void *pb)
|
||||||
|
{
|
||||||
|
const FcNameMapping *a = (const FcNameMapping *) pa;
|
||||||
|
const FcNameMapping *b = (const FcNameMapping *) pb;
|
||||||
|
|
||||||
|
if (a->platform_id != b->platform_id) return (int) a->platform_id - (int) b->platform_id;
|
||||||
|
if (a->name_id != b->name_id) return (int) a->name_id - (int) b->name_id;
|
||||||
|
if (a->encoding_id != b->encoding_id) return (int) a->encoding_id - (int) b->encoding_id;
|
||||||
|
if (a->language_id != b->language_id) return (int) a->language_id - (int) b->language_id;
|
||||||
|
if (a->idx != b->idx) return (int) a->idx - (int) b->idx;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
FcFreeTypeGetFirstName (const FT_Face face,
|
||||||
unsigned int platform,
|
unsigned int platform,
|
||||||
unsigned int nameid,
|
unsigned int nameid,
|
||||||
|
FcNameMapping *mapping,
|
||||||
|
unsigned int count,
|
||||||
FT_SfntName *sname)
|
FT_SfntName *sname)
|
||||||
{
|
{
|
||||||
int min = 0, max = (int) FT_Get_Sfnt_Name_Count (face) - 1;
|
int min = 0, max = (int) count - 1;
|
||||||
|
|
||||||
while (min <= max)
|
while (min <= max)
|
||||||
{
|
{
|
||||||
int mid = (min + max) / 2;
|
int mid = (min + max) / 2;
|
||||||
|
|
||||||
if (FT_Get_Sfnt_Name (face, mid, sname) != 0)
|
if (FT_Get_Sfnt_Name (face, mapping[mid].idx, sname) != 0)
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
|
|
||||||
if (platform < sname->platform_id || (platform == sname->platform_id && nameid < sname->name_id))
|
if (platform < sname->platform_id ||
|
||||||
|
(platform == sname->platform_id &&
|
||||||
|
(nameid < sname->name_id ||
|
||||||
|
(nameid == sname->name_id &&
|
||||||
|
(mid &&
|
||||||
|
platform == mapping[mid - 1].platform_id &&
|
||||||
|
nameid == mapping[mid - 1].name_id
|
||||||
|
)))))
|
||||||
max = mid - 1;
|
max = mid - 1;
|
||||||
else if (platform > sname->platform_id || (platform == sname->platform_id && nameid > sname->name_id))
|
else if (platform > sname->platform_id ||
|
||||||
|
(platform == sname->platform_id &&
|
||||||
|
nameid > sname->name_id))
|
||||||
min = mid + 1;
|
min = mid + 1;
|
||||||
else
|
else
|
||||||
return FcTrue;
|
return mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FcFalse;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FcPattern *
|
static FcPattern *
|
||||||
|
@ -1180,6 +1215,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
|
||||||
FcBool variable_size = FcFalse;
|
FcBool variable_size = FcFalse;
|
||||||
FcCharSet *cs;
|
FcCharSet *cs;
|
||||||
FcLangSet *ls;
|
FcLangSet *ls;
|
||||||
|
FcNameMapping *name_mapping = 0;
|
||||||
#if 0
|
#if 0
|
||||||
FcChar8 *family = 0;
|
FcChar8 *family = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1203,6 +1239,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
|
||||||
TT_Header *head;
|
TT_Header *head;
|
||||||
const FcChar8 *exclusiveLang = 0;
|
const FcChar8 *exclusiveLang = 0;
|
||||||
|
|
||||||
|
int name_count = 0;
|
||||||
int nfamily = 0;
|
int nfamily = 0;
|
||||||
int nfamily_lang = 0;
|
int nfamily_lang = 0;
|
||||||
int nstyle = 0;
|
int nstyle = 0;
|
||||||
|
@ -1369,6 +1406,36 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
|
||||||
* and style names. FreeType makes quite a hash
|
* and style names. FreeType makes quite a hash
|
||||||
* of them
|
* of them
|
||||||
*/
|
*/
|
||||||
|
name_count = FT_Get_Sfnt_Name_Count (face);
|
||||||
|
if (!name_mapping)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
name_mapping = malloc (name_count * sizeof (FcNameMapping));
|
||||||
|
if (!name_mapping)
|
||||||
|
name_count = 0;
|
||||||
|
for (i = 0; i < name_count; i++)
|
||||||
|
{
|
||||||
|
FcNameMapping *p = &name_mapping[i];
|
||||||
|
FT_SfntName sname;
|
||||||
|
if (FT_Get_Sfnt_Name (face, i, &sname) == 0)
|
||||||
|
{
|
||||||
|
p->platform_id = sname.platform_id;
|
||||||
|
p->name_id = sname.name_id;
|
||||||
|
p->encoding_id = sname.encoding_id;
|
||||||
|
p->language_id = sname.language_id;
|
||||||
|
p->idx = i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p->platform_id =
|
||||||
|
p->name_id =
|
||||||
|
p->encoding_id =
|
||||||
|
p->language_id =
|
||||||
|
p->idx = (unsigned int) -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qsort (name_mapping, name_count, sizeof(FcNameMapping), name_mapping_cmp);
|
||||||
|
}
|
||||||
for (p = 0; p < NUM_PLATFORM_ORDER; p++)
|
for (p = 0; p < NUM_PLATFORM_ORDER; p++)
|
||||||
{
|
{
|
||||||
int platform = platform_order[p];
|
int platform = platform_order[p];
|
||||||
|
@ -1380,6 +1447,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
|
||||||
for (n = 0; n < NUM_NAMEID_ORDER; n++)
|
for (n = 0; n < NUM_NAMEID_ORDER; n++)
|
||||||
{
|
{
|
||||||
FT_SfntName sname;
|
FT_SfntName sname;
|
||||||
|
int nameidx;
|
||||||
const FcChar8 *lang;
|
const FcChar8 *lang;
|
||||||
const char *elt = 0, *eltlang = 0;
|
const char *elt = 0, *eltlang = 0;
|
||||||
int *np = 0, *nlangp = 0;
|
int *np = 0, *nlangp = 0;
|
||||||
|
@ -1401,9 +1469,13 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
|
||||||
lookupid = instance->strid;
|
lookupid = instance->strid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FcFreeTypeGetName (face, platform, lookupid, &sname))
|
nameidx = FcFreeTypeGetFirstName (face, platform, lookupid,
|
||||||
|
name_mapping, name_count,
|
||||||
|
&sname);
|
||||||
|
if (nameidx == -1)
|
||||||
continue;
|
continue;
|
||||||
|
do
|
||||||
|
{
|
||||||
switch (nameid) {
|
switch (nameid) {
|
||||||
case TT_NAME_ID_WWS_FAMILY:
|
case TT_NAME_ID_WWS_FAMILY:
|
||||||
case TT_NAME_ID_PREFERRED_FAMILY:
|
case TT_NAME_ID_PREFERRED_FAMILY:
|
||||||
|
@ -1513,7 +1585,12 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
|
||||||
++*np;
|
++*np;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (++nameidx < name_count &&
|
||||||
|
FT_Get_Sfnt_Name (face, name_mapping[nameidx].idx, &sname) == 0 &&
|
||||||
|
platform == sname.platform_id && lookupid == sname.name_id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
free (name_mapping);
|
||||||
|
|
||||||
if (!nfamily && face->family_name &&
|
if (!nfamily && face->family_name &&
|
||||||
FcStrCmpIgnoreBlanksAndCase ((FcChar8 *) face->family_name, (FcChar8 *) "") != 0)
|
FcStrCmpIgnoreBlanksAndCase ((FcChar8 *) face->family_name, (FcChar8 *) "") != 0)
|
||||||
|
|
Loading…
Reference in New Issue