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"
32 #include "../gfxtools.h"
36 #define UNKNOWN_BOUNDING_BOX 0,0,0,0
38 static SplashColor splash_white = {255,255,255};
39 static SplashColor splash_black = {0,0,0};
41 ClipState::ClipState()
48 BitmapOutputDev::BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
52 this->xref = doc->getXRef();
54 /* color graphic output device, for creating bitmaps */
55 this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
57 /* color mode for binary bitmaps */
58 SplashColorMode colorMode = splashModeMono1;
60 /* two devices for testing things against clipping: one clips, the other doesn't */
61 this->clip0dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
62 this->clip1dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
64 /* device indicating where polygonal pixels were drawn */
65 this->boolpolydev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
66 /* device indicating where text pixels were drawn */
67 this->booltextdev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
69 /* device for handling texts and links */
70 this->gfxdev = new GFXOutputDev(info, this->doc);
72 this->rgbdev->startDoc(this->xref);
73 this->boolpolydev->startDoc(this->xref);
74 this->booltextdev->startDoc(this->xref);
75 this->clip0dev->startDoc(this->xref);
76 this->clip1dev->startDoc(this->xref);
78 this->gfxoutput = (gfxdevice_t*)malloc(sizeof(gfxdevice_t));
79 gfxdevice_record_init(this->gfxoutput, 0);
81 this->gfxdev->setDevice(this->gfxoutput);
83 this->config_extrafontdata = 0;
84 this->config_skewedtobitmap = 0;
85 this->config_optimizeplaincolorfills = 0;
88 //this->clipstates = 0;
90 BitmapOutputDev::~BitmapOutputDev()
93 gfxresult_t*r = this->gfxoutput->finish(this->gfxoutput);
95 free(this->gfxoutput);this->gfxoutput = 0;
98 delete this->bboxpath;this->bboxpath = 0;
101 delete this->rgbdev;this->rgbdev = 0;
104 delete this->gfxdev;this->gfxdev= 0;
106 if(this->boolpolydev) {
107 delete this->boolpolydev;this->boolpolydev = 0;
109 if(this->stalepolybitmap) {
110 delete this->stalepolybitmap;this->stalepolybitmap = 0;
112 if(this->staletextbitmap) {
113 delete this->staletextbitmap;this->staletextbitmap = 0;
115 if(this->booltextdev) {
116 delete this->booltextdev;this->booltextdev = 0;
119 delete this->clip0dev;this->clip0dev = 0;
122 delete this->clip1dev;this->clip1dev = 0;
124 //if(this->clipbitmap) {
125 // delete this->clipbitmap;this->clipbitmap = 0;
127 //if(this->clipdev) {
128 // delete this->clipdev;this->clipdev = 0;
133 GBool BitmapOutputDev::getVectorAntialias()
135 return this->rgbdev->getVectorAntialias();
137 void BitmapOutputDev::setVectorAntialias(GBool vaa)
139 this->rgbdev->setVectorAntialias(vaa);
141 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
145 void BitmapOutputDev::setMove(int x,int y)
147 this->gfxdev->setMove(x,y);
148 this->user_movex = x;
149 this->user_movey = y;
151 void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
153 this->gfxdev->setClip(x1,y1,x2,y2);
154 this->user_clipx1 = x1;
155 this->user_clipy1 = y1;
156 this->user_clipx2 = x2;
157 this->user_clipy2 = y2;
159 void BitmapOutputDev::setParameter(const char*key, const char*value)
161 if(!strcmp(key, "extrafontdata")) {
162 this->config_extrafontdata = atoi(value);
164 this->gfxdev->setParameter(key, value);
166 void BitmapOutputDev::setPageMap(int*page2page, int num_pages)
168 this->gfxdev->setPageMap(page2page, num_pages);
171 void writeBitmap(SplashBitmap*bitmap, char*filename);
172 void writeAlpha(SplashBitmap*bitmap, char*filename);
174 static int dbg_btm_counter=1;
176 void BitmapOutputDev::flushBitmap()
178 int width = rgbdev->getBitmapWidth();
179 int height = rgbdev->getBitmapHeight();
181 if(sizeof(SplashColor)!=3) {
182 msg("<error> sizeof(SplashColor)!=3");
186 /*static int counter=0;
188 writeBitmap(rgbdev->getBitmap(), "test.png");
191 /*static int counter=0;
193 sprintf(filename, "test%d.png", counter++);
194 writeBitmap(rgbbitmap, filename);*/
196 SplashColorPtr rgb = rgbbitmap->getDataPtr();
197 Guchar*alpha = rgbbitmap->getAlphaPtr();
199 Guchar*alpha2 = stalepolybitmap->getDataPtr();
200 int width8 = (stalepolybitmap->getWidth()+7)/8;
203 sprintf(filename, "flush%d_mask.png", dbg_btm_counter);
204 writeAlpha(stalepolybitmap, filename);
205 sprintf(filename, "flush%d_alpha.png", dbg_btm_counter);
206 writeAlpha(rgbbitmap, filename);
207 sprintf(filename, "flush%d_bitmap.png", dbg_btm_counter);
208 writeBitmap(rgbbitmap, filename);*/
210 ibbox_t* boxes = get_bitmap_bboxes((unsigned char*)alpha, width, height);
213 for(b=boxes;b;b=b->next) {
219 /* clip against (-movex, -movey, -movex+width, -movey+height) */
221 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d %dx%d) (clipped against %d,%d,%d,%d)", xmin,ymin,xmax,ymax, xmax-xmin, ymax-ymin,
222 -this->movex, -this->movey, -this->movex+this->width, -this->movey+this->height);
224 if(xmin < -this->movex) {
226 if(xmax < -this->movex) continue;
228 if(ymin < -this->movey) {
230 if(ymax < -this->movey) continue;
232 if(xmax >= -this->movex + this->width) {
233 xmax = -this->movex+this->width;
234 if(xmin >= -this->movex + this->width) continue;
236 if(ymax >= -this->movey + this->height) {
237 ymax = -this->movey+this->height;
238 if(ymin >= -this->movey + this->height) continue;
241 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
244 int rangex = xmax-xmin;
245 int rangey = ymax-ymin;
246 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
247 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
249 img->height = rangey;
251 for(y=0;y<rangey;y++) {
252 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
253 gfxcolor_t*out = &img->data[y*rangex];
254 Guchar*ain = &alpha[(y+ymin)*width+xmin];
255 Guchar*ain2 = &alpha2[(y+ymin)*width8];
256 if(this->emptypage) {
257 for(x=0;x<rangex;x++) {
258 /* the first bitmap on the page doesn't need to have an alpha channel-
259 blend against a white background*/
260 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
261 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
262 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
266 for(x=0;x<rangex;x++) {
267 if(!(ain2[(x+xmin)/8]&(0x80>>((x+xmin)&7)))) {
268 /* cut away pixels that we don't remember drawing (i.e., that are
269 not in the monochrome bitmap). Prevents some "hairlines" showing
270 up to the left and right of bitmaps. */
271 out[x].r = 0;out[x].g = 0;out[x].b = 0;out[x].a = 0;
273 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, this
274 data has non-premultiplied alpha, which is exactly what the output device
275 expects, so don't premultiply it here, either.
277 out[x].r = in[x*3+0];
278 out[x].g = in[x*3+1];
279 out[x].b = in[x*3+2];
286 /* transform bitmap rectangle to "device space" */
300 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
301 dev->fillbitmap(dev, line, img, &m, 0);
304 free(img->data);img->data=0;free(img);img=0;
306 ibbox_destroy(boxes);
308 memset(rgbbitmap->getAlphaPtr(), 0, rgbbitmap->getWidth()*rgbbitmap->getHeight());
309 memset(rgbbitmap->getDataPtr(), 0, rgbbitmap->getRowSize()*rgbbitmap->getHeight());
314 void BitmapOutputDev::flushText()
316 msg("<verbose> Flushing text");
318 static gfxfontlist_t*output_font_list = 0;
319 static gfxdevice_t*last = 0;
320 if(last != this->dev) {
322 gfxfontlist_free(output_font_list, 0);
323 output_font_list = gfxfontlist_create();
325 gfxdevice_record_flush(this->gfxoutput, this->dev, &output_font_list);
331 void writeMonoBitmap(SplashBitmap*btm, char*filename)
333 int width8 = (btm->getWidth()+7)/8;
334 int width = btm->getWidth();
335 int height = btm->getHeight();
336 gfxcolor_t*b = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
337 unsigned char*data = btm->getDataPtr();
339 for(y=0;y<height;y++) {
340 unsigned char*l = &data[width8*y];
341 gfxcolor_t*d = &b[width*y];
342 for(x=0;x<width;x++) {
343 if(l[x>>3]&(128>>(x&7))) {
344 d[x].r = d[x].b = d[x].a = 255;
347 d[x].r = d[x].g = d[x].b = d[x].a = 0;
351 writePNG(filename, (unsigned char*)b, width, height);
355 void writeBitmap(SplashBitmap*bitmap, char*filename)
359 int width = bitmap->getWidth();
360 int height = bitmap->getHeight();
362 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
364 if(bitmap->getMode()==splashModeMono1) {
365 writeMonoBitmap(bitmap, filename);
369 for(y=0;y<height;y++) {
370 gfxcolor_t*line = &data[y*width];
371 for(x=0;x<width;x++) {
372 Guchar c[4] = {0,0,0,0};
373 bitmap->getPixel(x,y,c);
377 line[x].a = bitmap->getAlpha(x,y);
380 writePNG(filename, (unsigned char*)data, width, height);
384 void writeAlpha(SplashBitmap*bitmap, char*filename)
388 int width = bitmap->getWidth();
389 int height = bitmap->getHeight();
391 if(bitmap->getMode()==splashModeMono1) {
392 writeMonoBitmap(bitmap, filename);
396 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
398 for(y=0;y<height;y++) {
399 gfxcolor_t*line = &data[y*width];
400 for(x=0;x<width;x++) {
401 int a = bitmap->getAlpha(x,y);
408 writePNG(filename, (unsigned char*)data, width, height);
412 static const char*STATE_NAME[] = {"parallel", "textabovebitmap", "bitmapabovetext"};
414 int checkAlphaSanity(SplashBitmap*boolbtm, SplashBitmap*alphabtm)
416 assert(boolbtm->getWidth() == alphabtm->getWidth());
417 assert(boolbtm->getHeight() == alphabtm->getHeight());
418 if(boolbtm->getMode()==splashModeMono1) {
422 int width = boolbtm->getWidth();
423 int height = boolbtm->getHeight();
427 for(y=0;y<height;y++) {
428 for(x=0;x<width;x++) {
429 int a1 = alphabtm->getAlpha(x,y);
430 int a2 = boolbtm->getAlpha(x,y);
436 double badness = bad/(double)(width*height);
438 msg("<error> Bitmaps don't correspond: %d out of %d pixels wrong (%.2f%%)", bad, width*height,
442 msg("<notice> %f", badness);
446 static inline GBool fixBBox(int*x1, int*y1, int*x2, int*y2, int width, int height)
448 if(!(*x1|*y1|*x2|*y2)) {
455 if(*x2<=*x1) return gFalse;
456 if(*x2<0) return gFalse;
458 if(*x1>=width) return gFalse;
459 if(*x2>width) *x2=width;
461 if(*y2<=*y1) return gFalse;
462 if(*y2<0) return gFalse;
464 if(*y1>=height) return gFalse;
465 if(*y2>height) *y2=height;
469 static void update_bitmap(SplashBitmap*bitmap, SplashBitmap*update, int x1, int y1, int x2, int y2, char overwrite)
471 assert(bitmap->getMode()==splashModeMono1);
472 assert(update->getMode()==splashModeMono1);
474 int width8 = (bitmap->getWidth()+7)/8;
475 assert(width8 == bitmap->getRowSize());
476 assert(width8 == update->getRowSize());
477 int height = bitmap->getHeight();
478 assert(height == update->getHeight());
480 if(!fixBBox(&x1, &y1, &x2, &y2, bitmap->getWidth(), bitmap->getHeight()))
483 Guchar*b = bitmap->getDataPtr() + y1*width8 + x1/8;
484 Guchar*u = update->getDataPtr() + y1*width8 + x1/8;
486 int xspan = (x2+7)/8 - x1/8;
487 int size = (y2-y1)*width8;
491 for(y=0;y<yspan;y++) {
497 if(((ptroff_t)b&7)==((ptroff_t)u&7)) {
499 for(y=0;y<yspan;y++) {
500 Guchar*e1 = b+xspan-8;
502 while(((ptroff_t)b&7) && b<e1) {
507 *(long long*)b |= *(long long*)u;
519 for(y=0;y<yspan;y++) {
520 for(x=0;x<xspan;x++) {
530 static void clearBooleanBitmap(SplashBitmap*btm, int x1, int y1, int x2, int y2)
532 if(!fixBBox(&x1, &y1, &x2, &y2, btm->getWidth(), btm->getHeight()))
535 if(btm->getMode()==splashModeMono1) {
536 int width8 = (btm->getWidth()+7)/8;
537 assert(width8 == btm->getRowSize());
538 int width = btm->getWidth();
539 int height = btm->getHeight();
540 Guchar*data = btm->getDataPtr();
541 memset(data+y1*width8, 0, width8*(y2-y1));
543 int width = btm->getAlphaRowSize();
544 int height = btm->getHeight();
545 memset(btm->getAlphaPtr(), 0, width*height);
549 void BitmapOutputDev::dbg_newdata(char*newdata)
555 sprintf(filename1, "state%03dboolbitmap_after%s.png", dbg_btm_counter, newdata);
556 sprintf(filename2, "state%03dbooltext_after%s.png", dbg_btm_counter, newdata);
557 sprintf(filename3, "state%03dbitmap_after%s.png", dbg_btm_counter, newdata);
558 msg("<verbose> %s %s %s", filename1, filename2, filename3);
559 writeAlpha(stalepolybitmap, filename1);
560 writeAlpha(booltextbitmap, filename2);
561 writeBitmap(rgbdev->getBitmap(), filename3);
566 GBool BitmapOutputDev::checkNewText(int x1, int y1, int x2, int y2)
568 /* called once some new text was drawn on booltextdev, and
569 before the same thing is drawn on gfxdev */
571 msg("<trace> Testing new text data against current bitmap data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
574 if(intersection(booltextbitmap, stalepolybitmap, x1,y1,x2,y2)) {
575 if(layerstate==STATE_PARALLEL) {
576 /* the new text is above the bitmap. So record that fact. */
577 msg("<verbose> Text is above current bitmap/polygon data");
578 layerstate=STATE_TEXT_IS_ABOVE;
579 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
580 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
581 /* there's a bitmap above the (old) text. So we need
582 to flush out that text, and record that the *new*
583 text is now *above* the bitmap
585 msg("<verbose> Text is above current bitmap/polygon data (which is above some other text)");
587 layerstate=STATE_TEXT_IS_ABOVE;
590 /* re-apply the update (which we would otherwise lose) */
591 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 1);
594 /* we already know that the current text section is
595 above the current bitmap section- now just new
596 bitmap data *and* new text data was drawn, and
597 *again* it's above the current bitmap. */
598 msg("<verbose> Text is still above current bitmap/polygon data");
599 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
602 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
605 /* clear the thing we just drew from our temporary drawing bitmap */
606 clearBooleanBitmap(booltextbitmap, x1, y1, x2, y2);
610 GBool BitmapOutputDev::checkNewBitmap(int x1, int y1, int x2, int y2)
612 /* similar to checkNewText() above, only in reverse */
613 msg("<trace> Testing new graphics data against current text data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
616 if(intersection(boolpolybitmap, staletextbitmap, x1,y1,x2,y2)) {
617 if(layerstate==STATE_PARALLEL) {
618 msg("<verbose> Bitmap is above current text data");
619 layerstate=STATE_BITMAP_IS_ABOVE;
620 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
621 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
622 msg("<verbose> Bitmap is above current text data (which is above some bitmap)");
624 layerstate=STATE_BITMAP_IS_ABOVE;
626 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 1);
629 msg("<verbose> Bitmap is still above current text data");
630 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
633 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
636 /* clear the thing we just drew from our temporary drawing bitmap */
637 clearBooleanBitmap(boolpolybitmap, x1, y1, x2, y2);
642 //void checkNewText() {
643 // Guchar*alpha = rgbbitmap->getAlphaPtr();
644 // Guchar*charpixels = clip1bitmap->getDataPtr();
646 // for(yy=0;yy<height;yy++) {
647 // Guchar*aline = &alpha[yy*width];
648 // Guchar*cline = &charpixels[yy*width8];
649 // for(xx=0;xx<width;xx++) {
651 // int bytepos = xx>>3;
652 // /* TODO: is the bit order correct? */
653 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
660 GBool BitmapOutputDev::clip0and1differ(int x1,int y1,int x2,int y2)
662 if(clip0bitmap->getMode()==splashModeMono1) {
663 int width = clip0bitmap->getWidth();
664 int width8 = (width+7)/8;
665 int height = clip0bitmap->getHeight();
667 if(!fixBBox(&x1,&y1,&x2,&y2,width,height)) {
668 /* area is outside or null */
672 SplashBitmap*clip0 = clip0bitmap;
673 SplashBitmap*clip1 = clip1bitmap;
679 unsigned char*row1 = &clip0bitmap->getDataPtr()[width8*y+x18];
680 unsigned char*row2 = &clip1bitmap->getDataPtr()[width8*y+x18];
681 if(memcmp(row1, row2, x28-x18)) {
687 SplashBitmap*clip0 = clip0bitmap;
688 SplashBitmap*clip1 = clip1bitmap;
689 int width = clip0->getAlphaRowSize();
690 int height = clip0->getHeight();
692 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
696 Guchar*a0 = clip0->getAlphaPtr();
697 Guchar*a1 = clip1->getAlphaPtr();
702 if(a0[y*width+x]!=a1[y*width+x]) {
710 char differs2 = memcmp(a0, a1, width*height);
711 if(differs && !differs2)
712 msg("<warning> Strange internal error (2)");
713 else if(!differs && differs2) {
714 msg("<warning> Bad Bounding Box: Difference in clip0 and clip1 outside bbox");
715 msg("<warning> %d %d %d %d", x1, y1, x2, y2);
721 GBool compare8(unsigned char*data1, unsigned char*data2, int len)
725 if(((ptroff_t)data1&7)==((ptroff_t)data2&7)) {
726 // oh good, we can align both to 8 byte
727 while((ptroff_t)data1&7) {
736 /* use 64 bit for the (hopefully aligned) middle section */
738 long long unsigned int*d1 = (long long unsigned int*)data1;
739 long long unsigned int*d2 = (long long unsigned int*)data2;
740 long long unsigned int x = 0;
752 if(data1[t]&data2[t]) {
759 GBool BitmapOutputDev::intersection(SplashBitmap*boolpoly, SplashBitmap*booltext, int x1, int y1, int x2, int y2)
761 if(boolpoly->getMode()==splashModeMono1) {
762 /* alternative implementation, using one bit per pixel-
763 needs the no-dither patch in xpdf */
765 int width = boolpoly->getWidth();
766 int height = boolpoly->getHeight();
768 if(!fixBBox(&x1,&y1,&x2,&y2, width, height)) {
772 Guchar*polypixels = boolpoly->getDataPtr();
773 Guchar*textpixels = booltext->getDataPtr();
775 int width8 = (width+7)/8;
780 polypixels+=y1*width8+x1/8;
781 textpixels+=y1*width8+x1/8;
782 runx=(x2+7)/8 - x1/8;
789 /*assert(sizeof(unsigned long long int)==8);
790 if(((ptroff_t)polypixels&7) || ((ptroff_t)textpixels&7)) {
791 //msg("<warning> Non-optimal alignment");
795 unsigned char*data1 = (unsigned char*)polypixels;
796 unsigned char*data2 = (unsigned char*)textpixels;
797 msg("<verbose> Testing area (%d,%d,%d,%d), runx=%d,runy=%d", x1,y1,x2,y2, runx, runy);
798 for(y=0;y<runy;y++) {
799 if(compare8(data1,data2,runx))
806 int width = boolpoly->getAlphaRowSize();
807 int height = boolpoly->getHeight();
809 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
812 Guchar*polypixels = boolpoly->getAlphaPtr();
813 Guchar*textpixels = booltext->getAlphaPtr();
820 if(polypixels[width*y+x]&&textpixels[width*y+x])
824 int ax1=0,ay1=0,ax2=0,ay2=0;
825 for(y=0;y<height;y++) {
826 for(x=0;x<width;x++) {
827 if(polypixels[width*y+x]&&textpixels[width*y+x]) {
829 if(!(ax1|ay1|ax2|ay2)) {
841 if(overlap1 && !overlap2)
842 msg("<warning> strange internal error");
843 if(!overlap1 && overlap2) {
844 msg("<warning> Bad bounding box: intersection outside bbox");
845 msg("<warning> given bbox: %d %d %d %d", x1, y1, x2, y2);
846 msg("<warning> changed area: %d %d %d %d", ax1, ay1, ax2, ay2);
853 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
856 state->transform(crop_x1,crop_y1,&x1,&y1);
857 state->transform(crop_x2,crop_y2,&x2,&y2);
858 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
859 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
861 this->movex = -(int)x1 - user_movex;
862 this->movey = -(int)y1 - user_movey;
864 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
870 this->width = (int)(x2-x1);
871 this->height = (int)(y2-y1);
873 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
874 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
875 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
876 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
877 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
878 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
880 boolpolybitmap = boolpolydev->getBitmap();
881 stalepolybitmap = new SplashBitmap(boolpolybitmap->getWidth(), boolpolybitmap->getHeight(), 1, boolpolybitmap->getMode(), 0);
882 assert(stalepolybitmap->getRowSize() == boolpolybitmap->getRowSize());
884 booltextbitmap = booltextdev->getBitmap();
885 staletextbitmap = new SplashBitmap(booltextbitmap->getWidth(), booltextbitmap->getHeight(), 1, booltextbitmap->getMode(), 0);
886 assert(staletextbitmap->getRowSize() == booltextbitmap->getRowSize());
888 msg("<debug> startPage %dx%d (%dx%d)", this->width, this->height, booltextbitmap->getWidth(), booltextbitmap->getHeight());
890 clip0bitmap = clip0dev->getBitmap();
891 clip1bitmap = clip1dev->getBitmap();
892 rgbbitmap = rgbdev->getBitmap();
894 flushText(); // write out the initial clipping rectangle
896 /* just in case any device did draw a white background rectangle
901 this->layerstate = STATE_PARALLEL;
903 msg("<debug> startPage done");
906 void BitmapOutputDev::endPage()
908 msg("<verbose> endPage (BitmapOutputDev)");
910 /* notice: we're not fully done yet with this page- there might still be
911 a few calls to drawLink() yet to come */
913 void BitmapOutputDev::finishPage()
915 msg("<verbose> finishPage (BitmapOutputDev)");
918 if(layerstate == STATE_BITMAP_IS_ABOVE) {
926 /* splash will now destroy alpha, and paint the
927 background color into the "holes" in the bitmap */
928 boolpolydev->endPage();
929 booltextdev->endPage();
935 GBool BitmapOutputDev::upsideDown()
937 boolpolydev->upsideDown();
938 booltextdev->upsideDown();
939 clip0dev->upsideDown();
940 clip1dev->upsideDown();
941 return rgbdev->upsideDown();
944 GBool BitmapOutputDev::useDrawChar()
946 boolpolydev->useDrawChar();
947 booltextdev->useDrawChar();
948 clip0dev->useDrawChar();
949 clip1dev->useDrawChar();
950 return rgbdev->useDrawChar();
953 GBool BitmapOutputDev::useTilingPatternFill()
955 boolpolydev->useTilingPatternFill();
956 booltextdev->useTilingPatternFill();
957 clip0dev->useTilingPatternFill();
958 clip1dev->useTilingPatternFill();
959 return rgbdev->useTilingPatternFill();
962 GBool BitmapOutputDev::useShadedFills()
964 boolpolydev->useShadedFills();
965 booltextdev->useShadedFills();
966 clip0dev->useShadedFills();
967 clip1dev->useShadedFills();
968 return rgbdev->useShadedFills();
971 GBool BitmapOutputDev::useDrawForm()
973 boolpolydev->useDrawForm();
974 booltextdev->useDrawForm();
975 clip0dev->useDrawForm();
976 clip1dev->useDrawForm();
977 return rgbdev->useDrawForm();
980 GBool BitmapOutputDev::interpretType3Chars()
982 boolpolydev->interpretType3Chars();
983 booltextdev->interpretType3Chars();
984 clip0dev->interpretType3Chars();
985 clip1dev->interpretType3Chars();
986 return rgbdev->interpretType3Chars();
989 GBool BitmapOutputDev::needNonText()
991 boolpolydev->needNonText();
992 booltextdev->needNonText();
993 clip0dev->needNonText();
994 clip1dev->needNonText();
995 return rgbdev->needNonText();
997 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
998 int rotate, GBool useMediaBox, GBool crop,
999 int sliceX, int sliceY, int sliceW, int sliceH,
1000 GBool printing, Catalog *catalog,
1001 GBool (*abortCheckCbk)(void *data),
1002 void *abortCheckCbkData)
1006 void BitmapOutputDev::setDefaultCTM(double *ctm)
1008 boolpolydev->setDefaultCTM(ctm);
1009 booltextdev->setDefaultCTM(ctm);
1010 rgbdev->setDefaultCTM(ctm);
1011 clip0dev->setDefaultCTM(ctm);
1012 clip1dev->setDefaultCTM(ctm);
1013 gfxdev->setDefaultCTM(ctm);
1015 void BitmapOutputDev::saveState(GfxState *state)
1017 boolpolydev->saveState(state);
1018 booltextdev->saveState(state);
1019 rgbdev->saveState(state);
1020 clip0dev->saveState(state);
1021 clip1dev->saveState(state);
1023 /*ClipState*cstate = new ClipState();
1024 cstate->next = this->clipstates;
1025 this->clipstates = cstate;*/
1027 void BitmapOutputDev::restoreState(GfxState *state)
1029 boolpolydev->restoreState(state);
1030 booltextdev->restoreState(state);
1031 rgbdev->restoreState(state);
1032 clip0dev->restoreState(state);
1033 clip1dev->restoreState(state);
1035 /*if(this->clipstates) {
1036 ClipState*old = this->clipstates;
1038 gfxdev->restoreState(state);
1040 this->clipstates = this->clipstates->next;
1043 msg("<error> invalid restoreState()");
1046 void BitmapOutputDev::updateAll(GfxState *state)
1048 boolpolydev->updateAll(state);
1049 booltextdev->updateAll(state);
1050 rgbdev->updateAll(state);
1051 clip0dev->updateAll(state);
1052 clip1dev->updateAll(state);
1053 gfxdev->updateAll(state);
1055 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
1057 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1058 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1059 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1060 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1061 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1062 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1064 void BitmapOutputDev::updateLineDash(GfxState *state)
1066 boolpolydev->updateLineDash(state);
1067 booltextdev->updateLineDash(state);
1068 rgbdev->updateLineDash(state);
1069 clip0dev->updateLineDash(state);
1070 clip1dev->updateLineDash(state);
1071 gfxdev->updateLineDash(state);
1073 void BitmapOutputDev::updateFlatness(GfxState *state)
1075 boolpolydev->updateFlatness(state);
1076 booltextdev->updateFlatness(state);
1077 rgbdev->updateFlatness(state);
1078 clip0dev->updateFlatness(state);
1079 clip1dev->updateFlatness(state);
1080 gfxdev->updateFlatness(state);
1082 void BitmapOutputDev::updateLineJoin(GfxState *state)
1084 boolpolydev->updateLineJoin(state);
1085 booltextdev->updateLineJoin(state);
1086 rgbdev->updateLineJoin(state);
1087 clip0dev->updateLineJoin(state);
1088 clip1dev->updateLineJoin(state);
1089 gfxdev->updateLineJoin(state);
1091 void BitmapOutputDev::updateLineCap(GfxState *state)
1093 boolpolydev->updateLineCap(state);
1094 booltextdev->updateLineCap(state);
1095 rgbdev->updateLineCap(state);
1096 clip0dev->updateLineCap(state);
1097 clip1dev->updateLineCap(state);
1098 gfxdev->updateLineCap(state);
1100 void BitmapOutputDev::updateMiterLimit(GfxState *state)
1102 boolpolydev->updateMiterLimit(state);
1103 booltextdev->updateMiterLimit(state);
1104 rgbdev->updateMiterLimit(state);
1105 clip0dev->updateMiterLimit(state);
1106 clip1dev->updateMiterLimit(state);
1107 gfxdev->updateMiterLimit(state);
1109 void BitmapOutputDev::updateLineWidth(GfxState *state)
1111 boolpolydev->updateLineWidth(state);
1112 booltextdev->updateLineWidth(state);
1113 rgbdev->updateLineWidth(state);
1114 clip0dev->updateLineWidth(state);
1115 clip1dev->updateLineWidth(state);
1116 gfxdev->updateLineWidth(state);
1118 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
1120 boolpolydev->updateStrokeAdjust(state);
1121 booltextdev->updateStrokeAdjust(state);
1122 rgbdev->updateStrokeAdjust(state);
1123 clip0dev->updateStrokeAdjust(state);
1124 clip1dev->updateStrokeAdjust(state);
1125 gfxdev->updateStrokeAdjust(state);
1127 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
1129 boolpolydev->updateFillColorSpace(state);
1130 booltextdev->updateFillColorSpace(state);
1131 rgbdev->updateFillColorSpace(state);
1132 clip0dev->updateFillColorSpace(state);
1133 clip1dev->updateFillColorSpace(state);
1134 gfxdev->updateFillColorSpace(state);
1136 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
1138 boolpolydev->updateStrokeColorSpace(state);
1139 booltextdev->updateStrokeColorSpace(state);
1140 rgbdev->updateStrokeColorSpace(state);
1141 clip0dev->updateStrokeColorSpace(state);
1142 clip1dev->updateStrokeColorSpace(state);
1143 gfxdev->updateStrokeColorSpace(state);
1145 void BitmapOutputDev::updateFillColor(GfxState *state)
1147 boolpolydev->updateFillColor(state);
1148 booltextdev->updateFillColor(state);
1149 rgbdev->updateFillColor(state);
1150 clip0dev->updateFillColor(state);
1151 clip1dev->updateFillColor(state);
1152 gfxdev->updateFillColor(state);
1154 void BitmapOutputDev::updateStrokeColor(GfxState *state)
1156 boolpolydev->updateStrokeColor(state);
1157 booltextdev->updateStrokeColor(state);
1158 rgbdev->updateStrokeColor(state);
1159 clip0dev->updateStrokeColor(state);
1160 clip1dev->updateStrokeColor(state);
1161 gfxdev->updateStrokeColor(state);
1163 void BitmapOutputDev::updateBlendMode(GfxState *state)
1165 boolpolydev->updateBlendMode(state);
1166 booltextdev->updateBlendMode(state);
1167 rgbdev->updateBlendMode(state);
1168 clip0dev->updateBlendMode(state);
1169 clip1dev->updateBlendMode(state);
1170 gfxdev->updateBlendMode(state);
1172 void BitmapOutputDev::updateFillOpacity(GfxState *state)
1174 boolpolydev->updateFillOpacity(state);
1175 booltextdev->updateFillOpacity(state);
1176 rgbdev->updateFillOpacity(state);
1177 clip0dev->updateFillOpacity(state);
1178 clip1dev->updateFillOpacity(state);
1179 gfxdev->updateFillOpacity(state);
1181 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
1183 boolpolydev->updateStrokeOpacity(state);
1184 booltextdev->updateStrokeOpacity(state);
1185 rgbdev->updateStrokeOpacity(state);
1186 clip0dev->updateStrokeOpacity(state);
1187 clip1dev->updateStrokeOpacity(state);
1188 gfxdev->updateStrokeOpacity(state);
1190 void BitmapOutputDev::updateFillOverprint(GfxState *state)
1192 boolpolydev->updateFillOverprint(state);
1193 booltextdev->updateFillOverprint(state);
1194 rgbdev->updateFillOverprint(state);
1195 clip0dev->updateFillOverprint(state);
1196 clip1dev->updateFillOverprint(state);
1197 gfxdev->updateFillOverprint(state);
1199 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
1201 boolpolydev->updateStrokeOverprint(state);
1202 booltextdev->updateStrokeOverprint(state);
1203 rgbdev->updateStrokeOverprint(state);
1204 clip0dev->updateStrokeOverprint(state);
1205 clip1dev->updateStrokeOverprint(state);
1206 gfxdev->updateStrokeOverprint(state);
1208 void BitmapOutputDev::updateTransfer(GfxState *state)
1210 boolpolydev->updateTransfer(state);
1211 booltextdev->updateTransfer(state);
1212 rgbdev->updateTransfer(state);
1213 clip0dev->updateTransfer(state);
1214 clip1dev->updateTransfer(state);
1215 gfxdev->updateTransfer(state);
1218 void BitmapOutputDev::updateFont(GfxState *state)
1220 boolpolydev->updateFont(state);
1221 booltextdev->updateFont(state);
1222 rgbdev->updateFont(state);
1223 clip0dev->updateFont(state);
1224 clip1dev->updateFont(state);
1225 gfxdev->updateFont(state);
1227 void BitmapOutputDev::updateTextMat(GfxState *state)
1229 boolpolydev->updateTextMat(state);
1230 booltextdev->updateTextMat(state);
1231 rgbdev->updateTextMat(state);
1232 clip0dev->updateTextMat(state);
1233 clip1dev->updateTextMat(state);
1234 gfxdev->updateTextMat(state);
1236 void BitmapOutputDev::updateCharSpace(GfxState *state)
1238 boolpolydev->updateCharSpace(state);
1239 booltextdev->updateCharSpace(state);
1240 rgbdev->updateCharSpace(state);
1241 clip0dev->updateCharSpace(state);
1242 clip1dev->updateCharSpace(state);
1243 gfxdev->updateCharSpace(state);
1245 void BitmapOutputDev::updateRender(GfxState *state)
1247 boolpolydev->updateRender(state);
1248 booltextdev->updateRender(state);
1249 rgbdev->updateRender(state);
1250 clip0dev->updateRender(state);
1251 clip1dev->updateRender(state);
1252 gfxdev->updateRender(state);
1254 void BitmapOutputDev::updateRise(GfxState *state)
1256 boolpolydev->updateRise(state);
1257 booltextdev->updateRise(state);
1258 rgbdev->updateRise(state);
1259 clip0dev->updateRise(state);
1260 clip1dev->updateRise(state);
1261 gfxdev->updateRise(state);
1263 void BitmapOutputDev::updateWordSpace(GfxState *state)
1265 boolpolydev->updateWordSpace(state);
1266 booltextdev->updateWordSpace(state);
1267 rgbdev->updateWordSpace(state);
1268 clip0dev->updateWordSpace(state);
1269 clip1dev->updateWordSpace(state);
1270 gfxdev->updateWordSpace(state);
1272 void BitmapOutputDev::updateHorizScaling(GfxState *state)
1274 boolpolydev->updateHorizScaling(state);
1275 booltextdev->updateHorizScaling(state);
1276 rgbdev->updateHorizScaling(state);
1277 clip0dev->updateHorizScaling(state);
1278 clip1dev->updateHorizScaling(state);
1279 gfxdev->updateHorizScaling(state);
1281 void BitmapOutputDev::updateTextPos(GfxState *state)
1283 boolpolydev->updateTextPos(state);
1284 booltextdev->updateTextPos(state);
1285 rgbdev->updateTextPos(state);
1286 clip0dev->updateTextPos(state);
1287 clip1dev->updateTextPos(state);
1288 gfxdev->updateTextPos(state);
1290 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
1292 boolpolydev->updateTextShift(state, shift);
1293 booltextdev->updateTextShift(state, shift);
1294 rgbdev->updateTextShift(state, shift);
1295 clip0dev->updateTextShift(state, shift);
1296 clip1dev->updateTextShift(state, shift);
1297 gfxdev->updateTextShift(state, shift);
1300 double max(double x, double y)
1304 double min(double x, double y)
1309 gfxbbox_t BitmapOutputDev::getBBox(GfxState*state)
1311 GfxPath * path = state->getPath();
1312 int num = path->getNumSubpaths();
1313 gfxbbox_t bbox = {0,0,1,1};
1316 for(t = 0; t < num; t++) {
1317 GfxSubpath *subpath = path->getSubpath(t);
1318 int subnum = subpath->getNumPoints();
1320 for(s=0;s<subnum;s++) {
1322 state->transform(subpath->getX(s),subpath->getY(s),&x,&y);
1324 bbox.xmin = x; bbox.ymin = y;
1325 bbox.xmax = x; bbox.ymax = y;
1328 bbox.xmin = min(bbox.xmin, x);
1329 bbox.ymin = min(bbox.ymin, y);
1330 bbox.xmax = max(bbox.xmax, x);
1331 bbox.ymax = max(bbox.ymax, y);
1338 void BitmapOutputDev::stroke(GfxState *state)
1340 msg("<debug> stroke");
1341 boolpolydev->stroke(state);
1342 gfxbbox_t bbox = getBBox(state);
1343 double width = state->getTransformedLineWidth();
1344 bbox.xmin -= width; bbox.ymin -= width;
1345 bbox.xmax += width; bbox.ymax += width;
1346 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1347 rgbdev->stroke(state);
1348 dbg_newdata("stroke");
1351 extern gfxcolor_t getFillColor(GfxState * state);
1353 char area_is_plain_colored(GfxState*state, SplashBitmap*boolpoly, SplashBitmap*rgbbitmap, int x1, int y1, int x2, int y2)
1355 int width = boolpoly->getWidth();
1356 int height = boolpoly->getHeight();
1357 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
1360 gfxcolor_t color = getFillColor(state);
1361 SplashColorPtr rgb = rgbbitmap->getDataPtr()
1362 + (y1*width+x1)*sizeof(SplashColor);
1363 int width8 = (width+7)/8;
1364 unsigned char*bits = (unsigned char*)boolpoly->getDataPtr()
1371 if(rgb[x*3+0] != color.r ||
1372 rgb[x*3+1] != color.g ||
1373 rgb[x*3+2] != color.b)
1376 rgb += width*sizeof(SplashColor);
1381 void BitmapOutputDev::fill(GfxState *state)
1383 msg("<debug> fill");
1384 boolpolydev->fill(state);
1385 gfxbbox_t bbox = getBBox(state);
1386 if(config_optimizeplaincolorfills) {
1387 if(area_is_plain_colored(state, boolpolybitmap, rgbbitmap, bbox.xmin, bbox.ymin, bbox.xmax, bbox.ymax)) {
1391 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1392 rgbdev->fill(state);
1393 dbg_newdata("fill");
1395 void BitmapOutputDev::eoFill(GfxState *state)
1397 msg("<debug> eoFill");
1398 boolpolydev->eoFill(state);
1399 gfxbbox_t bbox = getBBox(state);
1400 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1401 rgbdev->eoFill(state);
1402 dbg_newdata("eofill");
1404 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1405 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
1406 int paintType, Dict *resDict,
1407 double *mat, double *bbox,
1408 int x0, int y0, int x1, int y1,
1409 double xStep, double yStep)
1411 msg("<debug> tilingPatternFill");
1412 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1413 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1414 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1415 dbg_newdata("tilingpatternfill");
1418 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
1419 int paintType, Dict *resDict,
1420 double *mat, double *bbox,
1421 int x0, int y0, int x1, int y1,
1422 double xStep, double yStep)
1424 msg("<debug> tilingPatternFill");
1425 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1426 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1427 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1428 dbg_newdata("tilingpatternfill");
1432 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
1434 msg("<debug> functionShadedFill");
1435 boolpolydev->functionShadedFill(state, shading);
1436 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1437 return rgbdev->functionShadedFill(state, shading);
1439 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
1441 msg("<debug> axialShadedFill");
1442 boolpolydev->axialShadedFill(state, shading);
1443 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1444 return rgbdev->axialShadedFill(state, shading);
1446 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
1448 msg("<debug> radialShadedFill");
1449 boolpolydev->radialShadedFill(state, shading);
1450 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1451 return rgbdev->radialShadedFill(state, shading);
1454 SplashColor black = {0,0,0};
1455 SplashColor white = {255,255,255};
1457 void BitmapOutputDev::clip(GfxState *state)
1459 msg("<debug> clip");
1460 boolpolydev->clip(state);
1461 booltextdev->clip(state);
1462 rgbdev->clip(state);
1463 clip1dev->clip(state);
1465 void BitmapOutputDev::eoClip(GfxState *state)
1467 msg("<debug> eoClip");
1468 boolpolydev->eoClip(state);
1469 booltextdev->eoClip(state);
1470 rgbdev->eoClip(state);
1471 clip1dev->eoClip(state);
1473 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1475 msg("<debug> clipToStrokePath");
1476 boolpolydev->clipToStrokePath(state);
1477 booltextdev->clipToStrokePath(state);
1478 rgbdev->clipToStrokePath(state);
1479 clip1dev->clipToStrokePath(state);
1482 void BitmapOutputDev::beginStringOp(GfxState *state)
1484 msg("<debug> beginStringOp");
1485 clip0dev->beginStringOp(state);
1486 clip1dev->beginStringOp(state);
1487 booltextdev->beginStringOp(state);
1488 gfxdev->beginStringOp(state);
1490 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1492 msg("<debug> beginString");
1493 clip0dev->beginString(state, s);
1494 clip1dev->beginString(state, s);
1495 booltextdev->beginString(state, s);
1496 gfxdev->beginString(state, s);
1499 void BitmapOutputDev::clearClips()
1501 clearBooleanBitmap(clip0bitmap, 0, 0, 0, 0);
1502 clearBooleanBitmap(clip1bitmap, 0, 0, 0, 0);
1504 void BitmapOutputDev::clearBoolPolyDev()
1506 clearBooleanBitmap(stalepolybitmap, 0, 0, stalepolybitmap->getWidth(), stalepolybitmap->getHeight());
1508 void BitmapOutputDev::clearBoolTextDev()
1510 clearBooleanBitmap(staletextbitmap, 0, 0, staletextbitmap->getWidth(), staletextbitmap->getHeight());
1512 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1513 double dx, double dy,
1514 double originX, double originY,
1515 CharCode code, int nBytes, Unicode *u, int uLen)
1517 msg("<debug> drawChar render=%d", state->getRender());
1519 if(state->getRender()&RENDER_CLIP) {
1520 //char is just a clipping boundary
1521 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1522 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1523 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1524 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1525 } else if(state->getRender()&RENDER_STROKE) {
1526 // we're drawing as stroke
1527 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1528 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1529 } else if(rgbbitmap != rgbdev->getBitmap()) {
1530 // we're doing softmasking or transparency grouping
1531 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1532 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1534 // we're drawing a regular char
1536 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1537 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1539 /* calculate the bbox of this character */
1540 int x1 = (int)x, x2 = (int)x+1, y1 = (int)y, y2 = (int)y+1;
1541 SplashFont*font = clip0dev->getCurrentFont();
1542 SplashPath*path = font?font->getGlyphPath(code):NULL;
1546 path->offset((SplashCoord)x, (SplashCoord)y);
1548 for(t=0;t<path->getLength();t++) {
1551 path->getPoint(t,&xx,&yy,&f);
1552 state->transform(xx,yy,&xx,&yy);
1553 if(xx<x1) x1=(int)xx;
1554 if(yy<y1) y1=(int)yy;
1555 if(xx>=x2) x2=(int)xx+1;
1556 if(yy>=y2) y2=(int)yy+1;
1558 delete(path);path=0;
1561 /* if this character is affected somehow by the various clippings (i.e., it looks
1562 different on a device without clipping), then draw it on the bitmap, not as
1564 if(clip0and1differ(x1,y1,x2,y2)) {
1565 msg("<verbose> Char %d is affected by clipping", code);
1566 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1567 checkNewBitmap(x1,y1,x2,y2);
1568 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1569 if(config_extrafontdata) {
1570 int oldrender = state->getRender();
1571 state->setRender(3); //invisible
1572 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1573 state->setRender(oldrender);
1577 /* this char is not at all affected by clipping.
1578 Now just dump out the bitmap we're currently working on, if necessary. */
1579 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1580 checkNewText(x1,y1,x2,y2);
1581 /* use polygonal output device to do the actual text handling */
1582 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1585 dbg_newdata("text");
1587 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1589 msg("<error> internal error: drawString not implemented");
1592 void BitmapOutputDev::endTextObject(GfxState *state)
1594 msg("<debug> endTextObject");
1595 rgbdev->endTextObject(state);
1596 clip0dev->endTextObject(state);
1597 clip1dev->endTextObject(state);
1598 booltextdev->endTextObject(state);
1599 /* the only thing "drawn" here is clipping */
1600 //checkNewText(UNKNOWN_BOUNDING_BOX);
1601 gfxdev->endTextObject(state);
1602 dbg_newdata("endtextobject");
1604 void BitmapOutputDev::endString(GfxState *state)
1606 msg("<debug> endString");
1607 clip0dev->endString(state);
1608 clip1dev->endString(state);
1609 booltextdev->endString(state);
1610 int render = state->getRender();
1611 if(render != RENDER_INVISIBLE && render != RENDER_FILL) {
1612 /* xpdf draws things like stroke text or fill+stroke text in the
1613 endString() method */
1614 checkNewText(UNKNOWN_BOUNDING_BOX);
1616 gfxdev->endString(state);
1617 dbg_newdata("endstring");
1619 void BitmapOutputDev::endStringOp(GfxState *state)
1621 msg("<debug> endStringOp");
1622 clip0dev->endStringOp(state);
1623 clip1dev->endStringOp(state);
1624 booltextdev->endStringOp(state);
1625 gfxdev->endStringOp(state);
1626 dbg_newdata("endstringop");
1629 /* TODO: these four operations below *should* do nothing, as type3
1630 chars are drawn using operations like fill() */
1631 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1632 double dx, double dy,
1633 CharCode code, Unicode *u, int uLen)
1635 msg("<debug> beginType3Char");
1636 /* call gfxdev so that it can generate "invisible" characters
1637 on top of the actual graphic content, for text extraction */
1638 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1640 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1642 msg("<debug> type3D0");
1643 return gfxdev->type3D0(state, wx, wy);
1645 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1647 msg("<debug> type3D1");
1648 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1650 void BitmapOutputDev::endType3Char(GfxState *state)
1652 msg("<debug> endType3Char");
1653 gfxdev->endType3Char(state);
1656 class CopyStream: public Object
1660 MemStream*memstream;
1662 CopyStream(Stream*str, int len)
1667 buf = (char*)malloc(len);
1669 for (t=0; t<len; t++)
1670 buf[t] = str->getChar();
1673 this->dict = str->getDict();
1674 this->memstream = new MemStream(buf, 0, len, this);
1678 ::free(this->buf);this->buf = 0;
1679 delete this->memstream;
1681 Dict* getDict() {return dict;}
1682 Stream* getStream() {return this->memstream;};
1685 gfxbbox_t BitmapOutputDev::getImageBBox(GfxState*state)
1689 state->transform(0, 1, &x, &y);
1690 bbox.xmin=bbox.xmax = x;
1691 bbox.ymin=bbox.ymax = y;
1692 state->transform(0, 0, &x, &y);
1693 bbox.xmin=min(bbox.xmin,x);
1694 bbox.ymin=min(bbox.ymin,y);
1695 bbox.xmax=max(bbox.xmax,x);
1696 bbox.ymax=max(bbox.ymax,y);
1697 state->transform(1, 0, &x, &y);
1698 bbox.xmin=min(bbox.xmin,x);
1699 bbox.ymin=min(bbox.ymin,y);
1700 bbox.xmax=max(bbox.xmax,x);
1701 bbox.ymax=max(bbox.ymax,y);
1702 state->transform(1, 1, &x, &y);
1703 bbox.xmin=min(bbox.xmin,x);
1704 bbox.ymin=min(bbox.ymin,y);
1705 bbox.xmax=max(bbox.xmax,x);
1706 bbox.ymax=max(bbox.ymax,y);
1709 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1710 int width, int height, GBool invert,
1713 msg("<debug> drawImageMask streamkind=%d", str->getKind());
1715 CopyStream*cpystr = new CopyStream(str, height * ((width + 7) / 8));
1716 str = cpystr->getStream();
1718 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1719 gfxbbox_t bbox = getImageBBox(state);
1720 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1721 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1723 dbg_newdata("imagemask");
1725 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1726 int width, int height, GfxImageColorMap *colorMap,
1727 int *maskColors, GBool inlineImg)
1729 msg("<debug> drawImage streamkind=%d", str->getKind());
1731 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1732 str = cpystr->getStream();
1734 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1735 gfxbbox_t bbox=getImageBBox(state);
1736 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1737 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1739 dbg_newdata("image");
1741 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1742 int width, int height,
1743 GfxImageColorMap *colorMap,
1744 Stream *maskStr, int maskWidth, int maskHeight,
1747 msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
1749 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1750 str = cpystr->getStream();
1752 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1753 gfxbbox_t bbox=getImageBBox(state);
1754 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1755 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1757 dbg_newdata("maskedimage");
1759 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1760 int width, int height,
1761 GfxImageColorMap *colorMap,
1763 int maskWidth, int maskHeight,
1764 GfxImageColorMap *maskColorMap)
1766 msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
1768 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1769 str = cpystr->getStream();
1771 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1772 gfxbbox_t bbox=getImageBBox(state);
1773 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1774 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1776 dbg_newdata("softmaskimage");
1778 void BitmapOutputDev::drawForm(Ref id)
1780 msg("<debug> drawForm");
1781 boolpolydev->drawForm(id);
1782 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1783 rgbdev->drawForm(id);
1786 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1788 msg("<debug> processLink");
1789 gfxdev->processLink(link, catalog);
1792 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1793 GfxColorSpace *blendingColorSpace,
1794 GBool isolated, GBool knockout,
1797 msg("<debug> beginTransparencyGroup");
1798 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1799 GfxState*state1 = state->copy();
1800 GfxState*state2 = state->copy();
1802 state1->setPath(state->getPath()->copy());
1804 state2->setPath(state->getPath()->copy());
1806 GfxState*state1 = state->copy(gTrue);
1807 GfxState*state2 = state->copy(gTrue);
1809 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1810 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1811 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1814 dbg_newdata("endtransparencygroup");
1816 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1818 msg("<debug> endTransparencyGroup");
1819 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1820 GfxState*state1 = state->copy();
1821 GfxState*state2 = state->copy();
1823 state1->setPath(state->getPath()->copy());
1825 state2->setPath(state->getPath()->copy());
1827 GfxState*state1 = state->copy(gTrue);
1828 GfxState*state2 = state->copy(gTrue);
1830 boolpolydev->endTransparencyGroup(state1);
1831 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1832 rgbdev->endTransparencyGroup(state2);
1835 clip1dev->endTransparencyGroup(state);
1836 dbg_newdata("endtransparencygroup");
1838 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1840 msg("<debug> paintTransparencyGroup");
1841 boolpolydev->paintTransparencyGroup(state,bbox);
1842 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1843 rgbdev->paintTransparencyGroup(state,bbox);
1844 clip1dev->paintTransparencyGroup(state,bbox);
1845 dbg_newdata("painttransparencygroup");
1847 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1849 msg("<debug> setSoftMask");
1850 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1851 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1852 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1853 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1854 dbg_newdata("setsoftmask");
1856 void BitmapOutputDev::clearSoftMask(GfxState *state)
1858 msg("<debug> clearSoftMask");
1859 boolpolydev->clearSoftMask(state);
1860 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1861 rgbdev->clearSoftMask(state);
1862 clip1dev->clearSoftMask(state);
1863 dbg_newdata("clearsoftmask");