Freigeben über


IDWriteFactory::CreateFontFace Method

Creates an object that represents a font face.

Syntax

virtual HRESULT CreateFontFace(
  DWRITE_FONT_FACE_TYPE  fontFaceType,
  UINT32  numberOfFiles,
  [in]   const IDWriteFontFile * fontFiles,
  UINT32  faceIndex,
  DWRITE_FONT_SIMULATIONS  fontFaceSimulationFlags,
  [out]  IDWriteFontFace ** fontFace
) = 0;

Parameter

  • fontFaceType
    A value that indicates the type of file format of the font face.

  • numberOfFiles
    The number of font files, in element count, required to represent the font face.

  • fontFiles [in]
    A font file object representing the font face. Because IDWriteFontFace maintains its own references to the input font file objects, you may release them after this call.

  • faceIndex
    The zero-based index of a font face, in cases when the font files contain a collection of font faces. If the font files contain a single face, this value should be zero.

  • fontFaceSimulationFlags
    A value that indicates which, if any, font face simulation flags for algorithmic means of making text bold or italic are applied to the current font face.

  • fontFace [out]
    When this method returns, contains an address of a pointer to the newly created font face object, or NULL in case of failure.

Rückgabewert

Ist Methode erfolgreich, wird "S_OK" zurückgegeben. Andernfalls wird ein HRESULT-Fehlercode zurückgegeben.

Beispiele

The following code example demonstrates creating a font face from a font file's file name.

HRESULT CreateFontFaceFromFontFile(wchar_t* filename, IDWriteFontFace **ppFontFace)
{
    HRESULT hr = S_OK;

    IDWriteFactory* pDWriteFactory = NULL;
    IDWriteFontFace* pFontFace = NULL;
    IDWriteFontFile* pFontFiles = NULL;

    // Create the DirectWrite factory.
    hr = DWriteCreateFactory(
            DWRITE_FACTORY_TYPE_SHARED,
            __uuidof(IDWriteFactory),
            reinterpret_cast<IUnknown**>(&pDWriteFactory)
            );
   
    //Gets a filename from a application directory
    WCHAR fontFolderPath[MAX_PATH];
    UINT curDirLength = GetCurrentDirectory(
        sizeof(fontFolderPath),
        fontFolderPath
        );

    if (curDirLength == 0)
    {
        return E_UNEXPECTED;
    }

    if (SUCCEEDED(hr))
    {
        hr = StringCchCatW(
            fontFolderPath,
            sizeof(fontFolderPath),
            L"\\"
            );
    }

    if (SUCCEEDED(hr))
    {
        hr = StringCchCatW(
            fontFolderPath,
            sizeof(fontFolderPath),
            (STRSAFE_LPCWSTR)filename
            );
    }

    if (SUCCEEDED(hr))
    {
        hr = pDWriteFactory->CreateFontFileReference(
            fontFolderPath,
            NULL,
            &pFontFiles);
    }

    IDWriteFontFile* fontFileArray[] = {pFontFiles};
    
    if (SUCCEEDED(hr))
    {
        hr = pDWriteFactory->CreateFontFace(
            DWRITE_FONT_FACE_TYPE_TRUETYPE,
            1, // file count
            fontFileArray,
            0,
            DWRITE_FONT_SIMULATIONS_NONE,
            &pFontFace
            );
    }

    //Return the pointer to the caller
    *ppFontFace = pFontFace;

    SafeRelease(&pDWriteFactory);
    SafeRelease(&pFontFiles);

    return hr;
}

Anforderungen

Mindestens unterstützter Client

Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista

Mindestens unterstützter Server

Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008

Header

Dwrite.h

Bibliothek

Dwrite.lib

DLL

Dwrite.dll

Siehe auch

IDWriteFactory