[canvaskit] Move to using SkFont instead of SkPaint.measure*
Bug: skia:
Change-Id: I72a744f58072f0bc5f9cad561c4367ff5d32e5ab
Reviewed-on: https://skia-review.googlesource.com/c/180643
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/experimental/canvaskit/htmlcanvas/canvas2dcontext.js b/experimental/canvaskit/htmlcanvas/canvas2dcontext.js
index 06e47dc..3d79f19 100644
--- a/experimental/canvaskit/htmlcanvas/canvas2dcontext.js
+++ b/experimental/canvaskit/htmlcanvas/canvas2dcontext.js
@@ -10,6 +10,8 @@
this._paint.setTypeface(null);
this._fontString = '10px monospace';
+ this._font = new CanvasKit.SkFont();
+
this._strokeStyle = CanvasKit.BLACK;
this._fillStyle = CanvasKit.BLACK;
this._shadowBlur = 0;
@@ -41,6 +43,7 @@
this._dispose = function() {
this._currentPath.delete();
this._paint.delete();
+ this._font.delete();
this._toCleanUp.forEach(function(c) {
c._dispose();
});
@@ -105,6 +108,8 @@
// bracket notation to tell closure not to minify these names.
this._paint.setTextSize(tf['sizePx']);
this._paint.setTypeface(tf['typeface']);
+ this._font.setSize(tf['sizePx']);
+ this._font.setTypeface(tf['typeface']);
this._fontString = newFont;
}
}
@@ -788,7 +793,7 @@
this.measureText = function(text) {
return {
- width: this._paint.measureText(text),
+ width: this._font.measureText(text),
// TODO other measurements?
}
}