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"
33 static SplashColor splash_white = {255,255,255};
34 static SplashColor splash_black = {0,0,0};
36 ClipState::ClipState()
43 BitmapOutputDev::BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
47 this->xref = doc->getXRef();
49 /* color graphic output device, for creating bitmaps */
50 this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
52 /* color mode for binary bitmaps */
53 SplashColorMode colorMode = splashModeMono8;
55 /* two devices for testing things against clipping: one clips, the other doesn't */
56 this->clip0dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
57 this->clip1dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
59 /* device indicating where polygonal pixels were drawn */
60 this->boolpolydev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
61 /* device indicating where text pixels were drawn */
62 this->booltextdev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
64 /* device for handling texts and links */
65 this->gfxdev = new GFXOutputDev(info, this->doc);
67 this->rgbdev->startDoc(this->xref);
68 this->boolpolydev->startDoc(this->xref);
69 this->booltextdev->startDoc(this->xref);
70 this->clip0dev->startDoc(this->xref);
71 this->clip1dev->startDoc(this->xref);
73 this->gfxoutput = (gfxdevice_t*)malloc(sizeof(gfxdevice_t));
74 gfxdevice_record_init(this->gfxoutput);
76 this->gfxdev->setDevice(this->gfxoutput);
78 this->config_extrafontdata = 0;
81 //this->clipstates = 0;
83 BitmapOutputDev::~BitmapOutputDev()
86 gfxresult_t*r = this->gfxoutput->finish(this->gfxoutput);
88 free(this->gfxoutput);this->gfxoutput = 0;
91 delete this->bboxpath;this->bboxpath = 0;
94 delete this->rgbdev;this->rgbdev = 0;
97 delete this->gfxdev;this->gfxdev= 0;
99 if(this->boolpolydev) {
100 delete this->boolpolydev;this->boolpolydev = 0;
102 if(this->booltextdev) {
103 delete this->booltextdev;this->booltextdev = 0;
106 delete this->clip0dev;this->clip0dev = 0;
109 delete this->clip1dev;this->clip1dev = 0;
111 //if(this->clipbitmap) {
112 // delete this->clipbitmap;this->clipbitmap = 0;
114 //if(this->clipdev) {
115 // delete this->clipdev;this->clipdev = 0;
120 GBool BitmapOutputDev::getVectorAntialias()
122 return this->rgbdev->getVectorAntialias();
124 void BitmapOutputDev::setVectorAntialias(GBool vaa)
126 this->rgbdev->setVectorAntialias(vaa);
128 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
132 void BitmapOutputDev::setMove(int x,int y)
134 this->gfxdev->setMove(x,y);
135 this->user_movex = x;
136 this->user_movey = y;
138 void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
140 this->gfxdev->setClip(x1,y1,x2,y2);
141 this->user_clipx1 = x1;
142 this->user_clipy1 = y1;
143 this->user_clipx2 = x2;
144 this->user_clipy2 = y2;
146 void BitmapOutputDev::setParameter(const char*key, const char*value)
148 if(!strcmp(key, "extrafontdata")) {
149 this->config_extrafontdata = atoi(value);
151 this->gfxdev->setParameter(key, value);
153 void BitmapOutputDev::preparePage(int pdfpage, int outputpage)
157 static void getBitmapBBox(Guchar*alpha, int width, int height, int*xmin, int*ymin, int*xmax, int*ymax)
163 for(y=0;y<height;y++) {
164 Guchar*a = &alpha[y*width];
165 for(x=0;x<width;x++) {
168 int left = x; //first occupied pixel from left
169 int right = x+1; //last non-occupied pixel from right
178 if(left<*xmin) *xmin = left;
179 if(right>*xmax) *xmax = right;
182 if(*xmin>=*xmax || *ymin>=*ymax) {
190 void BitmapOutputDev::flushBitmap()
192 int width = rgbdev->getBitmapWidth();
193 int height = rgbdev->getBitmapHeight();
195 SplashColorPtr rgb = rgbbitmap->getDataPtr();
196 Guchar*alpha = rgbbitmap->getAlphaPtr();
198 int xmin,ymin,xmax,ymax;
199 getBitmapBBox(alpha, width, height, &xmin,&ymin,&xmax,&ymax);
201 /* clip against (-movex, -movey, -movex+width, -movey+height) */
202 if(xmin < -this->movex) xmin = -this->movex;
203 if(ymin < -this->movey) ymin = -this->movey;
204 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
205 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
207 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
209 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
212 if(sizeof(SplashColor)!=3) {
213 msg("<error> sizeof(SplashColor)!=3");
220 int rangex = xmax-xmin;
221 int rangey = ymax-ymin;
222 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
223 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
225 img->height = rangey;
227 for(y=0;y<rangey;y++) {
228 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
229 gfxcolor_t*out = &img->data[y*rangex];
230 Guchar*ain = &alpha[(y+ymin)*width+xmin];
231 if(this->emptypage) {
232 for(x=0;x<rangex;x++) {
233 /* the first bitmap on the page doesn't need to have an alpha channel-
234 blend against a white background*/
235 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
236 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
237 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
241 for(x=0;x<rangex;x++) {
242 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we
243 have to premultiply alpha (mix background and pixel according to the alpha channel).
245 out[x].r = (in[x*3+0]*ain[x])/255;
246 out[x].g = (in[x*3+1]*ain[x])/255;
247 out[x].b = (in[x*3+2]*ain[x])/255;
252 /* transform bitmap rectangle to "device space" */
264 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
265 dev->fillbitmap(dev, line, img, &m, 0);
268 memset(rgbbitmap->getAlphaPtr(), 0, rgbbitmap->getWidth()*rgbbitmap->getHeight());
269 memset(rgbbitmap->getDataPtr(), 0, rgbbitmap->getRowSize()*rgbbitmap->getHeight());
271 free(img->data);img->data=0;free(img);img=0;
276 void BitmapOutputDev::flushText()
278 msg("<verbose> Flushing text/polygons");
279 gfxdevice_record_flush(this->gfxoutput, this->dev);
284 void writeAlpha(SplashBitmap*bitmap, char*filename)
288 int width = bitmap->getWidth();
289 int height = bitmap->getHeight();
291 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
293 for(y=0;y<height;y++) {
294 gfxcolor_t*line = &data[y*width];
295 for(x=0;x<width;x++) {
296 int a = bitmap->getAlpha(x,y);
303 writePNG(filename, (unsigned char*)data, width, height);
306 static int dbg_btm_counter=1;
308 static const char*STATE_NAME[] = {"parallel", "textabovebitmap", "bitmapabovetext"};
310 void BitmapOutputDev::checkNewText()
312 /* called once some new text was drawn on booltextdev, and
313 before the same thing is drawn on gfxdev */
315 msg("<trace> Testing new text data against current bitmap data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
319 sprintf(filename1, "state%dbitmap_afternewtext.png", dbg_btm_counter);
320 sprintf(filename2, "state%dtext_afternewtext.png", dbg_btm_counter);
322 writeAlpha(boolpolybitmap, filename1);
323 writeAlpha(booltextbitmap, filename2);
328 if(layerstate==STATE_PARALLEL) {
329 /* the new text is above the bitmap. So record that fact,
330 and also clear the bitmap buffer, so we can check for
332 msg("<verbose> Text is above current bitmap/polygon data");
333 layerstate=STATE_TEXT_IS_ABOVE;
335 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
336 /* there's a bitmap above the (old) text. So we need
337 to flush out that text, and record that the *new*
338 text is now *above* the bitmap
340 msg("<verbose> Text is above current bitmap/polygon data (which is above some other text)");
342 layerstate=STATE_TEXT_IS_ABOVE;
343 /* clear both bool devices- the text device because
344 we just dumped out all the (old) text, and the
345 poly dev so we can check for new intersections */
349 /* we already know that the current text section is
350 above the current bitmap section- now just new
351 bitmap data *and* new text data was drawn, and
352 *again* it's above the current bitmap- so clear
353 the polygon bitmap again, so we can check for
355 msg("<verbose> Text is still above current bitmap/polygon data");
361 void BitmapOutputDev::checkNewBitmap()
363 /* similar to checkNewText() above, only in reverse */
364 msg("<trace> Testing new graphics data against current text data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
368 sprintf(filename1, "state%dbitmap_afternewgfx.png", dbg_btm_counter);
369 sprintf(filename2, "state%dtext_afternewgfx.png", dbg_btm_counter);
371 writeAlpha(boolpolybitmap, filename1);
372 writeAlpha(booltextbitmap, filename2);
377 if(layerstate==STATE_PARALLEL) {
378 msg("<verbose> Bitmap is above current text data");
379 layerstate=STATE_BITMAP_IS_ABOVE;
381 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
382 msg("<verbose> Bitmap is above current text data (which is above some bitmap)");
384 layerstate=STATE_BITMAP_IS_ABOVE;
388 msg("<verbose> Bitmap is still above current text data");
394 //void checkNewText() {
395 // Guchar*alpha = rgbbitmap->getAlphaPtr();
396 // Guchar*charpixels = clip1bitmap->getDataPtr();
398 // for(yy=0;yy<height;yy++) {
399 // Guchar*aline = &alpha[yy*width];
400 // Guchar*cline = &charpixels[yy*width8];
401 // for(xx=0;xx<width;xx++) {
403 // int bytepos = xx>>3;
404 // /* TODO: is the bit order correct? */
405 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
412 GBool BitmapOutputDev::clip0and1differ()
414 if(clip0bitmap->getMode()==splashModeMono1) {
415 SplashBitmap*clip0 = clip0bitmap;
416 SplashBitmap*clip1 = clip1bitmap;
417 int width8 = (clip0->getWidth()+7)/8;
418 int height = clip0->getHeight();
419 return memcmp(clip0->getDataPtr(), clip1->getDataPtr(), width8*height);
421 SplashBitmap*clip0 = clip0bitmap;
422 SplashBitmap*clip1 = clip1bitmap;
423 int width = clip0->getAlphaRowSize();
424 int height = clip0->getHeight();
425 return memcmp(clip0->getAlphaPtr(), clip1->getAlphaPtr(), width*height);
429 static void clearBooleanBitmap(SplashBitmap*btm)
431 if(btm->getMode()==splashModeMono1) {
432 int width8 = (btm->getWidth()+7)/8;
433 int width = btm->getWidth();
434 int height = btm->getHeight();
435 memset(btm->getDataPtr(), 0, width8*height);
437 int width = btm->getAlphaRowSize();
438 int height = btm->getHeight();
439 memset(btm->getAlphaPtr(), 0, width*height);
443 long long unsigned int compare64(long long unsigned int*data1, long long unsigned int*data2, int len)
445 long long unsigned int c;
448 c |= data1[t]&data2[t];
453 GBool BitmapOutputDev::intersection()
455 SplashBitmap*boolpoly = boolpolybitmap;
456 SplashBitmap*booltext = booltextbitmap;
458 if(boolpoly->getMode()==splashModeMono1) {
459 /* alternative implementation, using one bit per pixel-
460 would work if xpdf wouldn't try to dither everything */
462 Guchar*polypixels = boolpoly->getDataPtr();
463 Guchar*textpixels = booltext->getDataPtr();
465 int width8 = (width+7)/8;
466 int height = boolpoly->getHeight();
469 int len = height*width8;
470 unsigned long long int c=0;
471 assert(sizeof(unsigned long long int)==8);
473 if(((int)polypixels&7) || ((int)textpixels&7)) {
474 msg("<warning> Non-optimal alignment");
477 len /= sizeof(unsigned long long int);
478 c = compare64((unsigned long long int*)polypixels, (unsigned long long int*)textpixels, len);
479 int l1 = len*sizeof(unsigned long long int);
481 c |= (unsigned long long int)(polypixels[t]&textpixels[t]);
485 /* if graphic data and the characters overlap, they have common bits */
490 Guchar*polypixels = boolpoly->getAlphaPtr();
491 Guchar*textpixels = booltext->getAlphaPtr();
493 int width = boolpoly->getAlphaRowSize();
494 int height = boolpoly->getHeight();
497 int len = height*width;
499 if(len & (sizeof(unsigned int)-1)) {
502 if(polypixels[t]&&textpixels[t])
506 len /= sizeof(unsigned int);
508 if((((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]))
517 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
520 state->transform(crop_x1,crop_y1,&x1,&y1);
521 state->transform(crop_x2,crop_y2,&x2,&y2);
522 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
523 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
525 this->movex = -(int)x1 - user_movex;
526 this->movey = -(int)y1 - user_movey;
528 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
534 this->width = (int)(x2-x1);
535 this->height = (int)(y2-y1);
537 msg("<debug> startPage");
538 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
539 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
540 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
541 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
542 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
543 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
545 boolpolybitmap = boolpolydev->getBitmap();
546 booltextbitmap = booltextdev->getBitmap();
547 clip0bitmap = clip0dev->getBitmap();
548 clip1bitmap = clip1dev->getBitmap();
549 rgbbitmap = rgbdev->getBitmap();
551 flushText(); // write out the initial clipping rectangle
553 /* just in case any device did draw a white background rectangle
558 this->layerstate = STATE_PARALLEL;
560 msg("<debug> startPage done");
563 void BitmapOutputDev::endPage()
565 msg("<verbose> endPage (BitmapOutputDev)");
567 /* notice: we're not fully done yet with this page- there might still be
568 a few calls to drawLink() yet to come */
570 void BitmapOutputDev::finishPage()
572 msg("<verbose> finishPage (BitmapOutputDev)");
575 if(layerstate == STATE_BITMAP_IS_ABOVE) {
583 /* splash will now destroy alpha, and paint the
584 background color into the "holes" in the bitmap */
585 boolpolydev->endPage();
586 booltextdev->endPage();
592 GBool BitmapOutputDev::upsideDown()
594 boolpolydev->upsideDown();
595 booltextdev->upsideDown();
596 clip0dev->upsideDown();
597 clip1dev->upsideDown();
598 return rgbdev->upsideDown();
601 GBool BitmapOutputDev::useDrawChar()
603 boolpolydev->useDrawChar();
604 booltextdev->useDrawChar();
605 clip0dev->useDrawChar();
606 clip1dev->useDrawChar();
607 return rgbdev->useDrawChar();
610 GBool BitmapOutputDev::useTilingPatternFill()
612 boolpolydev->useTilingPatternFill();
613 booltextdev->useTilingPatternFill();
614 clip0dev->useTilingPatternFill();
615 clip1dev->useTilingPatternFill();
616 return rgbdev->useTilingPatternFill();
619 GBool BitmapOutputDev::useShadedFills()
621 boolpolydev->useShadedFills();
622 booltextdev->useShadedFills();
623 clip0dev->useShadedFills();
624 clip1dev->useShadedFills();
625 return rgbdev->useShadedFills();
628 GBool BitmapOutputDev::useDrawForm()
630 boolpolydev->useDrawForm();
631 booltextdev->useDrawForm();
632 clip0dev->useDrawForm();
633 clip1dev->useDrawForm();
634 return rgbdev->useDrawForm();
637 GBool BitmapOutputDev::interpretType3Chars()
639 boolpolydev->interpretType3Chars();
640 booltextdev->interpretType3Chars();
641 clip0dev->interpretType3Chars();
642 clip1dev->interpretType3Chars();
643 return rgbdev->interpretType3Chars();
646 GBool BitmapOutputDev::needNonText()
648 boolpolydev->needNonText();
649 booltextdev->needNonText();
650 clip0dev->needNonText();
651 clip1dev->needNonText();
652 return rgbdev->needNonText();
654 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
655 int rotate, GBool useMediaBox, GBool crop,
656 int sliceX, int sliceY, int sliceW, int sliceH,
657 GBool printing, Catalog *catalog,
658 GBool (*abortCheckCbk)(void *data),
659 void *abortCheckCbkData)
663 void BitmapOutputDev::setDefaultCTM(double *ctm)
665 boolpolydev->setDefaultCTM(ctm);
666 booltextdev->setDefaultCTM(ctm);
667 rgbdev->setDefaultCTM(ctm);
668 clip0dev->setDefaultCTM(ctm);
669 clip1dev->setDefaultCTM(ctm);
670 gfxdev->setDefaultCTM(ctm);
672 void BitmapOutputDev::saveState(GfxState *state)
674 boolpolydev->saveState(state);
675 booltextdev->saveState(state);
676 rgbdev->saveState(state);
677 clip0dev->saveState(state);
678 clip1dev->saveState(state);
680 /*ClipState*cstate = new ClipState();
681 cstate->next = this->clipstates;
682 this->clipstates = cstate;*/
684 void BitmapOutputDev::restoreState(GfxState *state)
686 boolpolydev->restoreState(state);
687 booltextdev->restoreState(state);
688 rgbdev->restoreState(state);
689 clip0dev->restoreState(state);
690 clip1dev->restoreState(state);
692 /*if(this->clipstates) {
693 ClipState*old = this->clipstates;
695 gfxdev->restoreState(state);
697 this->clipstates = this->clipstates->next;
700 msg("<error> invalid restoreState()");
703 void BitmapOutputDev::updateAll(GfxState *state)
705 boolpolydev->updateAll(state);
706 booltextdev->updateAll(state);
707 rgbdev->updateAll(state);
708 clip0dev->updateAll(state);
709 clip1dev->updateAll(state);
710 gfxdev->updateAll(state);
712 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
714 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
715 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
716 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
717 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
718 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
719 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
721 void BitmapOutputDev::updateLineDash(GfxState *state)
723 boolpolydev->updateLineDash(state);
724 booltextdev->updateLineDash(state);
725 rgbdev->updateLineDash(state);
726 clip0dev->updateLineDash(state);
727 clip1dev->updateLineDash(state);
728 gfxdev->updateLineDash(state);
730 void BitmapOutputDev::updateFlatness(GfxState *state)
732 boolpolydev->updateFlatness(state);
733 booltextdev->updateFlatness(state);
734 rgbdev->updateFlatness(state);
735 clip0dev->updateFlatness(state);
736 clip1dev->updateFlatness(state);
737 gfxdev->updateFlatness(state);
739 void BitmapOutputDev::updateLineJoin(GfxState *state)
741 boolpolydev->updateLineJoin(state);
742 booltextdev->updateLineJoin(state);
743 rgbdev->updateLineJoin(state);
744 clip0dev->updateLineJoin(state);
745 clip1dev->updateLineJoin(state);
746 gfxdev->updateLineJoin(state);
748 void BitmapOutputDev::updateLineCap(GfxState *state)
750 boolpolydev->updateLineCap(state);
751 booltextdev->updateLineCap(state);
752 rgbdev->updateLineCap(state);
753 clip0dev->updateLineCap(state);
754 clip1dev->updateLineCap(state);
755 gfxdev->updateLineCap(state);
757 void BitmapOutputDev::updateMiterLimit(GfxState *state)
759 boolpolydev->updateMiterLimit(state);
760 booltextdev->updateMiterLimit(state);
761 rgbdev->updateMiterLimit(state);
762 clip0dev->updateMiterLimit(state);
763 clip1dev->updateMiterLimit(state);
764 gfxdev->updateMiterLimit(state);
766 void BitmapOutputDev::updateLineWidth(GfxState *state)
768 boolpolydev->updateLineWidth(state);
769 booltextdev->updateLineWidth(state);
770 rgbdev->updateLineWidth(state);
771 clip0dev->updateLineWidth(state);
772 clip1dev->updateLineWidth(state);
773 gfxdev->updateLineWidth(state);
775 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
777 boolpolydev->updateStrokeAdjust(state);
778 booltextdev->updateStrokeAdjust(state);
779 rgbdev->updateStrokeAdjust(state);
780 clip0dev->updateStrokeAdjust(state);
781 clip1dev->updateStrokeAdjust(state);
782 gfxdev->updateStrokeAdjust(state);
784 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
786 boolpolydev->updateFillColorSpace(state);
787 booltextdev->updateFillColorSpace(state);
788 rgbdev->updateFillColorSpace(state);
789 clip0dev->updateFillColorSpace(state);
790 clip1dev->updateFillColorSpace(state);
791 gfxdev->updateFillColorSpace(state);
793 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
795 boolpolydev->updateStrokeColorSpace(state);
796 booltextdev->updateStrokeColorSpace(state);
797 rgbdev->updateStrokeColorSpace(state);
798 clip0dev->updateStrokeColorSpace(state);
799 clip1dev->updateStrokeColorSpace(state);
800 gfxdev->updateStrokeColorSpace(state);
802 void BitmapOutputDev::updateFillColor(GfxState *state)
804 boolpolydev->updateFillColor(state);
805 booltextdev->updateFillColor(state);
806 rgbdev->updateFillColor(state);
807 clip0dev->updateFillColor(state);
808 clip1dev->updateFillColor(state);
809 gfxdev->updateFillColor(state);
811 void BitmapOutputDev::updateStrokeColor(GfxState *state)
813 boolpolydev->updateStrokeColor(state);
814 booltextdev->updateStrokeColor(state);
815 rgbdev->updateStrokeColor(state);
816 clip0dev->updateStrokeColor(state);
817 clip1dev->updateStrokeColor(state);
818 gfxdev->updateStrokeColor(state);
820 void BitmapOutputDev::updateBlendMode(GfxState *state)
822 boolpolydev->updateBlendMode(state);
823 booltextdev->updateBlendMode(state);
824 rgbdev->updateBlendMode(state);
825 clip0dev->updateBlendMode(state);
826 clip1dev->updateBlendMode(state);
827 gfxdev->updateBlendMode(state);
829 void BitmapOutputDev::updateFillOpacity(GfxState *state)
831 boolpolydev->updateFillOpacity(state);
832 booltextdev->updateFillOpacity(state);
833 rgbdev->updateFillOpacity(state);
834 clip0dev->updateFillOpacity(state);
835 clip1dev->updateFillOpacity(state);
836 gfxdev->updateFillOpacity(state);
838 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
840 boolpolydev->updateStrokeOpacity(state);
841 booltextdev->updateStrokeOpacity(state);
842 rgbdev->updateStrokeOpacity(state);
843 clip0dev->updateStrokeOpacity(state);
844 clip1dev->updateStrokeOpacity(state);
845 gfxdev->updateStrokeOpacity(state);
847 void BitmapOutputDev::updateFillOverprint(GfxState *state)
849 boolpolydev->updateFillOverprint(state);
850 booltextdev->updateFillOverprint(state);
851 rgbdev->updateFillOverprint(state);
852 clip0dev->updateFillOverprint(state);
853 clip1dev->updateFillOverprint(state);
854 gfxdev->updateFillOverprint(state);
856 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
858 boolpolydev->updateStrokeOverprint(state);
859 booltextdev->updateStrokeOverprint(state);
860 rgbdev->updateStrokeOverprint(state);
861 clip0dev->updateStrokeOverprint(state);
862 clip1dev->updateStrokeOverprint(state);
863 gfxdev->updateStrokeOverprint(state);
865 void BitmapOutputDev::updateTransfer(GfxState *state)
867 boolpolydev->updateTransfer(state);
868 booltextdev->updateTransfer(state);
869 rgbdev->updateTransfer(state);
870 clip0dev->updateTransfer(state);
871 clip1dev->updateTransfer(state);
872 gfxdev->updateTransfer(state);
874 void BitmapOutputDev::updateFont(GfxState *state)
876 boolpolydev->updateFont(state);
877 booltextdev->updateFont(state);
878 rgbdev->updateFont(state);
879 clip0dev->updateFont(state);
880 clip1dev->updateFont(state);
881 gfxdev->updateFont(state);
883 void BitmapOutputDev::updateTextMat(GfxState *state)
885 boolpolydev->updateTextMat(state);
886 booltextdev->updateTextMat(state);
887 rgbdev->updateTextMat(state);
888 clip0dev->updateTextMat(state);
889 clip1dev->updateTextMat(state);
890 gfxdev->updateTextMat(state);
892 void BitmapOutputDev::updateCharSpace(GfxState *state)
894 boolpolydev->updateCharSpace(state);
895 booltextdev->updateCharSpace(state);
896 rgbdev->updateCharSpace(state);
897 clip0dev->updateCharSpace(state);
898 clip1dev->updateCharSpace(state);
899 gfxdev->updateCharSpace(state);
901 void BitmapOutputDev::updateRender(GfxState *state)
903 boolpolydev->updateRender(state);
904 booltextdev->updateRender(state);
905 rgbdev->updateRender(state);
906 clip0dev->updateRender(state);
907 clip1dev->updateRender(state);
908 gfxdev->updateRender(state);
910 void BitmapOutputDev::updateRise(GfxState *state)
912 boolpolydev->updateRise(state);
913 booltextdev->updateRise(state);
914 rgbdev->updateRise(state);
915 clip0dev->updateRise(state);
916 clip1dev->updateRise(state);
917 gfxdev->updateRise(state);
919 void BitmapOutputDev::updateWordSpace(GfxState *state)
921 boolpolydev->updateWordSpace(state);
922 booltextdev->updateWordSpace(state);
923 rgbdev->updateWordSpace(state);
924 clip0dev->updateWordSpace(state);
925 clip1dev->updateWordSpace(state);
926 gfxdev->updateWordSpace(state);
928 void BitmapOutputDev::updateHorizScaling(GfxState *state)
930 boolpolydev->updateHorizScaling(state);
931 booltextdev->updateHorizScaling(state);
932 rgbdev->updateHorizScaling(state);
933 clip0dev->updateHorizScaling(state);
934 clip1dev->updateHorizScaling(state);
935 gfxdev->updateHorizScaling(state);
937 void BitmapOutputDev::updateTextPos(GfxState *state)
939 boolpolydev->updateTextPos(state);
940 booltextdev->updateTextPos(state);
941 rgbdev->updateTextPos(state);
942 clip0dev->updateTextPos(state);
943 clip1dev->updateTextPos(state);
944 gfxdev->updateTextPos(state);
946 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
948 boolpolydev->updateTextShift(state, shift);
949 booltextdev->updateTextShift(state, shift);
950 rgbdev->updateTextShift(state, shift);
951 clip0dev->updateTextShift(state, shift);
952 clip1dev->updateTextShift(state, shift);
953 gfxdev->updateTextShift(state, shift);
956 void BitmapOutputDev::stroke(GfxState *state)
958 msg("<debug> stroke");
959 boolpolydev->stroke(state);
961 rgbdev->stroke(state);
963 void BitmapOutputDev::fill(GfxState *state)
966 boolpolydev->fill(state);
970 void BitmapOutputDev::eoFill(GfxState *state)
972 msg("<debug> eoFill");
973 boolpolydev->eoFill(state);
975 rgbdev->eoFill(state);
977 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
978 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
979 int paintType, Dict *resDict,
980 double *mat, double *bbox,
981 int x0, int y0, int x1, int y1,
982 double xStep, double yStep)
984 msg("<debug> tilingPatternFill");
985 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
987 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
990 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
991 int paintType, Dict *resDict,
992 double *mat, double *bbox,
993 int x0, int y0, int x1, int y1,
994 double xStep, double yStep)
996 msg("<debug> tilingPatternFill");
997 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
999 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
1003 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
1005 msg("<debug> functionShadedFill");
1006 boolpolydev->functionShadedFill(state, shading);
1008 return rgbdev->functionShadedFill(state, shading);
1010 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
1012 msg("<debug> axialShadedFill");
1013 boolpolydev->axialShadedFill(state, shading);
1015 return rgbdev->axialShadedFill(state, shading);
1017 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
1019 msg("<debug> radialShadedFill");
1020 boolpolydev->radialShadedFill(state, shading);
1022 return rgbdev->radialShadedFill(state, shading);
1025 SplashColor black = {0,0,0};
1026 SplashColor white = {255,255,255};
1028 void BitmapOutputDev::clip(GfxState *state)
1030 msg("<debug> clip");
1031 boolpolydev->clip(state);
1032 booltextdev->clip(state);
1033 rgbdev->clip(state);
1034 clip1dev->clip(state);
1036 void BitmapOutputDev::eoClip(GfxState *state)
1038 msg("<debug> eoClip");
1039 boolpolydev->eoClip(state);
1040 booltextdev->eoClip(state);
1041 rgbdev->eoClip(state);
1042 clip1dev->eoClip(state);
1044 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1046 msg("<debug> clipToStrokePath");
1047 boolpolydev->clipToStrokePath(state);
1048 booltextdev->clipToStrokePath(state);
1049 rgbdev->clipToStrokePath(state);
1050 clip1dev->clipToStrokePath(state);
1053 void BitmapOutputDev::beginStringOp(GfxState *state)
1055 msg("<debug> beginStringOp");
1056 clip0dev->beginStringOp(state);
1057 clip1dev->beginStringOp(state);
1058 booltextdev->beginStringOp(state);
1059 gfxdev->beginStringOp(state);
1061 void BitmapOutputDev::endStringOp(GfxState *state)
1063 msg("<debug> endStringOp");
1064 clip0dev->endStringOp(state);
1065 clip1dev->endStringOp(state);
1066 booltextdev->endStringOp(state);
1068 gfxdev->endStringOp(state);
1070 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1072 msg("<debug> beginString");
1073 clip0dev->beginString(state, s);
1074 clip1dev->beginString(state, s);
1075 booltextdev->beginString(state, s);
1076 gfxdev->beginString(state, s);
1078 void BitmapOutputDev::endString(GfxState *state)
1080 msg("<debug> endString");
1081 clip0dev->endString(state);
1082 clip1dev->endString(state);
1083 booltextdev->endString(state);
1085 gfxdev->endString(state);
1088 void BitmapOutputDev::clearClips()
1090 clearBooleanBitmap(clip0bitmap);
1091 clearBooleanBitmap(clip1bitmap);
1093 void BitmapOutputDev::clearBoolPolyDev()
1095 clearBooleanBitmap(boolpolybitmap);
1097 void BitmapOutputDev::clearBoolTextDev()
1099 clearBooleanBitmap(booltextbitmap);
1101 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1102 double dx, double dy,
1103 double originX, double originY,
1104 CharCode code, int nBytes, Unicode *u, int uLen)
1106 msg("<debug> drawChar");
1107 if(state->getRender()&RENDER_CLIP) {
1108 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1111 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1112 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1114 /* if this character is affected somehow by the various clippings (i.e., it looks
1115 different on a device without clipping), then draw it on the bitmap, not as
1117 if(clip0and1differ()) {
1118 msg("<verbose> Char %d is affected by clipping", code);
1119 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1121 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1122 if(config_extrafontdata) {
1123 int oldrender = state->getRender();
1124 state->setRender(3); //invisible
1125 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1126 state->setRender(oldrender);
1129 /* this char is not at all affected by clipping.
1130 Now just dump out the bitmap we're currently working on, if necessary. */
1131 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1133 /* use polygonal output device to do the actual text handling */
1134 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1138 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1140 msg("<error> internal error: drawString not implemented");
1142 clip0dev->drawString(state, s);
1143 clip1dev->drawString(state, s);
1144 booltextdev->drawString(state, s);
1145 gfxdev->drawString(state, s);
1147 void BitmapOutputDev::endTextObject(GfxState *state)
1149 msg("<debug> endTextObject");
1150 rgbdev->endTextObject(state);
1151 clip0dev->endTextObject(state);
1152 clip1dev->endTextObject(state);
1153 booltextdev->endTextObject(state);
1155 gfxdev->endTextObject(state);
1158 /* TODO: these four operations below *should* do nothing, as type3
1159 chars are drawn using operations like fill() */
1160 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1161 double dx, double dy,
1162 CharCode code, Unicode *u, int uLen)
1164 msg("<debug> beginType3Char");
1165 /* call gfxdev so that it can generate "invisible" characters
1166 on top of the actual graphic content, for text extraction */
1167 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1169 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1171 msg("<debug> type3D0");
1172 return gfxdev->type3D0(state, wx, wy);
1174 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1176 msg("<debug> type3D1");
1177 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1179 void BitmapOutputDev::endType3Char(GfxState *state)
1181 msg("<debug> endType3Char");
1182 gfxdev->endType3Char(state);
1185 class CopyStream: public Object
1189 MemStream*memstream;
1191 CopyStream(Stream*str, int len)
1196 buf = (char*)malloc(len);
1198 for (t=0; t<len; t++)
1199 buf[t] = str->getChar();
1202 this->dict = str->getDict();
1203 this->memstream = new MemStream(buf, 0, len, this);
1207 ::free(this->buf);this->buf = 0;
1208 delete this->memstream;
1210 Dict* getDict() {return dict;}
1211 Stream* getStream() {return this->memstream;};
1214 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1215 int width, int height, GBool invert,
1218 msg("<debug> drawImageMask streamkind=%d", str->getKind());
1219 CopyStream*cpystr = 0;
1221 cpystr = new CopyStream(str, height * ((width + 7) / 8));
1222 str = cpystr->getStream();
1224 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1226 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1230 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1231 int width, int height, GfxImageColorMap *colorMap,
1232 int *maskColors, GBool inlineImg)
1234 msg("<debug> drawImage streamkind=%d", str->getKind());
1235 CopyStream*cpystr = 0;
1237 cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1238 str = cpystr->getStream();
1240 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1242 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1246 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1247 int width, int height,
1248 GfxImageColorMap *colorMap,
1249 Stream *maskStr, int maskWidth, int maskHeight,
1252 msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
1253 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1255 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1257 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1258 int width, int height,
1259 GfxImageColorMap *colorMap,
1261 int maskWidth, int maskHeight,
1262 GfxImageColorMap *maskColorMap)
1264 msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
1265 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1267 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1269 void BitmapOutputDev::drawForm(Ref id)
1271 msg("<debug> drawForm");
1272 boolpolydev->drawForm(id);
1274 rgbdev->drawForm(id);
1277 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1279 msg("<debug> processLink");
1280 gfxdev->processLink(link, catalog);
1283 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1284 GfxColorSpace *blendingColorSpace,
1285 GBool isolated, GBool knockout,
1288 msg("<debug> beginTransparencyGroup");
1289 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1290 GfxState*state1 = state->copy();
1291 GfxState*state2 = state->copy();
1293 state1->setPath(state->getPath()->copy());
1295 state2->setPath(state->getPath()->copy());
1297 GfxState*state1 = state->copy(gTrue);
1298 GfxState*state2 = state->copy(gTrue);
1300 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1301 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1302 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1306 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1308 msg("<debug> endTransparencyGroup");
1309 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1310 GfxState*state1 = state->copy();
1311 GfxState*state2 = state->copy();
1313 state1->setPath(state->getPath()->copy());
1315 state2->setPath(state->getPath()->copy());
1317 GfxState*state1 = state->copy(gTrue);
1318 GfxState*state2 = state->copy(gTrue);
1320 boolpolydev->endTransparencyGroup(state1);
1322 rgbdev->endTransparencyGroup(state2);
1325 clip1dev->endTransparencyGroup(state);
1327 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1329 msg("<debug> paintTransparencyGroup");
1330 boolpolydev->paintTransparencyGroup(state,bbox);
1332 rgbdev->paintTransparencyGroup(state,bbox);
1333 clip1dev->paintTransparencyGroup(state,bbox);
1335 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1337 msg("<debug> setSoftMask");
1338 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1340 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1341 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1343 void BitmapOutputDev::clearSoftMask(GfxState *state)
1345 msg("<debug> clearSoftMask");
1346 boolpolydev->clearSoftMask(state);
1348 rgbdev->clearSoftMask(state);
1349 clip1dev->clearSoftMask(state);