[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 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 "content/common/font_list.h" |
| 6 | |
| 7 | #include <windows.h> |
| 8 | |
| 9 | #include <set> |
| 10 | |
[email protected] | 30fe1f9 | 2013-06-12 16:34:34 | [diff] [blame] | 11 | #include "base/strings/string16.h" |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 12 | #include "base/values.h" |
| 13 | |
| 14 | namespace content { |
| 15 | |
| 16 | static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXW* logical_font, |
| 17 | NEWTEXTMETRICEXW* physical_font, |
| 18 | DWORD font_type, |
| 19 | LPARAM lparam) { |
| 20 | std::set<string16>* font_names = |
| 21 | reinterpret_cast<std::set<string16>*>(lparam); |
| 22 | if (font_names) { |
| 23 | const LOGFONTW& lf = logical_font->elfLogFont; |
| 24 | if (lf.lfFaceName[0] && lf.lfFaceName[0] != '@') { |
| 25 | string16 face_name(lf.lfFaceName); |
| 26 | font_names->insert(face_name); |
| 27 | } |
| 28 | } |
| 29 | return 1; |
| 30 | } |
| 31 | |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 32 | scoped_ptr<base::ListValue> GetFontList_SlowBlocking() { |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 33 | std::set<string16> font_names; |
| 34 | |
| 35 | LOGFONTW logfont; |
| 36 | memset(&logfont, 0, sizeof(logfont)); |
| 37 | logfont.lfCharSet = DEFAULT_CHARSET; |
| 38 | |
| 39 | HDC hdc = ::GetDC(NULL); |
| 40 | ::EnumFontFamiliesExW(hdc, &logfont, (FONTENUMPROCW)&EnumFontFamExProc, |
| 41 | (LPARAM)&font_names, 0); |
| 42 | ::ReleaseDC(NULL, hdc); |
| 43 | |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 44 | scoped_ptr<base::ListValue> font_list(new base::ListValue); |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 45 | std::set<string16>::iterator iter; |
[email protected] | 0cd50aa | 2013-02-12 22:28:01 | [diff] [blame] | 46 | for (iter = font_names.begin(); iter != font_names.end(); ++iter) { |
| 47 | base::ListValue* font_item = new base::ListValue(); |
| 48 | font_item->Append(new base::StringValue(*iter)); |
| 49 | font_item->Append(new base::StringValue(*iter)); |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 50 | font_list->Append(font_item); |
| 51 | } |
[email protected] | ec810db | 2012-02-29 19:20:14 | [diff] [blame] | 52 | return font_list.Pass(); |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } // namespace content |