-
Bug
-
Resolution: Unresolved
-
P3
-
8u91, 9, 10
FULL PRODUCT VERSION :
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [versão 10.0.15063]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Tested with 3 different printers, all showed the problem:
- HP LaserJet P3010 Series PCL 6 (61.83.41.3)
- Brother MFC-J6510DW FV
- Microsoft Print to PDF (The one that comes with Windows 10)
A DESCRIPTION OF THE PROBLEM :
When printing text that is both rotated and scale to a printer, the outputs text orientation is wrong. Aparently, the individual characters are correctly rotated, but the text orientation as a whole is wrong (left-to-right instead of top-to-bottom).
Some extra information:
- Doesn't seem to happen for all combinations of fonts, sizes and scales. With the one provided in the sample source code it happened on every printer I tested.
- Doesn't seem to happen on screen or image Graphics, only PrinterJob graphics
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the source code, select a printer in the spool, click "Print", and the 4th printed text should be wrong
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All four texts to be printed in the correct orientation
ACTUAL -
The 4th combination is printed in the wrong orientation
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.PrintService;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.JFrame;
public class Test {
public static void main(String[] args) throws Exception {
PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
PrinterJob job = PrinterJob.getPrinterJob();
if (job.printDialog()) {
PrintService sv = job.getPrintService();
job.setPrintable(new ThePrinter());
job.setJobName("Job");
job.print(attributeSet);
}
}
private static class ThePrinter implements Printable {
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex > 0) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) graphics.create();
AffineTransform af;
g2d.setColor(Color.BLACK);
// (Works) Text that is not rotated, without scale
af = new AffineTransform();
g2d.setFont(new Font("Arial", Font.PLAIN, 12).deriveFont(af));
g2d.drawString("No rotate, no scale", 100, 100);
// (Works) Text that is not rotated, with scale
af = new AffineTransform();
af.scale(0.93,1.0);
g2d.setFont(new Font("Arial", Font.PLAIN, 12).deriveFont(af));
g2d.drawString("No rotate, with scale", 100, 130);
// (Works) Text that is rotated, without scale
af = new AffineTransform();
af.rotate(Math.toRadians(90));
g2d.setFont(new Font("Arial", Font.PLAIN, 12).deriveFont(af));
g2d.drawString("With rotate, no scale", 100, 160);
// (DOESN'T Work) Text that is rotated, with scale
af = new AffineTransform();
af.rotate(Math.toRadians(90));
af.scale(0.93,1.0);
g2d.setFont(new Font("Arial", Font.PLAIN, 12).deriveFont(af));
g2d.drawString("With rotate, with scale", 130, 160);
g2d.dispose();
return Printable.PAGE_EXISTS;
}
}
}
---------- END SOURCE ----------
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [versão 10.0.15063]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Tested with 3 different printers, all showed the problem:
- HP LaserJet P3010 Series PCL 6 (61.83.41.3)
- Brother MFC-J6510DW FV
- Microsoft Print to PDF (The one that comes with Windows 10)
A DESCRIPTION OF THE PROBLEM :
When printing text that is both rotated and scale to a printer, the outputs text orientation is wrong. Aparently, the individual characters are correctly rotated, but the text orientation as a whole is wrong (left-to-right instead of top-to-bottom).
Some extra information:
- Doesn't seem to happen for all combinations of fonts, sizes and scales. With the one provided in the sample source code it happened on every printer I tested.
- Doesn't seem to happen on screen or image Graphics, only PrinterJob graphics
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the source code, select a printer in the spool, click "Print", and the 4th printed text should be wrong
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All four texts to be printed in the correct orientation
ACTUAL -
The 4th combination is printed in the wrong orientation
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.PrintService;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.JFrame;
public class Test {
public static void main(String[] args) throws Exception {
PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
PrinterJob job = PrinterJob.getPrinterJob();
if (job.printDialog()) {
PrintService sv = job.getPrintService();
job.setPrintable(new ThePrinter());
job.setJobName("Job");
job.print(attributeSet);
}
}
private static class ThePrinter implements Printable {
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex > 0) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) graphics.create();
AffineTransform af;
g2d.setColor(Color.BLACK);
// (Works) Text that is not rotated, without scale
af = new AffineTransform();
g2d.setFont(new Font("Arial", Font.PLAIN, 12).deriveFont(af));
g2d.drawString("No rotate, no scale", 100, 100);
// (Works) Text that is not rotated, with scale
af = new AffineTransform();
af.scale(0.93,1.0);
g2d.setFont(new Font("Arial", Font.PLAIN, 12).deriveFont(af));
g2d.drawString("No rotate, with scale", 100, 130);
// (Works) Text that is rotated, without scale
af = new AffineTransform();
af.rotate(Math.toRadians(90));
g2d.setFont(new Font("Arial", Font.PLAIN, 12).deriveFont(af));
g2d.drawString("With rotate, no scale", 100, 160);
// (DOESN'T Work) Text that is rotated, with scale
af = new AffineTransform();
af.rotate(Math.toRadians(90));
af.scale(0.93,1.0);
g2d.setFont(new Font("Arial", Font.PLAIN, 12).deriveFont(af));
g2d.drawString("With rotate, with scale", 130, 160);
g2d.dispose();
return Printable.PAGE_EXISTS;
}
}
}
---------- END SOURCE ----------