summaryrefslogtreecommitdiffstats
path: root/libs/minikin/FontFamily.cpp
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-10-29 11:04:04 -0700
committerArne Coucheron <arco68@gmail.com>2015-02-13 03:49:34 +0100
commit4e4ab1a6c8347e977245d1126d10e48a3412d35d (patch)
tree61d23f7172172f7e625eb7ccb6e4c3f7bc38685a /libs/minikin/FontFamily.cpp
parentd5804e3937a961736e5cef0e8a70eacf91ee00bb (diff)
downloadandroid_frameworks_minikin-4e4ab1a6c8347e977245d1126d10e48a3412d35d.tar.gz
android_frameworks_minikin-4e4ab1a6c8347e977245d1126d10e48a3412d35d.tar.bz2
android_frameworks_minikin-4e4ab1a6c8347e977245d1126d10e48a3412d35d.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