I use textpaint for measuring text width but it is happens frequently and textPaint.measureText(string)
is very slow.
How can I change my code to speed up the measuring?
This is my code -
void appendLines(String text, TextPaint textPaint){
String[] linesWords = text.split(" ", -1);
for (String linesWord : linesWords) {
appendWords( " " + linesWord , textPaint);
}
}
boolean firstWord = false;
private void appendWords(String text, TextPaint textPaint){
if (text.contains("<br/>")) {
text = text.replace("<br/>", "");
haveBrTag = true;
}
float textWidth = textPaint.measureText(text);
if(textWidth + currentLineWidth + marginRightLeft> pageWidth) {
finalizeAppend(textPaint);
firstWord = true;
}
if (currentLineWidth == 0){
text = text.replace(" ", "");
firstWord = false;
}
currentLineWidth += textWidth;
currentLine.append(text);
if (haveBrTag){
finalizeAppend(textPaint);
haveBrTag = false;
}
}