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 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "config.h" | 28 #include "config.h" |
29 #include "CSSSegmentedFontFaceCache.h" | 29 #include "CSSSegmentedFontFaceCache.h" |
30 | 30 |
31 #include "FontFamilyNames.h" | 31 #include "FontFamilyNames.h" |
32 #include "core/css/CSSFontFace.h" | 32 #include "core/css/CSSFontFace.h" |
33 #include "core/css/CSSFontFaceSource.h" | 33 #include "core/css/CSSFontFaceSource.h" |
34 #include "core/css/CSSFontSelector.h" | 34 #include "core/css/CSSFontSelector.h" |
35 #include "core/css/CSSSegmentedFontFace.h" | 35 #include "core/css/CSSSegmentedFontFace.h" |
36 #include "core/css/CSSValueList.h" | 36 #include "core/css/CSSValueList.h" |
37 #include "core/css/StyleRule.h" | 37 #include "core/css/StyleRule.h" |
38 #include "core/dom/Document.h" | |
39 #include "core/fetch/FontResource.h" | 38 #include "core/fetch/FontResource.h" |
40 #include "core/fetch/ResourceFetcher.h" | 39 #include "core/fetch/ResourceFetcher.h" |
41 #include "platform/fonts/FontDescription.h" | 40 #include "platform/fonts/FontDescription.h" |
42 #include "wtf/text/AtomicString.h" | 41 #include "wtf/text/AtomicString.h" |
43 | 42 |
44 namespace WebCore { | 43 namespace WebCore { |
45 | 44 |
46 CSSSegmentedFontFaceCache::CSSSegmentedFontFaceCache() | 45 CSSSegmentedFontFaceCache::CSSSegmentedFontFaceCache() |
47 : m_version(0) | 46 : m_version(0) |
48 { | 47 { |
49 } | 48 } |
50 | 49 |
51 void CSSSegmentedFontFaceCache::addFontFaceRule(CSSFontSelector* cssFontSelector
, const StyleRuleFontFace* fontFaceRule) | 50 void CSSSegmentedFontFaceCache::add(CSSFontSelector* cssFontSelector, const Styl
eRuleFontFace* fontFaceRule, PassRefPtr<CSSFontFace> prpCssFontFace) |
52 { | 51 { |
53 RefPtr<FontFace> fontFace = FontFace::create(fontFaceRule); | 52 RefPtr<CSSFontFace> cssFontFace = prpCssFontFace; |
54 if (!fontFace || fontFace->family().isEmpty()) | |
55 return; | |
56 | |
57 unsigned traitsMask = fontFace->traitsMask(); | |
58 if (!traitsMask) | |
59 return; | |
60 | |
61 RefPtr<CSSFontFace> cssFontFace = fontFace->createCSSFontFace(cssFontSelecto
r->document()); | |
62 if (!cssFontFace || !cssFontFace->isValid()) | |
63 return; | |
64 | 53 |
65 if (!m_styleRuleToFontFace.add(fontFaceRule, cssFontFace).isNewEntry) | 54 if (!m_styleRuleToFontFace.add(fontFaceRule, cssFontFace).isNewEntry) |
66 return; | 55 return; |
67 | 56 |
| 57 FontFace* fontFace = cssFontFace->fontFace(); |
| 58 |
68 OwnPtr<TraitsMap>& familyFontFaces = m_fontFaces.add(fontFace->family(), nul
lptr).iterator->value; | 59 OwnPtr<TraitsMap>& familyFontFaces = m_fontFaces.add(fontFace->family(), nul
lptr).iterator->value; |
69 if (!familyFontFaces) | 60 if (!familyFontFaces) |
70 familyFontFaces = adoptPtr(new TraitsMap); | 61 familyFontFaces = adoptPtr(new TraitsMap); |
71 | 62 |
72 RefPtr<CSSSegmentedFontFace>& segmentedFontFace = familyFontFaces->add(trait
sMask, 0).iterator->value; | 63 RefPtr<CSSSegmentedFontFace>& segmentedFontFace = familyFontFaces->add(fontF
ace->traitsMask(), 0).iterator->value; |
73 if (!segmentedFontFace) | 64 if (!segmentedFontFace) |
74 segmentedFontFace = CSSSegmentedFontFace::create(cssFontSelector, static
_cast<FontTraitsMask>(traitsMask)); | 65 segmentedFontFace = CSSSegmentedFontFace::create(cssFontSelector, static
_cast<FontTraitsMask>(fontFace->traitsMask())); |
75 | 66 |
76 segmentedFontFace->appendFontFace(cssFontFace); | 67 segmentedFontFace->appendFontFace(cssFontFace); |
77 | 68 |
78 ++m_version; | 69 ++m_version; |
79 } | 70 } |
80 | 71 |
81 void CSSSegmentedFontFaceCache::removeFontFaceRule(const StyleRuleFontFace* font
FaceRule) | 72 void CSSSegmentedFontFaceCache::remove(const StyleRuleFontFace* fontFaceRule) |
82 { | 73 { |
83 StyleRuleToFontFace::iterator styleRuleToFontFaceIter = m_styleRuleToFontFac
e.find(fontFaceRule); | 74 StyleRuleToFontFace::iterator styleRuleToFontFaceIter = m_styleRuleToFontFac
e.find(fontFaceRule); |
84 if (styleRuleToFontFaceIter == m_styleRuleToFontFace.end()) | 75 if (styleRuleToFontFaceIter == m_styleRuleToFontFace.end()) |
85 return; | 76 return; |
86 RefPtr<CSSFontFace> cssFontFace = styleRuleToFontFaceIter->value; | 77 RefPtr<CSSFontFace> cssFontFace = styleRuleToFontFaceIter->value; |
87 | 78 |
88 FamilyToTraitsMap::iterator fontFacesIter = m_fontFaces.find(cssFontFace->fo
ntFace()->family()); | 79 FamilyToTraitsMap::iterator fontFacesIter = m_fontFaces.find(cssFontFace->fo
ntFace()->family()); |
89 if (fontFacesIter == m_fontFaces.end()) | 80 if (fontFacesIter == m_fontFaces.end()) |
90 return; | 81 return; |
91 TraitsMap* familyFontFaces = fontFacesIter->value.get(); | 82 TraitsMap* familyFontFaces = fontFacesIter->value.get(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 for (unsigned i = 0; i < rulesPerSet; ++i) { | 170 for (unsigned i = 0; i < rulesPerSet; ++i) { |
180 if (secondTraitsMask & weightFallbackRule[i]) | 171 if (secondTraitsMask & weightFallbackRule[i]) |
181 return false; | 172 return false; |
182 if (firstTraitsMask & weightFallbackRule[i]) | 173 if (firstTraitsMask & weightFallbackRule[i]) |
183 return true; | 174 return true; |
184 } | 175 } |
185 | 176 |
186 return false; | 177 return false; |
187 } | 178 } |
188 | 179 |
189 CSSSegmentedFontFace* CSSSegmentedFontFaceCache::getFontFace(const FontDescripti
on& fontDescription, const AtomicString& family) | 180 CSSSegmentedFontFace* CSSSegmentedFontFaceCache::get(const FontDescription& font
Description, const AtomicString& family) |
190 { | 181 { |
191 TraitsMap* familyFontFaces = m_fontFaces.get(family); | 182 TraitsMap* familyFontFaces = m_fontFaces.get(family); |
192 if (!familyFontFaces || familyFontFaces->isEmpty()) | 183 if (!familyFontFaces || familyFontFaces->isEmpty()) |
193 return 0; | 184 return 0; |
194 | 185 |
195 OwnPtr<TraitsMap>& segmentedFontFaceCache = m_fonts.add(family, nullptr).ite
rator->value; | 186 OwnPtr<TraitsMap>& segmentedFontFaceCache = m_fonts.add(family, nullptr).ite
rator->value; |
196 if (!segmentedFontFaceCache) | 187 if (!segmentedFontFaceCache) |
197 segmentedFontFaceCache = adoptPtr(new TraitsMap); | 188 segmentedFontFaceCache = adoptPtr(new TraitsMap); |
198 | 189 |
199 FontTraitsMask traitsMask = fontDescription.traitsMask(); | 190 FontTraitsMask traitsMask = fontDescription.traitsMask(); |
200 | 191 |
201 RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsMask,
0).iterator->value; | 192 RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsMask,
0).iterator->value; |
202 if (!face) { | 193 if (!face) { |
203 for (TraitsMap::const_iterator i = familyFontFaces->begin(); i != family
FontFaces->end(); ++i) { | 194 for (TraitsMap::const_iterator i = familyFontFaces->begin(); i != family
FontFaces->end(); ++i) { |
204 CSSSegmentedFontFace* candidate = i->value.get(); | 195 CSSSegmentedFontFace* candidate = i->value.get(); |
205 unsigned candidateTraitsMask = candidate->traitsMask(); | 196 unsigned candidateTraitsMask = candidate->traitsMask(); |
206 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo
ntStyleNormalMask)) | 197 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo
ntStyleNormalMask)) |
207 continue; | 198 continue; |
208 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask &
FontVariantNormalMask)) | 199 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask &
FontVariantNormalMask)) |
209 continue; | 200 continue; |
210 if (!face || compareFontFaces(candidate, face.get(), traitsMask)) | 201 if (!face || compareFontFaces(candidate, face.get(), traitsMask)) |
211 face = candidate; | 202 face = candidate; |
212 } | 203 } |
213 } | 204 } |
214 return face.get(); | 205 return face.get(); |
215 } | 206 } |
216 | 207 |
217 } | 208 } |
OLD | NEW |