Table of Contents

Class FontFamily

Namespace
SharpDX.DirectWrite
Assembly
SharpDX.Direct2D1.dll
[Guid("da20d8ef-812a-4c43-9802-62ec4abd7add")]
public class FontFamily : FontList
Inheritance
FontFamily
Derived
Inherited Members

Constructors

FontFamily(nint)

public FontFamily(nint nativePtr)

Parameters

nativePtr nint

Properties

FamilyNames

Creates a localized strings object that contains the family names for the font family, indexed by locale name.

public LocalizedStrings FamilyNames { get; }

Property Value

LocalizedStrings

Remarks

The following code example shows how to get the font family name from a FontFamily object.

LocalizedStrings* pFamilyNames = null; // Get a list of localized strings for the family name.
if (SUCCEEDED(hr))
{ hr = pFontFamily->GetFamilyNames(&pFamilyNames);
} UINT32 index = 0;
SharpDX.Mathematics.Interop.RawBool exists = false; wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; if (SUCCEEDED(hr))
{ // Get the default locale for this user. int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH); // If the default locale is returned, find that locale name, otherwise use "en-us". if (defaultLocaleSuccess) { hr = pFamilyNames->FindLocaleName(localeName, &index, &exists); } if (SUCCEEDED(hr) & & !exists) // if the above find did not find a match, retry with US English { hr = pFamilyNames->FindLocaleName(L"en-us", &index, &exists); }
} // If the specified locale doesn't exist, select the first on the list.
if (!exists) index = 0; UINT32 length = 0; // Get the string length.
if (SUCCEEDED(hr))
{ hr = pFamilyNames->GetStringLength(index, &length);
} // Allocate a string big enough to hold the name.
wchar_t* name = new (std::nothrow) wchar_t[length+1];
if (name == null)
{ hr = E_OUTOFMEMORY;
} // Get the family name.
if (SUCCEEDED(hr))
{ hr = pFamilyNames->GetString(index, name, length+1);
}

Methods

GetFirstMatchingFont(FontWeight, FontStretch, FontStyle)

Gets the font that best matches the specified properties.

public Font GetFirstMatchingFont(FontWeight weight, FontStretch stretch, FontStyle style)

Parameters

weight FontWeight

A value that is used to match a requested font weight.

stretch FontStretch

A value that is used to match a requested font stretch.

style FontStyle

A value that is used to match a requested font style.

Returns

Font

When this method returns, contains the address of a reference to the newly created Font object.

GetMatchingFonts(FontWeight, FontStretch, FontStyle)

Gets a list of fonts in the font family ranked in order of how well they match the specified properties.

public FontList GetMatchingFonts(FontWeight weight, FontStretch stretch, FontStyle style)

Parameters

weight FontWeight

A value that is used to match a requested font weight.

stretch FontStretch

A value that is used to match a requested font stretch.

style FontStyle

A value that is used to match a requested font style.

Returns

FontList

An address of a reference to the newly created FontList object.

Operators

explicit operator FontFamily(nint)

public static explicit operator FontFamily(nint nativePtr)

Parameters

nativePtr nint

Returns

FontFamily