JDK-8232085 : [macos] Printing LinearGradientPaint with transparency does not work on Mac
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u221,12.0.2,14
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2019-09-25
  • Updated: 2019-10-10
  • Resolved: 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.
JDK 14
14Resolved
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
macOS High Sierra 10.13.6

A DESCRIPTION OF THE PROBLEM :
If you print a shape with transparent linear gradient on Mac, the colors will look opaque.

REGRESSION : Last worked in version 11.0.4

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test case.
Press the "print" button.
Save as pdf.
Open the pdf with any pdf viewer.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The printed shape should be filled with a gradient that uses transparency (as on Windows). See attached pdf file "LinearGradient-Win.pdf".
ACTUAL -
The printed shape is filled with a gradient that uses opaque colors. See attached pdf file "LinearGradient-Mac.pdf".

---------- BEGIN SOURCE ----------
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LinearGradientPaint;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class PrintTest
{
  public static void main(String[] args)
  {
    EventQueue.invokeLater(() -> {
      JFrame frame = new PrintTestFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
    });
  }
}

/**
 * This frame shows a panel with 2D graphics and buttons to print the graphics and to set up the
 * page format.
 */
class PrintTestFrame extends JFrame {
  private PrintComponent canvas;
  
  PrintTestFrame() {
    setTitle("PrintTest");
    setSize(300, 300);

    canvas = new PrintComponent();
    add(canvas, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    JButton printButton = new JButton("Print");
    buttonPanel.add(printButton);
    printButton.addActionListener(event -> {
      try {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPrintable(canvas);
        if (job.printDialog()) job.print();
      } catch (PrinterException e) {
        JOptionPane.showMessageDialog(PrintTestFrame.this, e);
      }
    });

    add(buttonPanel, BorderLayout.NORTH);
  }
}

/**
 * This component generates a 2D graphics image for screen display and printing.
 */
class PrintComponent extends JComponent implements Printable {
  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    drawPage(g2);
  }

  public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
    if (page >= 1) return Printable.NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D) g;
    g2.translate(pf.getImageableX(), pf.getImageableY());

    drawPage(g2);
    return Printable.PAGE_EXISTS;
  }

  /**
   * This method draws the page both on the screen and the printer graphics context.
   * @param g2 the graphics context
   */
  private void drawPage(Graphics2D g2) {
    double x = 0;
    double y = 0;
    double w = 100;
    double h = 100;

    Rectangle2D.Double rect = new Rectangle2D.Double(x, y, w, h);
    g2.setPaint(Color.ORANGE);
    g2.fill(rect);

    Path2D path = new Path2D.Double();
    path.moveTo(x, y);
    path.lineTo(x + w, y);
    path.lineTo(x, y + h);
    path.closePath();

    float[] dist = {0f, 0.8f};
    Color[] colors = {new Color(255, 255, 255, 200), new Color(255, 255, 255, 20)};
    LinearGradientPaint gradient = new LinearGradientPaint(0, 0, 50, 50, dist, colors);

    g2.setPaint(gradient);
    g2.fill(path);
  }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Reported with macOS, the printing a shape with transparent linear gradient on mac, the colors will look opaque. Checked this for reported version in 10.13.6 (macOS) and coulf confirm the results. Result (mac only): ======== 8u212: Fail 9: Fail 11.0.4: Fail 12.0.2: Fail 13: Fail 14 ea b17: Fail To verify, run the attached test case with respective JDK version. See attached screenshot as reference.
10-10-2019