I build a text editor and I use DirectWrite
, I want to give the user the option to enable OpenType features
on selected text, but not every font has all the features and many fonts do not at all. My question is how do I know which OpenType features are available in a given font using DirectWrite?
I have tried the following code but the res
always == S_OK
even the font missing the feature:
DWRITE_FONT_FEATURE fontFeature = { DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_7, 1 };
HRESULT res = pTypography->AddFontFeature(fontFeature); // res == S_OK
res = g_pFancyTextLayout->SetTypography(pTypography, range); // res == S_OK
UPDATE:
I have tried the following code with SharpDx
, but the list
always empty, even in Gabriola
font:
public static FontFeatureTag[] GetOpenTypeFeatures(FontFace fontFace)
{
var list = new List<FontFeatureTag>();
foreach (FontFeatureTag tag in System.Enum.GetValues(typeof(FontFeatureTag)))
{
if (fontFace.TryGetFontTable((int)tag, out DataPointer dataPointer, out IntPtr intPtr))
{
list.Add(tag);
}
}
return list.ToArray();
}
I am writing a C# application using SharpDX, however I can understand answers/examples that are provided in C++.
After deep search on Microsoft's documentation about DirectWirte I have manage to find the intended interface for that, by using the TextAnalyzer2.
Notice that DirectWrite adding new features and members for each new TextAnalyzer. It started with TextAnalyzer followed by TextAnalyzer1 and TextAnalyzer2. [You'll find the same evolution on other interfaces of DirectWrite].
So here it is: IDWriteTextAnalyzer2::GetTypographicFeatures
Use the IDWriteTextAnalyzer2 interface - can be found here. Using the GetTypographicFeatures that"Returns a complete list of OpenType features available for a script or font".