31
31
#include FT_STROKER_H
32
32
#include FT_GLYPH_H
33
33
#include FT_TRUETYPE_IDS_H
34
+ #include FT_TRUETYPE_TABLES_H
34
35
#include FT_IMAGE_H
35
36
36
37
/* Enable rendering with color
@@ -306,6 +307,7 @@ struct TTF_Font {
306
307
307
308
// The font style
308
309
TTF_FontStyleFlags style ;
310
+ int weight ;
309
311
int outline ;
310
312
FT_Stroker stroker ;
311
313
@@ -2129,6 +2131,7 @@ TTF_Font *TTF_OpenFontWithProperties(SDL_PropertiesID props)
2129
2131
// Set the default font style
2130
2132
if (existing_font ) {
2131
2133
font -> style = existing_font -> style ;
2134
+ font -> weight = existing_font -> weight ;
2132
2135
font -> outline = existing_font -> outline ;
2133
2136
font -> ft_load_target = existing_font -> ft_load_target ;
2134
2137
font -> enable_kerning = existing_font -> enable_kerning ;
@@ -2137,6 +2140,16 @@ TTF_Font *TTF_OpenFontWithProperties(SDL_PropertiesID props)
2137
2140
font -> outline = 0 ;
2138
2141
font -> ft_load_target = FT_LOAD_TARGET_NORMAL ;
2139
2142
TTF_SetFontKerning (font , true);
2143
+
2144
+ // Retrieve the weight from the OS2 TrueType table
2145
+ const TT_OS2 * os2_table = (const TT_OS2 * )FT_Get_Sfnt_Table (face , FT_SFNT_OS2 );
2146
+ if (os2_table != NULL && os2_table -> usWeightClass != 0 ) {
2147
+ font -> weight = os2_table -> usWeightClass ;
2148
+ } else if (face -> style_flags & FT_STYLE_FLAG_BOLD ) {
2149
+ font -> weight = TTF_FONT_WEIGHT_BOLD ;
2150
+ } else {
2151
+ font -> weight = TTF_FONT_WEIGHT_NORMAL ;
2152
+ }
2140
2153
}
2141
2154
2142
2155
#if TTF_USE_HARFBUZZ
@@ -5794,6 +5807,13 @@ bool TTF_GetFontSDF(const TTF_Font *font)
5794
5807
return font -> render_sdf ;
5795
5808
}
5796
5809
5810
+ int TTF_GetFontWeight (const TTF_Font * font )
5811
+ {
5812
+ TTF_CHECK_FONT (font , -1 );
5813
+
5814
+ return font -> weight ;
5815
+ }
5816
+
5797
5817
void TTF_SetFontWrapAlignment (TTF_Font * font , TTF_HorizontalAlignment align )
5798
5818
{
5799
5819
TTF_CHECK_FONT (font ,);
0 commit comments