Share via


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

El método PrivateFontCollection::AddFontFile agrega un archivo de fuente a esta colección de fuentes privada.

Sintaxis

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

Parámetros

[in] filename

Tipo: const WCHAR*

Puntero a una cadena de caracteres anchos que especifica el nombre de un archivo de fuente.

Valor devuelto

Tipo: Estado

Si el método se realiza correctamente, devuelve Ok, que es un elemento de la enumeración Status .

Si se produce un error en el método, devuelve uno de los otros elementos de la enumeración Status .

Comentarios

Al usar la API de GDI+, nunca debe permitir que la aplicación descargue fuentes arbitrarias de orígenes que no son de confianza. El sistema operativo requiere privilegios elevados para asegurarse de que todas las fuentes instaladas son de confianza.

Ejemplos

En el ejemplo siguiente se crea un objeto PrivateFontCollection y se agregan tres archivos de fuente a la colección. A continuación, el código obtiene las familias de fuentes que se encuentran en la colección y, para cada familia de la colección, crea una fuente que se usa para dibujar 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 compatible Windows XP, Windows 2000 Professional [solo aplicaciones de escritorio]
Servidor mínimo compatible Windows 2000 Server [solo aplicaciones de escritorio]
Plataforma de destino Windows
Encabezado gdiplusheaders.h (include Gdiplus.h)
Library Gdiplus.lib
Archivo DLL Gdiplus.dll

Consulte también

Creación de una colección de fuentes privadas

InstalledFontCollection

PrivateFontCollection

Uso de texto y fuentes