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

Unified Diff: Source/core/css/CSSFontFace.cpp

Issue 248473005: Make CSSFontFace::willUseFontData() load fonts with unicode-range (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/css/CSSFontFace.cpp
diff --git a/Source/core/css/CSSFontFace.cpp b/Source/core/css/CSSFontFace.cpp
index 891795c3fd7eb390600cb5e69917e963172db9a9..0cd6340e1b077fed332476600096bf05f92aa706 100644
--- a/Source/core/css/CSSFontFace.cpp
+++ b/Source/core/css/CSSFontFace.cpp
@@ -126,16 +126,16 @@ PassRefPtr<SimpleFontData> CSSFontFace::getFontData(const FontDescription& fontD
return nullptr;
}
-void CSSFontFace::willUseFontData(const FontDescription& fontDescription)
+bool CSSFontFace::willUseFontData(const FontDescription& fontDescription, const String& text)
{
- // Kicks off font load here only if the @font-face has no unicode-range.
- // @font-faces with unicode-range will be loaded when a GlyphPage for the
- // font is created.
- // FIXME: Pass around the text to render from RenderText, and kick download
- // if m_ranges intersects with the text. Make sure this does not cause
- // performance regression.
- if (m_ranges.isEntireRange())
+ // This is an optimization that kicks off font load early (before layout).
+ // In order to make it fast, we only check if the first character of |text|
+ // is included in the unicode-range.
+ 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
load(fontDescription);
+ return true;
+ }
+ return false;
}
void CSSFontFace::load(const FontDescription& fontDescription, CSSFontSelector* fontSelector)
@@ -217,6 +217,14 @@ CSSFontFace::UnicodeRangeSet::UnicodeRangeSet(const Vector<UnicodeRange>& ranges
m_ranges.shrink(targetIndex);
}
+bool CSSFontFace::UnicodeRangeSet::contains(UChar32 c) const
+{
+ if (isEntireRange())
+ return true;
+ Vector<UnicodeRange>::const_iterator it = std::lower_bound(m_ranges.begin(), m_ranges.end(), c);
+ return it != m_ranges.end() && it->contains(c);
+}
+
bool CSSFontFace::UnicodeRangeSet::intersectsWith(const String& text) const
{
if (text.isEmpty())
@@ -230,8 +238,7 @@ bool CSSFontFace::UnicodeRangeSet::intersectsWith(const String& text) const
while (index < text.length()) {
UChar32 c = text.characterStartingAt(index);
index += U16_LENGTH(c);
- Vector<UnicodeRange>::const_iterator it = std::lower_bound(m_ranges.begin(), m_ranges.end(), c);
- if (it != m_ranges.end() && it->contains(c))
+ if (contains(c))
return true;
}
return false;

Powered by Google App Engine
This is Rietveld 408576698