|
|
|
@@ -0,0 +1,572 @@
|
|
|
|
|
From: uazo <uazo@users.noreply.github.com>
|
|
|
|
|
Date: Wed, 3 Apr 2024 13:32:27 +0000
|
|
|
|
|
Subject: Emoji Fonts fingerprinting mitigation 01-02
|
|
|
|
|
|
|
|
|
|
Replaces the platform emoji font with the one embedded in the apk.
|
|
|
|
|
|
|
|
|
|
Require: Fonts-fingerprinting-mitigation.patch
|
|
|
|
|
License: GPL-2.0-or-later - https://spdx.org/licenses/GPL-2.0-or-later.html
|
|
|
|
|
---
|
|
|
|
|
chrome/android/BUILD.gn | 1 +
|
|
|
|
|
content/browser/v8_snapshot_files.cc | 9 ++
|
|
|
|
|
.../public/common/content_descriptor_keys.cc | 8 ++
|
|
|
|
|
.../public/common/content_descriptor_keys.h | 5 ++
|
|
|
|
|
...renderer_main_platform_delegate_android.cc | 88 +++++++++++++++++++
|
|
|
|
|
.../platform/fonts/skia/android/BUILD.gn | 17 ++++
|
|
|
|
|
.../fonts/skia/android/cromite_fonts.xml | 16 ++++
|
|
|
|
|
.../platform/fonts/skia/font_cache_skia.cc | 15 ++++
|
|
|
|
|
.../skia/include/ports/SkFontMgr_android.h | 30 ++++++-
|
|
|
|
|
.../skia/src/ports/SkFontMgr_android.cpp | 46 +++++++---
|
|
|
|
|
.../src/ports/SkFontMgr_android_parser.cpp | 37 +++++---
|
|
|
|
|
.../skia/src/ports/SkFontMgr_android_parser.h | 2 +
|
|
|
|
|
12 files changed, 250 insertions(+), 24 deletions(-)
|
|
|
|
|
create mode 100644 third_party/blink/renderer/platform/fonts/skia/android/BUILD.gn
|
|
|
|
|
create mode 100644 third_party/blink/renderer/platform/fonts/skia/android/cromite_fonts.xml
|
|
|
|
|
|
|
|
|
|
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
|
|
|
|
|
--- a/chrome/android/BUILD.gn
|
|
|
|
|
+++ b/chrome/android/BUILD.gn
|
|
|
|
|
@@ -2161,6 +2161,7 @@ if (current_toolchain == default_toolchain) {
|
|
|
|
|
|
|
|
|
|
java_group("chrome_public_non_pak_assets") {
|
|
|
|
|
deps = [
|
|
|
|
|
+ "//third_party/blink/renderer/platform/fonts/skia/android:font_assets",
|
|
|
|
|
"//chrome/android/webapk/libs/runtime_library:runtime_library_assets",
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
diff --git a/content/browser/v8_snapshot_files.cc b/content/browser/v8_snapshot_files.cc
|
|
|
|
|
--- a/content/browser/v8_snapshot_files.cc
|
|
|
|
|
+++ b/content/browser/v8_snapshot_files.cc
|
|
|
|
|
@@ -22,12 +22,21 @@ GetV8SnapshotFilesToPreload() {
|
|
|
|
|
base::FilePath(FILE_PATH_LITERAL("snapshot_blob.bin"));
|
|
|
|
|
#endif
|
|
|
|
|
#elif BUILDFLAG(IS_ANDROID)
|
|
|
|
|
+ files[kFontsXmlDataDescriptor] =
|
|
|
|
|
+ base::FilePath(FILE_PATH_LITERAL("assets/fonts/cromite_fonts.xml"));
|
|
|
|
|
+ files[kNotoColorEmonjiDataDescriptor] =
|
|
|
|
|
+ base::FilePath(FILE_PATH_LITERAL("assets/fonts/NotoColorEmoji.ttf"));
|
|
|
|
|
+ files[kNotoSansSymbolsRegularSubsettedDataDescriptor] =
|
|
|
|
|
+ base::FilePath(FILE_PATH_LITERAL("assets/fonts/NotoSansSymbols-Regular-Subsetted.ttf"));
|
|
|
|
|
+ files[kNotoSansSymbolsRegularSubsetted2DataDescriptor] =
|
|
|
|
|
+ base::FilePath(FILE_PATH_LITERAL("assets/fonts/NotoSansSymbols-Regular-Subsetted2.ttf"));
|
|
|
|
|
#if !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
|
|
|
|
|
files[kV8Snapshot64DataDescriptor] =
|
|
|
|
|
base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_64.bin"));
|
|
|
|
|
files[kV8Snapshot32DataDescriptor] =
|
|
|
|
|
base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_32.bin"));
|
|
|
|
|
#elif BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
|
|
|
|
|
+#error "Check this patch"
|
|
|
|
|
// For USE_V8_CONTEXT_SNAPSHOT, the renderer reads the files directly.
|
|
|
|
|
return {};
|
|
|
|
|
#endif
|
|
|
|
|
diff --git a/content/public/common/content_descriptor_keys.cc b/content/public/common/content_descriptor_keys.cc
|
|
|
|
|
--- a/content/public/common/content_descriptor_keys.cc
|
|
|
|
|
+++ b/content/public/common/content_descriptor_keys.cc
|
|
|
|
|
@@ -6,6 +6,14 @@
|
|
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
|
|
|
|
|
|
+const char kFontsXmlDataDescriptor[] = "fonts_xml";
|
|
|
|
|
+
|
|
|
|
|
+const char kNotoColorEmonjiDataDescriptor[] = "noto_color_emonji_data";
|
|
|
|
|
+
|
|
|
|
|
+const char kNotoSansSymbolsRegularSubsettedDataDescriptor[] = "notosanssymbols_regular_subsetted";
|
|
|
|
|
+
|
|
|
|
|
+const char kNotoSansSymbolsRegularSubsetted2DataDescriptor[] = "notosanssymbols_regular_subsetted2";
|
|
|
|
|
+
|
|
|
|
|
const char kV8SnapshotDataDescriptor[] = "v8_snapshot_data";
|
|
|
|
|
|
|
|
|
|
const char kV8Snapshot32DataDescriptor[] = "v8_snapshot_32_data";
|
|
|
|
|
diff --git a/content/public/common/content_descriptor_keys.h b/content/public/common/content_descriptor_keys.h
|
|
|
|
|
--- a/content/public/common/content_descriptor_keys.h
|
|
|
|
|
+++ b/content/public/common/content_descriptor_keys.h
|
|
|
|
|
@@ -10,6 +10,11 @@ namespace content {
|
|
|
|
|
// This is a list of global descriptor keys to be used with the
|
|
|
|
|
// base::FileDescriptorStore object (see base/file_descriptor_store.h)
|
|
|
|
|
|
|
|
|
|
+extern const char kFontsXmlDataDescriptor[];
|
|
|
|
|
+extern const char kNotoColorEmonjiDataDescriptor[];
|
|
|
|
|
+extern const char kNotoSansSymbolsRegularSubsettedDataDescriptor[];
|
|
|
|
|
+extern const char kNotoSansSymbolsRegularSubsetted2DataDescriptor[];
|
|
|
|
|
+
|
|
|
|
|
extern const char kV8SnapshotDataDescriptor[];
|
|
|
|
|
extern const char kV8Snapshot32DataDescriptor[];
|
|
|
|
|
extern const char kV8Snapshot64DataDescriptor[];
|
|
|
|
|
diff --git a/content/renderer/renderer_main_platform_delegate_android.cc b/content/renderer/renderer_main_platform_delegate_android.cc
|
|
|
|
|
--- a/content/renderer/renderer_main_platform_delegate_android.cc
|
|
|
|
|
+++ b/content/renderer/renderer_main_platform_delegate_android.cc
|
|
|
|
|
@@ -19,6 +19,93 @@
|
|
|
|
|
#include "sandbox/policy/sandbox_type.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+#include "base/path_service.h"
|
|
|
|
|
+#include "base/base_paths_android.h"
|
|
|
|
|
+#include "base/file_descriptor_store.h"
|
|
|
|
|
+#include "base/strings/string_number_conversions.h"
|
|
|
|
|
+#include "base/files/file_path.h"
|
|
|
|
|
+#include "content/public/common/content_descriptor_keys.h"
|
|
|
|
|
+#include "skia/ext/font_utils.h"
|
|
|
|
|
+#include "third_party/skia/include/core/SkFontMgr.h"
|
|
|
|
|
+#include "third_party/skia/include/ports/SkFontMgr_android.h"
|
|
|
|
|
+#include "third_party/blink/public/platform/web_font_render_style.h"
|
|
|
|
|
+
|
|
|
|
|
+namespace {
|
|
|
|
|
+ void InitializeCustomFonts() {
|
|
|
|
|
+ base::FileDescriptorStore& file_descriptor_store =
|
|
|
|
|
+ base::FileDescriptorStore::GetInstance();
|
|
|
|
|
+
|
|
|
|
|
+ base::MemoryMappedFile::Region fd_fonts_region;
|
|
|
|
|
+ base::ScopedFD fd_fonts = file_descriptor_store.MaybeTakeFD(
|
|
|
|
|
+ content::kFontsXmlDataDescriptor, &fd_fonts_region);
|
|
|
|
|
+ if (!fd_fonts.is_valid()) {
|
|
|
|
|
+ LOG(ERROR) << "FontsXmlDataDescriptor not found";
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ base::MemoryMappedFile::Region fd_noto_font_region;
|
|
|
|
|
+ base::ScopedFD fd_noto_font = file_descriptor_store.MaybeTakeFD(
|
|
|
|
|
+ content::kNotoColorEmonjiDataDescriptor, &fd_noto_font_region);
|
|
|
|
|
+ if (!fd_noto_font.is_valid()) {
|
|
|
|
|
+ LOG(ERROR) << "NotoColorEmonjiDataDescriptor not found";
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ base::MemoryMappedFile::Region fd_notosanssymbols_regular_subsetted_region;
|
|
|
|
|
+ base::ScopedFD fd_notosanssymbols_regular_subsetted_font = file_descriptor_store.MaybeTakeFD(
|
|
|
|
|
+ content::kNotoSansSymbolsRegularSubsettedDataDescriptor, &fd_notosanssymbols_regular_subsetted_region);
|
|
|
|
|
+ if (!fd_notosanssymbols_regular_subsetted_font.is_valid()) {
|
|
|
|
|
+ LOG(ERROR) << "kNotoSansSymbolsRegularSubsettedDataDescriptor not found";
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ base::MemoryMappedFile::Region fd_notosanssymbols_regular_subsetted2_region;
|
|
|
|
|
+ base::ScopedFD fd_notosanssymbols_regular_subsetted2_font = file_descriptor_store.MaybeTakeFD(
|
|
|
|
|
+ content::kNotoSansSymbolsRegularSubsetted2DataDescriptor, &fd_notosanssymbols_regular_subsetted2_region);
|
|
|
|
|
+ if (!fd_notosanssymbols_regular_subsetted2_font.is_valid()) {
|
|
|
|
|
+ DLOG(ERROR) << "kNotoSansSymbolsRegularSubsetted2DataDescriptor not found";
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ std::string kFontsXmlDataDescriptor =
|
|
|
|
|
+ "#" + std::string(content::kFontsXmlDataDescriptor);
|
|
|
|
|
+ std::string kNotoColorEmonjiDataDescriptor =
|
|
|
|
|
+ "#" + std::string(content::kNotoColorEmonjiDataDescriptor);
|
|
|
|
|
+ std::string kNotoSansSymbolsRegularSubsettedDataDescriptor =
|
|
|
|
|
+ "#" + std::string(content::kNotoSansSymbolsRegularSubsettedDataDescriptor);
|
|
|
|
|
+ std::string kNotoSansSymbolsRegularSubsetted2DataDescriptor =
|
|
|
|
|
+ "#" + std::string(content::kNotoSansSymbolsRegularSubsetted2DataDescriptor);
|
|
|
|
|
+
|
|
|
|
|
+ std::string android_fonts_dir = "use_fd";
|
|
|
|
|
+ std::string font_config = kFontsXmlDataDescriptor;
|
|
|
|
|
+
|
|
|
|
|
+ auto custom = std::make_unique<SkFontMgr_Android_CustomFonts>();
|
|
|
|
|
+ custom->fSystemFontUse =
|
|
|
|
|
+ SkFontMgr_Android_CustomFonts::SystemFontUse::kPreferCustom;
|
|
|
|
|
+ custom->fBasePath = android_fonts_dir.c_str();
|
|
|
|
|
+ custom->fFontsXml = font_config.c_str();
|
|
|
|
|
+ custom->fFallbackFontsXml = font_config.c_str();
|
|
|
|
|
+ custom->fIsolated = true;
|
|
|
|
|
+
|
|
|
|
|
+ custom->add_platform_file(
|
|
|
|
|
+ kFontsXmlDataDescriptor, fd_fonts.release(),
|
|
|
|
|
+ fd_fonts_region.offset, fd_fonts_region.size);
|
|
|
|
|
+ custom->add_platform_file(
|
|
|
|
|
+ kNotoColorEmonjiDataDescriptor, fd_noto_font.release(),
|
|
|
|
|
+ fd_noto_font_region.offset, fd_noto_font_region.size);
|
|
|
|
|
+ custom->add_platform_file(
|
|
|
|
|
+ kNotoSansSymbolsRegularSubsettedDataDescriptor, fd_notosanssymbols_regular_subsetted_font.release(),
|
|
|
|
|
+ fd_notosanssymbols_regular_subsetted_region.offset, fd_notosanssymbols_regular_subsetted_region.size);
|
|
|
|
|
+ custom->add_platform_file(
|
|
|
|
|
+ kNotoSansSymbolsRegularSubsetted2DataDescriptor, fd_notosanssymbols_regular_subsetted2_font.release(),
|
|
|
|
|
+ fd_notosanssymbols_regular_subsetted2_region.offset, fd_notosanssymbols_regular_subsetted2_region.size);
|
|
|
|
|
+
|
|
|
|
|
+ sk_sp<SkFontMgr> skia_font_manager =
|
|
|
|
|
+ SkFontMgr_New_Android(std::move(custom));
|
|
|
|
|
+ skia::OverrideDefaultSkFontMgr(std::move(skia_font_manager));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
namespace content {
|
|
|
|
|
|
|
|
|
|
RendererMainPlatformDelegate::RendererMainPlatformDelegate(
|
|
|
|
|
@@ -28,6 +115,7 @@ RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RendererMainPlatformDelegate::PlatformInitialize() {
|
|
|
|
|
+ InitializeCustomFonts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RendererMainPlatformDelegate::PlatformUninitialize() {
|
|
|
|
|
diff --git a/third_party/blink/renderer/platform/fonts/skia/android/BUILD.gn b/third_party/blink/renderer/platform/fonts/skia/android/BUILD.gn
|
|
|
|
|
new file mode 100644
|
|
|
|
|
--- /dev/null
|
|
|
|
|
+++ b/third_party/blink/renderer/platform/fonts/skia/android/BUILD.gn
|
|
|
|
|
@@ -0,0 +1,17 @@
|
|
|
|
|
+import("//build/config/android/rules.gni")
|
|
|
|
|
+
|
|
|
|
|
+android_assets("font_assets") {
|
|
|
|
|
+ renaming_sources = [
|
|
|
|
|
+ "cromite_fonts.xml",
|
|
|
|
|
+ "NotoColorEmoji.ttf",
|
|
|
|
|
+ "NotoSansSymbols-Regular-Subsetted.ttf",
|
|
|
|
|
+ "NotoSansSymbols-Regular-Subsetted2.ttf",
|
|
|
|
|
+ ]
|
|
|
|
|
+ renaming_destinations = [
|
|
|
|
|
+ "fonts/cromite_fonts.xml",
|
|
|
|
|
+ "fonts/NotoColorEmoji.ttf",
|
|
|
|
|
+ "fonts/NotoSansSymbols-Regular-Subsetted.ttf",
|
|
|
|
|
+ "fonts/NotoSansSymbols-Regular-Subsetted2.ttf",
|
|
|
|
|
+ ]
|
|
|
|
|
+ disable_compression = true
|
|
|
|
|
+}
|
|
|
|
|
diff --git a/third_party/blink/renderer/platform/fonts/skia/android/cromite_fonts.xml b/third_party/blink/renderer/platform/fonts/skia/android/cromite_fonts.xml
|
|
|
|
|
new file mode 100644
|
|
|
|
|
--- /dev/null
|
|
|
|
|
+++ b/third_party/blink/renderer/platform/fonts/skia/android/cromite_fonts.xml
|
|
|
|
|
@@ -0,0 +1,16 @@
|
|
|
|
|
+<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
|
+<familyset version="23">
|
|
|
|
|
+ <!-- fallback fonts -->
|
|
|
|
|
+ <family>
|
|
|
|
|
+ <font weight="400" style="normal">#notosanssymbols_regular_subsetted</font>
|
|
|
|
|
+ </family>
|
|
|
|
|
+ <family lang="und-Zsye">
|
|
|
|
|
+ <font weight="400" style="normal">#noto_color_emonji_data</font>
|
|
|
|
|
+ </family>
|
|
|
|
|
+ <family lang="und-Zsye" ttfVersion="1.0.11.0">
|
|
|
|
|
+ <font weight="400" style="normal">#noto_color_emonji_data</font>
|
|
|
|
|
+ </family>
|
|
|
|
|
+ <family lang="und-Zsym">
|
|
|
|
|
+ <font weight="400" style="normal">#notosanssymbols_regular_subsetted2</font>
|
|
|
|
|
+ </family>
|
|
|
|
|
+</familyset>
|
|
|
|
|
diff --git a/third_party/blink/renderer/platform/fonts/skia/font_cache_skia.cc b/third_party/blink/renderer/platform/fonts/skia/font_cache_skia.cc
|
|
|
|
|
--- a/third_party/blink/renderer/platform/fonts/skia/font_cache_skia.cc
|
|
|
|
|
+++ b/third_party/blink/renderer/platform/fonts/skia/font_cache_skia.cc
|
|
|
|
|
@@ -77,6 +77,21 @@ sk_sp<SkTypeface> ReturnIfAllowed(sk_sp<SkTypeface> typeface, const std::string&
|
|
|
|
|
if (!check_fonts) return typeface;
|
|
|
|
|
if (!typeface) return nullptr;
|
|
|
|
|
|
|
|
|
|
+#if BUILDFLAG(IS_ANDROID)
|
|
|
|
|
+ // check for synthetic family names (used for emoji)
|
|
|
|
|
+ if (!name.empty() &&
|
|
|
|
|
+ base::EndsWith(name, "##fallback", base::CompareCase::INSENSITIVE_ASCII)) {
|
|
|
|
|
+ SkString fallback_postscript_name;
|
|
|
|
|
+ typeface->getPostScriptName(&fallback_postscript_name);
|
|
|
|
|
+ const AtomicString& family = ToAtomicString(fallback_postscript_name);
|
|
|
|
|
+ std::string postscript_name = family.Utf8();
|
|
|
|
|
+ if (postscript_name != "NotoColorEmoji"
|
|
|
|
|
+ && postscript_name != "NotoSansSymbols") {
|
|
|
|
|
+ DLOG(INFO) << "--Font " << postscript_name << " not allowed";
|
|
|
|
|
+ return nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+#endif
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
|
SkString skia_family_name;
|
|
|
|
|
skia::DWriteFontTypeface_GetGDIFamilyName(typeface.get(), &skia_family_name);
|
|
|
|
|
diff --git a/third_party/skia/include/ports/SkFontMgr_android.h b/third_party/skia/include/ports/SkFontMgr_android.h
|
|
|
|
|
--- a/third_party/skia/include/ports/SkFontMgr_android.h
|
|
|
|
|
+++ b/third_party/skia/include/ports/SkFontMgr_android.h
|
|
|
|
|
@@ -9,6 +9,8 @@
|
|
|
|
|
#define SkFontMgr_android_DEFINED
|
|
|
|
|
|
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
|
+#include "include/core/SkStream.h"
|
|
|
|
|
+#include "src/core/SkTHash.h"
|
|
|
|
|
|
|
|
|
|
class SkFontMgr;
|
|
|
|
|
|
|
|
|
|
@@ -37,9 +39,35 @@ struct SkFontMgr_Android_CustomFonts {
|
|
|
|
|
* system IO resources on initialization.
|
|
|
|
|
*/
|
|
|
|
|
bool fIsolated;
|
|
|
|
|
+
|
|
|
|
|
+ struct SkFontMgr_Android_CustomFonts_MappedData {
|
|
|
|
|
+ int fd;
|
|
|
|
|
+ int64_t offset;
|
|
|
|
|
+ size_t size;
|
|
|
|
|
+ };
|
|
|
|
|
+ skia_private::THashMap<std::string,
|
|
|
|
|
+ SkFontMgr_Android_CustomFonts_MappedData> platform_file_map;
|
|
|
|
|
+
|
|
|
|
|
+ void add_platform_file(std::string key, int fd, int64_t offset, size_t size) {
|
|
|
|
|
+ SkFontMgr_Android_CustomFonts_MappedData data = {fd, offset, size};
|
|
|
|
|
+ platform_file_map.set(key, std::move(data));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ std::unique_ptr<SkStreamAsset> getPlatformFile(const char* filename) const {
|
|
|
|
|
+ const auto* it = platform_file_map.find(filename);
|
|
|
|
|
+ if (!it) {
|
|
|
|
|
+ return nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+ auto whole_data = SkData::MakeFromFD(it->fd);
|
|
|
|
|
+ auto data = SkData::MakeSubset(whole_data.get(), it->offset, it->size);
|
|
|
|
|
+ if (!data) {
|
|
|
|
|
+ return nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+ return std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data)));
|
|
|
|
|
+ }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Create a font manager for Android. If 'custom' is NULL, use only system fonts. */
|
|
|
|
|
-SK_API sk_sp<SkFontMgr> SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom);
|
|
|
|
|
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_Android(std::unique_ptr<SkFontMgr_Android_CustomFonts> custom);
|
|
|
|
|
|
|
|
|
|
#endif // SkFontMgr_android_DEFINED
|
|
|
|
|
diff --git a/third_party/skia/src/ports/SkFontMgr_android.cpp b/third_party/skia/src/ports/SkFontMgr_android.cpp
|
|
|
|
|
--- a/third_party/skia/src/ports/SkFontMgr_android.cpp
|
|
|
|
|
+++ b/third_party/skia/src/ports/SkFontMgr_android.cpp
|
|
|
|
|
@@ -65,20 +65,25 @@ public:
|
|
|
|
|
bool isFixedPitch,
|
|
|
|
|
const SkString& familyName,
|
|
|
|
|
const TArray<SkLanguage, true>& lang,
|
|
|
|
|
- FontVariant variantStyle)
|
|
|
|
|
+ FontVariant variantStyle,
|
|
|
|
|
+ const SkFontMgr_Android_CustomFonts* custom)
|
|
|
|
|
: INHERITED(style, isFixedPitch, familyName)
|
|
|
|
|
, fPathName(pathName)
|
|
|
|
|
, fIndex(index)
|
|
|
|
|
, fAxes(axes, axesCount)
|
|
|
|
|
, fLang(lang)
|
|
|
|
|
, fVariantStyle(variantStyle)
|
|
|
|
|
- , fFile(cacheFontFiles ? sk_fopen(fPathName.c_str(), kRead_SkFILE_Flag) : nullptr) {
|
|
|
|
|
- if (cacheFontFiles) {
|
|
|
|
|
+ , fFile(cacheFontFiles ? sk_fopen(fPathName.c_str(), kRead_SkFILE_Flag) : nullptr)
|
|
|
|
|
+ , custom_(custom) {
|
|
|
|
|
+ if (cacheFontFiles && !custom_) {
|
|
|
|
|
SkASSERT(fFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<SkStreamAsset> makeStream() const {
|
|
|
|
|
+ if (custom_ && fPathName.startsWith('#')) {
|
|
|
|
|
+ return custom_->getPlatformFile(fPathName.c_str());
|
|
|
|
|
+ }
|
|
|
|
|
if (fFile) {
|
|
|
|
|
sk_sp<SkData> data(SkData::MakeFromFILE(fFile));
|
|
|
|
|
return data ? std::make_unique<SkMemoryStream>(std::move(data)) : nullptr;
|
|
|
|
|
@@ -116,7 +121,7 @@ public:
|
|
|
|
|
this->isFixedPitch(),
|
|
|
|
|
fFamilyName,
|
|
|
|
|
fLang,
|
|
|
|
|
- fVariantStyle);
|
|
|
|
|
+ fVariantStyle, custom_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SkString fPathName;
|
|
|
|
|
@@ -125,6 +130,7 @@ public:
|
|
|
|
|
const STArray<4, SkLanguage, true> fLang;
|
|
|
|
|
const FontVariant fVariantStyle;
|
|
|
|
|
SkAutoTCallVProc<FILE, sk_fclose> fFile;
|
|
|
|
|
+ const SkFontMgr_Android_CustomFonts* custom_;
|
|
|
|
|
|
|
|
|
|
using INHERITED = SkTypeface_Android;
|
|
|
|
|
};
|
|
|
|
|
@@ -136,7 +142,7 @@ template <typename D, typename S> sk_sp<D> sk_sp_static_cast(sk_sp<S>&& s) {
|
|
|
|
|
class SkFontStyleSet_Android : public SkFontStyleSet {
|
|
|
|
|
public:
|
|
|
|
|
explicit SkFontStyleSet_Android(const FontFamily& family, const SkFontScanner* scanner,
|
|
|
|
|
- const bool cacheFontFiles) {
|
|
|
|
|
+ const bool cacheFontFiles, const SkFontMgr_Android_CustomFonts* custom) {
|
|
|
|
|
const SkString* cannonicalFamilyName = nullptr;
|
|
|
|
|
if (family.fNames.size() > 0) {
|
|
|
|
|
cannonicalFamilyName = &family.fNames[0];
|
|
|
|
|
@@ -145,12 +151,21 @@ public:
|
|
|
|
|
|
|
|
|
|
// TODO? make this lazy
|
|
|
|
|
for (int i = 0; i < family.fFonts.size(); ++i) {
|
|
|
|
|
+ bool use_custom = false;
|
|
|
|
|
const FontFileInfo& fontFile = family.fFonts[i];
|
|
|
|
|
|
|
|
|
|
SkString pathName(family.fBasePath);
|
|
|
|
|
pathName.append(fontFile.fFileName);
|
|
|
|
|
|
|
|
|
|
- std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(pathName.c_str());
|
|
|
|
|
+ std::unique_ptr<SkStreamAsset> stream;
|
|
|
|
|
+ if (!fontFile.fFileName.startsWith('#')) {
|
|
|
|
|
+ stream = SkStream::MakeFromFile(pathName.c_str());
|
|
|
|
|
+ } else if (custom) {
|
|
|
|
|
+ use_custom = true;
|
|
|
|
|
+ pathName = fontFile.fFileName;
|
|
|
|
|
+ SkDEBUGF("Requested font file apk %s", pathName.c_str());
|
|
|
|
|
+ stream = custom->getPlatformFile(pathName.c_str());
|
|
|
|
|
+ }
|
|
|
|
|
if (!stream) {
|
|
|
|
|
SkDEBUGF("Requested font file %s does not exist or cannot be opened.\n",
|
|
|
|
|
pathName.c_str());
|
|
|
|
|
@@ -202,7 +217,8 @@ public:
|
|
|
|
|
|
|
|
|
|
fStyles.push_back().reset(new SkTypeface_AndroidSystem(
|
|
|
|
|
pathName, cacheFontFiles, ttcIndex, axisValues.get(), axisDefinitions.size(),
|
|
|
|
|
- style, isFixedWidth, familyName, family.fLanguages, variant));
|
|
|
|
|
+ style, isFixedWidth, familyName, family.fLanguages, variant,
|
|
|
|
|
+ use_custom ? custom : nullptr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -256,13 +272,16 @@ struct NameToFamily {
|
|
|
|
|
|
|
|
|
|
class SkFontMgr_Android : public SkFontMgr {
|
|
|
|
|
public:
|
|
|
|
|
- SkFontMgr_Android(const SkFontMgr_Android_CustomFonts* custom) {
|
|
|
|
|
+ SkFontMgr_Android(std::unique_ptr<SkFontMgr_Android_CustomFonts> custom_in) {
|
|
|
|
|
+ custom_ = std::move(custom_in);
|
|
|
|
|
+ auto* custom = custom_.get();
|
|
|
|
|
+
|
|
|
|
|
fScanner = std::make_unique<SkFontScanner_FreeType>();
|
|
|
|
|
SkTDArray<FontFamily*> families;
|
|
|
|
|
if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem != custom->fSystemFontUse) {
|
|
|
|
|
SkString base(custom->fBasePath);
|
|
|
|
|
SkFontMgr_Android_Parser::GetCustomFontFamilies(
|
|
|
|
|
- families, base, custom->fFontsXml, custom->fFallbackFontsXml);
|
|
|
|
|
+ families, base, custom, custom->fFontsXml, custom->fFallbackFontsXml);
|
|
|
|
|
}
|
|
|
|
|
if (!custom ||
|
|
|
|
|
(custom && SkFontMgr_Android_CustomFonts::kOnlyCustom != custom->fSystemFontUse))
|
|
|
|
|
@@ -272,7 +291,7 @@ public:
|
|
|
|
|
if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem == custom->fSystemFontUse) {
|
|
|
|
|
SkString base(custom->fBasePath);
|
|
|
|
|
SkFontMgr_Android_Parser::GetCustomFontFamilies(
|
|
|
|
|
- families, base, custom->fFontsXml, custom->fFallbackFontsXml);
|
|
|
|
|
+ families, base, custom, custom->fFontsXml, custom->fFallbackFontsXml);
|
|
|
|
|
}
|
|
|
|
|
this->buildNameToFamilyMap(families, custom ? custom->fIsolated : false);
|
|
|
|
|
this->findDefaultStyleSet();
|
|
|
|
|
@@ -438,6 +457,7 @@ protected:
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<SkFontScanner> fScanner;
|
|
|
|
|
+ std::unique_ptr<SkFontMgr_Android_CustomFonts> custom_;
|
|
|
|
|
|
|
|
|
|
TArray<sk_sp<SkFontStyleSet_Android>> fStyleSets;
|
|
|
|
|
sk_sp<SkFontStyleSet> fDefaultStyleSet;
|
|
|
|
|
@@ -457,7 +477,7 @@ private:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sk_sp<SkFontStyleSet_Android> newSet =
|
|
|
|
|
- sk_make_sp<SkFontStyleSet_Android>(family, fScanner.get(), isolated);
|
|
|
|
|
+ sk_make_sp<SkFontStyleSet_Android>(family, fScanner.get(), isolated, custom_.get());
|
|
|
|
|
if (0 == newSet->count()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@@ -504,7 +524,7 @@ static char const * const gSystemFontUseStrings[] = {
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
-sk_sp<SkFontMgr> SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) {
|
|
|
|
|
+sk_sp<SkFontMgr> SkFontMgr_New_Android(std::unique_ptr<SkFontMgr_Android_CustomFonts> custom) {
|
|
|
|
|
if (custom) {
|
|
|
|
|
SkASSERT(0 <= custom->fSystemFontUse);
|
|
|
|
|
SkASSERT(custom->fSystemFontUse < std::size(gSystemFontUseStrings));
|
|
|
|
|
@@ -514,5 +534,5 @@ sk_sp<SkFontMgr> SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* cust
|
|
|
|
|
custom->fFontsXml,
|
|
|
|
|
custom->fFallbackFontsXml);
|
|
|
|
|
}
|
|
|
|
|
- return sk_make_sp<SkFontMgr_Android>(custom);
|
|
|
|
|
+ return sk_make_sp<SkFontMgr_Android>(std::move(custom));
|
|
|
|
|
}
|
|
|
|
|
diff --git a/third_party/skia/src/ports/SkFontMgr_android_parser.cpp b/third_party/skia/src/ports/SkFontMgr_android_parser.cpp
|
|
|
|
|
--- a/third_party/skia/src/ports/SkFontMgr_android_parser.cpp
|
|
|
|
|
+++ b/third_party/skia/src/ports/SkFontMgr_android_parser.cpp
|
|
|
|
|
@@ -645,14 +645,27 @@ static const XML_Memory_Handling_Suite sk_XML_alloc = {
|
|
|
|
|
* families array. Returns the version of the file, negative if the file does not exist.
|
|
|
|
|
*/
|
|
|
|
|
static int parse_config_file(const char* filename, SkTDArray<FontFamily*>& families,
|
|
|
|
|
- const SkString& basePath, bool isFallback)
|
|
|
|
|
+ const SkString& basePath, bool isFallback,
|
|
|
|
|
+ const SkFontMgr_Android_CustomFonts* custom = nullptr)
|
|
|
|
|
{
|
|
|
|
|
SkFILEStream file(filename);
|
|
|
|
|
-
|
|
|
|
|
- // Some of the files we attempt to parse (in particular, /vendor/etc/fallback_fonts.xml)
|
|
|
|
|
- // are optional - failure here is okay because one of these optional files may not exist.
|
|
|
|
|
- if (!file.isValid()) {
|
|
|
|
|
- SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "'%s' could not be opened\n", filename);
|
|
|
|
|
+ std::unique_ptr<SkStreamAsset> stream;
|
|
|
|
|
+ if (filename[0] != '#') {
|
|
|
|
|
+ // Some of the files we attempt to parse (in particular, /vendor/etc/fallback_fonts.xml)
|
|
|
|
|
+ // are optional - failure here is okay because one of these optional files may not exist.
|
|
|
|
|
+ if (!file.isValid()) {
|
|
|
|
|
+ SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "'%s' could not be opened\n", filename);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ stream = file.fork();
|
|
|
|
|
+ } else if (custom) {
|
|
|
|
|
+ stream = custom->getPlatformFile(filename);
|
|
|
|
|
+ if (!stream) {
|
|
|
|
|
+ SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "'%s' platform file map not found\n", filename);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "'%s' custom fonts not set\n", filename);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -684,8 +697,9 @@ static int parse_config_file(const char* filename, SkTDArray<FontFamily*>& famil
|
|
|
|
|
SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "could not buffer enough to continue\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
- size_t len = file.read(buffer, bufferSize);
|
|
|
|
|
- done = file.isAtEnd();
|
|
|
|
|
+ size_t len = stream->read(buffer, bufferSize);
|
|
|
|
|
+ // SkDebugf(SK_FONTMGR_ANDROID_PARSER_PREFIX "%.*s", len, buffer);
|
|
|
|
|
+ done = stream->isAtEnd();
|
|
|
|
|
XML_Status status = XML_ParseBuffer(parser, len, done);
|
|
|
|
|
if (XML_STATUS_ERROR == status) {
|
|
|
|
|
XML_Error error = XML_GetErrorCode(parser);
|
|
|
|
|
@@ -760,6 +774,7 @@ static void append_fallback_font_families_for_locale(SkTDArray<FontFamily*>& fal
|
|
|
|
|
static void append_system_fallback_font_families(SkTDArray<FontFamily*>& fallbackFonts,
|
|
|
|
|
const SkString& basePath)
|
|
|
|
|
{
|
|
|
|
|
+ if ((true)) return;
|
|
|
|
|
parse_config_file(FALLBACK_FONTS_FILE, fallbackFonts, basePath, true);
|
|
|
|
|
append_fallback_font_families_for_locale(fallbackFonts,
|
|
|
|
|
LOCALE_FALLBACK_FONTS_SYSTEM_DIR,
|
|
|
|
|
@@ -769,6 +784,7 @@ static void append_system_fallback_font_families(SkTDArray<FontFamily*>& fallbac
|
|
|
|
|
static void mixin_vendor_fallback_font_families(SkTDArray<FontFamily*>& fallbackFonts,
|
|
|
|
|
const SkString& basePath)
|
|
|
|
|
{
|
|
|
|
|
+ if ((true)) return;
|
|
|
|
|
SkTDArray<FontFamily*> vendorFonts;
|
|
|
|
|
parse_config_file(VENDOR_FONTS_FILE, vendorFonts, basePath, true);
|
|
|
|
|
append_fallback_font_families_for_locale(vendorFonts,
|
|
|
|
|
@@ -817,15 +833,16 @@ void SkFontMgr_Android_Parser::GetSystemFontFamilies(SkTDArray<FontFamily*>& fon
|
|
|
|
|
|
|
|
|
|
void SkFontMgr_Android_Parser::GetCustomFontFamilies(SkTDArray<FontFamily*>& fontFamilies,
|
|
|
|
|
const SkString& basePath,
|
|
|
|
|
+ const SkFontMgr_Android_CustomFonts* custom,
|
|
|
|
|
const char* fontsXml,
|
|
|
|
|
const char* fallbackFontsXml,
|
|
|
|
|
const char* langFallbackFontsDir)
|
|
|
|
|
{
|
|
|
|
|
if (fontsXml) {
|
|
|
|
|
- parse_config_file(fontsXml, fontFamilies, basePath, false);
|
|
|
|
|
+ parse_config_file(fontsXml, fontFamilies, basePath, false, custom);
|
|
|
|
|
}
|
|
|
|
|
if (fallbackFontsXml) {
|
|
|
|
|
- parse_config_file(fallbackFontsXml, fontFamilies, basePath, true);
|
|
|
|
|
+ parse_config_file(fallbackFontsXml, fontFamilies, basePath, true, custom);
|
|
|
|
|
}
|
|
|
|
|
if (langFallbackFontsDir) {
|
|
|
|
|
append_fallback_font_families_for_locale(fontFamilies,
|
|
|
|
|
diff --git a/third_party/skia/src/ports/SkFontMgr_android_parser.h b/third_party/skia/src/ports/SkFontMgr_android_parser.h
|
|
|
|
|
--- a/third_party/skia/src/ports/SkFontMgr_android_parser.h
|
|
|
|
|
+++ b/third_party/skia/src/ports/SkFontMgr_android_parser.h
|
|
|
|
|
@@ -15,6 +15,7 @@
|
|
|
|
|
#include "include/private/base/SkTArray.h"
|
|
|
|
|
#include "include/private/base/SkTDArray.h"
|
|
|
|
|
#include "src/core/SkTHash.h"
|
|
|
|
|
+#include "include/ports/SkFontMgr_android.h"
|
|
|
|
|
|
|
|
|
|
#include <climits>
|
|
|
|
|
#include <limits>
|
|
|
|
|
@@ -110,6 +111,7 @@ void GetSystemFontFamilies(SkTDArray<FontFamily*>& fontFamilies);
|
|
|
|
|
/** Parses font configuration files and appends result to fontFamilies. */
|
|
|
|
|
void GetCustomFontFamilies(SkTDArray<FontFamily*>& fontFamilies,
|
|
|
|
|
const SkString& basePath,
|
|
|
|
|
+ const SkFontMgr_Android_CustomFonts* custom,
|
|
|
|
|
const char* fontsXml,
|
|
|
|
|
const char* fallbackFontsXml,
|
|
|
|
|
const char* langFallbackFontsDir = nullptr);
|
|
|
|
|
--
|