Skip to content

Graphite Patch

Joel edited this page Apr 30, 2021 · 1 revision

This is the current version of the patch that is applied to Electron. Any time you want to patch a new version of Electron you just need to apply the below patch. You might need to make a few manual adjustments to account for merge conflicts in /DEPS and /patches/chromium/.patches.

From 7e16a4013b3da2449927cfdda72050ef9c568296 Mon Sep 17 00:00:00 2001
From: Joel <da1nerd@pm.me>
Date: Thu, 29 Apr 2021 15:13:47 +0700
Subject: add graphite to electron

---
 DEPS                                |  17 +++
 patches/chromium/.patches           |   1 +
 patches/chromium/add_graphite.patch | 228 ++++++++++++++++++++++++++++
 3 files changed, 246 insertions(+)
 create mode 100644 patches/chromium/add_graphite.patch

diff --git a/DEPS b/DEPS
index f7bd58bb0..16495c1e8 100644
--- a/DEPS
+++ b/DEPS
@@ -24,6 +24,7 @@ vars = {
 
   'pyyaml_version': '3.12',
   'requests_version': 'e4d59bedfd3c7f4f254f4f5d036587bcd8152458',
+  'graphite_version': '92f59dcc52f73ce747f1cdc831579ed2546884aa',
 
   'chromium_git': 'https://chromium.googlesource.com',
   'electron_git': 'https://github.com/electron',
@@ -31,6 +32,7 @@ vars = {
   'requests_git': 'https://github.com/kennethreitz',
   'yaml_git': 'https://github.com/yaml',
   'squirrel_git': 'https://github.com/Squirrel',
+  'graphite_git': 'https://github.com/silnrsi',
 
   # KEEP IN SYNC WITH utils.js FILE
   'yarn_version': '1.15.2',
@@ -46,6 +48,7 @@ vars = {
   'checkout_node': True,
   'checkout_nan': True,
   'checkout_pgo_profiles': True,
+  'checkout_graphite': True,
 
   # It's only needed to parse the native tests configurations.
   'checkout_pyyaml': False,
@@ -95,6 +98,10 @@ deps = {
     'url': (Var("nodejs_git")) + '/node.git@' + (Var("node_version")),
     'condition': 'checkout_node and process_deps',
   },
+  'src/third_party/graphite/graphite2': {
+    'url': (Var("graphite_git")) + '/graphite.git@' + (Var("graphite_version")),
+    'condition': 'checkout_graphite and process_deps',
+  },
   'src/electron/vendor/pyyaml': {
     'url': (Var("yaml_git")) + '/pyyaml.git@' + (Var("pyyaml_version")),
     'condition': 'checkout_pyyaml and process_deps',
@@ -132,6 +139,16 @@ pre_deps_hooks = [
       'src/electron/patches/config.json',
     ],
   },
+  {
+    'name': 'setup_graphite',
+    'condition': 'checkout_graphite and apply_patches and process_deps',
+    'pattern': 'src/electron',
+    'action': [
+      'python3',
+      '-c',
+      'import os; os.makedirs(os.path.join("src", "electron", "third_party", "graphite"));',
+    ],
+  },
 ]
 
 hooks = [
diff --git a/patches/chromium/.patches b/patches/chromium/.patches
index 54cd7d65c..f59de1ea2 100644
--- a/patches/chromium/.patches
+++ b/patches/chromium/.patches
@@ -113,3 +113,4 @@ word_break_between_space_and_alphanumeric.patch
 moves_background_color_setter_of_webview_to_blinks_webprefs_logic.patch
 blink_wasm_eval_csp.patch
 cherry-pick-162efe98330e.patch
+add_graphite.patch
\ No newline at end of file
diff --git a/patches/chromium/add_graphite.patch b/patches/chromium/add_graphite.patch
new file mode 100644
index 000000000..d941bcc2a
--- /dev/null
+++ b/patches/chromium/add_graphite.patch
@@ -0,0 +1,228 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Joel <da1nerd@pm.me>
+Date: Tue, 23 Jul 2019 15:48:39 -0700
+Subject: [PATCH] adds graphite support for font rendering
+
+---
+ third_party/BUILD.gn                          |   4 +
+ .../platform/fonts/web_font_decoder.cc        |  11 ++
+ third_party/graphite/BUILD.gn                 | 115 ++++++++++++++++++
+ third_party/graphite/graphite.gni             |   4 +
+ third_party/harfbuzz-ng/BUILD.gn              |  12 ++
+ 5 files changed, 146 insertions(+)
+ create mode 100644 third_party/graphite/BUILD.gn
+ create mode 100644 third_party/graphite/graphite.gni
+
+diff --git a/third_party/BUILD.gn b/third_party/BUILD.gn
+index f0a8651e4eac..4b4b1473fb26 100644
+--- a/third_party/BUILD.gn
++++ b/third_party/BUILD.gn
+@@ -4,6 +4,7 @@
+
+ import("//build/config/freetype/freetype.gni")
+ import("//third_party/harfbuzz-ng/harfbuzz.gni")
++import("//third_party/graphite/graphite.gni")
+ import("//third_party/libjpeg.gni")
+
+ assert(!is_ios, "This is not used on iOS, don't drag it in unintentionally")
+@@ -64,5 +65,8 @@ component("freetype_harfbuzz") {
+     public_configs += [ "//third_party/harfbuzz-ng:harfbuzz_from_pkgconfig" ]
+   } else {
+     public_deps += [ "//third_party/harfbuzz-ng:harfbuzz_source" ]
++    if (use_graphite) {
++      public_deps += [ "//third_party/graphite:graphite_source" ]
++    }
+   }
+ }
+diff --git a/third_party/blink/renderer/platform/fonts/web_font_decoder.cc b/third_party/blink/renderer/platform/fonts/web_font_decoder.cc
+index dad31d2a64db..c49bfd66fefe 100644
+--- a/third_party/blink/renderer/platform/fonts/web_font_decoder.cc
++++ b/third_party/blink/renderer/platform/fonts/web_font_decoder.cc
+@@ -97,6 +97,11 @@ ots::TableAction BlinkOTSContext::GetTableAction(uint32_t tag) {
+   const uint32_t kCblcTag = OTS_TAG('C', 'B', 'L', 'C');
+   const uint32_t kColrTag = OTS_TAG('C', 'O', 'L', 'R');
+   const uint32_t kCpalTag = OTS_TAG('C', 'P', 'A', 'L');
++  const uint32_t kFeatTag = OTS_TAG('F', 'e', 'a', 't');
++  const uint32_t kGlatTag = OTS_TAG('G', 'l', 'a', 't');
++  const uint32_t kGlocTag = OTS_TAG('G', 'l', 'o', 'c');
++  const uint32_t kSilfTag = OTS_TAG('S', 'i', 'l', 'f');
++  const uint32_t kSillTag = OTS_TAG('S', 'i', 'l', 'l');
+   const uint32_t kCff2Tag = OTS_TAG('C', 'F', 'F', '2');
+   const uint32_t kSbixTag = OTS_TAG('s', 'b', 'i', 'x');
+ #if HB_VERSION_ATLEAST(1, 0, 0)
+@@ -123,6 +128,12 @@ ots::TableAction BlinkOTSContext::GetTableAction(uint32_t tag) {
+     // Windows Color Emoji Tables
+     case kColrTag:
+     case kCpalTag:
++    // Graphite
++    case kFeatTag:
++    case kGlatTag:
++    case kGlocTag:
++    case kSilfTag:
++    case kSillTag:
+     case kCff2Tag:
+     case kSbixTag:
+ #if HB_VERSION_ATLEAST(1, 0, 0)
+diff --git a/third_party/graphite/BUILD.gn b/third_party/graphite/BUILD.gn
+new file mode 100644
+index 000000000000..75b8267c8091
+--- /dev/null
++++ b/third_party/graphite/BUILD.gn
+@@ -0,0 +1,115 @@
++
++config("graphite_config") {
++    include_dirs = [ "graphite2/include" ]
++}
++
++config("graphite_build") {
++    include_dirs = [ "graphite2/src" ]
++    cflags = []
++
++    if (is_win) {
++        defines = ["_SCL_SECURE_NO_WARNINGS",
++                   "_CRT_SECURE_NO_WARNINGS",
++                   "UNICODE",
++                   "GRAPHITE2_STATIC"]
++    } else {
++        cflags += ["-Wall",  "-Wextra",  "-Wno-unknown-pragmas",
++               "-Wendif-labels", "-Wshadow", "-Wctor-dtor-privacy",
++               "-Wnon-virtual-dtor"]
++
++
++#        if (is_clang) {
++#            cflags += ["-Wimplicit-fallthrough", "-Wshorten-64-to-32"]
++#        }
++    }
++}
++
++source_set("graphite_source") {
++    visibility = [ "//third_party:freetype_harfbuzz" ]
++
++    sources = [
++        "graphite2/src/direct_machine.cpp",
++        "graphite2/src/gr_char_info.cpp",
++        "graphite2/src/gr_face.cpp",
++        "graphite2/src/gr_features.cpp",
++        "graphite2/src/gr_font.cpp",
++        "graphite2/src/gr_logging.cpp",
++        "graphite2/src/gr_segment.cpp",
++        "graphite2/src/gr_slot.cpp",
++        "graphite2/src/json.cpp",
++        "graphite2/src/CmapCache.cpp",
++        "graphite2/src/Code.cpp",
++        "graphite2/src/Collider.cpp",
++        "graphite2/src/Decompressor.cpp",
++        "graphite2/src/Face.cpp",
++        "graphite2/src/FeatureMap.cpp",
++        "graphite2/src/FileFace.cpp",
++        "graphite2/src/Font.cpp",
++        "graphite2/src/GlyphCache.cpp",
++        "graphite2/src/GlyphFace.cpp",
++        "graphite2/src/Intervals.cpp",
++        "graphite2/src/Justifier.cpp",
++        "graphite2/src/NameTable.cpp",
++        "graphite2/src/Pass.cpp",
++        "graphite2/src/Position.cpp",
++        "graphite2/src/Segment.cpp",
++        "graphite2/src/Silf.cpp",
++        "graphite2/src/Slot.cpp",
++        "graphite2/src/Sparse.cpp",
++        "graphite2/src/TtfUtil.cpp",
++        "graphite2/src/UtfCodec.cpp",
++
++        "graphite2/src/inc/bits.h",
++        "graphite2/src/inc/debug.h",
++        "graphite2/src/inc/json.h",
++        "graphite2/src/inc/CharInfo.h",
++        "graphite2/src/inc/CmapCache.h",
++        "graphite2/src/inc/Code.h",
++        "graphite2/src/inc/Collider.h",
++        "graphite2/src/inc/Compression.h",
++        "graphite2/src/inc/Decompressor.h",
++        "graphite2/src/inc/Endian.h",
++        "graphite2/src/inc/Error.h",
++        "graphite2/src/inc/Face.h",
++        "graphite2/src/inc/FeatureMap.h",
++        "graphite2/src/inc/FeatureVal.h",
++        "graphite2/src/inc/FileFace.h",
++        "graphite2/src/inc/Font.h",
++        "graphite2/src/inc/GlyphCache.h",
++        "graphite2/src/inc/GlyphFace.h",
++        "graphite2/src/inc/Intervals.h",
++        "graphite2/src/inc/List.h",
++        "graphite2/src/inc/locale2lcid.h",
++        "graphite2/src/inc/Machine.h",
++        "graphite2/src/inc/Main.h",
++        "graphite2/src/inc/NameTable.h",
++        "graphite2/src/inc/opcode_table.h",
++        "graphite2/src/inc/opcodes.h",
++        "graphite2/src/inc/Pass.h",
++        "graphite2/src/inc/Position.h",
++        "graphite2/src/inc/Rule.h",
++        "graphite2/src/inc/Segment.h",
++        "graphite2/src/inc/Silf.h",
++        "graphite2/src/inc/Slot.h",
++        "graphite2/src/inc/Sparse.h",
++        "graphite2/src/inc/TtfTypes.h",
++        "graphite2/src/inc/TtfUtil.h",
++        "graphite2/src/inc/UtfCodec.h",
++
++        "graphite2/include/graphite2/Font.h",
++        "graphite2/include/graphite2/Log.h",
++        "graphite2/include/graphite2/Segment.h",
++        "graphite2/include/graphite2/Types.h",
++    ]
++
++    defines = [
++        "GRAPHITE2_NTRACING",
++        "GRAPHITE2_NSEGCACHE",
++        "GRAPHITE2_NFILEFACE"
++    ]
++
++    configs -= [ "//build/config/compiler:chromium_code" ]
++    configs += [ "//build/config/compiler:no_chromium_code",
++                 ":graphite_build" ]
++    public_configs = [ ":graphite_config" ]
++}
+diff --git a/third_party/graphite/graphite.gni b/third_party/graphite/graphite.gni
+new file mode 100644
+index 000000000000..a053150ebfb4
+--- /dev/null
++++ b/third_party/graphite/graphite.gni
+@@ -0,0 +1,4 @@
++
++declare_args() {
++    use_graphite = true
++}
+diff --git a/third_party/harfbuzz-ng/BUILD.gn b/third_party/harfbuzz-ng/BUILD.gn
+index 37d8e334c262..1f7eeb9aaa7a 100644
+--- a/third_party/harfbuzz-ng/BUILD.gn
++++ b/third_party/harfbuzz-ng/BUILD.gn
+@@ -8,6 +8,7 @@ import("//build/config/freetype/freetype.gni")
+ import("//build/config/ui.gni")
+ import("//testing/libfuzzer/fuzzer_test.gni")
+ import("//third_party/harfbuzz-ng/harfbuzz.gni")
++import("//third_party/graphite/graphite.gni")
+
+ if (use_system_harfbuzz) {
+   import("//build/config/linux/pkg_config.gni")
+@@ -278,6 +279,17 @@ if (use_system_harfbuzz) {
+       public += [ "src/src/hb-glib.h" ]
+       sources += [ "src/src/hb-glib.cc" ]
+     }
++
++    if (use_graphite) {
++      configs += [ "//third_party/graphite:graphite_config" ]
++      sources += [
++        "src/src/hb-graphite2.cc",
++        "src/src/hb-graphite2.h",
++      ]
++      defines += ["HAVE_GRAPHITE2",
++                  "GRAPHITE2_STATIC"
++                 ]
++    }
+   }
+ }
+
+--
+2.17.1
\ No newline at end of file
-- 
2.27.0

Clone this wiki locally