GetFontData

3.1

  DWORD GetFontData(hdc, dwTable, dwOffset, lpvBuffer, cbData)    
  HDC hdc; /* handle of device context */
  DWORD dwTable; /* metric table to query */
  DWORD dwOffset; /* offset into table being queried */
  void FAR* lpvBuffer; /* address of buffer for font data */
  DWORD cbData; /* length of data to query */

The GetFontData function retrieves font-metric information from a scalable font file. The information to retrieve is identified by specifying an offset into the font file and the length of the information to return.

Parameters

hdc

Identifies the device context.

dwTable

Specifies the name of the metric table to be returned. This parameter can be one of the metric tables documented in the TrueType Font Files specification, published by Microsoft Corporation. If this parameter is zero, the information is retrieved starting at the beginning of the font file.

dwOffset

Specifies the offset from the beginning of the table at which to begin retrieving information. If this parameter is zero, the information is retrieved starting at the beginning of the table specified by the dwTable parameter. If this value is greater than or equal to the size of the table, GetFontData returns zero.

lpvBuffer

Points to a buffer that will receive the font information. If this value is NULL, the function returns the size of the buffer required for the font data specified in the dwTable parameter.

cbData

Specifies the length, in bytes, of the information to be retrieved. If this parameter is zero, GetFontData returns the size of the data specified in the dwTable parameter.

Return Value

The return value specifies the number of bytes returned in the buffer pointed to by the lpvBuffer parameter, if the function is successful. Otherwise, it is –1.

Comments

An application can sometimes use the GetFontData function to save a TrueType font with a document. To do this, the application determines whether the font can be embedded and then retrieves the entire font file, specifying zero for the dwTable, dwOffset, and cbData parameters.

Applications can determine whether a font can be embedded by checking the
otmfsType
member of the OUTLINETEXTMETRIC structure. If bit 1 of
otmfsType
is set, embedding is not permitted for the font. If bit 1 is clear, the font can be embedded. If bit 2 is set, the embedding is read-only.

If an application attempts to use this function to retrieve information for a non-TrueType font, the GetFontData function returns –1.

Example

The following example retrieves an entire TrueType font file:

HGLOBAL hglb;
DWORD dwSize;
void FAR* lpvBuffer;

dwSize = GetFontData(hdc, NULL, 0L, NULL, 0L); /* get file size   */

hglb = GlobalAlloc(GPTR, dwSize);  /* allocate memory */
lpvBuffer = GlobalLock(hglb);
GetFontData(hdc, NULL, 0L, lpvBuffer, dwSize);  /* retrieve data   */

The following retrieves an entire TrueType font file 4K at a time:

#define SIZE  4096
BYTE Buffer[SIZE];
DWORD dwOffset;
DWORD dwSize;


dwOffset = 0L;
while(dwSize = GetFontData(hdc, NULL, dwOffset, Buffer, SIZE)) {
  .
  . /* process data in buffer */
  .
  dwOffset += dwSize;
}

The following example retrieves a TrueType font table:

HGLOBAL hglb;
DWORD dwSize;
void FAR* lpvBuffer;

LPSTR lpszTable;
DWORD dwTable;

lpszTable = "cmap";
dwTable   = *(LPDWORD) lpszTable;          /* construct DWORD type */

dwSize = GetFontData(hdc, dwTable, 0L, NULL, 0L); /* get table size */

hglb = GlobalAlloc(GPTR, dwSize);                /* allocate memory */
lpvBuffer = GlobalLock(hglb);
GetFontData(hdc, dwTable, 0L, lpvBuffer, dwSize);  /* retrieve data */

See Also

GetOutlineTextMetrics