Chromium Code Reviews| Index: chrome/browser/dom_ui/options/font_settings_utils_win.cc |
| =================================================================== |
| --- chrome/browser/dom_ui/options/font_settings_utils_win.cc (revision 72546) |
| +++ chrome/browser/dom_ui/options/font_settings_utils_win.cc (working copy) |
| @@ -1,9 +1,11 @@ |
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #include "chrome/browser/dom_ui/options/font_settings_utils.h" |
| +#include <set> |
| +#include <string> |
| #include <windows.h> |
| #include "base/values.h" |
| @@ -12,22 +14,20 @@ |
| NEWTEXTMETRICEXW *physical_font, |
| DWORD font_type, |
| LPARAM lparam) { |
| - ListValue* font_list = reinterpret_cast<ListValue*>(lparam); |
| - if (font_list) { |
| + std::set<std::wstring>* font_names = |
| + reinterpret_cast<std::set<std::wstring>*>(lparam); |
| + if (font_names) { |
| const LOGFONTW& lf = logical_font->elfLogFont; |
| if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') { |
| - ListValue* font_item = new ListValue(); |
| std::wstring face_name(lf.lfFaceName); |
| - font_item->Append(Value::CreateStringValue(face_name)); |
| - font_item->Append(Value::CreateStringValue(face_name)); |
| - font_list->Append(font_item); |
| + font_names->insert(face_name); |
| } |
| } |
| return 1; |
| } |
| ListValue* FontSettingsUtilities::GetFontsList() { |
| - ListValue* font_list = new ListValue; |
| + std::set<std::wstring> font_names; |
| LOGFONTW logfont; |
| memset(&logfont, 0, sizeof(logfont)); |
| @@ -35,9 +35,17 @@ |
| HDC hdc = ::GetDC(NULL); |
| ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, |
| - (LPARAM)font_list, 0); |
| + (LPARAM)&font_names, 0); |
| ::ReleaseDC(NULL, hdc); |
| + ListValue* font_list = new ListValue; |
| + std::set<std::wstring>::iterator iter; |
| + for (iter = font_names.begin(); iter != font_names.end(); iter++) { |
| + ListValue* font_item = new ListValue(); |
| + font_item->Append(Value::CreateStringValue(*iter)); |
|
James Hawkins
2011/01/27 01:15:51
Why Append() twice?
csilv
2011/01/27 01:18:23
The font_item is a list that contains two items, a
|
| + font_item->Append(Value::CreateStringValue(*iter)); |
| + font_list->Append(font_item); |
| + } |
| return font_list; |
| } |