Index: work/util/ttf2lht/Makefile =================================================================== --- work/util/ttf2lht/Makefile (revision 20256) +++ work/util/ttf2lht/Makefile (revision 20257) @@ -2,7 +2,8 @@ RND=$(TRUNK)/src RND3=$(TRUNK)/src_3rd RNDLIB=$(RND)/polygon1.o $(RND)/heap.o $(RND)/rtree.o \ - $(RND3)/genvector/gds_char.o $(RND3)/genvector/vtp0.o + $(RND3)/genvector/gds_char.o $(RND3)/genvector/vtp0.o \ + $(TRUNK)/src_plugins/import_ttf/ttf_load.o CFLAGS = -Wall -g -I/usr/include/freetype2 -I$(TRUNK) -I$(RND3) LDFLAGS = -lfreetype -lm @@ -9,6 +10,8 @@ ttf2lht: ttf2lht.o drv_anim.o drv_poly.o drv_approx.o compat_dummy.o $(RNDLIB) +$(TRUNK)/src_plugins/import_ttf/ttf_load.o: $(TRUNK)/src_plugins/import_ttf/ttf_load.c $(TRUNK)/src_plugins/import_ttf/ttf_load.h + $(RND): cd $(RNDLIB) && make Index: work/util/ttf2lht/drv_anim.c =================================================================== --- work/util/ttf2lht/drv_anim.c (revision 20256) +++ work/util/ttf2lht/drv_anim.c (revision 20257) @@ -4,7 +4,7 @@ static int stroke_anim_move_to(const FT_Vector *to, void *s_) { - anim_stroke_t *s = (anim_stroke_t *)s_; + anim_pcb_ttf_stroke_t *s = (anim_pcb_ttf_stroke_t *)s_; s->s.x = to->x; s->s.y = to->y; return 0; @@ -12,7 +12,7 @@ static int stroke_anim_line_to(const FT_Vector *to, void *s_) { - anim_stroke_t *s = (anim_stroke_t *)s_; + anim_pcb_ttf_stroke_t *s = (anim_pcb_ttf_stroke_t *)s_; printf("line %f %f %ld %ld\n", s->s.x, s->s.y, to->x, to->y); s->s.x = to->x; s->s.y = to->y; @@ -19,25 +19,25 @@ return 0; } -void stroke_anim_init(stroke_t *s) +void stroke_anim_init(pcb_ttf_stroke_t *s) { printf("frame\n"); } -void stroke_anim_start(stroke_t *s, int chr) +void stroke_anim_start(pcb_ttf_stroke_t *s, int chr) { } -void stroke_anim_finish(stroke_t *s) +void stroke_anim_finish(pcb_ttf_stroke_t *s) { printf("flush\n"); } -void stroke_anim_uninit(stroke_t *s) +void stroke_anim_uninit(pcb_ttf_stroke_t *s) { } -anim_stroke_t anim_stroke = { +anim_pcb_ttf_stroke_t anim_stroke = { { { stroke_anim_move_to, Index: work/util/ttf2lht/drv_anim.h =================================================================== --- work/util/ttf2lht/drv_anim.h (revision 20256) +++ work/util/ttf2lht/drv_anim.h (revision 20257) @@ -1,7 +1,7 @@ typedef struct { - stroke_t s; -} anim_stroke_t; + pcb_ttf_stroke_t s; +} anim_pcb_ttf_stroke_t; -extern anim_stroke_t anim_stroke; +extern anim_pcb_ttf_stroke_t anim_stroke; Index: work/util/ttf2lht/drv_approx.c =================================================================== --- work/util/ttf2lht/drv_approx.c (revision 20256) +++ work/util/ttf2lht/drv_approx.c (revision 20257) @@ -9,7 +9,7 @@ int stroke_approx_conic_to(const FT_Vector *control, const FT_Vector *to, void *s_) { - stroke_t *s = (stroke_t *)s_; + pcb_ttf_stroke_t *s = (pcb_ttf_stroke_t *)s_; double t; double nodes = 10, td = 1.0 / nodes; FT_Vector v; @@ -29,7 +29,7 @@ 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_; + pcb_ttf_stroke_t *s = (pcb_ttf_stroke_t *)s_; if (drv_approx_comment != NULL) printf("%s cubic to {\n", drv_approx_comment); if (drv_approx_comment != NULL) printf("%s }\n", drv_approx_comment); return 0; Index: work/util/ttf2lht/drv_poly.c =================================================================== --- work/util/ttf2lht/drv_poly.c (revision 20256) +++ work/util/ttf2lht/drv_poly.c (revision 20257) @@ -9,7 +9,7 @@ list = pl; \ } while(0) -static void pline_close(poly_stroke_t *s) +static void pline_close(poly_pcb_ttf_stroke_t *s) { if (s->curr == NULL) return; @@ -30,7 +30,7 @@ static int stroke_poly_move_to(const FT_Vector *to, void *s_) { - poly_stroke_t *s = (poly_stroke_t *)s_; + poly_pcb_ttf_stroke_t *s = (poly_pcb_ttf_stroke_t *)s_; pcb_vector_t v; pline_close(s); @@ -44,7 +44,7 @@ static int stroke_poly_line_to(const FT_Vector *to, void *s_) { - poly_stroke_t *s = (poly_stroke_t *)s_; + poly_pcb_ttf_stroke_t *s = (poly_pcb_ttf_stroke_t *)s_; pcb_vnode_t *tmp; pcb_vector_t v; @@ -59,9 +59,9 @@ return 0; } -void stroke_poly_init(stroke_t *s_) +void stroke_poly_init(pcb_ttf_stroke_t *s_) { - poly_stroke_t *s = (poly_stroke_t *)s_; + poly_pcb_ttf_stroke_t *s = (poly_pcb_ttf_stroke_t *)s_; drv_approx_comment = NULL; printf("li:pcb-rnd-font-v1 {\n"); @@ -74,7 +74,7 @@ static void emit(pcb_pline_t *pl, void *user_data) { - poly_stroke_t *s = (poly_stroke_t *)user_data; + poly_pcb_ttf_stroke_t *s = (poly_pcb_ttf_stroke_t *)user_data; pcb_coord_t n, i; pcb_vnode_t *v; @@ -91,7 +91,7 @@ printf(" }\n"); } -void stroke_poly_start(stroke_t *s_, int chr) +void stroke_poly_start(pcb_ttf_stroke_t *s_, int chr) { if ((chr <= 32) || (chr > 126) || (chr == '&') || (chr == '#') || (chr == '{') || (chr == '}') || (chr == '/') || (chr == ':') || (chr == ';') || (chr == '=') || (chr == '\\') || (chr == ':')) printf(" ha:&%02x {\n", chr); @@ -99,9 +99,9 @@ printf(" ha:%c {\n", chr); } -void stroke_poly_finish(stroke_t *s_) +void stroke_poly_finish(pcb_ttf_stroke_t *s_) { - poly_stroke_t *s = (poly_stroke_t *)s_; + poly_pcb_ttf_stroke_t *s = (poly_pcb_ttf_stroke_t *)s_; pcb_pline_t *pl, *next; int err = 0; @@ -138,11 +138,13 @@ fprintf(stderr, "Invalid outlines\n"); printf(" }\n"); + s->neg = s->pos = s->curr = NULL; + pcb_polyarea_free(&s->pa); } -void stroke_poly_uninit(stroke_t *s_) +void stroke_poly_uninit(pcb_ttf_stroke_t *s_) { - poly_stroke_t *s = (poly_stroke_t *)s_; + poly_pcb_ttf_stroke_t *s = (poly_pcb_ttf_stroke_t *)s_; printf(" }\n"); printf(" cell_width = %fmil\n", s->maxx); @@ -153,7 +155,7 @@ } -poly_stroke_t poly_stroke = { +poly_pcb_ttf_stroke_t poly_stroke = { { { stroke_poly_move_to, Index: work/util/ttf2lht/drv_poly.h =================================================================== --- work/util/ttf2lht/drv_poly.h (revision 20256) +++ work/util/ttf2lht/drv_poly.h (revision 20257) @@ -4,7 +4,7 @@ #include "src/polyarea.h" typedef struct { - stroke_t s; + pcb_ttf_stroke_t s; /* polylines used while loading the outline */ pcb_pline_t *curr; @@ -15,8 +15,8 @@ int spid; double maxx, maxy; -} poly_stroke_t; +} poly_pcb_ttf_stroke_t; -extern poly_stroke_t poly_stroke; +extern poly_pcb_ttf_stroke_t poly_stroke; Index: work/util/ttf2lht/ttf2lht.c =================================================================== --- work/util/ttf2lht/ttf2lht.c (revision 20256) +++ work/util/ttf2lht/ttf2lht.c (revision 20257) @@ -1,102 +1,52 @@ #include -#include -#include -#include -#include -#include #include "ttf2lht.h" #include "drv_anim.h" #include "drv_poly.h" -FT_Library library; -FT_Face face; -const char *int_errtab[] = { - "success", - "Need an outline font" -}; +#include +#include +#include +#include -FT_Error dump(FT_ULong ttf_chr, FT_ULong out_chr, stroke_t *str) -{ - FT_Error err; - FT_Glyph gly; - FT_OutlineGlyph ol; +#include "../../../trunk/src_plugins/import_ttf/ttf_load.h" - - // load glyph - err = FT_Load_Glyph(face, FT_Get_Char_Index(face, ttf_chr), FT_LOAD_NO_BITMAP | FT_LOAD_NO_SCALE); - if (err != 0) - return err; - - FT_Get_Glyph(face->glyph, &gly); - ol = (FT_OutlineGlyph)gly; - if (face->glyph->format != ft_glyph_format_outline) - return -1; - - str->start(str, out_chr); - err = FT_Outline_Decompose(&(ol->outline), &str->funcs, str); - str->finish(str); - - if (err != 0) - return err; - - return 0; -} - int main(int argc, char *argv[]) { + pcb_ttf_t ctx; char *fontname = "FreeMono.ttf"; + const char *errmsg; FT_Error errnum; FT_ULong chr; FT_UInt idx; - stroke_t *stroker = (stroke_t *)&poly_stroke; + pcb_ttf_stroke_t *stroker = (pcb_ttf_stroke_t *)&poly_stroke; FT_ULong t, tbl[256]; -# undef __FTERRORS_H__ -# define FT_ERRORDEF( e, v, s ) { e, s }, -# define FT_ERROR_START_LIST { -# define FT_ERROR_END_LIST { 0, 0 } }; - static const struct { - FT_Error errnum; - const char *errstr; - } ft_errtab[] = -# include FT_ERRORS_H - - errnum = FT_Init_FreeType(&library); + errnum = pcb_ttf_load(&ctx, fontname); if (errnum != 0) { - fprintf(stderr, "FT_Init_FreeType: %s\n", ft_errtab[errnum].errstr); + fprintf(stderr, "%s\n", pcb_ttf_errmsg(errnum)); return 1; } - errnum = FT_New_Face(library, fontname, 0, &face); - if (errnum != 0) { - fprintf(stderr, "FT_New_Face: %s\n", ft_errtab[errnum].errstr); - return 1; - } - for(t = 0; t < 256; t++) tbl[t] = t; - fprintf(stderr, "Family: %s\n", face->family_name); - fprintf(stderr, "Height=%d ascender=%d descender=%d\n", face->height, face->ascender, face->descender); + fprintf(stderr, "Family: %s\n", ctx.face->family_name); + fprintf(stderr, "Height=%d ascender=%d descender=%d\n", ctx.face->height, ctx.face->ascender, ctx.face->descender); - stroker->scale_x = stroker->scale_y = 100.0 / face->height; + stroker->scale_x = stroker->scale_y = 100.0 / ctx.face->height; stroker->dx = 0; - stroker->dy = -face->descender; + stroker->dy = -ctx.face->descender; stroker->init(stroker); for(t = 33; t < 126; t++) { - errnum = dump(tbl[t], t, stroker); + errnum = pcb_ttf_trace(&ctx, tbl[t], t, stroker); if (errnum != 0) { - if (errnum > 0) - fprintf(stderr, "dump: %s\n", ft_errtab[errnum].errstr); - else - fprintf(stderr, "dump: %s\n", int_errtab[-errnum]); + fprintf(stderr, "%s\n", pcb_ttf_errmsg(errnum)); } } stroker->uninit(stroker); - FT_Done_Face(face); - FT_Done_Library(library); + pcb_ttf_unload(&ctx); return 0; -} \ No newline at end of file +} Index: work/util/ttf2lht/ttf2lht.h =================================================================== --- work/util/ttf2lht/ttf2lht.h (revision 20256) +++ work/util/ttf2lht/ttf2lht.h (revision 20257) @@ -1,18 +1,6 @@ #include -typedef struct stroke_s stroke_t; +#include "../../../trunk/src_plugins/import_ttf/ttf_load.h" -struct stroke_s { - FT_Outline_Funcs funcs; - void (*init)(stroke_t *s); - void (*start)(stroke_t *s, int chr); - void (*finish)(stroke_t *s); - void (*uninit)(stroke_t *s); - - double x, y; - double dx, dy, scale_x, scale_y; -}; - - #define OTX(s, x) (((x) + (s)->dx) * (s)->scale_x) #define OTY(s, y) (((y) + (s)->dy) * (s)->scale_y)