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
// 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 @@ static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW *logical_font,
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 @@ ListValue* FontSettingsUtilities::GetFontsList() {
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));
font_item->Append(Value::CreateStringValue(*iter));
font_list->Append(font_item);
}
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