X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fgfxfont.c;h=64461a419f9e8e282af5a782a5af3cbca1994404;hb=39256331a887c5d462253ab1aea538ee2e4fd4ba;hp=8a704fd3a717961614b7a4475c5c86cbb659faca;hpb=1479fbb7a5df24eb7c12e00e6be63465267dd679;p=swftools.git diff --git a/lib/gfxfont.c b/lib/gfxfont.c index 8a704fd..64461a4 100644 --- a/lib/gfxfont.c +++ b/lib/gfxfont.c @@ -60,7 +60,7 @@ typedef struct _gfxdrawinfo_t { double quality; } gfxdrawinfo_t; -static int ft_move_to(FT_Vector* _to, void* user) +static int ft_move_to(const FT_Vector* _to, void* user) { gfxdrawinfo_t* info = (gfxdrawinfo_t*)user; gfxdrawer_t* draw = info->draw; @@ -69,7 +69,7 @@ static int ft_move_to(FT_Vector* _to, void* user) draw->moveTo(draw, x,y); return 0; } -static int ft_line_to(FT_Vector* _to, void* user) +static int ft_line_to(const FT_Vector* _to, void* user) { gfxdrawinfo_t* info = (gfxdrawinfo_t*)user; gfxdrawer_t* draw = info->draw; @@ -78,7 +78,7 @@ static int ft_line_to(FT_Vector* _to, void* user) draw->lineTo(draw, x,y); return 0; } -static int ft_cubic_to(FT_Vector* _c1, FT_Vector* _c2, FT_Vector* _to, void* user) +static int ft_cubic_to(const FT_Vector* _c1, const FT_Vector* _c2, const FT_Vector* _to, void* user) { gfxdrawinfo_t* info = (gfxdrawinfo_t*)user; gfxdrawer_t* draw = info->draw; @@ -91,7 +91,7 @@ static int ft_cubic_to(FT_Vector* _c1, FT_Vector* _c2, FT_Vector* _to, void* use 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) +static int ft_conic_to(const FT_Vector* _c, const FT_Vector* _to, void* user) { gfxdrawinfo_t* info = (gfxdrawinfo_t*)user; gfxdrawer_t* draw = info->draw; @@ -129,14 +129,16 @@ static void glyph_clear(gfxglyph_t*g) { gfxline_t*line; if(g->name) { - free(g->name); g->name = 0; + free((void*)g->name); g->name = 0; } gfxline_free(g->line);g->line = 0; } static int errorno = 0; -gfxfont_t* gfxfont_load(char*filename, double quality) +//#define DEBUG 1 + +gfxfont_t* gfxfont_load(char*id, char*filename, unsigned int flags, double quality) { FT_Face face; FT_Error error; @@ -162,9 +164,12 @@ gfxfont_t* gfxfont_load(char*filename, double quality) } error = FT_New_Face(ftlibrary, filename, 0, &face); FT_Set_Pixel_Sizes (face, 16*loadfont_scale, 16*loadfont_scale); +#ifdef DEBUG + printf("gfxfont_load(%s, %s, %f)\n", id, filename, quality); +#endif if(error) { - fprintf(stderr, "Couldn't load file %s- not a TTF file?\n", filename); + fprintf(stderr, "Couldn't load file %s- not a TTF file? (error=%02x)\n", filename, error); return 0; } if(face->num_glyphs <= 0) { @@ -179,6 +184,7 @@ gfxfont_t* gfxfont_load(char*filename, double quality) //font->leading = font->layout->ascent + font->layout->descent; //font->encoding = FONT_ENCODING_UNICODE; font->max_unicode = 0; + font->id = strdup(id); font->glyphs = rfx_calloc(face->num_glyphs*sizeof(gfxglyph_t)); glyph2unicode = rfx_calloc(face->num_glyphs*sizeof(int)); @@ -190,9 +196,22 @@ gfxfont_t* gfxfont_load(char*filename, double quality) fontname = FT_Get_Postscript_Name(face); +#ifdef DEBUG + for(t=0;tnum_charmaps;t++) { + printf("possible encoding: %c%c%c%c (%d of %d)\n", + (face->charmaps[t]->encoding >> 24)&255, + (face->charmaps[t]->encoding >> 16)&255, + (face->charmaps[t]->encoding >> 8)&255, + (face->charmaps[t]->encoding >> 0)&255, + t+1, face->num_charmaps + ); + } +#endif + while(1) { charcode = FT_Get_First_Char(face, &gindex); + while(gindex != 0) { if(gindex >= 0 && gindexnum_glyphs) { @@ -206,19 +225,38 @@ gfxfont_t* gfxfont_load(char*filename, double quality) charcode = FT_Get_Next_Char(face, charcode, &gindex); } +#ifdef DEBUG + if(face->charmap) { + printf("ENCODING: %c%c%c%c (%d of %d) max_unicode=%d\n", + (face->charmap->encoding >> 24)&255, + (face->charmap->encoding >> 16)&255, + (face->charmap->encoding >> 8)&255, + (face->charmap->encoding >> 0)&255, + charmap, face->num_charmaps, font->max_unicode + ); + } else { + printf("ENCODING: NONE (%d of %d) max_unicode=%d\n", + charmap, face->num_charmaps, font->max_unicode + ); + } +#endif + /* if we didn't find a single encoding character, try the font's charmaps instead. That usually means that the encoding is no longer unicode. TODO: find a way to convert the encoding to unicode */ - if(font->max_unicode == 0 && charmap < face->num_charmaps - 1) { + if(font->max_unicode == 0 && charmap < face->num_charmaps-1 + && face->charmaps[charmap+1]->encoding != 0x41444243 /* adbc, custom */ + && face->charmaps[charmap+1]->encoding != 0x61726d6e /* armn */ + ) + { charmap++; FT_Set_Charmap(face, face->charmaps[charmap]); isunicode = 0; - } else + } else break; } - /* TODO: if isunicode is 1, we now need to permutate the character order so that each character is at it's encoding position */ @@ -233,6 +271,9 @@ gfxfont_t* gfxfont_load(char*filename, double quality) g = -1; font->unicode2glyph[t] = g; if(g>=0) { +#ifdef DEBUG + printf("u%d ->%d\n", t, g); +#endif max_unicode = t+1; if(!glyph2unicode[g]) { glyph2unicode[g] = t; @@ -280,12 +321,17 @@ gfxfont_t* gfxfont_load(char*filename, double quality) hasname = 1; } } - if(has_had_errors && (isunicode && !glyph2unicode[t]) && !hasname) { + +#if 0 // some cantonese pdfs fail to work if this is activated + + if(has_had_errors && (isunicode && !glyph2unicode[t]) && !hasname && t>=256) { /* some freetype versions crash or corrupt memory if we try to load characters (without unicode index or name) above 256 for some fonts. So skip those characters once the first error occured */ omit = 1; } +#endif + if(!omit) { error = FT_Load_Glyph(face, t, FT_LOAD_NO_BITMAP); if(error) { @@ -336,7 +382,7 @@ gfxfont_t* gfxfont_load(char*filename, double quality) FT_Done_Glyph(glyph); omit = 4; } else { - font->glyphs[font->num_glyphs].advance = glyph->advance.x*20/65536; + font->glyphs[font->num_glyphs].advance = glyph->advance.x/65536; font->glyphs[font->num_glyphs].line = (gfxline_t*)draw.result(&draw); } l = font->glyphs[font->num_glyphs].line; @@ -359,7 +405,7 @@ gfxfont_t* gfxfont_load(char*filename, double quality) */ font->glyphs[font->num_glyphs].unicode = 0; if(font->glyphs[font->num_glyphs].name) { - free(font->glyphs[font->num_glyphs].name); + free((void*)font->glyphs[font->num_glyphs].name); font->glyphs[font->num_glyphs].name = 0; } FT_Done_Glyph(glyph);