Construct fullname from family and style

OpenType spec says that the Regular descriptor would generally be
omitted from fullname. but some fonts doesn't follow on it.

So decided to construct a fullname from family and style instead of
relying on the meta data in a font.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/208
This commit is contained in:
Akira TAGOH 2020-02-04 15:34:42 +09:00
parent 76f88e780a
commit 0f9040406c
1 changed files with 11 additions and 28 deletions

View File

@ -1133,12 +1133,10 @@ static const FT_UShort platform_order[] = {
static const FT_UShort nameid_order[] = { static const FT_UShort nameid_order[] = {
TT_NAME_ID_WWS_FAMILY, TT_NAME_ID_WWS_FAMILY,
TT_NAME_ID_PREFERRED_FAMILY, TT_NAME_ID_TYPOGRAPHIC_FAMILY,
TT_NAME_ID_FONT_FAMILY, TT_NAME_ID_FONT_FAMILY,
TT_NAME_ID_MAC_FULL_NAME,
TT_NAME_ID_FULL_NAME,
TT_NAME_ID_WWS_SUBFAMILY, TT_NAME_ID_WWS_SUBFAMILY,
TT_NAME_ID_PREFERRED_SUBFAMILY, TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY,
TT_NAME_ID_FONT_SUBFAMILY, TT_NAME_ID_FONT_SUBFAMILY,
TT_NAME_ID_TRADEMARK, TT_NAME_ID_TRADEMARK,
TT_NAME_ID_MANUFACTURER, TT_NAME_ID_MANUFACTURER,
@ -1272,8 +1270,6 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
int nfamily_lang = 0; int nfamily_lang = 0;
int nstyle = 0; int nstyle = 0;
int nstyle_lang = 0; int nstyle_lang = 0;
int nfullname = 0;
int nfullname_lang = 0;
unsigned int p, n; unsigned int p, n;
FcChar8 *style = 0; FcChar8 *style = 0;
@ -1495,8 +1491,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
* and treat the instance's nameid as FONT_SUBFAMILY. * and treat the instance's nameid as FONT_SUBFAMILY.
* Postscript name is automatically handled by FreeType. */ * Postscript name is automatically handled by FreeType. */
if (nameid == TT_NAME_ID_WWS_SUBFAMILY || if (nameid == TT_NAME_ID_WWS_SUBFAMILY ||
nameid == TT_NAME_ID_PREFERRED_SUBFAMILY || nameid == TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY)
nameid == TT_NAME_ID_FULL_NAME)
continue; continue;
if (nameid == TT_NAME_ID_FONT_SUBFAMILY) if (nameid == TT_NAME_ID_FONT_SUBFAMILY)
@ -1512,7 +1507,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
{ {
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_TYPOGRAPHIC_FAMILY:
case TT_NAME_ID_FONT_FAMILY: case TT_NAME_ID_FONT_FAMILY:
#if 0 #if 0
case TT_NAME_ID_UNIQUE_ID: case TT_NAME_ID_UNIQUE_ID:
@ -1527,22 +1522,8 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
np = &nfamily; np = &nfamily;
nlangp = &nfamily_lang; nlangp = &nfamily_lang;
break; break;
case TT_NAME_ID_MAC_FULL_NAME:
case TT_NAME_ID_FULL_NAME:
if (variable)
break;
if (FcDebug () & FC_DBG_SCANV)
printf ("found full (n %2d p %d e %d l 0x%04x)",
sname.name_id, sname.platform_id,
sname.encoding_id, sname.language_id);
obj = FC_FULLNAME_OBJECT;
objlang = FC_FULLNAMELANG_OBJECT;
np = &nfullname;
nlangp = &nfullname_lang;
break;
case TT_NAME_ID_WWS_SUBFAMILY: case TT_NAME_ID_WWS_SUBFAMILY:
case TT_NAME_ID_PREFERRED_SUBFAMILY: case TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY:
case TT_NAME_ID_FONT_SUBFAMILY: case TT_NAME_ID_FONT_SUBFAMILY:
if (variable) if (variable)
break; break;
@ -1686,7 +1667,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
} }
/* Add the fullname into the cache */ /* Add the fullname into the cache */
if (!variable && !nfullname) if (!variable)
{ {
FcChar8 *family, *style, *lang; FcChar8 *family, *style, *lang;
int n = 0; int n = 0;
@ -1728,8 +1709,11 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
memcpy (style, &style[i], len - i); memcpy (style, &style[i], len - i);
FcStrBufInit (&sbuf, NULL, 0); FcStrBufInit (&sbuf, NULL, 0);
FcStrBufString (&sbuf, family); FcStrBufString (&sbuf, family);
if (FcStrCmpIgnoreBlanksAndCase(style, (const FcChar8 *) "Regular") != 0)
{
FcStrBufChar (&sbuf, ' '); FcStrBufChar (&sbuf, ' ');
FcStrBufString (&sbuf, style); FcStrBufString (&sbuf, style);
}
if (!FcPatternObjectAddString (pat, FC_FULLNAME_OBJECT, FcStrBufDoneStatic (&sbuf))) if (!FcPatternObjectAddString (pat, FC_FULLNAME_OBJECT, FcStrBufDoneStatic (&sbuf)))
{ {
FcStrBufDestroy (&sbuf); FcStrBufDestroy (&sbuf);
@ -1738,7 +1722,6 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
FcStrBufDestroy (&sbuf); FcStrBufDestroy (&sbuf);
if (!FcPatternObjectAddString (pat, FC_FULLNAMELANG_OBJECT, (const FcChar8 *) "en")) if (!FcPatternObjectAddString (pat, FC_FULLNAMELANG_OBJECT, (const FcChar8 *) "en"))
goto bail1; goto bail1;
++nfullname;
} }
/* Add the PostScript name into the cache */ /* Add the PostScript name into the cache */
if (!variable) if (!variable)