String fontFamily = text.getFontFamily();
int fontSize = (int) text.getFontSize();
Font font = new Font(fontFamily, Font.PLAIN, fontSize);
FontMetrics fm = g.getFontMetrics(font);
Point2D currentPosition = new Point2D.Double(renderArea.getX(), renderArea.getY());
TextLine textLine = null;
double minPadding = fm.getHeight();
try {
for (int i = 0; i < tags.size(); i++) {
Tag tag = tags.get(i);
String value = tag.getValue();
Rectangle2D rect = fm.getStringBounds(value, g);
// create new textline if not exists
if (i == 0) {
textLine = new TextLine();
textLines.add(textLine);
}
if (currentPosition.getX() + rect.getWidth() + minPadding >= (renderArea.getX() + renderArea.getWidth())) {
currentPosition.setLocation(renderArea.getX(),
currentPosition.getY() + fm.getHeight() * 1.2);
if ((currentPosition.getY() + fm.getHeight()) >= (renderArea.getY() + renderArea.getHeight()))
break;
textLine = new TextLine();
textLines.add(textLine);
}
TSpan tspan = new TSpan(currentPosition.getX(),
currentPosition.getY() + Math.abs(rect.getY()),
rect.getWidth(),
rect.getHeight(),
fontFamily, fontSize, value);
currentPosition.setLocation(currentPosition.getX() + rect.getWidth() + minPadding,
currentPosition.getY());
textLine.getTspans().add(tspan);
text.getTspans().add(tspan);
}
for (TextLine line : textLines) {
if (line.getTspans().size() > 1) {