void wrapbmp_flush(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings, int allow_full_justification) { BMPREGION region; WILLUSBITMAP *bmp8,_bmp8; int just; WRAPBMP *wrapbmp; /* int gap,nomss,dh; */ // char filename[256]; #if (WILLUSDEBUGX & 4) k2printf("@wrapbmp_flush()\n"); #endif /* Ignore if not re-flowing text */ if (!k2settings->text_wrap) return; wrapbmp=&masterinfo->wrapbmp; if (wrapbmp==NULL || wrapbmp->just_flushed_internal) return; #if (WILLUSDEBUGX & 4) k2printf(" wrapbmp=%p\n",wrapbmp); k2printf(" wrapbmp->bmp.width=%d\n",wrapbmp->bmp.width); #endif if (wrapbmp->bmp.width<=0) { wrapbmp->just_flushed_internal=1; return; } #if (WILLUSDEBUGX & 4) k2printf(" Past width check\n"); #endif /* { char filename[256]; int i; static int bcount=0; for (i=0;i<wrapbmp->bmp.height;i++) { unsigned char *p; int j; p=bmp_rowptr_from_top(&wrapbmp->bmp,i); for (j=0;j<wrapbmp->bmp.width;j++) if (p[j]>240) p[j]=192; } sprintf(filename,"out%05d.png",bcount++); bmp_write(wrapbmp,filename,stdout,100); } */ bmpregion_init(®ion); region.c1=0; region.c2=wrapbmp->bmp.width-1; region.r1=0; region.r2=wrapbmp->bmp.height-1; region.bbox.rowbase=wrapbmp->base; region.bmp=&wrapbmp->bmp; region.bgcolor=wrapbmp->bgcolor; region.dpi=k2settings->src_dpi; #if (WILLUSDEBUGX & 4) k2printf("Bitmap is %d x %d (baseline=%d)\n",wrapbmp->bmp.width,wrapbmp->bmp.height,wrapbmp->base); #endif if (wrapbmp->bmp.bpp==24) { bmp8=&_bmp8; bmp_init(bmp8); bmp_convert_to_greyscale_ex(bmp8,&wrapbmp->bmp); region.bmp8=bmp8; } else region.bmp8=&wrapbmp->bmp; /* Calculate lcheight and capheight */ bmpregion_calc_bbox(®ion,k2settings,1); region.bbox.rowbase=wrapbmp->base; region.bbox.rowheight=wrapbmp->textrow.rowheight; region.bbox.gap=wrapbmp->textrow.rowheight-(region.r2-region.r1+1); region.bbox.gapblank=wrapbmp->textrow.gapblank; region.bbox.type=REGION_TYPE_TEXTLINE; region.wrectmaps=&wrapbmp->wrectmaps; if (!allow_full_justification) just = (wrapbmp->just & 0xcf) | 0x20; else just = wrapbmp->just; /* ** For now, set pageinfo=NULL in calls to bmpregion_add because the ** pageinfo processing assumes that the BMPREGION structure it is working ** with is using the original source bitmap, not the wrapbmp bitmap. ** This means that word wrapping can't use the pageinfo structure for now. */ { int npr; double gap; npr=masterinfo->mandatory_region_gap; gap=masterinfo->page_region_gap_in; /* ** Temporarily set masterinfo->mandatory_region_gap to what it was when ** wrapbmp_add() was called. */ masterinfo->mandatory_region_gap=wrapbmp->mandatory_region_gap; masterinfo->page_region_gap_in=wrapbmp->page_region_gap_in; #if (WILLUSDEBUGX & 0x200) aprintf(ANSI_RED "mi->mandatory_region_gap temp change to %d by wrap_flush." ANSI_NORMAL "\n",masterinfo->mandatory_region_gap); #endif #if (WILLUSDEBUGX & 1) printf("wrapbmp_flush calling bmpregion_add() w/bbox.rowheight=%d\n",region.bbox.rowheight); #endif bmpregion_add(®ion,k2settings,masterinfo,0,0,0,-1.0,just,2, 0xf,wrapbmp->bmp.height-1-wrapbmp->base,-1); /* ** Restore masterinfo->mandatory_region_gap */ masterinfo->mandatory_region_gap=npr; masterinfo->page_region_gap_in=gap; #if (WILLUSDEBUGX & 0x200) aprintf(ANSI_RED "mi->mandatory_region_gap temp change back to %d by wrap_flush." ANSI_NORMAL "\n",masterinfo->mandatory_region_gap); #endif } wrectmaps_clear(&wrapbmp->wrectmaps); bmpregion_free(®ion); if (wrapbmp->bmp.bpp==24) bmp_free(bmp8); wrapbmp_reset(wrapbmp); }
void wrapbmp_flush(MASTERINFO *masterinfo,K2PDFOPT_SETTINGS *k2settings, int allow_full_justification,int use_bgi) { BMPREGION region; WILLUSBITMAP *bmp8,_bmp8; int gap,just,nomss,dh; int *colcount,*rowcount; static char *funcname="wrapbmp->flush"; WRAPBMP *wrapbmp; // char filename[256]; wrapbmp=&masterinfo->wrapbmp; if (wrapbmp->bmp.width<=0) { if (use_bgi==1 && wrapbmp->beginning_gap_internal > 0) masterinfo_add_gap_src_pixels(masterinfo,k2settings, wrapbmp->beginning_gap_internal,"wrapbmp->bgi0"); wrapbmp->beginning_gap_internal=-1; wrapbmp->last_h5050_internal=-1; if (use_bgi) wrapbmp->just_flushed_internal=1; return; } #ifdef WILLUSDEBUG printf("@wrapbmp->flush()\n"); #endif /* { char filename[256]; int i; static int bcount=0; for (i=0;i<wrapbmp->bmp.height;i++) { unsigned char *p; int j; p=bmp_rowptr_from_top(&wrapbmp->bmp,i); for (j=0;j<wrapbmp->bmp.width;j++) if (p[j]>240) p[j]=192; } sprintf(filename,"out%05d.png",bcount++); bmp_write(wrapbmp,filename,stdout,100); } */ colcount=rowcount=NULL; willus_dmem_alloc_warn(19,(void **)&colcount,(wrapbmp->bmp.width+16)*sizeof(int),funcname,10); willus_dmem_alloc_warn(20,(void **)&rowcount,(wrapbmp->bmp.height+16)*sizeof(int),funcname,10); region.c1=0; region.c2=wrapbmp->bmp.width-1; region.r1=0; region.r2=wrapbmp->bmp.height-1; region.rowbase=wrapbmp->base; region.bmp=&wrapbmp->bmp; region.bgcolor=wrapbmp->bgcolor; region.dpi=k2settings->src_dpi; #ifdef WILLUSDEBUG printf("Bitmap is %d x %d (baseline=%d)\n",wrapbmp->bmp.width,wrapbmp->bmp.height,wrapbmp->base); #endif /* Sanity check on row spacing -- don't let it be too large. */ nomss = wrapbmp->rhmax*1.7; /* Nominal single-spaced height for this row */ if (k2settings->last_rowbase_internal<0) dh = 0; else { dh=(int)(wrapbmp->line_spacing-k2settings->last_rowbase_internal - 1.2*fabs(k2settings->vertical_line_spacing)*nomss +.5); if (k2settings->vertical_line_spacing < 0.) { int dh1; if (wrapbmp->maxgap > 0) dh1 = region.rowbase+1-wrapbmp->rhmax-wrapbmp->maxgap; else dh1=(int)(wrapbmp->line_spacing-k2settings->last_rowbase_internal- 1.2*nomss+.5); if (dh1 > dh) dh =dh1; } } if (dh>0) { #ifdef WILLUSDEBUG aprintf(ANSI_YELLOW "dh > 0 = %d" ANSI_NORMAL "\n",dh); printf(" wrapbmp->line_spacing=%d\n",wrapbmp->line_spacing); printf(" nomss = %d\n",nomss); printf(" vls = %g\n",k2settings->vertical_line_spacing); printf(" lrbi=%d\n",k2settings->last_rowbase_internal); printf(" wrapbmp->maxgap=%d\n",wrapbmp->maxgap); printf(" wrapbmp->rhmax=%d\n",wrapbmp->rhmax); #endif region.r1 = dh; /* if (dh>200) { bmp_write(wrapbmp,"out.png",stdout,100); exit(10); } */ } if (wrapbmp->bmp.bpp==24) { bmp8=&_bmp8; bmp_init(bmp8); bmp_convert_to_greyscale_ex(bmp8,&wrapbmp->bmp); region.bmp8=bmp8; } else region.bmp8=&wrapbmp->bmp; if (k2settings->gap_override_internal > 0) { region.r1=wrapbmp->base-wrapbmp->rhmax+1; if (region.r1<0) region.r1=0; if (region.r1>wrapbmp->base) region.r1=wrapbmp->base; gap=k2settings->gap_override_internal; k2settings->gap_override_internal = -1; } else { if (wrapbmp->height_extended) gap = wrapbmp->gap; else gap = 0; } #ifdef WILLUSDEBUG printf("wf: gap=%d\n",gap); #endif if (gap>0) masterinfo_add_gap_src_pixels(masterinfo,k2settings,gap,"wrapbmp"); if (!allow_full_justification) just = (wrapbmp->just & 0xcf) | 0x20; else just = wrapbmp->just; /* ** For now, set pageinfo=NULL in calls to bmpregion_add because the ** pageinfo processing assumes that the BMPREGION structure it is working ** with is using the original source bitmap, not the wrapbmp bitmap. ** This means that word wrapping can't use the pageinfo structure for now. */ bmpregion_add(®ion,k2settings,NULL,masterinfo,0,0,0,-1.0,just,2, colcount,rowcount,0xf,wrapbmp->bmp.height-1-wrapbmp->base); if (wrapbmp->bmp.bpp==24) bmp_free(bmp8); willus_dmem_free(20,(double **)&rowcount,funcname); willus_dmem_free(19,(double **)&colcount,funcname); wrapbmp->bmp.width=0; wrapbmp->bmp.height=0; wrapbmp->line_spacing=-1; wrapbmp->gap=-1; wrapbmp->rhmax=-1; wrapbmp->thmax=-1; wrapbmp->hyphen.ch=-1; if (use_bgi==1 && wrapbmp->beginning_gap_internal > 0) masterinfo_add_gap_src_pixels(masterinfo,k2settings, wrapbmp->beginning_gap_internal,"wrapbmp->bgi1"); wrapbmp->beginning_gap_internal = -1; wrapbmp->last_h5050_internal = -1; if (use_bgi) wrapbmp->just_flushed_internal=1; }