Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2011 Apple 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 m_sources.removeFirst(); | 119 m_sources.removeFirst(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 if (loadStatus() == FontFace::Unloaded) | 122 if (loadStatus() == FontFace::Unloaded) |
| 123 setLoadStatus(FontFace::Loading); | 123 setLoadStatus(FontFace::Loading); |
| 124 if (loadStatus() == FontFace::Loading) | 124 if (loadStatus() == FontFace::Loading) |
| 125 setLoadStatus(FontFace::Error); | 125 setLoadStatus(FontFace::Error); |
| 126 return nullptr; | 126 return nullptr; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void CSSFontFace::willUseFontData(const FontDescription& fontDescription) | 129 bool CSSFontFace::willUseFontData(const FontDescription& fontDescription, const String& text) |
| 130 { | 130 { |
| 131 // Kicks off font load here only if the @font-face has no unicode-range. | 131 // This is an optimization that kicks off font load early (before layout). |
| 132 // @font-faces with unicode-range will be loaded when a GlyphPage for the | 132 // In order to make it fast, we only check if the first character of |text| |
| 133 // font is created. | 133 // is included in the unicode-range. |
| 134 // FIXME: Pass around the text to render from RenderText, and kick download | 134 if (!text.isEmpty() && m_ranges.contains(text.characterStartingAt(0))) { |
|
dglazkov
2014/04/29 16:37:00
text.isEmpty check is not necessary, right? The Re
Kunihiko Sakamoto
2014/04/30 03:31:21
Ah, you're right.
Changed to pass the first charac
| |
| 135 // if m_ranges intersects with the text. Make sure this does not cause | |
| 136 // performance regression. | |
| 137 if (m_ranges.isEntireRange()) | |
| 138 load(fontDescription); | 135 load(fontDescription); |
| 136 return true; | |
| 137 } | |
| 138 return false; | |
| 139 } | 139 } |
| 140 | 140 |
| 141 void CSSFontFace::load(const FontDescription& fontDescription, CSSFontSelector* fontSelector) | 141 void CSSFontFace::load(const FontDescription& fontDescription, CSSFontSelector* fontSelector) |
| 142 { | 142 { |
| 143 if (loadStatus() != FontFace::Unloaded) | 143 if (loadStatus() != FontFace::Unloaded) |
| 144 return; | 144 return; |
| 145 setLoadStatus(FontFace::Loading); | 145 setLoadStatus(FontFace::Loading); |
| 146 | 146 |
| 147 while (!m_sources.isEmpty()) { | 147 while (!m_sources.isEmpty()) { |
| 148 OwnPtr<CSSFontFaceSource>& source = m_sources.first(); | 148 OwnPtr<CSSFontFaceSource>& source = m_sources.first(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 } else { | 210 } else { |
| 211 m_ranges[targetIndex++] = UnicodeRange(from, to); | 211 m_ranges[targetIndex++] = UnicodeRange(from, to); |
| 212 from = m_ranges[i].from(); | 212 from = m_ranges[i].from(); |
| 213 to = m_ranges[i].to(); | 213 to = m_ranges[i].to(); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 m_ranges[targetIndex++] = UnicodeRange(from, to); | 216 m_ranges[targetIndex++] = UnicodeRange(from, to); |
| 217 m_ranges.shrink(targetIndex); | 217 m_ranges.shrink(targetIndex); |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool CSSFontFace::UnicodeRangeSet::contains(UChar32 c) const | |
| 221 { | |
| 222 if (isEntireRange()) | |
| 223 return true; | |
| 224 Vector<UnicodeRange>::const_iterator it = std::lower_bound(m_ranges.begin(), m_ranges.end(), c); | |
| 225 return it != m_ranges.end() && it->contains(c); | |
| 226 } | |
| 227 | |
| 220 bool CSSFontFace::UnicodeRangeSet::intersectsWith(const String& text) const | 228 bool CSSFontFace::UnicodeRangeSet::intersectsWith(const String& text) const |
| 221 { | 229 { |
| 222 if (text.isEmpty()) | 230 if (text.isEmpty()) |
| 223 return false; | 231 return false; |
| 224 if (isEntireRange()) | 232 if (isEntireRange()) |
| 225 return true; | 233 return true; |
| 226 if (text.is8Bit() && m_ranges[0].from() >= 0x100) | 234 if (text.is8Bit() && m_ranges[0].from() >= 0x100) |
| 227 return false; | 235 return false; |
| 228 | 236 |
| 229 unsigned index = 0; | 237 unsigned index = 0; |
| 230 while (index < text.length()) { | 238 while (index < text.length()) { |
| 231 UChar32 c = text.characterStartingAt(index); | 239 UChar32 c = text.characterStartingAt(index); |
| 232 index += U16_LENGTH(c); | 240 index += U16_LENGTH(c); |
| 233 Vector<UnicodeRange>::const_iterator it = std::lower_bound(m_ranges.begi n(), m_ranges.end(), c); | 241 if (contains(c)) |
| 234 if (it != m_ranges.end() && it->contains(c)) | |
| 235 return true; | 242 return true; |
| 236 } | 243 } |
| 237 return false; | 244 return false; |
| 238 } | 245 } |
| 239 | 246 |
| 240 } | 247 } |
| OLD | NEW |