3 Output Device which creates a bitmap.
5 Swftools is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 Swftools is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with swftools; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 #include "BitmapOutputDev.h"
25 #include "GFXOutputDev.h"
26 #include "SplashBitmap.h"
27 #include "SplashPattern.h"
31 #include "../devices/record.h"
35 #define UNKNOWN_BOUNDING_BOX 0,0,0,0
37 static SplashColor splash_white = {255,255,255};
38 static SplashColor splash_black = {0,0,0};
40 ClipState::ClipState()
47 BitmapOutputDev::BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
51 this->xref = doc->getXRef();
53 /* color graphic output device, for creating bitmaps */
54 this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
56 /* color mode for binary bitmaps */
57 SplashColorMode colorMode = splashModeMono1;
59 /* two devices for testing things against clipping: one clips, the other doesn't */
60 this->clip0dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
61 this->clip1dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
63 /* device indicating where polygonal pixels were drawn */
64 this->boolpolydev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
65 /* device indicating where text pixels were drawn */
66 this->booltextdev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
68 /* device for handling texts and links */
69 this->gfxdev = new GFXOutputDev(info, this->doc);
71 this->rgbdev->startDoc(this->xref);
72 this->boolpolydev->startDoc(this->xref);
73 this->booltextdev->startDoc(this->xref);
74 this->clip0dev->startDoc(this->xref);
75 this->clip1dev->startDoc(this->xref);
77 this->gfxoutput = (gfxdevice_t*)malloc(sizeof(gfxdevice_t));
78 gfxdevice_record_init(this->gfxoutput, 0);
80 this->gfxdev->setDevice(this->gfxoutput);
82 this->config_extrafontdata = 0;
85 //this->clipstates = 0;
87 BitmapOutputDev::~BitmapOutputDev()
90 gfxresult_t*r = this->gfxoutput->finish(this->gfxoutput);
92 free(this->gfxoutput);this->gfxoutput = 0;
95 delete this->bboxpath;this->bboxpath = 0;
98 delete this->rgbdev;this->rgbdev = 0;
101 delete this->gfxdev;this->gfxdev= 0;
103 if(this->boolpolydev) {
104 delete this->boolpolydev;this->boolpolydev = 0;
106 if(this->stalepolybitmap) {
107 delete this->stalepolybitmap;this->stalepolybitmap = 0;
109 if(this->staletextbitmap) {
110 delete this->staletextbitmap;this->staletextbitmap = 0;
112 if(this->booltextdev) {
113 delete this->booltextdev;this->booltextdev = 0;
116 delete this->clip0dev;this->clip0dev = 0;
119 delete this->clip1dev;this->clip1dev = 0;
121 //if(this->clipbitmap) {
122 // delete this->clipbitmap;this->clipbitmap = 0;
124 //if(this->clipdev) {
125 // delete this->clipdev;this->clipdev = 0;
130 GBool BitmapOutputDev::getVectorAntialias()
132 return this->rgbdev->getVectorAntialias();
134 void BitmapOutputDev::setVectorAntialias(GBool vaa)
136 this->rgbdev->setVectorAntialias(vaa);
138 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
142 void BitmapOutputDev::setMove(int x,int y)
144 this->gfxdev->setMove(x,y);
145 this->user_movex = x;
146 this->user_movey = y;
148 void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
150 this->gfxdev->setClip(x1,y1,x2,y2);
151 this->user_clipx1 = x1;
152 this->user_clipy1 = y1;
153 this->user_clipx2 = x2;
154 this->user_clipy2 = y2;
156 void BitmapOutputDev::setParameter(const char*key, const char*value)
158 if(!strcmp(key, "extrafontdata")) {
159 this->config_extrafontdata = atoi(value);
161 this->gfxdev->setParameter(key, value);
163 void BitmapOutputDev::setPageMap(int*page2page, int num_pages)
165 this->gfxdev->setPageMap(page2page, num_pages);
168 void writeBitmap(SplashBitmap*bitmap, char*filename);
169 void writeAlpha(SplashBitmap*bitmap, char*filename);
171 static int dbg_btm_counter=1;
173 void BitmapOutputDev::flushBitmap()
175 int width = rgbdev->getBitmapWidth();
176 int height = rgbdev->getBitmapHeight();
178 if(sizeof(SplashColor)!=3) {
179 msg("<error> sizeof(SplashColor)!=3");
183 /*static int counter=0;
185 writeBitmap(rgbdev->getBitmap(), "test.png");
188 /*static int counter=0;
190 sprintf(filename, "test%d.png", counter++);
191 writeBitmap(rgbbitmap, filename);*/
193 SplashColorPtr rgb = rgbbitmap->getDataPtr();
194 Guchar*alpha = rgbbitmap->getAlphaPtr();
196 Guchar*alpha2 = stalepolybitmap->getDataPtr();
197 int width8 = (stalepolybitmap->getWidth()+7)/8;
200 sprintf(filename, "flush%d_mask.png", dbg_btm_counter);
201 writeAlpha(stalepolybitmap, filename);
202 sprintf(filename, "flush%d_alpha.png", dbg_btm_counter);
203 writeAlpha(rgbbitmap, filename);
204 sprintf(filename, "flush%d_bitmap.png", dbg_btm_counter);
205 writeBitmap(rgbbitmap, filename);*/
207 ibbox_t* boxes = get_bitmap_bboxes((unsigned char*)alpha, width, height);
210 for(b=boxes;b;b=b->next) {
216 /* clip against (-movex, -movey, -movex+width, -movey+height) */
217 if(xmin < -this->movex) xmin = -this->movex;
218 if(ymin < -this->movey) ymin = -this->movey;
219 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
220 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
222 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
224 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
227 int rangex = xmax-xmin;
228 int rangey = ymax-ymin;
229 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
230 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
232 img->height = rangey;
234 for(y=0;y<rangey;y++) {
235 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
236 gfxcolor_t*out = &img->data[y*rangex];
237 Guchar*ain = &alpha[(y+ymin)*width+xmin];
238 Guchar*ain2 = &alpha2[(y+ymin)*width8];
239 if(this->emptypage) {
240 for(x=0;x<rangex;x++) {
241 /* the first bitmap on the page doesn't need to have an alpha channel-
242 blend against a white background*/
243 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
244 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
245 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
249 for(x=0;x<rangex;x++) {
250 if(!(ain2[(x+xmin)/8]&(0x80>>((x+xmin)&7)))) {
251 /* cut away pixels that we don't remember drawing (i.e., that are
252 not in the monochrome bitmap). Prevents some "hairlines" showing
253 up to the left and right of bitmaps. */
254 out[x].r = 0;out[x].g = 0;out[x].b = 0;out[x].a = 0;
256 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, this
257 data has non-premultiplied alpha, which is exactly what the output device
258 expects, so don't premultiply it here, either.
260 out[x].r = in[x*3+0];
261 out[x].g = in[x*3+1];
262 out[x].b = in[x*3+2];
269 /* transform bitmap rectangle to "device space" */
283 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
284 dev->fillbitmap(dev, line, img, &m, 0);
287 free(img->data);img->data=0;free(img);img=0;
289 ibbox_destroy(boxes);
291 memset(rgbbitmap->getAlphaPtr(), 0, rgbbitmap->getWidth()*rgbbitmap->getHeight());
292 memset(rgbbitmap->getDataPtr(), 0, rgbbitmap->getRowSize()*rgbbitmap->getHeight());
297 void BitmapOutputDev::flushText()
299 msg("<verbose> Flushing text");
300 gfxdevice_record_flush(this->gfxoutput, this->dev);
305 void writeMonoBitmap(SplashBitmap*btm, char*filename)
307 int width8 = (btm->getWidth()+7)/8;
308 int width = btm->getWidth();
309 int height = btm->getHeight();
310 gfxcolor_t*b = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
311 unsigned char*data = btm->getDataPtr();
313 for(y=0;y<height;y++) {
314 unsigned char*l = &data[width8*y];
315 gfxcolor_t*d = &b[width*y];
316 for(x=0;x<width;x++) {
317 if(l[x>>3]&(128>>(x&7))) {
318 d[x].r = d[x].b = d[x].a = 255;
321 d[x].r = d[x].g = d[x].b = d[x].a = 0;
325 writePNG(filename, (unsigned char*)b, width, height);
329 void writeBitmap(SplashBitmap*bitmap, char*filename)
333 int width = bitmap->getWidth();
334 int height = bitmap->getHeight();
336 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
338 if(bitmap->getMode()==splashModeMono1) {
339 writeMonoBitmap(bitmap, filename);
343 for(y=0;y<height;y++) {
344 gfxcolor_t*line = &data[y*width];
345 for(x=0;x<width;x++) {
346 Guchar c[4] = {0,0,0,0};
347 bitmap->getPixel(x,y,c);
351 line[x].a = bitmap->getAlpha(x,y);
354 writePNG(filename, (unsigned char*)data, width, height);
358 void writeAlpha(SplashBitmap*bitmap, char*filename)
362 int width = bitmap->getWidth();
363 int height = bitmap->getHeight();
365 if(bitmap->getMode()==splashModeMono1) {
366 writeMonoBitmap(bitmap, filename);
370 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
372 for(y=0;y<height;y++) {
373 gfxcolor_t*line = &data[y*width];
374 for(x=0;x<width;x++) {
375 int a = bitmap->getAlpha(x,y);
382 writePNG(filename, (unsigned char*)data, width, height);
386 static const char*STATE_NAME[] = {"parallel", "textabovebitmap", "bitmapabovetext"};
388 int checkAlphaSanity(SplashBitmap*boolbtm, SplashBitmap*alphabtm)
390 assert(boolbtm->getWidth() == alphabtm->getWidth());
391 assert(boolbtm->getHeight() == alphabtm->getHeight());
392 if(boolbtm->getMode()==splashModeMono1) {
396 int width = boolbtm->getWidth();
397 int height = boolbtm->getHeight();
401 for(y=0;y<height;y++) {
402 for(x=0;x<width;x++) {
403 int a1 = alphabtm->getAlpha(x,y);
404 int a2 = boolbtm->getAlpha(x,y);
410 double badness = bad/(double)(width*height);
412 msg("<error> Bitmaps don't correspond: %d out of %d pixels wrong (%.2f%%)", bad, width*height,
416 msg("<notice> %f", badness);
420 static inline GBool fixBBox(int*x1, int*y1, int*x2, int*y2, int width, int height)
422 if(!(*x1|*y1|*x2|*y2)) {
429 if(*x2<=*x1) return gFalse;
430 if(*x2<0) return gFalse;
432 if(*x1>=width) return gFalse;
433 if(*x2>width) *x2=width;
435 if(*y2<=*y1) return gFalse;
436 if(*y2<0) return gFalse;
438 if(*y1>=height) return gFalse;
439 if(*y2>height) *y2=height;
443 static void update_bitmap(SplashBitmap*bitmap, SplashBitmap*update, int x1, int y1, int x2, int y2, char overwrite)
445 assert(bitmap->getMode()==splashModeMono1);
446 assert(update->getMode()==splashModeMono1);
448 int width8 = (bitmap->getWidth()+7)/8;
449 assert(width8 == bitmap->getRowSize());
450 assert(width8 == update->getRowSize());
451 int height = bitmap->getHeight();
452 assert(height == update->getHeight());
454 if(!fixBBox(&x1, &y1, &x2, &y2, bitmap->getWidth(), bitmap->getHeight()))
457 Guchar*b = bitmap->getDataPtr() + y1*width8 + x1/8;
458 Guchar*u = update->getDataPtr() + y1*width8 + x1/8;
460 int xspan = (x2+7)/8 - x1/8;
461 int size = (y2-y1)*width8;
465 for(y=0;y<yspan;y++) {
471 if(((ptroff_t)b&7)==((ptroff_t)u&7)) {
473 for(y=0;y<yspan;y++) {
474 Guchar*e1 = b+xspan-8;
476 while(((ptroff_t)b&7) && b<e1) {
481 *(long long*)b |= *(long long*)u;
493 for(y=0;y<yspan;y++) {
494 for(x=0;x<xspan;x++) {
504 static void clearBooleanBitmap(SplashBitmap*btm, int x1, int y1, int x2, int y2)
506 if(!fixBBox(&x1, &y1, &x2, &y2, btm->getWidth(), btm->getHeight()))
509 if(btm->getMode()==splashModeMono1) {
510 int width8 = (btm->getWidth()+7)/8;
511 assert(width8 == btm->getRowSize());
512 int width = btm->getWidth();
513 int height = btm->getHeight();
514 Guchar*data = btm->getDataPtr();
515 memset(data+y1*width8, 0, width8*(y2-y1));
517 int width = btm->getAlphaRowSize();
518 int height = btm->getHeight();
519 memset(btm->getAlphaPtr(), 0, width*height);
523 void BitmapOutputDev::dbg_newdata(char*newdata)
529 sprintf(filename1, "state%03dboolbitmap_after%s.png", dbg_btm_counter, newdata);
530 sprintf(filename2, "state%03dbooltext_after%s.png", dbg_btm_counter, newdata);
531 sprintf(filename3, "state%03dbitmap_after%s.png", dbg_btm_counter, newdata);
532 msg("<verbose> %s %s %s", filename1, filename2, filename3);
533 writeAlpha(stalepolybitmap, filename1);
534 writeAlpha(booltextbitmap, filename2);
535 writeBitmap(rgbdev->getBitmap(), filename3);
540 GBool BitmapOutputDev::checkNewText(int x1, int y1, int x2, int y2)
542 /* called once some new text was drawn on booltextdev, and
543 before the same thing is drawn on gfxdev */
545 msg("<trace> Testing new text data against current bitmap data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
548 if(intersection(booltextbitmap, stalepolybitmap, x1,y1,x2,y2)) {
549 if(layerstate==STATE_PARALLEL) {
550 /* the new text is above the bitmap. So record that fact. */
551 msg("<verbose> Text is above current bitmap/polygon data");
552 layerstate=STATE_TEXT_IS_ABOVE;
553 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
554 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
555 /* there's a bitmap above the (old) text. So we need
556 to flush out that text, and record that the *new*
557 text is now *above* the bitmap
559 msg("<verbose> Text is above current bitmap/polygon data (which is above some other text)");
561 layerstate=STATE_TEXT_IS_ABOVE;
564 /* re-apply the update (which we would otherwise lose) */
565 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 1);
568 /* we already know that the current text section is
569 above the current bitmap section- now just new
570 bitmap data *and* new text data was drawn, and
571 *again* it's above the current bitmap. */
572 msg("<verbose> Text is still above current bitmap/polygon data");
573 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
576 update_bitmap(staletextbitmap, booltextbitmap, x1, y1, x2, y2, 0);
579 /* clear the thing we just drew from our temporary drawing bitmap */
580 clearBooleanBitmap(booltextbitmap, x1, y1, x2, y2);
584 GBool BitmapOutputDev::checkNewBitmap(int x1, int y1, int x2, int y2)
586 /* similar to checkNewText() above, only in reverse */
587 msg("<trace> Testing new graphics data against current text data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
590 if(intersection(boolpolybitmap, staletextbitmap, x1,y1,x2,y2)) {
591 if(layerstate==STATE_PARALLEL) {
592 msg("<verbose> Bitmap is above current text data");
593 layerstate=STATE_BITMAP_IS_ABOVE;
594 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
595 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
596 msg("<verbose> Bitmap is above current text data (which is above some bitmap)");
598 layerstate=STATE_BITMAP_IS_ABOVE;
600 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 1);
603 msg("<verbose> Bitmap is still above current text data");
604 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
607 update_bitmap(stalepolybitmap, boolpolybitmap, x1, y1, x2, y2, 0);
610 /* clear the thing we just drew from our temporary drawing bitmap */
611 clearBooleanBitmap(boolpolybitmap, x1, y1, x2, y2);
616 //void checkNewText() {
617 // Guchar*alpha = rgbbitmap->getAlphaPtr();
618 // Guchar*charpixels = clip1bitmap->getDataPtr();
620 // for(yy=0;yy<height;yy++) {
621 // Guchar*aline = &alpha[yy*width];
622 // Guchar*cline = &charpixels[yy*width8];
623 // for(xx=0;xx<width;xx++) {
625 // int bytepos = xx>>3;
626 // /* TODO: is the bit order correct? */
627 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
634 GBool BitmapOutputDev::clip0and1differ(int x1,int y1,int x2,int y2)
636 if(clip0bitmap->getMode()==splashModeMono1) {
637 int width = clip0bitmap->getWidth();
638 int width8 = (width+7)/8;
639 int height = clip0bitmap->getHeight();
641 if(!fixBBox(&x1,&y1,&x2,&y2,width,height)) {
642 /* area is outside or null */
646 SplashBitmap*clip0 = clip0bitmap;
647 SplashBitmap*clip1 = clip1bitmap;
653 unsigned char*row1 = &clip0bitmap->getDataPtr()[width8*y+x18];
654 unsigned char*row2 = &clip1bitmap->getDataPtr()[width8*y+x18];
655 if(memcmp(row1, row2, x28-x18)) {
661 SplashBitmap*clip0 = clip0bitmap;
662 SplashBitmap*clip1 = clip1bitmap;
663 int width = clip0->getAlphaRowSize();
664 int height = clip0->getHeight();
666 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
670 Guchar*a0 = clip0->getAlphaPtr();
671 Guchar*a1 = clip1->getAlphaPtr();
676 if(a0[y*width+x]!=a1[y*width+x]) {
684 char differs2 = memcmp(a0, a1, width*height);
685 if(differs && !differs2)
686 msg("<warning> Strange internal error (2)");
687 else if(!differs && differs2) {
688 msg("<warning> Bad Bounding Box: Difference in clip0 and clip1 outside bbox");
689 msg("<warning> %d %d %d %d", x1, y1, x2, y2);
695 GBool compare8(unsigned char*data1, unsigned char*data2, int len)
699 if(((ptroff_t)data1&7)==((ptroff_t)data2&7)) {
700 // oh good, we can align both to 8 byte
701 while((ptroff_t)data1&7) {
710 /* use 64 bit for the (hopefully aligned) middle section */
712 long long unsigned int*d1 = (long long unsigned int*)data1;
713 long long unsigned int*d2 = (long long unsigned int*)data2;
714 long long unsigned int x = 0;
726 if(data1[t]&data2[t]) {
733 GBool BitmapOutputDev::intersection(SplashBitmap*boolpoly, SplashBitmap*booltext, int x1, int y1, int x2, int y2)
735 if(boolpoly->getMode()==splashModeMono1) {
736 /* alternative implementation, using one bit per pixel-
737 needs the no-dither patch in xpdf */
739 int width = boolpoly->getWidth();
740 int height = boolpoly->getHeight();
742 if(!fixBBox(&x1,&y1,&x2,&y2, width, height)) {
746 Guchar*polypixels = boolpoly->getDataPtr();
747 Guchar*textpixels = booltext->getDataPtr();
749 int width8 = (width+7)/8;
754 polypixels+=y1*width8+x1/8;
755 textpixels+=y1*width8+x1/8;
756 runx=(x2+7)/8 - x1/8;
763 /*assert(sizeof(unsigned long long int)==8);
764 if(((ptroff_t)polypixels&7) || ((ptroff_t)textpixels&7)) {
765 //msg("<warning> Non-optimal alignment");
769 unsigned char*data1 = (unsigned char*)polypixels;
770 unsigned char*data2 = (unsigned char*)textpixels;
771 msg("<verbose> Testing area (%d,%d,%d,%d), runx=%d,runy=%d", x1,y1,x2,y2, runx, runy);
772 for(y=0;y<runy;y++) {
773 if(compare8(data1,data2,runx))
780 int width = boolpoly->getAlphaRowSize();
781 int height = boolpoly->getHeight();
783 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
786 Guchar*polypixels = boolpoly->getAlphaPtr();
787 Guchar*textpixels = booltext->getAlphaPtr();
794 if(polypixels[width*y+x]&&textpixels[width*y+x])
798 int ax1=0,ay1=0,ax2=0,ay2=0;
799 for(y=0;y<height;y++) {
800 for(x=0;x<width;x++) {
801 if(polypixels[width*y+x]&&textpixels[width*y+x]) {
803 if(!(ax1|ay1|ax2|ay2)) {
815 if(overlap1 && !overlap2)
816 msg("<warning> strange internal error");
817 if(!overlap1 && overlap2) {
818 msg("<warning> Bad bounding box: intersection outside bbox");
819 msg("<warning> given bbox: %d %d %d %d", x1, y1, x2, y2);
820 msg("<warning> changed area: %d %d %d %d", ax1, ay1, ax2, ay2);
827 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
830 state->transform(crop_x1,crop_y1,&x1,&y1);
831 state->transform(crop_x2,crop_y2,&x2,&y2);
832 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
833 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
835 this->movex = -(int)x1 - user_movex;
836 this->movey = -(int)y1 - user_movey;
838 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
844 this->width = (int)(x2-x1);
845 this->height = (int)(y2-y1);
847 msg("<debug> startPage");
848 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
849 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
850 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
851 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
852 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
853 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
855 boolpolybitmap = boolpolydev->getBitmap();
856 stalepolybitmap = new SplashBitmap(boolpolybitmap->getWidth(), boolpolybitmap->getHeight(), 1, boolpolybitmap->getMode(), 0);
857 assert(stalepolybitmap->getRowSize() == boolpolybitmap->getRowSize());
859 booltextbitmap = booltextdev->getBitmap();
860 staletextbitmap = new SplashBitmap(booltextbitmap->getWidth(), booltextbitmap->getHeight(), 1, booltextbitmap->getMode(), 0);
861 assert(staletextbitmap->getRowSize() == booltextbitmap->getRowSize());
863 clip0bitmap = clip0dev->getBitmap();
864 clip1bitmap = clip1dev->getBitmap();
865 rgbbitmap = rgbdev->getBitmap();
867 flushText(); // write out the initial clipping rectangle
869 /* just in case any device did draw a white background rectangle
874 this->layerstate = STATE_PARALLEL;
876 msg("<debug> startPage done");
879 void BitmapOutputDev::endPage()
881 msg("<verbose> endPage (BitmapOutputDev)");
883 /* notice: we're not fully done yet with this page- there might still be
884 a few calls to drawLink() yet to come */
886 void BitmapOutputDev::finishPage()
888 msg("<verbose> finishPage (BitmapOutputDev)");
891 if(layerstate == STATE_BITMAP_IS_ABOVE) {
899 /* splash will now destroy alpha, and paint the
900 background color into the "holes" in the bitmap */
901 boolpolydev->endPage();
902 booltextdev->endPage();
908 GBool BitmapOutputDev::upsideDown()
910 boolpolydev->upsideDown();
911 booltextdev->upsideDown();
912 clip0dev->upsideDown();
913 clip1dev->upsideDown();
914 return rgbdev->upsideDown();
917 GBool BitmapOutputDev::useDrawChar()
919 boolpolydev->useDrawChar();
920 booltextdev->useDrawChar();
921 clip0dev->useDrawChar();
922 clip1dev->useDrawChar();
923 return rgbdev->useDrawChar();
926 GBool BitmapOutputDev::useTilingPatternFill()
928 boolpolydev->useTilingPatternFill();
929 booltextdev->useTilingPatternFill();
930 clip0dev->useTilingPatternFill();
931 clip1dev->useTilingPatternFill();
932 return rgbdev->useTilingPatternFill();
935 GBool BitmapOutputDev::useShadedFills()
937 boolpolydev->useShadedFills();
938 booltextdev->useShadedFills();
939 clip0dev->useShadedFills();
940 clip1dev->useShadedFills();
941 return rgbdev->useShadedFills();
944 GBool BitmapOutputDev::useDrawForm()
946 boolpolydev->useDrawForm();
947 booltextdev->useDrawForm();
948 clip0dev->useDrawForm();
949 clip1dev->useDrawForm();
950 return rgbdev->useDrawForm();
953 GBool BitmapOutputDev::interpretType3Chars()
955 boolpolydev->interpretType3Chars();
956 booltextdev->interpretType3Chars();
957 clip0dev->interpretType3Chars();
958 clip1dev->interpretType3Chars();
959 return rgbdev->interpretType3Chars();
962 GBool BitmapOutputDev::needNonText()
964 boolpolydev->needNonText();
965 booltextdev->needNonText();
966 clip0dev->needNonText();
967 clip1dev->needNonText();
968 return rgbdev->needNonText();
970 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
971 int rotate, GBool useMediaBox, GBool crop,
972 int sliceX, int sliceY, int sliceW, int sliceH,
973 GBool printing, Catalog *catalog,
974 GBool (*abortCheckCbk)(void *data),
975 void *abortCheckCbkData)
979 void BitmapOutputDev::setDefaultCTM(double *ctm)
981 boolpolydev->setDefaultCTM(ctm);
982 booltextdev->setDefaultCTM(ctm);
983 rgbdev->setDefaultCTM(ctm);
984 clip0dev->setDefaultCTM(ctm);
985 clip1dev->setDefaultCTM(ctm);
986 gfxdev->setDefaultCTM(ctm);
988 void BitmapOutputDev::saveState(GfxState *state)
990 boolpolydev->saveState(state);
991 booltextdev->saveState(state);
992 rgbdev->saveState(state);
993 clip0dev->saveState(state);
994 clip1dev->saveState(state);
996 /*ClipState*cstate = new ClipState();
997 cstate->next = this->clipstates;
998 this->clipstates = cstate;*/
1000 void BitmapOutputDev::restoreState(GfxState *state)
1002 boolpolydev->restoreState(state);
1003 booltextdev->restoreState(state);
1004 rgbdev->restoreState(state);
1005 clip0dev->restoreState(state);
1006 clip1dev->restoreState(state);
1008 /*if(this->clipstates) {
1009 ClipState*old = this->clipstates;
1011 gfxdev->restoreState(state);
1013 this->clipstates = this->clipstates->next;
1016 msg("<error> invalid restoreState()");
1019 void BitmapOutputDev::updateAll(GfxState *state)
1021 boolpolydev->updateAll(state);
1022 booltextdev->updateAll(state);
1023 rgbdev->updateAll(state);
1024 clip0dev->updateAll(state);
1025 clip1dev->updateAll(state);
1026 gfxdev->updateAll(state);
1028 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
1030 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1031 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1032 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1033 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1034 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1035 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
1037 void BitmapOutputDev::updateLineDash(GfxState *state)
1039 boolpolydev->updateLineDash(state);
1040 booltextdev->updateLineDash(state);
1041 rgbdev->updateLineDash(state);
1042 clip0dev->updateLineDash(state);
1043 clip1dev->updateLineDash(state);
1044 gfxdev->updateLineDash(state);
1046 void BitmapOutputDev::updateFlatness(GfxState *state)
1048 boolpolydev->updateFlatness(state);
1049 booltextdev->updateFlatness(state);
1050 rgbdev->updateFlatness(state);
1051 clip0dev->updateFlatness(state);
1052 clip1dev->updateFlatness(state);
1053 gfxdev->updateFlatness(state);
1055 void BitmapOutputDev::updateLineJoin(GfxState *state)
1057 boolpolydev->updateLineJoin(state);
1058 booltextdev->updateLineJoin(state);
1059 rgbdev->updateLineJoin(state);
1060 clip0dev->updateLineJoin(state);
1061 clip1dev->updateLineJoin(state);
1062 gfxdev->updateLineJoin(state);
1064 void BitmapOutputDev::updateLineCap(GfxState *state)
1066 boolpolydev->updateLineCap(state);
1067 booltextdev->updateLineCap(state);
1068 rgbdev->updateLineCap(state);
1069 clip0dev->updateLineCap(state);
1070 clip1dev->updateLineCap(state);
1071 gfxdev->updateLineCap(state);
1073 void BitmapOutputDev::updateMiterLimit(GfxState *state)
1075 boolpolydev->updateMiterLimit(state);
1076 booltextdev->updateMiterLimit(state);
1077 rgbdev->updateMiterLimit(state);
1078 clip0dev->updateMiterLimit(state);
1079 clip1dev->updateMiterLimit(state);
1080 gfxdev->updateMiterLimit(state);
1082 void BitmapOutputDev::updateLineWidth(GfxState *state)
1084 boolpolydev->updateLineWidth(state);
1085 booltextdev->updateLineWidth(state);
1086 rgbdev->updateLineWidth(state);
1087 clip0dev->updateLineWidth(state);
1088 clip1dev->updateLineWidth(state);
1089 gfxdev->updateLineWidth(state);
1091 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
1093 boolpolydev->updateStrokeAdjust(state);
1094 booltextdev->updateStrokeAdjust(state);
1095 rgbdev->updateStrokeAdjust(state);
1096 clip0dev->updateStrokeAdjust(state);
1097 clip1dev->updateStrokeAdjust(state);
1098 gfxdev->updateStrokeAdjust(state);
1100 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
1102 boolpolydev->updateFillColorSpace(state);
1103 booltextdev->updateFillColorSpace(state);
1104 rgbdev->updateFillColorSpace(state);
1105 clip0dev->updateFillColorSpace(state);
1106 clip1dev->updateFillColorSpace(state);
1107 gfxdev->updateFillColorSpace(state);
1109 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
1111 boolpolydev->updateStrokeColorSpace(state);
1112 booltextdev->updateStrokeColorSpace(state);
1113 rgbdev->updateStrokeColorSpace(state);
1114 clip0dev->updateStrokeColorSpace(state);
1115 clip1dev->updateStrokeColorSpace(state);
1116 gfxdev->updateStrokeColorSpace(state);
1118 void BitmapOutputDev::updateFillColor(GfxState *state)
1120 boolpolydev->updateFillColor(state);
1121 booltextdev->updateFillColor(state);
1122 rgbdev->updateFillColor(state);
1123 clip0dev->updateFillColor(state);
1124 clip1dev->updateFillColor(state);
1125 gfxdev->updateFillColor(state);
1127 void BitmapOutputDev::updateStrokeColor(GfxState *state)
1129 boolpolydev->updateStrokeColor(state);
1130 booltextdev->updateStrokeColor(state);
1131 rgbdev->updateStrokeColor(state);
1132 clip0dev->updateStrokeColor(state);
1133 clip1dev->updateStrokeColor(state);
1134 gfxdev->updateStrokeColor(state);
1136 void BitmapOutputDev::updateBlendMode(GfxState *state)
1138 boolpolydev->updateBlendMode(state);
1139 booltextdev->updateBlendMode(state);
1140 rgbdev->updateBlendMode(state);
1141 clip0dev->updateBlendMode(state);
1142 clip1dev->updateBlendMode(state);
1143 gfxdev->updateBlendMode(state);
1145 void BitmapOutputDev::updateFillOpacity(GfxState *state)
1147 boolpolydev->updateFillOpacity(state);
1148 booltextdev->updateFillOpacity(state);
1149 rgbdev->updateFillOpacity(state);
1150 clip0dev->updateFillOpacity(state);
1151 clip1dev->updateFillOpacity(state);
1152 gfxdev->updateFillOpacity(state);
1154 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
1156 boolpolydev->updateStrokeOpacity(state);
1157 booltextdev->updateStrokeOpacity(state);
1158 rgbdev->updateStrokeOpacity(state);
1159 clip0dev->updateStrokeOpacity(state);
1160 clip1dev->updateStrokeOpacity(state);
1161 gfxdev->updateStrokeOpacity(state);
1163 void BitmapOutputDev::updateFillOverprint(GfxState *state)
1165 boolpolydev->updateFillOverprint(state);
1166 booltextdev->updateFillOverprint(state);
1167 rgbdev->updateFillOverprint(state);
1168 clip0dev->updateFillOverprint(state);
1169 clip1dev->updateFillOverprint(state);
1170 gfxdev->updateFillOverprint(state);
1172 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
1174 boolpolydev->updateStrokeOverprint(state);
1175 booltextdev->updateStrokeOverprint(state);
1176 rgbdev->updateStrokeOverprint(state);
1177 clip0dev->updateStrokeOverprint(state);
1178 clip1dev->updateStrokeOverprint(state);
1179 gfxdev->updateStrokeOverprint(state);
1181 void BitmapOutputDev::updateTransfer(GfxState *state)
1183 boolpolydev->updateTransfer(state);
1184 booltextdev->updateTransfer(state);
1185 rgbdev->updateTransfer(state);
1186 clip0dev->updateTransfer(state);
1187 clip1dev->updateTransfer(state);
1188 gfxdev->updateTransfer(state);
1191 void BitmapOutputDev::updateFont(GfxState *state)
1193 boolpolydev->updateFont(state);
1194 booltextdev->updateFont(state);
1195 rgbdev->updateFont(state);
1196 clip0dev->updateFont(state);
1197 clip1dev->updateFont(state);
1198 gfxdev->updateFont(state);
1200 void BitmapOutputDev::updateTextMat(GfxState *state)
1202 boolpolydev->updateTextMat(state);
1203 booltextdev->updateTextMat(state);
1204 rgbdev->updateTextMat(state);
1205 clip0dev->updateTextMat(state);
1206 clip1dev->updateTextMat(state);
1207 gfxdev->updateTextMat(state);
1209 void BitmapOutputDev::updateCharSpace(GfxState *state)
1211 boolpolydev->updateCharSpace(state);
1212 booltextdev->updateCharSpace(state);
1213 rgbdev->updateCharSpace(state);
1214 clip0dev->updateCharSpace(state);
1215 clip1dev->updateCharSpace(state);
1216 gfxdev->updateCharSpace(state);
1218 void BitmapOutputDev::updateRender(GfxState *state)
1220 boolpolydev->updateRender(state);
1221 booltextdev->updateRender(state);
1222 rgbdev->updateRender(state);
1223 clip0dev->updateRender(state);
1224 clip1dev->updateRender(state);
1225 gfxdev->updateRender(state);
1227 void BitmapOutputDev::updateRise(GfxState *state)
1229 boolpolydev->updateRise(state);
1230 booltextdev->updateRise(state);
1231 rgbdev->updateRise(state);
1232 clip0dev->updateRise(state);
1233 clip1dev->updateRise(state);
1234 gfxdev->updateRise(state);
1236 void BitmapOutputDev::updateWordSpace(GfxState *state)
1238 boolpolydev->updateWordSpace(state);
1239 booltextdev->updateWordSpace(state);
1240 rgbdev->updateWordSpace(state);
1241 clip0dev->updateWordSpace(state);
1242 clip1dev->updateWordSpace(state);
1243 gfxdev->updateWordSpace(state);
1245 void BitmapOutputDev::updateHorizScaling(GfxState *state)
1247 boolpolydev->updateHorizScaling(state);
1248 booltextdev->updateHorizScaling(state);
1249 rgbdev->updateHorizScaling(state);
1250 clip0dev->updateHorizScaling(state);
1251 clip1dev->updateHorizScaling(state);
1252 gfxdev->updateHorizScaling(state);
1254 void BitmapOutputDev::updateTextPos(GfxState *state)
1256 boolpolydev->updateTextPos(state);
1257 booltextdev->updateTextPos(state);
1258 rgbdev->updateTextPos(state);
1259 clip0dev->updateTextPos(state);
1260 clip1dev->updateTextPos(state);
1261 gfxdev->updateTextPos(state);
1263 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
1265 boolpolydev->updateTextShift(state, shift);
1266 booltextdev->updateTextShift(state, shift);
1267 rgbdev->updateTextShift(state, shift);
1268 clip0dev->updateTextShift(state, shift);
1269 clip1dev->updateTextShift(state, shift);
1270 gfxdev->updateTextShift(state, shift);
1273 double max(double x, double y)
1277 double min(double x, double y)
1282 gfxbbox_t BitmapOutputDev::getBBox(GfxState*state)
1284 GfxPath * path = state->getPath();
1285 int num = path->getNumSubpaths();
1286 gfxbbox_t bbox = {0,0,1,1};
1289 for(t = 0; t < num; t++) {
1290 GfxSubpath *subpath = path->getSubpath(t);
1291 int subnum = subpath->getNumPoints();
1293 for(s=0;s<subnum;s++) {
1295 state->transform(subpath->getX(s),subpath->getY(s),&x,&y);
1297 bbox.xmin = x; bbox.ymin = y;
1298 bbox.xmax = x; bbox.ymax = y;
1301 bbox.xmin = min(bbox.xmin, x);
1302 bbox.ymin = min(bbox.ymin, y);
1303 bbox.xmax = max(bbox.xmax, x);
1304 bbox.ymax = max(bbox.ymax, y);
1311 void BitmapOutputDev::stroke(GfxState *state)
1313 msg("<debug> stroke");
1314 boolpolydev->stroke(state);
1315 gfxbbox_t bbox = getBBox(state);
1316 double width = state->getTransformedLineWidth();
1317 bbox.xmin -= width; bbox.ymin -= width;
1318 bbox.xmax += width; bbox.ymax += width;
1319 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1320 rgbdev->stroke(state);
1321 dbg_newdata("stroke");
1323 void BitmapOutputDev::fill(GfxState *state)
1325 msg("<debug> fill");
1326 boolpolydev->fill(state);
1327 gfxbbox_t bbox = getBBox(state);
1328 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1329 rgbdev->fill(state);
1330 dbg_newdata("fill");
1332 void BitmapOutputDev::eoFill(GfxState *state)
1334 msg("<debug> eoFill");
1335 boolpolydev->eoFill(state);
1336 gfxbbox_t bbox = getBBox(state);
1337 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1338 rgbdev->eoFill(state);
1339 dbg_newdata("eofill");
1341 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1342 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
1343 int paintType, Dict *resDict,
1344 double *mat, double *bbox,
1345 int x0, int y0, int x1, int y1,
1346 double xStep, double yStep)
1348 msg("<debug> tilingPatternFill");
1349 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1350 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1351 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1352 dbg_newdata("tilingpatternfill");
1355 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
1356 int paintType, Dict *resDict,
1357 double *mat, double *bbox,
1358 int x0, int y0, int x1, int y1,
1359 double xStep, double yStep)
1361 msg("<debug> tilingPatternFill");
1362 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1363 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1364 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1365 dbg_newdata("tilingpatternfill");
1369 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
1371 msg("<debug> functionShadedFill");
1372 boolpolydev->functionShadedFill(state, shading);
1373 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1374 return rgbdev->functionShadedFill(state, shading);
1376 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
1378 msg("<debug> axialShadedFill");
1379 boolpolydev->axialShadedFill(state, shading);
1380 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1381 return rgbdev->axialShadedFill(state, shading);
1383 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
1385 msg("<debug> radialShadedFill");
1386 boolpolydev->radialShadedFill(state, shading);
1387 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1388 return rgbdev->radialShadedFill(state, shading);
1391 SplashColor black = {0,0,0};
1392 SplashColor white = {255,255,255};
1394 void BitmapOutputDev::clip(GfxState *state)
1396 msg("<debug> clip");
1397 boolpolydev->clip(state);
1398 booltextdev->clip(state);
1399 rgbdev->clip(state);
1400 clip1dev->clip(state);
1402 void BitmapOutputDev::eoClip(GfxState *state)
1404 msg("<debug> eoClip");
1405 boolpolydev->eoClip(state);
1406 booltextdev->eoClip(state);
1407 rgbdev->eoClip(state);
1408 clip1dev->eoClip(state);
1410 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1412 msg("<debug> clipToStrokePath");
1413 boolpolydev->clipToStrokePath(state);
1414 booltextdev->clipToStrokePath(state);
1415 rgbdev->clipToStrokePath(state);
1416 clip1dev->clipToStrokePath(state);
1419 void BitmapOutputDev::beginStringOp(GfxState *state)
1421 msg("<debug> beginStringOp");
1422 clip0dev->beginStringOp(state);
1423 clip1dev->beginStringOp(state);
1424 booltextdev->beginStringOp(state);
1425 gfxdev->beginStringOp(state);
1427 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1429 msg("<debug> beginString");
1430 clip0dev->beginString(state, s);
1431 clip1dev->beginString(state, s);
1432 booltextdev->beginString(state, s);
1433 gfxdev->beginString(state, s);
1436 void BitmapOutputDev::clearClips()
1438 clearBooleanBitmap(clip0bitmap, 0, 0, 0, 0);
1439 clearBooleanBitmap(clip1bitmap, 0, 0, 0, 0);
1441 void BitmapOutputDev::clearBoolPolyDev()
1443 clearBooleanBitmap(stalepolybitmap, 0, 0, stalepolybitmap->getWidth(), stalepolybitmap->getHeight());
1445 void BitmapOutputDev::clearBoolTextDev()
1447 clearBooleanBitmap(staletextbitmap, 0, 0, staletextbitmap->getWidth(), staletextbitmap->getHeight());
1449 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1450 double dx, double dy,
1451 double originX, double originY,
1452 CharCode code, int nBytes, Unicode *u, int uLen)
1454 msg("<debug> drawChar render=%d", state->getRender());
1456 if(state->getRender()&RENDER_CLIP) {
1457 //char is just a clipping boundary
1458 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1459 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1460 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1461 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1462 } else if(rgbbitmap != rgbdev->getBitmap()) {
1463 // we're doing softmasking or transparency grouping
1464 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1465 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1467 // we're drawing a regular char
1469 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1470 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1472 /* calculate the bbox of this character */
1473 int x1 = (int)x, x2 = (int)x+1, y1 = (int)y, y2 = (int)y+1;
1474 SplashFont*font = clip0dev->getCurrentFont();
1475 SplashPath*path = font?font->getGlyphPath(code):NULL;
1479 path->offset((SplashCoord)x, (SplashCoord)y);
1481 for(t=0;t<path->getLength();t++) {
1484 path->getPoint(t,&xx,&yy,&f);
1485 state->transform(xx,yy,&xx,&yy);
1486 if(xx<x1) x1=(int)xx;
1487 if(yy<y1) y1=(int)yy;
1488 if(xx>=x2) x2=(int)xx+1;
1489 if(yy>=y2) y2=(int)yy+1;
1491 delete(path);path=0;
1494 /* if this character is affected somehow by the various clippings (i.e., it looks
1495 different on a device without clipping), then draw it on the bitmap, not as
1497 if(clip0and1differ(x1,y1,x2,y2)) {
1498 msg("<verbose> Char %d is affected by clipping", code);
1499 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1500 checkNewBitmap(x1,y1,x2,y2);
1501 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1502 if(config_extrafontdata) {
1503 int oldrender = state->getRender();
1504 state->setRender(3); //invisible
1505 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1506 state->setRender(oldrender);
1510 /* this char is not at all affected by clipping.
1511 Now just dump out the bitmap we're currently working on, if necessary. */
1512 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1513 checkNewText(x1,y1,x2,y2);
1514 /* use polygonal output device to do the actual text handling */
1515 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1518 dbg_newdata("text");
1520 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1522 msg("<error> internal error: drawString not implemented");
1525 void BitmapOutputDev::endTextObject(GfxState *state)
1527 msg("<debug> endTextObject");
1528 rgbdev->endTextObject(state);
1529 clip0dev->endTextObject(state);
1530 clip1dev->endTextObject(state);
1531 booltextdev->endTextObject(state);
1532 /* the only thing "drawn" here is clipping */
1533 //checkNewText(UNKNOWN_BOUNDING_BOX);
1534 gfxdev->endTextObject(state);
1535 dbg_newdata("endtextobject");
1537 void BitmapOutputDev::endString(GfxState *state)
1539 msg("<debug> endString");
1540 clip0dev->endString(state);
1541 clip1dev->endString(state);
1542 booltextdev->endString(state);
1543 int render = state->getRender();
1544 if(render != RENDER_INVISIBLE && render != RENDER_FILL) {
1545 /* xpdf draws things like stroke text or fill+stroke text in the
1546 endString() method */
1547 checkNewText(UNKNOWN_BOUNDING_BOX);
1549 gfxdev->endString(state);
1550 dbg_newdata("endstring");
1552 void BitmapOutputDev::endStringOp(GfxState *state)
1554 msg("<debug> endStringOp");
1555 clip0dev->endStringOp(state);
1556 clip1dev->endStringOp(state);
1557 booltextdev->endStringOp(state);
1558 gfxdev->endStringOp(state);
1559 dbg_newdata("endstringop");
1562 /* TODO: these four operations below *should* do nothing, as type3
1563 chars are drawn using operations like fill() */
1564 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1565 double dx, double dy,
1566 CharCode code, Unicode *u, int uLen)
1568 msg("<debug> beginType3Char");
1569 /* call gfxdev so that it can generate "invisible" characters
1570 on top of the actual graphic content, for text extraction */
1571 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1573 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1575 msg("<debug> type3D0");
1576 return gfxdev->type3D0(state, wx, wy);
1578 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1580 msg("<debug> type3D1");
1581 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1583 void BitmapOutputDev::endType3Char(GfxState *state)
1585 msg("<debug> endType3Char");
1586 gfxdev->endType3Char(state);
1589 class CopyStream: public Object
1593 MemStream*memstream;
1595 CopyStream(Stream*str, int len)
1600 buf = (char*)malloc(len);
1602 for (t=0; t<len; t++)
1603 buf[t] = str->getChar();
1606 this->dict = str->getDict();
1607 this->memstream = new MemStream(buf, 0, len, this);
1611 ::free(this->buf);this->buf = 0;
1612 delete this->memstream;
1614 Dict* getDict() {return dict;}
1615 Stream* getStream() {return this->memstream;};
1618 gfxbbox_t BitmapOutputDev::getImageBBox(GfxState*state)
1622 state->transform(0, 1, &x, &y);
1623 bbox.xmin=bbox.xmax = x;
1624 bbox.ymin=bbox.ymax = y;
1625 state->transform(0, 0, &x, &y);
1626 bbox.xmin=min(bbox.xmin,x);
1627 bbox.ymin=min(bbox.ymin,y);
1628 bbox.xmax=max(bbox.xmax,x);
1629 bbox.ymax=max(bbox.ymax,y);
1630 state->transform(1, 0, &x, &y);
1631 bbox.xmin=min(bbox.xmin,x);
1632 bbox.ymin=min(bbox.ymin,y);
1633 bbox.xmax=max(bbox.xmax,x);
1634 bbox.ymax=max(bbox.ymax,y);
1635 state->transform(1, 1, &x, &y);
1636 bbox.xmin=min(bbox.xmin,x);
1637 bbox.ymin=min(bbox.ymin,y);
1638 bbox.xmax=max(bbox.xmax,x);
1639 bbox.ymax=max(bbox.ymax,y);
1642 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1643 int width, int height, GBool invert,
1646 msg("<debug> drawImageMask streamkind=%d", str->getKind());
1648 CopyStream*cpystr = new CopyStream(str, height * ((width + 7) / 8));
1649 str = cpystr->getStream();
1651 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1652 gfxbbox_t bbox = getImageBBox(state);
1653 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1654 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1656 dbg_newdata("imagemask");
1658 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1659 int width, int height, GfxImageColorMap *colorMap,
1660 int *maskColors, GBool inlineImg)
1662 msg("<debug> drawImage streamkind=%d", str->getKind());
1664 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1665 str = cpystr->getStream();
1667 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1668 gfxbbox_t bbox=getImageBBox(state);
1669 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1670 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1672 dbg_newdata("image");
1674 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1675 int width, int height,
1676 GfxImageColorMap *colorMap,
1677 Stream *maskStr, int maskWidth, int maskHeight,
1680 msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
1682 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1683 str = cpystr->getStream();
1685 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1686 gfxbbox_t bbox=getImageBBox(state);
1687 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1688 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1690 dbg_newdata("maskedimage");
1692 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1693 int width, int height,
1694 GfxImageColorMap *colorMap,
1696 int maskWidth, int maskHeight,
1697 GfxImageColorMap *maskColorMap)
1699 msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
1701 CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1702 str = cpystr->getStream();
1704 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1705 gfxbbox_t bbox=getImageBBox(state);
1706 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1707 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1709 dbg_newdata("softmaskimage");
1711 void BitmapOutputDev::drawForm(Ref id)
1713 msg("<debug> drawForm");
1714 boolpolydev->drawForm(id);
1715 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1716 rgbdev->drawForm(id);
1719 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1721 msg("<debug> processLink");
1722 gfxdev->processLink(link, catalog);
1725 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1726 GfxColorSpace *blendingColorSpace,
1727 GBool isolated, GBool knockout,
1730 msg("<debug> beginTransparencyGroup");
1731 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1732 GfxState*state1 = state->copy();
1733 GfxState*state2 = state->copy();
1735 state1->setPath(state->getPath()->copy());
1737 state2->setPath(state->getPath()->copy());
1739 GfxState*state1 = state->copy(gTrue);
1740 GfxState*state2 = state->copy(gTrue);
1742 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1743 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1744 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1747 dbg_newdata("endtransparencygroup");
1749 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1751 msg("<debug> endTransparencyGroup");
1752 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1753 GfxState*state1 = state->copy();
1754 GfxState*state2 = state->copy();
1756 state1->setPath(state->getPath()->copy());
1758 state2->setPath(state->getPath()->copy());
1760 GfxState*state1 = state->copy(gTrue);
1761 GfxState*state2 = state->copy(gTrue);
1763 boolpolydev->endTransparencyGroup(state1);
1764 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1765 rgbdev->endTransparencyGroup(state2);
1768 clip1dev->endTransparencyGroup(state);
1769 dbg_newdata("endtransparencygroup");
1771 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1773 msg("<debug> paintTransparencyGroup");
1774 boolpolydev->paintTransparencyGroup(state,bbox);
1775 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1776 rgbdev->paintTransparencyGroup(state,bbox);
1777 clip1dev->paintTransparencyGroup(state,bbox);
1778 dbg_newdata("painttransparencygroup");
1780 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1782 msg("<debug> setSoftMask");
1783 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1784 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1785 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1786 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1787 dbg_newdata("setsoftmask");
1789 void BitmapOutputDev::clearSoftMask(GfxState *state)
1791 msg("<debug> clearSoftMask");
1792 boolpolydev->clearSoftMask(state);
1793 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1794 rgbdev->clearSoftMask(state);
1795 clip1dev->clearSoftMask(state);
1796 dbg_newdata("clearsoftmask");