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 GBool BitmapOutputDev::intersection()
445 SplashBitmap*boolpoly = boolpolybitmap;
446 SplashBitmap*booltext = booltextbitmap;
448 if(boolpoly->getMode()==splashModeMono1) {
449 /* alternative implementation, using one bit per pixel-
450 would work if xpdf wouldn't try to dither everything */
452 Guchar*polypixels = boolpoly->getDataPtr();
453 Guchar*textpixels = booltext->getDataPtr();
455 int width8 = (width+7)/8;
456 int height = boolpoly->getHeight();
459 int len = height*width8;
461 if(len & (sizeof(unsigned int)-1)) {
464 c2 |= polypixels[t]&textpixels[t];
468 len /= sizeof(unsigned int);
470 c |= (((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]);
474 /* if graphic data and the characters overlap, they have common bits */
479 Guchar*polypixels = boolpoly->getAlphaPtr();
480 Guchar*textpixels = booltext->getAlphaPtr();
482 int width = boolpoly->getAlphaRowSize();
483 int height = boolpoly->getHeight();
486 int len = height*width;
488 if(len & (sizeof(unsigned int)-1)) {
491 if(polypixels[t]&&textpixels[t])
495 len /= sizeof(unsigned int);
497 if((((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]))
506 void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
509 state->transform(crop_x1,crop_y1,&x1,&y1);
510 state->transform(crop_x2,crop_y2,&x2,&y2);
511 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
512 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
514 this->movex = -(int)x1 - user_movex;
515 this->movey = -(int)y1 - user_movey;
517 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
523 this->width = (int)(x2-x1);
524 this->height = (int)(y2-y1);
526 msg("<debug> startPage");
527 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
528 boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
529 booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
530 clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
531 clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
532 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
534 boolpolybitmap = boolpolydev->getBitmap();
535 booltextbitmap = booltextdev->getBitmap();
536 clip0bitmap = clip0dev->getBitmap();
537 clip1bitmap = clip1dev->getBitmap();
538 rgbbitmap = rgbdev->getBitmap();
540 flushText(); // write out the initial clipping rectangle
542 /* just in case any device did draw a white background rectangle
547 this->layerstate = STATE_PARALLEL;
549 msg("<debug> startPage done");
552 void BitmapOutputDev::endPage()
554 msg("<verbose> endPage (BitmapOutputDev)");
556 /* notice: we're not fully done yet with this page- there might still be
557 a few calls to drawLink() yet to come */
559 void BitmapOutputDev::finishPage()
561 msg("<verbose> finishPage (BitmapOutputDev)");
564 if(layerstate == STATE_BITMAP_IS_ABOVE) {
572 /* splash will now destroy alpha, and paint the
573 background color into the "holes" in the bitmap */
574 boolpolydev->endPage();
575 booltextdev->endPage();
581 GBool BitmapOutputDev::upsideDown()
583 boolpolydev->upsideDown();
584 booltextdev->upsideDown();
585 clip0dev->upsideDown();
586 clip1dev->upsideDown();
587 return rgbdev->upsideDown();
590 GBool BitmapOutputDev::useDrawChar()
592 boolpolydev->useDrawChar();
593 booltextdev->useDrawChar();
594 clip0dev->useDrawChar();
595 clip1dev->useDrawChar();
596 return rgbdev->useDrawChar();
599 GBool BitmapOutputDev::useTilingPatternFill()
601 boolpolydev->useTilingPatternFill();
602 booltextdev->useTilingPatternFill();
603 clip0dev->useTilingPatternFill();
604 clip1dev->useTilingPatternFill();
605 return rgbdev->useTilingPatternFill();
608 GBool BitmapOutputDev::useShadedFills()
610 boolpolydev->useShadedFills();
611 booltextdev->useShadedFills();
612 clip0dev->useShadedFills();
613 clip1dev->useShadedFills();
614 return rgbdev->useShadedFills();
617 GBool BitmapOutputDev::useDrawForm()
619 boolpolydev->useDrawForm();
620 booltextdev->useDrawForm();
621 clip0dev->useDrawForm();
622 clip1dev->useDrawForm();
623 return rgbdev->useDrawForm();
626 GBool BitmapOutputDev::interpretType3Chars()
628 boolpolydev->interpretType3Chars();
629 booltextdev->interpretType3Chars();
630 clip0dev->interpretType3Chars();
631 clip1dev->interpretType3Chars();
632 return rgbdev->interpretType3Chars();
635 GBool BitmapOutputDev::needNonText()
637 boolpolydev->needNonText();
638 booltextdev->needNonText();
639 clip0dev->needNonText();
640 clip1dev->needNonText();
641 return rgbdev->needNonText();
643 /*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
644 int rotate, GBool useMediaBox, GBool crop,
645 int sliceX, int sliceY, int sliceW, int sliceH,
646 GBool printing, Catalog *catalog,
647 GBool (*abortCheckCbk)(void *data),
648 void *abortCheckCbkData)
652 void BitmapOutputDev::setDefaultCTM(double *ctm)
654 boolpolydev->setDefaultCTM(ctm);
655 booltextdev->setDefaultCTM(ctm);
656 rgbdev->setDefaultCTM(ctm);
657 clip0dev->setDefaultCTM(ctm);
658 clip1dev->setDefaultCTM(ctm);
659 gfxdev->setDefaultCTM(ctm);
661 void BitmapOutputDev::saveState(GfxState *state)
663 boolpolydev->saveState(state);
664 booltextdev->saveState(state);
665 rgbdev->saveState(state);
666 clip0dev->saveState(state);
667 clip1dev->saveState(state);
669 /*ClipState*cstate = new ClipState();
670 cstate->next = this->clipstates;
671 this->clipstates = cstate;*/
673 void BitmapOutputDev::restoreState(GfxState *state)
675 boolpolydev->restoreState(state);
676 booltextdev->restoreState(state);
677 rgbdev->restoreState(state);
678 clip0dev->restoreState(state);
679 clip1dev->restoreState(state);
681 /*if(this->clipstates) {
682 ClipState*old = this->clipstates;
684 gfxdev->restoreState(state);
686 this->clipstates = this->clipstates->next;
689 msg("<error> invalid restoreState()");
692 void BitmapOutputDev::updateAll(GfxState *state)
694 boolpolydev->updateAll(state);
695 booltextdev->updateAll(state);
696 rgbdev->updateAll(state);
697 clip0dev->updateAll(state);
698 clip1dev->updateAll(state);
699 gfxdev->updateAll(state);
701 void BitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
703 boolpolydev->updateCTM(state,m11,m12,m21,m22,m31,m32);
704 booltextdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
705 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
706 clip0dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
707 clip1dev->updateCTM(state,m11,m12,m21,m22,m31,m32);
708 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
710 void BitmapOutputDev::updateLineDash(GfxState *state)
712 boolpolydev->updateLineDash(state);
713 booltextdev->updateLineDash(state);
714 rgbdev->updateLineDash(state);
715 clip0dev->updateLineDash(state);
716 clip1dev->updateLineDash(state);
717 gfxdev->updateLineDash(state);
719 void BitmapOutputDev::updateFlatness(GfxState *state)
721 boolpolydev->updateFlatness(state);
722 booltextdev->updateFlatness(state);
723 rgbdev->updateFlatness(state);
724 clip0dev->updateFlatness(state);
725 clip1dev->updateFlatness(state);
726 gfxdev->updateFlatness(state);
728 void BitmapOutputDev::updateLineJoin(GfxState *state)
730 boolpolydev->updateLineJoin(state);
731 booltextdev->updateLineJoin(state);
732 rgbdev->updateLineJoin(state);
733 clip0dev->updateLineJoin(state);
734 clip1dev->updateLineJoin(state);
735 gfxdev->updateLineJoin(state);
737 void BitmapOutputDev::updateLineCap(GfxState *state)
739 boolpolydev->updateLineCap(state);
740 booltextdev->updateLineCap(state);
741 rgbdev->updateLineCap(state);
742 clip0dev->updateLineCap(state);
743 clip1dev->updateLineCap(state);
744 gfxdev->updateLineCap(state);
746 void BitmapOutputDev::updateMiterLimit(GfxState *state)
748 boolpolydev->updateMiterLimit(state);
749 booltextdev->updateMiterLimit(state);
750 rgbdev->updateMiterLimit(state);
751 clip0dev->updateMiterLimit(state);
752 clip1dev->updateMiterLimit(state);
753 gfxdev->updateMiterLimit(state);
755 void BitmapOutputDev::updateLineWidth(GfxState *state)
757 boolpolydev->updateLineWidth(state);
758 booltextdev->updateLineWidth(state);
759 rgbdev->updateLineWidth(state);
760 clip0dev->updateLineWidth(state);
761 clip1dev->updateLineWidth(state);
762 gfxdev->updateLineWidth(state);
764 void BitmapOutputDev::updateStrokeAdjust(GfxState *state)
766 boolpolydev->updateStrokeAdjust(state);
767 booltextdev->updateStrokeAdjust(state);
768 rgbdev->updateStrokeAdjust(state);
769 clip0dev->updateStrokeAdjust(state);
770 clip1dev->updateStrokeAdjust(state);
771 gfxdev->updateStrokeAdjust(state);
773 void BitmapOutputDev::updateFillColorSpace(GfxState *state)
775 boolpolydev->updateFillColorSpace(state);
776 booltextdev->updateFillColorSpace(state);
777 rgbdev->updateFillColorSpace(state);
778 clip0dev->updateFillColorSpace(state);
779 clip1dev->updateFillColorSpace(state);
780 gfxdev->updateFillColorSpace(state);
782 void BitmapOutputDev::updateStrokeColorSpace(GfxState *state)
784 boolpolydev->updateStrokeColorSpace(state);
785 booltextdev->updateStrokeColorSpace(state);
786 rgbdev->updateStrokeColorSpace(state);
787 clip0dev->updateStrokeColorSpace(state);
788 clip1dev->updateStrokeColorSpace(state);
789 gfxdev->updateStrokeColorSpace(state);
791 void BitmapOutputDev::updateFillColor(GfxState *state)
793 boolpolydev->updateFillColor(state);
794 booltextdev->updateFillColor(state);
795 rgbdev->updateFillColor(state);
796 clip0dev->updateFillColor(state);
797 clip1dev->updateFillColor(state);
798 gfxdev->updateFillColor(state);
800 void BitmapOutputDev::updateStrokeColor(GfxState *state)
802 boolpolydev->updateStrokeColor(state);
803 booltextdev->updateStrokeColor(state);
804 rgbdev->updateStrokeColor(state);
805 clip0dev->updateStrokeColor(state);
806 clip1dev->updateStrokeColor(state);
807 gfxdev->updateStrokeColor(state);
809 void BitmapOutputDev::updateBlendMode(GfxState *state)
811 boolpolydev->updateBlendMode(state);
812 booltextdev->updateBlendMode(state);
813 rgbdev->updateBlendMode(state);
814 clip0dev->updateBlendMode(state);
815 clip1dev->updateBlendMode(state);
816 gfxdev->updateBlendMode(state);
818 void BitmapOutputDev::updateFillOpacity(GfxState *state)
820 boolpolydev->updateFillOpacity(state);
821 booltextdev->updateFillOpacity(state);
822 rgbdev->updateFillOpacity(state);
823 clip0dev->updateFillOpacity(state);
824 clip1dev->updateFillOpacity(state);
825 gfxdev->updateFillOpacity(state);
827 void BitmapOutputDev::updateStrokeOpacity(GfxState *state)
829 boolpolydev->updateStrokeOpacity(state);
830 booltextdev->updateStrokeOpacity(state);
831 rgbdev->updateStrokeOpacity(state);
832 clip0dev->updateStrokeOpacity(state);
833 clip1dev->updateStrokeOpacity(state);
834 gfxdev->updateStrokeOpacity(state);
836 void BitmapOutputDev::updateFillOverprint(GfxState *state)
838 boolpolydev->updateFillOverprint(state);
839 booltextdev->updateFillOverprint(state);
840 rgbdev->updateFillOverprint(state);
841 clip0dev->updateFillOverprint(state);
842 clip1dev->updateFillOverprint(state);
843 gfxdev->updateFillOverprint(state);
845 void BitmapOutputDev::updateStrokeOverprint(GfxState *state)
847 boolpolydev->updateStrokeOverprint(state);
848 booltextdev->updateStrokeOverprint(state);
849 rgbdev->updateStrokeOverprint(state);
850 clip0dev->updateStrokeOverprint(state);
851 clip1dev->updateStrokeOverprint(state);
852 gfxdev->updateStrokeOverprint(state);
854 void BitmapOutputDev::updateTransfer(GfxState *state)
856 boolpolydev->updateTransfer(state);
857 booltextdev->updateTransfer(state);
858 rgbdev->updateTransfer(state);
859 clip0dev->updateTransfer(state);
860 clip1dev->updateTransfer(state);
861 gfxdev->updateTransfer(state);
863 void BitmapOutputDev::updateFont(GfxState *state)
865 boolpolydev->updateFont(state);
866 booltextdev->updateFont(state);
867 rgbdev->updateFont(state);
868 clip0dev->updateFont(state);
869 clip1dev->updateFont(state);
870 gfxdev->updateFont(state);
872 void BitmapOutputDev::updateTextMat(GfxState *state)
874 boolpolydev->updateTextMat(state);
875 booltextdev->updateTextMat(state);
876 rgbdev->updateTextMat(state);
877 clip0dev->updateTextMat(state);
878 clip1dev->updateTextMat(state);
879 gfxdev->updateTextMat(state);
881 void BitmapOutputDev::updateCharSpace(GfxState *state)
883 boolpolydev->updateCharSpace(state);
884 booltextdev->updateCharSpace(state);
885 rgbdev->updateCharSpace(state);
886 clip0dev->updateCharSpace(state);
887 clip1dev->updateCharSpace(state);
888 gfxdev->updateCharSpace(state);
890 void BitmapOutputDev::updateRender(GfxState *state)
892 boolpolydev->updateRender(state);
893 booltextdev->updateRender(state);
894 rgbdev->updateRender(state);
895 clip0dev->updateRender(state);
896 clip1dev->updateRender(state);
897 gfxdev->updateRender(state);
899 void BitmapOutputDev::updateRise(GfxState *state)
901 boolpolydev->updateRise(state);
902 booltextdev->updateRise(state);
903 rgbdev->updateRise(state);
904 clip0dev->updateRise(state);
905 clip1dev->updateRise(state);
906 gfxdev->updateRise(state);
908 void BitmapOutputDev::updateWordSpace(GfxState *state)
910 boolpolydev->updateWordSpace(state);
911 booltextdev->updateWordSpace(state);
912 rgbdev->updateWordSpace(state);
913 clip0dev->updateWordSpace(state);
914 clip1dev->updateWordSpace(state);
915 gfxdev->updateWordSpace(state);
917 void BitmapOutputDev::updateHorizScaling(GfxState *state)
919 boolpolydev->updateHorizScaling(state);
920 booltextdev->updateHorizScaling(state);
921 rgbdev->updateHorizScaling(state);
922 clip0dev->updateHorizScaling(state);
923 clip1dev->updateHorizScaling(state);
924 gfxdev->updateHorizScaling(state);
926 void BitmapOutputDev::updateTextPos(GfxState *state)
928 boolpolydev->updateTextPos(state);
929 booltextdev->updateTextPos(state);
930 rgbdev->updateTextPos(state);
931 clip0dev->updateTextPos(state);
932 clip1dev->updateTextPos(state);
933 gfxdev->updateTextPos(state);
935 void BitmapOutputDev::updateTextShift(GfxState *state, double shift)
937 boolpolydev->updateTextShift(state, shift);
938 booltextdev->updateTextShift(state, shift);
939 rgbdev->updateTextShift(state, shift);
940 clip0dev->updateTextShift(state, shift);
941 clip1dev->updateTextShift(state, shift);
942 gfxdev->updateTextShift(state, shift);
945 void BitmapOutputDev::stroke(GfxState *state)
947 msg("<debug> stroke");
948 boolpolydev->stroke(state);
950 rgbdev->stroke(state);
952 void BitmapOutputDev::fill(GfxState *state)
955 boolpolydev->fill(state);
959 void BitmapOutputDev::eoFill(GfxState *state)
961 msg("<debug> eoFill");
962 boolpolydev->eoFill(state);
964 rgbdev->eoFill(state);
966 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
967 void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
968 int paintType, Dict *resDict,
969 double *mat, double *bbox,
970 int x0, int y0, int x1, int y1,
971 double xStep, double yStep)
973 msg("<debug> tilingPatternFill");
974 boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
976 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
979 void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
980 int paintType, Dict *resDict,
981 double *mat, double *bbox,
982 int x0, int y0, int x1, int y1,
983 double xStep, double yStep)
985 msg("<debug> tilingPatternFill");
986 boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
988 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
992 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
994 msg("<debug> functionShadedFill");
995 boolpolydev->functionShadedFill(state, shading);
997 return rgbdev->functionShadedFill(state, shading);
999 GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
1001 msg("<debug> axialShadedFill");
1002 boolpolydev->axialShadedFill(state, shading);
1004 return rgbdev->axialShadedFill(state, shading);
1006 GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
1008 msg("<debug> radialShadedFill");
1009 boolpolydev->radialShadedFill(state, shading);
1011 return rgbdev->radialShadedFill(state, shading);
1014 SplashColor black = {0,0,0};
1015 SplashColor white = {255,255,255};
1017 void BitmapOutputDev::clip(GfxState *state)
1019 msg("<debug> clip");
1020 boolpolydev->clip(state);
1021 booltextdev->clip(state);
1022 rgbdev->clip(state);
1023 clip1dev->clip(state);
1025 void BitmapOutputDev::eoClip(GfxState *state)
1027 msg("<debug> eoClip");
1028 boolpolydev->eoClip(state);
1029 booltextdev->eoClip(state);
1030 rgbdev->eoClip(state);
1031 clip1dev->eoClip(state);
1033 void BitmapOutputDev::clipToStrokePath(GfxState *state)
1035 msg("<debug> clipToStrokePath");
1036 boolpolydev->clipToStrokePath(state);
1037 booltextdev->clipToStrokePath(state);
1038 rgbdev->clipToStrokePath(state);
1039 clip1dev->clipToStrokePath(state);
1042 void BitmapOutputDev::beginStringOp(GfxState *state)
1044 msg("<debug> beginStringOp");
1045 clip0dev->beginStringOp(state);
1046 clip1dev->beginStringOp(state);
1047 booltextdev->beginStringOp(state);
1048 gfxdev->beginStringOp(state);
1050 void BitmapOutputDev::endStringOp(GfxState *state)
1052 msg("<debug> endStringOp");
1053 clip0dev->endStringOp(state);
1054 clip1dev->endStringOp(state);
1055 booltextdev->endStringOp(state);
1057 gfxdev->endStringOp(state);
1059 void BitmapOutputDev::beginString(GfxState *state, GString *s)
1061 msg("<debug> beginString");
1062 clip0dev->beginString(state, s);
1063 clip1dev->beginString(state, s);
1064 booltextdev->beginString(state, s);
1065 gfxdev->beginString(state, s);
1067 void BitmapOutputDev::endString(GfxState *state)
1069 msg("<debug> endString");
1070 clip0dev->endString(state);
1071 clip1dev->endString(state);
1072 booltextdev->endString(state);
1074 gfxdev->endString(state);
1077 void BitmapOutputDev::clearClips()
1079 clearBooleanBitmap(clip0bitmap);
1080 clearBooleanBitmap(clip1bitmap);
1082 void BitmapOutputDev::clearBoolPolyDev()
1084 clearBooleanBitmap(boolpolybitmap);
1086 void BitmapOutputDev::clearBoolTextDev()
1088 clearBooleanBitmap(booltextbitmap);
1090 void BitmapOutputDev::drawChar(GfxState *state, double x, double y,
1091 double dx, double dy,
1092 double originX, double originY,
1093 CharCode code, int nBytes, Unicode *u, int uLen)
1095 msg("<debug> drawChar");
1096 if(state->getRender()&RENDER_CLIP) {
1097 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1100 clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1101 clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1103 /* if this character is affected somehow by the various clippings (i.e., it looks
1104 different on a device without clipping), then draw it on the bitmap, not as
1106 if(clip0and1differ()) {
1107 msg("<verbose> Char %d is affected by clipping", code);
1108 boolpolydev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1110 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1111 if(config_extrafontdata) {
1112 int oldrender = state->getRender();
1113 state->setRender(3); //invisible
1114 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1115 state->setRender(oldrender);
1118 /* this char is not at all affected by clipping.
1119 Now just dump out the bitmap we're currently working on, if necessary. */
1120 booltextdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1122 /* use polygonal output device to do the actual text handling */
1123 gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
1127 void BitmapOutputDev::drawString(GfxState *state, GString *s)
1129 msg("<error> internal error: drawString not implemented");
1131 clip0dev->drawString(state, s);
1132 clip1dev->drawString(state, s);
1133 booltextdev->drawString(state, s);
1134 gfxdev->drawString(state, s);
1136 void BitmapOutputDev::endTextObject(GfxState *state)
1138 msg("<debug> endTextObject");
1139 rgbdev->endTextObject(state);
1140 clip0dev->endTextObject(state);
1141 clip1dev->endTextObject(state);
1142 booltextdev->endTextObject(state);
1144 gfxdev->endTextObject(state);
1147 /* TODO: these four operations below *should* do nothing, as type3
1148 chars are drawn using operations like fill() */
1149 GBool BitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
1150 double dx, double dy,
1151 CharCode code, Unicode *u, int uLen)
1153 msg("<debug> beginType3Char");
1154 /* call gfxdev so that it can generate "invisible" characters
1155 on top of the actual graphic content, for text extraction */
1156 return gfxdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
1158 void BitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
1160 msg("<debug> type3D0");
1161 return gfxdev->type3D0(state, wx, wy);
1163 void BitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
1165 msg("<debug> type3D1");
1166 return gfxdev->type3D1(state, wx, wy, llx, lly, urx, ury);
1168 void BitmapOutputDev::endType3Char(GfxState *state)
1170 msg("<debug> endType3Char");
1171 gfxdev->endType3Char(state);
1174 class CopyStream: public Object
1178 MemStream*memstream;
1180 CopyStream(Stream*str, int len)
1185 buf = (char*)malloc(len);
1187 for (t=0; t<len; t++)
1188 buf[t] = str->getChar();
1191 this->dict = str->getDict();
1192 this->memstream = new MemStream(buf, 0, len, this);
1196 ::free(this->buf);this->buf = 0;
1197 delete this->memstream;
1199 Dict* getDict() {return dict;}
1200 Stream* getStream() {return this->memstream;};
1203 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
1204 int width, int height, GBool invert,
1207 msg("<debug> drawImageMask streamkind=%d", str->getKind());
1208 CopyStream*cpystr = 0;
1210 cpystr = new CopyStream(str, height * ((width + 7) / 8));
1211 str = cpystr->getStream();
1213 boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1215 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
1219 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
1220 int width, int height, GfxImageColorMap *colorMap,
1221 int *maskColors, GBool inlineImg)
1223 msg("<debug> drawImage streamkind=%d", str->getKind());
1224 CopyStream*cpystr = 0;
1226 cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
1227 str = cpystr->getStream();
1229 boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1231 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
1235 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
1236 int width, int height,
1237 GfxImageColorMap *colorMap,
1238 Stream *maskStr, int maskWidth, int maskHeight,
1241 msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
1242 boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1244 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
1246 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
1247 int width, int height,
1248 GfxImageColorMap *colorMap,
1250 int maskWidth, int maskHeight,
1251 GfxImageColorMap *maskColorMap)
1253 msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
1254 boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1256 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
1258 void BitmapOutputDev::drawForm(Ref id)
1260 msg("<debug> drawForm");
1261 boolpolydev->drawForm(id);
1263 rgbdev->drawForm(id);
1266 void BitmapOutputDev::processLink(Link *link, Catalog *catalog)
1268 msg("<debug> processLink");
1269 gfxdev->processLink(link, catalog);
1272 void BitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
1273 GfxColorSpace *blendingColorSpace,
1274 GBool isolated, GBool knockout,
1277 msg("<debug> beginTransparencyGroup");
1278 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1279 GfxState*state1 = state->copy();
1280 GfxState*state2 = state->copy();
1282 state1->setPath(state->getPath()->copy());
1284 state2->setPath(state->getPath()->copy());
1286 GfxState*state1 = state->copy(gTrue);
1287 GfxState*state2 = state->copy(gTrue);
1289 boolpolydev->beginTransparencyGroup(state1, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1290 rgbdev->beginTransparencyGroup(state2, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1291 clip1dev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
1295 void BitmapOutputDev::endTransparencyGroup(GfxState *state)
1297 msg("<debug> endTransparencyGroup");
1298 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
1299 GfxState*state1 = state->copy();
1300 GfxState*state2 = state->copy();
1302 state1->setPath(state->getPath()->copy());
1304 state2->setPath(state->getPath()->copy());
1306 GfxState*state1 = state->copy(gTrue);
1307 GfxState*state2 = state->copy(gTrue);
1309 boolpolydev->endTransparencyGroup(state1);
1311 rgbdev->endTransparencyGroup(state2);
1314 clip1dev->endTransparencyGroup(state);
1316 void BitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
1318 msg("<debug> paintTransparencyGroup");
1319 boolpolydev->paintTransparencyGroup(state,bbox);
1321 rgbdev->paintTransparencyGroup(state,bbox);
1322 clip1dev->paintTransparencyGroup(state,bbox);
1324 void BitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
1326 msg("<debug> setSoftMask");
1327 boolpolydev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1329 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1330 clip1dev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
1332 void BitmapOutputDev::clearSoftMask(GfxState *state)
1334 msg("<debug> clearSoftMask");
1335 boolpolydev->clearSoftMask(state);
1337 rgbdev->clearSoftMask(state);
1338 clip1dev->clearSoftMask(state);