Método PrivateFontCollection::AddFontFile (gdiplusheaders.h)

O método PrivateFontCollection::AddFontFile adiciona um arquivo de fonte a essa coleção de fontes privadas.

Sintaxe

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

Parâmetros

[in] filename

Tipo: const WCHAR*

Ponteiro para uma cadeia de caracteres largos que especifica o nome de um arquivo de fonte.

Valor retornado

Tipo: Status

Se o método for bem-sucedido, ele retornará Ok, que é um elemento da enumeração Status .

Se o método falhar, ele retornará um dos outros elementos da enumeração Status .

Comentários

Ao usar a API GDI+, você nunca deve permitir que seu aplicativo baixe fontes arbitrárias de fontes não confiáveis. O sistema operacional requer privilégios elevados para garantir que todas as fontes instaladas sejam confiáveis.

Exemplos

O exemplo a seguir cria um objeto PrivateFontCollection e adiciona três arquivos de fonte à coleção. Em seguida, o código obtém as famílias de fontes que estão na coleção e, para cada família na coleção, cria uma fonte que é usada para desenhar texto.

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

Requisitos

   
Cliente mínimo com suporte Windows XP, Windows 2000 Professional [somente aplicativos da área de trabalho]
Servidor mínimo com suporte Windows 2000 Server [somente aplicativos da área de trabalho]
Plataforma de Destino Windows
Cabeçalho gdiplusheaders.h (inclua Gdiplus.h)
Biblioteca Gdiplus.lib
DLL Gdiplus.dll

Confira também

Criar uma coleções de fontes privadas

Installedfontcollection

Privatefontcollection

Usando texto e fontes