本文整理汇总了Java中org.eclipse.swt.graphics.FontMetrics.getAscent方法的典型用法代码示例。如果您正苦于以下问题:Java FontMetrics.getAscent方法的具体用法?Java FontMetrics.getAscent怎么用?Java FontMetrics.getAscent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.graphics.FontMetrics
的用法示例。
在下文中一共展示了FontMetrics.getAscent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateTextBounds
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
/**
* Calculates the bounds of the text in the box as measured by the given
* graphics context and font metrics.
*
* @param gc graphics context from which the measurements are done
* @return point representing the dimensions of the text's bounds
*/
private Point calculateTextBounds(final GC gc) {
final SWTGraphics2D g2 = new SWTGraphics2D(gc, Display.getDefault());
g2.setFont(font);
final FontMetrics fm = g2.getSWTFontMetrics();
final Point textBounds = new Point(0, 0);
boolean firstLine = true;
final Iterator lineIterator = lines.iterator();
while (lineIterator.hasNext()) {
String line = (String) lineIterator.next();
Point lineBounds = gc.stringExtent(line);
if (firstLine) {
textBounds.x = lineBounds.x;
textBounds.y += fm.getAscent() + fm.getDescent() + fm.getLeading();
firstLine = false;
}
else {
textBounds.x = Math.max(lineBounds.x, textBounds.x);
textBounds.y += fm.getHeight();
}
}
return textBounds;
}
示例2: getBaselineBias
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
/**
* Returns the difference between the baseline of the widget and the
* baseline as specified by the font for <code>gc</code>. When drawing
* line numbers, the returned bias should be added to obtain text lined up
* on the correct base line of the text widget.
*
* @param gc the <code>GC</code> to get the font metrics from
* @param widgetLine the widget line
* @return the baseline bias to use when drawing text that is lined up with
* <code>fCachedTextWidget</code>
* @since 3.2
*/
private int getBaselineBias(GC gc, int widgetLine) {
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951
* widget line height may be more than the font height used for the
* line numbers, since font styles (bold, italics...) can have larger
* font metrics than the simple font used for the numbers.
*/
int offset= fCachedTextWidget.getOffsetAtLine(widgetLine);
int widgetBaseline= fCachedTextWidget.getBaseline(offset);
FontMetrics fm= gc.getFontMetrics();
int fontBaseline= fm.getAscent() + fm.getLeading();
int baselineBias= widgetBaseline - fontBaseline;
return Math.max(0, baselineBias);
}
示例3: createRotatedImageOfString
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
/**
* Returns a new Image with the given String rotated left (by 90 degrees).
* The String will be rendered using the provided colors and fonts. The
* client is responsible for disposing the returned Image. Strings cannot
* contain newline or tab characters.
*
* @param string
* the String to be rendered
* @param font
* the font
* @param foreground
* the text's color
* @param background
* the background color
* @return an Image which must be disposed
*/
public static Image createRotatedImageOfString(String string, Font font,
Color foreground, Color background) {
Display display = Display.getDefault();
FontMetrics metrics = FigureUtilities.getFontMetrics(font);
Dimension strSize = FigureUtilities.getStringExtents(string, font);
Image srcImage = new Image(display, strSize.width, metrics.getAscent());
GC gc = new GC(srcImage);
gc.setFont(font);
gc.setForeground(foreground);
gc.setBackground(background);
gc.fillRectangle(srcImage.getBounds());
gc.drawString(string, 0, 0 - metrics.getLeading());
Image result = createRotatedImage(srcImage);
gc.dispose();
srcImage.dispose();
return result;
}
示例4: createColorImage
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
private ImageData createColorImage(Control w, String fileLocation) {
GC gc = new GC(w);
FontMetrics fm = gc.getFontMetrics();
int size = fm.getAscent();
gc.dispose();
int indent = 6;
int extent = DEFAULT_EXTENT;
if (w instanceof Table) {
extent = ((Table) w).getItemHeight() - 1;
} else if (w instanceof Tree) {
extent = ((Tree) w).getItemHeight() - 1;
}
if (size > extent) {
size = extent;
}
int width = indent + size;
int height = extent;
ImageData data = null;
// If its a url then we will not show anything.
boolean isUrl = Converter.isStringUrl(fileLocation);
if (!isUrl) {
try {
Image rImage = new Image(Display.getCurrent(), fileLocation);
data = rImage.getImageData().scaledTo(width, height);
} catch (Exception e) {
ForgedUICorePlugin.logError(e);
}
return data;
} else {
return null;
}
}
示例5: draw
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
/**
* Draw string at widget offset.
*
* @param gc
* @param offset
* the widget offset
* @param s
* the string to be drawn
* @param fg
* the foreground color
*/
private void draw(GC gc, int offset, String s, Color fg)
{
// Compute baseline delta (see
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=165640)
int baseline = fTextWidget.getBaseline(offset);
FontMetrics fontMetrics = gc.getFontMetrics();
int fontBaseline = fontMetrics.getAscent() + fontMetrics.getLeading();
int baslineDelta = baseline - fontBaseline;
Point pos = fTextWidget.getLocationAtOffset(offset);
gc.setForeground(fg);
gc.drawString(s, pos.x, pos.y + baslineDelta, true);
}
示例6: getFMAscent
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
public float getFMAscent(){
this.setAdvanced(false);
FontMetrics fm = this.gc.getFontMetrics();
return (fm.getAscent() + fm.getLeading());
}
示例7: createColorImage
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
/**
* Creates and returns the color image data for the given control
* and RGB value. The image's size is either the control's item extent
* or the cell editor's default extent, which is 16 pixels square.
*
* @param w the control
* @param color the color
*/
private ImageData createColorImage(Control w, RGB color) {
GC gc = new GC(w);
FontMetrics fm = gc.getFontMetrics();
int size = fm.getAscent();
gc.dispose();
int indent = 6;
int extent = DEFAULT_EXTENT;
if (w instanceof Table) {
extent = ((Table) w).getItemHeight() - 1;
} else if (w instanceof Tree) {
extent = ((Tree) w).getItemHeight() - 1;
} else if (w instanceof TableTree) {
extent = ((TableTree) w).getItemHeight() - 1;
}
if (size > extent) {
size = extent;
}
int width = indent + size;
int height = extent;
int xoffset = indent;
int yoffset = (height - size) / 2;
RGB black = new RGB(0, 0, 0);
PaletteData dataPalette = new PaletteData(new RGB[] { black, black,
color });
ImageData data = new ImageData(width, height, 4, dataPalette);
data.transparentPixel = 0;
int end = size - 1;
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (x == 0 || y == 0 || x == end || y == end) {
data.setPixel(x + xoffset, y + yoffset, 1);
} else {
data.setPixel(x + xoffset, y + yoffset, 2);
}
}
}
return data;
}
示例8: getBaselineBias
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
/**
* Returns the difference between the baseline of the widget and the baseline as specified by
* the font for <code>gc</code>. When drawing line numbers, the returned bias should be added to
* obtain text lined up on the correct base line of the text widget.
*
* @param gc
* the {@code GC} to get the font metrics from
* @param widgetLine
* the widget line
* @return the baseline bias to use when drawing text that is lined up with the text widget.
*/
private int getBaselineBias(GC gc, int widgetLine) {
ITextViewer textViewer = getParentRuler().getTextViewer();
int offset = textViewer.getTextWidget().getOffsetAtLine(widgetLine);
int widgetBaseline = textViewer.getTextWidget().getBaseline(offset);
FontMetrics fm = gc.getFontMetrics();
int fontBaseline = fm.getAscent() + fm.getLeading();
int baselineBias = widgetBaseline - fontBaseline;
return Math.max(0, baselineBias);
}