[directwrite] Copy font variations when shaping

This commit is contained in:
Khaled Hosny 2025-03-19 16:37:56 +02:00
parent 59aee7f3e8
commit 686503e2e0
2 changed files with 48 additions and 1 deletions

View file

@ -442,6 +442,44 @@ _hb_directwrite_shape (hb_shape_plan_t *shape_plan,
mbstowcs ((wchar_t*) localeName,
hb_language_to_string (buffer->props.language), 20);
/*
* Set up variations.
*/
IDWriteFontFace5 *fontFaceVariations = nullptr;
if (font->num_coords)
{
IDWriteFontFace5 *fontFace5;
if (SUCCEEDED (fontFace->QueryInterface (__uuidof (IDWriteFontFace5), (void **) &fontFace5)))
{
IDWriteFontResource *fontResource;
if (SUCCEEDED (fontFace5->GetFontResource (&fontResource)))
{
hb_vector_t<DWRITE_FONT_AXIS_VALUE> axis_values;
if (likely (axis_values.resize_exact (font->num_coords)))
{
for (unsigned int i = 0; i < font->num_coords; i++)
{
hb_ot_var_axis_info_t info;
unsigned int c = 1;
hb_ot_var_get_axis_infos (font->face, i, &c, &info);
axis_values[i].axisTag = (DWRITE_FONT_AXIS_TAG) hb_uint32_swap (info.tag);
axis_values[i].value = i < font->num_coords ?
hb_clamp (font->design_coords[i], info.min_value, info.max_value) :
info.default_value;
}
if (SUCCEEDED (fontResource->CreateFontFace (DWRITE_FONT_SIMULATIONS::DWRITE_FONT_SIMULATIONS_NONE,
axis_values.arrayZ, axis_values.length, &fontFaceVariations)))
{
fontFace = fontFaceVariations;
}
}
fontResource->Release ();
}
fontFace5->Release ();
}
}
/*
* Set up features.
*/
@ -614,6 +652,9 @@ retry_getglyphs:
delete [] glyphAdvances;
delete [] glyphOffsets;
if (fontFaceVariations)
fontFaceVariations->Release ();
/* Wow, done! */
return true;
}

View file

@ -1,5 +1,11 @@
@font-funcs-=directwrite
../fonts/872d2955d326bd6676a06f66b8238ebbaabc212f.ttf;--shaper=directwrite;U+0628,U+0628,U+0628;[uni0628.fina=2+883|uni0628.medi_High=1+244|uni0628.init_High=0+233]
../fonts/7bbd3175734d5d291e1c15271ec0cbb97b626ebf.ttf;--shaper=directwrite;U+0066,U+0066,U+0069;[f_f_i=0+795]
../fonts/7bbd3175734d5d291e1c15271ec0cbb97b626ebf.ttf;--shaper=directwrite --features=-liga;U+0066,U+0066,U+0069;[f=0+300|f=1+300|i=2+263]
../fonts/7bbd3175734d5d291e1c15271ec0cbb97b626ebf.ttf;--shaper=directwrite;U+0648,U+0628,U+0627;[alef-ar.fina=2+229|beh-ar.init=1+190|waw-ar=0+483]
../fonts/7bbd3175734d5d291e1c15271ec0cbb97b626ebf.ttf;--shaper=directwrite --features=ss01;U+0648,U+0628,U+0627;[alef-ar.fina=2+229|beh-ar.init.LD=1+190|waw-ar=0+400]
../fonts/7bbd3175734d5d291e1c15271ec0cbb97b626ebf.ttf;--shaper=directwrite --features=ss01;U+0648,U+0628,U+0627;[alef-ar.fina=2+229|beh-ar.init.LD=1+190|waw-ar=0+400]
#../fonts/HBTest-VF.ttf;--shaper=directwrite --variations=TEST=491;U+0041;[A=0+496]
#../fonts/HBTest-VF.ttf;--shaper=directwrite --variations=TEST=509;U+0041;[A=0+505]
../fonts/ab40c89624a6104e5d0a2308e448a989302f515b.ttf;--shaper=directwrite --variations=wdth=60;U+0020;[space=0+266]
../fonts/ab40c89624a6104e5d0a2308e448a989302f515b.ttf;--shaper=directwrite --variations=wdth=402;U+0020;[space=0+639]
../fonts/e8691822f6a705e3e9fb48a0405c645b1a036590.ttf;--shaper=directwrite --variations=0001=500;U+002E,U+0065;[period=0+681|e=1+650]