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;
Parameters
- filePath [in]
-
Type: const WCHAR*
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]
-
Type: const FILETIME*
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]
-
Type: IDWriteFontFile**
When this method returns, contains an address of a pointer to the newly created font file reference 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 |
|
|
Library |
|
|
DLL |
|
See also