IDWriteFontCollection 인터페이스(dwrite.h)

시스템에 설치된 글꼴 집합 또는 특정 디렉터리의 글꼴 집합과 같은 글꼴 집합을 캡슐화하는 개체입니다. 글꼴 컬렉션 API를 사용하여 사용할 수 있는 글꼴 패밀리 및 글꼴을 검색하고 글꼴에 대한 일부 메타데이터를 가져올 수 있습니다.

상속

IDWriteFontCollection 인터페이스는 IUnknown 인터페이스에서 상속됩니다. IDWriteFontCollection 에는 다음과 같은 유형의 멤버도 있습니다.

메서드

IDWriteFontCollection 인터페이스에는 이러한 메서드가 있습니다.

 
IDWriteFontCollection::FindFamilyName

지정된 패밀리 이름을 사용하여 글꼴 패밀리를 찾습니다.
IDWriteFontCollection::GetFontFamily

0부터 시작하는 글꼴 패밀리 인덱스가 지정된 글꼴 패밀리 개체를 만듭니다.
IDWriteFontCollection::GetFontFamilyCount

컬렉션의 글꼴 패밀리 수를 가져옵니다.
IDWriteFontCollection::GetFontFromFontFace

지정된 글꼴 얼굴 개체와 동일한 실제 글꼴에 해당하는 글꼴 개체를 가져옵니다. 지정한 실제 글꼴이 글꼴 컬렉션에 속해야 합니다.

설명

IDWriteFactory::GetSystemFontCollection 메서드는 다음 코드 예제와 같이 시스템에 설치된 글꼴 집합을 캡슐화하는 IDWriteFontCollection 개체를 제공합니다.

IDWriteFontCollection* pFontCollection = NULL;

// Get the system font collection.
if (SUCCEEDED(hr))
{
    hr = pDWriteFactory->GetSystemFontCollection(&pFontCollection);
}

IDWriteTextFormatIDWriteTextLayout 에는 개체에서 사용하는 글꼴 컬렉션을 반환하는 GetFontCollection 메서드가 있습니다. 이러한 인터페이스는 기본적으로 시스템 글꼴 컬렉션을 사용하지만 대신 사용자 지정 글꼴 컬렉션을 사용할 수 있습니다.

시스템에서 사용할 수 있는 글꼴을 확인하려면 시스템 글꼴 컬렉션에 대한 참조를 가져옵니다. 그런 다음 IDWriteFontCollection::GetFontFamilyCount 메서드를 사용하여 글꼴 수를 확인하고 목록을 반복할 수 있습니다. 다음 예제에서는 시스템 글꼴 컬렉션의 글꼴을 열거하고 글꼴 패밀리 이름을 콘솔에 인쇄합니다.


#include <dwrite.h>
#include <string.h>
#include <stdio.h>
#include <new>

// SafeRelease inline function.
template <class T> inline void SafeRelease(T **ppT)
{
    if (*ppT)
    {
        (*ppT)->Release();
        *ppT = NULL;
    }
}

void wmain()
{
    IDWriteFactory* pDWriteFactory = NULL;

    HRESULT hr = DWriteCreateFactory(
            DWRITE_FACTORY_TYPE_SHARED,
            __uuidof(IDWriteFactory),
            reinterpret_cast<IUnknown**>(&pDWriteFactory)
            );

    IDWriteFontCollection* pFontCollection = NULL;

    // Get the system font collection.
    if (SUCCEEDED(hr))
    {
        hr = pDWriteFactory->GetSystemFontCollection(&pFontCollection);
    }

    UINT32 familyCount = 0;

    // Get the number of font families in the collection.
    if (SUCCEEDED(hr))
    {
        familyCount = pFontCollection->GetFontFamilyCount();
    }

    for (UINT32 i = 0; i < familyCount; ++i)
    {
        IDWriteFontFamily* pFontFamily = NULL;

        // Get the font family.
        if (SUCCEEDED(hr))
        {
            hr = pFontCollection->GetFontFamily(i, &pFontFamily);
        }

        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);
        }
        if (SUCCEEDED(hr))
        {
            // Print out the family name.
            wprintf(L"%s\n", name);
        }

        SafeRelease(&pFontFamily);
        SafeRelease(&pFamilyNames);

        delete [] name;
    }

    SafeRelease(&pFontCollection);
    SafeRelease(&pDWriteFactory);
}


요구 사항

요구 사항
지원되는 최소 클라이언트 Windows 7, Windows Vista SP2 및 Windows Vista용 플랫폼 업데이트 [데스크톱 앱 | UWP 앱]
지원되는 최소 서버 Windows Server 2008 R2, Windows Server 2008 SP2 및 Windows Server 2008용 플랫폼 업데이트 [데스크톱 앱 | UWP 앱]
대상 플랫폼 Windows
헤더 dwrite.h