public static void drawAtPoint(String texttodisplay, CGPoint point, UIFont font) { Graphics2D graphicsContext = CGContext.UICurrentContext().xmlvmGetGraphics2D(); Font savedFont = graphicsContext.getFont(); graphicsContext.setFont(font.xmlvmGetFont()); graphicsContext.drawString(texttodisplay, point.x, point.y); graphicsContext.setFont(savedFont); }
public static CGSize sizeWithFont(String text, UIFont font) { Graphics2D graphicsContext = CGContext.UICurrentContext().xmlvmGetGraphics2D(); Font savedFont = graphicsContext.getFont(); Font awtFont = font.xmlvmGetFont(); graphicsContext.setFont(awtFont); Rectangle2D size = awtFont.getStringBounds(text, graphicsContext.getFontRenderContext()); graphicsContext.setFont(savedFont); return new CGSize( (float) size.getWidth(), text != null && text.length() > 0 ? (float) size.getHeight() : 0.0f); }