Bug 195154 Snippet132 using drawString incorrectly
Snippet132 has the following code at the "business end:" String testString = "Hello World!"; Point extent = gc.stringExtent(testString); gc.drawString(testString, leftMargin, topMargin + font.getFontData()[0].getHeight()); I'm not sure why we're adding font.getFontData()[0].getHeight() and I believe it should be removed. drawString()'s x and y parameters are measured in pixels, but FontData.getHeight() is a measure of the font face's height in points. On my printer there is no appreciable difference on the printout, since the printer DPI is 600 and the FontData.getHeight() returns 2 (not sure why) which amounts to only 1/300" == 0.085mm difference. However in working with the SWTSwing folks, where printing is always 72DPI (ugh) the error in this snippet is more obvious. An 8-point font will be drawn at an 8-point offset (about 1/8" == 2.82mm). This makes SWTSwing's behavior appear to be wrong when in fact it is the snippet.
examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet132.java
Color black = printer.getSystemColor(SWT.COLOR_BLACK);
		Color white = printer.getSystemColor(SWT.COLOR_WHITE);
		Color red = printer.getSystemColor(SWT.COLOR_RED);
		Rectangle trim = printer.computeTrim(0, 0, 0, 0);
		Point dpi = printer.getDPI();
		int leftMargin = dpi.x + trim.x; 
		int topMargin = dpi.y / 2 + trim.y; 
		GC gc = new GC(printer);
		Font font = gc.getFont(); 
		if (printer.startPage()) {
			gc.setBackground(white);
			gc.setForeground(black);
			String testString = "Hello World!";
			Point extent = gc.stringExtent(testString);
			gc.drawString(testString, leftMargin, topMargin + font.getFontData()[0].getHeight());
			gc.setForeground(red);
			gc.drawRectangle(leftMargin, topMargin, extent.x, extent.y);
			printer.endPage();
		}
		gc.dispose();
		printer.endJob();
		}
	printer.dispose();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose();
	}
}