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 */
23 #include "BitmapOutputDev.h"
24 #include "GFXOutputDev.h"
25 #include "SplashBitmap.h"
26 #include "SplashPattern.h"
30 #include "../devices/record.h"
32 static SplashColor splash_white = {255,255,255};
33 static SplashColor splash_black = {0,0,0};
35 ClipState::ClipState()
42 BitmapOutputDev::BitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
46 this->xref = doc->getXRef();
48 /* color graphic output device, for creating bitmaps */
49 this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
51 /* color mode for binary bitmaps */
52 SplashColorMode colorMode = splashModeMono8;
54 /* two devices for testing things against clipping: one clips, the other doesn't */
55 this->clip0dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
56 this->clip1dev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
58 /* device indicating where polygonal pixels were drawn */
59 this->boolpolydev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
60 /* device indicating where text pixels were drawn */
61 this->booltextdev = new SplashOutputDev(colorMode, 1, gFalse, splash_black, gTrue, gFalse);
63 /* device for handling texts and links */
64 this->gfxdev = new GFXOutputDev(info, this->doc);
66 this->rgbdev->startDoc(this->xref);
67 this->boolpolydev->startDoc(this->xref);
68 this->booltextdev->startDoc(this->xref);
69 this->clip0dev->startDoc(this->xref);
70 this->clip1dev->startDoc(this->xref);
72 this->gfxoutput = (gfxdevice_t*)malloc(sizeof(gfxdevice_t));
73 gfxdevice_record_init(this->gfxoutput);
75 this->gfxdev->setDevice(this->gfxoutput);
77 this->config_extrafontdata = 0;
80 //this->clipstates = 0;
82 BitmapOutputDev::~BitmapOutputDev()
85 gfxresult_t*r = this->gfxoutput->finish(this->gfxoutput);
87 free(this->gfxoutput);this->gfxoutput = 0;
90 delete this->bboxpath;this->bboxpath = 0;
93 delete this->rgbdev;this->rgbdev = 0;
96 delete this->gfxdev;this->gfxdev= 0;
98 if(this->boolpolydev) {
99 delete this->boolpolydev;this->boolpolydev = 0;
101 if(this->booltextdev) {
102 delete this->booltextdev;this->booltextdev = 0;
105 delete this->clip0dev;this->clip0dev = 0;
108 delete this->clip1dev;this->clip1dev = 0;
110 //if(this->clipbitmap) {
111 // delete this->clipbitmap;this->clipbitmap = 0;
113 //if(this->clipdev) {
114 // delete this->clipdev;this->clipdev = 0;
119 GBool BitmapOutputDev::getVectorAntialias()
121 return this->rgbdev->getVectorAntialias();
123 void BitmapOutputDev::setVectorAntialias(GBool vaa)
125 this->rgbdev->setVectorAntialias(vaa);
127 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
131 void BitmapOutputDev::setMove(int x,int y)
133 this->gfxdev->setMove(x,y);
134 this->user_movex = x;
135 this->user_movey = y;
137 void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
139 this->gfxdev->setClip(x1,y1,x2,y2);
140 this->user_clipx1 = x1;
141 this->user_clipy1 = y1;
142 this->user_clipx2 = x2;
143 this->user_clipy2 = y2;
145 void BitmapOutputDev::setParameter(const char*key, const char*value)
147 if(!strcmp(key, "extrafontdata")) {
148 this->config_extrafontdata = atoi(value);
150 this->gfxdev->setParameter(key, value);
152 void BitmapOutputDev::preparePage(int pdfpage, int outputpage)
156 static void getBitmapBBox(Guchar*alpha, int width, int height, int*xmin, int*ymin, int*xmax, int*ymax)
162 for(y=0;y<height;y++) {
163 Guchar*a = &alpha[y*width];
164 for(x=0;x<width;x++) {
167 int left = x; //first occupied pixel from left
168 int right = x+1; //last non-occupied pixel from right
177 if(left<*xmin) *xmin = left;
178 if(right>*xmax) *xmax = right;
181 if(*xmin>=*xmax || *ymin>=*ymax) {
189 void BitmapOutputDev::flushBitmap()
191 int width = rgbdev->getBitmapWidth();
192 int height = rgbdev->getBitmapHeight();
194 SplashColorPtr rgb = rgbdev->getBitmap()->getDataPtr();
195 Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
197 int xmin,ymin,xmax,ymax;
198 getBitmapBBox(alpha, width, height, &xmin,&ymin,&xmax,&ymax);
200 /* clip against (-movex, -movey, -movex+width, -movey+height) */
201 if(xmin < -this->movex) xmin = -this->movex;
202 if(ymin < -this->movey) ymin = -this->movey;
203 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
204 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
206 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
208 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
211 if(sizeof(SplashColor)!=3) {
212 msg("<error> sizeof(SplashColor)!=3");
219 int rangex = xmax-xmin;
220 int rangey = ymax-ymin;
221 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
222 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
224 img->height = rangey;
226 for(y=0;y<rangey;y++) {
227 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
228 gfxcolor_t*out = &img->data[y*rangex];
229 Guchar*ain = &alpha[(y+ymin)*width+xmin];
230 for(x=0;x<rangex;x++) {
231 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we
232 have to premultiply alpha (mix background and pixel according to the alpha channel).
234 out[x].r = (in[x*3+0]*ain[x])/255;
235 out[x].g = (in[x*3+1]*ain[x])/255;
236 out[x].b = (in[x*3+2]*ain[x])/255;
240 /* transform bitmap rectangle to "device space" */
252 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
253 dev->fillbitmap(dev, line, img, &m, 0);
256 memset(rgbdev->getBitmap()->getAlphaPtr(), 0, rgbdev->getBitmap()->getWidth()*rgbdev->getBitmap()->getHeight());
257 memset(rgbdev->getBitmap()->getDataPtr(), 0, rgbdev->getBitmap()->getRowSize()*rgbdev->getBitmap()->getHeight());
259 free(img->data);img->data=0;free(img);img=0;
262 void BitmapOutputDev::flushText()
264 msg("<verbose> Flushing text/polygons");
265 gfxdevice_record_flush(this->gfxoutput, this->dev);
268 void writeAlpha(SplashBitmap*bitmap, char*filename)
273 int width = bitmap->getWidth();
274 int height = bitmap->getHeight();
276 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
278 for(y=0;y<height;y++) {
279 gfxcolor_t*line = &data[y*width];
280 for(x=0;x<width;x++) {
281 int a = bitmap->getAlpha(x,y);
288 writePNG(filename, (unsigned char*)data, width, height);
291 static int dbg_btm_counter=1;
293 void BitmapOutputDev::checkNewText()
295 /* called once some new text was drawn on booltextdev, and
296 before the same thing is drawn on gfxdev */
298 msg("<trace> Testing new text data against current bitmap data, state=%d, counter=%d\n", layerstate, dbg_btm_counter);
302 sprintf(filename1, "state%dbitmap_newtext.png", dbg_btm_counter);
303 sprintf(filename2, "state%dtext_newtext.png", dbg_btm_counter);
304 writeAlpha(boolpolydev->getBitmap(), filename1);
305 writeAlpha(booltextdev->getBitmap(), filename2);
309 msg("<verbose> Text is above current bitmap/polygon data");
310 if(layerstate==STATE_PARALLEL) {
311 /* the new text is above the bitmap. So record that fact,
312 and also clear the bitmap buffer, so we can check for
314 layerstate=STATE_TEXT_IS_ABOVE;
316 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
317 /* there's a bitmap above the (old) text. So we need
318 to flush out that text, and record that the *new*
319 text is now *above* the bitmap
322 layerstate=STATE_TEXT_IS_ABOVE;
323 /* clear both bool devices- the text device because
324 we just dumped out all the (old) text, and the
325 poly dev so we can check for new intersections */
329 /* we already know that the current text section is
330 above the current bitmap section- now just new
331 bitmap data *and* new text data was drawn, and
332 *again* it's above the current bitmap- so clear
333 the polygon bitmap again, so we can check for
340 void BitmapOutputDev::checkNewBitmap()
342 /* similar to checkNewText() above, only in reverse */
343 msg("<trace> Testing new graphics data against current text data, state=%d, counter=%d\n", layerstate, dbg_btm_counter);
347 sprintf(filename1, "state%dbitmap_newbitmap.png", dbg_btm_counter);
348 sprintf(filename2, "state%dtext_newbitmap.png", dbg_btm_counter);
349 writeAlpha(boolpolydev->getBitmap(), filename1);
350 writeAlpha(booltextdev->getBitmap(), filename2);
354 msg("<verbose> Bitmap is above current text data");
355 if(layerstate==STATE_PARALLEL) {
356 layerstate=STATE_BITMAP_IS_ABOVE;
358 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
360 layerstate=STATE_BITMAP_IS_ABOVE;
369 //void checkNewText() {
370 // Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
371 // Guchar*charpixels = clip1dev->getBitmap()->getDataPtr();
373 // for(yy=0;yy<height;yy++) {
374 // Guchar*aline = &alpha[yy*width];
375 // Guchar*cline = &charpixels[yy*width8];
376 // for(xx=0;xx<width;xx++) {
378 // int bytepos = xx>>3;
379 // /* TODO: is the bit order correct? */
380 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
387 GBool BitmapOutputDev::clip0and1differ()
389 if(clip0dev->getBitmap()->getMode()==splashModeMono1) {
390 SplashBitmap*clip0 = clip0dev->getBitmap();
391 SplashBitmap*clip1 = clip1dev->getBitmap();
392 int width8 = (clip0->getWidth()+7)/8;
393 int height = clip0->getHeight();
394 return memcmp(clip0->getDataPtr(), clip1->getDataPtr(), width8*height);
396 SplashBitmap*clip0 = clip0dev->getBitmap();
397 SplashBitmap*clip1 = clip1dev->getBitmap();
398 int width = clip0->getAlphaRowSize();
399 int height = clip0->getHeight();
400 return memcmp(clip0->getAlphaPtr(), clip1->getAlphaPtr(), width*height);
404 static void clearBooleanDev(SplashOutputDev*dev)
406 SplashBitmap*btm = dev->getBitmap();
407 if(btm->getMode()==splashModeMono1) {
408 int width8 = (btm->getWidth()+7)/8;
409 int width = btm->getWidth();
410 int height = btm->getHeight();
411 memset(btm->getDataPtr(), 0, width8*height);
413 int width = btm->getAlphaRowSize();
414 int height = btm->getHeight();
415 memset(btm->getAlphaPtr(), 0, width*height);
419 GBool BitmapOutputDev::intersection()
421 SplashBitmap*boolpoly = boolpolydev->getBitmap();
422 SplashBitmap*booltext = booltextdev->getBitmap();
424 if(boolpoly->getMode()==splashModeMono1) {
425 /* alternative implementation, using one bit per pixel-
426 would work if xpdf wouldn't try to dither everything */
428 Guchar*polypixels = boolpoly->getDataPtr();
429 Guchar*textpixels = booltext->getDataPtr();
431 int width8 = (width+7)/8;
432 int height = boolpoly->getHeight();
435 int len = height*width8;
437 if(len & (sizeof(unsigned int)-1)) {
440 c2 |= polypixels[t]&textpixels[t];
444 len /= sizeof(unsigned int);
446 c |= (((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]);
450 /* if graphic data and the characters overlap, they have common bits */
455 Guchar*polypixels = boolpoly->getAlphaPtr();
456 Guchar*textpixels = booltext->getAlphaPtr();
458 int width = boolpoly->getAlphaRowSize();
459 int height = boolpoly->getHeight();
462 int len = height*width;
464 if(len & (sizeof(unsigned int)-1)) {
467 if(polypixels[t]&&textpixels[t])
471 len /= sizeof(unsigned int);
473 if((((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]))
482 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
485 state->transform(crop_x1,crop_y1,&x1,&y1);
486 state->transform(crop_x2,crop_y2,&x2,&y2);
487 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
488 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
490 this->movex = -(int)x1 - user_movex;
491 this->movey = -(int)y1 - user_movey;
493 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
499 this->width = (int)(x2-x1);
500 this->height = (int)(y2-y1);
502 msg("<debug> startPage");
503 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
504 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
505 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
506 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
507 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
508 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
510 flushText(); // write out the initial clipping rectangle
512 /* just in case any device did draw a white background rectangle
517 this->layerstate = STATE_PARALLEL;
520 void BitmapOutputDev::endPage()
522 msg("<verbose> endPage (BitmapOutputDev)");
524 if(layerstate == STATE_BITMAP_IS_ABOVE) {
532 /* splash will now destroy alpha, and paint the
533 background color into the "holes" in the bitmap */
534 boolpolydev->endPage();
535 booltextdev->endPage();
542 GBool BitmapOutputDev::upsideDown()
544 boolpolydev->upsideDown();
545 booltextdev->upsideDown();
546 clip0dev->upsideDown();
547 clip1dev->upsideDown();
548 return rgbdev->upsideDown();
551 GBool BitmapOutputDev::useDrawChar()
553 boolpolydev->useDrawChar();
554 booltextdev->useDrawChar();
555 clip0dev->useDrawChar();
556 clip1dev->useDrawChar();
557 return rgbdev->useDrawChar();
560 GBool BitmapOutputDev::useTilingPatternFill()
562 boolpolydev->useTilingPatternFill();
563 booltextdev->useTilingPatternFill();
564 clip0dev->useTilingPatternFill();
565 clip1dev->useTilingPatternFill();
566 return rgbdev->useTilingPatternFill();
569 GBool BitmapOutputDev::useShadedFills()
571 boolpolydev->useShadedFills();
572 booltextdev->useShadedFills();
573 clip0dev->useShadedFills();
574 clip1dev->useShadedFills();
575 return rgbdev->useShadedFills();
578 GBool BitmapOutputDev::useDrawForm()
580 boolpolydev->useDrawForm();
581 booltextdev->useDrawForm();
582 clip0dev->useDrawForm();
583 clip1dev->useDrawForm();
584 return rgbdev->useDrawForm();
587 GBool BitmapOutputDev::interpretType3Chars()
589 boolpolydev->interpretType3Chars();
590 booltextdev->interpretType3Chars();
591 clip0dev->interpretType3Chars();
592 clip1dev->interpretType3Chars();
593 return rgbdev->interpretType3Chars();
596 GBool BitmapOutputDev::needNonText()
598 boolpolydev->needNonText();
599 booltextdev->needNonText();
600 clip0dev->needNonText();
601 clip1dev->needNonText();
602 return rgbdev->needNonText();
604 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
605 int rotate, GBool useMediaBox, GBool crop,
606 int sliceX, int sliceY, int sliceW, int sliceH,
607 GBool printing, Catalog *catalog,
608 GBool (*abortCheckCbk)(void *data),
609 void *abortCheckCbkData)
613 void BitmapOutputDev::setDefaultCTM(double *ctm)
615 boolpolydev->setDefaultCTM(ctm);
616 booltextdev->setDefaultCTM(ctm);
617 rgbdev->setDefaultCTM(ctm);
618 clip0dev->setDefaultCTM(ctm);
619 clip1dev->setDefaultCTM(ctm);
620 gfxdev->setDefaultCTM(ctm);
622 void BitmapOutputDev::saveState(GfxState *state)
624 boolpolydev->saveState(state);
625 booltextdev->saveState(state);
626 rgbdev->saveState(state);
627 clip0dev->saveState(state);
628 clip1dev->saveState(state);
630 /*ClipState*cstate = new ClipState();
631 cstate->next = this->clipstates;
632 this->clipstates = cstate;*/
634 void BitmapOutputDev::restoreState(GfxState *state)
636 boolpolydev->restoreState(state);
637 booltextdev->restoreState(state);
638 rgbdev->restoreState(state);
639 clip0dev->restoreState(state);
640 clip1dev->restoreState(state);
642 /*if(this->clipstates) {
643 ClipState*old = this->clipstates;
645 gfxdev->restoreState(state);
647 this->clipstates = this->clipstates->next;
650 msg("<error> invalid restoreState()");
653 void BitmapOutputDev::updateAll(GfxState *state)
655 boolpolydev->updateAll(state);
656 booltextdev->updateAll(state);
657 rgbdev->updateAll(state);
658 clip0dev->updateAll(state);
659 clip1dev->updateAll(state);
660 gfxdev->updateAll(state);
662 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
664 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
665 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
666 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
667 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
668 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
669 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
671 void BitmapOutputDev::updateLineDash(GfxState *state)
673 boolpolydev->updateLineDash(state);
674 booltextdev->updateLineDash(state);
675 rgbdev->updateLineDash(state);
676 clip0dev->updateLineDash(state);
677 clip1dev->updateLineDash(state);
678 gfxdev->updateLineDash(state);
680 void BitmapOutputDev::updateFlatness(GfxState *state)
682 boolpolydev->updateFlatness(state);
683 booltextdev->updateFlatness(state);
684 rgbdev->updateFlatness(state);
685 clip0dev->updateFlatness(state);
686 clip1dev->updateFlatness(state);
687 gfxdev->updateFlatness(state);
689 void BitmapOutputDev::updateLineJoin(GfxState *state)
691 boolpolydev->updateLineJoin(state);
692 booltextdev->updateLineJoin(state);
693 rgbdev->updateLineJoin(state);
694 clip0dev->updateLineJoin(state);
695 clip1dev->updateLineJoin(state);
696 gfxdev->updateLineJoin(state);
698 void BitmapOutputDev::updateLineCap(GfxState *state)
700 boolpolydev->updateLineCap(state);
701 booltextdev->updateLineCap(state);
702 rgbdev->updateLineCap(state);
703 clip0dev->updateLineCap(state);
704 clip1dev->updateLineCap(state);
705 gfxdev->updateLineCap(state);
707 void BitmapOutputDev::updateMiterLimit(GfxState *state)
709 boolpolydev->updateMiterLimit(state);
710 booltextdev->updateMiterLimit(state);
711 rgbdev->updateMiterLimit(state);
712 clip0dev->updateMiterLimit(state);
713 clip1dev->updateMiterLimit(state);
714 gfxdev->updateMiterLimit(state);
716 void BitmapOutputDev::updateLineWidth(GfxState *state)
718 boolpolydev->updateLineWidth(state);
719 booltextdev->updateLineWidth(state);
720 rgbdev->updateLineWidth(state);
721 clip0dev->updateLineWidth(state);
722 clip1dev->updateLineWidth(state);
723 gfxdev->updateLineWidth(state);
725 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
727 boolpolydev->updateStrokeAdjust(state);
728 booltextdev->updateStrokeAdjust(state);
729 rgbdev->updateStrokeAdjust(state);
730 clip0dev->updateStrokeAdjust(state);
731 clip1dev->updateStrokeAdjust(state);
732 gfxdev->updateStrokeAdjust(state);
734 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
736 boolpolydev->updateFillColorSpace(state);
737 booltextdev->updateFillColorSpace(state);
738 rgbdev->updateFillColorSpace(state);
739 clip0dev->updateFillColorSpace(state);
740 clip1dev->updateFillColorSpace(state);
741 gfxdev->updateFillColorSpace(state);
743 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
745 boolpolydev->updateStrokeColorSpace(state);
746 booltextdev->updateStrokeColorSpace(state);
747 rgbdev->updateStrokeColorSpace(state);
748 clip0dev->updateStrokeColorSpace(state);
749 clip1dev->updateStrokeColorSpace(state);
750 gfxdev->updateStrokeColorSpace(state);
752 void BitmapOutputDev::updateFillColor(GfxState *state)
754 boolpolydev->updateFillColor(state);
755 booltextdev->updateFillColor(state);
756 rgbdev->updateFillColor(state);
757 clip0dev->updateFillColor(state);
758 clip1dev->updateFillColor(state);
759 gfxdev->updateFillColor(state);
761 void BitmapOutputDev::updateStrokeColor(GfxState *state)
763 boolpolydev->updateStrokeColor(state);
764 booltextdev->updateStrokeColor(state);
765 rgbdev->updateStrokeColor(state);
766 clip0dev->updateStrokeColor(state);
767 clip1dev->updateStrokeColor(state);
768 gfxdev->updateStrokeColor(state);
770 void BitmapOutputDev::updateBlendMode(GfxState *state)
772 boolpolydev->updateBlendMode(state);
773 booltextdev->updateBlendMode(state);
774 rgbdev->updateBlendMode(state);
775 clip0dev->updateBlendMode(state);
776 clip1dev->updateBlendMode(state);
777 gfxdev->updateBlendMode(state);
779 void BitmapOutputDev::updateFillOpacity(GfxState *state)
781 boolpolydev->updateFillOpacity(state);
782 booltextdev->updateFillOpacity(state);
783 rgbdev->updateFillOpacity(state);
784 clip0dev->updateFillOpacity(state);
785 clip1dev->updateFillOpacity(state);
786 gfxdev->updateFillOpacity(state);
788 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
790 boolpolydev->updateStrokeOpacity(state);
791 booltextdev->updateStrokeOpacity(state);
792 rgbdev->updateStrokeOpacity(state);
793 clip0dev->updateStrokeOpacity(state);
794 clip1dev->updateStrokeOpacity(state);
795 gfxdev->updateStrokeOpacity(state);
797 void BitmapOutputDev::updateFillOverprint(GfxState *state)
799 boolpolydev->updateFillOverprint(state);
800 booltextdev->updateFillOverprint(state);
801 rgbdev->updateFillOverprint(state);
802 clip0dev->updateFillOverprint(state);
803 clip1dev->updateFillOverprint(state);
804 gfxdev->updateFillOverprint(state);
806 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
808 boolpolydev->updateStrokeOverprint(state);
809 booltextdev->updateStrokeOverprint(state);
810 rgbdev->updateStrokeOverprint(state);
811 clip0dev->updateStrokeOverprint(state);
812 clip1dev->updateStrokeOverprint(state);
813 gfxdev->updateStrokeOverprint(state);
815 void BitmapOutputDev::updateTransfer(GfxState *state)
817 boolpolydev->updateTransfer(state);
818 booltextdev->updateTransfer(state);
819 rgbdev->updateTransfer(state);
820 clip0dev->updateTransfer(state);
821 clip1dev->updateTransfer(state);
822 gfxdev->updateTransfer(state);
824 void BitmapOutputDev::updateFont(GfxState *state)
826 boolpolydev->updateFont(state);
827 booltextdev->updateFont(state);
828 rgbdev->updateFont(state);
829 clip0dev->updateFont(state);
830 clip1dev->updateFont(state);
831 gfxdev->updateFont(state);
833 void BitmapOutputDev::updateTextMat(GfxState *state)
835 boolpolydev->updateTextMat(state);
836 booltextdev->updateTextMat(state);
837 rgbdev->updateTextMat(state);
838 clip0dev->updateTextMat(state);
839 clip1dev->updateTextMat(state);
840 gfxdev->updateTextMat(state);
842 void BitmapOutputDev::updateCharSpace(GfxState *state)
844 boolpolydev->updateCharSpace(state);
845 booltextdev->updateCharSpace(state);
846 rgbdev->updateCharSpace(state);
847 clip0dev->updateCharSpace(state);
848 clip1dev->updateCharSpace(state);
849 gfxdev->updateCharSpace(state);
851 void BitmapOutputDev::updateRender(GfxState *state)
853 boolpolydev->updateRender(state);
854 booltextdev->updateRender(state);
855 rgbdev->updateRender(state);
856 clip0dev->updateRender(state);
857 clip1dev->updateRender(state);
858 gfxdev->updateRender(state);
860 void BitmapOutputDev::updateRise(GfxState *state)
862 boolpolydev->updateRise(state);
863 booltextdev->updateRise(state);
864 rgbdev->updateRise(state);
865 clip0dev->updateRise(state);
866 clip1dev->updateRise(state);
867 gfxdev->updateRise(state);
869 void BitmapOutputDev::updateWordSpace(GfxState *state)
871 boolpolydev->updateWordSpace(state);
872 booltextdev->updateWordSpace(state);
873 rgbdev->updateWordSpace(state);
874 clip0dev->updateWordSpace(state);
875 clip1dev->updateWordSpace(state);
876 gfxdev->updateWordSpace(state);
878 void BitmapOutputDev::updateHorizScaling(GfxState *state)
880 boolpolydev->updateHorizScaling(state);
881 booltextdev->updateHorizScaling(state);
882 rgbdev->updateHorizScaling(state);
883 clip0dev->updateHorizScaling(state);
884 clip1dev->updateHorizScaling(state);
885 gfxdev->updateHorizScaling(state);
887 void BitmapOutputDev::updateTextPos(GfxState *state)
889 boolpolydev->updateTextPos(state);
890 booltextdev->updateTextPos(state);
891 rgbdev->updateTextPos(state);
892 clip0dev->updateTextPos(state);
893 clip1dev->updateTextPos(state);
894 gfxdev->updateTextPos(state);
896 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
898 boolpolydev->updateTextShift(state, shift);
899 booltextdev->updateTextShift(state, shift);
900 rgbdev->updateTextShift(state, shift);
901 clip0dev->updateTextShift(state, shift);
902 clip1dev->updateTextShift(state, shift);
903 gfxdev->updateTextShift(state, shift);
906 void BitmapOutputDev::stroke(GfxState *state)
908 msg("<debug> stroke");
909 boolpolydev->stroke(state);
911 rgbdev->stroke(state);
913 void BitmapOutputDev::fill(GfxState *state)
916 boolpolydev->fill(state);
920 void BitmapOutputDev::eoFill(GfxState *state)
922 msg("<debug> eoFill");
923 boolpolydev->eoFill(state);
925 rgbdev->eoFill(state);
927 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
928 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
929 int paintType, Dict *resDict,
930 double *mat, double *bbox,
931 int x0, int y0, int x1, int y1,
932 double xStep, double yStep)
934 msg("<debug> tilingPatternFill");
935 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
937 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
940 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
941 int paintType, Dict *resDict,
942 double *mat, double *bbox,
943 int x0, int y0, int x1, int y1,
944 double xStep, double yStep)
946 msg("<debug> tilingPatternFill");
947 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
949 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
953 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
955 msg("<debug> functionShadedFill");
956 boolpolydev->functionShadedFill(state, shading);
958 return rgbdev->functionShadedFill(state, shading);
960 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
962 msg("<debug> axialShadedFill");
963 boolpolydev->axialShadedFill(state, shading);
965 return rgbdev->axialShadedFill(state, shading);
967 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
969 msg("<debug> radialShadedFill");
970 boolpolydev->radialShadedFill(state, shading);
972 return rgbdev->radialShadedFill(state, shading);
975 SplashColor black = {0,0,0};
976 SplashColor white = {255,255,255};
978 void BitmapOutputDev::clip(GfxState *state)
981 boolpolydev->clip(state);
982 booltextdev->clip(state);
984 clip1dev->clip(state);
986 void BitmapOutputDev::eoClip(GfxState *state)
988 msg("<debug> eoClip");
989 boolpolydev->eoClip(state);
990 booltextdev->eoClip(state);
991 rgbdev->eoClip(state);
992 clip1dev->eoClip(state);
994 void BitmapOutputDev::clipToStrokePath(GfxState *state)
996 msg("<debug> clipToStrokePath");
997 boolpolydev->clipToStrokePath(state);
998 booltextdev->clipToStrokePath(state);
999 rgbdev->clipToStrokePath(state);
1000 clip1dev->clipToStrokePath(state);
1003 void BitmapOutputDev::beginStringOp(GfxState *state)
1005 msg("<debug> beginStringOp");
1006 clip0dev->beginStringOp(state);
1007 clip1dev->beginStringOp(state);
1008 booltextdev->beginStringOp(state);
1009 gfxdev->beginStringOp(state);
1011 void BitmapOutputDev::endStringOp(GfxState *state)
1013 msg("<debug> endStringOp");
1014 clip0dev->endStringOp(state);
1015 clip1dev->endStringOp(state);
1016 booltextdev->endStringOp(state);
1018 gfxdev->endStringOp(state);
1020 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1022 msg("<debug> beginString");
1023 clip0dev->beginString(state, s);
1024 clip1dev->beginString(state, s);
1025 booltextdev->beginString(state, s);
1026 gfxdev->beginString(state, s);
1028 void BitmapOutputDev::endString(GfxState *state)
1030 msg("<debug> endString");
1031 clip0dev->endString(state);
1032 clip1dev->endString(state);
1033 booltextdev->endString(state);
1035 gfxdev->endString(state);
1038 void BitmapOutputDev::clearClips()
1040 clearBooleanDev(clip0dev);
1041 clearBooleanDev(clip1dev);
1043 void BitmapOutputDev::clearBoolPolyDev()
1045 clearBooleanDev(boolpolydev);
1047 void BitmapOutputDev::clearBoolTextDev()
1049 clearBooleanDev(booltextdev);
1051 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1052 double dx, double dy,
1053 double originX, double originY,
1054 CharCode code, int nBytes, Unicode *u, int uLen)
1056 msg("<debug> drawChar");
1057 if(state->getRender()&4 /*clip*/ ) {
1058 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1061 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1062 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1064 /* if this character is affected somehow by the various clippings (i.e., it looks
1065 different on a device without clipping), then draw it on the bitmap, not as
1067 if(clip0and1differ()) {
1068 msg("<verbose> Char %d is affected by clipping", code);
1069 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1071 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1072 if(config_extrafontdata) {
1073 int oldrender = state->getRender();
1074 state->setRender(3); //invisible
1075 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1076 state->setRender(oldrender);
1079 /* this char is not at all affected by clipping.
1080 Now just dump out the bitmap we're currently working on, if necessary. */
1081 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1083 /* use polygonal output device to do the actual text handling */
1084 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1088 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1090 msg("<error> internal error: drawString not implemented");
1092 clip0dev->drawString(state, s);
1093 clip1dev->drawString(state, s);
1094 booltextdev->drawString(state, s);
1095 gfxdev->drawString(state, s);
1097 void BitmapOutputDev::endTextObject(GfxState *state)
1099 msg("<debug> endTextObject");
1100 clip0dev->endTextObject(state);
1101 clip1dev->endTextObject(state);
1102 booltextdev->endTextObject(state);
1104 gfxdev->endTextObject(state);
1107 /* TODO: these four operations below *should* do nothing, as type3
1108 chars are drawn using operations like fill() */
1109 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1110 double dx, double dy,
1111 CharCode code, Unicode *u, int uLen)
1113 msg("<debug> beginType3Char");
1114 /* call gfxdev so that it can generate "invisible" characters
1115 on top of the actual graphic content, for text extraction */
1116 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1118 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1120 msg("<debug> type3D0");
1121 return gfxdev->type3D0(state, wx, wy);
1123 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1125 msg("<debug> type3D1");
1126 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1128 void BitmapOutputDev::endType3Char(GfxState *state)
1130 msg("<debug> endType3Char");
1131 gfxdev->endType3Char(state);
1133 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1134 int width, int height, GBool invert,
1137 msg("<debug> drawImageMask");
1138 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1140 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1142 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1143 int width, int height, GfxImageColorMap *colorMap,
1144 int *maskColors, GBool inlineImg)
1146 msg("<debug> drawImage");
1147 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1149 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1151 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1152 int width, int height,
1153 GfxImageColorMap *colorMap,
1154 Stream *maskStr, int maskWidth, int maskHeight,
1157 msg("<debug> drawMaskedImage");
1158 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1160 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1162 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1163 int width, int height,
1164 GfxImageColorMap *colorMap,
1166 int maskWidth, int maskHeight,
1167 GfxImageColorMap *maskColorMap)
1169 msg("<debug> drawSoftMaskedImage");
1170 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1172 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1174 void BitmapOutputDev::drawForm(Ref id)
1176 msg("<debug> drawForm");
1177 boolpolydev->drawForm(id);
1179 rgbdev->drawForm(id);
1182 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1184 msg("<debug> processLink");
1185 gfxdev->processLink(link, catalog);
1188 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1189 GfxColorSpace *blendingColorSpace,
1190 GBool isolated, GBool knockout,
1193 msg("<debug> beginTransparencyGroup");
1194 GfxState*state1 = state->copy(gTrue);
1195 GfxState*state2 = state->copy(gTrue);
1196 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1197 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1198 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1202 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1204 msg("<debug> endTransparencyGroup");
1205 GfxState*state1 = state->copy(gTrue);
1206 GfxState*state2 = state->copy(gTrue);
1207 boolpolydev->endTransparencyGroup(state1);
1209 rgbdev->endTransparencyGroup(state2);
1212 clip1dev->endTransparencyGroup(state);
1214 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1216 msg("<debug> paintTransparencyGroup");
1217 boolpolydev->paintTransparencyGroup(state,bbox);
1219 rgbdev->paintTransparencyGroup(state,bbox);
1220 clip1dev->paintTransparencyGroup(state,bbox);
1222 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1224 msg("<debug> setSoftMask");
1225 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1227 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1228 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1230 void BitmapOutputDev::clearSoftMask(GfxState *state)
1232 msg("<debug> clearSoftMask");
1233 boolpolydev->clearSoftMask(state);
1235 rgbdev->clearSoftMask(state);
1236 clip1dev->clearSoftMask(state);