return;
}
AttributedCharacterIterator aci = this.atribStr.getIterator();
FontRenderContext frc = g.getFontRenderContext();
LineBreakMeasurer lbm;
try{
lbm = new LineBreakMeasurer(aci, frc);
}catch(Exception e){
e.printStackTrace();
return;
}
// Compute text font size
float drawPosY;
float fontReduction = 0f;
int limit;
do {
getFullWord: {
this.atribStr.addAttribute(TextAttribute.SIZE, getFontSize() - fontReduction);
lbm = new LineBreakMeasurer(aci, frc);
fontReduction += 1f;
drawPosY = 0;
while (lbm.getPosition() < formatedString.length() ) {
//TextLayout layout = lbm.nextLayout(this.getWidth());
limit = lbm.getPosition() + formatedString.substring( lbm.getPosition() ).indexOf('\n')+1;
if (limit <= lbm.getPosition()){
limit = formatedString.length();
}
TextLayout layout = lbm.nextLayout(this.getWidth(), limit, true);
if (layout == null){
break getFullWord;
}
drawPosY += layout.getAscent();
drawPosY += layout.getDescent();
drawPosY += layout.getLeading();
}
}
}while ( (lbm.getPosition() < formatedString.length()) || ( drawPosY > this.getHeight() && fontReduction < getFontSize()));
// do the paiting
aci = this.atribStr.getIterator();
lbm.setPosition(0);
if ( vertAlign == VALIGN_MIDDLE ){
drawPosY = (this.getHeight() - drawPosY) / 2;
} else if (vertAlign == VALIGN_BOTTOM){
drawPosY = this.getHeight() - drawPosY;
} else {
drawPosY = 0;
}
Color oldColor = g.getColor();
Composite oldComposite = g.getComposite();
try{
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.getAlpha() * time ) );
while (lbm.getPosition() < formatedString.length() ) {
limit = lbm.getPosition() + formatedString.substring( lbm.getPosition() ).indexOf('\n')+1;
if (limit <= lbm.getPosition()){
limit = formatedString.length();
}
TextLayout layout = lbm.nextLayout(this.getWidth(), limit, true);
drawPosY += layout.getAscent();
// default alignment = Left
float drawPosX = this.getLeft();