Index: work/util/ttf2lht/Makefile =================================================================== --- work/util/ttf2lht/Makefile (revision 18926) +++ work/util/ttf2lht/Makefile (revision 18927) @@ -1,4 +1,5 @@ CFLAGS = -Wall -g -I/usr/include/freetype2 LDFLAGS = -lfreetype -ttf2lht: ttf2lht.c +ttf2lht: ttf2lht.o drv_anim.o drv_approx.o + Index: work/util/ttf2lht/drv_anim.c =================================================================== --- work/util/ttf2lht/drv_anim.c (nonexistent) +++ work/util/ttf2lht/drv_anim.c (revision 18927) @@ -0,0 +1,29 @@ +#include "ttf2lht.h" +#include "drv_anim.h" +#include "drv_approx.h" + +static int stroke_anim_move_to(const FT_Vector *to, void *s_) +{ + stroke_t *s = (stroke_t *)s_; + s->x = to->x; + s->y = to->y; + return 0; +} + +static int stroke_anim_line_to(const FT_Vector *to, void *s_) +{ + stroke_t *s = (stroke_t *)s_; + printf("line %f %f %ld %ld\n", s->x, s->y, to->x, to->y); + s->x = to->x; + s->y = to->y; + return 0; +} + +FT_Outline_Funcs drv_anim_funcs = { + stroke_anim_move_to, + stroke_anim_line_to, + stroke_approx_conic_to, + stroke_approx_cubic_to, + 0, + 0 +}; Index: work/util/ttf2lht/drv_anim.h =================================================================== --- work/util/ttf2lht/drv_anim.h (nonexistent) +++ work/util/ttf2lht/drv_anim.h (revision 18927) @@ -0,0 +1 @@ +extern FT_Outline_Funcs drv_anim_funcs; Index: work/util/ttf2lht/drv_approx.c =================================================================== --- work/util/ttf2lht/drv_approx.c (nonexistent) +++ work/util/ttf2lht/drv_approx.c (revision 18927) @@ -0,0 +1,33 @@ +#include "ttf2lht.h" + +static double sqr(double a) +{ + return a*a; +} + +int stroke_approx_conic_to(const FT_Vector *control, const FT_Vector *to, void *s_) +{ + stroke_t *s = (stroke_t *)s_; + double t; + double nodes = 10, td = 1.0 / nodes; + FT_Vector v; + + printf("## conic to {\n"); + for(t = 0.0; t <= 1.0; t += td) { + v.x = sqr(1.0-t) * s->x + 2*t*(1.0-t)*control->x + t*t*to->x; + v.y = sqr(1.0-t) * s->y + 2*t*(1.0-t)*control->y + t*t*to->y; + s->funcs->line_to(&v, s); + } + printf("## }\n"); + + s->x = to->x; + s->y = to->y; + return 0; +} + +int stroke_approx_cubic_to(const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to, void *s_) +{ + stroke_t *s = (stroke_t *)s_; + printf("# cubic to\n"); + return 0; +} Index: work/util/ttf2lht/drv_approx.h =================================================================== --- work/util/ttf2lht/drv_approx.h (nonexistent) +++ work/util/ttf2lht/drv_approx.h (revision 18927) @@ -0,0 +1,2 @@ +int stroke_approx_conic_to(const FT_Vector *control, const FT_Vector *to, void *s_); +int stroke_approx_cubic_to(const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to, void *s_); Index: work/util/ttf2lht/ttf2lht.c =================================================================== --- work/util/ttf2lht/ttf2lht.c (revision 18926) +++ work/util/ttf2lht/ttf2lht.c (revision 18927) @@ -4,7 +4,10 @@ #include #include #include +#include "ttf2lht.h" +#include "drv_anim.h" + FT_Library library; FT_Face face; const char *int_errtab[] = { @@ -12,68 +15,6 @@ "Need an outline font" }; -typedef struct { - double x, y; - FT_Outline_Funcs *funcs; -} stroke_t; - -static double sqr(double a) -{ - return a*a; -} - -int stroke_move_to(const FT_Vector *to, void *s_) -{ - stroke_t *s = (stroke_t *)s_; - printf("# move to\n"); - return 0; -} - -int stroke_line_to(const FT_Vector *to, void *s_) -{ - stroke_t *s = (stroke_t *)s_; - printf("# line to\n"); - return 0; -} - -int stroke_conic_to(const FT_Vector *control, const FT_Vector *to, void *s_) -{ - stroke_t *s = (stroke_t *)s_; - double t; - double nodes = 10, td = 1.0 / nodes; - FT_Vector v; - - printf("## conic to {\n"); - for(t = 0.0; t <= 1.0; t += td) { - v.x = sqr(1.0-t) * s->x + 2*t*(1.0-t)*control->x + t*t*to->x; - v.y = sqr(1.0-t) * s->y + 2*t*(1.0-t)*control->y + t*t*to->y; - s->funcs->line_to(&v, s); - } - printf("## }\n"); - - s->x = to->x; - s->y = to->y; - return 0; -} - -int stroke_cubic_to(const FT_Vector *control1, const FT_Vector *control2, const FT_Vector *to, void *s_) -{ - stroke_t *s = (stroke_t *)s_; - printf("# cubic to\n"); - return 0; -} - - -static const FT_Outline_Funcs funcs = { - stroke_move_to, - stroke_line_to, - stroke_conic_to, - stroke_cubic_to, - 0, - 0 -}; - - FT_Error dump(FT_ULong chr) { FT_Error err; @@ -91,8 +32,8 @@ if (face->glyph->format != ft_glyph_format_outline) return -1; - str.funcs = &funcs; - err = FT_Outline_Decompose(&(ol->outline), &funcs, &str); + str.funcs = &drv_anim_funcs; + err = FT_Outline_Decompose(&(ol->outline), str.funcs, &str); if (err != 0) return err;