1 11 package org.eclipse.ui.internal.forms.widgets; 12 13 import org.eclipse.swt.graphics.FontMetrics; 14 import org.eclipse.swt.graphics.GC; 15 import org.eclipse.swt.widgets.Control; 16 17 public class PixelConverter { 18 21 private static final int HORIZONTAL_DIALOG_UNIT_PER_CHAR = 4; 22 23 private FontMetrics fFontMetrics; 24 25 public PixelConverter(Control control) { 26 GC gc = new GC(control); 27 gc.setFont(control.getFont()); 28 fFontMetrics = gc.getFontMetrics(); 29 gc.dispose(); 30 } 31 32 public int convertHorizontalDLUsToPixels(int dlus) { 33 return (fFontMetrics.getAverageCharWidth() * dlus + HORIZONTAL_DIALOG_UNIT_PER_CHAR / 2) 35 / HORIZONTAL_DIALOG_UNIT_PER_CHAR; 36 } 37 } 38 | Popular Tags |