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

Printing: banded raster path doesn't account for device offset values

XMLWordPrintable

    • 2d
    • b11
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      OS: Windows 10 and earlier
      Java: 17.0.6

      A DESCRIPTION OF THE PROBLEM :
      There are 3 elements (rectangle, left line, bottom line) painted on imageable area in the same way. But Java Print Service draws them differently depends on some conditions.
      When is using alpha value less than 255 and page orientation is set to LANDSCAPE only rectangle is painted on the paper though all 3 figures must be drawn.
      When I replace alpha value to 255 in the ((Graphics2D)graphics).setPaint(new java.awt.Color(0,0,0,100)) everything works well.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile and run the code below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Rectangle, left line, bottom line is painted
      ACTUAL -
      Rectangle is painted

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

      public class Printing implements Printable {
          private static Paper paper;
          @Override
          public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
              if (Thread.interrupted())
              {
                  throw new PrinterException("Current thread interrupted.");
              }

              Stroke oldstroke = ((Graphics2D)graphics).getStroke();
              ((Graphics2D)graphics).setStroke(new BasicStroke(10));
              ((Graphics2D)graphics).translate(15, 0);
              graphics.drawLine(0,0,0,300); //LEFT margin line
              ((Graphics2D)graphics).translate(-15, 0);

              ((Graphics2D)graphics).translate(0, -15);
              graphics.drawLine(0,(int)paper.getImageableWidth(),300,(int)paper.getImageableWidth());//BOTTOM margin line
              ((Graphics2D)graphics).translate(0, 15);
              ((Graphics2D)graphics).setStroke(oldstroke);

              ((Graphics2D)graphics).setPaint(new java.awt.Color(0,0,0,100));
              ((Graphics2D)graphics).fill(new Rectangle(0,0,200,200));


              return Printable.PAGE_EXISTS;
          }

          public static void main(String[] argv) {
              Printing printer = new Printing();
              PrinterJob printJob = PrinterJob.getPrinterJob();
              PageFormat pageFormat = printJob.defaultPage();
              paper = pageFormat.getPaper();
              paper.setImageableArea(0,0,paper.getWidth(),paper.getHeight());
              pageFormat.setOrientation(PageFormat.LANDSCAPE);
              pageFormat.setPaper(paper);

              Book book = new Book();
              book.append(printer, pageFormat,1);
              printJob.setPageable(book);
              try {
                  printJob.print();
              } catch (PrinterException e) {
                  e.printStackTrace();
              }

          }
      }

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

      FREQUENCY : always


        1. 1.jpg
          1.jpg
          2.74 MB
        2. 2.jpg
          2.jpg
          2.84 MB
        3. 3.jpg
          3.jpg
          2.89 MB
        4. Capture.pdf
          142 kB
        5. Printing.java
          2 kB

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: