[canvaskit] Canvas API for loading fonts

There's the barest hint of a "font manager" here.
Basically, nothing smart to deal with bold or fallbacks.

Maybe one day, we'll expose
SkTypeface* matchStyleCSS3(const SkFontStyle& pattern);

and do smart things for fallbacks, but for now that's not
in the immediate future.

Docs-Preview: https://skia.org/?cl=177067
Bug: skia:
Change-Id: Iaeabcbf5ff4511a01b37c16c983e447c25b0e3e7
Reviewed-on: https://skia-review.googlesource.com/c/177067
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/experimental/canvaskit/htmlcanvas/htmlcanvas.js b/experimental/canvaskit/htmlcanvas/htmlcanvas.js
index b756b26..6f118e5 100644
--- a/experimental/canvaskit/htmlcanvas/htmlcanvas.js
+++ b/experimental/canvaskit/htmlcanvas/htmlcanvas.js
@@ -9,7 +9,8 @@
 function HTMLCanvas(skSurface) {
   this._surface = skSurface;
   this._context = new CanvasRenderingContext2D(skSurface.getCanvas());
-  this._imgs = [];
+  this._toCleanup = [];
+  this._fontmgr = CanvasKit.SkFontMgr.RefDefault();
 
   // Data is either an ArrayBuffer, a TypedArray, or a Node Buffer
   this.decodeImage = function(data) {
@@ -17,10 +18,20 @@
     if (!img) {
       throw 'Invalid input';
     }
-    this._imgs.push(img);
+    this._toCleanup.push(img);
     return img;
   }
 
+  this.loadFont = function(buffer, descriptors) {
+    var newFont = this._fontmgr.MakeTypefaceFromData(buffer);
+    if (!newFont) {
+      SkDebug('font could not be processed', descriptors);
+      return null;
+    }
+    this._toCleanup.push(newFont);
+    addToFontCache(newFont, descriptors);
+  }
+
   // A normal <canvas> requires that clients call getContext
   this.getContext = function(type) {
     if (type === '2d') {
@@ -56,7 +67,7 @@
 
   this.dispose = function() {
     this._context._dispose();
-    this._imgs.forEach(function(i) {
+    this._toCleanup.forEach(function(i) {
       i.delete();
     });
     this._surface.dispose();