Fix some stuff
This commit is contained in:
parent
0452e1f809
commit
903a61e39b
1 changed files with 7 additions and 4 deletions
|
@ -51,25 +51,28 @@ public class Renderer {
|
||||||
int textHeight = (int) bounds.getHeight();
|
int textHeight = (int) bounds.getHeight();
|
||||||
y += textHeight;
|
y += textHeight;
|
||||||
|
|
||||||
|
int textLength = text.length();
|
||||||
|
|
||||||
String[] lines;
|
String[] lines;
|
||||||
|
|
||||||
if (textWidth > tileSize) { // TODO ideally this should be splitting by word
|
if (textWidth > tileSize) { // TODO ideally this should be splitting by word
|
||||||
int linesAmount = (int) Math.ceil((double) textWidth / tileSize);
|
int linesAmount = (int) Math.ceil((double) textWidth / tileSize);
|
||||||
|
|
||||||
if (linesAmount * textHeight > tileSize) {
|
if (linesAmount * textHeight > tileSize) {
|
||||||
int removeChars = (int) (text.length() - (text.length() / ((double) textWidth / tileSize)) * (tileSize / textHeight));
|
double tsd = tileSize;
|
||||||
System.out.printf("Warning: text can't fit in a tile (%d > %d). Remove %d characters. \"%s\"\n", linesAmount * textHeight, tileSize, removeChars, text);
|
int removeChars = (int) (textLength - (textLength / (textWidth / tsd)) * (tsd / textHeight));
|
||||||
|
System.out.printf("Warning: text doesn't fit in a tile (%d > %d). Remove %d characters. \"%s\"\n", linesAmount * textHeight, tileSize, removeChars, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
lines = new String[linesAmount];
|
lines = new String[linesAmount];
|
||||||
int partLength = text.length() / linesAmount;
|
int partLength = textLength / linesAmount;
|
||||||
|
|
||||||
for (int i=0; i<linesAmount; i++) {
|
for (int i=0; i<linesAmount; i++) {
|
||||||
lines[i] = text.substring(partLength * i, partLength * (i + 1));
|
lines[i] = text.substring(partLength * i, partLength * (i + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case the ending was lost due to imprecise division
|
// in case the ending was lost due to imprecise division
|
||||||
if (partLength * linesAmount < text.length()) {
|
if (partLength * linesAmount < textLength) {
|
||||||
lines[linesAmount - 1] += text.substring(partLength * linesAmount);
|
lines[linesAmount - 1] += text.substring(partLength * linesAmount);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue