| 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 = (20 * 1024 * 1024); | 80 const double kArbitraryCacheFileSizeLimit = (20 * 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 = 101; | 87 const DWORD kCacheFileVersion = 102; |
| 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 { |
| 98 CacheFileHeader() { | 98 CacheFileHeader() { |
| 99 file_signature = kFileSignature; | 99 file_signature = kFileSignature; |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 IDWriteFontCollection* GetCustomFontCollection(IDWriteFactory* factory) { | 1018 IDWriteFontCollection* GetCustomFontCollection(IDWriteFactory* factory) { |
| 1019 if (g_font_collection.Get() != NULL) | 1019 if (g_font_collection.Get() != NULL) |
| 1020 return g_font_collection.Get(); | 1020 return g_font_collection.Get(); |
| 1021 | 1021 |
| 1022 base::TimeTicks start_tick = base::TimeTicks::Now(); | 1022 base::TimeTicks start_tick = base::TimeTicks::Now(); |
| 1023 | 1023 |
| 1024 FontCollectionLoader::Initialize(factory); | 1024 FontCollectionLoader::Initialize(factory); |
| 1025 | 1025 |
| 1026 bool cache_file_loaded = g_font_loader->LoadCacheFile(); | 1026 bool cache_file_loaded = g_font_loader->LoadCacheFile(); |
| 1027 | 1027 |
| 1028 // We try here to put arbitrary limit on max number of fonts that could | |
| 1029 // be loaded, otherwise we fallback to restricted set of fonts. | |
| 1030 const UINT32 kMaxFontThreshold = 1750; | |
| 1031 HRESULT hr = E_FAIL; | 1028 HRESULT hr = E_FAIL; |
| 1032 if (g_font_loader->GetFontMapSize() < kMaxFontThreshold) { | 1029 g_font_loader->EnableCollectionBuildingMode(true); |
| 1033 g_font_loader->EnableCollectionBuildingMode(true); | 1030 hr = factory->CreateCustomFontCollection( |
| 1034 hr = factory->CreateCustomFontCollection( | 1031 g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf()); |
| 1035 g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf()); | 1032 g_font_loader->EnableCollectionBuildingMode(false); |
| 1036 g_font_loader->EnableCollectionBuildingMode(false); | |
| 1037 } | |
| 1038 | 1033 |
| 1039 bool loading_restricted = false; | 1034 bool loading_restricted = false; |
| 1040 if (FAILED(hr) || !g_font_collection.Get()) { | 1035 if (FAILED(hr) || !g_font_collection.Get()) { |
| 1041 loading_restricted = true; | 1036 loading_restricted = true; |
| 1042 // We will try here just one more time with restricted font set. | 1037 // We will try here just one more time with restricted font set. |
| 1043 g_font_loader->LoadRestrictedFontList(); | 1038 g_font_loader->LoadRestrictedFontList(); |
| 1044 hr = factory->CreateCustomFontCollection( | 1039 hr = factory->CreateCustomFontCollection( |
| 1045 g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf()); | 1040 g_font_loader.Get(), NULL, 0, g_font_collection.GetAddressOf()); |
| 1046 } | 1041 } |
| 1047 | 1042 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 reinterpret_cast<IUnknown**>(factory.GetAddressOf())))); | 1090 reinterpret_cast<IUnknown**>(factory.GetAddressOf())))); |
| 1096 | 1091 |
| 1097 base::TimeTicks start_tick = base::TimeTicks::Now(); | 1092 base::TimeTicks start_tick = base::TimeTicks::Now(); |
| 1098 | 1093 |
| 1099 FontCollectionLoader::Initialize(factory.Get()); | 1094 FontCollectionLoader::Initialize(factory.Get()); |
| 1100 | 1095 |
| 1101 g_font_loader->EnterStaticCacheMode(file_name); | 1096 g_font_loader->EnterStaticCacheMode(file_name); |
| 1102 | 1097 |
| 1103 mswr::ComPtr<IDWriteFontCollection> font_collection; | 1098 mswr::ComPtr<IDWriteFontCollection> font_collection; |
| 1104 | 1099 |
| 1105 // We try here to put arbitrary limit on max number of fonts that could | |
| 1106 // be loaded, otherwise we fallback to restricted set of fonts. | |
| 1107 const UINT32 kMaxFontThreshold = 1750; | |
| 1108 HRESULT hr = E_FAIL; | 1100 HRESULT hr = E_FAIL; |
| 1109 if (g_font_loader->GetFontMapSize() < kMaxFontThreshold) { | 1101 g_font_loader->EnableCollectionBuildingMode(true); |
| 1110 g_font_loader->EnableCollectionBuildingMode(true); | 1102 hr = factory->CreateCustomFontCollection( |
| 1111 hr = factory->CreateCustomFontCollection( | 1103 g_font_loader.Get(), NULL, 0, font_collection.GetAddressOf()); |
| 1112 g_font_loader.Get(), NULL, 0, font_collection.GetAddressOf()); | 1104 g_font_loader->EnableCollectionBuildingMode(false); |
| 1113 g_font_loader->EnableCollectionBuildingMode(false); | |
| 1114 } | |
| 1115 | 1105 |
| 1116 bool loading_restricted = false; | 1106 bool loading_restricted = false; |
| 1117 if (FAILED(hr) || !font_collection.Get()) { | 1107 if (FAILED(hr) || !font_collection.Get()) { |
| 1118 loading_restricted = true; | 1108 loading_restricted = true; |
| 1119 // We will try here just one more time with restricted font set. | 1109 // We will try here just one more time with restricted font set. |
| 1120 g_font_loader->LoadRestrictedFontList(); | 1110 g_font_loader->LoadRestrictedFontList(); |
| 1121 hr = factory->CreateCustomFontCollection( | 1111 hr = factory->CreateCustomFontCollection( |
| 1122 g_font_loader.Get(), NULL, 0, font_collection.GetAddressOf()); | 1112 g_font_loader.Get(), NULL, 0, font_collection.GetAddressOf()); |
| 1123 } | 1113 } |
| 1124 | 1114 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 g_shared_font_cache.Set(mapping); | 1171 g_shared_font_cache.Set(mapping); |
| 1182 | 1172 |
| 1183 return true; | 1173 return true; |
| 1184 } | 1174 } |
| 1185 | 1175 |
| 1186 bool BuildFontCache(const base::FilePath& file) { | 1176 bool BuildFontCache(const base::FilePath& file) { |
| 1187 return BuildFontCacheInternal(file.value().c_str()); | 1177 return BuildFontCacheInternal(file.value().c_str()); |
| 1188 } | 1178 } |
| 1189 | 1179 |
| 1190 } // namespace content | 1180 } // namespace content |
| OLD | NEW |