From 4e4ab1a6c8347e977245d1126d10e48a3412d35d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 29 Oct 2014 11:04:04 -0700 Subject: Move coverage bitmap from FontCollection to FontFamily This will significantly reduce memory usage and also speed the creation of new font families. In particular, the coverage bitmaps for the fonts in the fallback stack will be computed once in the Zygote, rather than separately in each app process. Bug: 17756900 Change-Id: I66f5706bddd4658d78fe5b709f7251ca9d2ff4f8 --- libs/minikin/FontFamily.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libs/minikin/FontFamily.cpp') diff --git a/libs/minikin/FontFamily.cpp b/libs/minikin/FontFamily.cpp index f688a33..d2e5867 100644 --- a/libs/minikin/FontFamily.cpp +++ b/libs/minikin/FontFamily.cpp @@ -23,6 +23,7 @@ #include "MinikinInternal.h" #include #include +#include #include #include @@ -128,6 +129,7 @@ void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); + mCoverageValid = false; } // Compute a matching metric between two styles - 0 is an exact match @@ -183,4 +185,23 @@ FontStyle FontFamily::getStyle(size_t index) const { return mFonts[index].style; } +const SparseBitSet* FontFamily::getCoverage() { + if (!mCoverageValid) { + const FontStyle defaultStyle; + MinikinFont* typeface = getClosestMatch(defaultStyle).font; + const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); + size_t cmapSize = 0; + bool ok = typeface->GetTable(cmapTag, NULL, &cmapSize); + UniquePtr cmapData(new uint8_t[cmapSize]); + ok = typeface->GetTable(cmapTag, cmapData.get(), &cmapSize); + CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize); +#ifdef VERBOSE_DEBUG + ALOGD("font coverage length=%d, first ch=%x\n", mCoverage->length(), + mCoverage->nextSetBit(0)); +#endif + mCoverageValid = true; + } + return &mCoverage; +} + } // namespace android -- cgit v1.2.3