-
Bug
-
Resolution: Unresolved
-
P3
-
8u181, 9, 10, 11, 12
-
x86
-
os_x
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
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
- duplicates
-
JDK-8231512 Printing LinearGradientPaint with transparency does not work on Mac
- Closed
-
JDK-8232085 [macos] Printing LinearGradientPaint with transparency does not work on Mac
- Closed
- relates to
-
JDK-8162796 [macosx] LinearGradientPaint and RadialGradientPaint are not printed on OS X.
- Resolved
-
JDK-8231512 Printing LinearGradientPaint with transparency does not work on Mac
- Closed