IDWriteLocalizedStrings interface (dwrite.h)

Represents a collection of strings indexed by locale name.

Inheritance

The IDWriteLocalizedStrings interface inherits from the IUnknown interface. IDWriteLocalizedStrings also has these types of members:

Methods

The IDWriteLocalizedStrings interface has these methods.

 
IDWriteLocalizedStrings::FindLocaleName

Gets the zero-based index of the locale name/string pair with the specified locale name.
IDWriteLocalizedStrings::GetCount

Gets the number of language/string pairs.
IDWriteLocalizedStrings::GetLocaleName

Copies the locale name with the specified index to the specified array. (IDWriteLocalizedStrings.GetLocaleName)
IDWriteLocalizedStrings::GetLocaleNameLength

Gets the length in characters (not including the null terminator) of the locale name with the specified index. (IDWriteLocalizedStrings.GetLocaleNameLength)
IDWriteLocalizedStrings::GetString

Copies the string with the specified index to the specified array. (IDWriteLocalizedStrings.GetString)
IDWriteLocalizedStrings::GetStringLength

Gets the length in characters (not including the null terminator) of the string with the specified index. (IDWriteLocalizedStrings.GetStringLength)

Remarks

The set of strings represented by an IDWriteLocalizedStrings are indexed by a zero based UINT32 number that maps to a locale. The numeric index for a specific locale is retreived by using the FindLocaleName method.

A common use for the IDWriteLocalizedStrings interface is to hold a list of localized font family names created by using the IDWriteFontFamily::GetFamilyNames method. The following example shows how to get the family name for the "en-us" locale.

IDWriteLocalizedStrings* pFamilyNames = NULL;

// Get a list of localized strings for the family name.
if (SUCCEEDED(hr))
{
    hr = pFontFamily->GetFamilyNames(&pFamilyNames);
}

UINT32 index = 0;
BOOL 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);
}

Requirements

Requirement Value
Minimum supported client Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header dwrite.h