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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/webui/options/font_settings_utils.h" 6 7 #include <set> 8 #include <string> 9 #include <windows.h> 10 11 #include "base/values.h" 12 13 static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW *logical_font, 14 NEWTEXTMETRICEXW *physical_font, 15 DWORD font_type, 16 LPARAM lparam) { 17 std::set<std::wstring>* font_names = 18 reinterpret_cast<std::set<std::wstring>*>(lparam); 19 if (font_names) { 20 const LOGFONTW& lf = logical_font->elfLogFont; 21 if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') { 22 std::wstring face_name(lf.lfFaceName); 23 font_names->insert(face_name); 24 } 25 } 26 return 1; 27 } 28 29 ListValue* FontSettingsUtilities::GetFontsList() { 30 std::set<std::wstring> font_names; 31 32 LOGFONTW logfont; 33 memset(&logfont, 0, sizeof(logfont)); 34 logfont.lfCharSet = DEFAULT_CHARSET; 35 36 HDC hdc = ::GetDC(NULL); 37 ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, 38 (LPARAM)&font_names, 0); 39 ::ReleaseDC(NULL, hdc); 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)); 46 font_item->Append(Value::CreateStringValue(*iter)); 47 font_list->Append(font_item); 48 } 49 return font_list; 50 } 51 52 void FontSettingsUtilities::ValidateSavedFonts(PrefService* prefs) { 53 // nothing to do for Windows. 54 } 55 56