- else {
- String text = e.getHint(ElementHints.KEY_TEXT);
- Font font = e.getHint(ElementHints.KEY_FONT);
- if(text == null || font == null)
- size.setFrame(0, 0, 0, 0);
- else {
- FontRenderContext FRC = new FontRenderContext(new AffineTransform(), true, true);
- TextLayout tl = new TextLayout(text, font, FRC);
- Rectangle2D bounds = tl.getLogicalHighlightShape(0, text.length()).getBounds2D();
- size.setFrame(
- getAlignedXCoordinate(bounds, horizontalAlignment) * scale - paddingX,
- bounds.getY() * scale -paddingY,
- bounds.getWidth()* scale + paddingX + paddingX,
- bounds.getHeight()* scale + paddingY + paddingY);
- }
- }
+ else calculateBounds(e, size, horizontalAlignment, verticalAlignment, scale, paddingX, paddingY);
+
+ return size;
+ }
+
+ public static Rectangle2D calculateBounds(
+ IElement e,
+ Rectangle2D size,
+ Alignment horizontalAlignment,
+ Alignment verticalAlignment,
+ double scale,
+ double paddingX,
+ double paddingY) {
+
+ if (size == null)
+ size = new Rectangle2D.Double();
+
+ String text = e.getHint(ElementHints.KEY_TEXT);
+ Font font = e.getHint(ElementHints.KEY_FONT);
+ if(text == null || font == null) {
+ size.setFrame(0, 0, 0, 0);
+ } else {
+ TextNode n= new TextNode();
+ n.init(text, font, Color.black, 0.0, 0.0, scale);
+ n.setHorizontalAlignment((byte)horizontalAlignment.ordinal());
+ n.setVerticalAlignment((byte)verticalAlignment.ordinal());
+ n.setPadding(paddingX, paddingY);
+ Rectangle2D r = n.getBoundsInLocal();
+ size.setFrame(r);
+ return r;
+ }