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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 // users, so we are putting arbitrary limit on cache file size. There are | 77 // users, so we are putting arbitrary limit on cache file size. There are |
78 // multiple ways we can tune our working size, like mapping only required part | 78 // multiple ways we can tune our working size, like mapping only required part |
79 // of section at any given time. | 79 // of section at any given time. |
80 const double kArbitraryCacheFileSizeLimit = (30 * 1024 * 1024); | 80 const double kArbitraryCacheFileSizeLimit = (30 * 1024 * 1024); |
81 | 81 |
82 // We have chosen current font file length arbitrarily. In our logic | 82 // We have chosen current font file length arbitrarily. In our logic |
83 // if we don't find file we are looking for in cache we end up loading | 83 // if we don't find file we are looking for in cache we end up loading |
84 // that file directly from system fonts folder. | 84 // that file directly from system fonts folder. |
85 const unsigned int kMaxFontFileNameLength = 34; | 85 const unsigned int kMaxFontFileNameLength = 34; |
86 | 86 |
87 const DWORD kCacheFileVersion = 103; | 87 const DWORD kCacheFileVersion = 104; |
scottmg
2015/02/06 19:27:33
shrikant: Is this necessary?
Shrikant Kelkar
2015/02/06 20:56:22
Not necessary in this case.. Registry fonts will b
scottmg
2015/02/06 21:39:33
OK, undid this change.
| |
88 const DWORD kFileSignature = 0x4D4F5243; // CROM | 88 const DWORD kFileSignature = 0x4D4F5243; // CROM |
89 const DWORD kMagicCompletionSignature = 0x454E4F44; // DONE | 89 const DWORD kMagicCompletionSignature = 0x454E4F44; // DONE |
90 | 90 |
91 const DWORD kUndefinedDWORDS = 36; | 91 const DWORD kUndefinedDWORDS = 36; |
92 | 92 |
93 // Make sure that all structure sizes align with 8 byte boundary otherwise | 93 // Make sure that all structure sizes align with 8 byte boundary otherwise |
94 // dr. memory test may complain. | 94 // dr. memory test may complain. |
95 #pragma pack(push, 8) | 95 #pragma pack(push, 8) |
96 // Cache file header, includes signature, completion bits and version. | 96 // Cache file header, includes signature, completion bits and version. |
97 struct CacheFileHeader { | 97 struct CacheFileHeader { |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 regkey.ReadValue(name.c_str(), &value) == ERROR_SUCCESS) { | 766 regkey.ReadValue(name.c_str(), &value) == ERROR_SUCCESS) { |
767 base::FilePath path(value.c_str()); | 767 base::FilePath path(value.c_str()); |
768 // We need to check if file name is the only component that exists, | 768 // We need to check if file name is the only component that exists, |
769 // we will ignore all other registry entries. | 769 // we will ignore all other registry entries. |
770 std::vector<base::FilePath::StringType> components; | 770 std::vector<base::FilePath::StringType> components; |
771 path.GetComponents(&components); | 771 path.GetComponents(&components); |
772 if ((components.size() == 1 && | 772 if ((components.size() == 1 && |
773 value.size() < kMaxFontFileNameLength - 1) || | 773 value.size() < kMaxFontFileNameLength - 1) || |
774 base::FilePath::CompareEqualIgnoreCase(system_font_path.value(), | 774 base::FilePath::CompareEqualIgnoreCase(system_font_path.value(), |
775 path.DirName().value())) { | 775 path.DirName().value())) { |
776 reg_fonts_.push_back(value.c_str()); | 776 // "Gill Sans Ultra Bold" turns into an Ultra Bold weight "Gill Sans" |
777 // in DirectWrite, but most users don't have any other weights. The | |
778 // regular weight font is named "Gill Sans MT", but that ends up in a | |
779 // different family with that name. On Mac, there's a "Gill Sans" with | |
780 // various weights, so CSS authors use { 'font-family': 'Gill Sans', | |
781 // 'Gill Sans MT', ... } and because of the DirectWrite family futzing, | |
782 // they end up with an Ultra Bold font, when they just wanted "Gill | |
783 // Sans". Mozilla implemented a more complicated hack where they | |
784 // effectively rename the Ultra Bold font to "Gill Sans MT Ultra Bold", | |
785 // but because the Ultra Bold font is so ugly anyway, we simply ignore | |
786 // it. See http://www.microsoft.com/typography/fonts/font.aspx?FMID=978 | |
787 // for a picture of the font, and the file name. We also ignore "Gill | |
788 // Sans Ultra Bold Condensed". | |
789 if (!base::FilePath::CompareEqualIgnoreCase( | |
790 path.value(), FILE_PATH_LITERAL("gilsanub.ttf")) && | |
791 !base::FilePath::CompareEqualIgnoreCase( | |
792 path.value(), FILE_PATH_LITERAL("gillubcd.ttf"))) { | |
Shrikant Kelkar
2015/02/06 20:56:22
Since more than one, please consider using fonts_t
scottmg
2015/02/06 21:39:33
Done.
| |
793 reg_fonts_.push_back(value.c_str()); | |
794 } | |
777 } | 795 } |
778 } | 796 } |
779 } | 797 } |
780 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Loaded", reg_fonts_.size()); | 798 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Loaded", reg_fonts_.size()); |
781 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Ignored", | 799 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Ignored", |
782 regkey.GetValueCount() - reg_fonts_.size()); | 800 regkey.GetValueCount() - reg_fonts_.size()); |
783 return true; | 801 return true; |
784 } | 802 } |
785 | 803 |
786 // This list is mainly based on prefs/prefs_tab_helper.cc kFontDefaults. | 804 // This list is mainly based on prefs/prefs_tab_helper.cc kFontDefaults. |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 g_shared_font_cache.Set(mapping); | 1195 g_shared_font_cache.Set(mapping); |
1178 | 1196 |
1179 return true; | 1197 return true; |
1180 } | 1198 } |
1181 | 1199 |
1182 bool BuildFontCache(const base::FilePath& file) { | 1200 bool BuildFontCache(const base::FilePath& file) { |
1183 return BuildFontCacheInternal(file.value().c_str()); | 1201 return BuildFontCacheInternal(file.value().c_str()); |
1184 } | 1202 } |
1185 | 1203 |
1186 } // namespace content | 1204 } // namespace content |
OLD | NEW |