| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/font_fallback_win.h" | 5 #include "ui/gfx/font_fallback_win.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/win/registry.h" | 13 #include "base/win/registry.h" |
| 14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
| 15 #include "ui/gfx/font_fallback.h" |
| 15 | 16 |
| 16 namespace gfx { | 17 namespace gfx { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Queries the registry to get a mapping from font filenames to font names. | 21 // Queries the registry to get a mapping from font filenames to font names. |
| 21 void QueryFontsFromRegistry(std::map<std::string, std::string>* map) { | 22 void QueryFontsFromRegistry(std::map<std::string, std::string>* map) { |
| 22 const wchar_t* kFonts = | 23 const wchar_t* kFonts = |
| 23 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; | 24 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; |
| 24 | 25 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 if (!font_names->empty()) { | 180 if (!font_names->empty()) { |
| 180 const size_t index = font_names->back().find('('); | 181 const size_t index = font_names->back().find('('); |
| 181 if (index != std::string::npos) { | 182 if (index != std::string::npos) { |
| 182 font_names->back().resize(index); | 183 font_names->back().resize(index); |
| 183 base::TrimWhitespace(font_names->back(), base::TRIM_TRAILING, | 184 base::TrimWhitespace(font_names->back(), base::TRIM_TRAILING, |
| 184 &font_names->back()); | 185 &font_names->back()); |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 } | 188 } |
| 188 | 189 |
| 189 } // namespace internal | |
| 190 | |
| 191 LinkedFontsIterator::LinkedFontsIterator(Font font) | 190 LinkedFontsIterator::LinkedFontsIterator(Font font) |
| 192 : original_font_(font), | 191 : original_font_(font), |
| 193 next_font_set_(false), | 192 next_font_set_(false), |
| 194 linked_fonts_(NULL), | 193 linked_fonts_(NULL), |
| 195 linked_font_index_(0) { | 194 linked_font_index_(0) { |
| 196 SetNextFont(original_font_); | 195 SetNextFont(original_font_); |
| 197 } | 196 } |
| 198 | 197 |
| 199 LinkedFontsIterator::~LinkedFontsIterator() { | 198 LinkedFontsIterator::~LinkedFontsIterator() { |
| 200 } | 199 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 // | 235 // |
| 237 // Note: One possibility would be to always merge both lists of fonts, | 236 // Note: One possibility would be to always merge both lists of fonts, |
| 238 // but it is not clear whether there are any real world scenarios | 237 // but it is not clear whether there are any real world scenarios |
| 239 // where this would actually help. | 238 // where this would actually help. |
| 240 if (fonts->empty()) | 239 if (fonts->empty()) |
| 241 fonts = font_link->GetLinkedFonts(current_font_); | 240 fonts = font_link->GetLinkedFonts(current_font_); |
| 242 | 241 |
| 243 return fonts; | 242 return fonts; |
| 244 } | 243 } |
| 245 | 244 |
| 245 } // namespace internal |
| 246 |
| 247 std::vector<std::string> GetFallbackFontFamilies(std::string font_family) { |
| 248 internal::LinkedFontsIterator linked_fonts(Font(font_family, 10)); |
| 249 std::vector<std::string> fallback_fonts; |
| 250 Font current; |
| 251 while (linked_fonts.NextFont(¤t)) |
| 252 fallback_fonts.push_back(current.GetFontName()); |
| 253 return fallback_fonts; |
| 254 } |
| 255 |
| 246 } // namespace gfx | 256 } // namespace gfx |
| OLD | NEW |