BOOL CreateScalableFontResource(fHidden, lpszResourceFile, lpszFontFile, lpszCurrentPath) | |||||
UINT fHidden; | /* flag for read-only embedded font | */ | |||
LPCSTR lpszResourceFile; | /* address of filename of font resource | */ | |||
LPCSTR lpszFontFile; | /* address of filename of scalable font | */ | |||
LPCSTR lpszCurrentPath; | /* address of path to font file | */ |
The CreateScalableFontResource function creates a font resource file for the specified scalable font file.
fHidden
Specifies whether the font is a read-only embedded font. This parameter can be one of the following values:
Value | Meaning |
0 | The font has read-write permission. |
1 | The font has read-only permission and should be hidden from other applications in the system. When this flag is set, the font is not enumerated by the EnumFonts or EnumFontFamilies function. |
lpszResourceFile
Points to a null-terminated string specifying the name of the font resource file that this function creates.
lpszFontFile
Points to a null-terminated string specifying the scalable font file this function uses to create the font resource file. This parameter must specify either the filename and extension or a full path and filename, including drive and filename extension.
lpszCurrentPath
Points to a null-terminated string specifying either the path to the scalable font file specified in the lpszFontFile parameter or NULL, if lpszFontFile specifies a full path.
The return value is nonzero if the function is successful. Otherwise, it is zero.
An application must use the CreateScalableFontResource function to create a font resource file before installing an embedded font. Font resource files for fonts with read-write permission should use the .FOT filename extension. Font resource files for read-only fonts should use a different extension (for example, .FOR) and should be hidden from other applications in the system by specifying 1 for the fHidden parameter. The font resource files can be installed by using the AddFontResource function.
When the lpszFontFile parameter specifies only a filename and extension, the lpszCurrentPath parameter must specify a path. When the lpszFontFile parameter specifies a full path, the lpszCurrentPath parameter must be NULL or a pointer to NULL.
When only a filename and extension is specified in the lpszFontFile parameter and a path is specified in the lpszCurrentPath parameter, the string in lpszFontFile is copied into the .FOT file as the .TTF file that belongs to this resource. When the AddFontResource function is called, the system assumes that the .TTF file has been copied into the SYSTEM directory (or into the main Windows directory in the case of a network installation). The .TTF file need not be in this directory when the CreateScalableFontResource function is called, because the lpszCurrentPath parameter contains the directory information. A resource created in this manner does not contain absolute path information and can be used in any Windows installation.
When a path is specified in the lpszFontFile parameter and NULL is specified in the lpszCurrentPath parameter, the string in lpszFontFile is copied into the .FOT file. In this case, when the AddFontResource function is called, the .TTF file must be at the location specified in the lpszFontFile parameter when the CreateScalableFontResource function was called; the lpszCurrentPath parameter is not needed. A resource created in this manner contains absolute references to paths and drives and will not work if the .TTF file is moved to a different location.
The CreateScalableFontResource function supports only TrueType scalable fonts.
The following example shows how to create a TrueType font file in the SYSTEM directory of the Windows startup directory:
CreateScalableFontResource(0, "c:\\windows\\system\\font.fot",
"font.ttr", "c:\\windows\\system");
AddFontResource("c:\\windows\\system\\font.fot");
The following example shows how to create a TrueType font file in a specified directory:
CreateScalableFontResource(0, "c:\\windows\\system\\font.fot",
"c:\\fontdir\\font.ttr", NULL);
AddFontResource("c:\\windows\\system\\font.fot");
The following example shows how to work with a standard embedded font:
HFONT hfont;
/* Extract .TTF file into C:\MYDIR\FONT.TTR. */
CreateScalableFontResource(0, "font.fot", "c:\\mydir\\font.ttr", NULL);
AddFontResource("font.fot");
hfont = CreateFont(..., CLIP_DEFAULT_PRECIS, ..., "FONT");
.
. /* Use the font. */
.
DeleteObject(hfont);
RemoveFontResource("font.fot");
.
. /* Delete C:\MYDIR\FONT.FOT and C:\MYDIR\FONT.TTR. */
.
The following example shows how to work with a read-only embedded font:
HFONT hfont;
/* Extract.TTF file into C:\MYDIR\FONT.TTR. */
CreateScalableFontResource(1, "font.for", "c:\\mydir\\font.ttr", NULL);
AddFontResource("font.for");
hfont = CreateFont(..., CLIP_EMBEDDED, ..., "FONT");
.
. /* Use the font. */
.
DeleteObject(hfont);
RemoveFontResource("font.for");
.
. /* Delete C:\MYDIR\FONT.FOR and C:\MYDIR\FONT.TTR. */
.