Applying font variations to underline position and thickness seems incorrect
Consider the following test program:
#include <freetype/freetype.h>
#include <freetype/ftmm.h>
#include <hb.h>
#include <hb-ot.h>
void
get_ft (char *path, long wght)
{
FT_Library lib;
FT_Face face;
FT_Fixed coord = wght;
FT_Init_FreeType (&lib);
FT_New_Face (lib, path, 0, &face);
printf("FreeType\n");
printf("default\t\tunderline_position=%d\tunderline_thickness=%d\n",
face->underline_position + (face->underline_thickness / 2),
face->underline_thickness);
FT_Set_Var_Design_Coordinates (face, 1, &coord);
printf("wght=%ld\tunderline_position=%d\tunderline_thickness=%d\n",
coord,
face->underline_position + (face->underline_thickness / 2),
face->underline_thickness);
}
void
get_hb (char *path, long wght)
{
hb_blob_t *blob;
hb_face_t *face;
hb_font_t *font;
float coord = wght;
blob = hb_blob_create_from_file (path);
face = hb_face_create (blob, 0);
font = hb_font_create (face);
hb_position_t undo, unds;
printf("HarfBuzz\n");
hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_UNDERLINE_OFFSET, &undo);
hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_UNDERLINE_SIZE, &unds);
printf("default\t\tunderline_position=%d\tunderline_thickness=%d\n", undo, unds);
hb_font_set_var_coords_design (font, &coord, 1);
hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_UNDERLINE_OFFSET, &undo);
hb_ot_metrics_get_position (font, HB_OT_METRICS_TAG_UNDERLINE_SIZE, &unds);
printf("wght=%ld\tunderline_position=%d\tunderline_thickness=%d\n", wght, undo, unds);
}
int
main (int argc, char **argv)
{
long wght = strtol (argv[2], NULL, 10);
get_ft(argv[1], wght);
printf("\n");
get_hb(argv[1], wght);
}
Used with the font Mada.subset.otf, e.g.:
$ cc test.c $(pkg-config --cflags --libs freetype2 harfbuzz) -o test
$ ./test Mada.subset.otf 100
FreeType
default underline_position=-300 underline_thickness=55
wght=100 underline_position=-260 underline_thickness=32
HarfBuzz
default underline_position=-300 underline_thickness=55
wght=100 underline_position=-260 underline_thickness=32
$./test Mada.subset.otf 900
FreeType
default underline_position=-300 underline_thickness=55
wght=900 underline_position=-260 underline_thickness=32
HarfBuzz
default underline_position=-300 underline_thickness=55
wght=900 underline_position=-360 underline_thickness=94
I’m not sure if I’m doing something wrong, but The values reported by FreeType seem to always corresponding to the wght=100, no matter what value I use. HarfBuzz is reporting the values I expect from checking the font.