Commit e70ca0a2 authored by drott's avatar drott Committed by Commit bot

Filter font list, use Fontconfig and build on Ozone

Since we dropped support for rendering Type 1 fonts in Chrome, we should
filter the list of fonts that can be configured as defaults to only
display fonts that have the right font format, i.e. TrueType or CFF.

A a side effect, this allows us to build the font list enumeration for
ozone as well, as it is only dependent on Fontconfig after this CL, not
dependent on Pango anymore.

For backwards compability with the old implementation, we're adding
three Fontconfig alias families Sans, Serif and Monospace to the list,
since our default settings on Linux included the "Monospace" family for
the fixed width font.

BUG=630508,457307

Review-Url: https://codereview.chromium.org/2278143002
Cr-Commit-Position: refs/heads/master@{#414677}
parent bce76d10
......@@ -143,10 +143,7 @@ source_set("common") {
if (use_ozone) {
deps += [ "//ui/ozone" ]
} else {
sources -= [
"cursors/webcursor_ozone.cc",
"font_list_ozone.cc",
]
sources -= [ "cursors/webcursor_ozone.cc" ]
}
if (!use_aura || is_android) {
......@@ -157,15 +154,12 @@ source_set("common") {
sources -= [ "cursors/webcursor_aurax11.cc" ]
}
if (use_pango) {
configs += [ "//build/config/linux/pangocairo" ]
if (use_ozone) {
# If we're using pango, never use this ozone file (it was removed in all
# non-ozone cases above).
sources -= [ "font_list_ozone.cc" ]
}
} else {
sources -= [ "font_list_pango.cc" ]
if (is_linux) {
deps += [ "//build/linux:fontconfig" ]
}
if (is_mac || is_win || is_android) {
sources -= [ "font_list_fontconfig.cc" ]
}
if (enable_plugins) {
......
// Copyright 2016 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 "content/common/font_list.h"
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <fontconfig/fontconfig.h>
#include "base/values.h"
namespace content {
std::unique_ptr<FcPattern, decltype(&FcPatternDestroy)> CreateFormatPattern(
const char* format) {
std::unique_ptr<FcPattern, decltype(&FcPatternDestroy)> pattern(
FcPatternCreate(), FcPatternDestroy);
FcPatternAddBool(pattern.get(), FC_SCALABLE, FcTrue);
FcPatternAddString(pattern.get(), FC_FONTFORMAT,
reinterpret_cast<const FcChar8*>(format));
return pattern;
}
std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() {
std::unique_ptr<base::ListValue> font_list(new base::ListValue);
std::unique_ptr<FcObjectSet, decltype(&FcObjectSetDestroy)> object_set(
FcObjectSetBuild(FC_FAMILY, NULL), FcObjectSetDestroy);
std::set<std::string> sorted_families;
// See https://www.freetype.org/freetype2/docs/reference/ft2-font_formats.html
// for the list of possible formats.
const char* allowed_formats[] = { "TrueType", "CFF" };
for (size_t i = 0; i < arraysize(allowed_formats); ++i) {
auto format_pattern = CreateFormatPattern(allowed_formats[i]);
std::unique_ptr<FcFontSet, decltype(&FcFontSetDestroy)> fontset(
FcFontList(0, format_pattern.get(), object_set.get()),
FcFontSetDestroy);
for (int j = 0; j < fontset->nfont; ++j) {
char* family_string;
FcPatternGetString(fontset->fonts[j], FC_FAMILY, 0,
reinterpret_cast<FcChar8**>(&family_string));
sorted_families.insert(family_string);
}
}
// For backwards compatibility with the older pango implementation, add the
// three Fontconfig aliases that pango added. Our linux default settings for
// fixed-width was "Monospace". If we remove that, this entry is not found in
// the list anymore, see also:
// https://git.gnome.org/browse/pango/tree/pango/pangofc-fontmap.c?h=1.40.1#n1351
sorted_families.insert("Monospace");
sorted_families.insert("Sans");
sorted_families.insert("Serif");
for (const auto& family : sorted_families) {
std::unique_ptr<base::ListValue> font_item(new base::ListValue());
font_item->AppendString(family);
font_item->AppendString(family); // localized name.
// TODO(yusukes): Support localized family names.
font_list->Append(std::move(font_item));
}
return font_list;
}
} // namespace content
// Copyright 2013 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 "content/common/font_list.h"
#include "base/values.h"
namespace content {
std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() {
return std::unique_ptr<base::ListValue>(new base::ListValue);
}
} // namespace content
// 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 "content/common/font_list.h"
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <set>
#include <string>
#include <utility>
#include "base/values.h"
namespace content {
std::unique_ptr<base::ListValue> GetFontList_SlowBlocking() {
std::unique_ptr<base::ListValue> font_list(new base::ListValue);
PangoFontMap* font_map = ::pango_cairo_font_map_get_default();
PangoFontFamily** families = NULL;
int num_families = 0;
::pango_font_map_list_families(font_map, &families, &num_families);
std::set<std::string> sorted_families;
for (int i = 0; i < num_families; i++) {
sorted_families.insert(::pango_font_family_get_name(families[i]));
}
g_free(families);
for (std::set<std::string>::const_iterator iter = sorted_families.begin();
iter != sorted_families.end(); ++iter) {
std::unique_ptr<base::ListValue> font_item(new base::ListValue());
font_item->AppendString(*iter);
font_item->AppendString(*iter); // localized name.
// TODO(yusukes): Support localized family names.
font_list->Append(std::move(font_item));
}
return font_list;
}
} // namespace content
......@@ -324,9 +324,8 @@
'common/font_list.cc',
'common/font_list.h',
'common/font_list_android.cc',
'common/font_list_fontconfig.cc',
'common/font_list_mac.mm',
'common/font_list_ozone.cc',
'common/font_list_pango.cc',
'common/font_list_win.cc',
'common/frame_message_enums.h',
'common/frame_messages.h',
......@@ -578,14 +577,6 @@
'content.gyp:common_aidl',
],
}],
['use_pango == 1', {
'dependencies': [
'../build/linux/system.gyp:pangocairo',
],
'sources!': [
'common/font_list_ozone.cc',
],
}],
['use_x11 == 1', {
'include_dirs': [
'<(DEPTH)/third_party/khronos',
......@@ -652,7 +643,6 @@
}, { # use_ozone!=1
'sources!': [
'common/cursors/webcursor_ozone.cc',
'common/font_list_ozone.cc',
'common/gpu/gpu_memory_buffer_factory_ozone.cc',
'common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.cc',
'common/gpu/gpu_memory_buffer_factory_ozone_native_pixmap.h',
......
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