Community
Participate
Working Groups
Try the following snippet: import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.printing.*; public class TestSnippet { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.open(); PrinterData data = Printer.getDefaultPrinterData(); if (data == null) { System.out.println("Warning: No default printer."); display.dispose(); return; } Printer printer = new Printer(data); if (printer.startJob("SWT Printing Snippet")) { Color black = printer.getSystemColor(SWT.COLOR_BLACK); Color white = printer.getSystemColor(SWT.COLOR_WHITE); Rectangle trim = printer.computeTrim(0, 0, 0, 0); Point dpi = printer.getDPI(); int leftMargin = dpi.x + trim.x; // one inch from left side of paper if (leftMargin < 0) leftMargin = -trim.x; // make sure to print on theprintable area int topMargin = dpi.y / 2 + trim.y; // one-half inch from top edge // of paper if (topMargin < 0) topMargin = -trim.y; // make sure to print on the printable area GC gc = new GC(printer); if (printer.startPage()) { gc.setBackground(white); gc.setForeground(black); float scale = Math.round((float) printer.getDPI().x / display.getDPI().x); int size = Math.round(scale * 50); int offset = Math.round(scale * 5); gc.setClipping(leftMargin, topMargin, size, size); gc.drawRectangle(leftMargin, topMargin, size, size); gc.setClipping(leftMargin + size + offset, topMargin, size, size); gc.drawRectangle(leftMargin + size + offset, topMargin, size, size); printer.endPage(); } gc.dispose(); printer.endJob(); } printer.dispose(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } Note that only one rectangle is printed, namely the second one. If the 2nd setClipping(int,int,int,int) call is removed and the first includes the area for both rectangles then it would work I think. On Win XP it prints both rectangles. Problem noticed in Draw2D PrintExample. Figures are usually drawn as follows: 1) Clip rectangle == bounds of the figure 2) paint the figure Appears that only the last figure gets drawn everything else is wiped out for the GC built from Printer device. Works fine if the GC is built from the Display device.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.