Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8212643

[macos] Transparency lost on LinearGradient paint when printing to MacOS X printer

    Details

    • Subcomponent:
      2d
    • CPU:
      x86
    • OS:
      os_x

      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


        Attachments

        1. 8u-9-11-12.PNG
          8u-9-11-12.PNG
          5 kB
        2. Original.PNG
          Original.PNG
          12 kB
        3. TestGradient.java
          2 kB

          Issue Links

            Activity

              People

              • Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: