2013-08-13 11:08:54 +00:00
|
|
|
/*
|
2013-10-09 09:07:32 +00:00
|
|
|
gcc main.c -I/usr/include/freetype2 -lfreetype && ./a.out 12 ../../testdata/luxisr.ttf with_hinting
|
2013-08-13 11:08:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
|
2013-10-09 09:07:32 +00:00
|
|
|
void usage(char** argv) {
|
2013-10-29 09:59:39 +00:00
|
|
|
fprintf(stderr, "usage: %s font_size font_file [with_hinting|sans_hinting]\n", argv[0]);
|
2013-10-09 09:07:32 +00:00
|
|
|
}
|
2013-08-13 11:08:54 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
FT_Error error;
|
|
|
|
FT_Library library;
|
|
|
|
FT_Face face;
|
|
|
|
FT_Outline* o;
|
2013-10-29 09:59:39 +00:00
|
|
|
FT_Int major, minor, patch;
|
2013-10-09 09:07:32 +00:00
|
|
|
int i, j, font_size, no_hinting;
|
2013-08-13 11:08:54 +00:00
|
|
|
|
2013-10-09 09:07:32 +00:00
|
|
|
if (argc != 4) {
|
|
|
|
usage(argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
font_size = atoi(argv[1]);
|
|
|
|
if (font_size <= 0) {
|
2013-10-29 09:59:39 +00:00
|
|
|
fprintf(stderr, "invalid font_size\n");
|
2013-10-09 09:07:32 +00:00
|
|
|
usage(argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[3], "with_hinting")) {
|
|
|
|
no_hinting = 0;
|
|
|
|
} else if (!strcmp(argv[3], "sans_hinting")) {
|
|
|
|
no_hinting = 1;
|
|
|
|
} else {
|
2013-10-29 09:59:39 +00:00
|
|
|
fprintf(stderr, "neither \"with_hinting\" nor \"sans_hinting\"\n");
|
2013-10-09 09:07:32 +00:00
|
|
|
usage(argv);
|
|
|
|
return 1;
|
|
|
|
};
|
2013-08-13 11:08:54 +00:00
|
|
|
error = FT_Init_FreeType(&library);
|
|
|
|
if (error) {
|
2013-10-29 09:59:39 +00:00
|
|
|
fprintf(stderr, "FT_Init_FreeType: error #%d\n", error);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
FT_Library_Version(library, &major, &minor, &patch);
|
2013-11-28 03:02:28 +00:00
|
|
|
printf("freetype version %d.%d.%d\n", major, minor, patch);
|
2013-10-09 09:07:32 +00:00
|
|
|
error = FT_New_Face(library, argv[2], 0, &face);
|
2013-08-13 11:08:54 +00:00
|
|
|
if (error) {
|
2013-10-29 09:59:39 +00:00
|
|
|
fprintf(stderr, "FT_New_Face: error #%d\n", error);
|
2013-08-13 11:08:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
error = FT_Set_Char_Size(face, 0, font_size*64, 0, 0);
|
|
|
|
if (error) {
|
2013-10-29 09:59:39 +00:00
|
|
|
fprintf(stderr, "FT_Set_Char_Size: error #%d\n", error);
|
2013-08-13 11:08:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < face->num_glyphs; i++) {
|
|
|
|
error = FT_Load_Glyph(face, i, no_hinting ? FT_LOAD_NO_HINTING : FT_LOAD_DEFAULT);
|
|
|
|
if (error) {
|
2013-10-29 09:59:39 +00:00
|
|
|
fprintf(stderr, "FT_Load_Glyph: glyph %d: error #%d\n", i, error);
|
2013-08-13 11:08:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (face->glyph->format != FT_GLYPH_FORMAT_OUTLINE) {
|
2013-10-29 09:59:39 +00:00
|
|
|
fprintf(stderr, "glyph format for glyph %d is not FT_GLYPH_FORMAT_OUTLINE\n", i);
|
2013-08-13 11:08:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
o = &face->glyph->outline;
|
|
|
|
for (j = 0; j < o->n_points; j++) {
|
|
|
|
if (j != 0) {
|
|
|
|
printf(", ");
|
|
|
|
}
|
|
|
|
printf("%ld %ld %d", o->points[j].x, o->points[j].y, o->tags[j] & 0x01);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2013-10-09 09:07:32 +00:00
|
|
|
return 0;
|
2013-08-13 11:08:54 +00:00
|
|
|
}
|