Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/common/dwrite_font_platform_win.h" | 5 #include "content/public/common/dwrite_font_platform_win.h" |
| 6 | 6 |
| 7 #include <dwrite.h> | 7 #include <dwrite.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 | 739 |
| 740 UINT32 FontCollectionLoader::GetFontMapSize() { | 740 UINT32 FontCollectionLoader::GetFontMapSize() { |
| 741 return reg_fonts_.size(); | 741 return reg_fonts_.size(); |
| 742 } | 742 } |
| 743 | 743 |
| 744 base::string16 FontCollectionLoader::GetFontNameFromKey(UINT32 idx) { | 744 base::string16 FontCollectionLoader::GetFontNameFromKey(UINT32 idx) { |
| 745 DCHECK(idx < reg_fonts_.size()); | 745 DCHECK(idx < reg_fonts_.size()); |
| 746 return reg_fonts_[idx]; | 746 return reg_fonts_[idx]; |
| 747 } | 747 } |
| 748 | 748 |
| 749 const base::FilePath::CharType* kFontExtensionsToIgnore[] { | |
| 750 FILE_PATH_LITERAL(".FON"), // Bitmap or vector | |
|
scottmg
2015/03/26 01:26:54
huh! I didn't know .fon had a vector format too.
| |
| 751 FILE_PATH_LITERAL(".PFM"), // Adobe Type 1 | |
| 752 FILE_PATH_LITERAL(".PFB"), // Adobe Type 1 | |
| 753 }; | |
| 754 | |
| 749 const wchar_t* kFontsToIgnore[] = { | 755 const wchar_t* kFontsToIgnore[] = { |
| 750 // "Gill Sans Ultra Bold" turns into an Ultra Bold weight "Gill Sans" in | 756 // "Gill Sans Ultra Bold" turns into an Ultra Bold weight "Gill Sans" in |
| 751 // DirectWrite, but most users don't have any other weights. The regular | 757 // DirectWrite, but most users don't have any other weights. The regular |
| 752 // weight font is named "Gill Sans MT", but that ends up in a different | 758 // weight font is named "Gill Sans MT", but that ends up in a different |
| 753 // family with that name. On Mac, there's a "Gill Sans" with various weights, | 759 // family with that name. On Mac, there's a "Gill Sans" with various weights, |
| 754 // so CSS authors use { 'font-family': 'Gill Sans', 'Gill Sans MT', ... } and | 760 // so CSS authors use { 'font-family': 'Gill Sans', 'Gill Sans MT', ... } and |
| 755 // because of the DirectWrite family futzing, they end up with an Ultra Bold | 761 // because of the DirectWrite family futzing, they end up with an Ultra Bold |
| 756 // font, when they just wanted "Gill Sans". Mozilla implemented a more | 762 // font, when they just wanted "Gill Sans". Mozilla implemented a more |
| 757 // complicated hack where they effectively rename the Ultra Bold font to | 763 // complicated hack where they effectively rename the Ultra Bold font to |
| 758 // "Gill Sans MT Ultra Bold", but because the Ultra Bold font is so ugly | 764 // "Gill Sans MT Ultra Bold", but because the Ultra Bold font is so ugly |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 value.size() < kMaxFontFileNameLength - 1) || | 797 value.size() < kMaxFontFileNameLength - 1) || |
| 792 base::FilePath::CompareEqualIgnoreCase(system_font_path.value(), | 798 base::FilePath::CompareEqualIgnoreCase(system_font_path.value(), |
| 793 path.DirName().value())) { | 799 path.DirName().value())) { |
| 794 bool should_ignore = false; | 800 bool should_ignore = false; |
| 795 for (const auto& ignore : kFontsToIgnore) { | 801 for (const auto& ignore : kFontsToIgnore) { |
| 796 if (base::FilePath::CompareEqualIgnoreCase(path.value(), ignore)) { | 802 if (base::FilePath::CompareEqualIgnoreCase(path.value(), ignore)) { |
| 797 should_ignore = true; | 803 should_ignore = true; |
| 798 break; | 804 break; |
| 799 } | 805 } |
| 800 } | 806 } |
| 807 // DirectWrite doesn't support bitmap/vector fonts and Adobe type 1 | |
| 808 // fonts, we will ignore those font extensions. | |
| 809 // MSDN article: http://goo.gl/TfCOA | |
| 810 if (!should_ignore) { | |
| 811 for (const auto& ignore : kFontExtensionsToIgnore) { | |
| 812 if (path.MatchesExtension(ignore)) { | |
| 813 should_ignore = true; | |
| 814 break; | |
| 815 } | |
| 816 } | |
| 817 } | |
| 818 | |
| 801 if (!should_ignore) | 819 if (!should_ignore) |
| 802 reg_fonts_.push_back(value.c_str()); | 820 reg_fonts_.push_back(value.c_str()); |
| 803 } | 821 } |
| 804 } | 822 } |
| 805 } | 823 } |
| 806 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Loaded", reg_fonts_.size()); | 824 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Loaded", reg_fonts_.size()); |
| 807 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Ignored", | 825 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Ignored", |
| 808 regkey.GetValueCount() - reg_fonts_.size()); | 826 regkey.GetValueCount() - reg_fonts_.size()); |
| 809 return true; | 827 return true; |
| 810 } | 828 } |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 g_shared_font_cache.Set(mapping); | 1221 g_shared_font_cache.Set(mapping); |
| 1204 | 1222 |
| 1205 return true; | 1223 return true; |
| 1206 } | 1224 } |
| 1207 | 1225 |
| 1208 bool BuildFontCache(const base::FilePath& file) { | 1226 bool BuildFontCache(const base::FilePath& file) { |
| 1209 return BuildFontCacheInternal(file.value().c_str()); | 1227 return BuildFontCacheInternal(file.value().c_str()); |
| 1210 } | 1228 } |
| 1211 | 1229 |
| 1212 } // namespace content | 1230 } // namespace content |
| OLD | NEW |