[font] Load named-instance if face index top bits are set
This matches FreeType behavior.
Fixes https://github.com/harfbuzz/harfbuzz/issues/3348
diff --git a/src/hb-face.cc b/src/hb-face.cc
index 2f6f291..5365598 100644
--- a/src/hb-face.cc
+++ b/src/hb-face.cc
@@ -205,6 +205,10 @@
* is ignored. Otherwise, only the lower 16-bits of @index are used.
* The unmodified @index can be accessed via hb_face_get_index().</note>
*
+ * <note>Note: The high 16-bits of @index, if non-zero, are used by
+ * hb_font_create() to load named-instances in variable fonts. See
+ * hb_font_create() for details.</note>
+ *
* Return value: (transfer full): The new face object
*
* Since: 0.9.2
diff --git a/src/hb-font.cc b/src/hb-font.cc
index fa8da96..d1cb349 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -1521,6 +1521,13 @@
*
* Constructs a new font object from the specified face.
*
+ * <note>Note: If @face's index value (as passed to hb_face_create()
+ * has non-zero top 16-bits, those bits minus one are passed to
+ * hb_font_set_var_named_instance(), effectively loading a named-instance
+ * of a variable font, instead of the default-instance. This allows
+ * specifying which named-instance to load by default when creating the
+ * face.</note>
+ *
* Return value: (transfer full): The new font object
*
* Since: 0.9.2
@@ -1535,6 +1542,9 @@
hb_ot_font_set_funcs (font);
#endif
+ if (face && face->index >> 16)
+ hb_font_set_var_named_instance (font, (face->index >> 16) - 1);
+
return font;
}