Last active
February 20, 2022 23:13
-
-
Save yashi/7f440d808539738686d26dd29aab42c6 to your computer and use it in GitHub Desktop.
List pixel widths from front size 10 to 30 for given fonts
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 <libgen.h> | |
#include <ft2build.h> | |
#include FT_FREETYPE_H | |
#define DPI (96) /* device resolution */ | |
void die(void) | |
{ | |
printf("oops\n"); | |
exit(1); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
FT_Library lib; | |
FT_Face face; | |
int ret; | |
if (argc < 2) die(); | |
ret = FT_Init_FreeType(&lib); | |
if (ret) die(); | |
FT_ULong codepoints[] = {'a', 0x3042}; | |
int min_size = 10; | |
int max_size = 30; | |
printf("font size:"); | |
for (int i = min_size; i <= max_size; i++) { | |
printf(" %d", i); | |
} | |
printf("\n"); | |
for (int j = 0; j < argc-1; j++) { | |
printf("%s\n", basename(argv[j+1])); | |
ret = FT_New_Face(lib, argv[j+1], 0, &face); | |
if (ret) die(); | |
for (FT_ULong k = 0; k < 2; k++) { | |
int index = FT_Get_Char_Index(face, codepoints[k]); | |
//printf("%ld -> %d\n", codepoints[k], index); | |
if (!index) { | |
printf(" U+%04lx: (not found)\n", codepoints[k]); | |
} | |
else { | |
printf(" U+%04lx:", codepoints[k]); | |
for (int i = min_size; i <= max_size; i++) { | |
FT_Set_Char_Size(face, 0, i*64, DPI, DPI); | |
FT_Load_Glyph(face, index, FT_LOAD_DEFAULT); | |
printf(" %2ld", face->glyph->metrics.horiAdvance/64); | |
} | |
printf("\n"); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment