-
Enhancement
-
Resolution: Fixed
-
P4
-
6
-
mustang
-
x86
-
windows_98
Name: skT88420 Date: 09/28/99
This program when run under Windows98 and printing to a
printer on an NT server (LaserJet 4L 300DPI) gives the following
output:
0.0,0.0
Graphics2D Xform = AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
Device Defualt Xform = AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
Device Normal Xform = AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
IMAGE_BUFFER
Graphics2D Xform = AffineTransform[[4.166666666666667, 0.0, 0.0], [0.0, 4.166666666666667, 0.0]]
Device Defualt Xform = AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
Device Normal Xform = AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
IMAGE_BUFFER
This shows (at least for the second call to Printable.print()) that the Graphics2D was rendering to a 300 DPI device. Calculated by multiplying 72 by the constants in the AffineTransform. This is what one would expect.
However Graphics2D.getDeviceConfiguration() returns a GraphicsConfiguration object that seems to be unrelated to the printer (it claims to be an IMAGE_BUFFER with an identity transform).
My understanding is that Graphics2D.getDeviceConfiguration() should return useful information rather that the incorrect information that it currently returns.
Don't try to run this under jdk 1.2.2 because you will get a NullPointerException.
/*----------- Program Follows --------------*/
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.awt.image.renderable.*;
import java.awt.event.*;
import java.awt.print.*;
import java.util.*;
import java.net.*;
public class PTest3 implements Printable
{
public static void main(String args[])
{
try {
PrinterJob pj = null;
pj = PrinterJob.getPrinterJob();
Book b = new Book();
PageFormat pf = new PageFormat();
Paper paper = pf.getPaper();
paper.setImageableArea(0d, 0d, paper.getWidth(), paper.getHeight());
pf.setPaper(paper);
System.out.println(paper.getImageableX() + "," + paper.getImageableY());
PTest3 ni = new PTest3();
b.append(ni, pf);
pj.setPageable(b);
pj.print();
}
catch(Exception ex) {
ex.printStackTrace();
}
System.exit(0);
}
public PTest3()
{
}
public int print(Graphics g, PageFormat pf, int pageIndex)
{
Graphics2D g2 = (Graphics2D)g;
GraphicsConfiguration gConfig = g2.getDeviceConfiguration();
AffineTransform dt = gConfig.getDefaultTransform();
AffineTransform nt = gConfig.getNormalizingTransform();
AffineTransform gt = g2.getTransform();
System.out.println("Graphics2D Xform = " + gt);
System.out.println("Device Defualt Xform = " + dt);
System.out.println("Device Normal Xform = " + nt);
GraphicsDevice gd = gConfig.getDevice();
switch(gd.getType()){
case GraphicsDevice.TYPE_IMAGE_BUFFER:
System.out.println("IMAGE_BUFFER");
break;
case GraphicsDevice.TYPE_PRINTER:
System.out.println("PRINTER");
break;
case GraphicsDevice.TYPE_RASTER_SCREEN:
System.out.println("RASTER_SCREEN");
break;
}
g2.setFont(new Font("SansSerif", Font.PLAIN, 24));
g2.setColor(Color.black);
g2.drawString("Painted Text", 20, 100);
return Printable.PAGE_EXISTS;
}
}
(Review ID: 95847)
======================================================================