Revert "Reduce memory usage of FontCollection."

This reverts commit c4b989fc812af6c94018bad2e30ed6a006e2f8f5.

Test: Manually tested
Bug: 34247671
Change-Id: I0510009b2deac784770f26059681b1980800abc8
(cherry picked from commit 1d753f6fe91ff47e5a76fa1707da91cfe90c200e)
diff --git a/include/minikin/FontCollection.h b/include/minikin/FontCollection.h
index f6312dc..c9c8520 100644
--- a/include/minikin/FontCollection.h
+++ b/include/minikin/FontCollection.h
@@ -58,8 +58,8 @@
     static const int kPageMask = (1 << kLogCharsPerPage) - 1;
 
     struct Range {
-        uint8_t start;
-        uint8_t end;
+        size_t start;
+        size_t end;
     };
 
     FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const;
@@ -87,14 +87,14 @@
     // This vector can't be empty.
     std::vector<FontFamily*> mFamilies;
 
-    // This vector contains indices into mFamilies.
+    // This vector contains pointers into mInstances
     // This vector can't be empty.
-    std::vector<uint8_t> mFamilyVec;
+    std::vector<FontFamily*> mFamilyVec;
 
     // This vector has pointers to the font family instance which has cmap 14 subtable.
     std::vector<FontFamily*> mVSFamilyVec;
 
-    // These are offsets into mFamilyVec, one range per page
+    // These are offsets into mInstanceVec, one range per page
     std::vector<Range> mRanges;
 };
 
diff --git a/libs/minikin/FontCollection.cpp b/libs/minikin/FontCollection.cpp
index 2a35689..9d26377 100644
--- a/libs/minikin/FontCollection.cpp
+++ b/libs/minikin/FontCollection.cpp
@@ -111,8 +111,6 @@
     nTypefaces = mFamilies.size();
     LOG_ALWAYS_FATAL_IF(nTypefaces == 0,
         "Font collection must have at least one valid typeface");
-    LOG_ALWAYS_FATAL_IF(nTypefaces > 254,
-        "Up to 254 font families can be registered to collection.");
     size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage;
     size_t offset = 0;
     // TODO: Use variation selector map for mRanges construction.
@@ -126,11 +124,11 @@
 #ifdef VERBOSE_DEBUG
         ALOGD("i=%zd: range start = %zd\n", i, offset);
 #endif
-        range->start = (uint8_t)offset;
+        range->start = offset;
         for (size_t j = 0; j < nTypefaces; j++) {
             if (lastChar[j] < (i + 1) << kLogCharsPerPage) {
                 FontFamily* family = mFamilies[j];
-                mFamilyVec.push_back((uint8_t)j);
+                mFamilyVec.push_back(family);
                 offset++;
                 uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage);
 #ifdef VERBOSE_DEBUG
@@ -139,7 +137,7 @@
                 lastChar[j] = nextChar;
             }
         }
-        range->end = (uint8_t)offset;
+        range->end = offset;
     }
 }
 
@@ -286,10 +284,11 @@
         return mFamilies[0];
     }
 
+    const std::vector<FontFamily*>& familyVec = (vs == 0) ? mFamilyVec : mFamilies;
     Range range = mRanges[ch >> kLogCharsPerPage];
 
     if (vs != 0) {
-        range = { 0, (uint8_t)mFamilies.size() };
+        range = { 0, mFamilies.size() };
     }
 
 #ifdef VERBOSE_DEBUG
@@ -298,7 +297,7 @@
     FontFamily* bestFamily = nullptr;
     uint32_t bestScore = kUnsupportedFontScore;
     for (size_t i = range.start; i < range.end; i++) {
-        FontFamily* family = vs == 0 ? mFamilies[mFamilyVec[i]] : mFamilies[i];
+        FontFamily* family = familyVec[i];
         const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family);
         if (score == kFirstFontScore) {
             // If the first font family supports the given character or variation sequence, always