Can anyone recommend resources or techniques for precise line placement for
output to printers? As a simple example I would like to be able to output
evenly spaced lines (eg graph paper) to any printer, but regardless of the
resolution, or rendering hints, I seem to get lines of slightly different
thicknesses and position no matter what I do. I have tried drawing the lines by
using Graphics2D.fill on a Rectangle2D with a single unit thickness instead of
Graphics2D.draw, and that produced better results, but the line thicknesses are
still not all the same, and the differences seem to vary from printer to
printer. Is there a a special technique for this in the Java 1.4+ world? Can
this even be done in a printer independent way in java?
Here's my original test case:
public class PrintTest implements Printable
{
public int print (Graphics g, PageFormat format, int pageIndex) {
if (pageIndex != 0) return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
g2.translate (format.getImageableX (), format.getImageableY ());
int cellSize = 10; // Arbitrary
int hcells = (int) (format.getImageableWidth () / cellSize);
int vcells = (int) (format.getImageableHeight () / cellSize);
for (int x = 0; x <= hcells; ++x)
g2.drawLine (x * cellSize, 0, x * cellSize, vcells * cellSize);
for (int y = 0; y <= vcells; ++y)
g2.drawLine (0, y * cellSize, hcells * cellSize, y * cellSize);
return PAGE_EXISTS;
}
public static void main (String [] argv)
{
try {
PrinterJob job = PrinterJob.getPrinterJob ();
job.setPrintable (new PrintTest ());
if (job.printDialog ())
job.print ();
} catch (Exception e) { e.printStackTrace (); }
}
}
[Message sent by forum member 'jawathehut' (jawathehut)]
http://forums.java.net/jive/thread.jspa?messageID=323696
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[email protected] and include in the body of the message "help".