PrivateFontCollection::AddFontFile 메서드(gdiplusheaders.h)

PrivateFontCollection::AddFontFile 메서드는 이 개인 글꼴 컬렉션에 글꼴 파일을 추가합니다.

구문

Status AddFontFile(
  [in] const WCHAR *filename
);

매개 변수

[in] filename

형식: const WCHAR*

글꼴 파일의 이름을 지정하는 와이드 문자열에 대한 포인터입니다.

반환 값

형식: 상태

메서드가 성공하면 Status 열거형의 요소인 확인을 반환합니다.

메서드가 실패하면 Status 열거형의 다른 요소 중 하나를 반환합니다.

설명

GDI+ API를 사용하는 경우 애플리케이션이 신뢰할 수 없는 원본에서 임의의 글꼴을 다운로드하도록 허용해서는 안 됩니다. 운영 체제에는 설치된 모든 글꼴을 신뢰할 수 있도록 하기 위해 상승된 권한이 필요합니다.

예제

다음 예제에서는 PrivateFontCollection 개체를 만들고 컬렉션에 세 개의 글꼴 파일을 추가합니다. 그런 다음, 코드는 컬렉션에 있는 글꼴 패밀리를 가져오고 컬렉션의 각 패밀리에 대해 텍스트를 그리는 데 사용되는 글꼴을 만듭니다.

VOID Example_AddFontFile(HDC hdc)
{
   Graphics              graphics(hdc);
   SolidBrush            solidBrush(Color(255, 0, 0, 0));
   INT                   found = 0;
   INT                   count = 0;
   WCHAR                 familyName[50];
   FontFamily*           pFontFamily;
   PrivateFontCollection privateFontCollection;

   // Add three font files to the private collection.
   privateFontCollection.AddFontFile(L"C:\\WINNT\\Fonts\\Arial.ttf");
   privateFontCollection.AddFontFile(L"C:\\WINNT\\Fonts\\Cour.ttf");
   privateFontCollection.AddFontFile(L"C:\\WINNT\\Fonts\\Times.ttf");

   // How many font families are in the private collection?
   count = privateFontCollection.GetFamilyCount();

   // Allocate a buffer to hold the array of FontFamily objects returned by
   // the GetFamilies method.
   pFontFamily = (FontFamily*)malloc(count * sizeof(FontFamily));

   // Get the array of FontFamily objects.
   privateFontCollection.GetFamilies(count, pFontFamily, &found);

   for(INT j = 0; j < found; ++j)
   {
      // Get the font family name.
      pFontFamily[j].GetFamilyName(familyName);
   
      // Pass the family name and the address of the private collection to a
      // Font constructor.
      Font* pFont = new Font(familyName, 16, FontStyleRegular,
                             UnitPixel, &privateFontCollection);

      // Use the font to draw a string.
      graphics.DrawString(
                          L"Hello", 
                          5,          // string length 
                          pFont, 
                          PointF(10.0f, (REAL)j*25), 
                          &solidBrush);

      delete(pFont);
   }

   free(pFontFamily);
}

요구 사항

   
지원되는 최소 클라이언트 Windows XP, Windows 2000 Professional [데스크톱 앱만 해당]
지원되는 최소 서버 Windows 2000 Server[데스크톱 앱만]
대상 플랫폼 Windows
헤더 gdiplusheaders.h(Gdiplus.h 포함)
라이브러리 Gdiplus.lib
DLL Gdiplus.dll

참고 항목

개인 글꼴 컬렉션 만들기

InstalledFontCollection

PrivateFontCollection

텍스트 및 글꼴 사용