JDK-8080134 : [macosx] Printing LinearGradientPaint and TexturePaint does not work on Mac
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: generic
  • Submitted: 2015-05-08
  • Updated: 2016-08-12
  • Resolved: 2015-05-12
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
1.8.0_45

ADDITIONAL OS VERSION INFORMATION :
OS X Yosemite Version 10.10.3

A DESCRIPTION OF THE PROBLEM :
Printing AWT shapes e.g. Rectangle2D.Double filled with LinearGradientPaint or with TexturePaint does not work on MacOSX. 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the test sample above and print in a PDF document or on any printer.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
There should be printed three rectangles: the first is filled with the "old" GradientPaint, the second is filled with the newer LinearGradientPaint and the third is filled with a TexturePaint.
ACTUAL -
Only the first rectangle with the "old" GradientPaint is printed, the remaining rectangles are missing.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package test;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.LinearGradientPaint;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;


public class PrintTest {
  public static void main(String[] args) throws PrinterException {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable((graphics, pageFormat, pageIndex) -> {
      if (pageIndex != 0) {
        return Printable.NO_SUCH_PAGE;
      }

      float x = 100;
      float y = 100;
      float w = 200;
      float h = 200;

      Graphics2D graphics2D = (Graphics2D) graphics;

      // fill rectangle with GradientPaint
      Rectangle2D rect1 = new Rectangle2D.Double(x, y, w, h);
      Paint fill1 = new GradientPaint(x, y, Color.WHITE, x + w, y + h, Color.RED);
      graphics2D.setPaint(fill1);
      graphics2D.fill(rect1);

      y += h + 20;
      // fill rectangle with LinearGradientPaint
      Rectangle2D rect2 = new Rectangle2D.Double(x, y, w, h);
      Paint fill2 = new LinearGradientPaint(x, y, x + w, y + h,
          new float[]{0.1f, 0.9f}, new Color[]{Color.WHITE, Color.RED});
      graphics2D.setPaint(fill2);
      graphics2D.fill(rect2);

      y += h + 20;
      // fill rectangle with TexturePaint
      Rectangle2D rect3 = new Rectangle2D.Double(x, y, w, h);
      BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
      image.setRGB(0, 0, Color.BLACK.getRGB());
      image.setRGB(0, 1, Color.WHITE.getRGB());
      image.setRGB(1, 0, Color.WHITE.getRGB());
      image.setRGB(1, 1, Color.BLACK.getRGB());
      Paint fill3 = new TexturePaint(image, new Rectangle(2, 2));
      graphics2D.setPaint(fill3);
      graphics2D.fill(rect3);

      return Printable.PAGE_EXISTS;
    });

    if (job.printDialog()) {
      job.print();
    }
  }
}

---------- END SOURCE ----------


Comments
Add to that list RadialGradientPaint as noticed in https://bugs.openjdk.java.net/browse/JDK-8162796
12-08-2016

reproduced on the latest 8u-dev and 9b41
12-05-2015