Properly pre-cache latin glyphs
Bug #6408362

Change-Id: Ie11644c5a9e2d87d3b851b7e619e5f04b60a7e02
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 9e7fbb5..44bfb11 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -776,12 +776,6 @@
     initTextTexture();
     initVertexArrayBuffers();
 
-    // We store a string with letters in a rough frequency of occurrence
-    mLatinPrecache = String16("eisarntolcdugpmhbyfvkwzxjq ");
-    mLatinPrecache += String16("EISARNTOLCDUGPMHBYFVKWZXJQ");
-    mLatinPrecache += String16(",.?!()-+@;:'");
-    mLatinPrecache += String16("0123456789");
-
     mInitialized = true;
 }
 
@@ -944,11 +938,19 @@
 void FontRenderer::precacheLatin(SkPaint* paint) {
     // Remaining capacity is measured in %
     uint32_t remainingCapacity = getRemainingCacheCapacity();
-    uint32_t precacheIdx = 0;
-    while (remainingCapacity > 25 && precacheIdx < mLatinPrecache.size()) {
-        mCurrentFont->getCachedGlyph(paint, (int32_t) mLatinPrecache[precacheIdx]);
+    uint32_t precacheIndex = 0;
+
+    // We store a string with letters in a rough frequency of occurrence
+    String16 l("eisarntolcdugpmhbyfvkwzxjq EISARNTOLCDUGPMHBYFVKWZXJQ,.?!()-+@;:'0123456789");
+
+    size_t size = l.size();
+    uint16_t latin[size];
+    paint->utfToGlyphs(l.string(), SkPaint::kUTF16_TextEncoding, size * sizeof(char16_t), latin);
+
+    while (remainingCapacity > 25 && precacheIndex < size) {
+        mCurrentFont->getCachedGlyph(paint, TO_GLYPH(latin[precacheIndex]));
         remainingCapacity = getRemainingCacheCapacity();
-        precacheIdx ++;
+        precacheIndex++;
     }
 }