I'm writing an application that has a custom text layout engine, and for this to work I must measure lots (thousands) of Strings using the .getTextBounds() method on the Paint class.
It does work. But on some devices, this measurement is extremely slow.
For example, measuring 10,000 5-6 chars long words
- Samsung Galaxy S2 phone (or any other kind of device from the Samsung Galaxy series): 1.5 seconds
- HTC Desire HD: ~90 seconds.
- Asus Transformer TF300: ~30 seconds
- Etc.
I've done method profiling and all I can see that the native Skia implementation of the measurement method takes much longer on some devices.
I'm doing nothing fancy during measurement, my code looks something like this:
Paint paint = new Paint();
Rect bounds = new Rect();
paint.setTextSize(22.0f);
for (int i = 0; i < input.length; i++) {
paint.getTextBounds(input[i], 0, input[i].length(), bounds);
}
Is there something to look out for when measuring text dimensions? Did the manufacturers screw up something related to the font cache implementation in the ROM? Is there something I can do about this?