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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 fontSelector->beginLoadingFontSoon(resource); | 77 fontSelector->beginLoadingFontSoon(resource); |
78 | 78 |
79 if (loadStatus() == FontFace::Unloaded) | 79 if (loadStatus() == FontFace::Unloaded) |
80 setLoadStatus(FontFace::Loading); | 80 setLoadStatus(FontFace::Loading); |
81 } | 81 } |
82 | 82 |
83 void CSSFontFace::fontLoaded(CSSFontFaceSource* source) | 83 void CSSFontFace::fontLoaded(CSSFontFaceSource* source) |
84 { | 84 { |
85 if (source != m_activeSource) | 85 if (source != m_activeSource) |
86 return; | 86 return; |
| 87 m_activeSource = 0; |
87 | 88 |
88 // FIXME: Can we assert that m_segmentedFontFace is non-null? That may | 89 // FIXME: Can we assert that m_segmentedFontFace is non-null? That may |
89 // require stopping in-progress font loading when the last | 90 // require stopping in-progress font loading when the last |
90 // CSSSegmentedFontFace is removed. | 91 // CSSSegmentedFontFace is removed. |
91 if (!m_segmentedFontFace) | 92 if (!m_segmentedFontFace) |
92 return; | 93 return; |
93 | 94 |
94 CSSFontSelector* fontSelector = m_segmentedFontFace->fontSelector(); | 95 CSSFontSelector* fontSelector = m_segmentedFontFace->fontSelector(); |
95 fontSelector->fontLoaded(); | 96 fontSelector->fontLoaded(); |
96 | 97 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 131 |
131 if (loadStatus() == FontFace::Unloaded) | 132 if (loadStatus() == FontFace::Unloaded) |
132 setLoadStatus(FontFace::Loading); | 133 setLoadStatus(FontFace::Loading); |
133 if (loadStatus() == FontFace::Loading) | 134 if (loadStatus() == FontFace::Loading) |
134 setLoadStatus(FontFace::Error); | 135 setLoadStatus(FontFace::Error); |
135 return 0; | 136 return 0; |
136 } | 137 } |
137 | 138 |
138 void CSSFontFace::willUseFontData(const FontDescription& fontDescription) | 139 void CSSFontFace::willUseFontData(const FontDescription& fontDescription) |
139 { | 140 { |
140 if (loadStatus() != FontFace::Unloaded) | 141 if (loadStatus() != FontFace::Unloaded || m_activeSource) |
| 142 return; |
| 143 |
| 144 // Kicks off font load here only if the @font-face has no unicode-range. |
| 145 // @font-faces with unicode-range will be loaded when a GlyphPage for the |
| 146 // font is created. |
| 147 // FIXME: Pass around the text to render from RenderText, and kick download |
| 148 // if m_ranges intersects with the text. Make sure this does not cause |
| 149 // performance regression. |
| 150 if (!m_ranges.isEntireRange()) |
141 return; | 151 return; |
142 | 152 |
143 ASSERT(m_segmentedFontFace); | 153 ASSERT(m_segmentedFontFace); |
144 | 154 |
145 size_t size = m_sources.size(); | 155 size_t size = m_sources.size(); |
146 for (size_t i = 0; i < size; ++i) { | 156 for (size_t i = 0; i < size; ++i) { |
147 if (!m_sources[i]->isValid() || (m_sources[i]->isLocal() && !m_sources[i
]->isLocalFontAvailable(fontDescription))) | 157 if (!m_sources[i]->isValid() || (m_sources[i]->isLocal() && !m_sources[i
]->isLocalFontAvailable(fontDescription))) |
148 continue; | 158 continue; |
149 if (!m_sources[i]->isLocal()) | 159 if (!m_sources[i]->isLocal()) { |
| 160 m_activeSource = m_sources[i].get(); |
150 m_sources[i]->willUseFontData(); | 161 m_sources[i]->willUseFontData(); |
| 162 } |
151 break; | 163 break; |
152 } | 164 } |
153 } | 165 } |
154 | 166 |
155 void CSSFontFace::setLoadStatus(FontFace::LoadStatus newStatus) | 167 void CSSFontFace::setLoadStatus(FontFace::LoadStatus newStatus) |
156 { | 168 { |
157 ASSERT(m_fontFace); | 169 ASSERT(m_fontFace); |
158 m_fontFace->setLoadStatus(newStatus); | 170 m_fontFace->setLoadStatus(newStatus); |
159 | 171 |
160 Document* document = m_segmentedFontFace->fontSelector()->document(); | 172 Document* document = m_segmentedFontFace->fontSelector()->document(); |
(...skipping 12 matching lines...) Expand all Loading... |
173 break; | 185 break; |
174 default: | 186 default: |
175 break; | 187 break; |
176 } | 188 } |
177 } | 189 } |
178 | 190 |
179 bool CSSFontFace::UnicodeRangeSet::intersectsWith(const String& text) const | 191 bool CSSFontFace::UnicodeRangeSet::intersectsWith(const String& text) const |
180 { | 192 { |
181 if (text.isEmpty()) | 193 if (text.isEmpty()) |
182 return false; | 194 return false; |
183 if (m_ranges.isEmpty()) | 195 if (isEntireRange()) |
184 return true; // Empty UnicodeRangeSet represents the whole code space. | 196 return true; |
185 | 197 |
186 // FIXME: This takes O(text.length() * m_ranges.size()) time. It would be | 198 // FIXME: This takes O(text.length() * m_ranges.size()) time. It would be |
187 // better to make m_ranges sorted and use binary search. | 199 // better to make m_ranges sorted and use binary search. |
188 unsigned index = 0; | 200 unsigned index = 0; |
189 while (index < text.length()) { | 201 while (index < text.length()) { |
190 UChar32 c = text.characterStartingAt(index); | 202 UChar32 c = text.characterStartingAt(index); |
191 index += U16_LENGTH(c); | 203 index += U16_LENGTH(c); |
192 for (unsigned i = 0; i < m_ranges.size(); i++) { | 204 for (unsigned i = 0; i < m_ranges.size(); i++) { |
193 if (m_ranges[i].contains(c)) | 205 if (m_ranges[i].contains(c)) |
194 return true; | 206 return true; |
195 } | 207 } |
196 } | 208 } |
197 return false; | 209 return false; |
198 } | 210 } |
199 | 211 |
200 } | 212 } |
OLD | NEW |