Java Code Examples for javafx.scene.text.Text#getLayoutBounds()

The following examples show how to use javafx.scene.text.Text#getLayoutBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FontDetails.java    From dm3270 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: GraphicsContextImpl.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 3
Source File: StringViewer.java    From JetUML with GNU General Public License v3.0 4 votes vote down vote up
/**
    * 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());
}
 
Example 4
Source File: JFXCanvasDepictor.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License votes vote down vote up
private Bounds getBounds(String s)
    {
        Text t = new Text(s);
        t.setFont(currentFont);
        return t.getLayoutBounds();
    }