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);
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->booltextdev) {
107 delete this->booltextdev;this->booltextdev = 0;
110 delete this->clip0dev;this->clip0dev = 0;
113 delete this->clip1dev;this->clip1dev = 0;
115 //if(this->clipbitmap) {
116 // delete this->clipbitmap;this->clipbitmap = 0;
118 //if(this->clipdev) {
119 // delete this->clipdev;this->clipdev = 0;
124 GBool BitmapOutputDev::getVectorAntialias()
126 return this->rgbdev->getVectorAntialias();
128 void BitmapOutputDev::setVectorAntialias(GBool vaa)
130 this->rgbdev->setVectorAntialias(vaa);
132 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
136 void BitmapOutputDev::setMove(int x,int y)
138 this->gfxdev->setMove(x,y);
139 this->user_movex = x;
140 this->user_movey = y;
142 void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
144 this->gfxdev->setClip(x1,y1,x2,y2);
145 this->user_clipx1 = x1;
146 this->user_clipy1 = y1;
147 this->user_clipx2 = x2;
148 this->user_clipy2 = y2;
150 void BitmapOutputDev::setParameter(const char*key, const char*value)
152 if(!strcmp(key, "extrafontdata")) {
153 this->config_extrafontdata = atoi(value);
155 this->gfxdev->setParameter(key, value);
157 void BitmapOutputDev::setPageMap(int*page2page, int num_pages)
159 this->gfxdev->setPageMap(page2page, num_pages);
162 void writeBitmap(SplashBitmap*bitmap, char*filename);
164 void BitmapOutputDev::flushBitmap()
166 int width = rgbdev->getBitmapWidth();
167 int height = rgbdev->getBitmapHeight();
169 if(sizeof(SplashColor)!=3) {
170 msg("<error> sizeof(SplashColor)!=3");
174 /*static int counter=0;
176 writeBitmap(rgbdev->getBitmap(), "test.png");
179 SplashColorPtr rgb = rgbbitmap->getDataPtr();
180 Guchar*alpha = rgbbitmap->getAlphaPtr();
182 Guchar*alpha2 = boolpolybitmap->getDataPtr();
183 int width8 = (boolpolybitmap->getWidth()+7)/8;
185 ibbox_t* boxes = get_bitmap_bboxes((unsigned char*)alpha, width, height);
189 for(b=boxes;b;b=b->next) {
195 /* clip against (-movex, -movey, -movex+width, -movey+height) */
196 if(xmin < -this->movex) xmin = -this->movex;
197 if(ymin < -this->movey) ymin = -this->movey;
198 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
199 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
201 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
203 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
206 int rangex = xmax-xmin;
207 int rangey = ymax-ymin;
208 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
209 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
211 img->height = rangey;
213 for(y=0;y<rangey;y++) {
214 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
215 gfxcolor_t*out = &img->data[y*rangex];
216 Guchar*ain = &alpha[(y+ymin)*width+xmin];
217 Guchar*ain2 = &alpha2[(y+ymin)*width8];
218 if(this->emptypage) {
219 for(x=0;x<rangex;x++) {
220 /* the first bitmap on the page doesn't need to have an alpha channel-
221 blend against a white background*/
222 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
223 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
224 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
228 for(x=0;x<rangex;x++) {
229 if(!(ain2[(x+xmin)/8]&(0x80>>(x&7)))) {
230 /* cut away pixels that we don't remember drawing (i.e., that are
231 not in the monochrome bitmap. Prevents some "hairlines" showing
232 up to the left and right of bitmaps */
233 out[x].r = 0;out[x].g = 0;out[x].b = 0;out[x].a = 0;
235 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we
236 have to premultiply alpha (mix background and pixel according to the alpha channel).
238 out[x].r = (in[x*3+0]*ain[x])/255;
239 out[x].g = (in[x*3+1]*ain[x])/255;
240 out[x].b = (in[x*3+2]*ain[x])/255;
247 /* transform bitmap rectangle to "device space" */
261 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
262 dev->fillbitmap(dev, line, img, &m, 0);
265 free(img->data);img->data=0;free(img);img=0;
267 ibbox_destroy(boxes);
269 memset(rgbbitmap->getAlphaPtr(), 0, rgbbitmap->getWidth()*rgbbitmap->getHeight());
270 memset(rgbbitmap->getDataPtr(), 0, rgbbitmap->getRowSize()*rgbbitmap->getHeight());
275 void BitmapOutputDev::flushText()
277 msg("<verbose> Flushing text/polygons");
278 gfxdevice_record_flush(this->gfxoutput, this->dev);
283 void writeMonoBitmap(SplashBitmap*btm, char*filename)
285 int width8 = (btm->getWidth()+7)/8;
286 int width = btm->getWidth();
287 int height = btm->getHeight();
288 gfxcolor_t*b = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
289 unsigned char*data = btm->getDataPtr();
291 for(y=0;y<height;y++) {
292 unsigned char*l = &data[width8*y];
293 gfxcolor_t*d = &b[width*y];
294 for(x=0;x<width;x++) {
295 if(l[x>>3]&(128>>(x&7))) {
296 d[x].r = d[x].g = d[x].b = 255;
298 d[x].r = d[x].g = d[x].b = 0;
303 writePNG(filename, (unsigned char*)b, width, height);
307 void writeBitmap(SplashBitmap*bitmap, char*filename)
311 int width = bitmap->getWidth();
312 int height = bitmap->getHeight();
314 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
316 if(bitmap->getMode()==splashModeMono1) {
317 writeMonoBitmap(bitmap, filename);
321 for(y=0;y<height;y++) {
322 gfxcolor_t*line = &data[y*width];
323 for(x=0;x<width;x++) {
324 Guchar c[4] = {0,0,0,0};
325 bitmap->getPixel(x,y,c);
329 line[x].a = bitmap->getAlpha(x,y);
332 writePNG(filename, (unsigned char*)data, width, height);
336 void writeAlpha(SplashBitmap*bitmap, char*filename)
340 int width = bitmap->getWidth();
341 int height = bitmap->getHeight();
343 if(bitmap->getMode()==splashModeMono1) {
344 writeMonoBitmap(bitmap, filename);
348 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
350 for(y=0;y<height;y++) {
351 gfxcolor_t*line = &data[y*width];
352 for(x=0;x<width;x++) {
353 int a = bitmap->getAlpha(x,y);
360 writePNG(filename, (unsigned char*)data, width, height);
363 static int dbg_btm_counter=1;
365 static const char*STATE_NAME[] = {"parallel", "textabovebitmap", "bitmapabovetext"};
367 int checkAlphaSanity(SplashBitmap*boolbtm, SplashBitmap*alphabtm)
369 assert(boolbtm->getWidth() == alphabtm->getWidth());
370 assert(boolbtm->getHeight() == alphabtm->getHeight());
371 if(boolbtm->getMode()==splashModeMono1) {
375 int width = boolbtm->getWidth();
376 int height = boolbtm->getHeight();
380 for(y=0;y<height;y++) {
381 for(x=0;x<width;x++) {
382 int a1 = alphabtm->getAlpha(x,y);
383 int a2 = boolbtm->getAlpha(x,y);
389 double badness = bad/(double)(width*height);
391 msg("<error> Bitmaps don't correspond: %d out of %d pixels wrong (%.2f%%)", bad, width*height,
395 msg("<notice> %f", badness);
399 GBool BitmapOutputDev::checkNewText(int x1, int y1, int x2, int y2)
401 /* called once some new text was drawn on booltextdev, and
402 before the same thing is drawn on gfxdev */
404 msg("<trace> Testing new text data against current bitmap data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
410 sprintf(filename1, "state%dboolbitmap_afternewtext.png", dbg_btm_counter);
411 sprintf(filename2, "state%dbooltext_afternewtext.png", dbg_btm_counter);
412 sprintf(filename3, "state%dbitmap_afternewtext.png", dbg_btm_counter);
413 msg("<verbose> %s %s %s", filename1, filename2, filename3);
414 writeAlpha(boolpolybitmap, filename1);
415 writeAlpha(booltextbitmap, filename2);
416 writeBitmap(rgbdev->getBitmap(), filename3);
421 if(intersection(x1,y1,x2,y2)) {
422 if(layerstate==STATE_PARALLEL) {
423 /* the new text is above the bitmap. So record that fact,
424 and also clear the bitmap buffer, so we can check for
426 msg("<verbose> Text is above current bitmap/polygon data");
427 layerstate=STATE_TEXT_IS_ABOVE;
428 clearBoolPolyDev(x1,y1,x2,y2);
429 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
430 /* there's a bitmap above the (old) text. So we need
431 to flush out that text, and record that the *new*
432 text is now *above* the bitmap
434 msg("<verbose> Text is above current bitmap/polygon data (which is above some other text)");
436 layerstate=STATE_TEXT_IS_ABOVE;
437 /* clear both bool devices- the text device because
438 we just dumped out all the (old) text, and the
439 poly dev so we can check for new intersections */
440 clearBoolPolyDev(x1,y1,x2,y2);
441 /* FIXME this destroys the text pixels we just
442 drew to test for the intersection- however we need
443 those to check for the *new* intersections */
444 clearBoolTextDev(x1,y1,x2,y2);
447 /* we already know that the current text section is
448 above the current bitmap section- now just new
449 bitmap data *and* new text data was drawn, and
450 *again* it's above the current bitmap- so clear
451 the polygon bitmap again, so we can check for
453 msg("<verbose> Text is still above current bitmap/polygon data");
454 clearBoolPolyDev(x1,y1,x2,y2);
460 GBool BitmapOutputDev::checkNewBitmap(int x1, int y1, int x2, int y2)
462 /* similar to checkNewText() above, only in reverse */
463 msg("<trace> Testing new graphics data against current text data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
469 sprintf(filename1, "state%dboolbitmap_afternewgfx.png", dbg_btm_counter);
470 sprintf(filename2, "state%dbooltext_afternewgfx.png", dbg_btm_counter);
471 sprintf(filename3, "state%dbitmap_afternewgfx.png", dbg_btm_counter);
472 msg("<verbose> %s %s %s", filename1, filename2, filename3);
473 writeAlpha(boolpolybitmap, filename1);
474 writeAlpha(booltextbitmap, filename2);
475 writeBitmap(rgbdev->getBitmap(), filename3);
480 if(intersection(x1,y1,x2,y2)) {
481 if(layerstate==STATE_PARALLEL) {
482 msg("<verbose> Bitmap is above current text data");
483 layerstate=STATE_BITMAP_IS_ABOVE;
484 clearBoolTextDev(x1,y1,x2,y2);
485 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
486 msg("<verbose> Bitmap is above current text data (which is above some bitmap)");
488 layerstate=STATE_BITMAP_IS_ABOVE;
489 clearBoolTextDev(x1,y1,x2,y2);
490 /* FIXME this destroys the polygon pixels we just
491 drew to test for the intersection- however we need
492 those to check for the *new* intersections */
493 clearBoolPolyDev(x1,y1,x2,y2);
496 msg("<verbose> Bitmap is still above current text data");
497 clearBoolTextDev(x1,y1,x2,y2);
503 //void checkNewText() {
504 // Guchar*alpha = rgbbitmap->getAlphaPtr();
505 // Guchar*charpixels = clip1bitmap->getDataPtr();
507 // for(yy=0;yy<height;yy++) {
508 // Guchar*aline = &alpha[yy*width];
509 // Guchar*cline = &charpixels[yy*width8];
510 // for(xx=0;xx<width;xx++) {
512 // int bytepos = xx>>3;
513 // /* TODO: is the bit order correct? */
514 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
521 static inline GBool fixBBox(int*x1, int*y1, int*x2, int*y2, int width, int height)
523 if(!(*x1|*y1|*x2|*y2)) {
530 if(*x2<=*x1) return gFalse;
531 if(*x2<0) return gFalse;
533 if(*x1>=width) return gFalse;
534 if(*x2>width) *x2=width;
536 if(*y2<=*y1) return gFalse;
537 if(*y2<0) return gFalse;
539 if(*y1>=height) return gFalse;
540 if(*y2>height) *y2=height;
544 GBool BitmapOutputDev::clip0and1differ(int x1,int y1,int x2,int y2)
546 if(clip0bitmap->getMode()==splashModeMono1) {
547 int width = clip0bitmap->getWidth();
548 int width8 = (width+7)/8;
549 int height = clip0bitmap->getHeight();
551 if(!fixBBox(&x1,&y1,&x2,&y2,width,height)) {
552 /* area is outside or null */
556 SplashBitmap*clip0 = clip0bitmap;
557 SplashBitmap*clip1 = clip1bitmap;
563 unsigned char*row1 = &clip0bitmap->getDataPtr()[width8*y+x18];
564 unsigned char*row2 = &clip1bitmap->getDataPtr()[width8*y+x18];
565 if(memcmp(row1, row2, x28-x18)) {
571 SplashBitmap*clip0 = clip0bitmap;
572 SplashBitmap*clip1 = clip1bitmap;
573 int width = clip0->getAlphaRowSize();
574 int height = clip0->getHeight();
576 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
580 Guchar*a0 = clip0->getAlphaPtr();
581 Guchar*a1 = clip1->getAlphaPtr();
586 if(a0[y*width+x]!=a1[y*width+x]) {
594 char differs2 = memcmp(a0, a1, width*height);
595 if(differs && !differs2)
596 msg("<warning> Strange internal error (2)");
597 else if(!differs && differs2) {
598 msg("<warning> Bad Bounding Box: Difference in clip0 and clip1 outside bbox");
599 msg("<warning> %d %d %d %d", x1, y1, x2, y2);
605 static void clearBooleanBitmap(SplashBitmap*btm, int x1, int y1, int x2, int y2)
609 x2 = btm->getWidth();
610 y2 = btm->getHeight();
612 if(btm->getMode()==splashModeMono1) {
613 int width8 = (btm->getWidth()+7)/8;
614 int width = btm->getWidth();
615 int height = btm->getHeight();
616 memset(btm->getDataPtr(), 0, width8*height);
618 int width = btm->getAlphaRowSize();
619 int height = btm->getHeight();
620 memset(btm->getAlphaPtr(), 0, width*height);
624 GBool compare8(unsigned char*data1, unsigned char*data2, int len)
628 if(((ptroff_t)data1&7)==((ptroff_t)data2&7)) {
629 // oh good, we can do aligning
630 while((ptroff_t)data1&7) {
639 /* use 64 bit for the (hopefully aligned) middle section */
641 long long unsigned int*d1 = (long long unsigned int*)data1;
642 long long unsigned int*d2 = (long long unsigned int*)data2;
643 long long unsigned int x = 0;
655 if(data1[t]&data2[t]) {
662 GBool BitmapOutputDev::intersection(int x1, int y1, int x2, int y2)
664 SplashBitmap*boolpoly = boolpolybitmap;
665 SplashBitmap*booltext = booltextbitmap;
667 if(boolpoly->getMode()==splashModeMono1) {
668 /* alternative implementation, using one bit per pixel-
669 needs the no-dither patch in xpdf */
671 int width = boolpoly->getWidth();
672 int height = boolpoly->getHeight();
674 if(!fixBBox(&x1,&y1,&x2,&y2, width, height)) {
678 Guchar*polypixels = boolpoly->getDataPtr();
679 Guchar*textpixels = booltext->getDataPtr();
681 int width8 = (width+7)/8;
686 polypixels+=y1*width8+x1/8;
687 textpixels+=y1*width8+x1/8;
688 runx=(x2+7)/8 - x1/8;
695 /*assert(sizeof(unsigned long long int)==8);
696 if(((ptroff_t)polypixels&7) || ((ptroff_t)textpixels&7)) {
697 //msg("<warning> Non-optimal alignment");
701 unsigned char*data1 = (unsigned char*)polypixels;
702 unsigned char*data2 = (unsigned char*)textpixels;
703 msg("<verbose> Testing area (%d,%d,%d,%d), runx=%d,runy=%d", x1,y1,x2,y2, runx, runy);
704 for(y=0;y<runy;y++) {
705 if(compare8(data1,data2,runx))
712 int width = boolpoly->getAlphaRowSize();
713 int height = boolpoly->getHeight();
715 if(!fixBBox(&x1, &y1, &x2, &y2, width, height)) {
718 Guchar*polypixels = boolpoly->getAlphaPtr();
719 Guchar*textpixels = booltext->getAlphaPtr();
726 if(polypixels[width*y+x]&&textpixels[width*y+x])
730 int ax1=0,ay1=0,ax2=0,ay2=0;
731 for(y=0;y<height;y++) {
732 for(x=0;x<width;x++) {
733 if(polypixels[width*y+x]&&textpixels[width*y+x]) {
735 if(!(ax1|ay1|ax2|ay2)) {
747 if(overlap1 && !overlap2)
748 msg("<warning> strange internal error");
749 if(!overlap1 && overlap2) {
750 msg("<warning> Bad bounding box: intersection outside bbox");
751 msg("<warning> given bbox: %d %d %d %d", x1, y1, x2, y2);
752 msg("<warning> changed area: %d %d %d %d", ax1, ay1, ax2, ay2);
753 //writeAlpha(booltextbitmap, "alpha.png");
760 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
763 state->transform(crop_x1,crop_y1,&x1,&y1);
764 state->transform(crop_x2,crop_y2,&x2,&y2);
765 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
766 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
768 this->movex = -(int)x1 - user_movex;
769 this->movey = -(int)y1 - user_movey;
771 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
777 this->width = (int)(x2-x1);
778 this->height = (int)(y2-y1);
780 msg("<debug> startPage");
781 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
782 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
783 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
784 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
785 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
786 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
788 boolpolybitmap = boolpolydev->getBitmap();
789 booltextbitmap = booltextdev->getBitmap();
790 clip0bitmap = clip0dev->getBitmap();
791 clip1bitmap = clip1dev->getBitmap();
792 rgbbitmap = rgbdev->getBitmap();
794 flushText(); // write out the initial clipping rectangle
796 /* just in case any device did draw a white background rectangle
798 clearBoolTextDev(UNKNOWN_BOUNDING_BOX);
799 clearBoolPolyDev(UNKNOWN_BOUNDING_BOX);
801 this->layerstate = STATE_PARALLEL;
803 msg("<debug> startPage done");
806 void BitmapOutputDev::endPage()
808 msg("<verbose> endPage (BitmapOutputDev)");
810 /* notice: we're not fully done yet with this page- there might still be
811 a few calls to drawLink() yet to come */
813 void BitmapOutputDev::finishPage()
815 msg("<verbose> finishPage (BitmapOutputDev)");
818 if(layerstate == STATE_BITMAP_IS_ABOVE) {
826 /* splash will now destroy alpha, and paint the
827 background color into the "holes" in the bitmap */
828 boolpolydev->endPage();
829 booltextdev->endPage();
835 GBool BitmapOutputDev::upsideDown()
837 boolpolydev->upsideDown();
838 booltextdev->upsideDown();
839 clip0dev->upsideDown();
840 clip1dev->upsideDown();
841 return rgbdev->upsideDown();
844 GBool BitmapOutputDev::useDrawChar()
846 boolpolydev->useDrawChar();
847 booltextdev->useDrawChar();
848 clip0dev->useDrawChar();
849 clip1dev->useDrawChar();
850 return rgbdev->useDrawChar();
853 GBool BitmapOutputDev::useTilingPatternFill()
855 boolpolydev->useTilingPatternFill();
856 booltextdev->useTilingPatternFill();
857 clip0dev->useTilingPatternFill();
858 clip1dev->useTilingPatternFill();
859 return rgbdev->useTilingPatternFill();
862 GBool BitmapOutputDev::useShadedFills()
864 boolpolydev->useShadedFills();
865 booltextdev->useShadedFills();
866 clip0dev->useShadedFills();
867 clip1dev->useShadedFills();
868 return rgbdev->useShadedFills();
871 GBool BitmapOutputDev::useDrawForm()
873 boolpolydev->useDrawForm();
874 booltextdev->useDrawForm();
875 clip0dev->useDrawForm();
876 clip1dev->useDrawForm();
877 return rgbdev->useDrawForm();
880 GBool BitmapOutputDev::interpretType3Chars()
882 boolpolydev->interpretType3Chars();
883 booltextdev->interpretType3Chars();
884 clip0dev->interpretType3Chars();
885 clip1dev->interpretType3Chars();
886 return rgbdev->interpretType3Chars();
889 GBool BitmapOutputDev::needNonText()
891 boolpolydev->needNonText();
892 booltextdev->needNonText();
893 clip0dev->needNonText();
894 clip1dev->needNonText();
895 return rgbdev->needNonText();
897 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
898 int rotate, GBool useMediaBox, GBool crop,
899 int sliceX, int sliceY, int sliceW, int sliceH,
900 GBool printing, Catalog *catalog,
901 GBool (*abortCheckCbk)(void *data),
902 void *abortCheckCbkData)
906 void BitmapOutputDev::setDefaultCTM(double *ctm)
908 boolpolydev->setDefaultCTM(ctm);
909 booltextdev->setDefaultCTM(ctm);
910 rgbdev->setDefaultCTM(ctm);
911 clip0dev->setDefaultCTM(ctm);
912 clip1dev->setDefaultCTM(ctm);
913 gfxdev->setDefaultCTM(ctm);
915 void BitmapOutputDev::saveState(GfxState *state)
917 boolpolydev->saveState(state);
918 booltextdev->saveState(state);
919 rgbdev->saveState(state);
920 clip0dev->saveState(state);
921 clip1dev->saveState(state);
923 /*ClipState*cstate = new ClipState();
924 cstate->next = this->clipstates;
925 this->clipstates = cstate;*/
927 void BitmapOutputDev::restoreState(GfxState *state)
929 boolpolydev->restoreState(state);
930 booltextdev->restoreState(state);
931 rgbdev->restoreState(state);
932 clip0dev->restoreState(state);
933 clip1dev->restoreState(state);
935 /*if(this->clipstates) {
936 ClipState*old = this->clipstates;
938 gfxdev->restoreState(state);
940 this->clipstates = this->clipstates->next;
943 msg("<error> invalid restoreState()");
946 void BitmapOutputDev::updateAll(GfxState *state)
948 boolpolydev->updateAll(state);
949 booltextdev->updateAll(state);
950 rgbdev->updateAll(state);
951 clip0dev->updateAll(state);
952 clip1dev->updateAll(state);
953 gfxdev->updateAll(state);
955 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
957 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
958 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
959 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
960 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
961 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
962 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
964 void BitmapOutputDev::updateLineDash(GfxState *state)
966 boolpolydev->updateLineDash(state);
967 booltextdev->updateLineDash(state);
968 rgbdev->updateLineDash(state);
969 clip0dev->updateLineDash(state);
970 clip1dev->updateLineDash(state);
971 gfxdev->updateLineDash(state);
973 void BitmapOutputDev::updateFlatness(GfxState *state)
975 boolpolydev->updateFlatness(state);
976 booltextdev->updateFlatness(state);
977 rgbdev->updateFlatness(state);
978 clip0dev->updateFlatness(state);
979 clip1dev->updateFlatness(state);
980 gfxdev->updateFlatness(state);
982 void BitmapOutputDev::updateLineJoin(GfxState *state)
984 boolpolydev->updateLineJoin(state);
985 booltextdev->updateLineJoin(state);
986 rgbdev->updateLineJoin(state);
987 clip0dev->updateLineJoin(state);
988 clip1dev->updateLineJoin(state);
989 gfxdev->updateLineJoin(state);
991 void BitmapOutputDev::updateLineCap(GfxState *state)
993 boolpolydev->updateLineCap(state);
994 booltextdev->updateLineCap(state);
995 rgbdev->updateLineCap(state);
996 clip0dev->updateLineCap(state);
997 clip1dev->updateLineCap(state);
998 gfxdev->updateLineCap(state);
1000 void BitmapOutputDev::updateMiterLimit(GfxState *state)
1002 boolpolydev->updateMiterLimit(state);
1003 booltextdev->updateMiterLimit(state);
1004 rgbdev->updateMiterLimit(state);
1005 clip0dev->updateMiterLimit(state);
1006 clip1dev->updateMiterLimit(state);
1007 gfxdev->updateMiterLimit(state);
1009 void BitmapOutputDev::updateLineWidth(GfxState *state)
1011 boolpolydev->updateLineWidth(state);
1012 booltextdev->updateLineWidth(state);
1013 rgbdev->updateLineWidth(state);
1014 clip0dev->updateLineWidth(state);
1015 clip1dev->updateLineWidth(state);
1016 gfxdev->updateLineWidth(state);
1018 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
1020 boolpolydev->updateStrokeAdjust(state);
1021 booltextdev->updateStrokeAdjust(state);
1022 rgbdev->updateStrokeAdjust(state);
1023 clip0dev->updateStrokeAdjust(state);
1024 clip1dev->updateStrokeAdjust(state);
1025 gfxdev->updateStrokeAdjust(state);
1027 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
1029 boolpolydev->updateFillColorSpace(state);
1030 booltextdev->updateFillColorSpace(state);
1031 rgbdev->updateFillColorSpace(state);
1032 clip0dev->updateFillColorSpace(state);
1033 clip1dev->updateFillColorSpace(state);
1034 gfxdev->updateFillColorSpace(state);
1036 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
1038 boolpolydev->updateStrokeColorSpace(state);
1039 booltextdev->updateStrokeColorSpace(state);
1040 rgbdev->updateStrokeColorSpace(state);
1041 clip0dev->updateStrokeColorSpace(state);
1042 clip1dev->updateStrokeColorSpace(state);
1043 gfxdev->updateStrokeColorSpace(state);
1045 void BitmapOutputDev::updateFillColor(GfxState *state)
1047 boolpolydev->updateFillColor(state);
1048 booltextdev->updateFillColor(state);
1049 rgbdev->updateFillColor(state);
1050 clip0dev->updateFillColor(state);
1051 clip1dev->updateFillColor(state);
1052 gfxdev->updateFillColor(state);
1054 void BitmapOutputDev::updateStrokeColor(GfxState *state)
1056 boolpolydev->updateStrokeColor(state);
1057 booltextdev->updateStrokeColor(state);
1058 rgbdev->updateStrokeColor(state);
1059 clip0dev->updateStrokeColor(state);
1060 clip1dev->updateStrokeColor(state);
1061 gfxdev->updateStrokeColor(state);
1063 void BitmapOutputDev::updateBlendMode(GfxState *state)
1065 boolpolydev->updateBlendMode(state);
1066 booltextdev->updateBlendMode(state);
1067 rgbdev->updateBlendMode(state);
1068 clip0dev->updateBlendMode(state);
1069 clip1dev->updateBlendMode(state);
1070 gfxdev->updateBlendMode(state);
1072 void BitmapOutputDev::updateFillOpacity(GfxState *state)
1074 boolpolydev->updateFillOpacity(state);
1075 booltextdev->updateFillOpacity(state);
1076 rgbdev->updateFillOpacity(state);
1077 clip0dev->updateFillOpacity(state);
1078 clip1dev->updateFillOpacity(state);
1079 gfxdev->updateFillOpacity(state);
1081 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
1083 boolpolydev->updateStrokeOpacity(state);
1084 booltextdev->updateStrokeOpacity(state);
1085 rgbdev->updateStrokeOpacity(state);
1086 clip0dev->updateStrokeOpacity(state);
1087 clip1dev->updateStrokeOpacity(state);
1088 gfxdev->updateStrokeOpacity(state);
1090 void BitmapOutputDev::updateFillOverprint(GfxState *state)
1092 boolpolydev->updateFillOverprint(state);
1093 booltextdev->updateFillOverprint(state);
1094 rgbdev->updateFillOverprint(state);
1095 clip0dev->updateFillOverprint(state);
1096 clip1dev->updateFillOverprint(state);
1097 gfxdev->updateFillOverprint(state);
1099 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
1101 boolpolydev->updateStrokeOverprint(state);
1102 booltextdev->updateStrokeOverprint(state);
1103 rgbdev->updateStrokeOverprint(state);
1104 clip0dev->updateStrokeOverprint(state);
1105 clip1dev->updateStrokeOverprint(state);
1106 gfxdev->updateStrokeOverprint(state);
1108 void BitmapOutputDev::updateTransfer(GfxState *state)
1110 boolpolydev->updateTransfer(state);
1111 booltextdev->updateTransfer(state);
1112 rgbdev->updateTransfer(state);
1113 clip0dev->updateTransfer(state);
1114 clip1dev->updateTransfer(state);
1115 gfxdev->updateTransfer(state);
1118 void BitmapOutputDev::updateFont(GfxState *state)
1120 boolpolydev->updateFont(state);
1121 booltextdev->updateFont(state);
1122 rgbdev->updateFont(state);
1123 clip0dev->updateFont(state);
1124 clip1dev->updateFont(state);
1125 gfxdev->updateFont(state);
1127 void BitmapOutputDev::updateTextMat(GfxState *state)
1129 boolpolydev->updateTextMat(state);
1130 booltextdev->updateTextMat(state);
1131 rgbdev->updateTextMat(state);
1132 clip0dev->updateTextMat(state);
1133 clip1dev->updateTextMat(state);
1134 gfxdev->updateTextMat(state);
1136 void BitmapOutputDev::updateCharSpace(GfxState *state)
1138 boolpolydev->updateCharSpace(state);
1139 booltextdev->updateCharSpace(state);
1140 rgbdev->updateCharSpace(state);
1141 clip0dev->updateCharSpace(state);
1142 clip1dev->updateCharSpace(state);
1143 gfxdev->updateCharSpace(state);
1145 void BitmapOutputDev::updateRender(GfxState *state)
1147 boolpolydev->updateRender(state);
1148 booltextdev->updateRender(state);
1149 rgbdev->updateRender(state);
1150 clip0dev->updateRender(state);
1151 clip1dev->updateRender(state);
1152 gfxdev->updateRender(state);
1154 void BitmapOutputDev::updateRise(GfxState *state)
1156 boolpolydev->updateRise(state);
1157 booltextdev->updateRise(state);
1158 rgbdev->updateRise(state);
1159 clip0dev->updateRise(state);
1160 clip1dev->updateRise(state);
1161 gfxdev->updateRise(state);
1163 void BitmapOutputDev::updateWordSpace(GfxState *state)
1165 boolpolydev->updateWordSpace(state);
1166 booltextdev->updateWordSpace(state);
1167 rgbdev->updateWordSpace(state);
1168 clip0dev->updateWordSpace(state);
1169 clip1dev->updateWordSpace(state);
1170 gfxdev->updateWordSpace(state);
1172 void BitmapOutputDev::updateHorizScaling(GfxState *state)
1174 boolpolydev->updateHorizScaling(state);
1175 booltextdev->updateHorizScaling(state);
1176 rgbdev->updateHorizScaling(state);
1177 clip0dev->updateHorizScaling(state);
1178 clip1dev->updateHorizScaling(state);
1179 gfxdev->updateHorizScaling(state);
1181 void BitmapOutputDev::updateTextPos(GfxState *state)
1183 boolpolydev->updateTextPos(state);
1184 booltextdev->updateTextPos(state);
1185 rgbdev->updateTextPos(state);
1186 clip0dev->updateTextPos(state);
1187 clip1dev->updateTextPos(state);
1188 gfxdev->updateTextPos(state);
1190 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
1192 boolpolydev->updateTextShift(state, shift);
1193 booltextdev->updateTextShift(state, shift);
1194 rgbdev->updateTextShift(state, shift);
1195 clip0dev->updateTextShift(state, shift);
1196 clip1dev->updateTextShift(state, shift);
1197 gfxdev->updateTextShift(state, shift);
1200 double max(double x, double y)
1204 double min(double x, double y)
1209 gfxbbox_t BitmapOutputDev::getBBox(GfxState*state)
1211 GfxPath * path = state->getPath();
1212 int num = path->getNumSubpaths();
1213 gfxbbox_t bbox = {0,0,1,1};
1216 for(t = 0; t < num; t++) {
1217 GfxSubpath *subpath = path->getSubpath(t);
1218 int subnum = subpath->getNumPoints();
1220 for(s=0;s<subnum;s++) {
1222 state->transform(subpath->getX(s),subpath->getY(s),&x,&y);
1224 bbox.xmin = x; bbox.ymin = y;
1225 bbox.xmax = x; bbox.ymax = y;
1228 bbox.xmin = min(bbox.xmin, x);
1229 bbox.ymin = min(bbox.ymin, y);
1230 bbox.xmax = max(bbox.xmax, x);
1231 bbox.ymax = max(bbox.ymax, y);
1238 void BitmapOutputDev::stroke(GfxState *state)
1240 msg("<debug> stroke");
1241 boolpolydev->stroke(state);
1242 gfxbbox_t bbox = getBBox(state);
1243 double width = state->getTransformedLineWidth();
1244 bbox.xmin -= width; bbox.ymin -= width;
1245 bbox.xmax += width; bbox.ymax += width;
1246 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1247 rgbdev->stroke(state);
1249 void BitmapOutputDev::fill(GfxState *state)
1251 msg("<debug> fill");
1252 boolpolydev->fill(state);
1253 gfxbbox_t bbox = getBBox(state);
1254 if(checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax))) {
1255 boolpolydev->fill(state);
1257 rgbdev->fill(state);
1259 void BitmapOutputDev::eoFill(GfxState *state)
1261 msg("<debug> eoFill");
1262 boolpolydev->eoFill(state);
1263 gfxbbox_t bbox = getBBox(state);
1264 if(checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax))) {
1265 boolpolydev->eoFill(state);
1267 rgbdev->eoFill(state);
1269 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1270 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
1271 int paintType, Dict *resDict,
1272 double *mat, double *bbox,
1273 int x0, int y0, int x1, int y1,
1274 double xStep, double yStep)
1276 msg("<debug> tilingPatternFill");
1277 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1278 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1279 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1282 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
1283 int paintType, Dict *resDict,
1284 double *mat, double *bbox,
1285 int x0, int y0, int x1, int y1,
1286 double xStep, double yStep)
1288 msg("<debug> tilingPatternFill");
1289 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1290 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1291 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1295 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
1297 msg("<debug> functionShadedFill");
1298 boolpolydev->functionShadedFill(state, shading);
1299 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1300 return rgbdev->functionShadedFill(state, shading);
1302 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
1304 msg("<debug> axialShadedFill");
1305 boolpolydev->axialShadedFill(state, shading);
1306 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1307 return rgbdev->axialShadedFill(state, shading);
1309 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
1311 msg("<debug> radialShadedFill");
1312 boolpolydev->radialShadedFill(state, shading);
1313 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1314 return rgbdev->radialShadedFill(state, shading);
1317 SplashColor black = {0,0,0};
1318 SplashColor white = {255,255,255};
1320 void BitmapOutputDev::clip(GfxState *state)
1322 msg("<debug> clip");
1323 boolpolydev->clip(state);
1324 booltextdev->clip(state);
1325 rgbdev->clip(state);
1326 clip1dev->clip(state);
1328 void BitmapOutputDev::eoClip(GfxState *state)
1330 msg("<debug> eoClip");
1331 boolpolydev->eoClip(state);
1332 booltextdev->eoClip(state);
1333 rgbdev->eoClip(state);
1334 clip1dev->eoClip(state);
1336 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1338 msg("<debug> clipToStrokePath");
1339 boolpolydev->clipToStrokePath(state);
1340 booltextdev->clipToStrokePath(state);
1341 rgbdev->clipToStrokePath(state);
1342 clip1dev->clipToStrokePath(state);
1345 void BitmapOutputDev::beginStringOp(GfxState *state)
1347 msg("<debug> beginStringOp");
1348 clip0dev->beginStringOp(state);
1349 clip1dev->beginStringOp(state);
1350 booltextdev->beginStringOp(state);
1351 gfxdev->beginStringOp(state);
1353 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1355 msg("<debug> beginString");
1356 clip0dev->beginString(state, s);
1357 clip1dev->beginString(state, s);
1358 booltextdev->beginString(state, s);
1359 gfxdev->beginString(state, s);
1362 void BitmapOutputDev::clearClips()
1364 clearBooleanBitmap(clip0bitmap, 0, 0, 0, 0);
1365 clearBooleanBitmap(clip1bitmap, 0, 0, 0, 0);
1367 void BitmapOutputDev::clearBoolPolyDev(int x1, int y1, int x2, int y2)
1369 clearBooleanBitmap(boolpolybitmap, x1, y1, x2, y2);
1371 void BitmapOutputDev::clearBoolTextDev(int x1, int y1, int x2, int y2)
1373 clearBooleanBitmap(booltextbitmap, x1, y1, x2, y2);
1375 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1376 double dx, double dy,
1377 double originX, double originY,
1378 CharCode code, int nBytes, Unicode *u, int uLen)
1380 msg("<debug> drawChar render=%d", state->getRender());
1382 if(state->getRender()&RENDER_CLIP) {
1383 //char is just a clipping boundary
1384 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1385 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1386 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1387 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1388 } else if(rgbbitmap != rgbdev->getBitmap()) {
1389 // we're doing softmasking or transparency grouping
1390 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1391 //checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1392 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1394 // we're drawing a regular char
1396 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1397 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1399 /* calculate the bbox of this character */
1400 int x1 = (int)x, x2 = (int)x+1, y1 = (int)y, y2 = (int)y+1;
1401 SplashFont*font = clip0dev->getCurrentFont();
1402 SplashPath*path = font?font->getGlyphPath(code):NULL;
1406 msg("<error> couldn't create outline for char %d", code);
1411 path->offset((SplashCoord)x, (SplashCoord)y);
1413 for(t=0;t<path->getLength();t++) {
1416 path->getPoint(t,&xx,&yy,&f);
1417 state->transform(xx,yy,&xx,&yy);
1418 if(xx<x1) x1=(int)xx;
1419 if(yy<y1) y1=(int)yy;
1420 if(xx>=x2) x2=(int)xx+1;
1421 if(yy>=y2) y2=(int)yy+1;
1424 /* if this character is affected somehow by the various clippings (i.e., it looks
1425 different on a device without clipping), then draw it on the bitmap, not as
1427 if(clip0and1differ(x1,y1,x2,y2)) {
1428 msg("<verbose> Char %d is affected by clipping", code);
1429 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1430 checkNewBitmap(x1,y1,x2,y2);
1431 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1432 if(config_extrafontdata) {
1433 int oldrender = state->getRender();
1434 state->setRender(3); //invisible
1435 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1436 state->setRender(oldrender);
1440 /* this char is not at all affected by clipping.
1441 Now just dump out the bitmap we're currently working on, if necessary. */
1442 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1443 checkNewText(x1,y1,x2,y2);
1444 /* use polygonal output device to do the actual text handling */
1445 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1449 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1451 msg("<error> internal error: drawString not implemented");
1453 clip0dev->drawString(state, s);
1454 clip1dev->drawString(state, s);
1455 booltextdev->drawString(state, s);
1456 gfxdev->drawString(state, s);
1458 void BitmapOutputDev::endTextObject(GfxState *state)
1460 msg("<debug> endTextObject");
1461 rgbdev->endTextObject(state);
1462 clip0dev->endTextObject(state);
1463 clip1dev->endTextObject(state);
1464 booltextdev->endTextObject(state);
1465 /* the only thing "drawn" here is clipping */
1466 //checkNewText(UNKNOWN_BOUNDING_BOX);
1467 gfxdev->endTextObject(state);
1469 void BitmapOutputDev::endString(GfxState *state)
1471 msg("<debug> endString");
1472 clip0dev->endString(state);
1473 clip1dev->endString(state);
1474 booltextdev->endString(state);
1475 int render = state->getRender();
1476 if(render != RENDER_INVISIBLE && render != RENDER_FILL) {
1477 checkNewText(UNKNOWN_BOUNDING_BOX);
1479 gfxdev->endString(state);
1481 void BitmapOutputDev::endStringOp(GfxState *state)
1483 msg("<debug> endStringOp");
1484 clip0dev->endStringOp(state);
1485 clip1dev->endStringOp(state);
1486 booltextdev->endStringOp(state);
1487 gfxdev->endStringOp(state);
1490 /* TODO: these four operations below *should* do nothing, as type3
1491 chars are drawn using operations like fill() */
1492 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1493 double dx, double dy,
1494 CharCode code, Unicode *u, int uLen)
1496 msg("<debug> beginType3Char");
1497 /* call gfxdev so that it can generate "invisible" characters
1498 on top of the actual graphic content, for text extraction */
1499 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1501 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1503 msg("<debug> type3D0");
1504 return gfxdev->type3D0(state, wx, wy);
1506 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1508 msg("<debug> type3D1");
1509 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1511 void BitmapOutputDev::endType3Char(GfxState *state)
1513 msg("<debug> endType3Char");
1514 gfxdev->endType3Char(state);
1517 class CopyStream: public Object
1521 MemStream*memstream;
1523 CopyStream(Stream*str, int len)
1528 buf = (char*)malloc(len);
1530 for (t=0; t<len; t++)
1531 buf[t] = str->getChar();
1534 this->dict = str->getDict();
1535 this->memstream = new MemStream(buf, 0, len, this);
1539 ::free(this->buf);this->buf = 0;
1540 delete this->memstream;
1542 Dict* getDict() {return dict;}
1543 Stream* getStream() {return this->memstream;};
1546 gfxbbox_t BitmapOutputDev::getImageBBox(GfxState*state)
1550 state->transform(0, 1, &x, &y);
1551 bbox.xmin=bbox.xmax = x;
1552 bbox.ymin=bbox.ymax = x;
1553 state->transform(0, 0, &x, &y);
1554 bbox.xmin=min(bbox.xmin,x);
1555 bbox.ymin=min(bbox.ymin,y);
1556 bbox.xmax=max(bbox.xmin,x);
1557 bbox.ymax=max(bbox.ymin,y);
1558 state->transform(1, 0, &x, &y);
1559 bbox.xmin=min(bbox.xmin,x);
1560 bbox.ymin=min(bbox.ymin,y);
1561 bbox.xmax=max(bbox.xmin,x);
1562 bbox.ymax=max(bbox.ymin,y);
1563 state->transform(1, 1, &x, &y);
1564 bbox.xmin=min(bbox.xmin,x);
1565 bbox.ymin=min(bbox.ymin,y);
1566 bbox.xmax=max(bbox.xmin,x);
1567 bbox.ymax=max(bbox.ymin,y);
1570 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1571 int width, int height, GBool invert,
1574 msg("<debug> drawImageMask streamkind=%d", str->getKind());
1575 CopyStream*cpystr = 0;
1577 cpystr = new CopyStream(str, height * ((width + 7) / 8));
1578 str = cpystr->getStream();
1580 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1581 gfxbbox_t bbox = getImageBBox(state);
1582 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1583 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1587 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1588 int width, int height, GfxImageColorMap *colorMap,
1589 int *maskColors, GBool inlineImg)
1591 msg("<debug> drawImage streamkind=%d", str->getKind());
1592 CopyStream*cpystr = 0;
1594 cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1595 str = cpystr->getStream();
1597 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1598 gfxbbox_t bbox=getImageBBox(state);
1599 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1600 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1604 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1605 int width, int height,
1606 GfxImageColorMap *colorMap,
1607 Stream *maskStr, int maskWidth, int maskHeight,
1610 msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
1611 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1612 gfxbbox_t bbox=getImageBBox(state);
1613 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1614 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1616 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1617 int width, int height,
1618 GfxImageColorMap *colorMap,
1620 int maskWidth, int maskHeight,
1621 GfxImageColorMap *maskColorMap)
1623 msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
1624 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1625 gfxbbox_t bbox=getImageBBox(state);
1626 checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
1627 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1629 void BitmapOutputDev::drawForm(Ref id)
1631 msg("<debug> drawForm");
1632 boolpolydev->drawForm(id);
1633 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1634 rgbdev->drawForm(id);
1637 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1639 msg("<debug> processLink");
1640 gfxdev->processLink(link, catalog);
1643 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1644 GfxColorSpace *blendingColorSpace,
1645 GBool isolated, GBool knockout,
1648 msg("<debug> beginTransparencyGroup");
1649 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1650 GfxState*state1 = state->copy();
1651 GfxState*state2 = state->copy();
1653 state1->setPath(state->getPath()->copy());
1655 state2->setPath(state->getPath()->copy());
1657 GfxState*state1 = state->copy(gTrue);
1658 GfxState*state2 = state->copy(gTrue);
1660 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1661 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1662 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1666 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1668 msg("<debug> endTransparencyGroup");
1669 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1670 GfxState*state1 = state->copy();
1671 GfxState*state2 = state->copy();
1673 state1->setPath(state->getPath()->copy());
1675 state2->setPath(state->getPath()->copy());
1677 GfxState*state1 = state->copy(gTrue);
1678 GfxState*state2 = state->copy(gTrue);
1680 boolpolydev->endTransparencyGroup(state1);
1681 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1682 rgbdev->endTransparencyGroup(state2);
1685 clip1dev->endTransparencyGroup(state);
1687 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1689 msg("<debug> paintTransparencyGroup");
1690 boolpolydev->paintTransparencyGroup(state,bbox);
1691 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1692 rgbdev->paintTransparencyGroup(state,bbox);
1693 clip1dev->paintTransparencyGroup(state,bbox);
1695 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1697 msg("<debug> setSoftMask");
1698 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1699 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1700 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1701 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1703 void BitmapOutputDev::clearSoftMask(GfxState *state)
1705 msg("<debug> clearSoftMask");
1706 boolpolydev->clearSoftMask(state);
1707 checkNewBitmap(UNKNOWN_BOUNDING_BOX);
1708 rgbdev->clearSoftMask(state);
1709 clip1dev->clearSoftMask(state);