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

[macosx] Printing LinearGradientPaint and TexturePaint does not work on Mac

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8, 9
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • CPU:
      generic
    • OS:
      os_x

      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 ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              prr Philip Race
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: