Allow runtime switching between sftntly and HarfBuzz

Incorporate a feature flag around PDF document subsetter metadata to
switch between enums indicating HarfBuzz or sftnly subsetters. The
metadata is later passed down to Skia, which will use the appropriate
subsetter. The feature flag, named "HarfBuzz PDF Subsetter," can be
toggled on chrome://flags.

Change the Skia build config to enable HarfBuzz's subsetter, meaning
that both HarfBuzz and sfntly will be available. The addition of
HarfBuzz adds a temporary 24kB to Chrome, with the intention of later
removing the 50kB that comes with sfntly.

Move printing_export.h to a new target to avoid a circular build
dependency. This is also a good first step in reorganizing the
'printing/' directory.

Original CL by Hal Canary [1]

[1] https://chromium-review.googlesource.com/c/chromium/src/+/1531173

HarfBuzz as a PDF font subsetter through a Finch experiment.

Bug: 931719, 976905
Binary-Size: Increase is temporary and necessary for validating
Change-Id: Ibe67c6c13c5c2379124188a943763076360e9b0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1659130
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672248}
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 983e8a6..078c3aa 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -184,7 +184,7 @@
 #endif
 
 #if BUILDFLAG(ENABLE_PRINTING)
-#include "printing/printing_features.h"
+#include "printing/common/printing_features.h"
 #endif
 
 #if defined(USE_OZONE)
diff --git a/printing/BUILD.gn b/printing/BUILD.gn
index 48a5884..5fe480f 100644
--- a/printing/BUILD.gn
+++ b/printing/BUILD.gn
@@ -22,6 +22,14 @@
              "set enable_pdf=true.")
 }
 
+# Several targets want to include this header file. We separate it out
+# here so multiple targets can depend on it.
+source_set("printing_export") {
+  sources = [
+    "printing_export.h",
+  ]
+}
+
 component("printing") {
   sources = [
     "backend/print_backend.cc",
@@ -67,9 +75,6 @@
     "printed_document_win.cc",
     "printing_context.cc",
     "printing_context.h",
-    "printing_export.h",
-    "printing_features.cc",
-    "printing_features.h",
     "printing_utils.cc",
     "printing_utils.h",
     "pwg_raster_settings.h",
@@ -84,6 +89,7 @@
     "//printing/buildflags",
   ]
   deps = [
+    ":printing_export",
     "//base",
     "//base:i18n",
     "//base/third_party/dynamic_annotations",
diff --git a/printing/common/BUILD.gn b/printing/common/BUILD.gn
index c40a79c..4143ca72 100644
--- a/printing/common/BUILD.gn
+++ b/printing/common/BUILD.gn
@@ -6,10 +6,15 @@
   sources = [
     "metafile_utils.cc",
     "metafile_utils.h",
+    "printing_features.cc",
+    "printing_features.h",
   ]
 
   deps = [
     "//base",
+    "//printing:printing_export",
     "//skia",
   ]
+
+  defines = [ "PRINTING_IMPLEMENTATION" ]
 }
diff --git a/printing/common/metafile_utils.cc b/printing/common/metafile_utils.cc
index 1dcae3a..eae01fb 100644
--- a/printing/common/metafile_utils.cc
+++ b/printing/common/metafile_utils.cc
@@ -5,6 +5,7 @@
 #include "printing/common/metafile_utils.h"
 
 #include "base/time/time.h"
+#include "printing/common/printing_features.h"
 #include "third_party/skia/include/core/SkCanvas.h"
 #include "third_party/skia/include/core/SkPicture.h"
 #include "third_party/skia/include/core/SkPictureRecorder.h"
@@ -51,6 +52,10 @@
                           ? SkString("Chromium")
                           : SkString(creator.c_str(), creator.size());
   metadata.fRasterDPI = 300.0f;
+  metadata.fSubsetter =
+      base::FeatureList::IsEnabled(printing::features::kHarfBuzzPDFSubsetter)
+          ? SkPDF::Metadata::kHarfbuzz_Subsetter
+          : SkPDF::Metadata::kSfntly_Subsetter;
   return SkPDF::MakeDocument(stream, metadata);
 }
 
diff --git a/printing/printing_features.cc b/printing/common/printing_features.cc
similarity index 89%
rename from printing/printing_features.cc
rename to printing/common/printing_features.cc
index 9e8f542..41b37e0 100644
--- a/printing/printing_features.cc
+++ b/printing/common/printing_features.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "printing/printing_features.h"
+#include "printing/common/printing_features.h"
 
 namespace printing {
 namespace features {
diff --git a/printing/printing_features.h b/printing/common/printing_features.h
similarity index 74%
rename from printing/printing_features.h
rename to printing/common/printing_features.h
index 5be47e9..22c6295 100644
--- a/printing/printing_features.h
+++ b/printing/common/printing_features.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef PRINTING_PRINTING_FEATURES_H_
-#define PRINTING_PRINTING_FEATURES_H_
+#ifndef PRINTING_COMMON_PRINTING_FEATURES_H_
+#define PRINTING_COMMON_PRINTING_FEATURES_H_
 
 #include "base/feature_list.h"
 #include "printing/printing_export.h"
@@ -16,4 +16,4 @@
 }  // namespace features
 }  // namespace printing
 
-#endif  // PRINTING_PRINTING_FEATURES_H_
+#endif  // PRINTING_COMMON_PRINTING_FEATURES_H_
diff --git a/skia/BUILD.gn b/skia/BUILD.gn
index 91e90bf..31aae1e 100644
--- a/skia/BUILD.gn
+++ b/skia/BUILD.gn
@@ -536,6 +536,7 @@
 
   if (skia_support_pdf) {
     deps += [
+      "//third_party:freetype_harfbuzz",
       "//third_party/sfntly",
       "//third_party/sfntly:sfntly_chromium",
       "//third_party/zlib",
diff --git a/skia/config/SkUserConfig.h b/skia/config/SkUserConfig.h
index c2c2605..648c7a3e 100644
--- a/skia/config/SkUserConfig.h
+++ b/skia/config/SkUserConfig.h
@@ -132,6 +132,7 @@
 /*  Define this to provide font subsetter for font subsetting when generating
     PDF documents.
  */
+#define SK_PDF_USE_HARFBUZZ_SUBSET
 #define SK_PDF_USE_SFNTLY
 
 // Chromium does not use these fonts.  This define causes type1 fonts to be