3 Output Device which creates a bitmap.
5 Swftools is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 Swftools is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with swftools; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 #include "BitmapOutputDev.h"
25 #include "GFXOutputDev.h"
26 #include "SplashBitmap.h"
27 #include "SplashPattern.h"
31 #include "../devices/record.h"
35 #define UNKNOWN_BOUNDING_BOX 0,0,0,0
37 static SplashColor splash_white = {255,255,255};
38 static SplashColor splash_black = {0,0,0};
40 ClipState::ClipState()
47 BitmapOutputDev::BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
51 this->xref = doc->getXRef();
53 /* color graphic output device, for creating bitmaps */
54 this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
56 /* color mode for binary bitmaps */
57 SplashColorMode colorMode = splashModeMono1;
59 /* two devices for testing things against clipping: one clips, the other doesn't */
60 this->clip0dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
61 this->clip1dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
63 /* device indicating where polygonal pixels were drawn */
64 this->boolpolydev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
65 /* device indicating where text pixels were drawn */
66 this->booltextdev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
68 /* device for handling texts and links */
69 this->gfxdev = new GFXOutputDev(info, this->doc);
71 this->rgbdev->startDoc(this->xref);
72 this->boolpolydev->startDoc(this->xref);
73 this->booltextdev->startDoc(this->xref);
74 this->clip0dev->startDoc(this->xref);
75 this->clip1dev->startDoc(this->xref);
77 this->gfxoutput = (gfxdevice_t*)malloc(sizeof(gfxdevice_t));
78 gfxdevice_record_init(this->gfxoutput, 0);
80 this->gfxdev->setDevice(this->gfxoutput);
82 this->config_extrafontdata = 0;
85 //this->clipstates = 0;
87 BitmapOutputDev::~BitmapOutputDev()
90 gfxresult_t*r = this->gfxoutput->finish(this->gfxoutput);
92 free(this->gfxoutput);this->gfxoutput = 0;
95 delete this->bboxpath;this->bboxpath = 0;
98 delete this->rgbdev;this->rgbdev = 0;
101 delete this->gfxdev;this->gfxdev= 0;
103 if(this->boolpolydev) {
104 delete this->boolpolydev;this->boolpolydev = 0;
106 if(this->stalepolybitmap) {
107 delete this->stalepolybitmap;this->stalepolybitmap = 0;
109 if(this->staletextbitmap) {
110 delete this->staletextbitmap;this->staletextbitmap = 0;
112 if(this->booltextdev) {
113 delete this->booltextdev;this->booltextdev = 0;
116 delete this->clip0dev;this->clip0dev = 0;
119 delete this->clip1dev;this->clip1dev = 0;
121 //if(this->clipbitmap) {
122 // delete this->clipbitmap;this->clipbitmap = 0;
124 //if(this->clipdev) {
125 // delete this->clipdev;this->clipdev = 0;
130 GBool BitmapOutputDev::getVectorAntialias()
132 return this->rgbdev->getVectorAntialias();
134 void BitmapOutputDev::setVectorAntialias(GBool vaa)
136 this->rgbdev->setVectorAntialias(vaa);
138 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
142 void BitmapOutputDev::setMove(int x,int y)
144 this->gfxdev->setMove(x,y);
145 this->user_movex = x;
146 this->user_movey = y;
148 void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
150 this->gfxdev->setClip(x1,y1,x2,y2);
151 this->user_clipx1 = x1;
152 this->user_clipy1 = y1;
153 this->user_clipx2 = x2;
154 this->user_clipy2 = y2;
156 void BitmapOutputDev::setParameter(const char*key, const char*value)
158 if(!strcmp(key, "extrafontdata")) {
159 this->config_extrafontdata = atoi(value);
161 this->gfxdev->setParameter(key, value);
163 void BitmapOutputDev::setPageMap(int*page2page, int num_pages)
165 this->gfxdev->setPageMap(page2page, num_pages);
168 void writeBitmap(SplashBitmap*bitmap, char*filename);
169 void writeAlpha(SplashBitmap*bitmap, char*filename);
171 static int dbg_btm_counter=1;
173 void BitmapOutputDev::flushBitmap()
175 int width = rgbdev->getBitmapWidth();
176 int height = rgbdev->getBitmapHeight();
178 if(sizeof(SplashColor)!=3) {
179 msg("<error> sizeof(SplashColor)!=3");
183 /*static int counter=0;
185 writeBitmap(rgbdev->getBitmap(), "test.png");
188 /*static int counter=0;
190 sprintf(filename, "test%d.png", counter++);
191 writeBitmap(rgbbitmap, filename);*/
193 SplashColorPtr rgb = rgbbitmap->getDataPtr();
194 Guchar*alpha = rgbbitmap->getAlphaPtr();
196 Guchar*alpha2 = stalepolybitmap->getDataPtr();
197 int width8 = (stalepolybitmap->getWidth()+7)/8;
200 sprintf(filename, "flush%d_mask.png", dbg_btm_counter);
201 writeAlpha(stalepolybitmap, filename);
202 sprintf(filename, "flush%d_alpha.png", dbg_btm_counter);
203 writeAlpha(rgbbitmap, filename);
204 sprintf(filename, "flush%d_bitmap.png", dbg_btm_counter);
205 writeBitmap(rgbbitmap, filename);*/
207 ibbox_t* boxes = get_bitmap_bboxes((unsigned char*)alpha, width, height);
210 for(b=boxes;b;b=b->next) {
216 /* clip against (-movex, -movey, -movex+width, -movey+height) */
218 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d %dx%d) (clipped against %d,%d,%d,%d)", xmin,ymin,xmax,ymax, xmax-xmin, ymax-ymin,
219 -this->movex, -this->movey, -this->movex+this->width, -this->movey+this->height);
221 if(xmin < -this->movex) {
223 if(xmax < -this->movex) continue;
225 if(ymin < -this->movey) {
227 if(ymax < -this->movey) continue;
229 if(xmax >= -this->movex + this->width) {
230 xmax = -this->movex+this->width;
231 if(xmin >= -this->movex + this->width) continue;
233 if(ymax >= -this->movey + this->height) {
234 ymax = -this->movey+this->height;
235 if(ymin >= -this->movey + this->height) continue;
238 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
241 int rangex = xmax-xmin;
242 int rangey = ymax-ymin;
243 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
244 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
246 img->height = rangey;
248 for(y=0;y<rangey;y++) {
249 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
250 gfxcolor_t*out = &img->data[y*rangex];
251 Guchar*ain = &alpha[(y+ymin)*width+xmin];
252 Guchar*ain2 = &alpha2[(y+ymin)*width8];
253 if(this->emptypage) {
254 for(x=0;x<rangex;x++) {
255 /* the first bitmap on the page doesn't need to have an alpha channel-
256 blend against a white background*/
257 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
258 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
259 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
263 for(x=0;x<rangex;x++) {
264 if(!(ain2[(x+xmin)/8]&(0x80>>((x+xmin)&7)))) {
265 /* cut away pixels that we don't remember drawing (i.e., that are
266 not in the monochrome bitmap). Prevents some "hairlines" showing
267 up to the left and right of bitmaps. */
268 out[x].r = 0;out[x].g = 0;out[x].b = 0;out[x].a = 0;
270 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, this
271 data has non-premultiplied alpha, which is exactly what the output device
272 expects, so don't premultiply it here, either.
274 out[x].r = in[x*3+0];
275 out[x].g = in[x*3+1];
276 out[x].b = in[x*3+2];
283 /* transform bitmap rectangle to "device space" */
297 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
298 dev->fillbitmap(dev, line, img, &m, 0);
301 free(img->data);img->data=0;free(img);img=0;
303 ibbox_destroy(boxes);
305 memset(rgbbitmap->getAlphaPtr(), 0, rgbbitmap->getWidth()*rgbbitmap->getHeight());
306 memset(rgbbitmap->getDataPtr(), 0, rgbbitmap->getRowSize()*rgbbitmap->getHeight());
311 void BitmapOutputDev::flushText()
313 msg("<verbose> Flushing text");
314 gfxdevice_record_flush(this->gfxoutput, this->dev);
319 void writeMonoBitmap(SplashBitmap*btm, char*filename)
321 int width8 = (btm->getWidth()+7)/8;
322 int width = btm->getWidth();
323 int height = btm->getHeight();
324 gfxcolor_t*b = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
325 unsigned char*data = btm->getDataPtr();
327 for(y=0;y<height;y++) {
328 unsigned char*l = &data[width8*y];
329 gfxcolor_t*d = &b[width*y];
330 for(x=0;x<width;x++) {
331 if(l[x>>3]&(128>>(x&7))) {
332 d[x].r = d[x].b = d[x].a = 255;
335 d[x].r = d[x].g = d[x].b = d[x].a = 0;
339 writePNG(filename, (unsigned char*)b, width, height);
343 void writeBitmap(SplashBitmap*bitmap, char*filename)
347 int width = bitmap->getWidth();
348 int height = bitmap->getHeight();
350 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
352 if(bitmap->getMode()==splashModeMono1) {
353 writeMonoBitmap(bitmap, filename);
357 for(y=0;y<height;y++) {
358 gfxcolor_t*line = &data[y*width];
359 for(x=0;x<width;x++) {
360 Guchar c[4] = {0,0,0,0};
361 bitmap->getPixel(x,y,c);
365 line[x].a = bitmap->getAlpha(x,y);
368 writePNG(filename, (unsigned char*)data, width, height);
372 void writeAlpha(SplashBitmap*bitmap, char*filename)
376 int width = bitmap->getWidth();
377 int height = bitmap->getHeight();
379 if(bitmap->getMode()==splashModeMono1) {
380 writeMonoBitmap(bitmap, filename);
384 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
386 for(y=0;y<height;y++) {
387 gfxcolor_t*line = &data[y*width];
388 for(x=0;x<width;x++) {
389 int a = bitmap->getAlpha(x,y);
396 writePNG(filename, (unsigned char*)data, width, height);
400 static const char*STATE_NAME[] = {"parallel", "textabovebitmap", "bitmapabovetext"};
402 int checkAlphaSanity(SplashBitmap*boolbtm, SplashBitmap*alphabtm)
404 assert(boolbtm->getWidth() == alphabtm->getWidth());
405 assert(boolbtm->getHeight() == alphabtm->getHeight());
406 if(boolbtm->getMode()==splashModeMono1) {
410 int width = boolbtm->getWidth();
411 int height = boolbtm->getHeight();
415 for(y=0;y<height;y++) {
416 for(x=0;x<width;x++) {
417 int a1 = alphabtm->getAlpha(x,y);
418 int a2 = boolbtm->getAlpha(x,y);
424 double badness = bad/(double)(width*height);
426 msg("<error> Bitmaps don't correspond: %d out of %d pixels wrong (%.2f%%)", bad, width*height,
430 msg("<notice> %f", badness);
434 static inline GBool fixBBox(int*x1, int*y1, int*x2, int*y2, int width, int height)
436 if(!(*x1|*y1|*x2|*y2)) {
443 if(*x2<=*x1) return gFalse;
444 if(*x2<0) return gFalse;
446 if(*x1>=width) return gFalse;
447 if(*x2>width) *x2=width;
449 if(*y2<=*y1) return gFalse;
450 if(*y2<0) return gFalse;
452 if(*y1>=height) return gFalse;
453 if(*y2>height) *y2=height;
457 static void update_bitmap(SplashBitmap*bitmap, SplashBitmap*update, int x1, int y1, int x2, int y2, char overwrite)
459 assert(bitmap->getMode()==splashModeMono1);
460 assert(update->getMode()==splashModeMono1);
462 int width8 = (bitmap->getWidth()+7)/8;
463 assert(width8 == bitmap->getRowSize());
464 assert(width8 == update->getRowSize());
465 int height = bitmap->getHeight();
466 assert(height == update->getHeight());
468 if(!fixBBox(&x1, &y1, &x2, &y2, bitmap->getWidth(), bitmap->getHeight()))
471 Guchar*b = bitmap->getDataPtr() + y1*width8 + x1/8;
472 Guchar*u = update->getDataPtr() + y1*width8 + x1/8;
474 int xspan = (x2+7)/8 - x1/8;
475 int size = (y2-y1)*width8;
479 for(y=0;y<yspan;y++) {
485 if(((ptroff_t)b&7)==((ptroff_t)u&7)) {
487 for(y=0;y<yspan;y++) {
488 Guchar*e1 = b+xspan-8;
490 while(((ptroff_t)b&7) && b<e1) {
495 *(long long*)b |= *(long long*)u;
507 for(y=0;y<yspan;y++) {
508 for(x=0;x<xspan;x++) {
518 static void clearBooleanBitmap(SplashBitmap*btm, int x1, int y1, int x2, int y2)
520 if(!fixBBox(&x1, &y1, &x2, &y2, btm->getWidth(), btm->getHeight()))
523 if(btm->getMode()==splashModeMono1) {
524 int width8 = (btm->getWidth()+7)/8;
525 assert(width8 == btm->getRowSize());
526 int width = btm->getWidth();
527 int height = btm->getHeight();
528 Guchar*data = btm->getDataPtr();
529 memset(data+y1*width8, 0, width8*(y2-y1));
531 int width = btm->getAlphaRowSize();
532 int height = btm->getHeight();
533 memset(btm->getAlphaPtr(), 0, width*height);
537 void BitmapOutputDev::dbg_newdata(char*newdata)
543 sprintf(filename1, "state%03dboolbitmap_after%s.png", dbg_btm_counter, newdata);
544 sprintf(filename2, "state%03dbooltext_after%s.png", dbg_btm_counter, newdata);
545 sprintf(filename3, "state%03dbitmap_after%s.png", dbg_btm_counter, newdata);
546 msg("<verbose> %s %s %s", filename1, filename2, filename3);
547 writeAlpha(stalepolybitmap, filename1);
548 writeAlpha(booltextbitmap, filename2);
549 writeBitmap(rgbdev->getBitmap(), filename3);
554 GBool BitmapOutputDev::checkNewText(int x1, int y1, int x2, int y2)
556 /* called once some new text was drawn on booltextdev, and
557 before the same thing is drawn on gfxdev */
559 msg("<trace> Testing new text data against current bitmap data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
562 if(intersection(booltextbitmap, stalepolybitmap, x1,y1,x2,y2)) {
563 if(layerstate==STATE_PARALLEL) {
564 /* the new text is above the bitmap. So record that fact. */
565 msg("<verbose> Text is above current bitmap/polygon data");
566 layerstate=STATE_TEXT_IS_ABOVE;
567 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
568 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
569 /* there's a bitmap above the (old) text. So we need
570 to flush out that text, and record that the *new*
571 text is now *above* the bitmap
573 msg("<verbose> Text is above current bitmap/polygon data (which is above some other text)");
575 layerstate=STATE_TEXT_IS_ABOVE;
578 /* re-apply the update (which we would otherwise lose) */
579 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 1);
582 /* we already know that the current text section is
583 above the current bitmap section- now just new
584 bitmap data *and* new text data was drawn, and
585 *again* it's above the current bitmap. */
586 msg("<verbose> Text is still above current bitmap/polygon data");
587 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
590 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
593 /* clear the thing we just drew from our temporary drawing bitmap */
594 clearBooleanBitmap(booltextbitmap, x1, y1, x2, y2);
598 GBool BitmapOutputDev::checkNewBitmap(int x1, int y1, int x2, int y2)
600 /* similar to checkNewText() above, only in reverse */
601 msg("<trace> Testing new graphics data against current text data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
604 if(intersection(boolpolybitmap, staletextbitmap, x1,y1,x2,y2)) {
605 if(layerstate==STATE_PARALLEL) {
606 msg("<verbose> Bitmap is above current text data");
607 layerstate=STATE_BITMAP_IS_ABOVE;
608 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
609 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
610 msg("<verbose> Bitmap is above current text data (which is above some bitmap)");
612 layerstate=STATE_BITMAP_IS_ABOVE;
614 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 1);
617 msg("<verbose> Bitmap is still above current text data");
618 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
621 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
624 /* clear the thing we just drew from our temporary drawing bitmap */
625 clearBooleanBitmap(boolpolybitmap, x1, y1, x2, y2);
630 //void checkNewText() {
631 // Guchar*alpha = rgbbitmap->getAlphaPtr();
632 // Guchar*charpixels = clip1bitmap->getDataPtr();
634 // for(yy=0;yy<height;yy++) {
635 // Guchar*aline = &alpha[yy*width];
636 // Guchar*cline = &charpixels[yy*width8];
637 // for(xx=0;xx<width;xx++) {
639 // int bytepos = xx>>3;
640 // /* TODO: is the bit order correct? */
641 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
648 GBool BitmapOutputDev::clip0and1differ(int x1,int y1,int x2,int y2)
650 if(clip0bitmap->getMode()==splashModeMono1) {
651 int width = clip0bitmap->getWidth();
652 int width8 = (width+7)/8;
653 int height = clip0bitmap->getHeight();
655 if(!fixBBox(&x1,&y1,&x2,&y2,width,height)) {
656 /* area is outside or null */
660 SplashBitmap*clip0 = clip0bitmap;
661 SplashBitmap*clip1 = clip1bitmap;
667 unsigned char*row1 = &clip0bitmap->getDataPtr()[width8*y+x18];
668 unsigned char*row2 = &clip1bitmap->getDataPtr()[width8*y+x18];
669 if(memcmp(row1, row2, x28-x18)) {
675 SplashBitmap*clip0 = clip0bitmap;
676 SplashBitmap*clip1 = clip1bitmap;
677 int width = clip0->getAlphaRowSize();
678 int height = clip0->getHeight();
680 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
684 Guchar*a0 = clip0->getAlphaPtr();
685 Guchar*a1 = clip1->getAlphaPtr();
690 if(a0[y*width+x]!=a1[y*width+x]) {
698 char differs2 = memcmp(a0, a1, width*height);
699 if(differs && !differs2)
700 msg("<warning> Strange internal error (2)");
701 else if(!differs && differs2) {
702 msg("<warning> Bad Bounding Box: Difference in clip0 and clip1 outside bbox");
703 msg("<warning> %d %d %d %d", x1, y1, x2, y2);
709 GBool compare8(unsigned char*data1, unsigned char*data2, int len)
713 if(((ptroff_t)data1&7)==((ptroff_t)data2&7)) {
714 // oh good, we can align both to 8 byte
715 while((ptroff_t)data1&7) {
724 /* use 64 bit for the (hopefully aligned) middle section */
726 long long unsigned int*d1 = (long long unsigned int*)data1;
727 long long unsigned int*d2 = (long long unsigned int*)data2;
728 long long unsigned int x = 0;
740 if(data1[t]&data2[t]) {
747 GBool BitmapOutputDev::intersection(SplashBitmap*boolpoly, SplashBitmap*booltext, int x1, int y1, int x2, int y2)
749 if(boolpoly->getMode()==splashModeMono1) {
750 /* alternative implementation, using one bit per pixel-
751 needs the no-dither patch in xpdf */
753 int width = boolpoly->getWidth();
754 int height = boolpoly->getHeight();
756 if(!fixBBox(&x1,&y1,&x2,&y2, width, height)) {
760 Guchar*polypixels = boolpoly->getDataPtr();
761 Guchar*textpixels = booltext->getDataPtr();
763 int width8 = (width+7)/8;
768 polypixels+=y1*width8+x1/8;
769 textpixels+=y1*width8+x1/8;
770 runx=(x2+7)/8 - x1/8;
777 /*assert(sizeof(unsigned long long int)==8);
778 if(((ptroff_t)polypixels&7) || ((ptroff_t)textpixels&7)) {
779 //msg("<warning> Non-optimal alignment");
783 unsigned char*data1 = (unsigned char*)polypixels;
784 unsigned char*data2 = (unsigned char*)textpixels;
785 msg("<verbose> Testing area (%d,%d,%d,%d), runx=%d,runy=%d", x1,y1,x2,y2, runx, runy);
786 for(y=0;y<runy;y++) {
787 if(compare8(data1,data2,runx))
794 int width = boolpoly->getAlphaRowSize();
795 int height = boolpoly->getHeight();
797 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
800 Guchar*polypixels = boolpoly->getAlphaPtr();
801 Guchar*textpixels = booltext->getAlphaPtr();
808 if(polypixels[width*y+x]&&textpixels[width*y+x])
812 int ax1=0,ay1=0,ax2=0,ay2=0;
813 for(y=0;y<height;y++) {
814 for(x=0;x<width;x++) {
815 if(polypixels[width*y+x]&&textpixels[width*y+x]) {
817 if(!(ax1|ay1|ax2|ay2)) {
829 if(overlap1 && !overlap2)
830 msg("<warning> strange internal error");
831 if(!overlap1 && overlap2) {
832 msg("<warning> Bad bounding box: intersection outside bbox");
833 msg("<warning> given bbox: %d %d %d %d", x1, y1, x2, y2);
834 msg("<warning> changed area: %d %d %d %d", ax1, ay1, ax2, ay2);
841 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
844 state->transform(crop_x1,crop_y1,&x1,&y1);
845 state->transform(crop_x2,crop_y2,&x2,&y2);
846 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
847 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
849 this->movex = -(int)x1 - user_movex;
850 this->movey = -(int)y1 - user_movey;
852 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
858 this->width = (int)(x2-x1);
859 this->height = (int)(y2-y1);
861 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
862 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
863 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
864 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
865 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
866 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
868 boolpolybitmap = boolpolydev->getBitmap();
869 stalepolybitmap = new SplashBitmap(boolpolybitmap->getWidth(), boolpolybitmap->getHeight(), 1, boolpolybitmap->getMode(), 0);
870 assert(stalepolybitmap->getRowSize() == boolpolybitmap->getRowSize());
872 booltextbitmap = booltextdev->getBitmap();
873 staletextbitmap = new SplashBitmap(booltextbitmap->getWidth(), booltextbitmap->getHeight(), 1, booltextbitmap->getMode(), 0);
874 assert(staletextbitmap->getRowSize() == booltextbitmap->getRowSize());
876 msg("<debug> startPage %dx%d (%dx%d)", this->width, this->height, booltextbitmap->getWidth(), booltextbitmap->getHeight());
878 clip0bitmap = clip0dev->getBitmap();
879 clip1bitmap = clip1dev->getBitmap();
880 rgbbitmap = rgbdev->getBitmap();
882 flushText(); // write out the initial clipping rectangle
884 /* just in case any device did draw a white background rectangle
889 this->layerstate = STATE_PARALLEL;
891 msg("<debug> startPage done");
894 void BitmapOutputDev::endPage()
896 msg("<verbose> endPage (BitmapOutputDev)");
898 /* notice: we're not fully done yet with this page- there might still be
899 a few calls to drawLink() yet to come */
901 void BitmapOutputDev::finishPage()
903 msg("<verbose> finishPage (BitmapOutputDev)");
906 if(layerstate == STATE_BITMAP_IS_ABOVE) {
914 /* splash will now destroy alpha, and paint the
915 background color into the "holes" in the bitmap */
916 boolpolydev->endPage();
917 booltextdev->endPage();
923 GBool BitmapOutputDev::upsideDown()
925 boolpolydev->upsideDown();
926 booltextdev->upsideDown();
927 clip0dev->upsideDown();
928 clip1dev->upsideDown();
929 return rgbdev->upsideDown();
932 GBool BitmapOutputDev::useDrawChar()
934 boolpolydev->useDrawChar();
935 booltextdev->useDrawChar();
936 clip0dev->useDrawChar();
937 clip1dev->useDrawChar();
938 return rgbdev->useDrawChar();
941 GBool BitmapOutputDev::useTilingPatternFill()
943 boolpolydev->useTilingPatternFill();
944 booltextdev->useTilingPatternFill();
945 clip0dev->useTilingPatternFill();
946 clip1dev->useTilingPatternFill();
947 return rgbdev->useTilingPatternFill();
950 GBool BitmapOutputDev::useShadedFills()
952 boolpolydev->useShadedFills();
953 booltextdev->useShadedFills();
954 clip0dev->useShadedFills();
955 clip1dev->useShadedFills();
956 return rgbdev->useShadedFills();
959 GBool BitmapOutputDev::useDrawForm()
961 boolpolydev->useDrawForm();
962 booltextdev->useDrawForm();
963 clip0dev->useDrawForm();
964 clip1dev->useDrawForm();
965 return rgbdev->useDrawForm();
968 GBool BitmapOutputDev::interpretType3Chars()
970 boolpolydev->interpretType3Chars();
971 booltextdev->interpretType3Chars();
972 clip0dev->interpretType3Chars();
973 clip1dev->interpretType3Chars();
974 return rgbdev->interpretType3Chars();
977 GBool BitmapOutputDev::needNonText()
979 boolpolydev->needNonText();
980 booltextdev->needNonText();
981 clip0dev->needNonText();
982 clip1dev->needNonText();
983 return rgbdev->needNonText();
985 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
986 int rotate, GBool useMediaBox, GBool crop,
987 int sliceX, int sliceY, int sliceW, int sliceH,
988 GBool printing, Catalog *catalog,
989 GBool (*abortCheckCbk)(void *data),
990 void *abortCheckCbkData)
994 void BitmapOutputDev::setDefaultCTM(double *ctm)
996 boolpolydev->setDefaultCTM(ctm);
997 booltextdev->setDefaultCTM(ctm);
998 rgbdev->setDefaultCTM(ctm);
999 clip0dev->setDefaultCTM(ctm);
1000 clip1dev->setDefaultCTM(ctm);
1001 gfxdev->setDefaultCTM(ctm);
1003 void BitmapOutputDev::saveState(GfxState *state)
1005 boolpolydev->saveState(state);
1006 booltextdev->saveState(state);
1007 rgbdev->saveState(state);
1008 clip0dev->saveState(state);
1009 clip1dev->saveState(state);
1011 /*ClipState*cstate = new ClipState();
1012 cstate->next = this->clipstates;
1013 this->clipstates = cstate;*/
1015 void BitmapOutputDev::restoreState(GfxState *state)
1017 boolpolydev->restoreState(state);
1018 booltextdev->restoreState(state);
1019 rgbdev->restoreState(state);
1020 clip0dev->restoreState(state);
1021 clip1dev->restoreState(state);
1023 /*if(this->clipstates) {
1024 ClipState*old = this->clipstates;
1026 gfxdev->restoreState(state);
1028 this->clipstates = this->clipstates->next;
1031 msg("<error> invalid restoreState()");
1034 void BitmapOutputDev::updateAll(GfxState *state)
1036 boolpolydev->updateAll(state);
1037 booltextdev->updateAll(state);
1038 rgbdev->updateAll(state);
1039 clip0dev->updateAll(state);
1040 clip1dev->updateAll(state);
1041 gfxdev->updateAll(state);
1043 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
1045 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1046 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1047 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1048 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1049 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1050 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1052 void BitmapOutputDev::updateLineDash(GfxState *state)
1054 boolpolydev->updateLineDash(state);
1055 booltextdev->updateLineDash(state);
1056 rgbdev->updateLineDash(state);
1057 clip0dev->updateLineDash(state);
1058 clip1dev->updateLineDash(state);
1059 gfxdev->updateLineDash(state);
1061 void BitmapOutputDev::updateFlatness(GfxState *state)
1063 boolpolydev->updateFlatness(state);
1064 booltextdev->updateFlatness(state);
1065 rgbdev->updateFlatness(state);
1066 clip0dev->updateFlatness(state);
1067 clip1dev->updateFlatness(state);
1068 gfxdev->updateFlatness(state);
1070 void BitmapOutputDev::updateLineJoin(GfxState *state)
1072 boolpolydev->updateLineJoin(state);
1073 booltextdev->updateLineJoin(state);
1074 rgbdev->updateLineJoin(state);
1075 clip0dev->updateLineJoin(state);
1076 clip1dev->updateLineJoin(state);
1077 gfxdev->updateLineJoin(state);
1079 void BitmapOutputDev::updateLineCap(GfxState *state)
1081 boolpolydev->updateLineCap(state);
1082 booltextdev->updateLineCap(state);
1083 rgbdev->updateLineCap(state);
1084 clip0dev->updateLineCap(state);
1085 clip1dev->updateLineCap(state);
1086 gfxdev->updateLineCap(state);
1088 void BitmapOutputDev::updateMiterLimit(GfxState *state)
1090 boolpolydev->updateMiterLimit(state);
1091 booltextdev->updateMiterLimit(state);
1092 rgbdev->updateMiterLimit(state);
1093 clip0dev->updateMiterLimit(state);
1094 clip1dev->updateMiterLimit(state);
1095 gfxdev->updateMiterLimit(state);
1097 void BitmapOutputDev::updateLineWidth(GfxState *state)
1099 boolpolydev->updateLineWidth(state);
1100 booltextdev->updateLineWidth(state);
1101 rgbdev->updateLineWidth(state);
1102 clip0dev->updateLineWidth(state);
1103 clip1dev->updateLineWidth(state);
1104 gfxdev->updateLineWidth(state);
1106 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
1108 boolpolydev->updateStrokeAdjust(state);
1109 booltextdev->updateStrokeAdjust(state);
1110 rgbdev->updateStrokeAdjust(state);
1111 clip0dev->updateStrokeAdjust(state);
1112 clip1dev->updateStrokeAdjust(state);
1113 gfxdev->updateStrokeAdjust(state);
1115 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
1117 boolpolydev->updateFillColorSpace(state);
1118 booltextdev->updateFillColorSpace(state);
1119 rgbdev->updateFillColorSpace(state);
1120 clip0dev->updateFillColorSpace(state);
1121 clip1dev->updateFillColorSpace(state);
1122 gfxdev->updateFillColorSpace(state);
1124 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
1126 boolpolydev->updateStrokeColorSpace(state);
1127 booltextdev->updateStrokeColorSpace(state);
1128 rgbdev->updateStrokeColorSpace(state);
1129 clip0dev->updateStrokeColorSpace(state);
1130 clip1dev->updateStrokeColorSpace(state);
1131 gfxdev->updateStrokeColorSpace(state);
1133 void BitmapOutputDev::updateFillColor(GfxState *state)
1135 boolpolydev->updateFillColor(state);
1136 booltextdev->updateFillColor(state);
1137 rgbdev->updateFillColor(state);
1138 clip0dev->updateFillColor(state);
1139 clip1dev->updateFillColor(state);
1140 gfxdev->updateFillColor(state);
1142 void BitmapOutputDev::updateStrokeColor(GfxState *state)
1144 boolpolydev->updateStrokeColor(state);
1145 booltextdev->updateStrokeColor(state);
1146 rgbdev->updateStrokeColor(state);
1147 clip0dev->updateStrokeColor(state);
1148 clip1dev->updateStrokeColor(state);
1149 gfxdev->updateStrokeColor(state);
1151 void BitmapOutputDev::updateBlendMode(GfxState *state)
1153 boolpolydev->updateBlendMode(state);
1154 booltextdev->updateBlendMode(state);
1155 rgbdev->updateBlendMode(state);
1156 clip0dev->updateBlendMode(state);
1157 clip1dev->updateBlendMode(state);
1158 gfxdev->updateBlendMode(state);
1160 void BitmapOutputDev::updateFillOpacity(GfxState *state)
1162 boolpolydev->updateFillOpacity(state);
1163 booltextdev->updateFillOpacity(state);
1164 rgbdev->updateFillOpacity(state);
1165 clip0dev->updateFillOpacity(state);
1166 clip1dev->updateFillOpacity(state);
1167 gfxdev->updateFillOpacity(state);
1169 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
1171 boolpolydev->updateStrokeOpacity(state);
1172 booltextdev->updateStrokeOpacity(state);
1173 rgbdev->updateStrokeOpacity(state);
1174 clip0dev->updateStrokeOpacity(state);
1175 clip1dev->updateStrokeOpacity(state);
1176 gfxdev->updateStrokeOpacity(state);
1178 void BitmapOutputDev::updateFillOverprint(GfxState *state)
1180 boolpolydev->updateFillOverprint(state);
1181 booltextdev->updateFillOverprint(state);
1182 rgbdev->updateFillOverprint(state);
1183 clip0dev->updateFillOverprint(state);
1184 clip1dev->updateFillOverprint(state);
1185 gfxdev->updateFillOverprint(state);
1187 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
1189 boolpolydev->updateStrokeOverprint(state);
1190 booltextdev->updateStrokeOverprint(state);
1191 rgbdev->updateStrokeOverprint(state);
1192 clip0dev->updateStrokeOverprint(state);
1193 clip1dev->updateStrokeOverprint(state);
1194 gfxdev->updateStrokeOverprint(state);
1196 void BitmapOutputDev::updateTransfer(GfxState *state)
1198 boolpolydev->updateTransfer(state);
1199 booltextdev->updateTransfer(state);
1200 rgbdev->updateTransfer(state);
1201 clip0dev->updateTransfer(state);
1202 clip1dev->updateTransfer(state);
1203 gfxdev->updateTransfer(state);
1206 void BitmapOutputDev::updateFont(GfxState *state)
1208 boolpolydev->updateFont(state);
1209 booltextdev->updateFont(state);
1210 rgbdev->updateFont(state);
1211 clip0dev->updateFont(state);
1212 clip1dev->updateFont(state);
1213 gfxdev->updateFont(state);
1215 void BitmapOutputDev::updateTextMat(GfxState *state)
1217 boolpolydev->updateTextMat(state);
1218 booltextdev->updateTextMat(state);
1219 rgbdev->updateTextMat(state);
1220 clip0dev->updateTextMat(state);
1221 clip1dev->updateTextMat(state);
1222 gfxdev->updateTextMat(state);
1224 void BitmapOutputDev::updateCharSpace(GfxState *state)
1226 boolpolydev->updateCharSpace(state);
1227 booltextdev->updateCharSpace(state);
1228 rgbdev->updateCharSpace(state);
1229 clip0dev->updateCharSpace(state);
1230 clip1dev->updateCharSpace(state);
1231 gfxdev->updateCharSpace(state);
1233 void BitmapOutputDev::updateRender(GfxState *state)
1235 boolpolydev->updateRender(state);
1236 booltextdev->updateRender(state);
1237 rgbdev->updateRender(state);
1238 clip0dev->updateRender(state);
1239 clip1dev->updateRender(state);
1240 gfxdev->updateRender(state);
1242 void BitmapOutputDev::updateRise(GfxState *state)
1244 boolpolydev->updateRise(state);
1245 booltextdev->updateRise(state);
1246 rgbdev->updateRise(state);
1247 clip0dev->updateRise(state);
1248 clip1dev->updateRise(state);
1249 gfxdev->updateRise(state);
1251 void BitmapOutputDev::updateWordSpace(GfxState *state)
1253 boolpolydev->updateWordSpace(state);
1254 booltextdev->updateWordSpace(state);
1255 rgbdev->updateWordSpace(state);
1256 clip0dev->updateWordSpace(state);
1257 clip1dev->updateWordSpace(state);
1258 gfxdev->updateWordSpace(state);
1260 void BitmapOutputDev::updateHorizScaling(GfxState *state)
1262 boolpolydev->updateHorizScaling(state);
1263 booltextdev->updateHorizScaling(state);
1264 rgbdev->updateHorizScaling(state);
1265 clip0dev->updateHorizScaling(state);
1266 clip1dev->updateHorizScaling(state);
1267 gfxdev->updateHorizScaling(state);
1269 void BitmapOutputDev::updateTextPos(GfxState *state)
1271 boolpolydev->updateTextPos(state);
1272 booltextdev->updateTextPos(state);
1273 rgbdev->updateTextPos(state);
1274 clip0dev->updateTextPos(state);
1275 clip1dev->updateTextPos(state);
1276 gfxdev->updateTextPos(state);
1278 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
1280 boolpolydev->updateTextShift(state, shift);
1281 booltextdev->updateTextShift(state, shift);
1282 rgbdev->updateTextShift(state, shift);
1283 clip0dev->updateTextShift(state, shift);
1284 clip1dev->updateTextShift(state, shift);
1285 gfxdev->updateTextShift(state, shift);
1288 double max(double x, double y)
1292 double min(double x, double y)
1297 gfxbbox_t BitmapOutputDev::getBBox(GfxState*state)
1299 GfxPath * path = state->getPath();
1300 int num = path->getNumSubpaths();
1301 gfxbbox_t bbox = {0,0,1,1};
1304 for(t = 0; t < num; t++) {
1305 GfxSubpath *subpath = path->getSubpath(t);
1306 int subnum = subpath->getNumPoints();
1308 for(s=0;s<subnum;s++) {
1310 state->transform(subpath->getX(s),subpath->getY(s),&x,&y);
1312 bbox.xmin = x; bbox.ymin = y;
1313 bbox.xmax = x; bbox.ymax = y;
1316 bbox.xmin = min(bbox.xmin, x);
1317 bbox.ymin = min(bbox.ymin, y);
1318 bbox.xmax = max(bbox.xmax, x);
1319 bbox.ymax = max(bbox.ymax, y);
1326 void BitmapOutputDev::stroke(GfxState *state)
1328 msg("<debug> stroke");
1329 boolpolydev->stroke(state);
1330 gfxbbox_t bbox = getBBox(state);
1331 double width = state->getTransformedLineWidth();
1332 bbox.xmin -= width; bbox.ymin -= width;
1333 bbox.xmax += width; bbox.ymax += width;
1334 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1335 rgbdev->stroke(state);
1336 dbg_newdata("stroke");
1338 void BitmapOutputDev::fill(GfxState *state)
1340 msg("<debug> fill");
1341 boolpolydev->fill(state);
1342 gfxbbox_t bbox = getBBox(state);
1343 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1344 rgbdev->fill(state);
1345 dbg_newdata("fill");
1347 void BitmapOutputDev::eoFill(GfxState *state)
1349 msg("<debug> eoFill");
1350 boolpolydev->eoFill(state);
1351 gfxbbox_t bbox = getBBox(state);
1352 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1353 rgbdev->eoFill(state);
1354 dbg_newdata("eofill");
1356 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1357 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
1358 int paintType, Dict *resDict,
1359 double *mat, double *bbox,
1360 int x0, int y0, int x1, int y1,
1361 double xStep, double yStep)
1363 msg("<debug> tilingPatternFill");
1364 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1365 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1366 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1367 dbg_newdata("tilingpatternfill");
1370 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
1371 int paintType, Dict *resDict,
1372 double *mat, double *bbox,
1373 int x0, int y0, int x1, int y1,
1374 double xStep, double yStep)
1376 msg("<debug> tilingPatternFill");
1377 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1378 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1379 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1380 dbg_newdata("tilingpatternfill");
1384 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
1386 msg("<debug> functionShadedFill");
1387 boolpolydev->functionShadedFill(state, shading);
1388 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1389 return rgbdev->functionShadedFill(state, shading);
1391 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
1393 msg("<debug> axialShadedFill");
1394 boolpolydev->axialShadedFill(state, shading);
1395 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1396 return rgbdev->axialShadedFill(state, shading);
1398 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
1400 msg("<debug> radialShadedFill");
1401 boolpolydev->radialShadedFill(state, shading);
1402 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1403 return rgbdev->radialShadedFill(state, shading);
1406 SplashColor black = {0,0,0};
1407 SplashColor white = {255,255,255};
1409 void BitmapOutputDev::clip(GfxState *state)
1411 msg("<debug> clip");
1412 boolpolydev->clip(state);
1413 booltextdev->clip(state);
1414 rgbdev->clip(state);
1415 clip1dev->clip(state);
1417 void BitmapOutputDev::eoClip(GfxState *state)
1419 msg("<debug> eoClip");
1420 boolpolydev->eoClip(state);
1421 booltextdev->eoClip(state);
1422 rgbdev->eoClip(state);
1423 clip1dev->eoClip(state);
1425 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1427 msg("<debug> clipToStrokePath");
1428 boolpolydev->clipToStrokePath(state);
1429 booltextdev->clipToStrokePath(state);
1430 rgbdev->clipToStrokePath(state);
1431 clip1dev->clipToStrokePath(state);
1434 void BitmapOutputDev::beginStringOp(GfxState *state)
1436 msg("<debug> beginStringOp");
1437 clip0dev->beginStringOp(state);
1438 clip1dev->beginStringOp(state);
1439 booltextdev->beginStringOp(state);
1440 gfxdev->beginStringOp(state);
1442 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1444 msg("<debug> beginString");
1445 clip0dev->beginString(state, s);
1446 clip1dev->beginString(state, s);
1447 booltextdev->beginString(state, s);
1448 gfxdev->beginString(state, s);
1451 void BitmapOutputDev::clearClips()
1453 clearBooleanBitmap(clip0bitmap, 0, 0, 0, 0);
1454 clearBooleanBitmap(clip1bitmap, 0, 0, 0, 0);
1456 void BitmapOutputDev::clearBoolPolyDev()
1458 clearBooleanBitmap(stalepolybitmap, 0, 0, stalepolybitmap->getWidth(), stalepolybitmap->getHeight());
1460 void BitmapOutputDev::clearBoolTextDev()
1462 clearBooleanBitmap(staletextbitmap, 0, 0, staletextbitmap->getWidth(), staletextbitmap->getHeight());
1464 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1465 double dx, double dy,
1466 double originX, double originY,
1467 CharCode code, int nBytes, Unicode *u, int uLen)
1469 msg("<debug> drawChar render=%d", state->getRender());
1471 if(state->getRender()&RENDER_CLIP) {
1472 //char is just a clipping boundary
1473 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1474 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1475 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1476 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1477 } else if(rgbbitmap != rgbdev->getBitmap()) {
1478 // we're doing softmasking or transparency grouping
1479 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1480 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1482 // we're drawing a regular char
1484 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1485 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1487 /* calculate the bbox of this character */
1488 int x1 = (int)x, x2 = (int)x+1, y1 = (int)y, y2 = (int)y+1;
1489 SplashFont*font = clip0dev->getCurrentFont();
1490 SplashPath*path = font?font->getGlyphPath(code):NULL;
1494 path->offset((SplashCoord)x, (SplashCoord)y);
1496 for(t=0;t<path->getLength();t++) {
1499 path->getPoint(t,&xx,&yy,&f);
1500 state->transform(xx,yy,&xx,&yy);
1501 if(xx<x1) x1=(int)xx;
1502 if(yy<y1) y1=(int)yy;
1503 if(xx>=x2) x2=(int)xx+1;
1504 if(yy>=y2) y2=(int)yy+1;
1506 delete(path);path=0;
1509 /* if this character is affected somehow by the various clippings (i.e., it looks
1510 different on a device without clipping), then draw it on the bitmap, not as
1512 if(clip0and1differ(x1,y1,x2,y2)) {
1513 msg("<verbose> Char %d is affected by clipping", code);
1514 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1515 checkNewBitmap(x1,y1,x2,y2);
1516 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1517 if(config_extrafontdata) {
1518 int oldrender = state->getRender();
1519 state->setRender(3); //invisible
1520 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1521 state->setRender(oldrender);
1525 /* this char is not at all affected by clipping.
1526 Now just dump out the bitmap we're currently working on, if necessary. */
1527 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1528 checkNewText(x1,y1,x2,y2);
1529 /* use polygonal output device to do the actual text handling */
1530 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1533 dbg_newdata("text");
1535 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1537 msg("<error> internal error: drawString not implemented");
1540 void BitmapOutputDev::endTextObject(GfxState *state)
1542 msg("<debug> endTextObject");
1543 rgbdev->endTextObject(state);
1544 clip0dev->endTextObject(state);
1545 clip1dev->endTextObject(state);
1546 booltextdev->endTextObject(state);
1547 /* the only thing "drawn" here is clipping */
1548 //checkNewText(UNKNOWN_BOUNDING_BOX);
1549 gfxdev->endTextObject(state);
1550 dbg_newdata("endtextobject");
1552 void BitmapOutputDev::endString(GfxState *state)
1554 msg("<debug> endString");
1555 clip0dev->endString(state);
1556 clip1dev->endString(state);
1557 booltextdev->endString(state);
1558 int render = state->getRender();
1559 if(render != RENDER_INVISIBLE && render != RENDER_FILL) {
1560 /* xpdf draws things like stroke text or fill+stroke text in the
1561 endString() method */
1562 checkNewText(UNKNOWN_BOUNDING_BOX);
1564 gfxdev->endString(state);
1565 dbg_newdata("endstring");
1567 void BitmapOutputDev::endStringOp(GfxState *state)
1569 msg("<debug> endStringOp");
1570 clip0dev->endStringOp(state);
1571 clip1dev->endStringOp(state);
1572 booltextdev->endStringOp(state);
1573 gfxdev->endStringOp(state);
1574 dbg_newdata("endstringop");
1577 /* TODO: these four operations below *should* do nothing, as type3
1578 chars are drawn using operations like fill() */
1579 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1580 double dx, double dy,
1581 CharCode code, Unicode *u, int uLen)
1583 msg("<debug> beginType3Char");
1584 /* call gfxdev so that it can generate "invisible" characters
1585 on top of the actual graphic content, for text extraction */
1586 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1588 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1590 msg("<debug> type3D0");
1591 return gfxdev->type3D0(state, wx, wy);
1593 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1595 msg("<debug> type3D1");
1596 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1598 void BitmapOutputDev::endType3Char(GfxState *state)
1600 msg("<debug> endType3Char");
1601 gfxdev->endType3Char(state);
1604 class CopyStream: public Object
1608 MemStream*memstream;
1610 CopyStream(Stream*str, int len)
1615 buf = (char*)malloc(len);
1617 for (t=0; t<len; t++)
1618 buf[t] = str->getChar();
1621 this->dict = str->getDict();
1622 this->memstream = new MemStream(buf, 0, len, this);
1626 ::free(this->buf);this->buf = 0;
1627 delete this->memstream;
1629 Dict* getDict() {return dict;}
1630 Stream* getStream() {return this->memstream;};
1633 gfxbbox_t BitmapOutputDev::getImageBBox(GfxState*state)
1637 state->transform(0, 1, &x, &y);
1638 bbox.xmin=bbox.xmax = x;
1639 bbox.ymin=bbox.ymax = y;
1640 state->transform(0, 0, &x, &y);
1641 bbox.xmin=min(bbox.xmin,x);
1642 bbox.ymin=min(bbox.ymin,y);
1643 bbox.xmax=max(bbox.xmax,x);
1644 bbox.ymax=max(bbox.ymax,y);
1645 state->transform(1, 0, &x, &y);
1646 bbox.xmin=min(bbox.xmin,x);
1647 bbox.ymin=min(bbox.ymin,y);
1648 bbox.xmax=max(bbox.xmax,x);
1649 bbox.ymax=max(bbox.ymax,y);
1650 state->transform(1, 1, &x, &y);
1651 bbox.xmin=min(bbox.xmin,x);
1652 bbox.ymin=min(bbox.ymin,y);
1653 bbox.xmax=max(bbox.xmax,x);
1654 bbox.ymax=max(bbox.ymax,y);
1657 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1658 int width, int height, GBool invert,
1661 msg("<debug> drawImageMask streamkind=%d", str->getKind());
1663 CopyStream*cpystr = new CopyStream(str, height * ((width + 7) / 8));
1664 str = cpystr->getStream();
1666 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1667 gfxbbox_t bbox = getImageBBox(state);
1668 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1669 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1671 dbg_newdata("imagemask");
1673 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1674 int width, int height, GfxImageColorMap *colorMap,
1675 int *maskColors, GBool inlineImg)
1677 msg("<debug> drawImage streamkind=%d", str->getKind());
1679 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1680 str = cpystr->getStream();
1682 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1683 gfxbbox_t bbox=getImageBBox(state);
1684 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1685 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1687 dbg_newdata("image");
1689 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1690 int width, int height,
1691 GfxImageColorMap *colorMap,
1692 Stream *maskStr, int maskWidth, int maskHeight,
1695 msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
1697 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1698 str = cpystr->getStream();
1700 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1701 gfxbbox_t bbox=getImageBBox(state);
1702 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1703 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1705 dbg_newdata("maskedimage");
1707 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1708 int width, int height,
1709 GfxImageColorMap *colorMap,
1711 int maskWidth, int maskHeight,
1712 GfxImageColorMap *maskColorMap)
1714 msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
1716 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1717 str = cpystr->getStream();
1719 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1720 gfxbbox_t bbox=getImageBBox(state);
1721 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1722 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1724 dbg_newdata("softmaskimage");
1726 void BitmapOutputDev::drawForm(Ref id)
1728 msg("<debug> drawForm");
1729 boolpolydev->drawForm(id);
1730 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1731 rgbdev->drawForm(id);
1734 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1736 msg("<debug> processLink");
1737 gfxdev->processLink(link, catalog);
1740 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1741 GfxColorSpace *blendingColorSpace,
1742 GBool isolated, GBool knockout,
1745 msg("<debug> beginTransparencyGroup");
1746 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1747 GfxState*state1 = state->copy();
1748 GfxState*state2 = state->copy();
1750 state1->setPath(state->getPath()->copy());
1752 state2->setPath(state->getPath()->copy());
1754 GfxState*state1 = state->copy(gTrue);
1755 GfxState*state2 = state->copy(gTrue);
1757 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1758 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1759 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1762 dbg_newdata("endtransparencygroup");
1764 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1766 msg("<debug> endTransparencyGroup");
1767 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1768 GfxState*state1 = state->copy();
1769 GfxState*state2 = state->copy();
1771 state1->setPath(state->getPath()->copy());
1773 state2->setPath(state->getPath()->copy());
1775 GfxState*state1 = state->copy(gTrue);
1776 GfxState*state2 = state->copy(gTrue);
1778 boolpolydev->endTransparencyGroup(state1);
1779 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1780 rgbdev->endTransparencyGroup(state2);
1783 clip1dev->endTransparencyGroup(state);
1784 dbg_newdata("endtransparencygroup");
1786 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1788 msg("<debug> paintTransparencyGroup");
1789 boolpolydev->paintTransparencyGroup(state,bbox);
1790 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1791 rgbdev->paintTransparencyGroup(state,bbox);
1792 clip1dev->paintTransparencyGroup(state,bbox);
1793 dbg_newdata("painttransparencygroup");
1795 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1797 msg("<debug> setSoftMask");
1798 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1799 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1800 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1801 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1802 dbg_newdata("setsoftmask");
1804 void BitmapOutputDev::clearSoftMask(GfxState *state)
1806 msg("<debug> clearSoftMask");
1807 boolpolydev->clearSoftMask(state);
1808 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1809 rgbdev->clearSoftMask(state);
1810 clip1dev->clearSoftMask(state);
1811 dbg_newdata("clearsoftmask");