use font for measuring/paths

add get_text_path to sk_tool_utils

Bug: skia:
Change-Id: I45426bc018cd8a5a0309fd6a73adb30755e8155a
Reviewed-on: https://skia-review.googlesource.com/c/179847
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp
index ba9bd7c..74aa1a5 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -10,6 +10,7 @@
 #include "SkCanvas.h"
 #include "SkColorData.h"
 #include "SkColorPriv.h"
+#include "SkFontPriv.h"
 #include "SkFloatingPoint.h"
 #include "SkImage.h"
 #include "SkMatrix.h"
@@ -153,6 +154,32 @@
     add_to_text_blob_w_len(builder, text, strlen(text), origPaint, x, y);
 }
 
+void get_text_path(const SkFont& font, const void* text, size_t length, SkTextEncoding encoding,
+                   SkPath* dst, const SkPoint pos[]) {
+    SkAutoToGlyphs atg(font, text, length, encoding);
+    const int count = atg.count();
+    SkAutoTArray<SkPoint> computedPos;
+    if (pos == nullptr) {
+        computedPos.reset(count);
+        font.getPos(atg.glyphs(), count, &computedPos[0]);
+        pos = computedPos.get();
+    }
+
+    struct Rec {
+        SkPath* fDst;
+        const SkPoint* fPos;
+    } rec = { dst, pos };
+    font.getPaths(atg.glyphs(), atg.count(), [](const SkPath* src, const SkMatrix& mx, void* ctx) {
+        Rec* rec = (Rec*)ctx;
+        if (src) {
+            SkMatrix tmp(mx);
+            tmp.postTranslate(rec->fPos->fX, rec->fPos->fY);
+            rec->fDst->addPath(*src, tmp);
+        }
+        rec->fPos += 1;
+    }, &rec);
+}
+
 SkPath make_star(const SkRect& bounds, int numPts, int step) {
     SkPath path;
     path.setFillType(SkPath::kEvenOdd_FillType);