Hi,
I'm trying to fetch all the points from FT_Outline of a glyph, here is
a minimal example,
/* testft.c: test FreeType capabilities */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
int move_to(const FT_Vector *to, void *user);
int line_to(const FT_Vector *to, void *user);
int conic_to(const FT_Vector *control, const FT_Vector *to,
void *user);
int cubic_to(const FT_Vector *control1, const FT_Vector *control2,
const FT_Vector *to, void *user);
int main(int argc, char *argv[])
{
FT_Error error;
FT_Library library;
FT_Face face;
FT_UInt glyph_index;
FT_Outline *outline;
FT_ULong charcode = 'Z';
error = FT_Init_FreeType(&library);
assert(error == 0);
error = FT_New_Face(library, argv[1], 0, &face);
assert(error == 0);
glyph_index = FT_Get_Char_Index(face, charcode);
assert(glyph_index != 0);
error = FT_Load_Glyph(face, glyph_index,
FT_LOAD_DEFAULT);
assert(error == 0);
assert(face->glyph->format == FT_GLYPH_FORMAT_OUTLINE);
outline = &face->glyph->outline;
printf("n_contours = %d\n", outline->n_contours);
printf("n_points = %d\n", outline->n_points);
FT_Outline_Funcs outline_funcs = { move_to, line_to, conic_to,
cubic_to, 0, 0 };
FT_Outline_Decompose(outline, &outline_funcs, NULL);
FT_Done_Face(face);
FT_Done_FreeType(library);
return 0;
}
void print4bytes(const char *bytes)
{
int i;
for (i = 0; i < 4; i++)
printf("%02X ", bytes[i]);
printf("\n");
}
int move_to(const FT_Vector *to, void *user)
{
print4bytes((char *) &(to->x));
print4bytes((char *) &(to->y));
printf("move_to([%g, %g])\n",
DOUBLE_FROM_26_6(to->x), DOUBLE_FROM_26_6(to->y));
return 0;
}
int line_to(const FT_Vector *to, void *user)
{
printf("line_to([%g, %g])\n",
DOUBLE_FROM_26_6(to->x), DOUBLE_FROM_26_6(to->y));
return 0;
}
int conic_to(const FT_Vector *control, const FT_Vector *to,
void *user)
{
printf("conic_to(c = [%g, %g], to = [%g, %g])\n",
DOUBLE_FROM_26_6(control->x), DOUBLE_FROM_26_6
(control->y),
DOUBLE_FROM_26_6(to->x), DOUBLE_FROM_26_6(to->y));
return 0;
}
int cubic_to(const FT_Vector *control1, const FT_Vector *control2,
const FT_Vector *to, void *user)
{
printf("cubic_to(c1 = [%g, %g], c2 = [%g, %g], to = [%g, %
g])\n",
DOUBLE_FROM_26_6(control1->x), DOUBLE_FROM_26_6
(control1->y),
DOUBLE_FROM_26_6(control2->x), DOUBLE_FROM_26_6
(control2->y),
DOUBLE_FROM_26_6(to->x), DOUBLE_FROM_26_6(to->y));
return 0;
}
The n_points and n_contours printed is correct, but the point
FT_Vector
does not contain any useful values, for example:
$ ./testft /Library/Fonts/Arial.ttf
n_contours = 1
n_points = 13
00 00 00 00
04 00 00 00
move_to([0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
conic_to(c = [0, 0.0625], to = [0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
line_to([0, 0.0625])
I'm wondering what's wrong with my code. Thanks!
- Jiang
_______________________________________________
Freetype-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/freetype-devel