Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1333)

Side by Side Diff: content/common/dwrite_font_platform_win.cc

Issue 898403002: win: Hack around Gill Sans Ultra Bold DirectWrite problem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 wchar_t* kFontsToIgnore[] = {
750 // "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
752 // 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,
754 // 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
756 // font, when they just wanted "Gill Sans". Mozilla implemented a more
757 // 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
759 // anyway, we simply ignore it. See
760 // http://www.microsoft.com/typography/fonts/font.aspx?FMID=978 for a picture
761 // of the font, and the file name. We also ignore "Gill Sans Ultra Bold
762 // Condensed".
763 L"gilsanub.ttf",
764 L"gillubcd.ttf",
765 };
766
749 bool FontCollectionLoader::LoadFontListFromRegistry() { 767 bool FontCollectionLoader::LoadFontListFromRegistry() {
750 const wchar_t kFontsRegistry[] = 768 const wchar_t kFontsRegistry[] =
751 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; 769 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
752 CHECK(reg_fonts_.empty()); 770 CHECK(reg_fonts_.empty());
753 base::win::RegKey regkey; 771 base::win::RegKey regkey;
754 if (regkey.Open(HKEY_LOCAL_MACHINE, kFontsRegistry, KEY_READ) != 772 if (regkey.Open(HKEY_LOCAL_MACHINE, kFontsRegistry, KEY_READ) !=
755 ERROR_SUCCESS) { 773 ERROR_SUCCESS) {
756 return false; 774 return false;
757 } 775 }
758 776
759 base::FilePath system_font_path; 777 base::FilePath system_font_path;
760 PathService::Get(base::DIR_WINDOWS_FONTS, &system_font_path); 778 PathService::Get(base::DIR_WINDOWS_FONTS, &system_font_path);
761 779
762 base::string16 name; 780 base::string16 name;
763 base::string16 value; 781 base::string16 value;
764 for (DWORD idx = 0; idx < regkey.GetValueCount(); idx++) { 782 for (DWORD idx = 0; idx < regkey.GetValueCount(); idx++) {
765 if (regkey.GetValueNameAt(idx, &name) == ERROR_SUCCESS && 783 if (regkey.GetValueNameAt(idx, &name) == ERROR_SUCCESS &&
766 regkey.ReadValue(name.c_str(), &value) == ERROR_SUCCESS) { 784 regkey.ReadValue(name.c_str(), &value) == ERROR_SUCCESS) {
767 base::FilePath path(value.c_str()); 785 base::FilePath path(value.c_str());
768 // We need to check if file name is the only component that exists, 786 // We need to check if file name is the only component that exists,
769 // we will ignore all other registry entries. 787 // we will ignore all other registry entries.
770 std::vector<base::FilePath::StringType> components; 788 std::vector<base::FilePath::StringType> components;
771 path.GetComponents(&components); 789 path.GetComponents(&components);
772 if ((components.size() == 1 && 790 if ((components.size() == 1 &&
773 value.size() < kMaxFontFileNameLength - 1) || 791 value.size() < kMaxFontFileNameLength - 1) ||
774 base::FilePath::CompareEqualIgnoreCase(system_font_path.value(), 792 base::FilePath::CompareEqualIgnoreCase(system_font_path.value(),
775 path.DirName().value())) { 793 path.DirName().value())) {
776 reg_fonts_.push_back(value.c_str()); 794 bool should_ignore = false;
795 for (const auto& ignore : kFontsToIgnore) {
796 if (base::FilePath::CompareEqualIgnoreCase(path.value(), ignore)) {
797 should_ignore = true;
798 break;
799 }
800 }
801 if (!should_ignore)
802 reg_fonts_.push_back(value.c_str());
777 } 803 }
778 } 804 }
779 } 805 }
780 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Loaded", reg_fonts_.size()); 806 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Loaded", reg_fonts_.size());
781 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Ignored", 807 UMA_HISTOGRAM_COUNTS("DirectWrite.Fonts.Ignored",
782 regkey.GetValueCount() - reg_fonts_.size()); 808 regkey.GetValueCount() - reg_fonts_.size());
783 return true; 809 return true;
784 } 810 }
785 811
786 // This list is mainly based on prefs/prefs_tab_helper.cc kFontDefaults. 812 // This list is mainly based on prefs/prefs_tab_helper.cc kFontDefaults.
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 g_shared_font_cache.Set(mapping); 1203 g_shared_font_cache.Set(mapping);
1178 1204
1179 return true; 1205 return true;
1180 } 1206 }
1181 1207
1182 bool BuildFontCache(const base::FilePath& file) { 1208 bool BuildFontCache(const base::FilePath& file) {
1183 return BuildFontCacheInternal(file.value().c_str()); 1209 return BuildFontCacheInternal(file.value().c_str());
1184 } 1210 }
1185 1211
1186 } // namespace content 1212 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698