@Override
public Rectangle2D getBounds(IElement e, Rectangle2D size) {
- return calculateBounds(e, size, horizontalAlignment, verticalAlignment, scale, paddingX, paddingY);
+ return getBounds(e, size, horizontalAlignment, verticalAlignment, scale, paddingX, paddingY);
}
-
- public static Rectangle2D calculateBounds(
+
+ public static Rectangle2D getBounds(
IElement e,
Rectangle2D size,
Alignment horizontalAlignment,
double scale,
double paddingX,
double paddingY) {
-
TextNode node = (TextNode) e.getHint(SG_NODE);
Rectangle2D b = e.getHint(ElementHints.KEY_BOUNDS);
-
+
if (size == null)
size = new Rectangle2D.Double();
if (node != null)
size.setRect(node.getBoundsInLocal());
else if(b != null && ElementUtils.getHintOrDefault(e, ElementHints.KEY_RESIZABLE, false))
size.setRect(b);
- 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 {
- 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());
-
- Rectangle2D r = n.getBoundsInLocal();
- size.setFrame(r);
- return r;
- }
- }
+ 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;
+ }
return size;
}