* @param context
* @return TextMetric or null if the text is empty or null
*/
public TextMetrics measure(Context2D context)
{
TextMetrics size = null;
String text = getText();
if ((null == text) || (text.isEmpty()))
{
return size;
}
context.save();
context.setTextAlign(TextAlign.LEFT);
context.setTextBaseline(TextBaseLine.ALPHABETIC);
context.setTextFont(getFontStyle() + " " + getFontSize() + "pt " + getFontFamily());
double width = getStrokeWidth();
if (width == 0)
{
width = 1;
}
context.setStrokeWidth(width);
context.transform(getAbsoluteTransform());
size = context.measureText(text);
double height = context.measureText("M").getWidth();
size.setHeight(height - height / 6);
context.restore();
return size;
}