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_bitmapfonts = 0;
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;
96 if(this->boolpolydev) {
97 delete this->boolpolydev;this->boolpolydev = 0;
100 delete this->clip0dev;this->clip0dev = 0;
103 delete this->clip1dev;this->clip1dev = 0;
105 //if(this->clipbitmap) {
106 // delete this->clipbitmap;this->clipbitmap = 0;
108 //if(this->clipdev) {
109 // delete this->clipdev;this->clipdev = 0;
114 GBool BitmapOutputDev::getVectorAntialias()
116 return this->rgbdev->getVectorAntialias();
118 void BitmapOutputDev::setVectorAntialias(GBool vaa)
120 this->rgbdev->setVectorAntialias(vaa);
122 void BitmapOutputDev::setDevice(gfxdevice_t*dev)
126 void BitmapOutputDev::setMove(int x,int y)
128 this->gfxdev->setMove(x,y);
129 this->user_movex = x;
130 this->user_movey = y;
132 void BitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
134 this->gfxdev->setClip(x1,y1,x2,y2);
135 this->user_clipx1 = x1;
136 this->user_clipy1 = y1;
137 this->user_clipx2 = x2;
138 this->user_clipy2 = y2;
140 void BitmapOutputDev::setParameter(const char*key, const char*value)
142 if(!strcmp(key, "extrafontdata")) {
143 this->config_extrafontdata = atoi(value);
144 } else if(!strcmp(key, "bitmapfonts")) {
145 this->config_bitmapfonts = atoi(value);
147 this->gfxdev->setParameter(key, value);
149 void BitmapOutputDev::preparePage(int pdfpage, int outputpage)
153 void getBitmapBBox(Guchar*alpha, int width, int height, int*xmin, int*ymin, int*xmax, int*ymax)
159 for(y=0;y<height;y++) {
160 Guchar*a = &alpha[y*width];
161 for(x=0;x<width;x++) {
164 int left = x; //first occupied pixel from left
165 int right = x+1; //last non-occupied pixel from right
174 if(left<*xmin) *xmin = left;
175 if(right>*xmax) *xmax = right;
178 if(*xmin>=*xmax || *ymin>=*ymax) {
186 void BitmapOutputDev::flushBitmap()
188 int width = rgbdev->getBitmapWidth();
189 int height = rgbdev->getBitmapHeight();
191 SplashColorPtr rgb = rgbdev->getBitmap()->getDataPtr();
192 Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
194 int xmin,ymin,xmax,ymax;
195 getBitmapBBox(alpha, width, height, &xmin,&ymin,&xmax,&ymax);
197 /* clip against (-movex, -movey, -movex+width, -movey+height) */
198 if(xmin < -this->movex) xmin = -this->movex;
199 if(ymin < -this->movey) ymin = -this->movey;
200 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
201 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
203 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
205 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
208 if(sizeof(SplashColor)!=3) {
209 msg("<error> sizeof(SplashColor)!=3");
216 int rangex = xmax-xmin;
217 int rangey = ymax-ymin;
218 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
219 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
221 img->height = rangey;
223 for(y=0;y<rangey;y++) {
224 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
225 gfxcolor_t*out = &img->data[y*rangex];
226 Guchar*ain = &alpha[(y+ymin)*width+xmin];
227 for(x=0;x<rangex;x++) {
228 /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we
229 have to premultiply alpha (mix background and pixel according to the alpha channel).
231 out[x].r = (in[x*3+0]*ain[x])/255;
232 out[x].g = (in[x*3+1]*ain[x])/255;
233 out[x].b = (in[x*3+2]*ain[x])/255;
237 /* transform bitmap rectangle to "device space" */
249 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
250 dev->fillbitmap(dev, line, img, &m, 0);
253 memset(rgbdev->getBitmap()->getAlphaPtr(), 0, rgbdev->getBitmap()->getWidth()*rgbdev->getBitmap()->getHeight());
254 memset(rgbdev->getBitmap()->getDataPtr(), 0, rgbdev->getBitmap()->getRowSize()*rgbdev->getBitmap()->getHeight());
256 free(img->data);img->data=0;free(img);img=0;
259 void BitmapOutputDev::flushText()
261 msg("<verbose> Flushing text/polygons");
262 gfxdevice_record_flush(this->gfxoutput, this->dev);
265 void writeAlpha(SplashBitmap*bitmap, char*filename)
270 int width = bitmap->getWidth();
271 int height = bitmap->getHeight();
273 gfxcolor_t*data = (gfxcolor_t*)malloc(sizeof(gfxcolor_t)*width*height);
275 for(y=0;y<height;y++) {
276 gfxcolor_t*line = &data[y*width];
277 for(x=0;x<width;x++) {
278 int a = bitmap->getAlpha(x,y);
285 writePNG(filename, (unsigned char*)data, width, height);
288 static int dbg_btm_counter=1;
290 void BitmapOutputDev::checkNewText()
292 /* called once some new text was drawn on booltextdev, and
293 before the same thing is drawn on gfxdev */
295 msg("<debug> Testing new text data against current bitmap data, state=%d, counter=%d\n", layerstate, dbg_btm_counter);
299 sprintf(filename1, "state%dbitmap_newtext.png", dbg_btm_counter);
300 sprintf(filename2, "state%dtext_newtext.png", dbg_btm_counter);
301 writeAlpha(boolpolydev->getBitmap(), filename1);
302 writeAlpha(booltextdev->getBitmap(), filename2);
306 msg("<verbose> Text is above current bitmap/polygon data");
307 if(layerstate==STATE_PARALLEL) {
308 /* the new text is above the bitmap. So record that fact,
309 and also clear the bitmap buffer, so we can check for
311 layerstate=STATE_TEXT_IS_ABOVE;
313 } else if(layerstate==STATE_BITMAP_IS_ABOVE) {
314 /* there's a bitmap above the (old) text. So we need
315 to flush out that text, and record that the *new*
316 text is now *above* the bitmap
319 layerstate=STATE_TEXT_IS_ABOVE;
320 /* clear both bool devices- the text device because
321 we just dumped out all the (old) text, and the
322 poly dev so we can check for new intersections */
326 /* we already know that the current text section is
327 above the current bitmap section- now just new
328 bitmap data *and* new text data was drawn, and
329 *again* it's above the current bitmap- so clear
330 the polygon bitmap again, so we can check for
337 void BitmapOutputDev::checkNewBitmap()
339 /* similar to checkNewText() above, only in reverse */
340 msg("<debug> Testing new graphics data against current text data, state=%d, counter=%d\n", layerstate, dbg_btm_counter);
344 sprintf(filename1, "state%dbitmap_newbitmap.png", dbg_btm_counter);
345 sprintf(filename2, "state%dtext_newbitmap.png", dbg_btm_counter);
346 writeAlpha(boolpolydev->getBitmap(), filename1);
347 writeAlpha(booltextdev->getBitmap(), filename2);
351 msg("<verbose> Bitmap is above current text data");
352 if(layerstate==STATE_PARALLEL) {
353 layerstate=STATE_BITMAP_IS_ABOVE;
355 } else if(layerstate==STATE_TEXT_IS_ABOVE) {
357 layerstate=STATE_BITMAP_IS_ABOVE;
366 //void checkNewText() {
367 // Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
368 // Guchar*charpixels = clip1dev->getBitmap()->getDataPtr();
370 // for(yy=0;yy<height;yy++) {
371 // Guchar*aline = &alpha[yy*width];
372 // Guchar*cline = &charpixels[yy*width8];
373 // for(xx=0;xx<width;xx++) {
375 // int bytepos = xx>>3;
376 // /* TODO: is the bit order correct? */
377 // if(aline[xx] && (cline[bytepos]&(1<<bit)))
384 GBool BitmapOutputDev::clip0and1differ()
386 if(clip0dev->getBitmap()->getMode()==splashModeMono1) {
387 SplashBitmap*clip0 = clip0dev->getBitmap();
388 SplashBitmap*clip1 = clip1dev->getBitmap();
389 int width8 = (clip0->getWidth()+7)/8;
390 int height = clip0->getHeight();
391 return memcmp(clip0->getDataPtr(), clip1->getDataPtr(), width8*height);
393 SplashBitmap*clip0 = clip0dev->getBitmap();
394 SplashBitmap*clip1 = clip1dev->getBitmap();
395 int width = clip0->getAlphaRowSize();
396 int height = clip0->getHeight();
397 return memcmp(clip0->getAlphaPtr(), clip1->getAlphaPtr(), width*height);
401 static void clearBooleanDev(SplashOutputDev*dev)
403 SplashBitmap*btm = dev->getBitmap();
404 if(btm->getMode()==splashModeMono1) {
405 int width8 = (btm->getWidth()+7)/8;
406 int width = btm->getWidth();
407 int height = btm->getHeight();
408 memset(btm->getDataPtr(), 0, width8*height);
410 int width = btm->getAlphaRowSize();
411 int height = btm->getHeight();
412 memset(btm->getAlphaPtr(), 0, width*height);
416 GBool BitmapOutputDev::intersection()
418 SplashBitmap*boolpoly = boolpolydev->getBitmap();
419 SplashBitmap*booltext = booltextdev->getBitmap();
421 if(boolpoly->getMode()==splashModeMono1) {
422 /* alternative implementation, using one bit per pixel-
423 would work if xpdf wouldn't try to dither everything */
425 Guchar*polypixels = boolpoly->getDataPtr();
426 Guchar*textpixels = booltext->getDataPtr();
428 int width8 = (width+7)/8;
429 int height = boolpoly->getHeight();
432 int len = height*width8;
434 if(len & (sizeof(unsigned int)-1)) {
437 c2 |= polypixels[t]&textpixels[t];
441 len /= sizeof(unsigned int);
443 c |= (((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]);
447 /* if graphic data and the characters overlap, they have common bits */
452 Guchar*polypixels = boolpoly->getAlphaPtr();
453 Guchar*textpixels = booltext->getAlphaPtr();
455 int width = boolpoly->getAlphaRowSize();
456 int height = boolpoly->getHeight();
459 int len = height*width;
461 if(len & (sizeof(unsigned int)-1)) {
464 if(polypixels[t]&&textpixels[t])
468 len /= sizeof(unsigned int);
470 if((((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]))
479 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
482 state->transform(crop_x1,crop_y1,&x1,&y1);
483 state->transform(crop_x2,crop_y2,&x2,&y2);
484 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
485 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
487 this->movex = -(int)x1 - user_movex;
488 this->movey = -(int)y1 - user_movey;
490 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
496 this->width = (int)(x2-x1);
497 this->height = (int)(y2-y1);
499 msg("<verbose> startPage");
500 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
501 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
502 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
503 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
504 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
505 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
507 flushText(); // write out the initial clipping rectangle
509 /* just in case any device did draw a white background rectangle
514 this->layerstate = STATE_PARALLEL;
517 void BitmapOutputDev::endPage()
519 msg("<verbose> endPage (BitmapOutputDev)");
521 if(layerstate == STATE_BITMAP_IS_ABOVE) {
529 /* splash will now destroy alpha, and paint the
530 background color into the "holes" in the bitmap */
531 boolpolydev->endPage();
532 booltextdev->endPage();
539 GBool BitmapOutputDev::upsideDown()
541 boolpolydev->upsideDown();
542 booltextdev->upsideDown();
543 clip0dev->upsideDown();
544 clip1dev->upsideDown();
545 return rgbdev->upsideDown();
548 GBool BitmapOutputDev::useDrawChar()
550 boolpolydev->useDrawChar();
551 booltextdev->useDrawChar();
552 clip0dev->useDrawChar();
553 clip1dev->useDrawChar();
554 return rgbdev->useDrawChar();
557 GBool BitmapOutputDev::useTilingPatternFill()
559 boolpolydev->useTilingPatternFill();
560 booltextdev->useTilingPatternFill();
561 clip0dev->useTilingPatternFill();
562 clip1dev->useTilingPatternFill();
563 return rgbdev->useTilingPatternFill();
566 GBool BitmapOutputDev::useShadedFills()
568 boolpolydev->useShadedFills();
569 booltextdev->useShadedFills();
570 clip0dev->useShadedFills();
571 clip1dev->useShadedFills();
572 return rgbdev->useShadedFills();
575 GBool BitmapOutputDev::useDrawForm()
577 boolpolydev->useDrawForm();
578 booltextdev->useDrawForm();
579 clip0dev->useDrawForm();
580 clip1dev->useDrawForm();
581 return rgbdev->useDrawForm();
584 GBool BitmapOutputDev::interpretType3Chars()
586 if(!config_bitmapfonts) {
587 boolpolydev->interpretType3Chars();
588 booltextdev->interpretType3Chars();
589 clip0dev->interpretType3Chars();
590 clip1dev->interpretType3Chars();
591 return rgbdev->interpretType3Chars();
593 return gfxdev->interpretType3Chars();
597 GBool BitmapOutputDev::needNonText()
599 boolpolydev->needNonText();
600 booltextdev->needNonText();
601 clip0dev->needNonText();
602 clip1dev->needNonText();
603 return rgbdev->needNonText();
605 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
606 int rotate, GBool useMediaBox, GBool crop,
607 int sliceX, int sliceY, int sliceW, int sliceH,
608 GBool printing, Catalog *catalog,
609 GBool (*abortCheckCbk)(void *data),
610 void *abortCheckCbkData)
614 void BitmapOutputDev::setDefaultCTM(double *ctm)
616 boolpolydev->setDefaultCTM(ctm);
617 booltextdev->setDefaultCTM(ctm);
618 rgbdev->setDefaultCTM(ctm);
619 clip0dev->setDefaultCTM(ctm);
620 clip1dev->setDefaultCTM(ctm);
621 //gfxdev->setDefaultCTM(ctm);//?
623 void BitmapOutputDev::saveState(GfxState *state)
625 boolpolydev->saveState(state);
626 booltextdev->saveState(state);
627 rgbdev->saveState(state);
628 clip0dev->saveState(state);
629 clip1dev->saveState(state);
631 /*ClipState*cstate = new ClipState();
632 cstate->next = this->clipstates;
633 this->clipstates = cstate;*/
635 void BitmapOutputDev::restoreState(GfxState *state)
637 boolpolydev->restoreState(state);
638 booltextdev->restoreState(state);
639 rgbdev->restoreState(state);
640 clip0dev->restoreState(state);
641 clip1dev->restoreState(state);
643 /*if(this->clipstates) {
644 ClipState*old = this->clipstates;
646 gfxdev->restoreState(state);
648 this->clipstates = this->clipstates->next;
651 msg("<error> invalid restoreState()");
654 void BitmapOutputDev::updateAll(GfxState *state)
656 boolpolydev->updateAll(state);
657 booltextdev->updateAll(state);
658 rgbdev->updateAll(state);
659 clip0dev->updateAll(state);
660 clip1dev->updateAll(state);
661 if(!config_bitmapfonts)
662 gfxdev->updateAll(state);
664 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
666 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
667 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
668 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
669 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
670 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
671 if(!config_bitmapfonts)
672 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
674 void BitmapOutputDev::updateLineDash(GfxState *state)
676 boolpolydev->updateLineDash(state);
677 booltextdev->updateLineDash(state);
678 rgbdev->updateLineDash(state);
679 clip0dev->updateLineDash(state);
680 clip1dev->updateLineDash(state);
681 if(!config_bitmapfonts)
682 gfxdev->updateLineDash(state);
684 void BitmapOutputDev::updateFlatness(GfxState *state)
686 boolpolydev->updateFlatness(state);
687 booltextdev->updateFlatness(state);
688 rgbdev->updateFlatness(state);
689 clip0dev->updateFlatness(state);
690 clip1dev->updateFlatness(state);
691 if(!config_bitmapfonts)
692 gfxdev->updateFlatness(state);
694 void BitmapOutputDev::updateLineJoin(GfxState *state)
696 boolpolydev->updateLineJoin(state);
697 booltextdev->updateLineJoin(state);
698 rgbdev->updateLineJoin(state);
699 clip0dev->updateLineJoin(state);
700 clip1dev->updateLineJoin(state);
701 if(!config_bitmapfonts)
702 gfxdev->updateLineJoin(state);
704 void BitmapOutputDev::updateLineCap(GfxState *state)
706 boolpolydev->updateLineCap(state);
707 booltextdev->updateLineCap(state);
708 rgbdev->updateLineCap(state);
709 clip0dev->updateLineCap(state);
710 clip1dev->updateLineCap(state);
711 if(!config_bitmapfonts)
712 gfxdev->updateLineCap(state);
714 void BitmapOutputDev::updateMiterLimit(GfxState *state)
716 boolpolydev->updateMiterLimit(state);
717 booltextdev->updateMiterLimit(state);
718 rgbdev->updateMiterLimit(state);
719 clip0dev->updateMiterLimit(state);
720 clip1dev->updateMiterLimit(state);
721 if(!config_bitmapfonts)
722 gfxdev->updateMiterLimit(state);
724 void BitmapOutputDev::updateLineWidth(GfxState *state)
726 boolpolydev->updateLineWidth(state);
727 booltextdev->updateLineWidth(state);
728 rgbdev->updateLineWidth(state);
729 clip0dev->updateLineWidth(state);
730 clip1dev->updateLineWidth(state);
731 if(!config_bitmapfonts)
732 gfxdev->updateLineWidth(state);
734 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
736 boolpolydev->updateStrokeAdjust(state);
737 booltextdev->updateStrokeAdjust(state);
738 rgbdev->updateStrokeAdjust(state);
739 clip0dev->updateStrokeAdjust(state);
740 clip1dev->updateStrokeAdjust(state);
741 if(!config_bitmapfonts)
742 gfxdev->updateStrokeAdjust(state);
744 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
746 boolpolydev->updateFillColorSpace(state);
747 booltextdev->updateFillColorSpace(state);
748 rgbdev->updateFillColorSpace(state);
749 clip0dev->updateFillColorSpace(state);
750 clip1dev->updateFillColorSpace(state);
751 if(!config_bitmapfonts)
752 gfxdev->updateFillColorSpace(state);
754 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
756 boolpolydev->updateStrokeColorSpace(state);
757 booltextdev->updateStrokeColorSpace(state);
758 rgbdev->updateStrokeColorSpace(state);
759 clip0dev->updateStrokeColorSpace(state);
760 clip1dev->updateStrokeColorSpace(state);
761 if(!config_bitmapfonts)
762 gfxdev->updateStrokeColorSpace(state);
764 void BitmapOutputDev::updateFillColor(GfxState *state)
766 boolpolydev->updateFillColor(state);
767 booltextdev->updateFillColor(state);
768 rgbdev->updateFillColor(state);
769 clip0dev->updateFillColor(state);
770 clip1dev->updateFillColor(state);
771 if(!config_bitmapfonts)
772 gfxdev->updateFillColor(state);
774 void BitmapOutputDev::updateStrokeColor(GfxState *state)
776 boolpolydev->updateStrokeColor(state);
777 booltextdev->updateStrokeColor(state);
778 rgbdev->updateStrokeColor(state);
779 clip0dev->updateStrokeColor(state);
780 clip1dev->updateStrokeColor(state);
781 if(!config_bitmapfonts)
782 gfxdev->updateStrokeColor(state);
784 void BitmapOutputDev::updateBlendMode(GfxState *state)
786 boolpolydev->updateBlendMode(state);
787 booltextdev->updateBlendMode(state);
788 rgbdev->updateBlendMode(state);
789 clip0dev->updateBlendMode(state);
790 clip1dev->updateBlendMode(state);
791 if(!config_bitmapfonts)
792 gfxdev->updateBlendMode(state);
794 void BitmapOutputDev::updateFillOpacity(GfxState *state)
796 boolpolydev->updateFillOpacity(state);
797 booltextdev->updateFillOpacity(state);
798 rgbdev->updateFillOpacity(state);
799 clip0dev->updateFillOpacity(state);
800 clip1dev->updateFillOpacity(state);
801 if(!config_bitmapfonts)
802 gfxdev->updateFillOpacity(state);
804 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
806 boolpolydev->updateStrokeOpacity(state);
807 booltextdev->updateStrokeOpacity(state);
808 rgbdev->updateStrokeOpacity(state);
809 clip0dev->updateStrokeOpacity(state);
810 clip1dev->updateStrokeOpacity(state);
811 if(!config_bitmapfonts)
812 gfxdev->updateStrokeOpacity(state);
814 void BitmapOutputDev::updateFillOverprint(GfxState *state)
816 boolpolydev->updateFillOverprint(state);
817 booltextdev->updateFillOverprint(state);
818 rgbdev->updateFillOverprint(state);
819 clip0dev->updateFillOverprint(state);
820 clip1dev->updateFillOverprint(state);
821 if(!config_bitmapfonts)
822 gfxdev->updateFillOverprint(state);
824 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
826 boolpolydev->updateStrokeOverprint(state);
827 booltextdev->updateStrokeOverprint(state);
828 rgbdev->updateStrokeOverprint(state);
829 clip0dev->updateStrokeOverprint(state);
830 clip1dev->updateStrokeOverprint(state);
831 if(!config_bitmapfonts)
832 gfxdev->updateStrokeOverprint(state);
834 void BitmapOutputDev::updateTransfer(GfxState *state)
836 boolpolydev->updateTransfer(state);
837 booltextdev->updateTransfer(state);
838 rgbdev->updateTransfer(state);
839 clip0dev->updateTransfer(state);
840 clip1dev->updateTransfer(state);
841 if(!config_bitmapfonts)
842 gfxdev->updateTransfer(state);
844 void BitmapOutputDev::updateFont(GfxState *state)
846 boolpolydev->updateFont(state);
847 booltextdev->updateFont(state);
848 rgbdev->updateFont(state);
849 clip0dev->updateFont(state);
850 clip1dev->updateFont(state);
851 if(!config_bitmapfonts)
852 gfxdev->updateFont(state);
854 void BitmapOutputDev::updateTextMat(GfxState *state)
856 boolpolydev->updateTextMat(state);
857 booltextdev->updateTextMat(state);
858 rgbdev->updateTextMat(state);
859 clip0dev->updateTextMat(state);
860 clip1dev->updateTextMat(state);
861 if(!config_bitmapfonts)
862 gfxdev->updateTextMat(state);
864 void BitmapOutputDev::updateCharSpace(GfxState *state)
866 boolpolydev->updateCharSpace(state);
867 booltextdev->updateCharSpace(state);
868 rgbdev->updateCharSpace(state);
869 clip0dev->updateCharSpace(state);
870 clip1dev->updateCharSpace(state);
871 if(!config_bitmapfonts)
872 gfxdev->updateCharSpace(state);
874 void BitmapOutputDev::updateRender(GfxState *state)
876 boolpolydev->updateRender(state);
877 booltextdev->updateRender(state);
878 rgbdev->updateRender(state);
879 clip0dev->updateRender(state);
880 clip1dev->updateRender(state);
881 if(!config_bitmapfonts)
882 gfxdev->updateRender(state);
884 void BitmapOutputDev::updateRise(GfxState *state)
886 boolpolydev->updateRise(state);
887 booltextdev->updateRise(state);
888 rgbdev->updateRise(state);
889 clip0dev->updateRise(state);
890 clip1dev->updateRise(state);
891 if(!config_bitmapfonts)
892 gfxdev->updateRise(state);
894 void BitmapOutputDev::updateWordSpace(GfxState *state)
896 boolpolydev->updateWordSpace(state);
897 booltextdev->updateWordSpace(state);
898 rgbdev->updateWordSpace(state);
899 clip0dev->updateWordSpace(state);
900 clip1dev->updateWordSpace(state);
901 if(!config_bitmapfonts)
902 gfxdev->updateWordSpace(state);
904 void BitmapOutputDev::updateHorizScaling(GfxState *state)
906 boolpolydev->updateHorizScaling(state);
907 booltextdev->updateHorizScaling(state);
908 rgbdev->updateHorizScaling(state);
909 clip0dev->updateHorizScaling(state);
910 clip1dev->updateHorizScaling(state);
911 if(!config_bitmapfonts)
912 gfxdev->updateHorizScaling(state);
914 void BitmapOutputDev::updateTextPos(GfxState *state)
916 boolpolydev->updateTextPos(state);
917 booltextdev->updateTextPos(state);
918 rgbdev->updateTextPos(state);
919 clip0dev->updateTextPos(state);
920 clip1dev->updateTextPos(state);
921 if(!config_bitmapfonts)
922 gfxdev->updateTextPos(state);
924 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
926 boolpolydev->updateTextShift(state, shift);
927 booltextdev->updateTextShift(state, shift);
928 rgbdev->updateTextShift(state, shift);
929 clip0dev->updateTextShift(state, shift);
930 clip1dev->updateTextShift(state, shift);
931 if(!config_bitmapfonts)
932 gfxdev->updateTextShift(state, shift);
935 void BitmapOutputDev::stroke(GfxState *state)
937 msg("<verbose> stroke");
938 boolpolydev->stroke(state);
940 rgbdev->stroke(state);
942 void BitmapOutputDev::fill(GfxState *state)
944 msg("<verbose> fill");
945 boolpolydev->fill(state);
949 void BitmapOutputDev::eoFill(GfxState *state)
951 msg("<verbose> eoFill");
952 boolpolydev->eoFill(state);
954 rgbdev->eoFill(state);
956 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
957 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
958 int paintType, Dict *resDict,
959 double *mat, double *bbox,
960 int x0, int y0, int x1, int y1,
961 double xStep, double yStep)
963 msg("<verbose> tilingPatternFill");
964 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
966 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
969 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
970 int paintType, Dict *resDict,
971 double *mat, double *bbox,
972 int x0, int y0, int x1, int y1,
973 double xStep, double yStep)
975 msg("<verbose> tilingPatternFill");
976 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
978 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
982 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
984 msg("<verbose> functionShadedFill");
985 boolpolydev->functionShadedFill(state, shading);
987 return rgbdev->functionShadedFill(state, shading);
989 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
991 msg("<verbose> axialShadedFill");
992 boolpolydev->axialShadedFill(state, shading);
994 return rgbdev->axialShadedFill(state, shading);
996 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
998 msg("<verbose> radialShadedFill");
999 boolpolydev->radialShadedFill(state, shading);
1001 return rgbdev->radialShadedFill(state, shading);
1004 SplashColor black = {0,0,0};
1005 SplashColor white = {255,255,255};
1007 void BitmapOutputDev::clip(GfxState *state)
1009 msg("<verbose> clip");
1010 boolpolydev->clip(state);
1011 booltextdev->clip(state);
1012 rgbdev->clip(state);
1013 clip1dev->clip(state);
1015 void BitmapOutputDev::eoClip(GfxState *state)
1017 msg("<verbose> eoClip");
1018 boolpolydev->eoClip(state);
1019 booltextdev->eoClip(state);
1020 rgbdev->eoClip(state);
1021 clip1dev->eoClip(state);
1023 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1025 msg("<verbose> clipToStrokePath");
1026 boolpolydev->clipToStrokePath(state);
1027 booltextdev->clipToStrokePath(state);
1028 rgbdev->clipToStrokePath(state);
1029 clip1dev->clipToStrokePath(state);
1032 void BitmapOutputDev::beginStringOp(GfxState *state)
1034 msg("<verbose> beginStringOp");
1035 if(this->config_bitmapfonts) {
1036 rgbdev->beginStringOp(state);
1037 clip0dev->beginStringOp(state);
1038 clip1dev->beginStringOp(state);
1040 booltextdev->beginStringOp(state);
1041 gfxdev->beginStringOp(state);
1044 void BitmapOutputDev::endStringOp(GfxState *state)
1046 msg("<verbose> endStringOp");
1047 if(this->config_bitmapfonts) {
1048 rgbdev->endStringOp(state);
1049 clip0dev->endStringOp(state);
1050 clip1dev->endStringOp(state);
1052 booltextdev->endStringOp(state);
1054 gfxdev->endStringOp(state);
1057 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1059 msg("<verbose> beginString");
1060 if(this->config_bitmapfonts) {
1061 rgbdev->beginString(state, s);
1062 clip0dev->beginString(state, s);
1063 clip1dev->beginString(state, s);
1065 booltextdev->beginString(state, s);
1066 gfxdev->beginString(state, s);
1069 void BitmapOutputDev::endString(GfxState *state)
1071 msg("<verbose> endString");
1072 if(this->config_bitmapfonts) {
1073 rgbdev->endString(state);
1074 clip0dev->endString(state);
1075 clip1dev->endString(state);
1077 booltextdev->endString(state);
1079 gfxdev->endString(state);
1083 void BitmapOutputDev::clearClips()
1085 clearBooleanDev(clip0dev);
1086 clearBooleanDev(clip1dev);
1088 void BitmapOutputDev::clearBoolPolyDev()
1090 clearBooleanDev(boolpolydev);
1092 void BitmapOutputDev::clearBoolTextDev()
1094 clearBooleanDev(booltextdev);
1096 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1097 double dx, double dy,
1098 double originX, double originY,
1099 CharCode code, int nBytes, Unicode *u, int uLen)
1101 msg("<verbose> drawChar");
1102 if(this->config_bitmapfonts || (state->getRender()&4) /*clip*/ ) {
1103 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1106 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1107 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1109 /* if this character is affected somehow by the various clippings (i.e., it looks
1110 different on a device without clipping), then draw it on the bitmap, not as
1112 if(clip0and1differ()) {
1113 msg("<verbose> Char %d is affected by clipping", code);
1114 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1116 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1117 if(config_extrafontdata) {
1118 int oldrender = state->getRender();
1119 state->setRender(3); //invisible
1120 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1121 state->setRender(oldrender);
1124 /* this char is not at all affected by clipping.
1125 Now just dump out the bitmap we're currently working on, if necessary. */
1126 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1128 /* use polygonal output device to do the actual text handling */
1129 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1133 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1135 msg("<error> internal error: drawString not implemented");
1137 if(this->config_bitmapfonts) {
1138 rgbdev->drawString(state, s);
1139 clip0dev->drawString(state, s);
1140 clip1dev->drawString(state, s);
1142 booltextdev->drawString(state, s);
1143 gfxdev->drawString(state, s);
1146 void BitmapOutputDev::endTextObject(GfxState *state)
1148 /* FIXME: the below might render things (stroke outlines etc.) to gfxdev which
1149 might end up unflushed- should be handled similarily as
1152 msg("<verbose> endTextObject");
1153 if(this->config_bitmapfonts) {
1154 rgbdev->endTextObject(state);
1155 clip0dev->endTextObject(state);
1156 clip1dev->endTextObject(state);
1158 gfxdev->endType3Char(state);
1162 /* TODO: these four operations below *should* do nothing, as type3
1163 chars are drawn using operations like fill() */
1164 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1165 double dx, double dy,
1166 CharCode code, Unicode *u, int uLen)
1168 msg("<verbose> beginType3Char");
1169 if(this->config_bitmapfonts) {
1170 return rgbdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1172 /* call gfxdev so that it can generate "invisible" characters
1173 on top of the actual graphic content, for text extraction */
1174 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1177 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1179 msg("<verbose> type3D0");
1180 if(this->config_bitmapfonts) {
1181 rgbdev->type3D0(state, wx, wy);
1183 return gfxdev->type3D0(state, wx, wy);
1186 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1188 msg("<verbose> type3D1");
1189 if(this->config_bitmapfonts) {
1190 rgbdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1192 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1195 void BitmapOutputDev::endType3Char(GfxState *state)
1197 msg("<verbose> endType3Char");
1198 if(this->config_bitmapfonts) {
1199 rgbdev->endType3Char(state);
1201 gfxdev->endType3Char(state);
1204 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1205 int width, int height, GBool invert,
1208 msg("<verbose> drawImageMask");
1209 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1211 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1213 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1214 int width, int height, GfxImageColorMap *colorMap,
1215 int *maskColors, GBool inlineImg)
1217 msg("<verbose> drawImage");
1218 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1220 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1222 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1223 int width, int height,
1224 GfxImageColorMap *colorMap,
1225 Stream *maskStr, int maskWidth, int maskHeight,
1228 msg("<verbose> drawMaskedImage");
1229 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1231 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1233 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1234 int width, int height,
1235 GfxImageColorMap *colorMap,
1237 int maskWidth, int maskHeight,
1238 GfxImageColorMap *maskColorMap)
1240 msg("<verbose> drawSoftMaskedImage");
1241 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1243 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1245 void BitmapOutputDev::drawForm(Ref id)
1247 msg("<verbose> drawForm");
1248 boolpolydev->drawForm(id);
1250 rgbdev->drawForm(id);
1253 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1255 msg("<verbose> processLink");
1256 gfxdev->processLink(link, catalog);
1259 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1260 GfxColorSpace *blendingColorSpace,
1261 GBool isolated, GBool knockout,
1264 msg("<verbose> beginTransparencyGroup");
1265 rgbdev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1266 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1268 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1270 msg("<verbose> endTransparencyGroup");
1271 boolpolydev->endTransparencyGroup(state);
1273 rgbdev->endTransparencyGroup(state);
1274 clip1dev->endTransparencyGroup(state);
1276 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1278 msg("<verbose> paintTransparencyGroup");
1279 boolpolydev->paintTransparencyGroup(state,bbox);
1281 rgbdev->paintTransparencyGroup(state,bbox);
1283 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1285 msg("<verbose> setSoftMask");
1286 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1288 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1289 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1291 void BitmapOutputDev::clearSoftMask(GfxState *state)
1293 msg("<verbose> clearSoftMask");
1294 boolpolydev->clearSoftMask(state);
1296 rgbdev->clearSoftMask(state);
1297 clip1dev->clearSoftMask(state);