Skip to content

Instantly share code, notes, and snippets.

@kakwa
Created December 24, 2017 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakwa/87ed694b00a01a60310d4926b6f8fd90 to your computer and use it in GitHub Desktop.
Save kakwa/87ed694b00a01a60310d4926b6f8fd90 to your computer and use it in GitHub Desktop.
freetype reverse map
#define _XOPEN_SOURCE 500
#include <ftw.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <ft2build.h>
#include FT_FREETYPE_H
//gcc test.c -o crap -I/usr/include/freetype2/ -l freetype
static int
display_info(const char *fpath, const struct stat *sb,
int tflag, struct FTW *ftwbuf)
{
FT_Library library;
int error = FT_Init_FreeType( &library );
FT_Face face;
if ( error )
{
return 1;
}
if (tflag == FTW_F) {
error = FT_New_Face( library,
fpath,
0,
&face );
if ( error == FT_Err_Unknown_File_Format )
{
printf("%s not a font\n", fpath);
}
else if ( error )
{
printf("unknowm error %d\n", error);
}
else {
printf("font %s | name %s | style %s\n", fpath, face->family_name, face->style_name);
printf("%d\n", face->num_charmaps);
FT_Select_Charmap(face, FT_ENCODING_UNICODE);
FT_UInt gindex = 0;
//FT_ULong charcode = FT_Get_First_Char(face, &gindex);
//while ( gindex != 0 )
//{
// printf("index: %d | charcode %d\n", gindex, charcode);
// charcode = FT_Get_Next_Char( face, charcode, &gindex );
//}
FT_Done_Face ( face );
FT_Done_FreeType( library );
}
}
return 0; /* To tell nftw() to continue */
}
int
main(int argc, char *argv[])
{
int flags = 0;
if (argc > 2 && strchr(argv[2], 'd') != NULL)
flags |= FTW_DEPTH;
if (argc > 2 && strchr(argv[2], 'p') != NULL)
flags |= FTW_PHYS;
if (nftw((argc < 2) ? "." : argv[1], display_info, 20, flags)
== -1) {
perror("nftw");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment