[canvaskit] Clean up embedded fonts

See https://groups.google.com/forum/#!topic/skia-discuss/J2XT7XjmFtI

Change-Id: I73614208d26536924bc3ed3385c1cd3c490ef8a4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247098
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index e51e934..8d25cbe 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -328,17 +328,29 @@
 }
 
 optional("fontmgr_wasm") {
-  enabled = !skia_enable_fontmgr_empty && target_cpu == "wasm"
+  enabled = target_cpu == "wasm"
 
   deps = [
     ":typeface_freetype",
   ]
+
+  # custom_embedded has the source for both embedding a font in the binary
+  # (only used for the all-included build) and reading in a font from
+  # raw bytes passed over the wire (a typical way to load fonts).
   sources = [
-    "src/ports/SkFontMgr_custom.cpp",
-    "src/ports/SkFontMgr_custom.h",
     "src/ports/SkFontMgr_custom_embedded.cpp",
-    "src/ports/SkFontMgr_custom_embedded_factory.cpp",
   ]
+
+  # If we haven't opted for no fonts (empty) or fonts, but not the
+  # built-in one (custom), then, we need to provide the mechanism for
+  # using the built-in font.
+  if (!skia_enable_fontmgr_empty && !skia_enable_fontmgr_custom) {
+    sources += [
+      "src/ports/SkFontMgr_custom.cpp",
+      "src/ports/SkFontMgr_custom.h",
+      "src/ports/SkFontMgr_custom_embedded_factory.cpp",
+    ]
+  }
 }
 
 optional("fontmgr_win") {
diff --git a/modules/canvaskit/compile.sh b/modules/canvaskit/compile.sh
index 49b7faf..340e011 100755
--- a/modules/canvaskit/compile.sh
+++ b/modules/canvaskit/compile.sh
@@ -101,7 +101,7 @@
   HTML_CANVAS_API=""
 fi
 
-GN_FONT="skia_enable_fontmgr_empty=false"
+GN_FONT="skia_enable_fontmgr_empty=false skia_enable_fontmgr_custom_empty=false"
 FONT_CFLAGS=""
 BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp"
 if [[ $@ == *no_font* ]]; then
@@ -111,8 +111,8 @@
   GN_FONT="skia_enable_fontmgr_empty=true"
 elif [[ $@ == *no_embedded_font* ]]; then
   echo "Omitting the built-in font(s)"
-  BUILTIN_FONT="$BASE_DIR/fonts/nofonts.cpp"
-  GN_FONT="skia_enable_fontmgr_empty=false"
+  BUILTIN_FONT=""
+  GN_FONT="skia_enable_fontmgr_empty=false skia_enable_fontmgr_custom_empty=true"
 else
   # Generate the font's binary file (which is covered by .gitignore)
   python tools/embed_resources.py \
diff --git a/modules/canvaskit/fonts/nofonts.cpp b/modules/canvaskit/fonts/nofonts.cpp
deleted file mode 100644
index cc982c1..0000000
--- a/modules/canvaskit/fonts/nofonts.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright 2019 Google LLC
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include <stddef.h>
-#include <stdint.h>
-struct SkEmbeddedResource { const uint8_t* d; const size_t s; };
-static const SkEmbeddedResource header[] = {};
-static const int header_count = 0;
-struct SkEmbeddedHeader {const SkEmbeddedResource* e; const int c;};
-extern "C" const SkEmbeddedHeader SK_EMBEDDED_FONTS = { header, header_count };