-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.3, 1.1.4, 1.1.5
-
x86, sparc
-
solaris_2.5.1, windows_95
Name: el35337 Date: 08/28/97
// PrintBug.java
// a bug in Toolkit.getPrintJob():
import java.awt.*;
class PrintBug {
static double INCH_PRO_CM = 2.54; // 1 inch = 2.54 cm.
static double PAPER_WIDTH = 20; // maximal paper width (in cm).
static double PAPER_HEIGHT = 30; // maximal paper height (in cm).
public static void main(String[] args) {
Frame f = new Frame("PrintBug");
f.pack(); f.setVisible(true);
Toolkit tk = Toolkit.getDefaultToolkit();
PrintJob pjob = tk.getPrintJob(f, "PrintBug", null);
if (pjob != null) {
Graphics pg = pjob.getGraphics();
if (pg != null) {
Dimension pd = pjob.getPageDimension();
int resdpi = pjob.getPageResolution(); // resolution in dpi
int res = (int) (resdpi / INCH_PRO_CM); // resolutiin in dpc (point
per cm)
System.out.println("Printer " + pd.width + " x " + pd.height + " at " +
resdpi + " dpi"
+ " = " + res + "ppc.");
pg.drawRect(0,0,(int)(PAPER_WIDTH*res), (int)(PAPER_HEIGHT*res));
// horizonal:
for(int tic = 0; tic < PAPER_WIDTH; tic++) // long tics (1 cm)
pg.drawLine(tic*res, 0, tic*res, res/2);
for(int tic = 0; tic < PAPER_WIDTH*2; tic++) // medium tics (0.5 cm)
pg.drawLine(tic*res/2, 0, tic*res/2, res/3);
for(int tic = 0; tic < PAPER_WIDTH*10; tic++) // short tics (0.1 cm)
pg.drawLine(tic*res/10, 0, tic*res/10, res/4);
// vertical:
for(int tic = 0; tic < PAPER_HEIGHT; tic++) // long tics (1 cm)
pg.drawLine(0, tic*res, res/2, tic*res);
for(int tic = 0; tic < PAPER_HEIGHT*2; tic++) // mediun tics (0.5cm)
pg.drawLine(0, tic*res/2, res/3, tic*res/2);
for(int tic = 0; tic < PAPER_HEIGHT*10; tic++) // short tics (0.1cm)
pg.drawLine(0, tic*res/10, res/4, tic*res/10);
pg.dispose(); // flush page
}
pjob.end();
}
}
}
// Output:
// [console:]
// Printer 612 x 792 at 300 dpi = 118ppc.
//
// [printer:]
// horizontal and vertical line with long, medium and short tics.
// The distance between two long tics is 1 inch, and not 1 cm, as it should be.
//
// Bug:
// 1) PrintJob.getResolution() reports a wrong size of the paper: an DINa4-page
// (ca. 20 cm x 30 cm) at 300 dpi (= 118 dpc) should be about 2360 x 3540
points
// (not 612 x 792) !
// 2) Graphics are printed 2.54 times to big. (In consequence of this, printed
images
// look very square).
//
// System:
// Java: JDK 1.1.3,
// OS: Windows-95,
// Printer: HP LaserJet 4L.
//
// reported by
// Lars Schmidt-Thieme (###@###.###)
// 10.07.97
company - , email - ###@###.###
======================================================================
- duplicates
-
JDK-4084038 Win32 printing: Frequent crashes, page scaled down
- Closed