3131#include FT_STROKER_H
3232#include FT_GLYPH_H
3333#include FT_TRUETYPE_IDS_H
34+ #include FT_TRUETYPE_TABLES_H
3435#include FT_IMAGE_H
3536
3637/* Enable rendering with color
@@ -306,6 +307,7 @@ struct TTF_Font {
306307
307308 // The font style
308309 TTF_FontStyleFlags style ;
310+ int weight ;
309311 int outline ;
310312 FT_Stroker stroker ;
311313
@@ -2129,6 +2131,7 @@ TTF_Font *TTF_OpenFontWithProperties(SDL_PropertiesID props)
21292131 // Set the default font style
21302132 if (existing_font ) {
21312133 font -> style = existing_font -> style ;
2134+ font -> weight = existing_font -> weight ;
21322135 font -> outline = existing_font -> outline ;
21332136 font -> ft_load_target = existing_font -> ft_load_target ;
21342137 font -> enable_kerning = existing_font -> enable_kerning ;
@@ -2137,6 +2140,16 @@ TTF_Font *TTF_OpenFontWithProperties(SDL_PropertiesID props)
21372140 font -> outline = 0 ;
21382141 font -> ft_load_target = FT_LOAD_TARGET_NORMAL ;
21392142 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+ }
21402153 }
21412154
21422155#if TTF_USE_HARFBUZZ
@@ -5794,6 +5807,13 @@ bool TTF_GetFontSDF(const TTF_Font *font)
57945807 return font -> render_sdf ;
57955808}
57965809
5810+ int TTF_GetFontWeight (const TTF_Font * font )
5811+ {
5812+ TTF_CHECK_FONT (font , -1 );
5813+
5814+ return font -> weight ;
5815+ }
5816+
57975817void TTF_SetFontWrapAlignment (TTF_Font * font , TTF_HorizontalAlignment align )
57985818{
57995819 TTF_CHECK_FONT (font ,);
0 commit comments