add font widths and extend weight from OS/2 table

This commit is contained in:
Keith Packard 2003-03-12 22:16:43 +00:00
parent a8386abc91
commit 81fa16c336
5 changed files with 118 additions and 26 deletions

View File

@ -73,6 +73,7 @@ typedef int FcBool;
#define FC_VERTICAL_LAYOUT "verticallayout" /* Bool (false) */ #define FC_VERTICAL_LAYOUT "verticallayout" /* Bool (false) */
#define FC_AUTOHINT "autohint" /* Bool (false) */ #define FC_AUTOHINT "autohint" /* Bool (false) */
#define FC_GLOBAL_ADVANCE "globaladvance" /* Bool (true) */ #define FC_GLOBAL_ADVANCE "globaladvance" /* Bool (true) */
#define FC_WIDTH "width" /* Int */
#define FC_FILE "file" /* String */ #define FC_FILE "file" /* String */
#define FC_INDEX "index" /* Int */ #define FC_INDEX "index" /* Int */
#define FC_FT_FACE "ftface" /* FT_Face */ #define FC_FT_FACE "ftface" /* FT_Face */
@ -96,16 +97,33 @@ typedef int FcBool;
#define FC_CHAR_HEIGHT "charheight"/* Int */ #define FC_CHAR_HEIGHT "charheight"/* Int */
#define FC_MATRIX "matrix" /* FcMatrix */ #define FC_MATRIX "matrix" /* FcMatrix */
#define FC_WEIGHT_LIGHT 0 #define FC_WEIGHT_THIN 0
#define FC_WEIGHT_EXTRALIGHT 40
#define FC_WEIGHT_ULTRALIGHT FC_WEIGHT_EXTRALIGHT
#define FC_WEIGHT_LIGHT 50
#define FC_WEIGHT_REGULAR 80
#define FC_WEIGHT_NORMAL FC_WEIGHT_REGULAR
#define FC_WEIGHT_MEDIUM 100 #define FC_WEIGHT_MEDIUM 100
#define FC_WEIGHT_DEMIBOLD 180 #define FC_WEIGHT_DEMIBOLD 180
#define FC_WEIGHT_SEMIBOLD FC_WEIGHT_DEMIBOLD
#define FC_WEIGHT_BOLD 200 #define FC_WEIGHT_BOLD 200
#define FC_WEIGHT_EXTRABOLD 205
#define FC_WEIGHT_BLACK 210 #define FC_WEIGHT_BLACK 210
#define FC_SLANT_ROMAN 0 #define FC_SLANT_ROMAN 0
#define FC_SLANT_ITALIC 100 #define FC_SLANT_ITALIC 100
#define FC_SLANT_OBLIQUE 110 #define FC_SLANT_OBLIQUE 110
#define FC_WIDTH_ULTRACONDENSED 50
#define FC_WIDTH_EXTRACONDENSED 63
#define FC_WIDTH_CONDENSED 75
#define FC_WIDTH_SEMICONDENSED 87
#define FC_WIDTH_NORMAL 100
#define FC_WIDTH_SEMIEXPANDED 113
#define FC_WIDTH_EXPANDED 125
#define FC_WIDTH_EXTRAEXPANDED 150
#define FC_WIDTH_ULTRAEXPANDED 200
#define FC_PROPORTIONAL 0 #define FC_PROPORTIONAL 0
#define FC_MONO 100 #define FC_MONO 100
#define FC_CHARCELL 110 #define FC_CHARCELL 110

View File

@ -55,6 +55,9 @@ FcDefaultSubstitute (FcPattern *pattern)
} }
} }
if (FcPatternGet (pattern, FC_WIDTH, 0, &v) == FcResultNoMatch)
FcPatternAddInteger (pattern, FC_WIDTH, FC_WIDTH_NORMAL);
for (i = 0; i < NUM_FC_BOOL_DEFAULTS; i++) for (i = 0; i < NUM_FC_BOOL_DEFAULTS; i++)
if (FcPatternGet (pattern, FcBoolDefaults[i].field, 0, &v) == FcResultNoMatch) if (FcPatternGet (pattern, FcBoolDefaults[i].field, 0, &v) == FcResultNoMatch)
FcPatternAddBool (pattern, FcBoolDefaults[i].field, FcBoolDefaults[i].value); FcPatternAddBool (pattern, FcBoolDefaults[i].field, FcBoolDefaults[i].value);

View File

@ -121,6 +121,7 @@ FcFreeTypeQuery (const FcChar8 *file,
FcPattern *pat; FcPattern *pat;
int slant; int slant;
int weight; int weight;
int width = -1;
int i; int i;
FcCharSet *cs; FcCharSet *cs;
FcLangSet *ls; FcLangSet *ls;
@ -162,16 +163,11 @@ FcFreeTypeQuery (const FcChar8 *file,
if (face->style_flags & FT_STYLE_FLAG_ITALIC) if (face->style_flags & FT_STYLE_FLAG_ITALIC)
slant = FC_SLANT_ITALIC; slant = FC_SLANT_ITALIC;
if (!FcPatternAddInteger (pat, FC_SLANT, slant))
goto bail1;
weight = FC_WEIGHT_MEDIUM; weight = FC_WEIGHT_MEDIUM;
if (face->style_flags & FT_STYLE_FLAG_BOLD) if (face->style_flags & FT_STYLE_FLAG_BOLD)
weight = FC_WEIGHT_BOLD; weight = FC_WEIGHT_BOLD;
if (!FcPatternAddInteger (pat, FC_WEIGHT, weight))
goto bail1;
/* /*
* Grub through the name table looking for family * Grub through the name table looking for family
* and style names. FreeType makes quite a hash * and style names. FreeType makes quite a hash
@ -530,6 +526,54 @@ FcFreeTypeQuery (const FcChar8 *file,
} }
} }
if (os2 && os2->version != 0xffff)
{
if (os2->usWeightClass == 0)
weight = -1;
else if (os2->usWeightClass < 150)
weight = FC_WEIGHT_THIN;
else if (os2->usWeightClass < 250)
weight = FC_WEIGHT_EXTRALIGHT;
else if (os2->usWeightClass < 350)
weight = FC_WEIGHT_LIGHT;
else if (os2->usWeightClass < 450)
weight = FC_WEIGHT_REGULAR;
else if (os2->usWeightClass < 550)
weight = FC_WEIGHT_MEDIUM;
else if (os2->usWeightClass < 650)
weight = FC_WEIGHT_SEMIBOLD;
else if (os2->usWeightClass < 750)
weight = FC_WEIGHT_BOLD;
else if (os2->usWeightClass < 850)
weight = FC_WEIGHT_EXTRABOLD;
else if (os2->usWeightClass < 950)
weight = FC_WEIGHT_BLACK;
else
weight = FC_WEIGHT_MEDIUM;
switch (os2->usWidthClass) {
case 1: width = FC_WIDTH_ULTRACONDENSED; break;
case 2: width = FC_WIDTH_EXTRACONDENSED; break;
case 3: width = FC_WIDTH_CONDENSED; break;
case 4: width = FC_WIDTH_SEMICONDENSED; break;
case 5: width = FC_WIDTH_NORMAL; break;
case 6: width = FC_WIDTH_SEMIEXPANDED; break;
case 7: width = FC_WIDTH_EXPANDED; break;
case 8: width = FC_WIDTH_EXTRAEXPANDED; break;
case 9: width = FC_WIDTH_ULTRAEXPANDED; break;
}
}
if (!FcPatternAddInteger (pat, FC_SLANT, slant))
goto bail1;
if (!FcPatternAddInteger (pat, FC_WEIGHT, weight))
goto bail1;
if (width != -1)
if (!FcPatternAddInteger (pat, FC_WIDTH, width))
goto bail1;
/* /*
* Compute the unicode coverage for the font * Compute the unicode coverage for the font
*/ */

View File

@ -206,20 +206,23 @@ static FcMatcher _FcMatchers [] = {
{ FC_WEIGHT, FcCompareNumber, 9, 9 }, { FC_WEIGHT, FcCompareNumber, 9, 9 },
#define MATCH_WEIGHT 8 #define MATCH_WEIGHT 8
{ FC_ANTIALIAS, FcCompareBool, 10, 10 }, { FC_WIDTH, FcCompareNumber, 10, 10 },
#define MATCH_ANTIALIAS 9 #define MATCH_WIDTH 9
{ FC_RASTERIZER, FcCompareString, 11, 11 }, { FC_ANTIALIAS, FcCompareBool, 11, 11 },
#define MATCH_RASTERIZER 10 #define MATCH_ANTIALIAS 10
{ FC_OUTLINE, FcCompareBool, 12, 12 }, { FC_RASTERIZER, FcCompareString, 12, 12 },
#define MATCH_OUTLINE 11 #define MATCH_RASTERIZER 11
{ FC_FONTVERSION, FcCompareNumber, 13, 13 }, { FC_OUTLINE, FcCompareBool, 13, 13 },
#define MATCH_FONTVERSION 12 #define MATCH_OUTLINE 12
{ FC_FONTVERSION, FcCompareNumber, 14, 14 },
#define MATCH_FONTVERSION 13
}; };
#define NUM_MATCH_VALUES 14 #define NUM_MATCH_VALUES 15
static FcBool static FcBool
FcCompareValueList (const char *object, FcCompareValueList (const char *object,
@ -273,7 +276,13 @@ FcCompareValueList (const char *object,
case 'p': case 'p':
i = MATCH_PIXEL_SIZE; break; i = MATCH_PIXEL_SIZE; break;
case 'w': case 'w':
switch (FcToLower (object[1])) {
case 'i':
i = MATCH_WIDTH; break;
case 'e':
i = MATCH_WEIGHT; break; i = MATCH_WEIGHT; break;
}
break;
case 'r': case 'r':
i = MATCH_RASTERIZER; break; i = MATCH_RASTERIZER; break;
case 'o': case 'o':

View File

@ -33,6 +33,7 @@ static const FcObjectType _FcBaseObjectTypes[] = {
{ FC_STYLE, FcTypeString, }, { FC_STYLE, FcTypeString, },
{ FC_SLANT, FcTypeInteger, }, { FC_SLANT, FcTypeInteger, },
{ FC_WEIGHT, FcTypeInteger, }, { FC_WEIGHT, FcTypeInteger, },
{ FC_WIDTH, FcTypeInteger, },
{ FC_SIZE, FcTypeDouble, }, { FC_SIZE, FcTypeDouble, },
{ FC_ASPECT, FcTypeDouble, }, { FC_ASPECT, FcTypeDouble, },
{ FC_PIXEL_SIZE, FcTypeDouble, }, { FC_PIXEL_SIZE, FcTypeDouble, },
@ -137,16 +138,33 @@ FcNameGetObjectType (const char *object)
} }
static const FcConstant _FcBaseConstants[] = { static const FcConstant _FcBaseConstants[] = {
{ (FcChar8 *) "thin", "weight", FC_WEIGHT_THIN, },
{ (FcChar8 *) "extralight", "weight", FC_WEIGHT_EXTRALIGHT, },
{ (FcChar8 *) "ultralight", "weight", FC_WEIGHT_EXTRALIGHT, },
{ (FcChar8 *) "light", "weight", FC_WEIGHT_LIGHT, }, { (FcChar8 *) "light", "weight", FC_WEIGHT_LIGHT, },
{ (FcChar8 *) "regular", "weight", FC_WEIGHT_REGULAR, },
{ (FcChar8 *) "medium", "weight", FC_WEIGHT_MEDIUM, }, { (FcChar8 *) "medium", "weight", FC_WEIGHT_MEDIUM, },
{ (FcChar8 *) "demibold", "weight", FC_WEIGHT_DEMIBOLD, }, { (FcChar8 *) "demibold", "weight", FC_WEIGHT_DEMIBOLD, },
{ (FcChar8 *) "semibold", "weight", FC_WEIGHT_DEMIBOLD, },
{ (FcChar8 *) "bold", "weight", FC_WEIGHT_BOLD, }, { (FcChar8 *) "bold", "weight", FC_WEIGHT_BOLD, },
{ (FcChar8 *) "extrabold", "weight", FC_WEIGHT_EXTRABOLD, },
{ (FcChar8 *) "ultrabold", "weight", FC_WEIGHT_EXTRABOLD, },
{ (FcChar8 *) "black", "weight", FC_WEIGHT_BLACK, }, { (FcChar8 *) "black", "weight", FC_WEIGHT_BLACK, },
{ (FcChar8 *) "roman", "slant", FC_SLANT_ROMAN, }, { (FcChar8 *) "roman", "slant", FC_SLANT_ROMAN, },
{ (FcChar8 *) "italic", "slant", FC_SLANT_ITALIC, }, { (FcChar8 *) "italic", "slant", FC_SLANT_ITALIC, },
{ (FcChar8 *) "oblique", "slant", FC_SLANT_OBLIQUE, }, { (FcChar8 *) "oblique", "slant", FC_SLANT_OBLIQUE, },
{ (FcChar8 *) "ultracondensed", "width", FC_WIDTH_ULTRACONDENSED },
{ (FcChar8 *) "extracondensed", "width", FC_WIDTH_EXTRACONDENSED },
{ (FcChar8 *) "condensed", "width", FC_WIDTH_CONDENSED },
{ (FcChar8 *) "semicondensed", "width", FC_WIDTH_SEMICONDENSED },
{ (FcChar8 *) "normal", "width", FC_WIDTH_NORMAL },
{ (FcChar8 *) "semiexpanded", "width", FC_WIDTH_SEMIEXPANDED },
{ (FcChar8 *) "expanded", "width", FC_WIDTH_EXPANDED },
{ (FcChar8 *) "extraexpanded", "width", FC_WIDTH_EXTRAEXPANDED },
{ (FcChar8 *) "ultraexpanded", "width", FC_WIDTH_ULTRAEXPANDED },
{ (FcChar8 *) "proportional", "spacing", FC_PROPORTIONAL, }, { (FcChar8 *) "proportional", "spacing", FC_PROPORTIONAL, },
{ (FcChar8 *) "mono", "spacing", FC_MONO, }, { (FcChar8 *) "mono", "spacing", FC_MONO, },
{ (FcChar8 *) "charcell", "spacing", FC_CHARCELL, }, { (FcChar8 *) "charcell", "spacing", FC_CHARCELL, },