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 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 3 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 traitsMask |= FontVariantSmallCapsMask; | 188 traitsMask |= FontVariantSmallCapsMask; |
189 break; | 189 break; |
190 default: | 190 default: |
191 break; | 191 break; |
192 } | 192 } |
193 } | 193 } |
194 } else | 194 } else |
195 traitsMask |= FontVariantMask; | 195 traitsMask |= FontVariantMask; |
196 | 196 |
197 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace. | 197 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace. |
198 RefPtr<CSSFontFace> fontFace; | 198 Handle<CSSFontFace> fontFace; |
199 | 199 |
200 int srcLength = srcList->length(); | 200 int srcLength = srcList->length(); |
201 | 201 |
202 bool foundSVGFont = false; | 202 bool foundSVGFont = false; |
203 | 203 |
204 for (int i = 0; i < srcLength; i++) { | 204 for (int i = 0; i < srcLength; i++) { |
205 // An item in the list either specifies a string (local font name) or a URL (remote font to download). | 205 // An item in the list either specifies a string (local font name) or a URL (remote font to download). |
206 CSSFontFaceSrcValue* item = static_cast<CSSFontFaceSrcValue*>(srcList->i temWithoutBoundsCheck(i)); | 206 CSSFontFaceSrcValue* item = static_cast<CSSFontFaceSrcValue*>(srcList->i temWithoutBoundsCheck(i)); |
207 OwnPtr<CSSFontFaceSource> source; | 207 OwnPtr<CSSFontFaceSource> source; |
208 | 208 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 familyName = pictographFamily; | 285 familyName = pictographFamily; |
286 break; | 286 break; |
287 default: | 287 default: |
288 break; | 288 break; |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 if (familyName.isEmpty()) | 292 if (familyName.isEmpty()) |
293 continue; | 293 continue; |
294 | 294 |
295 OwnPtr<Vector<RefPtr<CSSFontFace> > >& familyFontFaces = m_fontFaces.add (familyName, nullptr).iterator->value; | 295 OwnPtr<CSSFontFaceVectorCollection>& familyFontFaces = m_fontFaces.add(f amilyName, nullptr).iterator->value; |
haraken
2013/07/03 04:39:20
What do you think about this? We cannot simply cha
Mads Ager (chromium)
2013/07/03 06:30:42
Yeah, this one is a little annoying. Another way w
haraken
2013/07/03 07:46:02
Done.
| |
296 if (!familyFontFaces) { | 296 if (!familyFontFaces) { |
297 familyFontFaces = adoptPtr(new Vector<RefPtr<CSSFontFace> >); | 297 familyFontFaces = adoptPtr(new CSSFontFaceVectorCollection); |
298 | 298 |
299 ASSERT(!m_locallyInstalledFontFaces.contains(familyName)); | 299 ASSERT(!m_locallyInstalledFontFaces.contains(familyName)); |
300 | 300 |
301 Vector<unsigned> locallyInstalledFontsTraitsMasks; | 301 Vector<unsigned> locallyInstalledFontsTraitsMasks; |
302 fontCache()->getTraitsInFamily(familyName, locallyInstalledFontsTrai tsMasks); | 302 fontCache()->getTraitsInFamily(familyName, locallyInstalledFontsTrai tsMasks); |
303 if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsM asks.size()) { | 303 if (unsigned numLocallyInstalledFaces = locallyInstalledFontsTraitsM asks.size()) { |
304 OwnPtr<Vector<RefPtr<CSSFontFace> > > familyLocallyInstalledFace s = adoptPtr(new Vector<RefPtr<CSSFontFace> >); | 304 OwnPtr<CSSFontFaceVectorCollection> familyLocallyInstalledFaces = adoptPtr(new CSSFontFaceVectorCollection); |
305 | 305 |
306 for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) { | 306 for (unsigned i = 0; i < numLocallyInstalledFaces; ++i) { |
307 RefPtr<CSSFontFace> locallyInstalledFontFace = CSSFontFace:: create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), nullptr , true); | 307 HandleScope scope; |
308 Handle<CSSFontFace> locallyInstalledFontFace = CSSFontFace:: create(static_cast<FontTraitsMask>(locallyInstalledFontsTraitsMasks[i]), nullptr , true); | |
308 locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFace Source(familyName))); | 309 locallyInstalledFontFace->addSource(adoptPtr(new CSSFontFace Source(familyName))); |
309 ASSERT(locallyInstalledFontFace->isValid()); | 310 ASSERT(locallyInstalledFontFace->isValid()); |
310 familyLocallyInstalledFaces->append(locallyInstalledFontFace ); | 311 (*familyLocallyInstalledFaces)->append(locallyInstalledFontF ace); |
311 } | 312 } |
312 | 313 |
313 m_locallyInstalledFontFaces.set(familyName, familyLocallyInstall edFaces.release()); | 314 m_locallyInstalledFontFaces.set(familyName, familyLocallyInstall edFaces.release()); |
314 } | 315 } |
315 } | 316 } |
316 | 317 |
317 familyFontFaces->append(fontFace); | 318 (*familyFontFaces)->append(fontFace); |
318 | 319 |
319 ++m_version; | 320 ++m_version; |
320 } | 321 } |
321 } | 322 } |
322 | 323 |
323 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien t) | 324 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* clien t) |
324 { | 325 { |
325 m_clients.add(client); | 326 m_clients.add(client); |
326 } | 327 } |
327 | 328 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 genericFamily = settings->standardFontFamily(script); | 386 genericFamily = settings->standardFontFamily(script); |
386 | 387 |
387 if (!genericFamily.isEmpty()) | 388 if (!genericFamily.isEmpty()) |
388 return fontCache()->getCachedFontData(fontDescription, genericFamily); | 389 return fontCache()->getCachedFontData(fontDescription, genericFamily); |
389 | 390 |
390 return 0; | 391 return 0; |
391 } | 392 } |
392 | 393 |
393 static FontTraitsMask desiredTraitsMaskForComparison; | 394 static FontTraitsMask desiredTraitsMaskForComparison; |
394 | 395 |
395 static inline bool compareFontFaces(CSSFontFace* first, CSSFontFace* second) | 396 static inline bool compareFontFaces(Handle<CSSFontFace> first, Handle<CSSFontFac e> second) |
396 { | 397 { |
397 FontTraitsMask firstTraitsMask = first->traitsMask(); | 398 FontTraitsMask firstTraitsMask = first->traitsMask(); |
398 FontTraitsMask secondTraitsMask = second->traitsMask(); | 399 FontTraitsMask secondTraitsMask = second->traitsMask(); |
399 | 400 |
400 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparis on & FontVariantMask; | 401 bool firstHasDesiredVariant = firstTraitsMask & desiredTraitsMaskForComparis on & FontVariantMask; |
401 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForCompar ison & FontVariantMask; | 402 bool secondHasDesiredVariant = secondTraitsMask & desiredTraitsMaskForCompar ison & FontVariantMask; |
402 | 403 |
403 if (firstHasDesiredVariant != secondHasDesiredVariant) | 404 if (firstHasDesiredVariant != secondHasDesiredVariant) |
404 return firstHasDesiredVariant; | 405 return firstHasDesiredVariant; |
405 | 406 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes cription, const AtomicString& familyName) | 476 PassRefPtr<FontData> CSSFontSelector::getFontData(const FontDescription& fontDes cription, const AtomicString& familyName) |
476 { | 477 { |
477 if (m_fontFaces.isEmpty()) { | 478 if (m_fontFaces.isEmpty()) { |
478 if (familyName.startsWith("-webkit-")) | 479 if (familyName.startsWith("-webkit-")) |
479 return fontDataForGenericFamily(m_document, fontDescription, familyN ame); | 480 return fontDataForGenericFamily(m_document, fontDescription, familyN ame); |
480 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) | 481 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) |
481 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); | 482 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); |
482 return 0; | 483 return 0; |
483 } | 484 } |
484 | 485 |
485 CSSSegmentedFontFace* face = getFontFace(fontDescription, familyName); | 486 Handle<CSSSegmentedFontFace> face = getFontFace(fontDescription, familyName) ; |
486 // If no face was found, then return 0 and let the OS come up with its best match for the name. | 487 // If no face was found, then return 0 and let the OS come up with its best match for the name. |
487 if (!face) { | 488 if (!face) { |
488 // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our | 489 // If we were handed a generic family, but there was no match, go ahead and return the correct font based off our |
489 // settings. | 490 // settings. |
490 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) | 491 if (fontDescription.genericFamily() == FontDescription::StandardFamily & & !fontDescription.isSpecifiedFont()) |
491 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); | 492 return fontDataForGenericFamily(m_document, fontDescription, "-webki t-standard"); |
492 return fontDataForGenericFamily(m_document, fontDescription, familyName) ; | 493 return fontDataForGenericFamily(m_document, fontDescription, familyName) ; |
493 } | 494 } |
494 | 495 |
495 // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over. | 496 // We have a face. Ask it for a font data. If it cannot produce one, it will fail, and the OS will take over. |
496 return face->getFontData(fontDescription); | 497 return face->getFontData(fontDescription); |
497 } | 498 } |
498 | 499 |
499 CSSSegmentedFontFace* CSSFontSelector::getFontFace(const FontDescription& fontDe scription, const AtomicString& family) | 500 Result<CSSSegmentedFontFace> CSSFontSelector::getFontFace(const FontDescription& fontDescription, const AtomicString& family) |
500 { | 501 { |
501 Vector<RefPtr<CSSFontFace> >* familyFontFaces = m_fontFaces.get(family); | 502 CSSFontFaceVectorCollection* familyFontFaces = m_fontFaces.get(family); |
502 if (!familyFontFaces || familyFontFaces->isEmpty()) | 503 if (!familyFontFaces || (*familyFontFaces)->isEmpty()) |
503 return 0; | 504 return nullptr; |
504 | 505 |
505 OwnPtr<HashMap<unsigned, RefPtr<CSSSegmentedFontFace> > >& segmentedFontFace Cache = m_fonts.add(family, nullptr).iterator->value; | 506 OwnPtr<HashMap<unsigned, Persistent<CSSSegmentedFontFace> > >& segmentedFont FaceCache = m_fonts.add(family, nullptr).iterator->value; |
506 if (!segmentedFontFaceCache) | 507 if (!segmentedFontFaceCache) |
507 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, RefPtr<CSSSegmen tedFontFace> >); | 508 segmentedFontFaceCache = adoptPtr(new HashMap<unsigned, Persistent<CSSSe gmentedFontFace> >); |
508 | 509 |
509 FontTraitsMask traitsMask = fontDescription.traitsMask(); | 510 FontTraitsMask traitsMask = fontDescription.traitsMask(); |
510 | 511 |
511 RefPtr<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsMask, 0).iterator->value; | 512 Persistent<CSSSegmentedFontFace>& face = segmentedFontFaceCache->add(traitsM ask, nullptr).iterator->value; |
Mads Ager (chromium)
2013/07/02 14:59:23
I don't think we should be using this pattern. The
haraken
2013/07/03 04:39:20
Done.
| |
512 if (!face) { | 513 if (!face) { |
513 face = CSSSegmentedFontFace::create(this); | 514 face = CSSSegmentedFontFace::create(this); |
514 | 515 |
515 // Collect all matching faces and sort them in order of preference. | 516 // Collect all matching faces and sort them in order of preference. |
516 Vector<CSSFontFace*, 32> candidateFontFaces; | 517 Vector<Handle<CSSFontFace>, 32> candidateFontFaces; |
517 for (int i = familyFontFaces->size() - 1; i >= 0; --i) { | 518 for (int i = (*familyFontFaces)->size() - 1; i >= 0; --i) { |
518 CSSFontFace* candidate = familyFontFaces->at(i).get(); | 519 HandleScope scope; |
520 Handle<CSSFontFace> candidate = (*familyFontFaces)->at(i); | |
519 unsigned candidateTraitsMask = candidate->traitsMask(); | 521 unsigned candidateTraitsMask = candidate->traitsMask(); |
520 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask)) | 522 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & Fo ntStyleNormalMask)) |
521 continue; | 523 continue; |
522 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask)) | 524 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMask & FontVariantNormalMask)) |
523 continue; | 525 continue; |
524 #if ENABLE(SVG_FONTS) | 526 #if ENABLE(SVG_FONTS) |
525 // For SVG Fonts that specify that they only support the "normal" va riant, we will assume they are incapable | 527 // For SVG Fonts that specify that they only support the "normal" va riant, we will assume they are incapable |
526 // of small-caps synthesis and just ignore the font face as a candid ate. | 528 // of small-caps synthesis and just ignore the font face as a candid ate. |
527 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSm allCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask)) | 529 if (candidate->hasSVGFontFaceSource() && (traitsMask & FontVariantSm allCapsMask) && !(candidateTraitsMask & FontVariantSmallCapsMask)) |
528 continue; | 530 continue; |
529 #endif | 531 #endif |
530 candidateFontFaces.append(candidate); | 532 candidateFontFaces.append(candidate); |
531 } | 533 } |
532 | 534 |
533 if (Vector<RefPtr<CSSFontFace> >* familyLocallyInstalledFontFaces = m_lo callyInstalledFontFaces.get(family)) { | 535 CSSFontFaceVectorCollection* familyLocallyInstalledFontFaces = m_locally InstalledFontFaces.get(family); |
534 unsigned numLocallyInstalledFontFaces = familyLocallyInstalledFontFa ces->size(); | 536 if (familyLocallyInstalledFontFaces) { |
537 unsigned numLocallyInstalledFontFaces = (*familyLocallyInstalledFont Faces)->size(); | |
535 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) { | 538 for (unsigned i = 0; i < numLocallyInstalledFontFaces; ++i) { |
536 CSSFontFace* candidate = familyLocallyInstalledFontFaces->at(i). get(); | 539 Handle<CSSFontFace> candidate = (*familyLocallyInstalledFontFace s)->at(i); |
537 unsigned candidateTraitsMask = candidate->traitsMask(); | 540 unsigned candidateTraitsMask = candidate->traitsMask(); |
538 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask)) | 541 if ((traitsMask & FontStyleNormalMask) && !(candidateTraitsMask & FontStyleNormalMask)) |
539 continue; | 542 continue; |
540 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMas k & FontVariantNormalMask)) | 543 if ((traitsMask & FontVariantNormalMask) && !(candidateTraitsMas k & FontVariantNormalMask)) |
541 continue; | 544 continue; |
542 candidateFontFaces.append(candidate); | 545 candidateFontFaces.append(candidate); |
543 } | 546 } |
544 } | 547 } |
545 | 548 |
546 desiredTraitsMaskForComparison = traitsMask; | 549 desiredTraitsMaskForComparison = traitsMask; |
547 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compar eFontFaces); | 550 stable_sort(candidateFontFaces.begin(), candidateFontFaces.end(), compar eFontFaces); |
548 unsigned numCandidates = candidateFontFaces.size(); | 551 unsigned numCandidates = candidateFontFaces.size(); |
549 for (unsigned i = 0; i < numCandidates; ++i) | 552 for (unsigned i = 0; i < numCandidates; ++i) |
550 face->appendFontFace(candidateFontFaces[i]); | 553 face->appendFontFace(candidateFontFaces[i]); |
551 } | 554 } |
552 return face.get(); | 555 return face; |
553 } | 556 } |
554 | 557 |
555 void CSSFontSelector::clearDocument() | 558 void CSSFontSelector::clearDocument() |
556 { | 559 { |
557 if (!m_document) { | 560 if (!m_document) { |
558 ASSERT(!m_beginLoadingTimer.isActive()); | 561 ASSERT(!m_beginLoadingTimer.isActive()); |
559 ASSERT(m_fontsToBeginLoading.isEmpty()); | 562 ASSERT(m_fontsToBeginLoading.isEmpty()); |
560 return; | 563 return; |
561 } | 564 } |
562 | 565 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 } | 605 } |
603 // Ensure that if the request count reaches zero, the frame loader will know about it. | 606 // Ensure that if the request count reaches zero, the frame loader will know about it. |
604 cachedResourceLoader->loadDone(0); | 607 cachedResourceLoader->loadDone(0); |
605 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched | 608 // New font loads may be triggered by layout after the document load is comp lete but before we have dispatched |
606 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly. | 609 // didFinishLoading for the frame. Make sure the delegate is always dispatch ed by checking explicitly. |
607 if (m_document && m_document->frame()) | 610 if (m_document && m_document->frame()) |
608 m_document->frame()->loader()->checkLoadComplete(); | 611 m_document->frame()->loader()->checkLoadComplete(); |
609 } | 612 } |
610 | 613 |
611 } | 614 } |
OLD | NEW |