Skip to content

Commit 925710e

Browse files
committed
Better support fonts that report uneven weight
1 parent 2ed09a1 commit 925710e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/FontDescriptor.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,26 @@ enum FontWidth {
3636
FontWidthUltraExpanded = 9
3737
};
3838

39+
inline FontWeight resolve_font_weight(FT_UShort weight) {
40+
if (weight == 0) return FontWeightUndefined;
41+
if (weight < 150) return FontWeightThin;
42+
if (weight < 250) return FontWeightUltraLight;
43+
if (weight < 350) return FontWeightLight;
44+
if (weight < 450) return FontWeightNormal;
45+
if (weight < 550) return FontWeightMedium;
46+
if (weight < 650) return FontWeightSemiBold;
47+
if (weight < 750) return FontWeightBold;
48+
if (weight < 850) return FontWeightUltraBold;
49+
return FontWeightHeavy;
50+
}
51+
3952
inline FontWeight get_font_weight(FT_Face face) {
4053
void* table = FT_Get_Sfnt_Table(face, FT_SFNT_OS2);
4154
if (table == NULL) {
4255
return FontWeightUndefined;
4356
}
4457
TT_OS2* os2_table = (TT_OS2*) table;
45-
return (FontWeight) os2_table->usWeightClass;
58+
return resolve_font_weight(os2_table->usWeightClass);
4659
}
4760

4861
inline FontWidth get_font_width(FT_Face face) {

0 commit comments

Comments
 (0)