OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2010, 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 pruneTable(); | 124 pruneTable(); |
125 if (m_face) | 125 if (m_face) |
126 m_face->fontLoaded(this); | 126 m_face->fontLoaded(this); |
127 } | 127 } |
128 | 128 |
129 PassRefPtr<SimpleFontData> CSSFontFaceSource::getFontData(const FontDescription&
fontDescription) | 129 PassRefPtr<SimpleFontData> CSSFontFaceSource::getFontData(const FontDescription&
fontDescription) |
130 { | 130 { |
131 // If the font hasn't loaded or an error occurred, then we've got nothing. | 131 // If the font hasn't loaded or an error occurred, then we've got nothing. |
132 if (!isValid()) | 132 if (!isValid()) |
133 return 0; | 133 return nullptr; |
134 | 134 |
135 if (isLocal()) { | 135 if (isLocal()) { |
136 // We're local. Just return a SimpleFontData from the normal cache. | 136 // We're local. Just return a SimpleFontData from the normal cache. |
137 // We don't want to check alternate font family names here, so pass true
as the checkingAlternateName parameter. | 137 // We don't want to check alternate font family names here, so pass true
as the checkingAlternateName parameter. |
138 RefPtr<SimpleFontData> fontData = FontCache::fontCache()->getFontData(fo
ntDescription, m_string, true); | 138 RefPtr<SimpleFontData> fontData = FontCache::fontCache()->getFontData(fo
ntDescription, m_string, true); |
139 m_histograms.recordLocalFont(fontData); | 139 m_histograms.recordLocalFont(fontData); |
140 return fontData; | 140 return fontData; |
141 } | 141 } |
142 | 142 |
143 // See if we have a mapping in our FontData cache. | 143 // See if we have a mapping in our FontData cache. |
144 AtomicString emptyFontFamily = ""; | 144 AtomicString emptyFontFamily = ""; |
145 FontCacheKey key = fontDescription.cacheKey(emptyFontFamily); | 145 FontCacheKey key = fontDescription.cacheKey(emptyFontFamily); |
146 | 146 |
147 RefPtr<SimpleFontData>& fontData = m_fontDataTable.add(key.hash(), 0).stored
Value->value; | 147 RefPtr<SimpleFontData>& fontData = m_fontDataTable.add(key.hash(), nullptr).
storedValue->value; |
148 if (fontData) | 148 if (fontData) |
149 return fontData; // No release, because fontData is a reference to a Ref
Ptr that is held in the m_fontDataTable. | 149 return fontData; // No release, because fontData is a reference to a Ref
Ptr that is held in the m_fontDataTable. |
150 | 150 |
151 // If we are still loading, then we let the system pick a font. | 151 // If we are still loading, then we let the system pick a font. |
152 if (isLoaded()) { | 152 if (isLoaded()) { |
153 if (m_font) { | 153 if (m_font) { |
154 #if ENABLE(SVG_FONTS) | 154 #if ENABLE(SVG_FONTS) |
155 if (m_hasExternalSVGFont) { | 155 if (m_hasExternalSVGFont) { |
156 // For SVG fonts parse the external SVG document, and extract th
e <font> element. | 156 // For SVG fonts parse the external SVG document, and extract th
e <font> element. |
157 if (!m_font->ensureSVGFontData()) | 157 if (!m_font->ensureSVGFontData()) |
158 return 0; | 158 return nullptr; |
159 | 159 |
160 if (!m_externalSVGFontElement) { | 160 if (!m_externalSVGFontElement) { |
161 String fragmentIdentifier; | 161 String fragmentIdentifier; |
162 size_t start = m_string.find('#'); | 162 size_t start = m_string.find('#'); |
163 if (start != kNotFound) | 163 if (start != kNotFound) |
164 fragmentIdentifier = m_string.string().substring(start +
1); | 164 fragmentIdentifier = m_string.string().substring(start +
1); |
165 m_externalSVGFontElement = m_font->getSVGFontById(fragmentId
entifier); | 165 m_externalSVGFontElement = m_font->getSVGFontById(fragmentId
entifier); |
166 } | 166 } |
167 | 167 |
168 if (!m_externalSVGFontElement) | 168 if (!m_externalSVGFontElement) |
169 return 0; | 169 return nullptr; |
170 | 170 |
171 SVGFontFaceElement* fontFaceElement = 0; | 171 SVGFontFaceElement* fontFaceElement = 0; |
172 | 172 |
173 // Select first <font-face> child | 173 // Select first <font-face> child |
174 for (Node* fontChild = m_externalSVGFontElement->firstChild(); f
ontChild; fontChild = fontChild->nextSibling()) { | 174 for (Node* fontChild = m_externalSVGFontElement->firstChild(); f
ontChild; fontChild = fontChild->nextSibling()) { |
175 if (fontChild->hasTagName(SVGNames::font_faceTag)) { | 175 if (fontChild->hasTagName(SVGNames::font_faceTag)) { |
176 fontFaceElement = toSVGFontFaceElement(fontChild); | 176 fontFaceElement = toSVGFontFaceElement(fontChild); |
177 break; | 177 break; |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 if (fontFaceElement) { | 181 if (fontFaceElement) { |
182 if (!m_svgFontFaceElement) { | 182 if (!m_svgFontFaceElement) { |
183 // We're created using a CSS @font-face rule, that means
we're not associated with a SVGFontFaceElement. | 183 // We're created using a CSS @font-face rule, that means
we're not associated with a SVGFontFaceElement. |
184 // Use the imported <font-face> tag as referencing font-
face element for these cases. | 184 // Use the imported <font-face> tag as referencing font-
face element for these cases. |
185 m_svgFontFaceElement = fontFaceElement; | 185 m_svgFontFaceElement = fontFaceElement; |
186 } | 186 } |
187 | 187 |
188 fontData = SimpleFontData::create( | 188 fontData = SimpleFontData::create( |
189 SVGFontData::create(fontFaceElement), | 189 SVGFontData::create(fontFaceElement), |
190 fontDescription.effectiveFontSize(), | 190 fontDescription.effectiveFontSize(), |
191 fontDescription.isSyntheticBold(), | 191 fontDescription.isSyntheticBold(), |
192 fontDescription.isSyntheticItalic()); | 192 fontDescription.isSyntheticItalic()); |
193 } | 193 } |
194 } else | 194 } else |
195 #endif | 195 #endif |
196 { | 196 { |
197 // Create new FontPlatformData from our CGFontRef, point size an
d ATSFontRef. | 197 // Create new FontPlatformData from our CGFontRef, point size an
d ATSFontRef. |
198 if (!m_font->ensureCustomFontData()) | 198 if (!m_font->ensureCustomFontData()) |
199 return 0; | 199 return nullptr; |
200 | 200 |
201 fontData = SimpleFontData::create( | 201 fontData = SimpleFontData::create( |
202 m_font->platformDataFromCustomData(fontDescription.effective
FontSize(), | 202 m_font->platformDataFromCustomData(fontDescription.effective
FontSize(), |
203 fontDescription.isSyntheticBold(), fontDescription.isSyn
theticItalic(), | 203 fontDescription.isSyntheticBold(), fontDescription.isSyn
theticItalic(), |
204 fontDescription.orientation(), fontDescription.widthVari
ant()), CustomFontData::create(false)); | 204 fontDescription.orientation(), fontDescription.widthVari
ant()), CustomFontData::create(false)); |
205 } | 205 } |
206 } else { | 206 } else { |
207 #if ENABLE(SVG_FONTS) | 207 #if ENABLE(SVG_FONTS) |
208 // In-Document SVG Fonts | 208 // In-Document SVG Fonts |
209 if (m_svgFontFaceElement) { | 209 if (m_svgFontFaceElement) { |
210 fontData = SimpleFontData::create( | 210 fontData = SimpleFontData::create( |
211 SVGFontData::create(m_svgFontFaceElement.get()), | 211 SVGFontData::create(m_svgFontFaceElement.get()), |
212 fontDescription.effectiveFontSize(), | 212 fontDescription.effectiveFontSize(), |
213 fontDescription.isSyntheticBold(), | 213 fontDescription.isSyntheticBold(), |
214 fontDescription.isSyntheticItalic()); | 214 fontDescription.isSyntheticItalic()); |
215 } | 215 } |
216 #endif | 216 #endif |
217 } | 217 } |
218 } else { | 218 } else { |
219 // This temporary font is not retained and should not be returned. | 219 // This temporary font is not retained and should not be returned. |
220 FontCachePurgePreventer fontCachePurgePreventer; | 220 FontCachePurgePreventer fontCachePurgePreventer; |
221 SimpleFontData* temporaryFont = FontCache::fontCache()->getNonRetainedLa
stResortFallbackFont(fontDescription); | 221 SimpleFontData* temporaryFont = FontCache::fontCache()->getNonRetainedLa
stResortFallbackFont(fontDescription); |
222 if (!temporaryFont) { | 222 if (!temporaryFont) { |
223 ASSERT_NOT_REACHED(); | 223 ASSERT_NOT_REACHED(); |
224 return 0; | 224 return nullptr; |
225 } | 225 } |
226 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(true); | 226 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(true); |
227 cssFontData->setCSSFontFaceSource(this); | 227 cssFontData->setCSSFontFaceSource(this); |
228 fontData = SimpleFontData::create(temporaryFont->platformData(), cssFont
Data); | 228 fontData = SimpleFontData::create(temporaryFont->platformData(), cssFont
Data); |
229 } | 229 } |
230 | 230 |
231 return fontData; // No release, because fontData is a reference to a RefPtr
that is held in the m_fontDataTable. | 231 return fontData; // No release, because fontData is a reference to a RefPtr
that is held in the m_fontDataTable. |
232 } | 232 } |
233 | 233 |
234 #if ENABLE(SVG_FONTS) | 234 #if ENABLE(SVG_FONTS) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 if (size < 50 * 1024) | 312 if (size < 50 * 1024) |
313 return "WebFont.DownloadTime.1.10KBTo50KB"; | 313 return "WebFont.DownloadTime.1.10KBTo50KB"; |
314 if (size < 100 * 1024) | 314 if (size < 100 * 1024) |
315 return "WebFont.DownloadTime.2.50KBTo100KB"; | 315 return "WebFont.DownloadTime.2.50KBTo100KB"; |
316 if (size < 1024 * 1024) | 316 if (size < 1024 * 1024) |
317 return "WebFont.DownloadTime.3.100KBTo1MB"; | 317 return "WebFont.DownloadTime.3.100KBTo1MB"; |
318 return "WebFont.DownloadTime.4.Over1MB"; | 318 return "WebFont.DownloadTime.4.Over1MB"; |
319 } | 319 } |
320 | 320 |
321 } | 321 } |
OLD | NEW |