のねのBlog

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

fontfamily

   1180 int RenderStyle::computedLineHeight(RenderView* renderView) const
   1181 {
   1182     const Length& lh = lineHeight();
   1183 
   1184     // Negative value means the line height is not set. Use the font's built-in spacing.
   1185     if (lh.isNegative())
   1186         return fontMetrics().lineSpacing(); <=====
   1187 
   1188     if (lh.isPercent())
   1189         return minimumValueForLength(lh, fontSize());
   1190 
   1191     if (lh.isViewportPercentage())
   1192         return valueForLength(lh, 0, renderView);
   1193 
   1194     return lh.value();
   1195 }
 1146 const FontMetrics& RenderStyle::fontMetrics() const {
          return inherited->font.fontMetrics(); 
      }
   135     const FontMetrics& fontMetrics() const {
               return primaryFont()->fontMetrics(); 
           }
    301 inline const SimpleFontData* Font::primaryFont() const
    302 {
    303     ASSERT(m_fontFallbackList);
    304     return m_fontFallbackList->primarySimpleFontData(this);
    305 }
     88     const SimpleFontData* primarySimpleFontData(const Font* f)
     89     {
     90         ASSERT(isMainThread());
     91         if (!m_cachedPrimarySimpleFontData)                                                <===== 下の関数を読んでいるのでNULL
     92             m_cachedPrimarySimpleFontData = primaryFontData(f)->fontDataForCharacter(' '); <=====
     93         return m_cachedPrimarySimpleFontData;
     94     }
     91 const FontData* FontFallbackList::primaryFontData(const Font* f) const
     92 {
     93     for (unsigned fontIndex = 0; ; ++fontIndex) {
     94         const FontData* fontData = fontDataAt(f, fontIndex); <=====
     95         if (!fontData) {
     96             // All fonts are custom fonts and a loading. Return the first FontData.
     97             // FIXME: Correct fallback to the default font.
     98             return fontDataAt(f, 0);
     99         }
    100 
    101         // When a custom font is loading, we should use the correct fallback font to layout the text.
    102         // Here skip the temporary font for the loading custom font which may not act as the correct fallback font.
    103         if (!fontData->isLoading())
    104             return fontData;
    105     }
    106 }
    108 const FontData* FontFallbackList::fontDataAt(const Font* font, unsigned realizedFontIndex) const
    109 {
    110     if (realizedFontIndex < m_fontList.size())
    111         return m_fontList[realizedFontIndex].get(); // This fallback font is already in our list.
    112 
    113     // Make sure we're not passing in some crazy value here.
    114     ASSERT(realizedFontIndex == m_fontList.size());
    115 
    116     if (m_familyIndex == cAllFamiliesScanned)
    117         return 0;
    118 
    119     // Ask the font cache for the font data.
    120     // We are obtaining this font for the first time.  We keep track of the families we've looked at before
    121     // in |m_familyIndex|, so that we never scan the same spot in the list twice.  getFontData will adjust our
    122     // |m_familyIndex| as it scans for the right font to make.
    123     ASSERT(fontCache()->generation() == m_generation);
    124     RefPtr<FontData> result = fontCache()->getFontData(*font, m_familyIndex, m_fontSelector.get()); <=====
    125     if (result) {
    126         m_fontList.append(result);
    127         if (result->isLoading())
    128             m_loadingCustomFonts = true;
    129     }
    130     return result.get();
    131 }
    132 
    457 PassRefPtr<FontData> FontCache::getFontData(const Font& font, int& familyIndex, FontSelector* fontSelector)
    458 {
    459     RefPtr<FontData> result;
    460 
    461     int startIndex = familyIndex;
    462     const FontFamily* startFamily = &font.fontDescription().family();
    463     for (int i = 0; startFamily && i < startIndex; i++)
    464         startFamily = startFamily->next();
    465     const FontFamily* currFamily = startFamily;
    466     while (currFamily && !result) {
    467         familyIndex++;
    468         if (currFamily->family().length()) {
    469             if (fontSelector)
    470                 result = fontSelector->getFontData(font.fontDescription(), currFamily->family());
    471 
    472             if (!result)
    473                 result = getFontResourceData(font.fontDescription(), currFamily->family());
    474         }
    475         currFamily = currFamily->next();
    476     }
    477 
    478     if (!currFamily)
    479         familyIndex = cAllFamiliesScanned;
    480 
    481     if (!result)
    482         // We didn't find a font. Try to find a similar font using our own specific knowledge about our platform.
    483         // For example on OS X, we know to map any families containing the words Arabic, Pashto, or Urdu to the
    484         // Geeza Pro font.
    485         result = getSimilarFontPlatformData(font);
    486 
    487     if (!result && startIndex == 0) {
    488         // If it's the primary font that we couldn't find, we try the following. In all other cases, we will
    489         // just use per-character system fallback.
    490 
    491         if (fontSelector) {
    492             // Try the user's preferred standard font.
    493             if (RefPtr<FontData> data = fontSelector->getFontData(font.fontDescription(), standardFamily))
    494                 return data.release();
    495         }
    496 
    497         // Still no result.  Hand back our last resort fallback font.
    498         result = getLastResortFallbackFont(font.fontDescription());
    499     }
    500     return result.release();
    501 }
    303 PassRefPtr<SimpleFontData> FontCache::getFontResourceData(const FontPlatformData* platformData, ShouldRetain shouldRetain)
    304 {
    305     if (!platformData)
    306         return 0;
    307 
    308 #if !ASSERT_DISABLED
    309     if (shouldRetain == DoNotRetain)
    310         ASSERT(m_purgePreventCount);
    311 #endif
    312 
    313     if (!gFontDataCache) {
    314         gFontDataCache = new FontDataCache;
    315         gInactiveFontData = new ListHashSet<RefPtr<SimpleFontData> >;
    316     }
    317 
    318     FontDataCache::iterator result = gFontDataCache->find(*platformData);
    319     if (result == gFontDataCache->end()) {
    320         pair<RefPtr<SimpleFontData>, unsigned> newValue(SimpleFontData::create(*platformData), shouldRetain == Retain ? 1 : 0);
    321         gFontDataCache->set(*platformData, newValue);
    322         if (shouldRetain == DoNotRetain)
    323             gInactiveFontData->add(newValue.first);
    324         return newValue.first.release();
    325     }
    326 
    327     if (!result.get()->value.second) {
    328         ASSERT(gInactiveFontData->contains(result.get()->value.first));
    329         gInactiveFontData->remove(result.get()->value.first);
    330     }
    331 
    332     if (shouldRetain == Retain)
    333         result.get()->value.second++;
    334     else if (!result.get()->value.second) {
    335         // If shouldRetain is DoNotRetain and count is 0, we want to remove the fontData from
    336         // gInactiveFontData (above) and re-add here to update LRU position.
    337         gInactiveFontData->add(result.get()->value.first);
    338     }
    339 
    340     return result.get()->value.first;
    341 }