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
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;
  
/*
 * Printing example snippet: print "Hello World!" in black, outlined in red, to default printer
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.printing.*;
public class Snippet132 {