[PATCH] printing of transparent images

Stephan Kulow coolo at kde.org
Wed Jul 10 18:03:33 BST 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

Printing web sites with black&white images, where white is transparent results
in black on black print outs. As an example check 
http://verein.lst.de/~coolo/printout.html

My suggested patch follows. It hard codes the color to print for transparent 
pixels to white. David is working on an alternative solution, but that would 
require bigger changes in QPSPrinter as it would need to generate PS level 3
to get transparancy in the generated PS. The patch works for me, but I'm
open for suggestions :)

Greetings, Stephan

Index: khtml/rendering/render_image.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_image.cpp,v
retrieving revision 1.97
diff -u -u -r1.97 render_image.cpp
- --- khtml/rendering/render_image.cpp    2002/06/16 11:55:34     1.97
+++ khtml/rendering/render_image.cpp    2002/07/10 16:58:32
@@ -175,6 +175,22 @@
     }
 }

+static QPixmap pixmapForPainter( const QPixmap &pix, QPainter *p)
+{
+    // as postscript doesn't allow transparency, we have to do something 
about it
+    if (pix.mask() && p->device()->devType() == QInternal::Printer) {
+        QImage rsc = pix.convertToImage().convertDepth(8, 0);
+        for (int n = 0; n < rsc.numColors(); n++)
+            if (qAlpha(rsc.color(n)) == 0)
+                rsc.setColor(n, qRgb(255, 255, 255));
+        rsc.setAlphaBuffer(false);
+        QPixmap rscp;
+        rscp.convertFromImage(rsc);
+        return rscp;
+    } else
+        return pix;
+}
+
 void RenderImage::printObject(QPainter *p, int /*_x*/, int /*_y*/, int 
/*_w*/, int /*_h*/, int _tx, int _ty)
 {
     // add offset for relative positioning
@@ -257,7 +273,7 @@
                                resizeCache, scaledrect );
             }
             else
- -                p->drawPixmap( QPoint( _tx + leftBorder + leftPad, _ty + 
topBorder + topPad), resizeCache );
+                p->drawPixmap(QPoint( _tx + leftBorder + leftPad, _ty + 
topBorder + topPad), pixmapForPainter(resizeCache, p));
         }
         else
         {
@@ -280,8 +296,8 @@


 //             p->drawPixmap( offs.x(), y, pix, rect.x(), rect.y(), 
rect.width(), rect.height() );
- -             p->drawPixmap(offs, pix, rect);

+            p->drawPixmap(offs, pixmapForPainter(pix, p), rect);
         }
     }
     if(style()->outlineWidth())
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9LGjpwFSBhlBjoJYRAgsoAKDkkLS5UZz9aVgAHFL0ABD1ZpDzcwCfT0cH
v2Hb82lqmAWjahQAy9lTdxU=
=jSpA
-----END PGP SIGNATURE-----





More information about the kfm-devel mailing list