From 6d98071cf6c5dbd48660ff8799b1000837600b0e Mon Sep 17 00:00:00 2001 From: Rodger Combs Date: Fri, 12 Oct 2018 00:22:53 -0500 Subject: font: add function to get the actual weight of a font face --- libass/ass_font.c | 17 +++++++++++++++++ libass/ass_font.h | 1 + 2 files changed, 18 insertions(+) diff --git a/libass/ass_font.c b/libass/ass_font.c index 480d5f9..d2fd76d 100644 --- a/libass/ass_font.c +++ b/libass/ass_font.c @@ -302,6 +302,23 @@ void ass_font_set_size(ASS_Font *font, double size) } } +/** + * \brief Get face weight + **/ +int ass_face_get_weight(FT_Face face) +{ +#if FREETYPE_MAJOR > 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR >= 6) + TT_OS2 *os2 = FT_Get_Sfnt_Table(face, FT_SFNT_OS2); +#else + // This old name is still included (as a macro), but deprecated as of 2.6, so avoid using it if we can + TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2); +#endif + if (os2 && os2->version != 0xffff && os2->usWeightClass) + return os2->usWeightClass; + else + return 300 * !!(face->style_flags & FT_STYLE_FLAG_BOLD) + 400; +} + /** * \brief Get maximal font ascender and descender. **/ diff --git a/libass/ass_font.h b/libass/ass_font.h index 9bf418d..05b776b 100644 --- a/libass/ass_font.h +++ b/libass/ass_font.h @@ -61,6 +61,7 @@ void charmap_magic(ASS_Library *library, FT_Face face); ASS_Font *ass_font_new(ASS_Renderer *render_priv, ASS_FontDesc *desc); void ass_face_set_size(FT_Face face, double size); void ass_font_set_size(ASS_Font *font, double size); +int ass_face_get_weight(FT_Face face); void ass_font_get_asc_desc(ASS_Font *font, int face_index, int *asc, int *desc); int ass_font_get_index(ASS_FontSelector *fontsel, ASS_Font *font, -- cgit v1.2.3