Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 FontFallbackList::FontFallbackList() | 43 FontFallbackList::FontFallbackList() |
| 44 : m_pageZero(0) | 44 : m_pageZero(0) |
| 45 , m_cachedPrimarySimpleFontData(0) | 45 , m_cachedPrimarySimpleFontData(0) |
| 46 , m_fontSelector(nullptr) | 46 , m_fontSelector(nullptr) |
| 47 , m_fontSelectorVersion(0) | 47 , m_fontSelectorVersion(0) |
| 48 , m_familyIndex(0) | 48 , m_familyIndex(0) |
| 49 , m_generation(FontCache::fontCache()->generation()) | 49 , m_generation(FontCache::fontCache()->generation()) |
| 50 , m_hasLoadingFallback(false) | 50 , m_hasLoadingFallback(false) |
| 51 , m_hasNonBlankFontData(false) | |
| 51 { | 52 { |
| 52 } | 53 } |
| 53 | 54 |
| 54 void FontFallbackList::invalidate(PassRefPtrWillBeRawPtr<FontSelector> fontSelec tor) | 55 void FontFallbackList::invalidate(PassRefPtrWillBeRawPtr<FontSelector> fontSelec tor) |
| 55 { | 56 { |
| 56 releaseFontData(); | 57 releaseFontData(); |
| 57 m_fontList.clear(); | 58 m_fontList.clear(); |
| 58 m_pageZero = 0; | 59 m_pageZero = 0; |
| 59 m_pages.clear(); | 60 m_pages.clear(); |
| 60 m_cachedPrimarySimpleFontData = 0; | 61 m_cachedPrimarySimpleFontData = 0; |
| 61 m_familyIndex = 0; | 62 m_familyIndex = 0; |
| 62 m_hasLoadingFallback = false; | 63 m_hasLoadingFallback = false; |
| 64 m_hasNonBlankFontData = false; | |
| 63 if (m_fontSelector != fontSelector) | 65 if (m_fontSelector != fontSelector) |
| 64 m_fontSelector = fontSelector; | 66 m_fontSelector = fontSelector; |
| 65 m_fontSelectorVersion = m_fontSelector ? m_fontSelector->version() : 0; | 67 m_fontSelectorVersion = m_fontSelector ? m_fontSelector->version() : 0; |
| 66 m_generation = FontCache::fontCache()->generation(); | 68 m_generation = FontCache::fontCache()->generation(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void FontFallbackList::releaseFontData() | 71 void FontFallbackList::releaseFontData() |
| 70 { | 72 { |
| 71 unsigned numFonts = m_fontList.size(); | 73 unsigned numFonts = m_fontList.size(); |
| 72 for (unsigned i = 0; i < numFonts; ++i) { | 74 for (unsigned i = 0; i < numFonts; ++i) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 // Begin to load the first custom font if needed. | 150 // Begin to load the first custom font if needed. |
| 149 if (shouldLoadCustomFont) { | 151 if (shouldLoadCustomFont) { |
| 150 shouldLoadCustomFont = false; | 152 shouldLoadCustomFont = false; |
| 151 fontDataForSpace->customFontData()->beginLoadIfNeeded(); | 153 fontDataForSpace->customFontData()->beginLoadIfNeeded(); |
| 152 } | 154 } |
| 153 } | 155 } |
| 154 } | 156 } |
| 155 | 157 |
| 156 PassRefPtr<FontData> FontFallbackList::getFontData(const FontDescription& fontDe scription, int& familyIndex) const | 158 PassRefPtr<FontData> FontFallbackList::getFontData(const FontDescription& fontDe scription, int& familyIndex) const |
| 157 { | 159 { |
| 158 RefPtr<FontData> result; | 160 const FontFamily* currFamily = &fontDescription.family(); |
| 161 for (int i = 0; currFamily && i < familyIndex; i++) | |
| 162 currFamily = currFamily->next(); | |
| 159 | 163 |
| 160 int startIndex = familyIndex; | 164 for (; currFamily; currFamily = currFamily->next()) { |
| 161 const FontFamily* startFamily = &fontDescription.family(); | |
| 162 for (int i = 0; startFamily && i < startIndex; i++) | |
| 163 startFamily = startFamily->next(); | |
| 164 const FontFamily* currFamily = startFamily; | |
| 165 while (currFamily && !result) { | |
| 166 familyIndex++; | 165 familyIndex++; |
| 167 if (currFamily->family().length()) { | 166 if (currFamily->family().length()) { |
| 167 RefPtr<FontData> result; | |
| 168 if (m_fontSelector) | 168 if (m_fontSelector) |
| 169 result = m_fontSelector->getFontData(fontDescription, currFamily ->family()); | 169 result = m_fontSelector->getFontData(fontDescription, currFamily ->family()); |
| 170 | |
| 171 if (!result) | 170 if (!result) |
| 172 result = FontCache::fontCache()->getFontData(fontDescription, cu rrFamily->family()); | 171 result = FontCache::fontCache()->getFontData(fontDescription, cu rrFamily->family()); |
| 172 if (result) | |
| 173 return result.release(); | |
| 173 } | 174 } |
| 174 currFamily = currFamily->next(); | |
| 175 } | 175 } |
| 176 familyIndex = cAllFamiliesScanned; | |
| 176 | 177 |
| 177 if (!currFamily) | 178 if (m_hasNonBlankFontData) |
| 178 familyIndex = cAllFamiliesScanned; | 179 return nullptr; |
| 179 | 180 |
| 180 if (result || startIndex) | 181 // If we couldn't find any non-blank font data in the family list, we try |
| 181 return result.release(); | 182 // the following. In all other cases, we will just use per-character system |
| 182 | 183 // fallback. |
| 183 // If it's the primary font that we couldn't find, we try the following. In all other cases, we will | |
| 184 // just use per-character system fallback. | |
| 185 | 184 |
| 186 if (m_fontSelector) { | 185 if (m_fontSelector) { |
| 187 // Try the user's preferred standard font. | 186 // Try the user's preferred standard font. |
| 188 if (RefPtr<FontData> data = m_fontSelector->getFontData(fontDescription, FontFamilyNames::webkit_standard)) | 187 if (RefPtr<FontData> data = m_fontSelector->getFontData(fontDescription, FontFamilyNames::webkit_standard)) |
| 189 return data.release(); | 188 return data.release(); |
| 190 } | 189 } |
| 191 | 190 |
| 192 // Still no result. Hand back our last resort fallback font. | 191 // Still no result. Hand back our last resort fallback font. |
| 193 return FontCache::fontCache()->getLastResortFallbackFont(fontDescription); | 192 return FontCache::fontCache()->getLastResortFallbackFont(fontDescription); |
| 194 } | 193 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 // Ask the font cache for the font data. | 230 // Ask the font cache for the font data. |
| 232 // We are obtaining this font for the first time. We keep track of the fami lies we've looked at before | 231 // We are obtaining this font for the first time. We keep track of the fami lies we've looked at before |
| 233 // in |m_familyIndex|, so that we never scan the same spot in the list twice . getFontData will adjust our | 232 // in |m_familyIndex|, so that we never scan the same spot in the list twice . getFontData will adjust our |
| 234 // |m_familyIndex| as it scans for the right font to make. | 233 // |m_familyIndex| as it scans for the right font to make. |
| 235 ASSERT(FontCache::fontCache()->generation() == m_generation); | 234 ASSERT(FontCache::fontCache()->generation() == m_generation); |
| 236 RefPtr<FontData> result = getFontData(fontDescription, m_familyIndex); | 235 RefPtr<FontData> result = getFontData(fontDescription, m_familyIndex); |
| 237 if (result) { | 236 if (result) { |
| 238 m_fontList.append(result); | 237 m_fontList.append(result); |
| 239 if (result->isLoadingFallback()) | 238 if (result->isLoadingFallback()) |
| 240 m_hasLoadingFallback = true; | 239 m_hasLoadingFallback = true; |
| 240 else | |
|
drott
2015/12/01 09:36:22
Is there a way we could avoid the additional flag?
| |
| 241 m_hasNonBlankFontData = true; | |
| 241 } | 242 } |
| 242 return result.get(); | 243 return result.get(); |
| 243 } | 244 } |
| 244 | 245 |
| 245 bool FontFallbackList::isValid() const | 246 bool FontFallbackList::isValid() const |
| 246 { | 247 { |
| 247 if (!m_fontSelector) | 248 if (!m_fontSelector) |
| 248 return m_fontSelectorVersion == 0; | 249 return m_fontSelectorVersion == 0; |
| 249 | 250 |
| 250 return m_fontSelector->version() == m_fontSelectorVersion; | 251 return m_fontSelector->version() == m_fontSelectorVersion; |
| 251 } | 252 } |
| 252 | 253 |
| 253 } // namespace blink | 254 } // namespace blink |
| OLD | NEW |