JDK-8212643 : [macos] Transparency lost on LinearGradient paint when printing to MacOS X printer
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8u181,9,10,11,12
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: os_x
  • CPU: x86
  • Submitted: 2018-10-01
  • Updated: 2019-10-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
I have a LinearGradientPaint with a color that has transparency. This is rendered correctly on screen. When printed to a printer or PDF, the transparency is lost on MacOSX but prints ok in Windows 7 and Windows 10.

REGRESSION : Last worked in version 8u181

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Paint a 2D shape with a LinearGradientPaint. One of the colors should have transparency (alpha value). Use Java print services to print the shape, either to a real printer or PDF.  The transparency is not rendered.  This may also affect RadialGradientPaint.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected that the printed shape would render the same as it appears on screen.
ACTUAL -
Transparency information was lost, shape prints opaque.  See also post to StackOverflow:
https://stackoverflow.com/questions/52488056/transparency-lost-on-lineargradient-paint-when-printing-to-macos-x-printer-using


---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.print.*;
import javax.swing.*;

public class TestGradient {

    public static class TwoRectangles extends JComponent {

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D)g;
        g2d.setColor(Color.RED);
        g2d.fillRect(0, 75, 500, 150);  //paint a red opaque rectangle

        LinearGradientPaint p = new LinearGradientPaint(50, 100, 500, 100, new float[]{0.0f, 1.0f}, new Color[]{Color.GREEN, new Color(128, 128, 128, 128)}, MultipleGradientPaint.CycleMethod.NO_CYCLE);
        g2d.setPaint(p);
        g2d.fillRect(50, 50, 500, 200);  //paint a green gradient with transparency
    }
}

public static final TwoRectangles rect = new TwoRectangles();

public static void main(String[] args) throws PrinterException {

    JFrame f  = new JFrame("Test Gradient");
    f.setLayout(new BorderLayout());
    f.add(rect);
    f.setSize(600, 300);
    f.setVisible(true);


    PrinterJob printJob = PrinterJob.getPrinterJob();


    Printable prt = new Printable() {

        @Override
        public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
            if (pageIndex > 0) 
                return(NO_SUCH_PAGE);

            rect.print(graphics);      
            return PAGE_EXISTS;
        }

    };

    printJob.setPrintable(prt);
    if (printJob.printDialog()) 
          printJob.print();

  } 
 }

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

FREQUENCY : always



Comments
MAC OS X Printer Related issue The issue is also being discussed in Stackoverflow: https://stackoverflow.com/questions/52488056/transparency-lost-on-lineargradient-paint-when-printing-to-macos-x-printer-using Reported with JDK 8u181, a 2D shape with a LinearGradientPaint when printed in MAC OS X, fails to render exactly in contrast to Windows 7 and 10. Checked this in MAC and Windows 10 as reported and could confirm the issue. Transparency information is lost and shape prints opaque. See attached screenshots (original and actual as it appears). Results: ============== 8u181: Fail 9: Fail 11.0.1: Fail 12 ea b14: Fail To verify, run the attached test case with respective JDK version. The issue is restricted to MAC OS X as it render correctly on Windows.
18-10-2018