X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfalignzones.c;h=21780d35fca64ecfe2765e0297458b71d7664a7b;hb=18c92a7b9532ccc8ad219fa4a2f83cdc651ec3e1;hp=d58cea2197fb06033355911af56dcd4aefbb84d7;hpb=e584fab17969f34332c92f7bf67ca2926668e197;p=swftools.git diff --git a/lib/modules/swfalignzones.c b/lib/modules/swfalignzones.c index d58cea2..21780d3 100644 --- a/lib/modules/swfalignzones.c +++ b/lib/modules/swfalignzones.c @@ -40,7 +40,7 @@ static void find_best(float*_row, int width, int*_x1, int*_x2, int min_size, int float max1=-1e20,max2=-1e20; int t; float*row = malloc(sizeof(float)*(width+1)); - int filter_size = 20; + int filter_size = 10; float* filter = malloc(sizeof(float)*(filter_size*2+1)); double var = filter_size/3; for(t=-filter_size;t<=filter_size;t++) { @@ -60,6 +60,7 @@ static void find_best(float*_row, int width, int*_x1, int*_x2, int min_size, int } row[t] = sum; } + free(filter); for(t=from;t<=to;t++) { if(row[t]>max1) { @@ -72,6 +73,14 @@ static void find_best(float*_row, int width, int*_x1, int*_x2, int min_size, int if(num<=1) { *_x1=x1; } else { + /* this code is slightly wrong, in that it assumes that the glyph distortion problem + gets worse when the font sizes get smaller. it doesn't. in fact, the smaller + the font size, the more of the scaling bugs disappear (http://www.quiss.org/files/scaletest.swf) + A better way would probably to use the font size you need for the two alignzones + to come to lie in different pixels, which what I think is what makes the problems + appear/disappear. + */ + double scale = min_size/1024.0; for(t=from;t<=to;t++) { if(t==x1) { @@ -107,7 +116,6 @@ static void find_best(float*_row, int width, int*_x1, int*_x2, int min_size, int *_x2=x2; } - free(row); } @@ -161,7 +169,7 @@ static ALIGNZONE detect_for_char(SWFFONT * f, int nr, float*row, float*column, S /* find two best x values */ int x1=-1,y1=-1,x2=-1,y2=-1; - int nr_x = 1; + int nr_x = 0; find_best(row, width, &x1, &x2, f->use->smallest_size, char_bbox.xmin - font_bbox.xmin, char_bbox.xmax - font_bbox.xmin, nr_x, @@ -192,7 +200,7 @@ void swf_FontCreateAlignZones(SWFFONT * f) f->alignzones = (ALIGNZONE*)rfx_calloc(sizeof(ALIGNZONE)*f->numchars); f->alignzone_flags = FONTALIGN_MEDIUM; - if(!f->layout) { + if(!f->layout || !f->use) { int t; for(t=0;tnumchars;t++) { // just align the baseline @@ -202,9 +210,8 @@ void swf_FontCreateAlignZones(SWFFONT * f) f->alignzones[t].dy = 0xffff;//floatToF16(460.80 / 1024.0); } } else { - int t; SRECT bounds = {0,0,0,0}; - + int t; for(t=0;tnumchars;t++) { SRECT b = f->layout->bounds[t]; negate_y(&b); @@ -223,7 +230,25 @@ void swf_FontCreateAlignZones(SWFFONT * f) for(t=0;t<=height;t++) {column_global[t]/=f->numchars/2;} for(t=0;tnumchars;t++) { - memcpy(column, column_global, sizeof(float)*(height+1)); + //memcpy(column, column_global, sizeof(float)*(height+1)); + + memset(column, 0, sizeof(float)*(height+1)); + int s; + int drawn = 0; + printf("[font %d] pairing %c with ", f->id, f->glyph2ascii[t]); + for(s=0;suse->num_neighbors;s++) { + if(f->use->neighbors[s].char2 == t) { + printf("%c (%d) ", f->glyph2ascii[f->use->neighbors[s].char1], f->use->neighbors[s].num); + draw_char(f, f->use->neighbors[s].char1, row, column, bounds); + drawn++; + } + } + printf("\n"); + + for(s=0;s<=height;s++) { + column[t] /= drawn*2; + } + memset(row, 0, sizeof(float)*(width+1)); draw_char(f, t, row, column, bounds); @@ -231,6 +256,9 @@ void swf_FontCreateAlignZones(SWFFONT * f) negate_y(&b); f->alignzones[t] = detect_for_char(f, t, row, column, bounds, b); } + free(row); + free(column_global); + free(column); } }