is there any way to get the facename from a TTF file ?
-
CString ReadLongName(const char *pszFile)
{
CString csOutName;
static char lpszLongName[256];
unsigned i;
char namebuf[255];
FILE* fp;
unsigned short numNames;
long curseek;
unsigned cTables;
sfnt_OffsetTable OffsetTable;
sfnt_DirectoryEntry Table;
sfnt_NamingTable NamingTable;
sfnt_NameRecord NameRecord;lpszLongName\[0\] = '\\0'; if ((fp = fopen (pszFile, "rb")) == NULL) { return csOutName; } /\* First off, read the initial directory header on the TTF. We're only \* interested in the "numOffsets" variable to tell us how many tables \* are present in this file. \* \* Remember to always convert from Motorola format (Big Endian to \* Little Endian). \*/ fread (&OffsetTable, 1, sizeof (OffsetTable) - sizeof(sfnt\_DirectoryEntry), fp); cTables = (int) SWAPW (OffsetTable.numOffsets); for ( i = 0; i < cTables && i < 40; i++) { if ((fread (&Table, 1, sizeof (Table), fp)) != sizeof(Table)) { return csOutName; } if (Table.tag == tag\_NamingTable) /\* defined in sfnt\_en.h \*/ { /\* Now that we've found the entry for the name table, seek to that \* position in the file and read in the initial header for this \* particular table. See "True Type Font Files" for information \* on this record layout. \*/ fseek (fp, SWAPL (Table.offset), SEEK\_SET); fread (&NamingTable, 1, sizeof (NamingTable), fp); numNames = SWAPW(NamingTable.count); while (numNames--) { fread (&NameRecord, 1, sizeof (NameRecord), fp); curseek = ftell(fp); if (SWAPW(NameRecord.platformID) == 1 && SWAPW(NameRecord.nameID) == 4) { fseek (fp, SWAPW (NameRecord.offset) + SWAPW(NamingTable.stringOffset) + SWAPL(Table.offset), SEEK\_SET); fread (&namebuf, 1, SWAPW(NameRecord.length), fp); namebuf\[SWAPW(NameRecord.length)\] = '\\0'; lstrcpy(lpszLongName,namebuf); fseek (fp, curseek, SEEK\_SET); csOutName = lpszLongName; } } break; } } fclose (fp); return csOutName;
}
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
-
CString ReadLongName(const char *pszFile)
{
CString csOutName;
static char lpszLongName[256];
unsigned i;
char namebuf[255];
FILE* fp;
unsigned short numNames;
long curseek;
unsigned cTables;
sfnt_OffsetTable OffsetTable;
sfnt_DirectoryEntry Table;
sfnt_NamingTable NamingTable;
sfnt_NameRecord NameRecord;lpszLongName\[0\] = '\\0'; if ((fp = fopen (pszFile, "rb")) == NULL) { return csOutName; } /\* First off, read the initial directory header on the TTF. We're only \* interested in the "numOffsets" variable to tell us how many tables \* are present in this file. \* \* Remember to always convert from Motorola format (Big Endian to \* Little Endian). \*/ fread (&OffsetTable, 1, sizeof (OffsetTable) - sizeof(sfnt\_DirectoryEntry), fp); cTables = (int) SWAPW (OffsetTable.numOffsets); for ( i = 0; i < cTables && i < 40; i++) { if ((fread (&Table, 1, sizeof (Table), fp)) != sizeof(Table)) { return csOutName; } if (Table.tag == tag\_NamingTable) /\* defined in sfnt\_en.h \*/ { /\* Now that we've found the entry for the name table, seek to that \* position in the file and read in the initial header for this \* particular table. See "True Type Font Files" for information \* on this record layout. \*/ fseek (fp, SWAPL (Table.offset), SEEK\_SET); fread (&NamingTable, 1, sizeof (NamingTable), fp); numNames = SWAPW(NamingTable.count); while (numNames--) { fread (&NameRecord, 1, sizeof (NameRecord), fp); curseek = ftell(fp); if (SWAPW(NameRecord.platformID) == 1 && SWAPW(NameRecord.nameID) == 4) { fseek (fp, SWAPW (NameRecord.offset) + SWAPW(NamingTable.stringOffset) + SWAPL(Table.offset), SEEK\_SET); fread (&namebuf, 1, SWAPW(NameRecord.length), fp); namebuf\[SWAPW(NameRecord.length)\] = '\\0'; lstrcpy(lpszLongName,namebuf); fseek (fp, curseek, SEEK\_SET); csOutName = lpszLongName; } } break; } } fclose (fp); return csOutName;
}
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey