Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IDWriteFontFile interface

Represents a font file. Applications such as font managers or font viewers can call IDWriteFontFile::Analyze to find out if a particular file is a font file, and whether it is a font type that is supported by the font system.

Members

The IDWriteFontFile interface inherits from the IUnknown interface. IDWriteFontFile also has these types of members:

Methods

The IDWriteFontFile interface has these methods.

MethodDescription
Analyze

Analyzes a file and returns whether it represents a font, and whether the font type is supported by the font system.

GetLoader

Obtains the file loader associated with a font file object.

GetReferenceKey

Obtains the pointer to the reference key of a font file. The returned pointer is valid until the font file object is released.

 

Examples

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
    UINT curDirLength = GetCurrentDirectory(
        MAX_PATH,
        fontFolderPath
        );

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

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

    if (SUCCEEDED(hr))
    {
        hr = StringCchCatW(
            fontFolderPath,
            MAX_PATH,
            (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;
}



Requirements

Minimum supported client

Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Header

Dwrite.h

Library

Dwrite.lib

DLL

Dwrite.dll

 

 

Show:
© 2016 Microsoft