FontData[] array = gc.getFont().getFontData(); String string = ""; String lf = text.getLineDelimiter();
try { gc= new GC(parent); gc.setFont(gc.getFont()); gd.heightHint= Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 6); // 6 characters tall } finally {
public Font getFont() { return gc.getFont(); }
/** * Returns the advance width of the character provided in the current font. * * @param ch character to calculate the advance width of. * * @return advance width of the character in the current font */ public int getAdvanceWidth(final char ch) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); final int width = gc.getAdvanceWidth(ch); gc.setFont(scaledFont); return width; }
/** * Returns the width of the character provided in the current font. * * @param ch character to calculate the width of. * * @return width of the character in the current font */ public int getCharWidth(final char ch) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); final int width = gc.getCharWidth(ch); gc.setFont(scaledFont); return width; }
/** * Returns the font in form of an AWT font created * with the parameters of the font of the SWT graphic * composite. * @return The font. * @see java.awt.Graphics#getFont() */ @Override public Font getFont() { // retrieve the swt font description in an os indept way FontData[] fontData = this.gc.getFont().getFontData(); // create a new AWT font with the appropiate data return SWTUtils.toAwtFont(this.gc.getDevice(), fontData[0], true); }
/** * Returns the extent of the provided string in the current font. * * @param str string to calculate the extent of. * * @return extent of the string in the current font */ public org.eclipse.swt.graphics.Point stringExtent(final String str) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); final org.eclipse.swt.graphics.Point extent = gc.stringExtent(str); gc.setFont(scaledFont); return extent; }
/** * Returns the extent of the provided text in the current font. * * @param str string to calculate the extent of. * * @return extent of the string in the current font */ public org.eclipse.swt.graphics.Point textExtent(final String str) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); final org.eclipse.swt.graphics.Point extent = gc.textExtent(str); gc.setFont(scaledFont); return extent; }
/** * Returns the extent of the provided text in the current font assuming the * flags given. * * @param str string to calculate the extent of * @param flags flags to apply to the rendered font before calculation of * extent takes place * @return extent of the string in the current font assuming flags provided */ public org.eclipse.swt.graphics.Point textExtent(final String str, final int flags) { final org.eclipse.swt.graphics.Font scaledFont = gc.getFont(); gc.setFont(curFont); final org.eclipse.swt.graphics.Point extent = gc.textExtent(str, flags); gc.setFont(scaledFont); return extent; }
@Override public void computeSelection(GC gc, Hashtable<String, Object> resourceTable, SelectionData selData) { Font oldFont = null; if (fontId != null) { oldFont = gc.getFont(); Font newFont = (Font) resourceTable.get(fontId); if (newFont != null) gc.setFont(newFont); } for (int i = 0; i < areaRectangles.size(); i++) { AreaRectangle areaRectangle = areaRectangles.get(i); Rectangle rect = areaRectangle.rect; String text = areaRectangle.getText(); Point extent = gc.textExtent(text); computeSelection(gc, text, extent.x, selData, rect); } // restore GC resources if (oldFont != null) { gc.setFont(oldFont); } }
@Override public void computeSelection(GC gc, Hashtable<String, Object> resourceTable, SelectionData selData) { Font oldFont = null; if (fontId != null) { oldFont = gc.getFont(); Font newFont = (Font) resourceTable.get(fontId); if (newFont != null) gc.setFont(newFont); } for (int i = 0; i < areaRectangles.size(); i++) { AreaRectangle areaRectangle = areaRectangles.get(i); Rectangle rect = areaRectangle.rect; String text = areaRectangle.getText(); Point extent = gc.textExtent(text); computeSelection(gc, text, extent.x, selData, rect); } // restore GC resources if (oldFont != null) { gc.setFont(oldFont); } }
public static Font getAnyFontItalic(GC gc) { if (fontItalic == null || fontItalic.isDisposed()) { FontData[] fontData = gc.getFont().getFontData(); for (FontData fd : fontData) { fd.setStyle(SWT.ITALIC); } fontItalic = new Font(gc.getDevice(), fontData); } return fontItalic; }
public static Font getAnyFontBold(GC gc) { if (fontBold == null || fontBold.isDisposed()) { FontData[] fontData = gc.getFont().getFontData(); for (FontData fd : fontData) { fd.setStyle(SWT.BOLD); } fontBold = new Font(gc.getDevice(), fontData); } return fontBold; }
public static Font getAnyFontBoldItalic(GC gc) { if (fontBoldItalic == null || fontBoldItalic.isDisposed()) { FontData[] fontData = gc.getFont().getFontData(); for (FontData fd : fontData) { fd.setStyle(SWT.BOLD | SWT.ITALIC); } fontBoldItalic = new Font(gc.getDevice(), fontData); } return fontBoldItalic; }
@Override public void addDamagedRegion(FigureDrawContext fdc, Region region) { Font oldFont = fdc.gc.getFont(); fdc.gc.setFont(font); Point textExtent = fdc.gc.textExtent(text); fdc.gc.setFont(oldFont); region.add(fdc.toClientRectangle(x, y, x + textExtent.x, y + textExtent.y)); } }
public int getWidth(FontContext context, FSFont font, String string) { GC gc = ((SWTFontContext) context).getGC(); Font previous = gc.getFont(); gc.setFont(((SWTFSFont) font).getSWTFont()); int width = gc.stringExtent(string).x; gc.setFont(previous); return width; }
private Point getTipCountTextSize(Composite providerButton, int tipCount) { GC gc2 = new GC(providerButton); gc2.setAdvanced(true); gc2.setFont(SWTResourceManager.getBoldFont(gc2.getFont())); Point textExtent = gc2.textExtent(tipCount + ""); //$NON-NLS-1$ gc2.dispose(); return textExtent; } }
private GCStringPrinter setupStringPrinter(GC gc, TableCellSWT cell) { ActivitiesEntry entry = (ActivitiesEntry) cell.getDataSource(); String text = entry.getText(); Rectangle drawBounds = getDrawBounds(cell); entry.setViewed(); if (!entry.isRead()) { if (font == null) { FontData[] fontData = gc.getFont().getFontData(); fontData[0].setStyle(SWT.BOLD); font = new Font(gc.getDevice(), fontData); } gc.setFont(font); } int style = SWT.WRAP; GCStringPrinter sp = new GCStringPrinter(gc, text, drawBounds, true, true, style); sp.calculateMetrics(); return sp; }
gc.setFont(SWTResourceManager.getBoldFont(gc.getFont())); gc.setAlpha(200); gc.setTextAntialias(SWT.ON);
}); e.gc.setAlpha(180); Font lastFont = e.gc.getFont(); e.gc.setFont(fontCount); spCount = new GCStringPrinter(e.gc, sCount, printArea, true, false,