Fix missing text on nonexistent font file

Fix for bug 15570313 "Missing text on nonexistent font file"

This patch makes sure that the lastChar and mInstances arrays are in
sync with each other even when a FontFamily being added has no valid
fonts in it. Previously, when they got out of sync, unicode coverage
calculation would be wrong, resulting in missing text.

Change-Id: I69c727ef69e2c61e2b2d6b81d5a28c806327f865
This commit is contained in:
Raph Levien 2014-06-11 15:02:11 -07:00
parent 9c9cab6487
commit 43e8943dfd

View File

@ -46,12 +46,6 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
const FontStyle defaultStyle;
for (size_t i = 0; i < nTypefaces; i++) {
FontFamily* family = typefaces[i];
family->RefLocked();
FontInstance dummy;
mInstances.push_back(dummy); // emplace_back would be better
FontInstance* instance = &mInstances.back();
instance->mFamily = family;
instance->mCoverage = new SparseBitSet;
MinikinFont* typeface = family->getClosestMatch(defaultStyle).font;
if (typeface == NULL) {
ALOGE("FontCollection: closest match was null");
@ -59,6 +53,12 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
// checks upstream to prevent empty/invalid FontFamily objects
continue;
}
family->RefLocked();
FontInstance dummy;
mInstances.push_back(dummy); // emplace_back would be better
FontInstance* instance = &mInstances.back();
instance->mFamily = family;
instance->mCoverage = new SparseBitSet;
#ifdef VERBOSE_DEBUG
ALOGD("closest match = %p, family size = %d\n", typeface, family->getNumFonts());
#endif
@ -75,6 +75,7 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
mMaxChar = max(mMaxChar, instance->mCoverage->length());
lastChar.push_back(instance->mCoverage->nextSetBit(0));
}
nTypefaces = mInstances.size();
size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage;
size_t offset = 0;
for (size_t i = 0; i < nPages; i++) {