OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007 Apple Computer, Inc. | 2 * Copyright (C) 2006, 2007 Apple Computer, Inc. |
3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved. | 3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 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 are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "platform/fonts/FontDescription.h" | 38 #include "platform/fonts/FontDescription.h" |
39 #include "platform/fonts/FontFaceCreationParams.h" | 39 #include "platform/fonts/FontFaceCreationParams.h" |
40 #include "platform/fonts/FontPlatformData.h" | 40 #include "platform/fonts/FontPlatformData.h" |
41 #include "platform/fonts/SimpleFontData.h" | 41 #include "platform/fonts/SimpleFontData.h" |
42 #include "platform/fonts/win/FontFallbackWin.h" | 42 #include "platform/fonts/win/FontFallbackWin.h" |
43 #include "wtf/PtrUtil.h" | 43 #include "wtf/PtrUtil.h" |
44 #include <memory> | 44 #include <memory> |
45 | 45 |
46 namespace blink { | 46 namespace blink { |
47 | 47 |
48 HashMap<String, RefPtr<SkTypeface>>* FontCache::s_sideloadedFonts = 0; | 48 HashMap<String, sk_sp<SkTypeface>>* FontCache::s_sideloadedFonts = 0; |
49 | 49 |
50 // Cached system font metrics. | 50 // Cached system font metrics. |
51 AtomicString* FontCache::s_menuFontFamilyName = 0; | 51 AtomicString* FontCache::s_menuFontFamilyName = 0; |
52 int32_t FontCache::s_menuFontHeight = 0; | 52 int32_t FontCache::s_menuFontHeight = 0; |
53 AtomicString* FontCache::s_smallCaptionFontFamilyName = 0; | 53 AtomicString* FontCache::s_smallCaptionFontFamilyName = 0; |
54 int32_t FontCache::s_smallCaptionFontHeight = 0; | 54 int32_t FontCache::s_smallCaptionFontHeight = 0; |
55 AtomicString* FontCache::s_statusFontFamilyName = 0; | 55 AtomicString* FontCache::s_statusFontFamilyName = 0; |
56 int32_t FontCache::s_statusFontHeight = 0; | 56 int32_t FontCache::s_statusFontHeight = 0; |
57 | 57 |
58 namespace { | 58 namespace { |
59 | 59 |
60 int32_t ensureMinimumFontHeightIfNeeded(int32_t fontHeight) | 60 int32_t ensureMinimumFontHeightIfNeeded(int32_t fontHeight) |
61 { | 61 { |
62 // Adjustment for codepage 936 to make the fonts more legible in Simplified
Chinese. | 62 // Adjustment for codepage 936 to make the fonts more legible in Simplified
Chinese. |
63 // Please refer to LayoutThemeFontProviderWin.cpp for more information. | 63 // Please refer to LayoutThemeFontProviderWin.cpp for more information. |
64 return (fontHeight < 12.0f) && (GetACP() == 936) ? 12.0f : fontHeight; | 64 return (fontHeight < 12.0f) && (GetACP() == 936) ? 12.0f : fontHeight; |
65 } | 65 } |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 // static | 69 // static |
70 void FontCache::addSideloadedFontForTesting(SkTypeface* typeface) | 70 void FontCache::addSideloadedFontForTesting(SkTypeface* typeface) |
71 { | 71 { |
72 if (!s_sideloadedFonts) | 72 if (!s_sideloadedFonts) |
73 s_sideloadedFonts = new HashMap<String, RefPtr<SkTypeface>>; | 73 s_sideloadedFonts = new HashMap<String, sk_sp<SkTypeface>>; |
74 SkString name; | 74 SkString name; |
75 typeface->getFamilyName(&name); | 75 typeface->getFamilyName(&name); |
76 s_sideloadedFonts->set(name.c_str(), adoptRef(typeface)); | 76 s_sideloadedFonts->set(name.c_str(), sk_sp<SkTypeface>(typeface)); |
77 } | 77 } |
78 | 78 |
79 // static | 79 // static |
80 void FontCache::setMenuFontMetrics(const wchar_t* familyName, int32_t fontHeight
) | 80 void FontCache::setMenuFontMetrics(const wchar_t* familyName, int32_t fontHeight
) |
81 { | 81 { |
82 s_menuFontFamilyName = new AtomicString(familyName); | 82 s_menuFontFamilyName = new AtomicString(familyName); |
83 s_menuFontHeight = ensureMinimumFontHeightIfNeeded(fontHeight); | 83 s_menuFontHeight = ensureMinimumFontHeightIfNeeded(fontHeight); |
84 } | 84 } |
85 | 85 |
86 // static | 86 // static |
87 void FontCache::setSmallCaptionFontMetrics(const wchar_t* familyName, int32_t fo
ntHeight) | 87 void FontCache::setSmallCaptionFontMetrics(const wchar_t* familyName, int32_t fo
ntHeight) |
88 { | 88 { |
89 s_smallCaptionFontFamilyName = new AtomicString(familyName); | 89 s_smallCaptionFontFamilyName = new AtomicString(familyName); |
90 s_smallCaptionFontHeight = ensureMinimumFontHeightIfNeeded(fontHeight); | 90 s_smallCaptionFontHeight = ensureMinimumFontHeightIfNeeded(fontHeight); |
91 } | 91 } |
92 | 92 |
93 // static | 93 // static |
94 void FontCache::setStatusFontMetrics(const wchar_t* familyName, int32_t fontHeig
ht) | 94 void FontCache::setStatusFontMetrics(const wchar_t* familyName, int32_t fontHeig
ht) |
95 { | 95 { |
96 s_statusFontFamilyName = new AtomicString(familyName); | 96 s_statusFontFamilyName = new AtomicString(familyName); |
97 s_statusFontHeight = ensureMinimumFontHeightIfNeeded(fontHeight); | 97 s_statusFontHeight = ensureMinimumFontHeightIfNeeded(fontHeight); |
98 } | 98 } |
99 | 99 |
100 FontCache::FontCache() | 100 FontCache::FontCache() |
101 : m_purgePreventCount(0) | 101 : m_purgePreventCount(0) |
102 { | 102 { |
103 m_fontManager = s_staticFontManager; | 103 m_fontManager = sk_ref_sp(s_staticFontManager); |
104 if (!m_fontManager.get()) | 104 if (!m_fontManager) |
105 m_fontManager = adoptRef(SkFontMgr_New_DirectWrite()); | 105 m_fontManager.reset(SkFontMgr_New_DirectWrite()); |
106 ASSERT(m_fontManager.get()); | 106 ASSERT(m_fontManager.get()); |
107 } | 107 } |
108 | 108 |
109 // Given the desired base font, this will create a SimpleFontData for a specific | 109 // Given the desired base font, this will create a SimpleFontData for a specific |
110 // font that can be used to render the given range of characters. | 110 // font that can be used to render the given range of characters. |
111 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter( | 111 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter( |
112 const FontDescription& fontDescription, UChar32 character, | 112 const FontDescription& fontDescription, UChar32 character, |
113 const SimpleFontData* originalFontData, | 113 const SimpleFontData* originalFontData, |
114 FontFallbackPriority fallbackPriority) | 114 FontFallbackPriority fallbackPriority) |
115 { | 115 { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 353 |
354 return false; | 354 return false; |
355 } | 355 } |
356 | 356 |
357 std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
scription& fontDescription, | 357 std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
scription& fontDescription, |
358 const FontFaceCreationParams& creationParams, float fontSize) | 358 const FontFaceCreationParams& creationParams, float fontSize) |
359 { | 359 { |
360 ASSERT(creationParams.creationType() == CreateFontByFamily); | 360 ASSERT(creationParams.creationType() == CreateFontByFamily); |
361 | 361 |
362 CString name; | 362 CString name; |
363 RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name
); | 363 sk_sp<SkTypeface> tf = createTypeface(fontDescription, creationParams, name)
; |
364 // Windows will always give us a valid pointer here, even if the face name | 364 // Windows will always give us a valid pointer here, even if the face name |
365 // is non-existent. We have to double-check and see if the family name was | 365 // is non-existent. We have to double-check and see if the family name was |
366 // really used. | 366 // really used. |
367 if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) { | 367 if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) { |
368 AtomicString adjustedName; | 368 AtomicString adjustedName; |
369 FontWeight variantWeight; | 369 FontWeight variantWeight; |
370 FontStretch variantStretch; | 370 FontStretch variantStretch; |
371 | 371 |
372 if (typefacesHasWeightSuffix(creationParams.family(), adjustedName, | 372 if (typefacesHasWeightSuffix(creationParams.family(), adjustedName, |
373 variantWeight)) { | 373 variantWeight)) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 if (typefacesMatchesFamily(tf.get(), family)) { | 444 if (typefacesMatchesFamily(tf.get(), family)) { |
445 result->setMinSizeForSubpixel(minSizeForSubpixelForFont); | 445 result->setMinSizeForSubpixel(minSizeForSubpixelForFont); |
446 break; | 446 break; |
447 } | 447 } |
448 } | 448 } |
449 | 449 |
450 return result; | 450 return result; |
451 } | 451 } |
452 | 452 |
453 } // namespace blink | 453 } // namespace blink |
OLD | NEW |