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

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

Issue 23446007: Use unicode-range to prevent unnecessary @font-face donwnloads (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase and add toSegmentedFontData() Created 7 years, 3 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/CSSFontFaceSource.cpp ('k') | Source/core/platform/graphics/FontFallbackList.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) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 85 }
86 } 86 }
87 87
88 void CSSSegmentedFontFace::appendFontFace(PassRefPtr<CSSFontFace> fontFace) 88 void CSSSegmentedFontFace::appendFontFace(PassRefPtr<CSSFontFace> fontFace)
89 { 89 {
90 pruneTable(); 90 pruneTable();
91 fontFace->setSegmentedFontFace(this); 91 fontFace->setSegmentedFontFace(this);
92 m_fontFaces.append(fontFace); 92 m_fontFaces.append(fontFace);
93 } 93 }
94 94
95 static void appendFontDataWithInvalidUnicodeRangeIfLoading(SegmentedFontData* ne wFontData, PassRefPtr<SimpleFontData> prpFaceFontData, const Vector<CSSFontFace: :UnicodeRange>& ranges) 95 static void appendFontData(SegmentedFontData* newFontData, PassRefPtr<SimpleFont Data> prpFaceFontData, const Vector<CSSFontFace::UnicodeRange>& ranges)
96 { 96 {
97 RefPtr<SimpleFontData> faceFontData = prpFaceFontData; 97 RefPtr<SimpleFontData> faceFontData = prpFaceFontData;
98 if (faceFontData->isLoading()) {
99 newFontData->appendRange(FontDataRange(0, 0, faceFontData));
100 return;
101 }
102
103 unsigned numRanges = ranges.size(); 98 unsigned numRanges = ranges.size();
104 if (!numRanges) { 99 if (!numRanges) {
105 newFontData->appendRange(FontDataRange(0, 0x7FFFFFFF, faceFontData)); 100 newFontData->appendRange(FontDataRange(0, 0x7FFFFFFF, faceFontData));
106 return; 101 return;
107 } 102 }
108 103
109 for (unsigned j = 0; j < numRanges; ++j) 104 for (unsigned j = 0; j < numRanges; ++j)
110 newFontData->appendRange(FontDataRange(ranges[j].from(), ranges[j].to(), faceFontData)); 105 newFontData->appendRange(FontDataRange(ranges[j].from(), ranges[j].to(), faceFontData));
111 } 106 }
112 107
(...skipping 16 matching lines...) Expand all
129 fontData = SegmentedFontData::create(); 124 fontData = SegmentedFontData::create();
130 125
131 bool syntheticBold = !(m_traitsMask & (FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask)) && (desiredTraitsMask & (FontWeight60 0Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask)); 126 bool syntheticBold = !(m_traitsMask & (FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask)) && (desiredTraitsMask & (FontWeight60 0Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask));
132 bool syntheticItalic = !(m_traitsMask & FontStyleItalicMask) && (desiredTrai tsMask & FontStyleItalicMask); 127 bool syntheticItalic = !(m_traitsMask & FontStyleItalicMask) && (desiredTrai tsMask & FontStyleItalicMask);
133 128
134 for (int i = m_fontFaces.size() - 1; i >= 0; --i) { 129 for (int i = m_fontFaces.size() - 1; i >= 0; --i) {
135 if (!m_fontFaces[i]->isValid()) 130 if (!m_fontFaces[i]->isValid())
136 continue; 131 continue;
137 if (RefPtr<SimpleFontData> faceFontData = m_fontFaces[i]->getFontData(fo ntDescription, syntheticBold, syntheticItalic)) { 132 if (RefPtr<SimpleFontData> faceFontData = m_fontFaces[i]->getFontData(fo ntDescription, syntheticBold, syntheticItalic)) {
138 ASSERT(!faceFontData->isSegmented()); 133 ASSERT(!faceFontData->isSegmented());
139 appendFontDataWithInvalidUnicodeRangeIfLoading(fontData.get(), faceF ontData.release(), m_fontFaces[i]->ranges()); 134 appendFontData(fontData.get(), faceFontData.release(), m_fontFaces[i ]->ranges());
140 } 135 }
141 } 136 }
142 if (fontData->numRanges()) 137 if (fontData->numRanges())
143 return fontData; // No release, we have a reference to an object in the cache which should retain the ref count it has. 138 return fontData; // No release, we have a reference to an object in the cache which should retain the ref count it has.
144 139
145 return 0; 140 return 0;
146 } 141 }
147 142
148 bool CSSSegmentedFontFace::hasSVGFontFaceSource() const 143 bool CSSSegmentedFontFace::hasSVGFontFaceSource() const
149 { 144 {
(...skipping 27 matching lines...) Expand all
177 unsigned size = m_fontFaces.size(); 172 unsigned size = m_fontFaces.size();
178 for (unsigned i = 0; i < size; i++) { 173 for (unsigned i = 0; i < size; i++) {
179 if (m_fontFaces[i]->loadStatus() != FontFace::Loaded) 174 if (m_fontFaces[i]->loadStatus() != FontFace::Loaded)
180 return false; 175 return false;
181 } 176 }
182 return true; 177 return true;
183 } 178 }
184 179
185 void CSSSegmentedFontFace::loadFont(const FontDescription& fontDescription, Pass RefPtr<LoadFontCallback> callback) 180 void CSSSegmentedFontFace::loadFont(const FontDescription& fontDescription, Pass RefPtr<LoadFontCallback> callback)
186 { 181 {
187 getFontData(fontDescription); // Kick off the load. 182 RefPtr<SegmentedFontData> fontData = toSegmentedFontData(getFontData(fontDes cription).get());
183 unsigned numRanges = fontData->numRanges();
184 for (unsigned i = 0; i < numRanges; i++)
185 fontData->rangeAt(i).fontData()->beginLoadIfNeeded();
188 186
189 if (callback) { 187 if (callback) {
190 if (isLoading()) 188 if (isLoading())
191 m_callbacks.append(callback); 189 m_callbacks.append(callback);
192 else if (checkFont()) 190 else if (checkFont())
193 callback->notifyLoaded(this); 191 callback->notifyLoaded(this);
194 else 192 else
195 callback->notifyError(this); 193 callback->notifyError(this);
196 } 194 }
197 } 195 }
198 196
199 } 197 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSFontFaceSource.cpp ('k') | Source/core/platform/graphics/FontFallbackList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698