]> granicus.if.org Git - libass/commitdiff
font: add function to get the actual weight of a font face
authorRodger Combs <rodger.combs@gmail.com>
Fri, 12 Oct 2018 05:22:53 +0000 (00:22 -0500)
committerOleg Oshmyan <chortos@inbox.lv>
Thu, 26 Sep 2019 13:48:42 +0000 (16:48 +0300)
libass/ass_font.c
libass/ass_font.h

index 480d5f9833ba7aa78467272fbf1aa07b0bf9f9ce..d2fd76df45c3f1ea6c62101b8658c27f9fc2314a 100644 (file)
@@ -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.
  **/
index 9bf418d8af4d3e29a56b1afa842fd2e950ae51c5..05b776be4873a42df178270d13d2be9395126303 100644 (file)
@@ -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,