From 602d0f0a1c8ad614029f235cc6ff38bfe26334e8 Mon Sep 17 00:00:00 2001 From: kramm Date: Thu, 13 Jun 2002 11:37:10 +0000 Subject: [PATCH] added antialiasing of type 3 fonts. --- pdf2swf/SWFOutputDev.cc | 121 +++++++++++++++++++++++++++++++++++++++++++---- pdf2swf/pdf2swf.cc | 2 +- pdf2swf/swfoutput.cc | 43 +++++++++-------- pdf2swf/swfoutput.h | 4 +- 4 files changed, 140 insertions(+), 30 deletions(-) diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index fe0b573..17e3788 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -1218,9 +1218,61 @@ void SWFOutputDev::updateFont(GfxState *state) int pic_xids[1024]; int pic_yids[1024]; int pic_ids[1024]; +int pic_width[1024]; +int pic_height[1024]; int picpos = 0; int pic_id = 0; +#define SQR(x) ((x)*(x)) + +unsigned char* antialize(unsigned char*data, int width, int height, int newwidth, int newheight, int palettesize) +{ + if((newwidth<2 || newheight<2) || + (width<=newwidth || height<=newheight)) + return 0; + unsigned char*newdata; + int x,y; + newdata= (unsigned char*)malloc(newwidth*newheight); + int t; + double fx = (double)(width)/newwidth; + double fy = (double)(height)/newheight; + double px = 0; + int blocksize = (int)(8192/(fx*fy)); + int r = 8192*256/palettesize; + for(x=0;xgetFillRGB(&rgb); + memset(pal,255,sizeof(pal)); pal[0].r = (int)(rgb.r*255); pal[0].g = (int)(rgb.g*255); pal[0].b = (int)(rgb.b*255); pal[0].a = 255; pal[1].r = 0; pal[1].g = 0; pal[1].b = 0; pal[1].a = 0; + int numpalette = 2; xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17; yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23; + int realwidth = (int)sqrt(SQR(x2-x3) + SQR(y2-y3)); + int realheight = (int)sqrt(SQR(x1-x2) + SQR(y1-y2)); for (y = 0; y < height; ++y) for (x = 0; x < width; ++x) { imgStr->getPixel(buf); - // if(invert) buf[0]=255-buf[0]? + if(invert) + buf[0]=1-buf[0]; pic[width*y+x] = buf[0]; xid+=x*buf[0]+1; - yid+=y*buf[0]+1; + yid+=y*buf[0]*3+1; + } + + /* the size of the drawn image is added to the identifier + as the same image may require different bitmaps if displayed + at different sizes (due to antialiasing): */ + if(type3active) { + xid += realwidth; + yid += realheight; } int t,found = -1; for(t=0;tymax) ymax=y4; if(x4linewidth,&obj->strokergb); //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb); - fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0); + fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1); swf_SetU16(tag, myshapeid); r.xmin = (int)(xmin*20); r.ymin = (int)(ymin*20); @@ -1472,11 +1477,11 @@ int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int si return bitid; } -int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey, +int swfoutput_drawimagelosslessN(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey, double x1,double y1, double x2,double y2, double x3,double y3, - double x4,double y4) + double x4,double y4, int n) { TAG*oldtag; U8*mem2 = 0; @@ -1505,7 +1510,7 @@ int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int s oldtag = tag; tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2); swf_SetU16(tag, bitid); - if(swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256)<0) { + if(swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, n)<0) { swf_DeleteTag(tag); tag = oldtag; return -1; diff --git a/pdf2swf/swfoutput.h b/pdf2swf/swfoutput.h index 55b13b1..1c66788 100644 --- a/pdf2swf/swfoutput.h +++ b/pdf2swf/swfoutput.h @@ -109,11 +109,11 @@ int swfoutput_drawimagelossless(struct swfoutput*, RGBA*pic, int sizex, int size double x2,double y2, double x3,double y3, double x4,double y4); -int swfoutput_drawimagelossless256(struct swfoutput*, U8*pic, RGBA*pal, int sizex, int sizey, +int swfoutput_drawimagelosslessN(struct swfoutput*, U8*pic, RGBA*pal, int sizex, int sizey, double x1,double y1, double x2,double y2, double x3,double y3, - double x4,double y4); + double x4,double y4, int n); void swfoutput_drawimageagain(struct swfoutput*, int id, int sizex, int sizey, double x1,double y1, double x2,double y2, -- 1.7.10.4