Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: Source/core/css/CSSFontFace.cpp

Issue 270813003: Reland r172943 "Make CSSFontFace::willUseFontData() load fonts with unicode-range" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/css/CSSFontFace.h ('k') | Source/core/css/CSSFontSelector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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::maybeScheduleFontLoad(const FontDescription& fontDescription, UChar32 character)
130 { 130 {
131 // Kicks off font load here only if the @font-face has no unicode-range. 131 if (m_ranges.contains(character)) {
132 // @font-faces with unicode-range will be loaded when a GlyphPage for the
133 // font is created.
134 // FIXME: Pass around the text to render from RenderText, and kick download
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); 132 load(fontDescription);
133 return true;
134 }
135 return false;
139 } 136 }
140 137
141 void CSSFontFace::load(const FontDescription& fontDescription, CSSFontSelector* fontSelector) 138 void CSSFontFace::load(const FontDescription& fontDescription, CSSFontSelector* fontSelector)
142 { 139 {
143 if (loadStatus() != FontFace::Unloaded) 140 if (loadStatus() != FontFace::Unloaded)
144 return; 141 return;
145 setLoadStatus(FontFace::Loading); 142 setLoadStatus(FontFace::Loading);
146 143
147 while (!m_sources.isEmpty()) { 144 while (!m_sources.isEmpty()) {
148 OwnPtr<CSSFontFaceSource>& source = m_sources.first(); 145 OwnPtr<CSSFontFaceSource>& source = m_sources.first();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } else { 207 } else {
211 m_ranges[targetIndex++] = UnicodeRange(from, to); 208 m_ranges[targetIndex++] = UnicodeRange(from, to);
212 from = m_ranges[i].from(); 209 from = m_ranges[i].from();
213 to = m_ranges[i].to(); 210 to = m_ranges[i].to();
214 } 211 }
215 } 212 }
216 m_ranges[targetIndex++] = UnicodeRange(from, to); 213 m_ranges[targetIndex++] = UnicodeRange(from, to);
217 m_ranges.shrink(targetIndex); 214 m_ranges.shrink(targetIndex);
218 } 215 }
219 216
217 bool CSSFontFace::UnicodeRangeSet::contains(UChar32 c) const
218 {
219 if (isEntireRange())
220 return true;
221 Vector<UnicodeRange>::const_iterator it = std::lower_bound(m_ranges.begin(), m_ranges.end(), c);
222 return it != m_ranges.end() && it->contains(c);
223 }
224
220 bool CSSFontFace::UnicodeRangeSet::intersectsWith(const String& text) const 225 bool CSSFontFace::UnicodeRangeSet::intersectsWith(const String& text) const
221 { 226 {
222 if (text.isEmpty()) 227 if (text.isEmpty())
223 return false; 228 return false;
224 if (isEntireRange()) 229 if (isEntireRange())
225 return true; 230 return true;
226 if (text.is8Bit() && m_ranges[0].from() >= 0x100) 231 if (text.is8Bit() && m_ranges[0].from() >= 0x100)
227 return false; 232 return false;
228 233
229 unsigned index = 0; 234 unsigned index = 0;
230 while (index < text.length()) { 235 while (index < text.length()) {
231 UChar32 c = text.characterStartingAt(index); 236 UChar32 c = text.characterStartingAt(index);
232 index += U16_LENGTH(c); 237 index += U16_LENGTH(c);
233 Vector<UnicodeRange>::const_iterator it = std::lower_bound(m_ranges.begi n(), m_ranges.end(), c); 238 if (contains(c))
234 if (it != m_ranges.end() && it->contains(c))
235 return true; 239 return true;
236 } 240 }
237 return false; 241 return false;
238 } 242 }
239 243
240 void CSSFontFace::trace(Visitor* visitor) 244 void CSSFontFace::trace(Visitor* visitor)
241 { 245 {
242 visitor->trace(m_segmentedFontFace); 246 visitor->trace(m_segmentedFontFace);
243 visitor->trace(m_fontFace); 247 visitor->trace(m_fontFace);
244 } 248 }
245 249
246 } 250 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSFontFace.h ('k') | Source/core/css/CSSFontSelector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698