@Override public Font createFont(Device device) { // If this descriptor is an existing font, then we can return the original font // if this is the same device. if (originalFont != null) { // If we're allocating on the same device as the original font, return the original. if (originalFont.getDevice() == device) { return originalFont; } } return new Font(device, data); }
public Font createFont(Device device) { // If this descriptor is an existing font, then we can return the original font // if this is the same device. if (originalFont != null) { // If we're allocating on the same device as the original font, return the original. if (originalFont.getDevice() == device) { return originalFont; } } return new Font(device, data); }
@Override public Font createFont(Device device) { // If this descriptor is an existing font, then we can return the original font // if this is the same device. if (originalFont != null) { // If we're allocating on the same device as the original font, return the original. if (originalFont.getDevice() == device) { return originalFont; } } return new Font(device, data); }
Font getScaledFont(Font editorFont) { if (editorFont == null) { return null; } Font scaledFont = fScaledFonts.get(editorFont); if (scaledFont != null) { return scaledFont; } FontData[] fontData = editorFont.getFontData(); FontData fontDatum = fontData[0]; scaledFont = new Font(editorFont.getDevice(), fontDatum.getName(), (int) Math.ceil(fontDatum.getHeight() * getScale()), fontDatum.getStyle()); fScaledFonts.put(editorFont, scaledFont); return scaledFont; }
private Font createBoldFont(Font original) { FontData[] font_data = original.getFontData(); for (int i=0; i<font_data.length; i++) { font_data[i].setStyle(font_data[i].getStyle() | SWT.BOLD); } return new Font(original.getDevice(), font_data); }
/** * Creates (if not already done) and returns the bold font used by the styler to apply the bold * style. * * <p> * <strong>Note:</strong> The callers must not cache and re-use the returned font outside the * current call. * </p> * * @return the bold font used by the styler */ public Font getBoldFont() { if (fBoldFont == null) { FontData[] data= fFont.getFontData(); for (int i= 0; i < data.length; i++) { data[i].setStyle(SWT.BOLD); } fBoldFont= new Font(fFont.getDevice(), data); } return fBoldFont; }
public PixelConverter(Font font) { GC gc = new GC(font.getDevice()); gc.setFont(font); fFontMetrics = gc.getFontMetrics(); gc.dispose(); }
public static int getFontHeightInPX(Font font) { GC gc = new GC(font.getDevice()); try { gc.setFont(font); return gc.textExtent(Utils.GOOD_STRING).y; } finally { gc.dispose(); } }
public static Font getFontPercentOf(Font baseFont, float pct) { FontData[] fontData = baseFont.getFontData(); float height = getHeight(fontData) * pct; setFontDataHeight(fontData, height); return new Font(baseFont.getDevice(), fontData); }
public PixelConverter(Font font) { GC gc = new GC(font.getDevice()); gc.setFont(font); fFontMetrics= gc.getFontMetrics(); gc.dispose(); }
/** * Create a PixelConverter which will convert device-independent units to * pixels using the specified font. * * @param font * the font that should be used for pixel conversions. */ public PixelConverter(Font font) { GC gc = new GC(font.getDevice()); gc.setFont(font); fontMetrics = gc.getFontMetrics(); gc.dispose(); }
public PixelConverter(Font font) { GC gc = new GC(font.getDevice()); gc.setFont(font); fFontMetrics= gc.getFontMetrics(); gc.dispose(); }
/** * Create a PixelConverter which will convert device-independent units to * pixels using the specified font. * * @param font * the font that should be used for pixel conversions. */ public PixelConverter(Font font) { GC gc = new GC(font.getDevice()); gc.setFont(font); fontMetrics = gc.getFontMetrics(); gc.dispose(); }
public PixelConverter(Font font) { GC gc = new GC(font.getDevice()); gc.setFont(font); fFontMetrics= gc.getFontMetrics(); gc.dispose(); }
/** * Create a PixelConverter which will convert device-independent units to * pixels using the specified font. * * @param font * the font that should be used for pixel conversions. */ public PixelConverter(Font font) { GC gc = new GC(font.getDevice()); gc.setFont(font); fontMetrics = gc.getFontMetrics(); gc.dispose(); }
public int convertWidthInCharsToPixels(Font font, int chars) { GC gc = new GC(font.getDevice()); gc.setFont(font); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); return Dialog.convertWidthInCharsToPixels(fontMetrics, chars); }
public static Font getFontWithStyle(Font baseFont, int style, float sizeByPct) { FontData[] fontData = baseFont.getFontData(); for (FontData fd : fontData) { fd.setStyle(style); } if (sizeByPct != 1.0f) { float height = getHeight(fontData) * sizeByPct; setFontDataHeight(fontData, height); } return new Font(baseFont.getDevice(), fontData); }
public int convertWidthInCharsToPixels(Font font, int chars) { GC gc = new GC(font.getDevice()); gc.setFont(font); FontMetrics fontMetrics= gc.getFontMetrics(); gc.dispose(); return Dialog.convertWidthInCharsToPixels(fontMetrics, chars); }
private static Font ensureFontFitsHeight(Font font, int pxMaxHeight) { int px = getFontHeightInPX(font); if (px <= pxMaxHeight) { //System.out.println("ensureFontFitsHeight; wanted max " + pxMaxHeight + "; got " + px); return font; } Device device = font.getDevice(); FontData[] fontData = font.getFontData(); float height = getHeight(fontData); int newPX; do { height -= 0.25; setFontDataHeight(fontData, height); font = new Font(device, fontData); newPX = getFontHeightInPX(font); //System.out.println("Reduced font; wanted max " + pxMaxHeight + "; got " + px + "; trying " + height + " adjusts to " + newPX); } while (newPX > pxMaxHeight); return font; } }
/** * Sets the text size. * * @param newSize the new text size */ private void setTextSize(int newSize) { Font font = getSourceViewer().getTextWidget().getFont(); if (font.getFontData().length > 0) { FontData fd = font.getFontData()[0]; getSourceViewer().getTextWidget().setFont(new Font(font.getDevice(), fd.getName(), newSize, fd.getStyle())); } }