-
Bug
-
Resolution: Fixed
-
P4
-
8, 17.0.6
-
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
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