Fix text width measurement on Android when there are spaces at the start/end of the string (bounds doesn't handle that). Fixes 10174

This commit is contained in:
Henrik Rydgård 2017-11-22 22:45:03 +01:00
parent 3ecd7b4c02
commit 495532f0ff

View File

@ -26,10 +26,8 @@ public class TextRenderer {
} }
} }
private static Point measure(String string, double textSize) { private static Point measure(String string, double textSize) {
Rect bound = new Rect();
p.setTextSize((float)textSize); p.setTextSize((float)textSize);
p.getTextBounds(string, 0, string.length(), bound); int w = (int)p.measureText(string);
int w = bound.width();
int h = (int)(p.descent() - p.ascent() + 2.0f); int h = (int)(p.descent() - p.ascent() + 2.0f);
// Round width up to even already here to avoid annoyances from odd-width 16-bit textures which // Round width up to even already here to avoid annoyances from odd-width 16-bit textures which
// OpenGL does not like - each line must be 4-byte aligned // OpenGL does not like - each line must be 4-byte aligned