Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. is there any way to get the facename from a TTF file ?

is there any way to get the facename from a TTF file ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adara
    wrote on last edited by
    #1

    is there any way to get the facename from a TTF file ? Thanx:rose:

    C 1 Reply Last reply
    0
    • A adara

      is there any way to get the facename from a TTF file ? Thanx:rose:

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      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

      Fractals

      A 1 Reply Last reply
      0
      • C Chris Losinger

        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

        Fractals

        A Offline
        A Offline
        adara
        wrote on last edited by
        #3

        great help , Thank you :rose:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups