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"
34 #define UNKNOWN_BOUNDING_BOX 0,0,0,0
36 static SplashColor splash_white = {255,255,255};
37 static SplashColor splash_black = {0,0,0};
39 ClipState::ClipState()
46 BitmapOutputDev::BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
50 this->xref = doc->getXRef();
52 /* color graphic output device, for creating bitmaps */
53 this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
55 /* color mode for binary bitmaps */
56 SplashColorMode colorMode = splashModeMono1;
58 /* two devices for testing things against clipping: one clips, the other doesn't */
59 this->clip0dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
60 this->clip1dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
62 /* device indicating where polygonal pixels were drawn */
63 this->boolpolydev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
64 /* device indicating where text pixels were drawn */
65 this->booltextdev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
67 /* device for handling texts and links */
68 this->gfxdev = new GFXOutputDev(info, this->doc);
70 this->rgbdev->startDoc(this->xref);
71 this->boolpolydev->startDoc(this->xref);
72 this->booltextdev->startDoc(this->xref);
73 this->clip0dev->startDoc(this->xref);
74 this->clip1dev->startDoc(this->xref);
76 this->gfxoutput = (gfxdevice_t*)malloc(sizeof(gfxdevice_t));
77 gfxdevice_record_init(this->gfxoutput);
79 this->gfxdev->setDevice(this->gfxoutput);
81 this->config_extrafontdata = 0;
84 //this->clipstates = 0;
86 BitmapOutputDev::~BitmapOutputDev()
89 gfxresult_t*r = this->gfxoutput->finish(this->gfxoutput);
91 free(this->gfxoutput);this->gfxoutput = 0;
94 delete this->bboxpath;this->bboxpath = 0;
97 delete this->rgbdev;this->rgbdev = 0;
100 delete this->gfxdev;this->gfxdev= 0;
102 if(this->boolpolydev) {
103 delete this->boolpolydev;this->boolpolydev = 0;
105 if(this->booltextdev) {
106 delete this->booltextdev;this->booltextdev = 0;
109 delete this->clip0dev;this->clip0dev = 0;
112 delete this->clip1dev;this->clip1dev = 0;
114 //if(this->clipbitmap) {
115 // delete this->clipbitmap;this->clipbitmap = 0;
117 //if(this->clipdev) {
118 // delete this->clipdev;this->clipdev = 0;
123 GBool BitmapOutputDev::getVectorAntialias()
125 return this->rgbdev->getVectorAntialias();
127 void BitmapOutputDev::setVectorAntialias(GBool vaa)
129 this->rgbdev->setVectorAntialias(vaa);
131 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
135 void BitmapOutputDev::setMove(int x,int y)
137 this->gfxdev->setMove(x,y);
138 this->user_movex = x;
139 this->user_movey = y;
141 void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
143 this->gfxdev->setClip(x1,y1,x2,y2);
144 this->user_clipx1 = x1;
145 this->user_clipy1 = y1;
146 this->user_clipx2 = x2;
147 this->user_clipy2 = y2;
149 void BitmapOutputDev::setParameter(const char*key, const char*value)
151 if(!strcmp(key, "extrafontdata")) {
152 this->config_extrafontdata = atoi(value);
154 this->gfxdev->setParameter(key, value);
156 void BitmapOutputDev::setPageMap(int*page2page, int num_pages)
158 this->gfxdev->setPageMap(page2page, num_pages);
161 typedef struct _ibbox {
162 int xmin,ymin,xmax,ymax;
166 static ibbox_t* ibbox_new(int x1, int y1, int x2, int y2)
168 ibbox_t*b = (ibbox_t*)rfx_calloc(sizeof(ibbox_t));
176 static void ibbox_destroy(ibbox_t*b)
179 ibbox_t*next = b->next;
185 static ibbox_t*getBitmapBBoxes(Guchar*alpha, int width, int height)
193 for(y=0;y<height;y++) {
194 Guchar*a = &alpha[y*width];
195 for(x=0;x<width;x++) {
198 int left = x; //first occupied pixel from left
199 int right = x+1; //last non-occupied pixel from right
208 if(left<xmin) xmin = left;
209 if(right>xmax) xmax = right;
213 if(xmin<xmax || ymin<ymax) {
214 bbox = ibbox_new(xmin, ymin, xmax, ymax);
219 void BitmapOutputDev::flushBitmap()
221 int width = rgbdev->getBitmapWidth();
222 int height = rgbdev->getBitmapHeight();
224 if(sizeof(SplashColor)!=3) {
225 msg("<error> sizeof(SplashColor)!=3");
229 SplashColorPtr rgb = rgbbitmap->getDataPtr();
230 Guchar*alpha = rgbbitmap->getAlphaPtr();
231 Guchar*alpha2 = boolpolybitmap->getAlphaPtr();
233 ibbox_t* boxes = getBitmapBBoxes(alpha, width, height);
236 for(b=boxes;boxes;boxes=boxes->next) {
242 /* clip against (-movex, -movey, -movex+width, -movey+height) */
243 if(xmin < -this->movex) xmin = -this->movex;
244 if(ymin < -this->movey) ymin = -this->movey;
245 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
246 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
248 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
250 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
253 int rangex = xmax-xmin;
254 int rangey = ymax-ymin;
255 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
256 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
258 img->height = rangey;
260 for(y=0;y<rangey;y++) {
261 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
262 gfxcolor_t*out = &img->data[y*rangex];
263 Guchar*ain = &alpha[(y+ymin)*width+xmin];
264 Guchar*ain2 = &alpha2[(y+ymin)*width+xmin];
265 if(this->emptypage) {
266 for(x=0;x<rangex;x++) {
267 /* the first bitmap on the page doesn't need to have an alpha channel-
268 blend against a white background*/
269 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
270 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
271 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
275 for(x=0;x<rangex;x++) {
278 out[x].r = 0;out[x].g = 0;out[x].b = 0;out[x].a = 0;
281 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we
282 have to premultiply alpha (mix background and pixel according to the alpha channel).
284 out[x].r = (in[x*3+0]*ain[x])/255;
285 out[x].g = (in[x*3+1]*ain[x])/255;
286 out[x].b = (in[x*3+2]*ain[x])/255;
292 /* transform bitmap rectangle to "device space" */
306 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
307 dev->fillbitmap(dev, line, img, &m, 0);
310 free(img->data);img->data=0;free(img);img=0;
312 ibbox_destroy(boxes);
314 memset(rgbbitmap->getAlphaPtr(), 0, rgbbitmap->getWidth()*rgbbitmap->getHeight());
315 memset(rgbbitmap->getDataPtr(), 0, rgbbitmap->getRowSize()*rgbbitmap->getHeight());
320 void BitmapOutputDev::flushText()
322 msg("<verbose> Flushing text/polygons");
323 gfxdevice_record_flush(this->gfxoutput, this->dev);
328 void writeMonoBitmap(SplashBitmap*btm, char*filename)
330 int width8 = (btm->getWidth()+7)/8;
331 int width = btm->getWidth();
332 int height = btm->getHeight();
333 gfxcolor_t*b = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
334 unsigned char*data = btm->getDataPtr();
336 for(y=0;y<height;y++) {
337 unsigned char*l = &data[width8*y];
338 gfxcolor_t*d = &b[width*y];
339 for(x=0;x<width;x++) {
340 if(l[x>>3]&(128>>(x&7))) {
341 d[x].r = d[x].g = d[x].b = 255;
343 d[x].r = d[x].g = d[x].b = 0;
348 writePNG(filename, (unsigned char*)b, width, height);
352 void writeBitmap(SplashBitmap*bitmap, char*filename)
356 int width = bitmap->getWidth();
357 int height = bitmap->getHeight();
359 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
361 if(bitmap->getMode()==splashModeMono1) {
362 writeMonoBitmap(bitmap, filename);
366 for(y=0;y<height;y++) {
367 gfxcolor_t*line = &data[y*width];
368 for(x=0;x<width;x++) {
369 Guchar c[4] = {0,0,0,0};
370 bitmap->getPixel(x,y,c);
374 line[x].a = bitmap->getAlpha(x,y);
377 writePNG(filename, (unsigned char*)data, width, height);
381 void writeAlpha(SplashBitmap*bitmap, char*filename)
385 int width = bitmap->getWidth();
386 int height = bitmap->getHeight();
388 if(bitmap->getMode()==splashModeMono1) {
389 writeMonoBitmap(bitmap, filename);
393 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
395 for(y=0;y<height;y++) {
396 gfxcolor_t*line = &data[y*width];
397 for(x=0;x<width;x++) {
398 int a = bitmap->getAlpha(x,y);
405 writePNG(filename, (unsigned char*)data, width, height);
408 static int dbg_btm_counter=1;
410 static const char*STATE_NAME[] = {"parallel", "textabovebitmap", "bitmapabovetext"};
412 int checkAlphaSanity(SplashBitmap*boolbtm, SplashBitmap*alphabtm)
414 assert(boolbtm->getWidth() == alphabtm->getWidth());
415 assert(boolbtm->getHeight() == alphabtm->getHeight());
416 if(boolbtm->getMode()==splashModeMono1) {
420 int width = boolbtm->getWidth();
421 int height = boolbtm->getHeight();
425 for(y=0;y<height;y++) {
426 for(x=0;x<width;x++) {
427 int a1 = alphabtm->getAlpha(x,y);
428 int a2 = boolbtm->getAlpha(x,y);
434 double badness = bad/(double)(width*height);
436 msg("<error> Bitmaps don't correspond: %d out of %d pixels wrong (%.2f%%)", bad, width*height,
440 msg("<notice> %f", badness);
444 GBool BitmapOutputDev::checkNewText(int x1, int y1, int x2, int y2)
446 /* called once some new text was drawn on booltextdev, and
447 before the same thing is drawn on gfxdev */
449 msg("<trace> Testing new text data against current bitmap data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
455 sprintf(filename1, "state%dboolbitmap_afternewtext.png", dbg_btm_counter);
456 sprintf(filename2, "state%dbooltext_afternewtext.png", dbg_btm_counter);
457 sprintf(filename3, "state%dbitmap_afternewtext.png", dbg_btm_counter);
458 msg("<verbose> %s %s %s", filename1, filename2, filename3);
459 writeAlpha(boolpolybitmap, filename1);
460 writeAlpha(booltextbitmap, filename2);
461 writeBitmap(rgbdev->getBitmap(), filename3);
466 if(intersection(x1,y1,x2,y2)) {
467 if(layerstate==STATE_PARALLEL) {
468 /* the new text is above the bitmap. So record that fact,
469 and also clear the bitmap buffer, so we can check for
471 msg("<verbose> Text is above current bitmap/polygon data");
472 layerstate=STATE_TEXT_IS_ABOVE;
473 clearBoolPolyDev(x1,y1,x2,y2);
474 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
475 /* there's a bitmap above the (old) text. So we need
476 to flush out that text, and record that the *new*
477 text is now *above* the bitmap
479 msg("<verbose> Text is above current bitmap/polygon data (which is above some other text)");
481 layerstate=STATE_TEXT_IS_ABOVE;
482 /* clear both bool devices- the text device because
483 we just dumped out all the (old) text, and the
484 poly dev so we can check for new intersections */
485 clearBoolPolyDev(x1,y1,x2,y2);
486 /* FIXME this destroys the text pixels we just
487 drew to test for the intersection- however we need
488 those to check for the *new* intersections */
489 clearBoolTextDev(x1,y1,x2,y2);
492 /* we already know that the current text section is
493 above the current bitmap section- now just new
494 bitmap data *and* new text data was drawn, and
495 *again* it's above the current bitmap- so clear
496 the polygon bitmap again, so we can check for
498 msg("<verbose> Text is still above current bitmap/polygon data");
499 clearBoolPolyDev(x1,y1,x2,y2);
505 GBool BitmapOutputDev::checkNewBitmap(int x1, int y1, int x2, int y2)
507 /* similar to checkNewText() above, only in reverse */
508 msg("<trace> Testing new graphics data against current text data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
514 sprintf(filename1, "state%dboolbitmap_afternewgfx.png", dbg_btm_counter);
515 sprintf(filename2, "state%dbooltext_afternewgfx.png", dbg_btm_counter);
516 sprintf(filename3, "state%dbitmap_afternewgfx.png", dbg_btm_counter);
517 msg("<verbose> %s %s %s", filename1, filename2, filename3);
518 writeAlpha(boolpolybitmap, filename1);
519 writeAlpha(booltextbitmap, filename2);
520 writeBitmap(rgbdev->getBitmap(), filename3);
525 if(intersection(x1,y1,x2,y2)) {
526 if(layerstate==STATE_PARALLEL) {
527 msg("<verbose> Bitmap is above current text data");
528 layerstate=STATE_BITMAP_IS_ABOVE;
529 clearBoolTextDev(x1,y1,x2,y2);
530 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
531 msg("<verbose> Bitmap is above current text data (which is above some bitmap)");
533 layerstate=STATE_BITMAP_IS_ABOVE;
534 clearBoolTextDev(x1,y1,x2,y2);
535 /* FIXME this destroys the polygon pixels we just
536 drew to test for the intersection- however we need
537 those to check for the *new* intersections */
538 clearBoolPolyDev(x1,y1,x2,y2);
541 msg("<verbose> Bitmap is still above current text data");
542 clearBoolTextDev(x1,y1,x2,y2);
548 //void checkNewText() {
549 // Guchar*alpha = rgbbitmap->getAlphaPtr();
550 // Guchar*charpixels = clip1bitmap->getDataPtr();
552 // for(yy=0;yy<height;yy++) {
553 // Guchar*aline = &alpha[yy*width];
554 // Guchar*cline = &charpixels[yy*width8];
555 // for(xx=0;xx<width;xx++) {
557 // int bytepos = xx>>3;
558 // /* TODO: is the bit order correct? */
559 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
566 static inline GBool fixBBox(int*x1, int*y1, int*x2, int*y2, int width, int height)
568 if(!(*x1|*y1|*x2|*y2)) {
575 if(*x2<=*x1) return gFalse;
576 if(*x2<0) return gFalse;
578 if(*x1>=width) return gFalse;
579 if(*x2>width) *x2=width;
581 if(*y2<=*y1) return gFalse;
582 if(*y2<0) return gFalse;
584 if(*y1>=height) return gFalse;
585 if(*y2>height) *y2=height;
589 GBool BitmapOutputDev::clip0and1differ(int x1,int y1,int x2,int y2)
591 if(clip0bitmap->getMode()==splashModeMono1) {
592 int width = clip0bitmap->getWidth();
593 int width8 = (width+7)/8;
594 int height = clip0bitmap->getHeight();
596 if(!fixBBox(&x1,&y1,&x2,&y2,width,height)) {
597 /* area is outside or null */
601 SplashBitmap*clip0 = clip0bitmap;
602 SplashBitmap*clip1 = clip1bitmap;
608 unsigned char*row1 = &clip0bitmap->getDataPtr()[width8*y+x18];
609 unsigned char*row2 = &clip1bitmap->getDataPtr()[width8*y+x18];
610 if(memcmp(row1, row2, x28-x18)) {
616 SplashBitmap*clip0 = clip0bitmap;
617 SplashBitmap*clip1 = clip1bitmap;
618 int width = clip0->getAlphaRowSize();
619 int height = clip0->getHeight();
621 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
625 Guchar*a0 = clip0->getAlphaPtr();
626 Guchar*a1 = clip1->getAlphaPtr();
631 if(a0[y*width+x]!=a1[y*width+x]) {
639 char differs2 = memcmp(a0, a1, width*height);
640 if(differs && !differs2)
641 msg("<warning> Strange internal error (2)");
642 else if(!differs && differs2) {
643 msg("<warning> Bad Bounding Box: Difference in clip0 and clip1 outside bbox");
644 msg("<warning> %d %d %d %d", x1, y1, x2, y2);
650 static void clearBooleanBitmap(SplashBitmap*btm, int x1, int y1, int x2, int y2)
654 x2 = btm->getWidth();
655 y2 = btm->getHeight();
657 if(btm->getMode()==splashModeMono1) {
658 int width8 = (btm->getWidth()+7)/8;
659 int width = btm->getWidth();
660 int height = btm->getHeight();
661 memset(btm->getDataPtr(), 0, width8*height);
663 int width = btm->getAlphaRowSize();
664 int height = btm->getHeight();
665 memset(btm->getAlphaPtr(), 0, width*height);
669 GBool compare8(unsigned char*data1, unsigned char*data2, int len)
673 if(((ptroff_t)data1&7)==((ptroff_t)data2&7)) {
674 // oh good, we can do aligning
675 while((ptroff_t)data1&7) {
684 /* use 64 bit for the (hopefully aligned) middle section */
686 long long unsigned int*d1 = (long long unsigned int*)data1;
687 long long unsigned int*d2 = (long long unsigned int*)data2;
688 long long unsigned int x = 0;
700 if(data1[t]&data2[t]) {
707 GBool BitmapOutputDev::intersection(int x1, int y1, int x2, int y2)
709 SplashBitmap*boolpoly = boolpolybitmap;
710 SplashBitmap*booltext = booltextbitmap;
712 if(boolpoly->getMode()==splashModeMono1) {
713 /* alternative implementation, using one bit per pixel-
714 needs the no-dither patch in xpdf */
716 int width = boolpoly->getWidth();
717 int height = boolpoly->getHeight();
719 if(!fixBBox(&x1,&y1,&x2,&y2, width, height)) {
723 Guchar*polypixels = boolpoly->getDataPtr();
724 Guchar*textpixels = booltext->getDataPtr();
726 int width8 = (width+7)/8;
731 polypixels+=y1*width8+x1/8;
732 textpixels+=y1*width8+x1/8;
733 runx=(x2+7)/8 - x1/8;
740 /*assert(sizeof(unsigned long long int)==8);
741 if(((ptroff_t)polypixels&7) || ((ptroff_t)textpixels&7)) {
742 //msg("<warning> Non-optimal alignment");
746 unsigned char*data1 = (unsigned char*)polypixels;
747 unsigned char*data2 = (unsigned char*)textpixels;
748 msg("<verbose> Testing area (%d,%d,%d,%d), runx=%d,runy=%d", x1,y1,x2,y2, runx, runy);
749 for(y=0;y<runy;y++) {
750 if(compare8(data1,data2,runx))
757 int width = boolpoly->getAlphaRowSize();
758 int height = boolpoly->getHeight();
760 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
763 Guchar*polypixels = boolpoly->getAlphaPtr();
764 Guchar*textpixels = booltext->getAlphaPtr();
771 if(polypixels[width*y+x]&&textpixels[width*y+x])
775 int ax1=0,ay1=0,ax2=0,ay2=0;
776 for(y=0;y<height;y++) {
777 for(x=0;x<width;x++) {
778 if(polypixels[width*y+x]&&textpixels[width*y+x]) {
780 if(!(ax1|ay1|ax2|ay2)) {
792 if(overlap1 && !overlap2)
793 msg("<warning> strange internal error");
794 if(!overlap1 && overlap2) {
795 msg("<warning> Bad bounding box: intersection outside bbox");
796 msg("<warning> given bbox: %d %d %d %d", x1, y1, x2, y2);
797 msg("<warning> changed area: %d %d %d %d", ax1, ay1, ax2, ay2);
798 //writeAlpha(booltextbitmap, "alpha.png");
805 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
808 state->transform(crop_x1,crop_y1,&x1,&y1);
809 state->transform(crop_x2,crop_y2,&x2,&y2);
810 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
811 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
813 this->movex = -(int)x1 - user_movex;
814 this->movey = -(int)y1 - user_movey;
816 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
822 this->width = (int)(x2-x1);
823 this->height = (int)(y2-y1);
825 msg("<debug> startPage");
826 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
827 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
828 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
829 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
830 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
831 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
833 boolpolybitmap = boolpolydev->getBitmap();
834 booltextbitmap = booltextdev->getBitmap();
835 clip0bitmap = clip0dev->getBitmap();
836 clip1bitmap = clip1dev->getBitmap();
837 rgbbitmap = rgbdev->getBitmap();
839 flushText(); // write out the initial clipping rectangle
841 /* just in case any device did draw a white background rectangle
843 clearBoolTextDev(UNKNOWN_BOUNDING_BOX);
844 clearBoolPolyDev(UNKNOWN_BOUNDING_BOX);
846 this->layerstate = STATE_PARALLEL;
848 msg("<debug> startPage done");
851 void BitmapOutputDev::endPage()
853 msg("<verbose> endPage (BitmapOutputDev)");
855 /* notice: we're not fully done yet with this page- there might still be
856 a few calls to drawLink() yet to come */
858 void BitmapOutputDev::finishPage()
860 msg("<verbose> finishPage (BitmapOutputDev)");
863 if(layerstate == STATE_BITMAP_IS_ABOVE) {
871 /* splash will now destroy alpha, and paint the
872 background color into the "holes" in the bitmap */
873 boolpolydev->endPage();
874 booltextdev->endPage();
880 GBool BitmapOutputDev::upsideDown()
882 boolpolydev->upsideDown();
883 booltextdev->upsideDown();
884 clip0dev->upsideDown();
885 clip1dev->upsideDown();
886 return rgbdev->upsideDown();
889 GBool BitmapOutputDev::useDrawChar()
891 boolpolydev->useDrawChar();
892 booltextdev->useDrawChar();
893 clip0dev->useDrawChar();
894 clip1dev->useDrawChar();
895 return rgbdev->useDrawChar();
898 GBool BitmapOutputDev::useTilingPatternFill()
900 boolpolydev->useTilingPatternFill();
901 booltextdev->useTilingPatternFill();
902 clip0dev->useTilingPatternFill();
903 clip1dev->useTilingPatternFill();
904 return rgbdev->useTilingPatternFill();
907 GBool BitmapOutputDev::useShadedFills()
909 boolpolydev->useShadedFills();
910 booltextdev->useShadedFills();
911 clip0dev->useShadedFills();
912 clip1dev->useShadedFills();
913 return rgbdev->useShadedFills();
916 GBool BitmapOutputDev::useDrawForm()
918 boolpolydev->useDrawForm();
919 booltextdev->useDrawForm();
920 clip0dev->useDrawForm();
921 clip1dev->useDrawForm();
922 return rgbdev->useDrawForm();
925 GBool BitmapOutputDev::interpretType3Chars()
927 boolpolydev->interpretType3Chars();
928 booltextdev->interpretType3Chars();
929 clip0dev->interpretType3Chars();
930 clip1dev->interpretType3Chars();
931 return rgbdev->interpretType3Chars();
934 GBool BitmapOutputDev::needNonText()
936 boolpolydev->needNonText();
937 booltextdev->needNonText();
938 clip0dev->needNonText();
939 clip1dev->needNonText();
940 return rgbdev->needNonText();
942 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
943 int rotate, GBool useMediaBox, GBool crop,
944 int sliceX, int sliceY, int sliceW, int sliceH,
945 GBool printing, Catalog *catalog,
946 GBool (*abortCheckCbk)(void *data),
947 void *abortCheckCbkData)
951 void BitmapOutputDev::setDefaultCTM(double *ctm)
953 boolpolydev->setDefaultCTM(ctm);
954 booltextdev->setDefaultCTM(ctm);
955 rgbdev->setDefaultCTM(ctm);
956 clip0dev->setDefaultCTM(ctm);
957 clip1dev->setDefaultCTM(ctm);
958 gfxdev->setDefaultCTM(ctm);
960 void BitmapOutputDev::saveState(GfxState *state)
962 boolpolydev->saveState(state);
963 booltextdev->saveState(state);
964 rgbdev->saveState(state);
965 clip0dev->saveState(state);
966 clip1dev->saveState(state);
968 /*ClipState*cstate = new ClipState();
969 cstate->next = this->clipstates;
970 this->clipstates = cstate;*/
972 void BitmapOutputDev::restoreState(GfxState *state)
974 boolpolydev->restoreState(state);
975 booltextdev->restoreState(state);
976 rgbdev->restoreState(state);
977 clip0dev->restoreState(state);
978 clip1dev->restoreState(state);
980 /*if(this->clipstates) {
981 ClipState*old = this->clipstates;
983 gfxdev->restoreState(state);
985 this->clipstates = this->clipstates->next;
988 msg("<error> invalid restoreState()");
991 void BitmapOutputDev::updateAll(GfxState *state)
993 boolpolydev->updateAll(state);
994 booltextdev->updateAll(state);
995 rgbdev->updateAll(state);
996 clip0dev->updateAll(state);
997 clip1dev->updateAll(state);
998 gfxdev->updateAll(state);
1000 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
1002 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1003 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1004 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1005 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1006 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1007 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1009 void BitmapOutputDev::updateLineDash(GfxState *state)
1011 boolpolydev->updateLineDash(state);
1012 booltextdev->updateLineDash(state);
1013 rgbdev->updateLineDash(state);
1014 clip0dev->updateLineDash(state);
1015 clip1dev->updateLineDash(state);
1016 gfxdev->updateLineDash(state);
1018 void BitmapOutputDev::updateFlatness(GfxState *state)
1020 boolpolydev->updateFlatness(state);
1021 booltextdev->updateFlatness(state);
1022 rgbdev->updateFlatness(state);
1023 clip0dev->updateFlatness(state);
1024 clip1dev->updateFlatness(state);
1025 gfxdev->updateFlatness(state);
1027 void BitmapOutputDev::updateLineJoin(GfxState *state)
1029 boolpolydev->updateLineJoin(state);
1030 booltextdev->updateLineJoin(state);
1031 rgbdev->updateLineJoin(state);
1032 clip0dev->updateLineJoin(state);
1033 clip1dev->updateLineJoin(state);
1034 gfxdev->updateLineJoin(state);
1036 void BitmapOutputDev::updateLineCap(GfxState *state)
1038 boolpolydev->updateLineCap(state);
1039 booltextdev->updateLineCap(state);
1040 rgbdev->updateLineCap(state);
1041 clip0dev->updateLineCap(state);
1042 clip1dev->updateLineCap(state);
1043 gfxdev->updateLineCap(state);
1045 void BitmapOutputDev::updateMiterLimit(GfxState *state)
1047 boolpolydev->updateMiterLimit(state);
1048 booltextdev->updateMiterLimit(state);
1049 rgbdev->updateMiterLimit(state);
1050 clip0dev->updateMiterLimit(state);
1051 clip1dev->updateMiterLimit(state);
1052 gfxdev->updateMiterLimit(state);
1054 void BitmapOutputDev::updateLineWidth(GfxState *state)
1056 boolpolydev->updateLineWidth(state);
1057 booltextdev->updateLineWidth(state);
1058 rgbdev->updateLineWidth(state);
1059 clip0dev->updateLineWidth(state);
1060 clip1dev->updateLineWidth(state);
1061 gfxdev->updateLineWidth(state);
1063 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
1065 boolpolydev->updateStrokeAdjust(state);
1066 booltextdev->updateStrokeAdjust(state);
1067 rgbdev->updateStrokeAdjust(state);
1068 clip0dev->updateStrokeAdjust(state);
1069 clip1dev->updateStrokeAdjust(state);
1070 gfxdev->updateStrokeAdjust(state);
1072 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
1074 boolpolydev->updateFillColorSpace(state);
1075 booltextdev->updateFillColorSpace(state);
1076 rgbdev->updateFillColorSpace(state);
1077 clip0dev->updateFillColorSpace(state);
1078 clip1dev->updateFillColorSpace(state);
1079 gfxdev->updateFillColorSpace(state);
1081 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
1083 boolpolydev->updateStrokeColorSpace(state);
1084 booltextdev->updateStrokeColorSpace(state);
1085 rgbdev->updateStrokeColorSpace(state);
1086 clip0dev->updateStrokeColorSpace(state);
1087 clip1dev->updateStrokeColorSpace(state);
1088 gfxdev->updateStrokeColorSpace(state);
1090 void BitmapOutputDev::updateFillColor(GfxState *state)
1092 boolpolydev->updateFillColor(state);
1093 booltextdev->updateFillColor(state);
1094 rgbdev->updateFillColor(state);
1095 clip0dev->updateFillColor(state);
1096 clip1dev->updateFillColor(state);
1097 gfxdev->updateFillColor(state);
1099 void BitmapOutputDev::updateStrokeColor(GfxState *state)
1101 boolpolydev->updateStrokeColor(state);
1102 booltextdev->updateStrokeColor(state);
1103 rgbdev->updateStrokeColor(state);
1104 clip0dev->updateStrokeColor(state);
1105 clip1dev->updateStrokeColor(state);
1106 gfxdev->updateStrokeColor(state);
1108 void BitmapOutputDev::updateBlendMode(GfxState *state)
1110 boolpolydev->updateBlendMode(state);
1111 booltextdev->updateBlendMode(state);
1112 rgbdev->updateBlendMode(state);
1113 clip0dev->updateBlendMode(state);
1114 clip1dev->updateBlendMode(state);
1115 gfxdev->updateBlendMode(state);
1117 void BitmapOutputDev::updateFillOpacity(GfxState *state)
1119 boolpolydev->updateFillOpacity(state);
1120 booltextdev->updateFillOpacity(state);
1121 rgbdev->updateFillOpacity(state);
1122 clip0dev->updateFillOpacity(state);
1123 clip1dev->updateFillOpacity(state);
1124 gfxdev->updateFillOpacity(state);
1126 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
1128 boolpolydev->updateStrokeOpacity(state);
1129 booltextdev->updateStrokeOpacity(state);
1130 rgbdev->updateStrokeOpacity(state);
1131 clip0dev->updateStrokeOpacity(state);
1132 clip1dev->updateStrokeOpacity(state);
1133 gfxdev->updateStrokeOpacity(state);
1135 void BitmapOutputDev::updateFillOverprint(GfxState *state)
1137 boolpolydev->updateFillOverprint(state);
1138 booltextdev->updateFillOverprint(state);
1139 rgbdev->updateFillOverprint(state);
1140 clip0dev->updateFillOverprint(state);
1141 clip1dev->updateFillOverprint(state);
1142 gfxdev->updateFillOverprint(state);
1144 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
1146 boolpolydev->updateStrokeOverprint(state);
1147 booltextdev->updateStrokeOverprint(state);
1148 rgbdev->updateStrokeOverprint(state);
1149 clip0dev->updateStrokeOverprint(state);
1150 clip1dev->updateStrokeOverprint(state);
1151 gfxdev->updateStrokeOverprint(state);
1153 void BitmapOutputDev::updateTransfer(GfxState *state)
1155 boolpolydev->updateTransfer(state);
1156 booltextdev->updateTransfer(state);
1157 rgbdev->updateTransfer(state);
1158 clip0dev->updateTransfer(state);
1159 clip1dev->updateTransfer(state);
1160 gfxdev->updateTransfer(state);
1163 void BitmapOutputDev::updateFont(GfxState *state)
1165 boolpolydev->updateFont(state);
1166 booltextdev->updateFont(state);
1167 rgbdev->updateFont(state);
1168 clip0dev->updateFont(state);
1169 clip1dev->updateFont(state);
1170 gfxdev->updateFont(state);
1172 void BitmapOutputDev::updateTextMat(GfxState *state)
1174 boolpolydev->updateTextMat(state);
1175 booltextdev->updateTextMat(state);
1176 rgbdev->updateTextMat(state);
1177 clip0dev->updateTextMat(state);
1178 clip1dev->updateTextMat(state);
1179 gfxdev->updateTextMat(state);
1181 void BitmapOutputDev::updateCharSpace(GfxState *state)
1183 boolpolydev->updateCharSpace(state);
1184 booltextdev->updateCharSpace(state);
1185 rgbdev->updateCharSpace(state);
1186 clip0dev->updateCharSpace(state);
1187 clip1dev->updateCharSpace(state);
1188 gfxdev->updateCharSpace(state);
1190 void BitmapOutputDev::updateRender(GfxState *state)
1192 boolpolydev->updateRender(state);
1193 booltextdev->updateRender(state);
1194 rgbdev->updateRender(state);
1195 clip0dev->updateRender(state);
1196 clip1dev->updateRender(state);
1197 gfxdev->updateRender(state);
1199 void BitmapOutputDev::updateRise(GfxState *state)
1201 boolpolydev->updateRise(state);
1202 booltextdev->updateRise(state);
1203 rgbdev->updateRise(state);
1204 clip0dev->updateRise(state);
1205 clip1dev->updateRise(state);
1206 gfxdev->updateRise(state);
1208 void BitmapOutputDev::updateWordSpace(GfxState *state)
1210 boolpolydev->updateWordSpace(state);
1211 booltextdev->updateWordSpace(state);
1212 rgbdev->updateWordSpace(state);
1213 clip0dev->updateWordSpace(state);
1214 clip1dev->updateWordSpace(state);
1215 gfxdev->updateWordSpace(state);
1217 void BitmapOutputDev::updateHorizScaling(GfxState *state)
1219 boolpolydev->updateHorizScaling(state);
1220 booltextdev->updateHorizScaling(state);
1221 rgbdev->updateHorizScaling(state);
1222 clip0dev->updateHorizScaling(state);
1223 clip1dev->updateHorizScaling(state);
1224 gfxdev->updateHorizScaling(state);
1226 void BitmapOutputDev::updateTextPos(GfxState *state)
1228 boolpolydev->updateTextPos(state);
1229 booltextdev->updateTextPos(state);
1230 rgbdev->updateTextPos(state);
1231 clip0dev->updateTextPos(state);
1232 clip1dev->updateTextPos(state);
1233 gfxdev->updateTextPos(state);
1235 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
1237 boolpolydev->updateTextShift(state, shift);
1238 booltextdev->updateTextShift(state, shift);
1239 rgbdev->updateTextShift(state, shift);
1240 clip0dev->updateTextShift(state, shift);
1241 clip1dev->updateTextShift(state, shift);
1242 gfxdev->updateTextShift(state, shift);
1245 double max(double x, double y)
1249 double min(double x, double y)
1254 gfxbbox_t BitmapOutputDev::getBBox(GfxState*state)
1256 GfxPath * path = state->getPath();
1257 int num = path->getNumSubpaths();
1258 gfxbbox_t bbox = {0,0,1,1};
1261 for(t = 0; t < num; t++) {
1262 GfxSubpath *subpath = path->getSubpath(t);
1263 int subnum = subpath->getNumPoints();
1265 for(s=0;s<subnum;s++) {
1267 state->transform(subpath->getX(s),subpath->getY(s),&x,&y);
1269 bbox.xmin = x; bbox.ymin = y;
1270 bbox.xmax = x; bbox.ymax = y;
1273 bbox.xmin = min(bbox.xmin, x);
1274 bbox.ymin = min(bbox.ymin, y);
1275 bbox.xmax = max(bbox.xmax, x);
1276 bbox.ymax = max(bbox.ymax, y);
1283 void BitmapOutputDev::stroke(GfxState *state)
1285 msg("<debug> stroke");
1286 boolpolydev->stroke(state);
1287 gfxbbox_t bbox = getBBox(state);
1288 double width = state->getTransformedLineWidth();
1289 bbox.xmin -= width; bbox.ymin -= width;
1290 bbox.xmax += width; bbox.ymax += width;
1291 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1292 rgbdev->stroke(state);
1294 void BitmapOutputDev::fill(GfxState *state)
1296 msg("<debug> fill");
1297 boolpolydev->fill(state);
1298 gfxbbox_t bbox = getBBox(state);
1299 if(checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax))) {
1300 boolpolydev->fill(state);
1302 rgbdev->fill(state);
1304 void BitmapOutputDev::eoFill(GfxState *state)
1306 msg("<debug> eoFill");
1307 boolpolydev->eoFill(state);
1308 gfxbbox_t bbox = getBBox(state);
1309 if(checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax))) {
1310 boolpolydev->eoFill(state);
1312 rgbdev->eoFill(state);
1314 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1315 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
1316 int paintType, Dict *resDict,
1317 double *mat, double *bbox,
1318 int x0, int y0, int x1, int y1,
1319 double xStep, double yStep)
1321 msg("<debug> tilingPatternFill");
1322 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1323 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1324 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1327 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
1328 int paintType, Dict *resDict,
1329 double *mat, double *bbox,
1330 int x0, int y0, int x1, int y1,
1331 double xStep, double yStep)
1333 msg("<debug> tilingPatternFill");
1334 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1335 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1336 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1340 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
1342 msg("<debug> functionShadedFill");
1343 boolpolydev->functionShadedFill(state, shading);
1344 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1345 return rgbdev->functionShadedFill(state, shading);
1347 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
1349 msg("<debug> axialShadedFill");
1350 boolpolydev->axialShadedFill(state, shading);
1351 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1352 return rgbdev->axialShadedFill(state, shading);
1354 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
1356 msg("<debug> radialShadedFill");
1357 boolpolydev->radialShadedFill(state, shading);
1358 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1359 return rgbdev->radialShadedFill(state, shading);
1362 SplashColor black = {0,0,0};
1363 SplashColor white = {255,255,255};
1365 void BitmapOutputDev::clip(GfxState *state)
1367 msg("<debug> clip");
1368 boolpolydev->clip(state);
1369 booltextdev->clip(state);
1370 rgbdev->clip(state);
1371 clip1dev->clip(state);
1373 void BitmapOutputDev::eoClip(GfxState *state)
1375 msg("<debug> eoClip");
1376 boolpolydev->eoClip(state);
1377 booltextdev->eoClip(state);
1378 rgbdev->eoClip(state);
1379 clip1dev->eoClip(state);
1381 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1383 msg("<debug> clipToStrokePath");
1384 boolpolydev->clipToStrokePath(state);
1385 booltextdev->clipToStrokePath(state);
1386 rgbdev->clipToStrokePath(state);
1387 clip1dev->clipToStrokePath(state);
1390 void BitmapOutputDev::beginStringOp(GfxState *state)
1392 msg("<debug> beginStringOp");
1393 clip0dev->beginStringOp(state);
1394 clip1dev->beginStringOp(state);
1395 booltextdev->beginStringOp(state);
1396 gfxdev->beginStringOp(state);
1398 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1400 msg("<debug> beginString");
1401 clip0dev->beginString(state, s);
1402 clip1dev->beginString(state, s);
1403 booltextdev->beginString(state, s);
1404 gfxdev->beginString(state, s);
1407 void BitmapOutputDev::clearClips()
1409 clearBooleanBitmap(clip0bitmap, 0, 0, 0, 0);
1410 clearBooleanBitmap(clip1bitmap, 0, 0, 0, 0);
1412 void BitmapOutputDev::clearBoolPolyDev(int x1, int y1, int x2, int y2)
1414 clearBooleanBitmap(boolpolybitmap, x1, y1, x2, y2);
1416 void BitmapOutputDev::clearBoolTextDev(int x1, int y1, int x2, int y2)
1418 clearBooleanBitmap(booltextbitmap, x1, y1, x2, y2);
1420 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1421 double dx, double dy,
1422 double originX, double originY,
1423 CharCode code, int nBytes, Unicode *u, int uLen)
1425 msg("<debug> drawChar render=%d", state->getRender());
1427 if(state->getRender()&RENDER_CLIP) {
1428 //char is just a clipping boundary
1429 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1430 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1431 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1432 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1433 } else if(rgbbitmap != rgbdev->getBitmap()) {
1434 // we're doing softmasking or transparency grouping
1435 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1436 //checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1437 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1439 // we're drawing a regular char
1441 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1442 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1444 /* calculate the bbox of this character */
1445 int x1 = (int)x, x2 = (int)x+1, y1 = (int)y, y2 = (int)y+1;
1446 SplashFont*font = clip0dev->getCurrentFont();
1447 SplashPath*path = font?font->getGlyphPath(code):NULL;
1451 msg("<error> couldn't create outline for char %d", code);
1456 path->offset((SplashCoord)x, (SplashCoord)y);
1458 for(t=0;t<path->getLength();t++) {
1461 path->getPoint(t,&xx,&yy,&f);
1462 state->transform(xx,yy,&xx,&yy);
1463 if(xx<x1) x1=(int)xx;
1464 if(yy<y1) y1=(int)yy;
1465 if(xx>=x2) x2=(int)xx+1;
1466 if(yy>=y2) y2=(int)yy+1;
1469 /* if this character is affected somehow by the various clippings (i.e., it looks
1470 different on a device without clipping), then draw it on the bitmap, not as
1472 if(clip0and1differ(x1,y1,x2,y2)) {
1473 msg("<verbose> Char %d is affected by clipping", code);
1474 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1475 checkNewBitmap(x1,y1,x2,y2);
1476 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1477 if(config_extrafontdata) {
1478 int oldrender = state->getRender();
1479 state->setRender(3); //invisible
1480 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1481 state->setRender(oldrender);
1485 /* this char is not at all affected by clipping.
1486 Now just dump out the bitmap we're currently working on, if necessary. */
1487 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1488 checkNewText(x1,y1,x2,y2);
1489 /* use polygonal output device to do the actual text handling */
1490 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1494 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1496 msg("<error> internal error: drawString not implemented");
1498 clip0dev->drawString(state, s);
1499 clip1dev->drawString(state, s);
1500 booltextdev->drawString(state, s);
1501 gfxdev->drawString(state, s);
1503 void BitmapOutputDev::endTextObject(GfxState *state)
1505 msg("<debug> endTextObject");
1506 rgbdev->endTextObject(state);
1507 clip0dev->endTextObject(state);
1508 clip1dev->endTextObject(state);
1509 booltextdev->endTextObject(state);
1510 /* the only thing "drawn" here is clipping */
1511 //checkNewText(UNKNOWN_BOUNDING_BOX);
1512 gfxdev->endTextObject(state);
1514 void BitmapOutputDev::endString(GfxState *state)
1516 msg("<debug> endString");
1517 clip0dev->endString(state);
1518 clip1dev->endString(state);
1519 booltextdev->endString(state);
1520 int render = state->getRender();
1521 if(render != RENDER_INVISIBLE && render != RENDER_FILL) {
1522 checkNewText(UNKNOWN_BOUNDING_BOX);
1524 gfxdev->endString(state);
1526 void BitmapOutputDev::endStringOp(GfxState *state)
1528 msg("<debug> endStringOp");
1529 clip0dev->endStringOp(state);
1530 clip1dev->endStringOp(state);
1531 booltextdev->endStringOp(state);
1532 gfxdev->endStringOp(state);
1535 /* TODO: these four operations below *should* do nothing, as type3
1536 chars are drawn using operations like fill() */
1537 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1538 double dx, double dy,
1539 CharCode code, Unicode *u, int uLen)
1541 msg("<debug> beginType3Char");
1542 /* call gfxdev so that it can generate "invisible" characters
1543 on top of the actual graphic content, for text extraction */
1544 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1546 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1548 msg("<debug> type3D0");
1549 return gfxdev->type3D0(state, wx, wy);
1551 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1553 msg("<debug> type3D1");
1554 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1556 void BitmapOutputDev::endType3Char(GfxState *state)
1558 msg("<debug> endType3Char");
1559 gfxdev->endType3Char(state);
1562 class CopyStream: public Object
1566 MemStream*memstream;
1568 CopyStream(Stream*str, int len)
1573 buf = (char*)malloc(len);
1575 for (t=0; t<len; t++)
1576 buf[t] = str->getChar();
1579 this->dict = str->getDict();
1580 this->memstream = new MemStream(buf, 0, len, this);
1584 ::free(this->buf);this->buf = 0;
1585 delete this->memstream;
1587 Dict* getDict() {return dict;}
1588 Stream* getStream() {return this->memstream;};
1591 gfxbbox_t BitmapOutputDev::getImageBBox(GfxState*state)
1595 state->transform(0, 1, &x, &y);
1596 bbox.xmin=bbox.xmax = x;
1597 bbox.ymin=bbox.ymax = x;
1598 state->transform(0, 0, &x, &y);
1599 bbox.xmin=min(bbox.xmin,x);
1600 bbox.ymin=min(bbox.ymin,y);
1601 bbox.xmax=max(bbox.xmin,x);
1602 bbox.ymax=max(bbox.ymin,y);
1603 state->transform(1, 0, &x, &y);
1604 bbox.xmin=min(bbox.xmin,x);
1605 bbox.ymin=min(bbox.ymin,y);
1606 bbox.xmax=max(bbox.xmin,x);
1607 bbox.ymax=max(bbox.ymin,y);
1608 state->transform(1, 1, &x, &y);
1609 bbox.xmin=min(bbox.xmin,x);
1610 bbox.ymin=min(bbox.ymin,y);
1611 bbox.xmax=max(bbox.xmin,x);
1612 bbox.ymax=max(bbox.ymin,y);
1615 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1616 int width, int height, GBool invert,
1619 msg("<debug> drawImageMask streamkind=%d", str->getKind());
1620 CopyStream*cpystr = 0;
1622 cpystr = new CopyStream(str, height * ((width + 7) / 8));
1623 str = cpystr->getStream();
1625 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1626 gfxbbox_t bbox = getImageBBox(state);
1627 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1628 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1632 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1633 int width, int height, GfxImageColorMap *colorMap,
1634 int *maskColors, GBool inlineImg)
1636 msg("<debug> drawImage streamkind=%d", str->getKind());
1637 CopyStream*cpystr = 0;
1639 cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1640 str = cpystr->getStream();
1642 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1643 gfxbbox_t bbox=getImageBBox(state);
1644 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1645 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1649 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1650 int width, int height,
1651 GfxImageColorMap *colorMap,
1652 Stream *maskStr, int maskWidth, int maskHeight,
1655 msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
1656 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1657 gfxbbox_t bbox=getImageBBox(state);
1658 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1659 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1661 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1662 int width, int height,
1663 GfxImageColorMap *colorMap,
1665 int maskWidth, int maskHeight,
1666 GfxImageColorMap *maskColorMap)
1668 msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
1669 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1670 gfxbbox_t bbox=getImageBBox(state);
1671 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1672 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1674 void BitmapOutputDev::drawForm(Ref id)
1676 msg("<debug> drawForm");
1677 boolpolydev->drawForm(id);
1678 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1679 rgbdev->drawForm(id);
1682 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1684 msg("<debug> processLink");
1685 gfxdev->processLink(link, catalog);
1688 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1689 GfxColorSpace *blendingColorSpace,
1690 GBool isolated, GBool knockout,
1693 msg("<debug> beginTransparencyGroup");
1694 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1695 GfxState*state1 = state->copy();
1696 GfxState*state2 = state->copy();
1698 state1->setPath(state->getPath()->copy());
1700 state2->setPath(state->getPath()->copy());
1702 GfxState*state1 = state->copy(gTrue);
1703 GfxState*state2 = state->copy(gTrue);
1705 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1706 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1707 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1711 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1713 msg("<debug> endTransparencyGroup");
1714 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1715 GfxState*state1 = state->copy();
1716 GfxState*state2 = state->copy();
1718 state1->setPath(state->getPath()->copy());
1720 state2->setPath(state->getPath()->copy());
1722 GfxState*state1 = state->copy(gTrue);
1723 GfxState*state2 = state->copy(gTrue);
1725 boolpolydev->endTransparencyGroup(state1);
1726 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1727 rgbdev->endTransparencyGroup(state2);
1730 clip1dev->endTransparencyGroup(state);
1732 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1734 msg("<debug> paintTransparencyGroup");
1735 boolpolydev->paintTransparencyGroup(state,bbox);
1736 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1737 rgbdev->paintTransparencyGroup(state,bbox);
1738 clip1dev->paintTransparencyGroup(state,bbox);
1740 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1742 msg("<debug> setSoftMask");
1743 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1744 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1745 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1746 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1748 void BitmapOutputDev::clearSoftMask(GfxState *state)
1750 msg("<debug> clearSoftMask");
1751 boolpolydev->clearSoftMask(state);
1752 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1753 rgbdev->clearSoftMask(state);
1754 clip1dev->clearSoftMask(state);