Share via


IDWriteFactory::CreateFontFileReference Method

Creates a font file reference object from a local font file.

Syntax

virtual HRESULT CreateFontFileReference(
  [in]            const WCHAR * filePath,
  [in, optional]  const FILETIME * lastWriteTime,
  [out]           IDWriteFontFile ** fontFile
) = 0;

Parameter

  • filePath [in]
    An array of characters that contains the absolute file path for the font file. Subsequent operations on the constructed object may fail if the user provided filePath doesn't correspond to a valid file on the disk.

  • lastWriteTime [in, optional]
    The last modified time of the input file path. If the parameter is omitted, the function will access the font file to obtain its last write time. You should specify this value to avoid extra disk access. Subsequent operations on the constructed object may fail if the user provided lastWriteTime doesn't match the file on the disk.

  • fontFile [out]
    When this method returns, contains an address of a pointer to the newly created font file reference 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