Created
June 22, 2012 14:49
-
-
Save favonia/2973210 to your computer and use it in GitHub Desktop.
Font copyright reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <ft2build.h> | |
#include FT_FREETYPE_H | |
#include <freetype/ftsnames.h> | |
int main (int argc, const char *argv[]) { | |
if (argc != 2) return -1; | |
FT_Library lib; | |
memset(&lib, 0, sizeof lib); | |
if (FT_Init_FreeType(&lib) != 0) return -1; | |
FT_Face face; | |
memset(&face, 0, sizeof face); | |
fprintf(stderr, "reading the font %s...\n", argv[1]); | |
if (FT_New_Face(lib, argv[1], 0, &face) != 0) return -1; | |
fprintf(stderr, "done.\n"); | |
#define COPYRIGHT_NOTICE 0U | |
#define LICENSE_DESCRIPTION 13U | |
#define LICENSE_URL 14U | |
unsigned int indices[] = {COPYRIGHT_NOTICE, LICENSE_DESCRIPTION, LICENSE_URL}; | |
FT_SfntName name; | |
for (int i = 0; i < (sizeof indices/sizeof(unsigned int)); i++) { | |
memset(&name, 0, sizeof name); | |
fprintf(stderr, "reading the table %u...\n", indices[i]); | |
if (FT_Get_Sfnt_Name(face, indices[i], &name) != 0) { | |
fprintf(stderr, "failed. (empty?)\n"); | |
continue; | |
} | |
fprintf(stderr, "done.\n"); | |
printf ("name table %u of size %u\n%.*s\n\n", indices[i], name.string_len, (int)name.string_len, name.string); | |
if (FT_Done_Face(face) != 0) return -1; | |
} | |
if (FT_Done_FreeType(lib) != 0) return -1; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment