提交 22e7e464 编写于 作者: S Siyamed Sinir 提交者: Android (Google) Code Review

Merge "Revert "Reduce memory usage of FontCollection.""

...@@ -63,8 +63,8 @@ private: ...@@ -63,8 +63,8 @@ private:
static const int kPageMask = (1 << kLogCharsPerPage) - 1; static const int kPageMask = (1 << kLogCharsPerPage) - 1;
struct Range { struct Range {
uint8_t start; size_t start;
uint8_t end; size_t end;
}; };
FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const; FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const;
...@@ -92,14 +92,14 @@ private: ...@@ -92,14 +92,14 @@ private:
// This vector can't be empty. // This vector can't be empty.
std::vector<FontFamily*> mFamilies; std::vector<FontFamily*> mFamilies;
// This vector contains indices into mFamilies. // This vector contains pointers into mInstances
// This vector can't be empty. // 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. // This vector has pointers to the font family instance which has cmap 14 subtable.
std::vector<FontFamily*> mVSFamilyVec; 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; std::vector<Range> mRanges;
// Set of supported axes in this collection. // Set of supported axes in this collection.
......
...@@ -110,8 +110,6 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) : ...@@ -110,8 +110,6 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
nTypefaces = mFamilies.size(); nTypefaces = mFamilies.size();
LOG_ALWAYS_FATAL_IF(nTypefaces == 0, LOG_ALWAYS_FATAL_IF(nTypefaces == 0,
"Font collection must have at least one valid typeface"); "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 nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage;
size_t offset = 0; size_t offset = 0;
// TODO: Use variation selector map for mRanges construction. // TODO: Use variation selector map for mRanges construction.
...@@ -125,11 +123,11 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) : ...@@ -125,11 +123,11 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
ALOGD("i=%zd: range start = %zd\n", i, offset); ALOGD("i=%zd: range start = %zd\n", i, offset);
#endif #endif
range->start = (uint8_t)offset; range->start = offset;
for (size_t j = 0; j < nTypefaces; j++) { for (size_t j = 0; j < nTypefaces; j++) {
if (lastChar[j] < (i + 1) << kLogCharsPerPage) { if (lastChar[j] < (i + 1) << kLogCharsPerPage) {
FontFamily* family = mFamilies[j]; FontFamily* family = mFamilies[j];
mFamilyVec.push_back((uint8_t)j); mFamilyVec.push_back(family);
offset++; offset++;
uint32_t nextChar = family->getCoverage().nextSetBit((i + 1) << kLogCharsPerPage); uint32_t nextChar = family->getCoverage().nextSetBit((i + 1) << kLogCharsPerPage);
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
...@@ -138,7 +136,7 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) : ...@@ -138,7 +136,7 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
lastChar[j] = nextChar; lastChar[j] = nextChar;
} }
} }
range->end = (uint8_t)offset; range->end = offset;
} }
} }
...@@ -285,10 +283,11 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, ...@@ -285,10 +283,11 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
return mFamilies[0]; return mFamilies[0];
} }
const std::vector<FontFamily*>& familyVec = (vs == 0) ? mFamilyVec : mFamilies;
Range range = mRanges[ch >> kLogCharsPerPage]; Range range = mRanges[ch >> kLogCharsPerPage];
if (vs != 0) { if (vs != 0) {
range = { 0, (uint8_t)mFamilies.size() }; range = { 0, mFamilies.size() };
} }
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
...@@ -297,7 +296,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, ...@@ -297,7 +296,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs,
FontFamily* bestFamily = nullptr; FontFamily* bestFamily = nullptr;
uint32_t bestScore = kUnsupportedFontScore; uint32_t bestScore = kUnsupportedFontScore;
for (size_t i = range.start; i < range.end; i++) { 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); const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family);
if (score == kFirstFontScore) { if (score == kFirstFontScore) {
// If the first font family supports the given character or variation sequence, always // If the first font family supports the given character or variation sequence, always
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册