当前位置: 首页>>代码示例>>Java>>正文


Java FontMetrics.getAscent方法代码示例

本文整理汇总了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;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:33,代码来源:PSWTText.java

示例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);
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:28,代码来源:CommonLineNumberRulerColumn.java

示例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;
}
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:35,代码来源:ImageUtilities.java

示例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;
        }
    }
 
开发者ID:ShoukriKattan,项目名称:ForgedUI-Eclipse,代码行数:39,代码来源:ImageCellEditor.java

示例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);
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:25,代码来源:WhitespaceCharacterPainter.java

示例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());
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:7,代码来源:TGPainterImpl.java

示例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;
  }
 
开发者ID:ghillairet,项目名称:gef-gwt,代码行数:55,代码来源:ColorCellEditor.java

示例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);
}
 
开发者ID:kopl,项目名称:SPLevo,代码行数:22,代码来源:UnifiedDiffRulerColumn.java


注:本文中的org.eclipse.swt.graphics.FontMetrics.getAscent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。