本文整理了Java中org.eclipse.swt.graphics.GC.getFontMetrics()
方法的一些代码示例,展示了GC.getFontMetrics()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GC.getFontMetrics()
方法的具体详情如下:
包路径:org.eclipse.swt.graphics.GC
类名称:GC
方法名:getFontMetrics
[英]Returns a FontMetrics which contains information about the font currently being used by the receiver to draw and measure text.
[中]
代码示例来源:origin: pentaho/pentaho-kettle
FontMetrics fm = gc.getFontMetrics();
int charWidth = fm.getAverageCharWidth();
int fieldWidth = text.computeSize( charWidth * 20, SWT.DEFAULT ).x;
代码示例来源:origin: stackoverflow.com
GC gc = new GC(text);
try
{
gc.setFont(text.getFont());
FontMetrics fm = gc.getFontMetrics();
/* Set the height to 5 rows of characters */
data.heightHint = 5 * fm.getHeight();
}
finally
{
gc.dispose();
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench
private static void createSpace(Composite parent) {
Label vfiller = new Label(parent, SWT.LEFT);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan= 2;
GC gc = new GC(parent);
gridData.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 1) / 2;
gc.dispose();
vfiller.setLayoutData(gridData);
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.linux.s390x
int getBandHeight () {
if (font == null) return ExpandItem.CHEVRON_SIZE;
GC gc = new GC (this);
FontMetrics metrics = gc.getFontMetrics ();
gc.dispose ();
return Math.max (ExpandItem.CHEVRON_SIZE, metrics.getHeight ());
}
代码示例来源:origin: org.eclipse.equinox.p2/ui
private void setButtonLayoutData(Button button) {
GridData data = new GridData(SWT.FILL, SWT.CENTER, false, false);
GC gc = new GC(button);
gc.setFont(JFaceResources.getDialogFont());
FontMetrics fm = gc.getFontMetrics();
gc.dispose();
int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
data.widthHint = Math.max(widthHint, minSize.x);
button.setLayoutData(data);
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.debug.ui
private static GridData getButtonGridData(Button button) {
GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
GC gc = new GC(button);
gc.setFont(button.getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
gc.dispose();
int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
gd.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
return gd;
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
@Override
public Point computeSizeConstraints(int widthInChars, int heightInChars) {
GC gc= new GC(fText);
gc.setFont(fTextFont);
int width= gc.getFontMetrics().getAverageCharWidth();
int height= fText.getLineHeight(); //https://bugs.eclipse.org/bugs/show_bug.cgi?id=377109
gc.dispose();
return new Point(widthInChars * width, heightInChars * height);
}
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text
@Override
public Point computeSizeConstraints(int widthInChars, int heightInChars) {
GC gc= new GC(fText);
gc.setFont(fTextFont);
double width= gc.getFontMetrics().getAverageCharacterWidth();
int height= fText.getLineHeight();
gc.dispose();
return new Point((int) (widthInChars * width), heightInChars * height);
}
}
代码示例来源:origin: org.eclipse/org.eclipse.ui.editors
public PixelConverter(Control control) {
GC gc = new GC(control);
gc.setFont(control.getFont());
fFontMetrics= gc.getFontMetrics();
gc.dispose();
}
代码示例来源:origin: org.eclipse/org.eclipse.jdt.debug.ui
public PixelConverter(Control control) {
GC gc = new GC(control);
gc.setFont(control.getFont());
fFontMetrics= gc.getFontMetrics();
gc.dispose();
}
代码示例来源:origin: org.eclipse.platform/org.eclipse.team.ui
public PixelConverter(Control control) {
GC gc = new GC(control);
try {
gc.setFont(control.getFont());
fFontMetrics= gc.getFontMetrics();
} finally {
gc.dispose();
}
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui
public PixelConverter(Font font) {
GC gc = new GC(font.getDevice());
gc.setFont(font);
fFontMetrics= gc.getFontMetrics();
gc.dispose();
}
代码示例来源:origin: org.eclipse/org.eclipse.search
public PixelConverter(Control control) {
GC gc = new GC(control);
gc.setFont(control.getFont());
fFontMetrics= gc.getFontMetrics();
gc.dispose();
}
代码示例来源:origin: org.eclipse/org.eclipse.team.ui
public PixelConverter(Control control) {
GC gc = new GC(control);
try {
gc.setFont(control.getFont());
fFontMetrics= gc.getFontMetrics();
} finally {
gc.dispose();
}
}
代码示例来源:origin: BiglySoftware/BiglyBT
@Override
public void handleEvent(Event event) {
GC gc = new GC(consoleText);
int charWidth = gc.getFontMetrics().getAverageCharWidth();
gc.dispose();
int areaWidth = consoleText.getBounds().width;
consoleText.setTabs(areaWidth / 6 / charWidth);
}
});
代码示例来源:origin: org.eclipse.pde/org.eclipse.pde.api.tools.ui
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);
}
代码示例来源:origin: BiglySoftware/BiglyBT
@Override
public void handleEvent(Event event) {
Color old = event.gc.getForeground();
event.gc.setForeground(Colors.black);
int char_width = event.gc.getFontMetrics().getAverageCharWidth();
String pb_text = pbt.convert(result.getSelection());
event.gc.drawText(pb_text, (result.getSize().x - pb_text.length() * char_width )/2, -1, true);
event.gc.setForeground(old);
}
});
代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui
private static int getButtonWidthHint(Button button) {
button.setFont(JFaceResources.getDialogFont());
GC gc = new GC(button);
gc.setFont(button.getFont());
FontMetrics fontMetrics= gc.getFontMetrics();
gc.dispose();
int widthHint= Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.forms
public int getFontHeight() {
if (fontHeight == -1) {
Control c = getMessageControl();
if (c == null)
return 0;
GC gc = new GC(c.getDisplay());
gc.setFont(c.getFont());
fontHeight = gc.getFontMetrics().getHeight();
gc.dispose();
}
return fontHeight;
}
代码示例来源:origin: org.eclipse/org.eclipse.wst.xml.ui
protected void addEmptyTreeMessage(GC gc) {
// here we print a message when the document is empty just to give the
// user a visual cue
// so that they know how to proceed to edit the blank view
gc.setForeground(fTree.getDisplay().getSystemColor(SWT.COLOR_BLACK));
gc.setBackground(fTree.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
gc.drawString(XMLEditorMessages.XMLTreeExtension_3, 10, 10);
gc.drawString(XMLEditorMessages.XMLTreeExtension_4, 10, 10 + gc.getFontMetrics().getHeight());
}
内容来源于网络,如有侵权,请联系作者删除!