Hello, Welcome to Micorosoft Q&A,
How can I get a list of the available font weights and styles for a font family?
Currently, there is no such api could load font weights and styles directly, derive from SharpDx.Direct2D1
api, you could get system font collection with GetSystemFontCollection
method. then get each font where in above fontFamily. by chance Font
class contain font weights and styles. For more please refer the following code.
public void GetFontLibrary()
{
SharpDX.DirectWrite.Factory factory = new SharpDX.DirectWrite.Factory();
var fontCollection = factory.GetSystemFontCollection(false);
var familCount = fontCollection.FontFamilyCount;
for (int i = 0; i < familCount; i++)
{
var fontFamily = fontCollection.GetFontFamily(i);
var familyNames = fontFamily.FamilyNames;
var fontfacelist = new List<string>();
var fontface = new List<string>();
for (int j = 0; j < fontFamily.FontCount; j++)
{
var font = fontFamily.GetFont(j);
fontface.Add($"{font.Weight},{ font.Style}");
Debug.WriteLine($"{font.Weight},{ font.Style}");
}
int index;
if (!familyNames.FindLocaleName(CultureInfo.CurrentCulture.Name, out index))
{
if (!familyNames.FindLocaleName("en-us", out index))
{
index = 0;
}
}
string name = familyNames.GetString(index);
}
}
Please note, that can't make sure the result were same as system setting page.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.