summaryrefslogtreecommitdiffstats
path: root/libs/minikin/FontFamily.cpp
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-10-29 11:04:04 -0700
committerRaph Levien <raph@google.com>2014-10-29 12:34:50 -0700
commit253320d25fccbb49621926d49dcf5ef64cf529c6 (patch)
tree1de01efab8dc3c9ec5026fa93cfe3d60d0d5d217 /libs/minikin/FontFamily.cpp
parent5f11abd31fa8cfa723f54bd1c98ce4e27e7d3c77 (diff)
downloadandroid_frameworks_minikin-253320d25fccbb49621926d49dcf5ef64cf529c6.tar.gz
android_frameworks_minikin-253320d25fccbb49621926d49dcf5ef64cf529c6.tar.bz2
android_frameworks_minikin-253320d25fccbb49621926d49dcf5ef64cf529c6.zip
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
Diffstat (limited to 'libs/minikin/FontFamily.cpp')
-rw-r--r--libs/minikin/FontFamily.cpp21
1 files changed, 21 insertions, 0 deletions
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 <minikin/MinikinFont.h>
#include <minikin/AnalyzeStyle.h>
+#include <minikin/CmapCoverage.h>
#include <minikin/FontFamily.h>
#include <UniquePtr.h>
@@ -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<uint8_t[]> 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