Hello,While working on some JFreeChart demos, I noticed a bug with PdfGraphics2D when filling shapes with a cyclic GradientPaint (I use iText 2.0.2 currently). I found this has already been reported at SourceForge as bug 1534739. I created a small test app to reproduce the problem, which for some reason I can't attach to the bug report - so I've attached the source file (and PDF output) to this e-mail.
Let me know if you need any further info... Regards, Dave Gilbert http://www.jfree.org/
import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.Image; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.FileOutputStream; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfWriter; /** * Test case for cyclic GradientPaint bug in iText 2.0.2. */ public class GradientPaintBug { /** * Default constructor. */ public GradientPaintBug() { } /** * Creates the test PDF output. */ public void writeTestPDF() { Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream( "GradientPaintBug.pdf")); doc.open(); doc.add(new Paragraph("This image shows a cyclic GradientPaint:")); com.lowagie.text.Image img = com.lowagie.text.Image.getInstance( createTestImage(), null); doc.add(img); doc.add(new Paragraph("Here is the same drawing created with " + "PdfGraphics2D, but the 'cyclic' flag is ignored:")); PdfContentByte cb = writer.getDirectContent(); Rectangle size = doc.getPageSize(); Graphics2D g2 = cb.createGraphics(size.width(), size.height()); draw(g2, new Rectangle2D.Double(doc.leftMargin(), doc.topMargin() + 120, 200, 50)); g2.dispose(); } catch (Exception e) { e.printStackTrace(); } doc.close(); } /** * Creates an image showing the correct behaviour for a cyclic * GradientPaint fill. * * @return The image. */ private Image createTestImage() { BufferedImage image = new BufferedImage(200, 50, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); draw(g2, new Rectangle2D.Double(0, 0, 200, 50)); return image; } /** * Drawing code used for both the embedded image and the PdfGraphics2D * drawing. * * @param g2 the drawing target. * @param area the area to fill. */ private void draw(Graphics2D g2, Rectangle2D area) { // create cyclic gradient paint GradientPaint gp = new GradientPaint((float) area.getMinX(), (float) area.getCenterY(), Color.yellow, (float) area.getCenterX(), (float) area.getCenterY(), Color.red, true); g2.setPaint(gp); g2.fill(area); } /** * Entry point for test app. * * @param args ignored. */ public static void main(String[] args) { GradientPaintBug app = new GradientPaintBug(); app.writeTestPDF(); } }
GradientPaintBug.pdf
Description: Adobe PDF document
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/