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.

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;

Parameters

fontFaceType

Type: DWRITE_FONT_FACE_TYPE

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

numberOfFiles

Type: UINT32

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

fontFiles [in]

Type: const IDWriteFontFile*

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

Type: UINT32

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

Type: DWRITE_FONT_SIMULATIONS

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]

Type: IDWriteFontFace**

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

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

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

See also

IDWriteFactory

 

 

Show:
© 2017 Microsoft