Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/dom_ui/options/font_settings_utils.h" | 5 #include "chrome/browser/dom_ui/options/font_settings_utils.h" |
| 6 | 6 |
| 7 #include <set> | |
| 8 #include <string> | |
| 7 #include <windows.h> | 9 #include <windows.h> |
| 8 | 10 |
| 9 #include "base/values.h" | 11 #include "base/values.h" |
| 10 | 12 |
| 11 static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW *logical_font, | 13 static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW *logical_font, |
| 12 NEWTEXTMETRICEXW *physical_font, | 14 NEWTEXTMETRICEXW *physical_font, |
| 13 DWORD font_type, | 15 DWORD font_type, |
| 14 LPARAM lparam) { | 16 LPARAM lparam) { |
| 15 ListValue* font_list = reinterpret_cast<ListValue*>(lparam); | 17 std::set<std::wstring>* font_names = |
| 16 if (font_list) { | 18 reinterpret_cast<std::set<std::wstring>*>(lparam); |
| 19 if (font_names) { | |
| 17 const LOGFONTW& lf = logical_font->elfLogFont; | 20 const LOGFONTW& lf = logical_font->elfLogFont; |
| 18 if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') { | 21 if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') { |
| 19 ListValue* font_item = new ListValue(); | |
| 20 std::wstring face_name(lf.lfFaceName); | 22 std::wstring face_name(lf.lfFaceName); |
| 21 font_item->Append(Value::CreateStringValue(face_name)); | 23 font_names->insert(face_name); |
| 22 font_item->Append(Value::CreateStringValue(face_name)); | |
| 23 font_list->Append(font_item); | |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 return 1; | 26 return 1; |
| 27 } | 27 } |
| 28 | 28 |
| 29 ListValue* FontSettingsUtilities::GetFontsList() { | 29 ListValue* FontSettingsUtilities::GetFontsList() { |
| 30 ListValue* font_list = new ListValue; | 30 std::set<std::wstring> font_names; |
| 31 | 31 |
| 32 LOGFONTW logfont; | 32 LOGFONTW logfont; |
| 33 memset(&logfont, 0, sizeof(logfont)); | 33 memset(&logfont, 0, sizeof(logfont)); |
| 34 logfont.lfCharSet = DEFAULT_CHARSET; | 34 logfont.lfCharSet = DEFAULT_CHARSET; |
| 35 | 35 |
| 36 HDC hdc = ::GetDC(NULL); | 36 HDC hdc = ::GetDC(NULL); |
| 37 ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, | 37 ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, |
| 38 (LPARAM)font_list, 0); | 38 (LPARAM)&font_names, 0); |
| 39 ::ReleaseDC(NULL, hdc); | 39 ::ReleaseDC(NULL, hdc); |
| 40 | 40 |
| 41 ListValue* font_list = new ListValue; | |
| 42 std::set<std::wstring>::iterator iter; | |
| 43 for (iter = font_names.begin(); iter != font_names.end(); iter++) { | |
| 44 ListValue* font_item = new ListValue(); | |
| 45 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
| |
| 46 font_item->Append(Value::CreateStringValue(*iter)); | |
| 47 font_list->Append(font_item); | |
| 48 } | |
| 41 return font_list; | 49 return font_list; |
| 42 } | 50 } |
| 43 | 51 |
| 44 void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { | 52 void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { |
| 45 // nothing to do for Windows. | 53 // nothing to do for Windows. |
| 46 } | 54 } |
| 47 | 55 |
| OLD | NEW |