X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfalignzones.c;h=36ddd341ec60e8675ccb2dbbc8368695a8a1d665;hb=2c719855eac434f01d47ba0717d76de65939d74e;hp=19619036c8da726fb4f0ca365ffb760879933c88;hpb=d040bee21c66541e231a68fea4936328e4ce4c39;p=swftools.git diff --git a/lib/modules/swfalignzones.c b/lib/modules/swfalignzones.c index 1961903..36ddd34 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++) { @@ -156,6 +156,8 @@ static void draw_char(SWFFONT * f, int nr, float*row, float*column, SRECT b) y = l->y; l = l->next; } + swf_Shape2Free(s); + free(s); } static ALIGNZONE detect_for_char(SWFFONT * f, int nr, float*row, float*column, SRECT font_bbox, SRECT char_bbox) @@ -169,7 +171,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, @@ -210,9 +212,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); @@ -231,7 +232,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; + for(s=0;suse->num_neighbors;s++) { + int char1 = f->use->neighbors[s].char1; + int char2 = f->use->neighbors[s].char2; + if(char1 == t || char2 == t) { + int other = t==char1?char2:char1; + draw_char(f, other, row, column, bounds); + drawn++; + } + } + + for(s=0;s<=height;s++) { + column[t] /= drawn*2; + } + memset(row, 0, sizeof(float)*(width+1)); draw_char(f, t, row, column, bounds); @@ -245,6 +264,26 @@ void swf_FontCreateAlignZones(SWFFONT * f) } } +void swf_FontPostprocess(SWF*swf) +{ + TAG*tag = swf->firstTag; + while(tag) { + TAG*next = tag->next; + if(tag->id == ST_DEFINEFONT3) { + U16 id = swf_GetDefineID(tag); + SWFFONT*font = 0; + swf_FontExtract(swf, id, &font); + if(!font->alignzones) { + swf_FontCreateAlignZones(font); + tag = swf_InsertTag(tag, ST_DEFINEFONTALIGNZONES); + swf_FontSetAlignZones(tag, font); + } + swf_FontFree(font); + } + tag = next; + } +} + void swf_FontSetAlignZones(TAG*t, SWFFONT *f) { swf_SetU16(t, f->id); @@ -271,4 +310,3 @@ void swf_FontSetAlignZones(TAG*t, SWFFONT *f) } } -