Revert of Use DirectWrite to populate list of avalible fonts (https://codereview.chromium.org/354023007/)
Reason for revert:
Uses a Vista+ only API
Original issue's description:
> Use DirectWrite to populate list of avalible fonts
>
> Use the DirectWrite API to populate the list of avalible fonts in
> settings when DirectWrite is enabled. False back on GDI on failure.
> As GDI and DirectWrite handle font family variants and alternate names
> differently this ensures that all fonts presented in the list are valid
> options that can be rendered.
>
> [email protected], [email protected]
> BUG=367702, 373494
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=280719
[email protected],[email protected],[email protected],[email protected]
NOTREECHECKS=true
NOTRY=true
BUG=367702, 373494
Review URL: https://codereview.chromium.org/368523002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280769 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/common/font_list_win.cc b/content/common/font_list_win.cc
index 4e662d06..bc6c1dc 100644
--- a/content/common/font_list_win.cc
+++ b/content/common/font_list_win.cc
@@ -5,14 +5,11 @@
#include "content/common/font_list.h"
#include <windows.h>
-#include <dwrite.h>
#include <set>
#include "base/strings/string16.h"
#include "base/values.h"
-#include "base/win/scoped_comptr.h"
-#include "content/common/sandbox_win.h"
namespace content {
@@ -32,7 +29,7 @@
return 1;
}
-static void GetFontListInternal_GDI(base::ListValue* font_list) {
+scoped_ptr<base::ListValue> GetFontList_SlowBlocking() {
std::set<base::string16> font_names;
LOGFONTW logfont;
@@ -44,6 +41,7 @@
(LPARAM)&font_names, 0);
::ReleaseDC(NULL, hdc);
+ scoped_ptr<base::ListValue> font_list(new base::ListValue);
std::set<base::string16>::iterator iter;
for (iter = font_names.begin(); iter != font_names.end(); ++iter) {
base::ListValue* font_item = new base::ListValue();
@@ -51,92 +49,6 @@
font_item->Append(new base::StringValue(*iter));
font_list->Append(font_item);
}
-}
-
-static void AddLocalizedFontFamily(base::ListValue* font_list,
- IDWriteFontFamily* font_family,
- wchar_t* user_locale) {
- base::win::ScopedComPtr<IDWriteLocalizedStrings> family_names;
- if (SUCCEEDED(font_family->GetFamilyNames(family_names.Receive()))) {
- UINT32 index = 0;
- BOOL exists = false;
-
- // Try to get name of font in the users locale first, failing that fall back
- // on US English and then the first name listed.
- family_names->FindLocaleName(user_locale, &index, &exists);
- if (!exists)
- family_names->FindLocaleName(L"en-us", &index, &exists);
- if (!exists)
- index = 0;
-
- UINT32 len = 0;
- if (SUCCEEDED(family_names->GetStringLength(index, &len))) {
- wchar_t* name = new wchar_t[len + 1];
- if (name) {
- if (SUCCEEDED(family_names->GetString(index, name, len + 1)) &&
- name[0] != '@') {
- base::ListValue* font_item = new base::ListValue();
- // First field is the name displayed to the user, second is the name
- // used internally and passed to the font system. For fonts the
- // localized name is used for both.
- font_item->Append(new base::StringValue(name));
- font_item->Append(new base::StringValue(name));
- font_list->Append(font_item);
- }
- delete[] name;
- }
- }
- }
-}
-
-static base::win::ScopedComPtr<IDWriteFactory> CreateDirectWriteFactory() {
- base::win::ScopedComPtr<IDWriteFactory> factory;
- typedef decltype(DWriteCreateFactory) * DWriteCreateFactoryProc;
- HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
- if (dwrite_dll) {
- DWriteCreateFactoryProc dwrite_create_factory_proc =
- reinterpret_cast<DWriteCreateFactoryProc>(
- GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
- if (dwrite_create_factory_proc) {
- dwrite_create_factory_proc(
- DWRITE_FACTORY_TYPE_ISOLATED,
- __uuidof(IDWriteFactory),
- reinterpret_cast<IUnknown**>(factory.Receive()));
- }
- }
- return factory;
-}
-
-static void GetFontListInternal_DirectWrite(base::ListValue* font_list) {
- wchar_t user_locale[LOCALE_NAME_MAX_LENGTH];
- GetUserDefaultLocaleName(user_locale, LOCALE_NAME_MAX_LENGTH);
-
- base::win::ScopedComPtr<IDWriteFactory> factory = CreateDirectWriteFactory();
-
- base::win::ScopedComPtr<IDWriteFontCollection> font_collection;
- BOOL check_for_updates = false;
- if (factory && SUCCEEDED(factory->GetSystemFontCollection(
- font_collection.Receive(), check_for_updates))) {
- UINT32 family_count = font_collection->GetFontFamilyCount();
- for (UINT32 i = 0; i < family_count; i++) {
- base::win::ScopedComPtr<IDWriteFontFamily> font_family;
- if (SUCCEEDED(font_collection->GetFontFamily(i, font_family.Receive())))
- AddLocalizedFontFamily(font_list, font_family, user_locale);
- }
- }
-}
-
-scoped_ptr<base::ListValue> GetFontList_SlowBlocking() {
- scoped_ptr<base::ListValue> font_list(new base::ListValue);
-
- if (ShouldUseDirectWrite())
- GetFontListInternal_DirectWrite(font_list.get());
-
- // Fallback on GDI if DirectWrite isn't enabled or if it failed to populate
- // the font list.
- if (font_list->GetSize() == 0)
- GetFontListInternal_GDI(font_list.get());
-
return font_list.Pass();
}