X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fgfxfont.c;h=893dd188a018ef72c8c0059909e7d0d59b4bae03;hb=e6425dcec64684d78e1cee29873af884c0a84afb;hp=45beedbbbeeafcbb369999a3a3c980ef9b722ae3;hpb=2ae69e978dd3ad2c7f6dfff4f33c4e2e81dabe9d;p=swftools.git diff --git a/lib/gfxfont.c b/lib/gfxfont.c index 45beedb..893dd18 100644 --- a/lib/gfxfont.c +++ b/lib/gfxfont.c @@ -55,9 +55,15 @@ static int full_unicode = 1; #define FT_SCALE 1 #define FT_SUBPIXELS 64 +typedef struct _gfxdrawinfo_t { + gfxdrawer_t* draw; + double quality; +} gfxdrawinfo_t; + static int ft_move_to(FT_Vector* _to, void* user) { - gfxdrawer_t* draw = (gfxdrawer_t*)user; + gfxdrawinfo_t* info = (gfxdrawinfo_t*)user; + gfxdrawer_t* draw = info->draw; double x = _to->x*FT_SCALE/(float)FT_SUBPIXELS; double y = -_to->y*FT_SCALE/(float)FT_SUBPIXELS; draw->moveTo(draw, x,y); @@ -65,7 +71,8 @@ static int ft_move_to(FT_Vector* _to, void* user) } static int ft_line_to(FT_Vector* _to, void* user) { - gfxdrawer_t* draw = (gfxdrawer_t*)user; + gfxdrawinfo_t* info = (gfxdrawinfo_t*)user; + gfxdrawer_t* draw = info->draw; double x = _to->x*FT_SCALE/(float)FT_SUBPIXELS; double y = -_to->y*FT_SCALE/(float)FT_SUBPIXELS; draw->lineTo(draw, x,y); @@ -73,24 +80,26 @@ static int ft_line_to(FT_Vector* _to, void* user) } static int ft_cubic_to(FT_Vector* _c1, FT_Vector* _c2, FT_Vector* _to, void* user) { - gfxdrawer_t* draw = (gfxdrawer_t*)user; + gfxdrawinfo_t* info = (gfxdrawinfo_t*)user; + gfxdrawer_t* draw = info->draw; double tox = _to->x*FT_SCALE/(float)FT_SUBPIXELS; double toy = -_to->y*FT_SCALE/(float)FT_SUBPIXELS; double c1x = _c1->x*FT_SCALE/(float)FT_SUBPIXELS; double c1y = -_c1->y*FT_SCALE/(float)FT_SUBPIXELS; double c2x = _c2->x*FT_SCALE/(float)FT_SUBPIXELS; double c2y = -_c2->y*FT_SCALE/(float)FT_SUBPIXELS; - gfxdraw_cubicTo(draw, c1x, c1y, c2x, c2y, tox, toy); + gfxdraw_cubicTo(draw, c1x, c1y, c2x, c2y, tox, toy, info->quality); return 0; } static int ft_conic_to(FT_Vector* _c, FT_Vector* _to, void* user) { - gfxdrawer_t* draw = (gfxdrawer_t*)user; + gfxdrawinfo_t* info = (gfxdrawinfo_t*)user; + gfxdrawer_t* draw = info->draw; double tox = _to->x*FT_SCALE/(float)FT_SUBPIXELS; double toy = -_to->y*FT_SCALE/(float)FT_SUBPIXELS; double cx = _c->x*FT_SCALE/(float)FT_SUBPIXELS; double cy = -_c->y*FT_SCALE/(float)FT_SUBPIXELS; - gfxdraw_conicTo(draw, cx,cy, tox,toy); + gfxdraw_conicTo(draw, cx,cy, tox,toy, info->quality); return 0; } static FT_Outline_Funcs outline_functions = @@ -104,25 +113,6 @@ static FT_Outline_Funcs outline_functions = static FT_Library ftlibrary = 0; -gfxline_t * clonePath(gfxline_t*line) -{ - gfxline_t*dest = 0; - gfxline_t*pos = 0; - while(line) { - gfxline_t*n = rfx_calloc(sizeof(gfxline_t)); - *n = *line; - n->next = 0; - if(!pos) { - dest = pos = n; - } else { - pos->next = n; - pos = n; - } - line = line->next; - } - return dest; -} - static gfxglyph_t cloneGlyph(gfxglyph_t*src) { gfxglyph_t dest; @@ -131,7 +121,7 @@ static gfxglyph_t cloneGlyph(gfxglyph_t*src) dest.name = strdup(src->name); dest.advance = src->advance; dest.unicode = src->unicode; - dest.line = clonePath(src->line); + dest.line = gfxline_clone(src->line); return dest; } @@ -157,13 +147,10 @@ void gfxfont_free(gfxfont_t*font) if(font->unicode2glyph) { free(font->unicode2glyph);font->unicode2glyph = 0; } - if(font->name) { - free(font->name);font->name = 0; - } free(font); } -gfxfont_t* gfxfont_load(char*filename) +gfxfont_t* gfxfont_load(char*filename, double quality) { FT_Face face; FT_Error error; @@ -213,9 +200,9 @@ gfxfont_t* gfxfont_load(char*filename) //font->glyphnames = rfx_calloc(face->num_glyphs*sizeof(char*)); } - name = FT_Get_Postscript_Name(face); + /*name = FT_Get_Postscript_Name(face); if(name && *name) - font->name = strdup(name); + font->name = strdup(name);*/ while(1) { @@ -277,6 +264,7 @@ gfxfont_t* gfxfont_load(char*filename) FT_Matrix matrix; char name[128]; gfxdrawer_t draw; + gfxdrawinfo_t info; int ret; char hasname = 0; name[0]=0; @@ -318,9 +306,11 @@ gfxfont_t* gfxfont_load(char*filename) } gfxdrawer_target_gfxline(&draw); + info.draw = &draw; + info.quality = quality; - //error = FT_Outline_Decompose(&face->glyph->outline, &outline_functions, &draw); - error = FT_Outline_Decompose(&face->glyph->outline, &outline_functions, &draw); + //error = FT_Outline_Decompose(&face->glyph->outline, &outline_functions, &info); + error = FT_Outline_Decompose(&face->glyph->outline, &outline_functions, &info); if(error) { fprintf(stderr, "Couldn't decompose glyph %d\n", t); @@ -364,7 +354,7 @@ gfxfont_t* gfxfont_load(char*filename) FT_Done_Face(face); FT_Done_FreeType(ftlibrary);ftlibrary=0; - + if(!isunicode && font->num_glyphs>0) { /* if the encoding isn't unicode, remap the font so that the encoding equals the char position, and