[canvaskit] Use textblob

Removes old API and replaces with new version.
drawText now requires SkFont and other changes.

Bug: skia:
Change-Id: Ie42a5243629542934c761223ed2e8dc6685d3572
Reviewed-on: https://skia-review.googlesource.com/c/183389
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/experimental/canvaskit/interface.js b/experimental/canvaskit/interface.js
index fbee8f4..fe0d6be 100644
--- a/experimental/canvaskit/interface.js
+++ b/experimental/canvaskit/interface.js
@@ -382,6 +382,17 @@
       throw 'encodeToData expected to take 0 or 2 arguments. Got ' + arguments.length;
     }
 
+    CanvasKit.SkCanvas.prototype.drawText = function(str, x, y, font, paint) {
+      // lengthBytesUTF8 and stringToUTF8Array are defined in the emscripten
+      // JS.  See https://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html#stringToUTF8
+      // Add 1 for null terminator
+      var strLen = lengthBytesUTF8(str) + 1;
+      var strPtr = CanvasKit._malloc(strLen);
+      // Add 1 for the null terminator.
+      stringToUTF8(str, strPtr, strLen);
+      this._drawSimpleText(strPtr, strLen, x, y, font, paint);
+    }
+
     // returns Uint8Array
     CanvasKit.SkCanvas.prototype.readPixels = function(x, y, w, h, alphaType,
                                                        colorType, dstRowBytes) {
@@ -453,6 +464,29 @@
       return font;
     }
 
+    CanvasKit.SkTextBlob.MakeFromText = function(str, font) {
+      // lengthBytesUTF8 and stringToUTF8Array are defined in the emscripten
+      // JS.  See https://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html#stringToUTF8
+      // Add 1 for null terminator
+      var strLen = lengthBytesUTF8(str) + 1;
+      var strPtr = CanvasKit._malloc(strLen);
+      // Add 1 for the null terminator.
+      stringToUTF8(str, strPtr, strLen);
+
+      var blob = CanvasKit.SkTextBlob._MakeFromText(strPtr, strLen - 1, font, CanvasKit.TextEncoding.UTF8);
+      if (!blob) {
+        SkDebug('Could not make textblob from string "' + str + '"');
+        return null;
+      }
+
+      var origDelete = blob.delete.bind(blob);
+      blob.delete = function() {
+        CanvasKit._free(strPtr);
+        origDelete();
+      }
+      return blob;
+    }
+
     // Run through the JS files that are added at compile time.
     if (CanvasKit._extraInitializations) {
       CanvasKit._extraInitializations.forEach(function(init) {