+ SplashBitmap*clip0 = clip0dev->getBitmap();
+ SplashBitmap*clip1 = clip1dev->getBitmap();
+ int width8 = (clip0->getWidth()+7)/8;
+ int width = clip0->getWidth();
+ int height = clip0->getHeight();
+ memset(clip0->getDataPtr(), 0, width8*height);
+ memset(clip1->getDataPtr(), 0, width8*height);
+ clip0dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+ clip1dev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+
+ /* if this character is affected somehow by the various clippings (i.e., it looks
+ different on a device without clipping), then draw it on the bitmap, not as
+ text */
+ if(memcmp(clip0->getDataPtr(), clip1->getDataPtr(), width8*height)) {
+ msg("<verbose> Char %d is affected by clipping", code);
+
+ rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+ if(config_extrafontdata) {
+ int oldrender = state->getRender();
+ state->setRender(3); //invisible
+ gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+ state->setRender(oldrender);
+ }
+ } else {
+ /* this char is not at all affected by clipping. Now just find out whether the
+ bitmap we're currently working on needs to be dumped out first */
+
+ Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
+ Guchar*charpixels = clip1dev->getBitmap()->getDataPtr();
+ int xx,yy;
+ for(yy=0;yy<height;yy++) {
+ Guchar*aline = &alpha[yy*width];
+ Guchar*cline = &charpixels[yy*width8];
+ for(xx=0;xx<width;xx++) {
+ int bit = xx&7;
+ int bytepos = xx>>3;
+ /* TODO: is the bit order correct? */
+ if(aline[xx] && (cline[bytepos]&(1<<bit)))
+ break;
+ }
+ if(xx!=width)
+ break;
+ }
+
+ if(yy!=height) {
+ /* yes, the graphic data and the characters overlap (the char is
+ above the current bitmap. Flush the bitmap to the output. */
+ msg("<verbose> Char %d is above current bitmap data", code);
+ flush();
+ }
+ gfxdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+ }