本文整理汇总了Java中org.eclipse.swt.graphics.FontMetrics.getDescent方法的典型用法代码示例。如果您正苦于以下问题:Java FontMetrics.getDescent方法的具体用法?Java FontMetrics.getDescent怎么用?Java FontMetrics.getDescent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.swt.graphics.FontMetrics
的用法示例。
在下文中一共展示了FontMetrics.getDescent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getAscent
import org.eclipse.swt.graphics.FontMetrics; //导入方法依赖的package包/类
/**
* Gets the font's ascent.
*
* @param font
* @return the font's ascent
*/
public int getAscent(Font font) {
FontMetrics fm = FigureUtilities.getFontMetrics(font);
return fm.getHeight() - fm.getDescent();
}