Does the PdfGraphics2D support translucent GradientPaints?

(And/or: where should I be looking if I want to engineer this support?)

Below is a simple test case demonstrating that gradients appear to  
ignore the opacity of colors.

I'm assuming this boils down to PdfShading.java in the getColorArray()  
method, where the alpha channel appears to be dropped.  But if I add  
the alpha channel back in, then that entry becomes a 4-color array,  
which is probably confused with a CMYK array.  I haven't found the  
entity responsible for decoding this data...

Any pointers/thoughts?

Regards,
  - Jeremy

package com.t4l.pdf;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class TestCase {
        public static void main(String[] args) {
                try {
                        TestCase demo = new TestCase();
                        demo.write();
                        demo.finish();
                } catch(Throwable t) {
                        t.printStackTrace();
                }
        }

        File tempDest;
        Document doc = new Document();
        PdfWriter writer;
        FileOutputStream out;

        public TestCase() throws IOException, DocumentException {
                tempDest = new File("deleteme.pdf");
                out = new FileOutputStream(tempDest);
                writer = PdfWriter.getInstance(doc, out);
                writer.setPdfVersion(PdfWriter.VERSION_1_6);

                doc.setPageSize(PageSize.A4);
                Insets margins = new Insets(36,36,36,36);
                doc.setMargins(margins.left, margins.right, margins.top,  
margins.bottom);
        }

        public void write() {
                if(doc.isOpen()==false) {
                        doc.open();
                } else {
                        doc.newPage();
                }

                PdfContentByte cb = writer.getDirectContent();
                Graphics2D g = cb.createGraphics(600, 600);

                g.setPaint(new GradientPaint(0,0, new 
Color(0,255,0,80),250,250,new  
Color(0,0,255,80)));
                g.fillRect(0,0,250,250);

                g.setPaint(new Color(255,0,0,100));
                g.fillRect(250,250,250,250);

                g.dispose();
        }

        public void finish() {
                doc.close();
                writer.flush();
        }
}



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to