のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

getClosestMatch

Cross Reference: /frameworks/minikin/libs/minikin/FontFamily.cpp

    129 FakedFont FontFamily::getClosestMatch(FontStyle style) const {
    130     const Font* bestFont = NULL;
    131     int bestMatch = 0;
    132     for (size_t i = 0; i < mFonts.size(); i++) {
    133         const Font& font = mFonts[i];
    134         int match = computeMatch(font.style, style);
    135         if (i == 0 || match < bestMatch) {
    136             bestFont = &font;
    137             bestMatch = match;
    138         }
    139     }
    140     FakedFont result;
    141     if (bestFont == NULL) {
    142         result.font = NULL;
    143     } else {
    144         result.font = bestFont->typeface;
    145         result.fakery = computeFakery(style, bestFont->style);
    146     }
    147     return result;
    148 }

Cross Reference: /frameworks/minikin/libs/minikin/FontCollection.cpp

     77 
     78 FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
     79     mMaxChar(0) {
     80     AutoMutex _l(gMinikinLock);
     81     mId = sNextId++;
     82     vector<uint32_t> lastChar;
     83     size_t nTypefaces = typefaces.size();
     84 #ifdef VERBOSE_DEBUG
     85     ALOGD("nTypefaces = %zd\n", nTypefaces);
     86 #endif
     87     const FontStyle defaultStyle;
     88     for (size_t i = 0; i < nTypefaces; i++) {
     89         FontFamily* family = typefaces[i];
     90         MinikinFont* typeface = family->getClosestMatch(defaultStyle).font;
     91         if (typeface == NULL) {
     92             continue;
     93         }
     94         family->RefLocked();
     95         const SparseBitSet* coverage = family->getCoverage();
     96         if (coverage == nullptr) {
     97             family->UnrefLocked();
     98             continue;
     99         }
    100         mFamilies.push_back(family);  // emplace_back would be better
    101         if (family->hasVSTable()) {
    102             mVSFamilyVec.push_back(family);
    103         }
    104         mMaxChar = max(mMaxChar, coverage->length());
    105         lastChar.push_back(coverage->nextSetBit(0));
    106     }
    107     nTypefaces = mFamilies.size();
    108     LOG_ALWAYS_FATAL_IF(nTypefaces == 0,
    109         "Font collection must have at least one valid typeface");
    110     size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage;
    111     size_t offset = 0;
    112     // TODO: Use variation selector map for mRanges construction.
    113     // A font can have a glyph for a base code point and variation selector pair but no glyph for
    114     // the base code point without variation selector. The family won't be listed in the range in
    115     // this case.
    116     for (size_t i = 0; i < nPages; i++) {
    117         Range dummy;
    118         mRanges.push_back(dummy);
    119         Range* range = &mRanges.back();
    120 #ifdef VERBOSE_DEBUG
    121         ALOGD("i=%zd: range start = %zd\n", i, offset);
    122 #endif
    123         range->start = offset;
    124         for (size_t j = 0; j < nTypefaces; j++) {
    125             if (lastChar[j] < (i + 1) << kLogCharsPerPage) {
    126                 FontFamily* family = mFamilies[j];
    127                 mFamilyVec.push_back(family);
    128                 offset++;
    129                 uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage);
    130 #ifdef VERBOSE_DEBUG
    131                 ALOGD("nextChar = %d (j = %zd)\n", nextChar, j);
    132 #endif
    133                 lastChar[j] = nextChar;
    134             }
    135         }
    136         range->end = offset;
    137     }
    138 }