Commit 7b688a1c authored by csilv@chromium.org's avatar csilv@chromium.org

dom-ui settings: Eliminate duplicate font names in WinChrome.

BUG=69155
TEST=Verify font names list does not contain duplicates in WinChrome.
Review URL: http://codereview.chromium.org/6277022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72822 0039d316-1c4b-4281-b951-d872f2087c98
parent d2ced047
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/dom_ui/options/font_settings_utils.h" #include "chrome/browser/dom_ui/options/font_settings_utils.h"
#include <set>
#include <string>
#include <windows.h> #include <windows.h>
#include "base/values.h" #include "base/values.h"
...@@ -12,22 +14,20 @@ static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW *logical_font, ...@@ -12,22 +14,20 @@ static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW *logical_font,
NEWTEXTMETRICEXW *physical_font, NEWTEXTMETRICEXW *physical_font,
DWORD font_type, DWORD font_type,
LPARAM lparam) { LPARAM lparam) {
ListValue* font_list = reinterpret_cast<ListValue*>(lparam); std::set<std::wstring>* font_names =
if (font_list) { reinterpret_cast<std::set<std::wstring>*>(lparam);
if (font_names) {
const LOGFONTW& lf = logical_font->elfLogFont; const LOGFONTW& lf = logical_font->elfLogFont;
if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') { if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') {
ListValue* font_item = new ListValue();
std::wstring face_name(lf.lfFaceName); std::wstring face_name(lf.lfFaceName);
font_item->Append(Value::CreateStringValue(face_name)); font_names->insert(face_name);
font_item->Append(Value::CreateStringValue(face_name));
font_list->Append(font_item);
} }
} }
return 1; return 1;
} }
ListValue* FontSettingsUtilities::GetFontsList() { ListValue* FontSettingsUtilities::GetFontsList() {
ListValue* font_list = new ListValue; std::set<std::wstring> font_names;
LOGFONTW logfont; LOGFONTW logfont;
memset(&logfont, 0, sizeof(logfont)); memset(&logfont, 0, sizeof(logfont));
...@@ -35,9 +35,17 @@ ListValue* FontSettingsUtilities::GetFontsList() { ...@@ -35,9 +35,17 @@ ListValue* FontSettingsUtilities::GetFontsList() {
HDC hdc = ::GetDC(NULL); HDC hdc = ::GetDC(NULL);
::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc,
(LPARAM)font_list, 0); (LPARAM)&font_names, 0);
::ReleaseDC(NULL, hdc); ::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));
font_item->Append(Value::CreateStringValue(*iter));
font_list->Append(font_item);
}
return font_list; return font_list;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment