Advertisement
Guest User

TTF Font Name

a guest
Mar 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. BOOL NEAR PASCAL bGetName( CFontFile& file,
  2.                            tttag *pTTTag,
  3.                            IDBlock_t& ID_Block,
  4.                            LPTSTR lpszName,
  5.                            LPFONTDESCINFO lpFDI )
  6. {
  7.     sfnt_pNameTable pNames;
  8.     WORD            size;
  9.     TCHAR           szSubFamily[ 64 ];
  10.  
  11.     IDBlock_t       ID_DefBlock = ID_Block;
  12.  
  13.  
  14.     ID_DefBlock.id_Language = (ID_DefBlock.id_Platform == PLATFORM_MS)
  15.                                                          ? LANG_US_ENG : 0;
  16.  
  17.     size = (WORD) SWAPL( pTTTag->dwLength );
  18.  
  19.     *lpszName = 0;
  20.  
  21.     pNames = (sfnt_pNameTable) LocalAlloc( LPTR, size );
  22.  
  23.     if( pNames )
  24.     {
  25.         if (ERROR_SUCCESS == file.Read(pNames, size))
  26.         {
  27.             //
  28.             //  The logic for what name to find:
  29.             //  If font file was converted from a Type1 font
  30.             //     1) POSTCRIPT_ID in current language
  31.             //  else
  32.             //     1) FACENAME_ID in current language.
  33.             //  2) FAMILY and SUBFAMILY in current language.
  34.             //  3) FACENAME_ID in default language.
  35.             //
  36.             // If the TrueType font was converted from a Type1 font, we want
  37.             // to use the "postscript" form of the font description so that
  38.             // it matches the description returned by IsPSFont() when invoked
  39.             // on the "parent" Type1 file.  These descriptions are used as registry
  40.             // keys in the "Fonts" and "Type1Fonts" sections and must match.
  41.             //
  42.             if (bIsConvertedTrueType(pNames, ID_Block) &&
  43.                 bFindNameThing(pNames, ID_Block, POSTSCRIPT_ID, lpszName))
  44.             {
  45.                //
  46.                // Replace all dashes with spaces (same as .PFM/.INF file reader code)
  47.                //
  48.                for (LPTSTR pc = lpszName; *pc; pc++)
  49.                  if (*pc == TEXT('-'))
  50.                     *pc = TEXT(' ');
  51.             }
  52.             else if( bFindNameThing( pNames, ID_Block, FACENAME_ID, lpszName ) )
  53.                ;
  54.             else if( bFindNameThing( pNames, ID_Block, SUBFAMILY_ID, szSubFamily )
  55.                  && (bFindNameThing( pNames, ID_Block,    FAMILY_ID, lpszName )
  56.                  ||  bFindNameThing( pNames, ID_DefBlock, FAMILY_ID, lpszName ) ) )
  57.             {
  58.                 lstrcat( lpszName, TEXT( " " ) );
  59.                 lstrcat( lpszName, szSubFamily );
  60.             }
  61.             else( bFindNameThing( pNames, ID_DefBlock, FACENAME_ID, lpszName ) )
  62.                 ;
  63. <some code skipped>
  64.         }
  65.         LocalFree( (HANDLE)pNames );
  66.    }
  67.  
  68.    return *lpszName != 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement