use SkFont for measuring and paths
Bug: skia:
Change-Id: I1810edfef6e04be0380bac0eeab5450fe302e078
Reviewed-on: https://skia-review.googlesource.com/c/179728
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/gm/drawatlas.cpp b/gm/drawatlas.cpp
index a06668f..5997bf6 100644
--- a/gm/drawatlas.cpp
+++ b/gm/drawatlas.cpp
@@ -11,6 +11,7 @@
#include "SkCanvas.h"
#include "SkRSXform.h"
#include "SkSurface.h"
+#include "SkTextBlob.h"
#include "sk_tool_utils.h"
class DrawAtlasGM : public skiagm::GM {
@@ -104,12 +105,10 @@
#include "SkPathMeasure.h"
static void draw_text_on_path(SkCanvas* canvas, const void* text, size_t length,
- const SkPoint xy[], const SkPath& path, const SkPaint& paint,
+ const SkPoint xy[], const SkPath& path, const SkFont& font, const SkPaint& paint,
float baseline_offset) {
SkPathMeasure meas(path, false);
- SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
-
int count = font.countText(text, length, kUTF8_SkTextEncoding);
size_t size = count * (sizeof(SkRSXform) + sizeof(SkScalar));
SkAutoSMalloc<512> storage(size);
@@ -122,7 +121,9 @@
SkTMax(SkScalarAbs(fontb.fTop), SkScalarAbs(fontb.fBottom)));
const SkRect bounds = path.getBounds().makeOutset(max, max);
- paint.getTextWidths(text, length, widths);
+ SkAutoTArray<SkGlyphID> glyphs(count);
+ font.textToGlyphs(text, length, kUTF8_SkTextEncoding, glyphs.get(), count);
+ font.getWidths(glyphs.get(), count, widths);
for (int i = 0; i < count; ++i) {
// we want to position each character on the center of its advance
@@ -141,7 +142,9 @@
xform[i].fTy = pos.y() + tan.x() * xy[i].y() - tan.y() * offset;
}
- canvas->drawTextRSXform(text, length, &xform[0], &bounds, paint);
+ canvas->drawTextBlob(SkTextBlob::MakeFromRSXform(glyphs.get(), count * sizeof(SkGlyphID),
+ &xform[0], font, kGlyphID_SkTextEncoding),
+ 0, 0, paint);
if (true) {
SkPaint p;
@@ -162,10 +165,12 @@
const int N = sizeof(text0) - 1;
SkPoint pos[N];
+ SkFont font;
+ font.setSize(100);
+
SkPaint paint;
paint.setShader(make_shader());
paint.setAntiAlias(true);
- paint.setTextSize(100);
if (doStroke) {
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2.25f);
@@ -175,7 +180,7 @@
SkScalar x = 0;
for (int i = 0; i < N; ++i) {
pos[i].set(x, 0);
- x += paint.measureText(&text0[i], 1);
+ x += font.measureText(&text0[i], 1, kUTF8_SkTextEncoding, nullptr, &paint);
}
SkPath path;
@@ -187,7 +192,7 @@
for (auto d : dirs) {
path.reset();
path.addOval(SkRect::MakeXYWH(160, 160, 540, 540), d);
- draw_text_on_path(canvas, text0, N, pos, path, paint, baseline_offset);
+ draw_text_on_path(canvas, text0, N, pos, path, font, paint, baseline_offset);
}
paint.reset();
@@ -204,8 +209,6 @@
}
}
-#include "SkTextBlob.h"
-
// Exercise xform blob and its bounds
DEF_SIMPLE_GM(blob_rsxform, canvas, 500, 100) {
SkFont font;