freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] Get copyright information from ttf file


From: Henk Jan Priester
Subject: Re: [ft] Get copyright information from ttf file
Date: Fri, 12 Nov 2010 11:11:39 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090812)

Aniruddha Apte wrote:
Hello,

Is there any api in FreeType2 that returns copyright, author, legal, license, and similar other information present in the .ttf file?

You can use the:

        FT_Get_Sfnt_Name_Count
        FT_Get_Sfnt_Name

And then parse these records.

I had written once a small program using these 2 functions to
get the 'localized' font names.

My program reports something like

Name-rec 0: type 0, (c) Copyright ZHONGYI Electronic Co. 1995
Name-rec 1: type 1, SimSun
Name-rec 2: type 2, Regular
Name-rec 3: type 3, SimSun
Name-rec 4: type 4, SimSun
Name-rec 5: type 5, Version 3.03
Name-rec 6: type 6, SimSun
Name-rec 7: type 7, Trademark of ZHONGYI Electronic Co., Beijing
Name-rec 8: type 0 for PEL 3, 1, 1033 <82 bytes>
Name-rec 9: type 1 for PEL 3, 1, 1033 <12 bytes>
Bytes:  0 53  0 69  0 6d  0 53  0 75  0 6e

I have attached it so you can play with it if you wish.

Henk Jan

>

thanks
aniruddhaFT_Get_Sfnt_Name


------------------------------------------------------------------------

_______________________________________________
Freetype mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/freetype


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_SFNT_NAMES_H 


/* see FreeType ttnameid.h for values */
#define TT_NAME_ID_COPYRIGHT            0
#define TT_NAME_ID_FONT_FAMILY          1
#define TT_NAME_ID_FONT_SUBFAMILY       2
#define TT_NAME_ID_UNIQUE_ID            3
#define TT_NAME_ID_FULL_NAME            4
#define TT_NAME_ID_VERSION_STRING       5
#define TT_NAME_ID_PS_NAME              6
#define TT_NAME_ID_TRADEMARK            7



void dumpFace( 
   FT_Face  face
)
{
   FT_UInt cnt, i, j;

   fprintf(stdout, "Family: %s\n\n", face->family_name); 

   cnt = FT_Get_Sfnt_Name_Count(face);
   fprintf(stdout, "Number of names: %d\n", cnt);
   for( i=0; i < cnt; i++)
   {
      FT_SfntName  fontname;

      if ( FT_Get_Sfnt_Name(face, i, &fontname) == 0 )
      {
         if ( fontname.platform_id == 1 &&
              fontname.encoding_id == 0 &&
              fontname.language_id == 0 )
         {
            char szBuf[255];
            int  iLen = (int)fontname.string_len;
            if ( iLen > (sizeof(szBuf) - 1) )
                iLen = sizeof(szBuf) - 1;
            memcpy(szBuf, (char *)fontname.string, iLen);
            szBuf[iLen] = '\0';          
            
            fprintf(stdout, "Name-rec %u: type %u, %s\n", i,
                    fontname.name_id, szBuf);   
         }
         else 
         {
            int skip_bytes;

            skip_bytes = 0;
            /* 0 copyright, 2 sub-family, 5 version, 6 ps name, 7 trademark */
            if ( fontname.name_id != 1 ) 
            {
               skip_bytes = 1;
            }
            fprintf(stdout, 
                  "Name-rec %u: type %u for PEL %u, %u, %u <%u bytes>\n", 
                       i, fontname.name_id, fontname.platform_id,
                       fontname.encoding_id, fontname.language_id,
                       fontname.string_len );
            if ( !skip_bytes )
            {
               int ascii = 0;
               fprintf(stdout, "Bytes: ");
               for (j=0; j < fontname.string_len; j++)
               {
                  fprintf(stdout, "%2x ", fontname.string[j]);
                  if ( isascii(fontname.string[j]) )
                     ascii++;
               }
               fprintf(stdout, "\n");
               if ( ascii == fontname.string_len )
               {
                  char szTmp[255];
                  if (ascii >= (sizeof(szTmp)) )
                     ascii = sizeof(szTmp) - 1;
                  memcpy(szTmp, fontname.string, ascii);
                  szTmp[ascii] = '\0';
                  fprintf(stdout, "(In Ascii: %s)", szTmp);
               }
            }
         }
      }
      else
         fprintf(stdout, "Error getting fontname %d\n", i);
   }
   fprintf(stdout, "\n");
}



int main( int argc, char *argv[] )
{
   FT_Library   FTlib;
   FT_Face      FTface;
   int          i, iFaces;

   if ( argc < 2 )
   {
      printf("\nUsage: fontcheck <file>\n");
      return EXIT_FAILURE;
   }
   
   FT_Init_FreeType(&FTlib);

   if ( FT_New_Face(FTlib, argv[1], 0, &FTface) == 0 )
   {
      iFaces = FTface->num_faces;
      fprintf(stdout, "Processing font %s - %d faces found\n\n", argv[1],
              iFaces);
      dumpFace(FTface);
      FT_Done_Face(FTface); 
      for(i=1; i < iFaces; i++)
      {
         FT_New_Face(FTlib, argv[1], i, &FTface);
         dumpFace(FTface);
         FT_Done_Face(FTface);
      }
   }
   else
      fprintf(stdout, "Error: %s is not a correct font\n", argv[1]);

   FT_Done_FreeType(FTlib);
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]