[GX] Support instance weight, width, and style name

This commit is contained in:
Behdad Esfahbod 2015-08-09 09:06:37 +02:00
parent 28f62d1bb8
commit 00c8408c6a
1 changed files with 68 additions and 6 deletions

View File

@ -62,6 +62,7 @@
#include FT_BDF_H #include FT_BDF_H
#include FT_MODULE_H #include FT_MODULE_H
#endif #endif
#include FT_MULTIPLE_MASTERS_H
#include "ftglue.h" #include "ftglue.h"
@ -1172,6 +1173,13 @@ FcFreeTypeQueryFace (const FT_Face face,
FcChar8 *complex_, *foundry_ = NULL; FcChar8 *complex_, *foundry_ = NULL;
const FcChar8 *foundry = 0; const FcChar8 *foundry = 0;
int spacing; int spacing;
/* Support for glyph-variation named-instances. */
FT_MM_Var *master = NULL;
FT_Var_Named_Style *instance = NULL;
double weight_mult = 1.0;
double width_mult = 1.0;
TT_OS2 *os2; TT_OS2 *os2;
#if HAVE_FT_GET_PS_FONT_INFO #if HAVE_FT_GET_PS_FONT_INFO
PS_FontInfoRec psfontinfo; PS_FontInfoRec psfontinfo;
@ -1231,6 +1239,35 @@ FcFreeTypeQueryFace (const FT_Face face,
goto bail1; goto bail1;
} }
if (id >> 16)
{
if (!FT_Get_MM_Var (face, &master))
instance = &master->namedstyle[(id >> 16) - 1];
if (instance)
{
/* Pull out weight and width from named-instance. */
unsigned int i;
for (i = 0; i < master->num_axis; i++)
{
double value = instance->coords[i] / (double) (1 << 16);
//printf ("named-instance, axis %d tag %lx value %g\n", i, master->axis[i].tag, value);
switch (master->axis[i].tag)
{
case FT_MAKE_TAG ('w','g','h','t'):
weight_mult = value;
break;
case FT_MAKE_TAG ('w','d','t','h'):
width_mult = value;
break;
/* TODO optical size! */
}
}
}
}
/* /*
* Get the OS/2 table * Get the OS/2 table
@ -1289,6 +1326,19 @@ FcFreeTypeQueryFace (const FT_Face face,
if (FT_Get_Sfnt_Name (face, snamei, &sname) != 0) if (FT_Get_Sfnt_Name (face, snamei, &sname) != 0)
continue; continue;
if (instance)
{
/* For named-instances, we regular style nameIDs,
* and map the instance's strid to FONT_SUBFAMILY. */
if (sname.name_id == TT_NAME_ID_WWS_SUBFAMILY ||
sname.name_id == TT_NAME_ID_PREFERRED_SUBFAMILY ||
sname.name_id == TT_NAME_ID_FONT_SUBFAMILY)
continue;
if (sname.name_id == instance->strid)
sname.name_id = TT_NAME_ID_FONT_SUBFAMILY;
}
if (sname.name_id != nameid) if (sname.name_id != nameid)
continue; continue;
@ -1428,6 +1478,8 @@ FcFreeTypeQueryFace (const FT_Face face,
printf ("using FreeType family \"%s\"\n", face->family_name); printf ("using FreeType family \"%s\"\n", face->family_name);
if (!FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) face->family_name)) if (!FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) face->family_name))
goto bail1; goto bail1;
if (!FcPatternAddString (pat, FC_STYLELANG, (FcChar8 *) "en"))
goto bail1;
++nfamily; ++nfamily;
} }
@ -1438,6 +1490,8 @@ FcFreeTypeQueryFace (const FT_Face face,
printf ("using FreeType style \"%s\"\n", face->style_name); printf ("using FreeType style \"%s\"\n", face->style_name);
if (!FcPatternAddString (pat, FC_STYLE, (FcChar8 *) face->style_name)) if (!FcPatternAddString (pat, FC_STYLE, (FcChar8 *) face->style_name))
goto bail1; goto bail1;
if (!FcPatternAddString (pat, FC_STYLELANG, (FcChar8 *) "en"))
goto bail1;
++nstyle; ++nstyle;
} }
@ -1583,12 +1637,15 @@ FcFreeTypeQueryFace (const FT_Face face,
if (os2 && os2->version != 0xffff) if (os2 && os2->version != 0xffff)
{ {
weight = FcWeightFromOpenType (os2->usWeightClass); weight = FcWeightFromOpenType ((int) (os2->usWeightClass * weight_mult + .5));
if ((FcDebug() & FC_DBG_SCANV) && weight != -1) if ((FcDebug() & FC_DBG_SCANV) && weight != -1)
printf ("\tos2 weight class %d maps to weight %d\n", printf ("\tos2 weight class %d multiplier %g maps to weight %d\n",
os2->usWeightClass, weight); os2->usWeightClass, weight_mult, weight);
switch (os2->usWidthClass) { /* TODO:
* Add FcWidthFromOpenType and FcWidthToOpenType,
* and apply width_mult post-conversion? */
switch ((int) (os2->usWidthClass * width_mult + .5)) {
case 1: width = FC_WIDTH_ULTRACONDENSED; break; case 1: width = FC_WIDTH_ULTRACONDENSED; break;
case 2: width = FC_WIDTH_EXTRACONDENSED; break; case 2: width = FC_WIDTH_EXTRACONDENSED; break;
case 3: width = FC_WIDTH_CONDENSED; break; case 3: width = FC_WIDTH_CONDENSED; break;
@ -1600,8 +1657,8 @@ FcFreeTypeQueryFace (const FT_Face face,
case 9: width = FC_WIDTH_ULTRAEXPANDED; break; case 9: width = FC_WIDTH_ULTRAEXPANDED; break;
} }
if ((FcDebug() & FC_DBG_SCANV) && width != -1) if ((FcDebug() & FC_DBG_SCANV) && width != -1)
printf ("\tos2 width class %d maps to width %d\n", printf ("\tos2 width class %d multiplier %g maps to width %d\n",
os2->usWidthClass, width); os2->usWidthClass, width_mult, width);
} }
if (os2 && (complex_ = FcFontCapabilities(face))) if (os2 && (complex_ = FcFontCapabilities(face)))
{ {
@ -1881,6 +1938,11 @@ FcFreeTypeQueryFace (const FT_Face face,
if (foundry_) if (foundry_)
free (foundry_); free (foundry_);
if (master)
{
/* TODO: How to free master?! */
}
return pat; return pat;
bail2: bail2: