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::preparePage(int pdfpage, int outputpage)
160 static void getBitmapBBox(Guchar*alpha, int width, int height, int*xmin, int*ymin, int*xmax, int*ymax)
166 for(y=0;y<height;y++) {
167 Guchar*a = &alpha[y*width];
168 for(x=0;x<width;x++) {
171 int left = x; //first occupied pixel from left
172 int right = x+1; //last non-occupied pixel from right
181 if(left<*xmin) *xmin = left;
182 if(right>*xmax) *xmax = right;
185 if(*xmin>=*xmax || *ymin>=*ymax) {
193 void BitmapOutputDev::flushBitmap()
195 int width = rgbdev->getBitmapWidth();
196 int height = rgbdev->getBitmapHeight();
198 SplashColorPtr rgb = rgbbitmap->getDataPtr();
199 Guchar*alpha = rgbbitmap->getAlphaPtr();
200 Guchar*alpha2 = boolpolybitmap->getAlphaPtr();
202 int xmin,ymin,xmax,ymax;
203 getBitmapBBox(alpha, width, height, &xmin,&ymin,&xmax,&ymax);
205 /* clip against (-movex, -movey, -movex+width, -movey+height) */
206 if(xmin < -this->movex) xmin = -this->movex;
207 if(ymin < -this->movey) ymin = -this->movey;
208 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
209 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
211 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
213 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
216 if(sizeof(SplashColor)!=3) {
217 msg("<error> sizeof(SplashColor)!=3");
224 int rangex = xmax-xmin;
225 int rangey = ymax-ymin;
226 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
227 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
229 img->height = rangey;
231 for(y=0;y<rangey;y++) {
232 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
233 gfxcolor_t*out = &img->data[y*rangex];
234 Guchar*ain = &alpha[(y+ymin)*width+xmin];
235 Guchar*ain2 = &alpha2[(y+ymin)*width+xmin];
236 if(this->emptypage) {
237 for(x=0;x<rangex;x++) {
238 /* the first bitmap on the page doesn't need to have an alpha channel-
239 blend against a white background*/
240 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
241 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
242 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
246 for(x=0;x<rangex;x++) {
249 out[x].r = 0;out[x].g = 0;out[x].b = 0;out[x].a = 0;
252 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we
253 have to premultiply alpha (mix background and pixel according to the alpha channel).
255 out[x].r = (in[x*3+0]*ain[x])/255;
256 out[x].g = (in[x*3+1]*ain[x])/255;
257 out[x].b = (in[x*3+2]*ain[x])/255;
262 /* transform bitmap rectangle to "device space" */
276 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
277 dev->fillbitmap(dev, line, img, &m, 0);
280 memset(rgbbitmap->getAlphaPtr(), 0, rgbbitmap->getWidth()*rgbbitmap->getHeight());
281 memset(rgbbitmap->getDataPtr(), 0, rgbbitmap->getRowSize()*rgbbitmap->getHeight());
283 free(img->data);img->data=0;free(img);img=0;
288 void BitmapOutputDev::flushText()
290 msg("<verbose> Flushing text/polygons");
291 gfxdevice_record_flush(this->gfxoutput, this->dev);
296 void writeBitmap(SplashBitmap*bitmap, char*filename)
300 int width = bitmap->getWidth();
301 int height = bitmap->getHeight();
303 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
306 if(bitmap->getMode()==splashModeMono1)
309 for(y=0;y<height;y++) {
310 gfxcolor_t*line = &data[y*width];
311 for(x=0;x<width;x++) {
312 Guchar c[4] = {0,0,0,0};
313 bitmap->getPixel(x,y,c);
320 int a = bitmap->getAlpha(x,y);
325 writePNG(filename, (unsigned char*)data, width, height);
329 void writeAlpha(SplashBitmap*bitmap, char*filename)
333 int width = bitmap->getWidth();
334 int height = bitmap->getHeight();
336 if(bitmap->getMode()==splashModeMono1) {
337 writeBitmap(bitmap, filename);
341 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
343 for(y=0;y<height;y++) {
344 gfxcolor_t*line = &data[y*width];
345 for(x=0;x<width;x++) {
346 int a = bitmap->getAlpha(x,y);
353 writePNG(filename, (unsigned char*)data, width, height);
356 static int dbg_btm_counter=1;
358 static const char*STATE_NAME[] = {"parallel", "textabovebitmap", "bitmapabovetext"};
360 int checkAlphaSanity(SplashBitmap*boolbtm, SplashBitmap*alphabtm)
362 assert(boolbtm->getWidth() == alphabtm->getWidth());
363 assert(boolbtm->getHeight() == alphabtm->getHeight());
364 if(boolbtm->getMode()==splashModeMono1) {
368 int width = boolbtm->getWidth();
369 int height = boolbtm->getHeight();
373 for(y=0;y<height;y++) {
374 for(x=0;x<width;x++) {
375 int a1 = alphabtm->getAlpha(x,y);
376 int a2 = boolbtm->getAlpha(x,y);
382 double badness = bad/(double)(width*height);
384 msg("<error> Bitmaps don't correspond: %d out of %d pixels wrong (%.2f%%)", bad, width*height,
388 msg("<notice> %f", badness);
392 GBool BitmapOutputDev::checkNewText(int x1, int y1, int x2, int y2)
394 /* called once some new text was drawn on booltextdev, and
395 before the same thing is drawn on gfxdev */
397 msg("<trace> Testing new text data against current bitmap data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
402 sprintf(filename1, "state%dboolbitmap_afternewtext.png", dbg_btm_counter);
403 sprintf(filename2, "state%dbooltext_afternewtext.png", dbg_btm_counter);
404 sprintf(filename3, "state%dbitmap_afternewtext.png", dbg_btm_counter);
406 msg("<verbose> %s %s %s", filename1, filename2, filename3);
407 writeAlpha(boolpolybitmap, filename1);
408 writeAlpha(booltextbitmap, filename2);
409 writeBitmap(rgbdev->getBitmap(), filename3);
414 if(intersection(x1,y1,x2,y2)) {
415 if(layerstate==STATE_PARALLEL) {
416 /* the new text is above the bitmap. So record that fact,
417 and also clear the bitmap buffer, so we can check for
419 msg("<verbose> Text is above current bitmap/polygon data");
420 layerstate=STATE_TEXT_IS_ABOVE;
421 clearBoolPolyDev(x1,y1,x2,y2);
422 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
423 /* there's a bitmap above the (old) text. So we need
424 to flush out that text, and record that the *new*
425 text is now *above* the bitmap
427 msg("<verbose> Text is above current bitmap/polygon data (which is above some other text)");
429 layerstate=STATE_TEXT_IS_ABOVE;
430 /* clear both bool devices- the text device because
431 we just dumped out all the (old) text, and the
432 poly dev so we can check for new intersections */
433 clearBoolPolyDev(x1,y1,x2,y2);
434 /* FIXME this destroys the text pixels we just
435 drew to test for the intersection- however we need
436 those to check for the *new* intersections */
437 clearBoolTextDev(x1,y1,x2,y2);
440 /* we already know that the current text section is
441 above the current bitmap section- now just new
442 bitmap data *and* new text data was drawn, and
443 *again* it's above the current bitmap- so clear
444 the polygon bitmap again, so we can check for
446 msg("<verbose> Text is still above current bitmap/polygon data");
447 clearBoolPolyDev(x1,y1,x2,y2);
453 GBool BitmapOutputDev::checkNewBitmap(int x1, int y1, int x2, int y2)
455 /* similar to checkNewText() above, only in reverse */
456 msg("<trace> Testing new graphics data against current text data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
461 sprintf(filename1, "state%dboolbitmap_afternewgfx.png", dbg_btm_counter);
462 sprintf(filename2, "state%dbooltext_afternewgfx.png", dbg_btm_counter);
463 sprintf(filename3, "state%dbitmap_afternewgfx.png", dbg_btm_counter);
465 if(dbg_btm_counter==12) {
466 msg("<verbose> %s %s %s", filename1, filename2, filename3);
467 writeAlpha(boolpolybitmap, filename1);
468 writeAlpha(booltextbitmap, filename2);
469 writeBitmap(rgbdev->getBitmap(), filename3);
474 if(intersection(x1,y1,x2,y2)) {
475 if(layerstate==STATE_PARALLEL) {
476 msg("<verbose> Bitmap is above current text data");
477 layerstate=STATE_BITMAP_IS_ABOVE;
478 clearBoolTextDev(x1,y1,x2,y2);
479 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
480 msg("<verbose> Bitmap is above current text data (which is above some bitmap)");
482 layerstate=STATE_BITMAP_IS_ABOVE;
483 clearBoolTextDev(x1,y1,x2,y2);
484 /* FIXME this destroys the polygon pixels we just
485 drew to test for the intersection- however we need
486 those to check for the *new* intersections */
487 clearBoolPolyDev(x1,y1,x2,y2);
490 msg("<verbose> Bitmap is still above current text data");
491 clearBoolTextDev(x1,y1,x2,y2);
497 //void checkNewText() {
498 // Guchar*alpha = rgbbitmap->getAlphaPtr();
499 // Guchar*charpixels = clip1bitmap->getDataPtr();
501 // for(yy=0;yy<height;yy++) {
502 // Guchar*aline = &alpha[yy*width];
503 // Guchar*cline = &charpixels[yy*width8];
504 // for(xx=0;xx<width;xx++) {
506 // int bytepos = xx>>3;
507 // /* TODO: is the bit order correct? */
508 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
515 static inline GBool fixBBox(int*x1, int*y1, int*x2, int*y2, int width, int height)
517 if(!(*x1|*y1|*x2|*y2)) {
524 if(*x2<=*x1) return gFalse;
525 if(*x2<0) return gFalse;
527 if(*x1>=width) return gFalse;
528 if(*x2>width) *x2=width;
530 if(*y2<=*y1) return gFalse;
531 if(*y2<0) return gFalse;
533 if(*y1>=height) return gFalse;
534 if(*y2>height) *y2=height;
538 GBool BitmapOutputDev::clip0and1differ(int x1,int y1,int x2,int y2)
540 if(clip0bitmap->getMode()==splashModeMono1) {
541 int width = clip0bitmap->getWidth();
542 int width8 = (width+7)/8;
543 int height = clip0bitmap->getHeight();
545 if(fixBBox(&x1,&y1,&x2,&y2,width,height)) {
546 /* area is outside or null */
550 SplashBitmap*clip0 = clip0bitmap;
551 SplashBitmap*clip1 = clip1bitmap;
557 unsigned char*row1 = &clip0bitmap->getDataPtr()[width8*y+x18];
558 unsigned char*row2 = &clip1bitmap->getDataPtr()[width8*y+x28];
559 if(memcmp(row1, row2, x28-x18))
564 SplashBitmap*clip0 = clip0bitmap;
565 SplashBitmap*clip1 = clip1bitmap;
566 int width = clip0->getAlphaRowSize();
567 int height = clip0->getHeight();
569 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
573 Guchar*a0 = clip0->getAlphaPtr();
574 Guchar*a1 = clip1->getAlphaPtr();
579 if(a0[y*width+x]!=a1[y*width+x]) {
587 char differs2 = memcmp(a0, a1, width*height);
588 if(differs && !differs2)
589 msg("<warning> Strange internal error (2)");
590 else if(!differs && differs2) {
591 msg("<warning> Bad Bounding Box: Difference in clip0 and clip1 outside bbox");
592 msg("<warning> %d %d %d %d", x1, y1, x2, y2);
598 static void clearBooleanBitmap(SplashBitmap*btm, int x1, int y1, int x2, int y2)
602 x2 = btm->getWidth();
603 y2 = btm->getHeight();
605 if(btm->getMode()==splashModeMono1) {
606 int width8 = (btm->getWidth()+7)/8;
607 int width = btm->getWidth();
608 int height = btm->getHeight();
609 memset(btm->getDataPtr(), 0, width8*height);
611 int width = btm->getAlphaRowSize();
612 int height = btm->getHeight();
613 memset(btm->getAlphaPtr(), 0, width*height);
617 GBool compare8(unsigned char*data1, unsigned char*data2, int len)
621 if(((ptroff_t)data1&7)==((ptroff_t)data2&7)) {
622 // oh good, we can do aligning
623 while((ptroff_t)data1&7) {
632 /* use 64 bit for the (hopefully aligned) middle section */
634 long long unsigned int*d1 = (long long unsigned int*)data1;
635 long long unsigned int*d2 = (long long unsigned int*)data2;
636 long long unsigned int x = 0;
648 if(data1[t]&data2[t]) {
655 GBool BitmapOutputDev::intersection(int x1, int y1, int x2, int y2)
657 SplashBitmap*boolpoly = boolpolybitmap;
658 SplashBitmap*booltext = booltextbitmap;
660 if(boolpoly->getMode()==splashModeMono1) {
661 /* alternative implementation, using one bit per pixel-
662 needs the no-dither patch in xpdf */
664 int width = boolpoly->getWidth();
665 int height = boolpoly->getHeight();
667 if(!fixBBox(&x1,&y1,&x2,&y2, width, height)) {
671 Guchar*polypixels = boolpoly->getDataPtr();
672 Guchar*textpixels = booltext->getDataPtr();
674 int width8 = (width+7)/8;
679 polypixels+=y1*width8+x1/8;
680 textpixels+=y1*width8+x1/8;
681 runx=(x2+7)/8 - x1/8;
688 /*assert(sizeof(unsigned long long int)==8);
689 if(((ptroff_t)polypixels&7) || ((ptroff_t)textpixels&7)) {
690 //msg("<warning> Non-optimal alignment");
694 unsigned char*data1 = (unsigned char*)polypixels;
695 unsigned char*data2 = (unsigned char*)textpixels;
696 msg("<verbose> Testing area (%d,%d,%d,%d), runx=%d,runy=%d", x1,y1,x2,y2, runx, runy);
697 for(y=0;y<runy;y++) {
698 compare8(data1,data2,runx);
699 /*for(x=0;x<runx;x++) {
700 if(data1[x]&data2[x])
708 int width = boolpoly->getAlphaRowSize();
709 int height = boolpoly->getHeight();
711 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
714 Guchar*polypixels = boolpoly->getAlphaPtr();
715 Guchar*textpixels = booltext->getAlphaPtr();
722 if(polypixels[width*y+x]&&textpixels[width*y+x])
726 int ax1=0,ay1=0,ax2=0,ay2=0;
727 for(y=0;y<height;y++) {
728 for(x=0;x<width;x++) {
729 if(polypixels[width*y+x]&&textpixels[width*y+x]) {
731 if(!(ax1|ay1|ax2|ay2)) {
743 if(overlap1 && !overlap2)
744 msg("<warning> strange internal error");
745 if(!overlap1 && overlap2) {
746 msg("<warning> Bad bounding box: intersection outside bbox");
747 msg("<warning> given bbox: %d %d %d %d", x1, y1, x2, y2);
748 msg("<warning> changed area: %d %d %d %d", ax1, ay1, ax2, ay2);
749 //writeAlpha(booltextbitmap, "alpha.png");
756 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
759 state->transform(crop_x1,crop_y1,&x1,&y1);
760 state->transform(crop_x2,crop_y2,&x2,&y2);
761 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
762 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
764 this->movex = -(int)x1 - user_movex;
765 this->movey = -(int)y1 - user_movey;
767 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
773 this->width = (int)(x2-x1);
774 this->height = (int)(y2-y1);
776 msg("<debug> startPage");
777 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
778 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
779 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
780 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
781 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
782 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
784 boolpolybitmap = boolpolydev->getBitmap();
785 booltextbitmap = booltextdev->getBitmap();
786 clip0bitmap = clip0dev->getBitmap();
787 clip1bitmap = clip1dev->getBitmap();
788 rgbbitmap = rgbdev->getBitmap();
790 flushText(); // write out the initial clipping rectangle
792 /* just in case any device did draw a white background rectangle
794 clearBoolTextDev(UNKNOWN_BOUNDING_BOX);
795 clearBoolPolyDev(UNKNOWN_BOUNDING_BOX);
797 this->layerstate = STATE_PARALLEL;
799 msg("<debug> startPage done");
802 void BitmapOutputDev::endPage()
804 msg("<verbose> endPage (BitmapOutputDev)");
806 /* notice: we're not fully done yet with this page- there might still be
807 a few calls to drawLink() yet to come */
809 void BitmapOutputDev::finishPage()
811 msg("<verbose> finishPage (BitmapOutputDev)");
814 if(layerstate == STATE_BITMAP_IS_ABOVE) {
822 /* splash will now destroy alpha, and paint the
823 background color into the "holes" in the bitmap */
824 boolpolydev->endPage();
825 booltextdev->endPage();
831 GBool BitmapOutputDev::upsideDown()
833 boolpolydev->upsideDown();
834 booltextdev->upsideDown();
835 clip0dev->upsideDown();
836 clip1dev->upsideDown();
837 return rgbdev->upsideDown();
840 GBool BitmapOutputDev::useDrawChar()
842 boolpolydev->useDrawChar();
843 booltextdev->useDrawChar();
844 clip0dev->useDrawChar();
845 clip1dev->useDrawChar();
846 return rgbdev->useDrawChar();
849 GBool BitmapOutputDev::useTilingPatternFill()
851 boolpolydev->useTilingPatternFill();
852 booltextdev->useTilingPatternFill();
853 clip0dev->useTilingPatternFill();
854 clip1dev->useTilingPatternFill();
855 return rgbdev->useTilingPatternFill();
858 GBool BitmapOutputDev::useShadedFills()
860 boolpolydev->useShadedFills();
861 booltextdev->useShadedFills();
862 clip0dev->useShadedFills();
863 clip1dev->useShadedFills();
864 return rgbdev->useShadedFills();
867 GBool BitmapOutputDev::useDrawForm()
869 boolpolydev->useDrawForm();
870 booltextdev->useDrawForm();
871 clip0dev->useDrawForm();
872 clip1dev->useDrawForm();
873 return rgbdev->useDrawForm();
876 GBool BitmapOutputDev::interpretType3Chars()
878 boolpolydev->interpretType3Chars();
879 booltextdev->interpretType3Chars();
880 clip0dev->interpretType3Chars();
881 clip1dev->interpretType3Chars();
882 return rgbdev->interpretType3Chars();
885 GBool BitmapOutputDev::needNonText()
887 boolpolydev->needNonText();
888 booltextdev->needNonText();
889 clip0dev->needNonText();
890 clip1dev->needNonText();
891 return rgbdev->needNonText();
893 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
894 int rotate, GBool useMediaBox, GBool crop,
895 int sliceX, int sliceY, int sliceW, int sliceH,
896 GBool printing, Catalog *catalog,
897 GBool (*abortCheckCbk)(void *data),
898 void *abortCheckCbkData)
902 void BitmapOutputDev::setDefaultCTM(double *ctm)
904 boolpolydev->setDefaultCTM(ctm);
905 booltextdev->setDefaultCTM(ctm);
906 rgbdev->setDefaultCTM(ctm);
907 clip0dev->setDefaultCTM(ctm);
908 clip1dev->setDefaultCTM(ctm);
909 gfxdev->setDefaultCTM(ctm);
911 void BitmapOutputDev::saveState(GfxState *state)
913 boolpolydev->saveState(state);
914 booltextdev->saveState(state);
915 rgbdev->saveState(state);
916 clip0dev->saveState(state);
917 clip1dev->saveState(state);
919 /*ClipState*cstate = new ClipState();
920 cstate->next = this->clipstates;
921 this->clipstates = cstate;*/
923 void BitmapOutputDev::restoreState(GfxState *state)
925 boolpolydev->restoreState(state);
926 booltextdev->restoreState(state);
927 rgbdev->restoreState(state);
928 clip0dev->restoreState(state);
929 clip1dev->restoreState(state);
931 /*if(this->clipstates) {
932 ClipState*old = this->clipstates;
934 gfxdev->restoreState(state);
936 this->clipstates = this->clipstates->next;
939 msg("<error> invalid restoreState()");
942 void BitmapOutputDev::updateAll(GfxState *state)
944 boolpolydev->updateAll(state);
945 booltextdev->updateAll(state);
946 rgbdev->updateAll(state);
947 clip0dev->updateAll(state);
948 clip1dev->updateAll(state);
949 gfxdev->updateAll(state);
951 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
953 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
954 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
955 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
956 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
957 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
958 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
960 void BitmapOutputDev::updateLineDash(GfxState *state)
962 boolpolydev->updateLineDash(state);
963 booltextdev->updateLineDash(state);
964 rgbdev->updateLineDash(state);
965 clip0dev->updateLineDash(state);
966 clip1dev->updateLineDash(state);
967 gfxdev->updateLineDash(state);
969 void BitmapOutputDev::updateFlatness(GfxState *state)
971 boolpolydev->updateFlatness(state);
972 booltextdev->updateFlatness(state);
973 rgbdev->updateFlatness(state);
974 clip0dev->updateFlatness(state);
975 clip1dev->updateFlatness(state);
976 gfxdev->updateFlatness(state);
978 void BitmapOutputDev::updateLineJoin(GfxState *state)
980 boolpolydev->updateLineJoin(state);
981 booltextdev->updateLineJoin(state);
982 rgbdev->updateLineJoin(state);
983 clip0dev->updateLineJoin(state);
984 clip1dev->updateLineJoin(state);
985 gfxdev->updateLineJoin(state);
987 void BitmapOutputDev::updateLineCap(GfxState *state)
989 boolpolydev->updateLineCap(state);
990 booltextdev->updateLineCap(state);
991 rgbdev->updateLineCap(state);
992 clip0dev->updateLineCap(state);
993 clip1dev->updateLineCap(state);
994 gfxdev->updateLineCap(state);
996 void BitmapOutputDev::updateMiterLimit(GfxState *state)
998 boolpolydev->updateMiterLimit(state);
999 booltextdev->updateMiterLimit(state);
1000 rgbdev->updateMiterLimit(state);
1001 clip0dev->updateMiterLimit(state);
1002 clip1dev->updateMiterLimit(state);
1003 gfxdev->updateMiterLimit(state);
1005 void BitmapOutputDev::updateLineWidth(GfxState *state)
1007 boolpolydev->updateLineWidth(state);
1008 booltextdev->updateLineWidth(state);
1009 rgbdev->updateLineWidth(state);
1010 clip0dev->updateLineWidth(state);
1011 clip1dev->updateLineWidth(state);
1012 gfxdev->updateLineWidth(state);
1014 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
1016 boolpolydev->updateStrokeAdjust(state);
1017 booltextdev->updateStrokeAdjust(state);
1018 rgbdev->updateStrokeAdjust(state);
1019 clip0dev->updateStrokeAdjust(state);
1020 clip1dev->updateStrokeAdjust(state);
1021 gfxdev->updateStrokeAdjust(state);
1023 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
1025 boolpolydev->updateFillColorSpace(state);
1026 booltextdev->updateFillColorSpace(state);
1027 rgbdev->updateFillColorSpace(state);
1028 clip0dev->updateFillColorSpace(state);
1029 clip1dev->updateFillColorSpace(state);
1030 gfxdev->updateFillColorSpace(state);
1032 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
1034 boolpolydev->updateStrokeColorSpace(state);
1035 booltextdev->updateStrokeColorSpace(state);
1036 rgbdev->updateStrokeColorSpace(state);
1037 clip0dev->updateStrokeColorSpace(state);
1038 clip1dev->updateStrokeColorSpace(state);
1039 gfxdev->updateStrokeColorSpace(state);
1041 void BitmapOutputDev::updateFillColor(GfxState *state)
1043 boolpolydev->updateFillColor(state);
1044 booltextdev->updateFillColor(state);
1045 rgbdev->updateFillColor(state);
1046 clip0dev->updateFillColor(state);
1047 clip1dev->updateFillColor(state);
1048 gfxdev->updateFillColor(state);
1050 void BitmapOutputDev::updateStrokeColor(GfxState *state)
1052 boolpolydev->updateStrokeColor(state);
1053 booltextdev->updateStrokeColor(state);
1054 rgbdev->updateStrokeColor(state);
1055 clip0dev->updateStrokeColor(state);
1056 clip1dev->updateStrokeColor(state);
1057 gfxdev->updateStrokeColor(state);
1059 void BitmapOutputDev::updateBlendMode(GfxState *state)
1061 boolpolydev->updateBlendMode(state);
1062 booltextdev->updateBlendMode(state);
1063 rgbdev->updateBlendMode(state);
1064 clip0dev->updateBlendMode(state);
1065 clip1dev->updateBlendMode(state);
1066 gfxdev->updateBlendMode(state);
1068 void BitmapOutputDev::updateFillOpacity(GfxState *state)
1070 boolpolydev->updateFillOpacity(state);
1071 booltextdev->updateFillOpacity(state);
1072 rgbdev->updateFillOpacity(state);
1073 clip0dev->updateFillOpacity(state);
1074 clip1dev->updateFillOpacity(state);
1075 gfxdev->updateFillOpacity(state);
1077 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
1079 boolpolydev->updateStrokeOpacity(state);
1080 booltextdev->updateStrokeOpacity(state);
1081 rgbdev->updateStrokeOpacity(state);
1082 clip0dev->updateStrokeOpacity(state);
1083 clip1dev->updateStrokeOpacity(state);
1084 gfxdev->updateStrokeOpacity(state);
1086 void BitmapOutputDev::updateFillOverprint(GfxState *state)
1088 boolpolydev->updateFillOverprint(state);
1089 booltextdev->updateFillOverprint(state);
1090 rgbdev->updateFillOverprint(state);
1091 clip0dev->updateFillOverprint(state);
1092 clip1dev->updateFillOverprint(state);
1093 gfxdev->updateFillOverprint(state);
1095 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
1097 boolpolydev->updateStrokeOverprint(state);
1098 booltextdev->updateStrokeOverprint(state);
1099 rgbdev->updateStrokeOverprint(state);
1100 clip0dev->updateStrokeOverprint(state);
1101 clip1dev->updateStrokeOverprint(state);
1102 gfxdev->updateStrokeOverprint(state);
1104 void BitmapOutputDev::updateTransfer(GfxState *state)
1106 boolpolydev->updateTransfer(state);
1107 booltextdev->updateTransfer(state);
1108 rgbdev->updateTransfer(state);
1109 clip0dev->updateTransfer(state);
1110 clip1dev->updateTransfer(state);
1111 gfxdev->updateTransfer(state);
1114 void BitmapOutputDev::updateFont(GfxState *state)
1116 boolpolydev->updateFont(state);
1117 booltextdev->updateFont(state);
1118 rgbdev->updateFont(state);
1119 clip0dev->updateFont(state);
1120 clip1dev->updateFont(state);
1121 gfxdev->updateFont(state);
1123 void BitmapOutputDev::updateTextMat(GfxState *state)
1125 boolpolydev->updateTextMat(state);
1126 booltextdev->updateTextMat(state);
1127 rgbdev->updateTextMat(state);
1128 clip0dev->updateTextMat(state);
1129 clip1dev->updateTextMat(state);
1130 gfxdev->updateTextMat(state);
1132 void BitmapOutputDev::updateCharSpace(GfxState *state)
1134 boolpolydev->updateCharSpace(state);
1135 booltextdev->updateCharSpace(state);
1136 rgbdev->updateCharSpace(state);
1137 clip0dev->updateCharSpace(state);
1138 clip1dev->updateCharSpace(state);
1139 gfxdev->updateCharSpace(state);
1141 void BitmapOutputDev::updateRender(GfxState *state)
1143 boolpolydev->updateRender(state);
1144 booltextdev->updateRender(state);
1145 rgbdev->updateRender(state);
1146 clip0dev->updateRender(state);
1147 clip1dev->updateRender(state);
1148 gfxdev->updateRender(state);
1150 void BitmapOutputDev::updateRise(GfxState *state)
1152 boolpolydev->updateRise(state);
1153 booltextdev->updateRise(state);
1154 rgbdev->updateRise(state);
1155 clip0dev->updateRise(state);
1156 clip1dev->updateRise(state);
1157 gfxdev->updateRise(state);
1159 void BitmapOutputDev::updateWordSpace(GfxState *state)
1161 boolpolydev->updateWordSpace(state);
1162 booltextdev->updateWordSpace(state);
1163 rgbdev->updateWordSpace(state);
1164 clip0dev->updateWordSpace(state);
1165 clip1dev->updateWordSpace(state);
1166 gfxdev->updateWordSpace(state);
1168 void BitmapOutputDev::updateHorizScaling(GfxState *state)
1170 boolpolydev->updateHorizScaling(state);
1171 booltextdev->updateHorizScaling(state);
1172 rgbdev->updateHorizScaling(state);
1173 clip0dev->updateHorizScaling(state);
1174 clip1dev->updateHorizScaling(state);
1175 gfxdev->updateHorizScaling(state);
1177 void BitmapOutputDev::updateTextPos(GfxState *state)
1179 boolpolydev->updateTextPos(state);
1180 booltextdev->updateTextPos(state);
1181 rgbdev->updateTextPos(state);
1182 clip0dev->updateTextPos(state);
1183 clip1dev->updateTextPos(state);
1184 gfxdev->updateTextPos(state);
1186 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
1188 boolpolydev->updateTextShift(state, shift);
1189 booltextdev->updateTextShift(state, shift);
1190 rgbdev->updateTextShift(state, shift);
1191 clip0dev->updateTextShift(state, shift);
1192 clip1dev->updateTextShift(state, shift);
1193 gfxdev->updateTextShift(state, shift);
1196 double max(double x, double y)
1200 double min(double x, double y)
1205 gfxbbox_t BitmapOutputDev::getBBox(GfxState*state)
1207 GfxPath * path = state->getPath();
1208 int num = path->getNumSubpaths();
1209 gfxbbox_t bbox = {0,0,1,1};
1212 for(t = 0; t < num; t++) {
1213 GfxSubpath *subpath = path->getSubpath(t);
1214 int subnum = subpath->getNumPoints();
1216 for(s=0;s<subnum;s++) {
1218 state->transform(subpath->getX(s),subpath->getY(s),&x,&y);
1220 bbox.xmin = x; bbox.ymin = y;
1221 bbox.xmax = x; bbox.ymax = y;
1224 bbox.xmin = min(bbox.xmin, x);
1225 bbox.ymin = min(bbox.ymin, y);
1226 bbox.xmax = max(bbox.xmax, x);
1227 bbox.ymax = max(bbox.ymax, y);
1234 void BitmapOutputDev::stroke(GfxState *state)
1236 msg("<debug> stroke");
1237 boolpolydev->stroke(state);
1238 gfxbbox_t bbox = getBBox(state);
1239 double width = state->getTransformedLineWidth();
1240 bbox.xmin -= width; bbox.ymin -= width;
1241 bbox.xmax += width; bbox.ymax += width;
1242 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1243 rgbdev->stroke(state);
1245 void BitmapOutputDev::fill(GfxState *state)
1247 msg("<debug> fill");
1248 boolpolydev->fill(state);
1249 gfxbbox_t bbox = getBBox(state);
1250 if(checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax))) {
1251 boolpolydev->fill(state);
1253 rgbdev->fill(state);
1255 void BitmapOutputDev::eoFill(GfxState *state)
1257 msg("<debug> eoFill");
1258 boolpolydev->eoFill(state);
1259 gfxbbox_t bbox = getBBox(state);
1260 if(checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax))) {
1261 boolpolydev->eoFill(state);
1263 rgbdev->eoFill(state);
1265 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1266 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
1267 int paintType, Dict *resDict,
1268 double *mat, double *bbox,
1269 int x0, int y0, int x1, int y1,
1270 double xStep, double yStep)
1272 msg("<debug> tilingPatternFill");
1273 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1274 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1275 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1278 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
1279 int paintType, Dict *resDict,
1280 double *mat, double *bbox,
1281 int x0, int y0, int x1, int y1,
1282 double xStep, double yStep)
1284 msg("<debug> tilingPatternFill");
1285 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1286 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1287 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1291 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
1293 msg("<debug> functionShadedFill");
1294 boolpolydev->functionShadedFill(state, shading);
1295 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1296 return rgbdev->functionShadedFill(state, shading);
1298 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
1300 msg("<debug> axialShadedFill");
1301 boolpolydev->axialShadedFill(state, shading);
1302 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1303 return rgbdev->axialShadedFill(state, shading);
1305 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
1307 msg("<debug> radialShadedFill");
1308 boolpolydev->radialShadedFill(state, shading);
1309 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1310 return rgbdev->radialShadedFill(state, shading);
1313 SplashColor black = {0,0,0};
1314 SplashColor white = {255,255,255};
1316 void BitmapOutputDev::clip(GfxState *state)
1318 msg("<debug> clip");
1319 boolpolydev->clip(state);
1320 booltextdev->clip(state);
1321 rgbdev->clip(state);
1322 clip1dev->clip(state);
1324 void BitmapOutputDev::eoClip(GfxState *state)
1326 msg("<debug> eoClip");
1327 boolpolydev->eoClip(state);
1328 booltextdev->eoClip(state);
1329 rgbdev->eoClip(state);
1330 clip1dev->eoClip(state);
1332 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1334 msg("<debug> clipToStrokePath");
1335 boolpolydev->clipToStrokePath(state);
1336 booltextdev->clipToStrokePath(state);
1337 rgbdev->clipToStrokePath(state);
1338 clip1dev->clipToStrokePath(state);
1341 void BitmapOutputDev::beginStringOp(GfxState *state)
1343 msg("<debug> beginStringOp");
1344 clip0dev->beginStringOp(state);
1345 clip1dev->beginStringOp(state);
1346 booltextdev->beginStringOp(state);
1347 gfxdev->beginStringOp(state);
1349 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1351 msg("<debug> beginString");
1352 clip0dev->beginString(state, s);
1353 clip1dev->beginString(state, s);
1354 booltextdev->beginString(state, s);
1355 gfxdev->beginString(state, s);
1358 void BitmapOutputDev::clearClips()
1360 clearBooleanBitmap(clip0bitmap, 0, 0, 0, 0);
1361 clearBooleanBitmap(clip1bitmap, 0, 0, 0, 0);
1363 void BitmapOutputDev::clearBoolPolyDev(int x1, int y1, int x2, int y2)
1365 clearBooleanBitmap(boolpolybitmap, x1, y1, x2, y2);
1367 void BitmapOutputDev::clearBoolTextDev(int x1, int y1, int x2, int y2)
1369 clearBooleanBitmap(booltextbitmap, x1, y1, x2, y2);
1371 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1372 double dx, double dy,
1373 double originX, double originY,
1374 CharCode code, int nBytes, Unicode *u, int uLen)
1376 msg("<debug> drawChar render=%d", state->getRender());
1378 if(state->getRender()&RENDER_CLIP) {
1379 //char is just a clipping boundary
1380 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1381 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1382 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1383 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1384 } else if(rgbbitmap != rgbdev->getBitmap()) {
1385 // we're doing softmasking or transparency grouping
1386 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1387 //checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1388 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1390 // we're drawing a regular char
1392 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1393 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1395 /* calculate the bbox of this character */
1396 int x1 = (int)x, x2 = (int)x+1, y1 = (int)y, y2 = (int)y+1;
1397 SplashPath*path = clip0dev->getCurrentFont()->getGlyphPath(code);
1400 msg("<error> couldn't create outline for char %d", code);
1405 path->offset((SplashCoord)x, (SplashCoord)y);
1407 for(t=0;t<path->getLength();t++) {
1410 path->getPoint(t,&xx,&yy,&f);
1411 state->transform(xx,yy,&xx,&yy);
1412 if(xx<x1) x1=(int)xx;
1413 if(yy<y1) y1=(int)yy;
1414 if(xx>=x2) x2=(int)xx+1;
1415 if(yy>=y2) y2=(int)yy+1;
1418 /* if this character is affected somehow by the various clippings (i.e., it looks
1419 different on a device without clipping), then draw it on the bitmap, not as
1421 if(clip0and1differ(x1,y1,x2,y2)) {
1422 msg("<verbose> Char %d is affected by clipping", code);
1423 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1424 checkNewBitmap(x1,y1,x2,y2);
1425 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1426 if(config_extrafontdata) {
1427 int oldrender = state->getRender();
1428 state->setRender(3); //invisible
1429 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1430 state->setRender(oldrender);
1433 /* this char is not at all affected by clipping.
1434 Now just dump out the bitmap we're currently working on, if necessary. */
1435 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1436 checkNewText(x1,y1,x2,y2);
1437 /* use polygonal output device to do the actual text handling */
1438 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1442 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1444 msg("<error> internal error: drawString not implemented");
1446 clip0dev->drawString(state, s);
1447 clip1dev->drawString(state, s);
1448 booltextdev->drawString(state, s);
1449 gfxdev->drawString(state, s);
1451 void BitmapOutputDev::endTextObject(GfxState *state)
1453 msg("<debug> endTextObject");
1454 rgbdev->endTextObject(state);
1455 clip0dev->endTextObject(state);
1456 clip1dev->endTextObject(state);
1457 booltextdev->endTextObject(state);
1458 /* the only thing "drawn" here is clipping */
1459 //checkNewText(UNKNOWN_BOUNDING_BOX);
1460 gfxdev->endTextObject(state);
1462 void BitmapOutputDev::endString(GfxState *state)
1464 msg("<debug> endString");
1465 clip0dev->endString(state);
1466 clip1dev->endString(state);
1467 booltextdev->endString(state);
1468 int render = state->getRender();
1469 if(render != RENDER_INVISIBLE && render != RENDER_FILL) {
1470 checkNewText(UNKNOWN_BOUNDING_BOX);
1472 gfxdev->endString(state);
1474 void BitmapOutputDev::endStringOp(GfxState *state)
1476 msg("<debug> endStringOp");
1477 clip0dev->endStringOp(state);
1478 clip1dev->endStringOp(state);
1479 booltextdev->endStringOp(state);
1480 gfxdev->endStringOp(state);
1483 /* TODO: these four operations below *should* do nothing, as type3
1484 chars are drawn using operations like fill() */
1485 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1486 double dx, double dy,
1487 CharCode code, Unicode *u, int uLen)
1489 msg("<debug> beginType3Char");
1490 /* call gfxdev so that it can generate "invisible" characters
1491 on top of the actual graphic content, for text extraction */
1492 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1494 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1496 msg("<debug> type3D0");
1497 return gfxdev->type3D0(state, wx, wy);
1499 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1501 msg("<debug> type3D1");
1502 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1504 void BitmapOutputDev::endType3Char(GfxState *state)
1506 msg("<debug> endType3Char");
1507 gfxdev->endType3Char(state);
1510 class CopyStream: public Object
1514 MemStream*memstream;
1516 CopyStream(Stream*str, int len)
1521 buf = (char*)malloc(len);
1523 for (t=0; t<len; t++)
1524 buf[t] = str->getChar();
1527 this->dict = str->getDict();
1528 this->memstream = new MemStream(buf, 0, len, this);
1532 ::free(this->buf);this->buf = 0;
1533 delete this->memstream;
1535 Dict* getDict() {return dict;}
1536 Stream* getStream() {return this->memstream;};
1539 gfxbbox_t BitmapOutputDev::getImageBBox(GfxState*state)
1543 state->transform(0, 1, &x, &y);
1544 bbox.xmin=bbox.xmax = x;
1545 bbox.ymin=bbox.ymax = x;
1546 state->transform(0, 0, &x, &y);
1547 bbox.xmin=min(bbox.xmin,x);
1548 bbox.ymin=min(bbox.ymin,y);
1549 bbox.xmax=max(bbox.xmin,x);
1550 bbox.ymax=max(bbox.ymin,y);
1551 state->transform(1, 0, &x, &y);
1552 bbox.xmin=min(bbox.xmin,x);
1553 bbox.ymin=min(bbox.ymin,y);
1554 bbox.xmax=max(bbox.xmin,x);
1555 bbox.ymax=max(bbox.ymin,y);
1556 state->transform(1, 1, &x, &y);
1557 bbox.xmin=min(bbox.xmin,x);
1558 bbox.ymin=min(bbox.ymin,y);
1559 bbox.xmax=max(bbox.xmin,x);
1560 bbox.ymax=max(bbox.ymin,y);
1563 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1564 int width, int height, GBool invert,
1567 msg("<debug> drawImageMask streamkind=%d", str->getKind());
1568 CopyStream*cpystr = 0;
1570 cpystr = new CopyStream(str, height * ((width + 7) / 8));
1571 str = cpystr->getStream();
1573 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1574 gfxbbox_t bbox = getImageBBox(state);
1575 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1576 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1580 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1581 int width, int height, GfxImageColorMap *colorMap,
1582 int *maskColors, GBool inlineImg)
1584 msg("<debug> drawImage streamkind=%d", str->getKind());
1585 CopyStream*cpystr = 0;
1587 cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1588 str = cpystr->getStream();
1590 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1591 gfxbbox_t bbox=getImageBBox(state);
1592 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1593 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1597 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1598 int width, int height,
1599 GfxImageColorMap *colorMap,
1600 Stream *maskStr, int maskWidth, int maskHeight,
1603 msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
1604 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1605 gfxbbox_t bbox=getImageBBox(state);
1606 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1607 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1609 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1610 int width, int height,
1611 GfxImageColorMap *colorMap,
1613 int maskWidth, int maskHeight,
1614 GfxImageColorMap *maskColorMap)
1616 msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
1617 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1618 gfxbbox_t bbox=getImageBBox(state);
1619 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1620 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1622 void BitmapOutputDev::drawForm(Ref id)
1624 msg("<debug> drawForm");
1625 boolpolydev->drawForm(id);
1626 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1627 rgbdev->drawForm(id);
1630 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1632 msg("<debug> processLink");
1633 gfxdev->processLink(link, catalog);
1636 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1637 GfxColorSpace *blendingColorSpace,
1638 GBool isolated, GBool knockout,
1641 msg("<debug> beginTransparencyGroup");
1642 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1643 GfxState*state1 = state->copy();
1644 GfxState*state2 = state->copy();
1646 state1->setPath(state->getPath()->copy());
1648 state2->setPath(state->getPath()->copy());
1650 GfxState*state1 = state->copy(gTrue);
1651 GfxState*state2 = state->copy(gTrue);
1653 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1654 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1655 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1659 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1661 msg("<debug> endTransparencyGroup");
1662 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1663 GfxState*state1 = state->copy();
1664 GfxState*state2 = state->copy();
1666 state1->setPath(state->getPath()->copy());
1668 state2->setPath(state->getPath()->copy());
1670 GfxState*state1 = state->copy(gTrue);
1671 GfxState*state2 = state->copy(gTrue);
1673 boolpolydev->endTransparencyGroup(state1);
1674 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1675 rgbdev->endTransparencyGroup(state2);
1678 clip1dev->endTransparencyGroup(state);
1680 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1682 msg("<debug> paintTransparencyGroup");
1683 boolpolydev->paintTransparencyGroup(state,bbox);
1684 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1685 rgbdev->paintTransparencyGroup(state,bbox);
1686 clip1dev->paintTransparencyGroup(state,bbox);
1688 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1690 msg("<debug> setSoftMask");
1691 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1692 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1693 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1694 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1696 void BitmapOutputDev::clearSoftMask(GfxState *state)
1698 msg("<debug> clearSoftMask");
1699 boolpolydev->clearSoftMask(state);
1700 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1701 rgbdev->clearSoftMask(state);
1702 clip1dev->clearSoftMask(state);