1 11 package org.eclipse.jdt.internal.ui.util; 12 13 import org.eclipse.swt.graphics.Font; 14 import org.eclipse.swt.graphics.FontMetrics; 15 import org.eclipse.swt.graphics.GC; 16 import org.eclipse.swt.widgets.Control; 17 18 import org.eclipse.jface.dialogs.Dialog; 19 20 public class PixelConverter { 21 22 private final FontMetrics fFontMetrics; 23 24 public PixelConverter(Control control) { 25 this(control.getFont()); 26 } 27 28 public PixelConverter(Font font) { 29 GC gc = new GC(font.getDevice()); 30 gc.setFont(font); 31 fFontMetrics= gc.getFontMetrics(); 32 gc.dispose(); 33 } 34 35 38 public int convertHeightInCharsToPixels(int chars) { 39 return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars); 40 } 41 42 45 public int convertHorizontalDLUsToPixels(int dlus) { 46 return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus); 47 } 48 49 52 public int convertVerticalDLUsToPixels(int dlus) { 53 return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus); 54 } 55 56 59 public int convertWidthInCharsToPixels(int chars) { 60 return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars); 61 } 62 63 } 64 | Popular Tags |