次の方法で共有


IDWriteFontFamily::GetFamilyNames メソッド

ロケール名でインデックス処理された、フォント ファミリのファミリ名を含むローカライズされた文字列のオブジェクトを作成します。

構文

virtual HRESULT GetFamilyNames(
  [out]  IDWriteLocalizedStrings ** names
) = 0;

パラメーター

  • names [out]
    新しく作成された IDWriteLocalizedStrings オブジェクトへのポインターのアドレス。

戻り値

メソッドが成功した場合は、S_OK が返されます。 それ以外の場合は、エラー コードが返されます。HRESULT.

解説

次の例では、IDWriteFontFamily オブジェクトからフォント ファミリ名を取得する方法を示します。

  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);
}

要件

クライアントの最小要件

Windows 7, Windows Vista SP2 および Windows Vista 用のプラットフォーム更新プログラム

サーバーの最小要件

Windows Server 2008 R2, Windows Server 2008 SP2 および Windows Server 2008 用のプラットフォーム更新プログラム

ヘッダー

Dwrite.h

ライブラリ

Dwrite.lib

DLL

Dwrite.dll

参照

IDWriteFontFamily