[var] Add a new API, hb_font_set_var_named_instance
This commit is contained in:
parent
b6a2281f1a
commit
40a4b6ddbd
|
@ -342,6 +342,7 @@ hb_font_set_user_data
|
||||||
hb_font_set_variations
|
hb_font_set_variations
|
||||||
hb_font_set_var_coords_design
|
hb_font_set_var_coords_design
|
||||||
hb_font_set_var_coords_normalized
|
hb_font_set_var_coords_normalized
|
||||||
|
hb_font_set_var_named_instance
|
||||||
hb_font_subtract_glyph_origin_for_direction
|
hb_font_subtract_glyph_origin_for_direction
|
||||||
hb_font_t
|
hb_font_t
|
||||||
hb_reference_table_func_t
|
hb_reference_table_func_t
|
||||||
|
|
|
@ -1861,6 +1861,7 @@ hb_font_set_variations (hb_font_t *font,
|
||||||
normalized, coords_length);
|
normalized, coords_length);
|
||||||
_hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
|
_hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hb_font_set_var_coords_design:
|
* hb_font_set_var_coords_design:
|
||||||
*
|
*
|
||||||
|
@ -1881,6 +1882,33 @@ hb_font_set_var_coords_design (hb_font_t *font,
|
||||||
hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
|
hb_ot_var_normalize_coords (font->face, coords_length, coords, normalized);
|
||||||
_hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
|
_hb_font_adopt_var_coords_normalized (font, normalized, coords_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hb_font_set_var_named_instance:
|
||||||
|
* @font: a font.
|
||||||
|
* @instance_index: named instance index.
|
||||||
|
*
|
||||||
|
* Sets design coords of a font from a named instance index.
|
||||||
|
*
|
||||||
|
* Since: REPLACEME
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
hb_font_set_var_named_instance (hb_font_t *font,
|
||||||
|
unsigned instance_index)
|
||||||
|
{
|
||||||
|
if (hb_object_is_immutable (font))
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned int coords_length = hb_ot_var_named_instance_get_design_coords (font->face, instance_index, nullptr, nullptr);
|
||||||
|
|
||||||
|
float *coords = coords_length ? (float *) calloc (coords_length, sizeof (float)) : nullptr;
|
||||||
|
if (unlikely (coords_length && !coords))
|
||||||
|
return;
|
||||||
|
|
||||||
|
hb_ot_var_named_instance_get_design_coords (font->face, instance_index, &coords_length, coords);
|
||||||
|
hb_font_set_var_coords_design (font, coords, coords_length);
|
||||||
|
free (coords);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -705,6 +705,10 @@ HB_EXTERN const int *
|
||||||
hb_font_get_var_coords_normalized (hb_font_t *font,
|
hb_font_get_var_coords_normalized (hb_font_t *font,
|
||||||
unsigned int *length);
|
unsigned int *length);
|
||||||
|
|
||||||
|
HB_EXTERN void
|
||||||
|
hb_font_set_var_named_instance (hb_font_t *font,
|
||||||
|
unsigned instance_index);
|
||||||
|
|
||||||
HB_END_DECLS
|
HB_END_DECLS
|
||||||
|
|
||||||
#endif /* HB_FONT_H */
|
#endif /* HB_FONT_H */
|
||||||
|
|
|
@ -184,6 +184,37 @@ test_extents_cff2_vsindex (void)
|
||||||
hb_font_destroy (font);
|
hb_font_destroy (font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_extents_cff2_vsindex_named_instance (void)
|
||||||
|
{
|
||||||
|
hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype_vsindex.otf");
|
||||||
|
g_assert (face);
|
||||||
|
hb_font_t *font = hb_font_create (face);
|
||||||
|
hb_face_destroy (face);
|
||||||
|
g_assert (font);
|
||||||
|
hb_ot_font_set_funcs (font);
|
||||||
|
|
||||||
|
hb_font_set_var_named_instance (font, 6); // 6 (BlackMediumContrast): 900, 50
|
||||||
|
hb_glyph_extents_t extents;
|
||||||
|
hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
|
||||||
|
g_assert (result);
|
||||||
|
|
||||||
|
g_assert_cmpint (extents.x_bearing, ==, 12);
|
||||||
|
g_assert_cmpint (extents.y_bearing, ==, 652);
|
||||||
|
g_assert_cmpint (extents.width, ==, 653);
|
||||||
|
g_assert_cmpint (extents.height, ==, -652);
|
||||||
|
|
||||||
|
result = hb_font_get_glyph_extents (font, 2, &extents);
|
||||||
|
g_assert (result);
|
||||||
|
|
||||||
|
g_assert_cmpint (extents.x_bearing, ==, 6);
|
||||||
|
g_assert_cmpint (extents.y_bearing, ==, 675);
|
||||||
|
g_assert_cmpint (extents.width, ==, 647);
|
||||||
|
g_assert_cmpint (extents.height, ==, -675);
|
||||||
|
|
||||||
|
hb_font_destroy (font);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -194,6 +225,7 @@ main (int argc, char **argv)
|
||||||
hb_test_add (test_extents_cff1_seac);
|
hb_test_add (test_extents_cff1_seac);
|
||||||
hb_test_add (test_extents_cff2);
|
hb_test_add (test_extents_cff2);
|
||||||
hb_test_add (test_extents_cff2_vsindex);
|
hb_test_add (test_extents_cff2_vsindex);
|
||||||
|
hb_test_add (test_extents_cff2_vsindex_named_instance);
|
||||||
|
|
||||||
return hb_test_run ();
|
return hb_test_run ();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue