]> git.eshelyaron.com Git - emacs.git/commitdiff
Properly detect medium fonts
authorPo Lu <luangruo@yahoo.com>
Thu, 24 Aug 2023 01:08:11 +0000 (09:08 +0800)
committerPo Lu <luangruo@yahoo.com>
Thu, 24 Aug 2023 01:08:11 +0000 (09:08 +0800)
* src/sfntfont.c (sfnt_decode_family_style): Refer to the
preferred family and subfamily if present.

src/sfntfont.c

index e2dfdaff3b657b07b7128c5de5a64ed65590728c..f2dc05c886ed25bc4933f2056df020583b1a7c4f 100644 (file)
@@ -322,11 +322,30 @@ sfnt_decode_family_style (struct sfnt_name_table *name,
   struct sfnt_name_record family_rec, style_rec;
   unsigned char *family_data, *style_data;
 
-  family_data = sfnt_find_name (name, SFNT_NAME_FONT_FAMILY,
+  /* Because MS-Windows is incapable of treating font families
+     comprising more than four styles correctly, the TrueType
+     specification incorporates additional PREFERRED_FAMILY and
+     PREFERRED_SUBFAMILY name resources that are meant to be consulted
+     over the traditional family and subfamily resources.  When
+     present within fonts supplying unusual styles, these names hold
+     the ``actual'' typographic family and style of the font, in lieu
+     of the font family with the style affixed to the front and
+     Regular.  */
+
+  family_data = sfnt_find_name (name, SFNT_NAME_PREFERRED_FAMILY,
                                &family_rec);
-  style_data = sfnt_find_name (name, SFNT_NAME_FONT_SUBFAMILY,
+
+  if (!family_data)
+    family_data = sfnt_find_name (name, SFNT_NAME_FONT_FAMILY,
+                                 &family_rec);
+
+  style_data = sfnt_find_name (name, SFNT_NAME_PREFERRED_SUBFAMILY,
                               &style_rec);
 
+  if (!style_data)
+    style_data = sfnt_find_name (name, SFNT_NAME_FONT_SUBFAMILY,
+                                &style_rec);
+
   if (!family_data || !style_data)
     return 1;