javafx.scene.text.Text#getLayoutBounds ( )源码实例Demo

下面列出了javafx.scene.text.Text#getLayoutBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dm3270   文件: FontDetails.java
public FontDetails (String name, int size, Font font)
{
  this.font = font;
  this.name = name;
  this.size = size;

  Text text = new Text ("W");
  text.setFont (font);
  Bounds bounds = text.getLayoutBounds ();
  height = (int) (bounds.getHeight () + 0.5);
  width = (int) (bounds.getWidth () + 0.5);
  ascent = (int) (-bounds.getMinY () + 0.5);
  descent = height - ascent;
}
 
源代码2 项目: openchemlib-js   文件: GraphicsContextImpl.java
@Override
public java.awt.Dimension getBounds(String s)
{
    Font currentFont = ctx.getFont();
    Text t = new Text(s);
    t.setFont(currentFont);
    Bounds b = t.getLayoutBounds();
    java.awt.Dimension bounds = new java.awt.Dimension((int)b.getWidth(), (int)b.getHeight());
    return bounds;
}
 
源代码3 项目: JetUML   文件: StringViewer.java
/**
    * Draws the string inside a given rectangle.
    * @param pString The string to draw.
    * @param pGraphics the graphics context
    * @param pRectangle the rectangle into which to place the string
 */
public void draw(String pString, GraphicsContext pGraphics, Rectangle pRectangle)
{
	Text label = getLabel(pString);
	
	pGraphics.setTextAlign(label.getTextAlignment());
	
	int textX = 0;
	int textY = 0;
	if(aAlignment == Align.CENTER) 
	{
		textX = pRectangle.getWidth()/2;
		textY = pRectangle.getHeight()/2;
		pGraphics.setTextBaseline(VPos.CENTER);
	}
	else
	{
		pGraphics.setTextBaseline(VPos.TOP);
		textX = HORIZONTAL_TEXT_PADDING;
	}
	
	pGraphics.translate(pRectangle.getX(), pRectangle.getY());
	ViewUtils.drawText(pGraphics, textX, textY, pString.trim(), getFont());
	
	if(aUnderlined && pString.trim().length() > 0)
	{
		int xOffset = 0;
		int yOffset = 0;
		Bounds bounds = label.getLayoutBounds();
		if(aAlignment == Align.CENTER)
		{
			xOffset = (int) (bounds.getWidth()/2);
			yOffset = (int) (getFont().getSize()/2) + 1;
		}
		else if(aAlignment == Align.RIGHT)
		{
			xOffset = (int) bounds.getWidth();
		}
		
		ViewUtils.drawLine(pGraphics, textX-xOffset, textY+yOffset, 
				(int) (textX-xOffset+bounds.getWidth()), textY+yOffset, LineStyle.SOLID);
	}
	pGraphics.translate(-pRectangle.getX(), -pRectangle.getY());
}
 
源代码4 项目: openchemlib-js   文件: JFXCanvasDepictor.java
private Bounds getBounds(String s)
    {
        Text t = new Text(s);
        t.setFont(currentFont);
        return t.getLayoutBounds();
    }